public function PageVariantAddForm::buildForm in Page Manager 8
Same name and namespace in other branches
- 8.4 page_manager_ui/src/Form/PageVariantAddForm.php \Drupal\page_manager_ui\Form\PageVariantAddForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- page_manager_ui/
src/ Form/ PageVariantAddForm.php, line 68 - Contains Drupal\page_manager_ui\Form\PageVariantAddForm.
Class
- PageVariantAddForm
- Provides a form for adding a variant.
Namespace
Drupal\page_manager_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $machine_name = '') {
$cached_values = $form_state
->getTemporaryValue('wizard');
// The name label for variants is not required and can be changed later.
$form['name']['label']['#required'] = FALSE;
$form['name']['label']['#disabled'] = FALSE;
$variant_plugin_options = [];
foreach ($this->variantManager
->getDefinitions() as $plugin_id => $definition) {
// The following two variants are provided by Drupal Core. They are not
// configurable and therefore not compatible with Page Manager but have
// similar and confusing labels. Skip them so that they are not shown in
// the UI.
if (in_array($plugin_id, [
'simple_page',
'block_page',
])) {
continue;
}
$variant_plugin_options[$plugin_id] = $definition['admin_label'];
}
$form['variant_plugin_id'] = [
'#title' => $this
->t('Type'),
'#type' => 'select',
'#options' => $variant_plugin_options,
'#default_value' => !empty($cached_values['variant_plugin_id']) ? $cached_values['variant_plugin_id'] : '',
];
$form['wizard_options'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Optional features'),
'#description' => $this
->t('Check any optional features you need to be presented with forms for configuring them. If you do not check them here you will still be able to utilize these features once the new variant is created.'),
'#options' => [
'selection' => $this
->t('Selection criteria'),
'contexts' => $this
->t('Contexts'),
],
'#default_value' => !empty($cached_values['wizard_options']) ? $cached_values['wizard_options'] : [],
];
return $form;
}