public function MenuLinkContentService::nodeSubmit in Menu Item Extras 8.2
Form submission handler for menu item field on the node form.
Parameters
array $form: Form array.
\Drupal\Core\Form\FormStateInterface $form_state: Form state object.
See also
menu_ui_form_node_form_submit()
menu_ui_form_node_form_alter()
File
- src/
Service/ MenuLinkContentService.php, line 243
Class
- MenuLinkContentService
- Class MenuLinkContentHelper.
Namespace
Drupal\menu_item_extras\ServiceCode
public function nodeSubmit(array $form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
$form_object = $form_state
->getFormObject();
/** @var \Drupal\Core\Entity\EntityInterface $node */
$node = $form_object
->getEntity();
if (!$form_state
->isValueEmpty('menu')) {
$values = $form_state
->getValue('menu');
if (!empty($values['enabled']) && trim($values['title'])) {
// Decompose the selected menu parent
// option into 'menu_name' and 'parent',
// if the form used the default parent selection widget.
if (!empty($values['menu_parent'])) {
list($menu_name, $parent) = explode(':', $values['menu_parent'], 2);
$values['menu_name'] = $menu_name;
$values['parent'] = $parent;
}
$link = $this
->nodeSave($node, $values);
$values['entity_id'] = $link
->id();
$form_state
->setValue('menu', $values);
}
}
}