MenuLinkContentForm::buildEntity

public MenuLinkContentForm::buildEntity(array $form, FormStateInterface $form_state)

Builds an updated entity object based upon the submitted form values.

For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.

Parameters

array $form: A nested array form elements comprising the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Entity\EntityInterface An updated copy of the form's entity object.

Overrides ContentEntityForm::buildEntity

See also

\Drupal\Core\Entity\EntityFormInterface::getEntity()

File

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

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(array('enabled', 'value')));
  $entity->expanded->value = (!$form_state->isValueEmpty(array('expanded', 'value')));

  return $entity;
}
doc_Drupal
2016-10-29 09:26:44
Comments
Leave a Comment

Please login to continue.