Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Add generic way for overriding nested options #9177

Copy link
Copy link
Closed
@webmozart

Description

@webmozart
Issue body actions

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.