You are here

public function MenuLinkDefaultForm::extractFormValues in Drupal 8

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

Extracts a plugin definition from form values.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The new plugin definition values taken from the form values. The plugin ID must be returned as part of the definition.

Overrides MenuLinkFormInterface::extractFormValues

2 calls to MenuLinkDefaultForm::extractFormValues()
MenuLinkDefaultForm::submitConfigurationForm in core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
Form submission handler.
ViewsMenuLinkForm::extractFormValues in core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php
Extracts a plugin definition from form values.
1 method overrides MenuLinkDefaultForm::extractFormValues()
ViewsMenuLinkForm::extractFormValues in core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php
Extracts a plugin definition from form values.

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;
  list($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;
}