Skip to content

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

@webmozart

Description

@webmozart

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy