function FieldLayoutEntityDisplayFormTrait::form

Same name in other branches
  1. 9 core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php \Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait::form()
  2. 8.9.x core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php \Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait::form()
  3. 10 core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php \Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait::form()

Overrides \Drupal\field_ui\Form\EntityDisplayFormBase::form().

File

core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php, line 51

Class

FieldLayoutEntityDisplayFormTrait
Provides shared code for entity display forms.

Namespace

Drupal\field_layout\Form

Code

public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $form['field_layouts'] = [
        '#type' => 'details',
        '#title' => $this->t('Layout settings'),
    ];
    $layout_plugin = $this->getLayout($this->getEntity(), $form_state);
    $form['field_layouts']['field_layout'] = [
        '#type' => 'select',
        '#title' => $this->t('Select a layout'),
        '#options' => $this->layoutPluginManager
            ->getLayoutOptions(),
        '#default_value' => $layout_plugin->getPluginId(),
        '#ajax' => [
            'callback' => '::settingsAjax',
            'wrapper' => 'field-layout-settings-wrapper',
            'trigger_as' => [
                'name' => 'field_layout_change',
            ],
        ],
    ];
    $form['field_layouts']['submit'] = [
        '#type' => 'submit',
        '#name' => 'field_layout_change',
        '#value' => $this->t('Change layout'),
        '#submit' => [
            '::settingsAjaxSubmit',
        ],
        '#attributes' => [
            'class' => [
                'js-hide',
            ],
        ],
        '#ajax' => [
            'callback' => '::settingsAjax',
            'wrapper' => 'field-layout-settings-wrapper',
        ],
    ];
    $form['field_layouts']['settings_wrapper'] = [
        '#type' => 'container',
        '#id' => 'field-layout-settings-wrapper',
        '#tree' => TRUE,
    ];
    $form['field_layouts']['settings_wrapper']['icon'] = $layout_plugin->getPluginDefinition()
        ->getIcon();
    if ($layout_plugin instanceof PluginFormInterface) {
        $form['field_layouts']['settings_wrapper']['layout_settings'] = [];
        $subform_state = SubformState::createForSubform($form['field_layouts']['settings_wrapper']['layout_settings'], $form, $form_state);
        $form['field_layouts']['settings_wrapper']['layout_settings'] = $layout_plugin->buildConfigurationForm($form['field_layouts']['settings_wrapper']['layout_settings'], $subform_state);
    }
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.