ui_patterns icon indicating copy to clipboard operation
ui_patterns copied to clipboard

Form fields in patterns not processed by the Form API

Open manuel-adan opened this issue 6 years ago • 1 comments

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 avatar Sep 30 '19 16:09 manuel-adan

Initial approach at pull request #276

manuel-adan avatar Sep 30 '19 18:09 manuel-adan