function LayoutBuilderEntityViewDisplayForm::entityFormEntityBuild

Same name in other branches
  1. 9 core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php \Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm::entityFormEntityBuild()
  2. 10 core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php \Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm::entityFormEntityBuild()
  3. 11.x core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php \Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm::entityFormEntityBuild()

Entity builder for layout options on the entity view display form.

File

core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php, line 199

Class

LayoutBuilderEntityViewDisplayForm
Edit form for the LayoutBuilderEntityViewDisplay entity type.

Namespace

Drupal\layout_builder\Form

Code

public function entityFormEntityBuild($entity_type_id, LayoutEntityDisplayInterface $display, &$form, FormStateInterface &$form_state) {
    $set_enabled = (bool) $form_state->getValue([
        'layout',
        'enabled',
    ], FALSE);
    $already_enabled = $display->isLayoutBuilderEnabled();
    if ($set_enabled) {
        $overridable = (bool) $form_state->getValue([
            'layout',
            'allow_custom',
        ], FALSE);
        $display->setOverridable($overridable);
        if (!$already_enabled) {
            $display->enableLayoutBuilder();
        }
    }
    elseif ($already_enabled) {
        $form_state->setRedirectUrl($this->sectionStorage
            ->getLayoutBuilderUrl('disable'));
    }
}

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