function MenuLinkDefaultForm::extractFormValues

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php \Drupal\Core\Menu\Form\MenuLinkDefaultForm::extractFormValues()

File

core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php, line 152

Class

MenuLinkDefaultForm
Provides an edit form for static menu links.

Namespace

Drupal\Core\Menu\Form

Code

public function extractFormValues(array &$form, FormStateInterface $form_state) {
  // Start from the complete, original, definition.
  $new_definition = $this->menuLink
    ->getPluginDefinition();
  // Since the ID may not be present in the definition used to construct the
  // plugin, add it here so it's available to any consumers of this method.
  $new_definition['id'] = $form_state->getValue('id');
  $new_definition['enabled'] = $form_state->getValue('enabled') ? 1 : 0;
  $new_definition['weight'] = (int) $form_state->getValue('weight');
  $new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0;
  [$menu_name, $parent] = explode(':', $form_state->getValue('menu_parent'), 2);
  if (!empty($menu_name)) {
    $new_definition['menu_name'] = $menu_name;
  }
  if (isset($parent)) {
    $new_definition['parent'] = $parent;
  }
  return $new_definition;
}

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