-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fix handling of empty_data's \Closure value in Date/Time form types #34123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,17 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
'invalid_message_parameters', | ||
])); | ||
|
||
if (isset($emptyData['date'])) { | ||
if ($emptyData instanceof \Closure) { | ||
$lazyEmptyData = static function ($option) use ($emptyData) { | ||
return static function (FormInterface $form) use ($emptyData, $option) { | ||
$emptyData = $emptyData($form->getParent()); | ||
|
||
return isset($emptyData[$option]) ? $emptyData[$option] : ''; | ||
}; | ||
}; | ||
|
||
$dateOptions['empty_data'] = $lazyEmptyData('date'); | ||
} elseif (isset($emptyData['date'])) { | ||
$dateOptions['empty_data'] = $emptyData['date']; | ||
} | ||
|
||
|
@@ -126,7 +136,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
'invalid_message_parameters', | ||
])); | ||
|
||
if (isset($emptyData['time'])) { | ||
if ($emptyData instanceof \Closure) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about doing the same as what you did in the if ($emptyData instanceof \Closure) {
$lazyEmptyData = static function ($option) use ($emptyData) {
return static function (FormInterface $form) use ($emptyData, $option) {
$emptyData = $emptyData($form->getParent());
return isset($emptyData[$option]) ? $emptyData[$option] : '';
};
};
$dateOptions['empty_data'] = $lazyEmptyData('date');
} else {
if (isset($emptyData['date'])) {
$dateOptions['empty_data'] = $emptyData['date'];
}
if (isset($emptyData['time'])) {
$timeOptions['empty_data'] = $emptyData['time'];
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To do that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see there are conflicting comments from Nicolas and Christian, so maybe we should always set |
||
$timeOptions['empty_data'] = $lazyEmptyData('time'); | ||
} elseif (isset($emptyData['time'])) { | ||
$timeOptions['empty_data'] = $emptyData['time']; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.