ui_patterns
ui_patterns copied to clipboard
Form fields in patterns not processed by the Form API
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,
Initial approach at pull request #276