diff --git a/src/NodeFormAlter.php b/src/NodeFormAlter.php index 09c62a8..9741d96 100644 --- a/src/NodeFormAlter.php +++ b/src/NodeFormAlter.php @@ -76,9 +76,6 @@ class NodeFormAlter { $default = $defaults['menu_name'] . ':' . $defaults['parent']; } - // Are there any traditional menus that are not group menus? - $traditional_menus = !empty($form['menu']['link']['menu_parent']['#options']); - $form['menu'] = [ '#type' => 'details', '#title' => t('Menu settings'), @@ -108,8 +105,16 @@ class NodeFormAlter { /** @var \Drupal\Core\Menu\MenuParentFormSelectorInterface $menu_parent_selector */ $menu_parent_selector = \Drupal::service('menu.parent_form_selector'); + $allowed_menus = []; + // If the menu options are already visible to the editor, show everything. + if (!empty($form['menu']['#access'])) { + $allowed_menus = array_merge($group_menus, $menu_ui_menus); + } + else { + $allowed_menus = $group_menus; + } $parent_element = $menu_parent_selector - ->parentSelectElement($default, $defaults['id'], array_merge($group_menus, $menu_ui_menus)); + ->parentSelectElement($default, $defaults['id'], $allowed_menus); $form['menu']['link']['menu_parent'] = $parent_element; // Populate the element with the link data. @@ -151,20 +156,15 @@ class NodeFormAlter { } } - $form['menu']['#access'] = FALSE; - if (!empty($form['menu']['link']['menu_parent']['#options'])) { - // If there are traditional menus and user has admin permission. - if ($traditional_menus && \Drupal::currentUser()->hasPermission('administer menu')) { + // If menus are allowed and the menu options are already visible, enable + // the menu options if the editor has group level access. + if (empty($form['menu']['#access']) && !empty($allowed_menus)) { + $context_id = '@group.group_route_context:group'; + $contexts = \Drupal::service('context.repository')->getRuntimeContexts([$context_id]); + $group = $contexts[$context_id]->getContextValue(); + if ($group && $this->canEditMenus($group, \Drupal::currentUser())) { $form['menu']['#access'] = TRUE; } - else { - $context_id = '@group.group_route_context:group'; - $contexts = \Drupal::service('context.repository')->getRuntimeContexts([$context_id]); - $group = $contexts[$context_id]->getContextValue(); - if ($group && $this->canEditMenus($group, \Drupal::currentUser())) { - $form['menu']['#access'] = TRUE; - } - } } $form['#entity_builders'][] = 'menu_ui_node_builder';