You are here

public function MenuLinkConfigForm::buildEntity in Config menu link 8

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 EntityForm::buildEntity

See also

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

File

src/Plugin/Menu/Form/MenuLinkConfigForm.php, line 253
Contains \Drupal\menu_link_config\Plugin\Menu\Form\MenuLinkConfigForm.

Class

MenuLinkConfigForm

Namespace

Drupal\menu_link_config\Plugin\Menu\Form

Code

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

  /** @var \Drupal\menu_link_config\Entity\MenuLinkConfig $entity */
  $entity = parent::buildEntity($form, $form_state);
  $new_definition = $this
    ->extractFormValues($form, $form_state);
  $entity->id = $new_definition['metadata']['entity_id'];
  $entity->parent = $new_definition['parent'];
  $entity->menu_name = $new_definition['menu_name'];
  $entity
    ->setStatus(!$new_definition['hidden']);
  $entity->expanded = $new_definition['expanded'];
  $entity->weight = $new_definition['weight'];
  $entity->url = $new_definition['url'];
  $entity->route_name = $new_definition['route_name'];
  $entity->route_parameters = $new_definition['route_parameters'];
  $entity->options = $new_definition['options'];
  return $entity;
}