public MenuLinkDefaultForm::extractFormValues(array &$form, FormStateInterface $form_state)
Extracts a plugin definition from form values.
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
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
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;
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Menu!Form!MenuLinkDefaultForm.php/function/MenuLinkDefaultForm::extractFormValues/8.1.x