nuvoleweb / ui_patterns

[NOTE] Development has moved to https://drupal.org/project/ui_patterns
https://drupal.org/project/ui_patterns
GNU General Public License v2.0
85 stars 56 forks source link

Form fields in patterns not processed by the Form API #275

Open manuel-adan opened 4 years ago

manuel-adan commented 4 years ago

I tried to render a form with UI Patterns as follows:

    $pattern_fields = [
      'title' => $this->t('Explore our catalog'),
      'lead' => [
        'text' => [
          '#type' => 'textfield',
          '#required' => TRUE,
          '#placeholder' => $this->t('Product name, brand, reference...'),
        ],
      ],
      'action_link' => [
        'actions' => [
          '#type' => 'actions',
          'submit' => [
            '#type' => 'submit',
            '#value' => $this->t('Search'),
          ],
        ],
      ],
    ];

    $form['content'] = [
      '#type' => 'pattern',
      '#id' => 'call_to_action',
      '#variant' => 'jumbotron',
      '#fields' => $pattern_fields,
    ];

The call-to-action pattern have three fields: title, lead, and action_link. The form has a text field that goes into the pattern lead, and the submit button into the action_link.

Form is rendered but the form fields are not processed by the Form API since the form fields themselves are children of '#fields', ( $form['content']['#fields']['lead']['text'] ), so $form_state->getValue('text') returns empty value.

Are there another way to achieve this?

Thanks,

manuel-adan commented 4 years ago

Initial approach at pull request #276