Description
We currently use various different ways for influencing the options of the children of an added type:
a) By letting one option accept multiple values for the children (e.g. the "empty_value" option in DateType)
$form->add('updatedAt', 'date', array(
'empty_value' => array(
'day' => 'The day...',
),
));
b) By having dedicated "options" options (e.g. "options" in CollectionType, "first_options"/"second_options" in RepeatedType)
$form->add('password', 'repeated', array(
'type' => 'password',
'first_options' => array(
'required' => true,
),
));
And in #3825, a third possibility was suggested:
c) By having one dedicated option per child and option (e.g. "day_widget", "month_widget" etc.)
$form->add('updatedAt', 'date', array(
'day_widget' => 'text',
'month_widget' => 'choice',
));
These different alternatives
- are inconsistent
- need to be implemented manually
- need to be changed whenever a new child option should be supported
Therefore I propose adding a generic way for overriding nested options by supporting a special syntax in the options array:
@child(/nestedChild)*[#option]
Examples:
$builder->add('updatedAt', 'datetime', array(
'@date' => array(
'required' => true,
'@day' => array(
'empty_value' => 'The day...',
),
),
));
// equivalent to
$builder->add('updatedAt', 'datetime', array(
'@date' => array(
'required' => true,
),
'@date/day' => array(
'empty_value' => 'The day...',
),
));
// equivalent to
$builder->add('updatedAt', 'datetime', array(
'@date#required' => true,
'@date/day#empty_value' => 'The day...',
));
Additionally, setting an option for all children at once should be supported:
$builder->add('updatedAt', 'datetime', array(
'@date/*#empty_value' => '...',
));
References:
- [2.2] [Form] Enhanced DateType with support for different widgets types per date part (year, month, day) #3825
- [Form] [Feature] Add a option to override options in embedded forms #6350
- [2.3] [Form] New CollectionType prototype_data option #6910
- [Form] Configure date and time field options in datetime type #8396
- [Form] It's impossible to set up invalid_message in datetime fieldtype #8443
- Allow the time type to use the preferred_choices for hours,minutes and s... #10012