The current codebase does not provide support for managing menu links in OG menus from within the node form.
When adding or editing a node, a menu link can only be added / edited in the core menus that are made available for that content type.

In our use case, we also want editors to add menu links to the OG menus they have access to from within this UI.
Since the OG menus are not listed on the content type "available menus" third-party settings form, and given we don't want to manually select the dynamically created OG menus for each content type anyway, some custom code will be needed to achieve this.

Issue fork og_menu-2885625

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

svendecabooter created an issue. See original summary.

svendecabooter’s picture

Status: Active » Needs review
FileSize
6.89 KB

Attached is a patch that provides this functionality.

Included in this patch:
* Updated the OgMenuParentFormSelector service to show both core menus as well as OG menus
* Updated the OgMenuParentFormSelector service to add access control checks for OG menus
* Added extra form_alter logic to set the default menu link retrieved from an OG menu

svendecabooter’s picture

Updated patch that filters out core menus from the parent selector, in case user does not have global permission to manage menus, but still has OG-based permission to manage their specific OG menu instance(s).

svendecabooter’s picture

Updated patch fixes a PHP notice error.

svendecabooter’s picture

autopoietic’s picture

Minor amendment to check in updated patch, to avod potential Undefined index: menu issue.

zerolab’s picture

FileSize
7.09 KB
660 bytes

Here is a new patch that fixes an incorrect permissions

heddn’s picture

Status: Needs review » Needs work
+++ b/og_menu.module
@@ -113,5 +115,105 @@ function og_menu_module_implements_alter(&$implementations, $hook) {
+function og_menu_form_node_form_alter(&$form, FormStateInterface $form_state) {

Can we do this on a base entity alter form? That way this is supported for things beside nodes?

mpp’s picture

It might make sense to limit the list of og menu's to the ones for the current group(s).

Someone could change the group(s) on the node edit so I presume it is not possible to make this solution generic?

ducktape’s picture

Status: Needs work » Needs review
FileSize
14.17 KB

I replaced the MenuParentFormSelector service with a form alter to only load the groups that are applicable to the node, as the service is not aware of any OG context.

mpp’s picture

Can we do this on a base entity alter form? That way this is supported for things beside nodes?

@heddn, not sure if we want to support attaching entities other than Node to the menu?

@ducktape:
Note the array() => [] notation

+  else {
+    if ($placeholder) {

=> elseif ($placeholder) {
https://www.drupal.org/docs/develop/standards/coding-standards#controlst...

+        '#empty_option' => 'Kies een thema',

=> t('Choose a group')

mpp’s picture

Status: Needs review » Needs work

@ducktape, we should use a build callback on submit (setRebuild) to fill the #options list.

  • mpp committed aba74a7 on feature/2885625
    #2885625 Add support for menu_ui node form widget
    
mpp’s picture

Rerolling #10.

Fernly’s picture

FileSize
17.93 KB

Replaced deprecated entity.manager service by entity_type.manager.

Fernly’s picture

Changed ogmenu_instance access() check to userAccessEntity() in og_menu.module. The check always returned "forbidden".

Fernly’s picture

FileSize
18.38 KB

Updated patch for latest dev release.
Changes in src/Form/OgMenuInstanceForm.php are removed from patch because already committed.

Fernly’s picture

FileSize
18.41 KB

Fix missing menu_name array key in og_menu_get_menu_link_defaults().

Fernly’s picture

FileSize
19.17 KB

Rerolled patch for Drupal 10

DamienMcKenna’s picture

The logic here interferes with core's standard node form logic.

DamienMcKenna’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs work » Needs review
FileSize
550 bytes
19.17 KB

I'm not sure why og_menu_form_node_form_alter() includes logic to force $form['menu']['enabled']['#default_value'] to be TRUE on new nodes, so this changes it subtly.