function MenuLinkContentForm::buildEntity

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

Overrides ContentEntityForm::buildEntity

File

core/modules/menu_link_content/src/Form/MenuLinkContentForm.php, line 110

Class

MenuLinkContentForm
Provides a form to add/update content menu links.

Namespace

Drupal\menu_link_content\Form

Code

public function buildEntity(array $form, FormStateInterface $form_state) {
    
    /** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
    $entity = parent::buildEntity($form, $form_state);
    list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2);
    $entity->parent->value = $parent;
    $entity->menu_name->value = $menu_name;
    $entity->enabled->value = !$form_state->isValueEmpty([
        'enabled',
        'value',
    ]);
    $entity->expanded->value = !$form_state->isValueEmpty([
        'expanded',
        'value',
    ]);
    return $entity;
}

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