You are here

public function MicrositeMenuItemForm::buildEntity in Entity Reference Hierarchy 8.2

Same name and namespace in other branches
  1. 3.x modules/entity_hierarchy_microsite/src/Form/MicrositeMenuItemForm.php \Drupal\entity_hierarchy_microsite\Form\MicrositeMenuItemForm::buildEntity()

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

modules/entity_hierarchy_microsite/src/Form/MicrositeMenuItemForm.php, line 106

Class

MicrositeMenuItemForm
Defines a class for menu link for microsite items.

Namespace

Drupal\entity_hierarchy_microsite\Form

Code

public function buildEntity(array $form, FormStateInterface $form_state) {

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