function LayoutBuilderEntityViewDisplayForm::copyFormValuesToEntity

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

Overrides EntityDisplayFormBase::copyFormValuesToEntity

File

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

Class

LayoutBuilderEntityViewDisplayForm
Edit form for the LayoutBuilderEntityViewDisplay entity type.

Namespace

Drupal\layout_builder\Form

Code

protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
    // Do not process field values if Layout Builder is or will be enabled.
    $set_enabled = (bool) $form_state->getValue([
        'layout',
        'enabled',
    ], FALSE);
    
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $entity */
    $already_enabled = $entity->isLayoutBuilderEnabled();
    if ($already_enabled || $set_enabled) {
        $form['#fields'] = [];
        $form['#extra'] = [];
    }
    parent::copyFormValuesToEntity($entity, $form, $form_state);
}

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