Problem/Motivation

views_menu_link_defaults() does not set a parent for links, so they can only be top-level in any menu.

Steps to reproduce

Apply the attached patch, which moves the Files link from a tab pointing to admin/content/files to a normal menu link pointing to admin/content. The link does not show up in the toolbar, and when you go to admin/structure/menu/manage/admin, you will see the link exists, but it's top-level instead of below Administration.

Proposed resolution

To be determined.

Remaining tasks

To be determined.

User interface changes

To be determined.

API changes

To be determined.

Comments

tim.plunkett’s picture

Issue tags: +VDC, +MenuSystemRevamp
xano’s picture

StatusFileSize
new1.02 KB

Note that this patch is a demonstration of the problem and not a fix.

tim.plunkett’s picture

If we have a bug, we have a bug. we shouldn't be changing the UI to work around it.
I don't think this is a good approach.

xano’s picture

Note that this patch is a demonstration of the problem and not a fix.

xano’s picture

Status: Active » Needs review
StatusFileSize
new5.84 KB

Status: Needs review » Needs work

The last submitted patch, 5: drupal_2202493_5.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new8.87 KB
new4.14 KB

I decided not to convert tabs, but only focus on menu links in this issue, since, as opposed to Drupal 7, these are no longer handled through the same mechanism.

Status: Needs review » Needs work

The last submitted patch, 7: drupal_2202493_7.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new9.56 KB
new1.33 KB

Status: Needs review » Needs work

The last submitted patch, 9: drupal_2202493_9.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new9.56 KB
new813 bytes

Status: Needs review » Needs work

The last submitted patch, 11: drupal_2202493_11.patch, failed testing.

dawehner’s picture

Don't we still want to implement some magic to auto-set the parent based upon the path?

tim.plunkett’s picture

Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new3.01 KB

Maybe something like this?

dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php
@@ -321,6 +333,26 @@ public function executeHookMenuLinkDefaults(array &$existing_links) {
+        if ($parent_paths) {
+          $mlids = $this->menuLinkStorage->getQuery()
+            ->condition('link_path', $parent_paths)
+            ->sort('link_path', 'DESC')
+            ->range(0, 1)
+            ->execute();
+          if ($mlids) {
+            $parent_menu_link = $this->menuLinkStorage->load(reset($mlids));
+            $links[$menu_link_id]['parent'] = $parent_menu_link->machine_name;
+          }

This will be problematic for a lot of reasons. We should use existing_links sadly, mh this is an N*M algorithm. The reason why we can't use it is that we are actually buillding menu links at the moment, which means that if at some points the menu links have to be actually rebuilt, good luck.
I will have a deeper look at this issue tomorrow.

Status: Needs review » Needs work

The last submitted patch, 14: vdc-2202493-14.patch, failed testing.

xano’s picture

@dawehner, @pwolanin, and I just had a chat about this and since the system now allows any link to be a child of any other link, we should let the user choose the parent instead of magically selecting it.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new9.17 KB

Re-roll of #11.

Status: Needs review » Needs work

The last submitted patch, 18: drupal_2202493_18.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new9.75 KB
new434 bytes
dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Page.php
@@ -216,32 +217,17 @@ public function buildOptionsForm(&$form, &$form_state) {
+            '#title' => t('Parent link'),
+            '#default_value' => $menu['menu_name'] . ':' . $menu['parent'],
+            '#options' => $options,

We kind of need to be able to select no parent.

On top of that some tests would be kinda cool.

The last submitted patch, 20: drupal_2202493_20.patch, failed testing.

xano’s picture

This is tricky, since the built-in code to build menu link selectors uses menu names and MLIDs as identifiers, because not all menu links have a machine name. The way Views exposes menu links requires them to refer to parents using machine names, though.

I guess this issue is postponed until menu links are converted to plugins.

longwave’s picture

Menu links are now plugins, this is still an issue and needs revisiting.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new4.65 KB

First attempt at a rework with menu link plugins. I could add a view display below an existing menu item and successfully edit it in either the menu UI or the Views UI in manual testing.

dawehner’s picture

Issue tags: +Needs tests

I will try to come up with some proper tests unless someone beets me until tomorrow.

  1. +++ b/core/modules/views/src/Plugin/views/display/Page.php
    @@ -51,6 +51,7 @@ protected function defineOptions() {
    +        'parent' => array('default' => 0),
    

    The default is an empty plugin ID "", not 0 anymore.

  2. +++ b/core/modules/views/src/Plugin/views/display/Page.php
    @@ -217,13 +218,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +            '#description' => t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'),
    

    We could at least use $this->t()

  3. +++ b/core/modules/views/src/Plugin/views/display/Page.php
    @@ -409,7 +412,9 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
    +        $menu = $form_state['values']['menu'];
    +        list($menu['name'], $menu['parent']) = explode(':', $menu['parent'], 2);
    +        $this->setOption('menu', $menu);
    

    Perfect!

longwave’s picture

StatusFileSize
new4.66 KB
new1.55 KB

Fixed #26.1 and #26.2.

dawehner’s picture

StatusFileSize
new7.33 KB
new2.67 KB

Here is a test.

longwave’s picture

Surely pgae is a typo (twice) in that test?

Status: Needs review » Needs work

The last submitted patch, 28: 2202493.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new7.33 KB
new1.07 KB

Rebased and fixed test.

dawehner’s picture

Issue tags: -Needs tests
StatusFileSize
new6.27 KB

Urg, I hate myself.

Status: Needs review » Needs work

The last submitted patch, 32: 2202493-views_match-32.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new6.29 KB
new1.34 KB

This should be it.

longwave’s picture

Status: Needs review » Needs work
           $form['menu']['menu_name'] = array(
             '#title' => t('Menu'),
             '#type' => 'select',
             '#options' => menu_ui_get_menus(),
             '#default_value' => $menu['menu_name'],
+          );
...
+        $menu = $form_state->getValue('menu');
+        list($menu['menu_name'], $menu['parent']) = explode(':', $menu['parent'], 2);

I think the Menu dropdown should be removed, the menu is selected via the Parent dropdown and the menu_name variable is overwritten at submit time anyway.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new6.18 KB
new1.69 KB

I think the Menu dropdown should be removed, the menu is selected via the Parent dropdown and the menu_name variable is overwritten at submit time anyway.

You are absolute right!

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Not sure I am allowed to RTBC this as I worked on part of it, but I think #36 is good to go.

dawehner’s picture

I really think that everyone in the community should be allowed to RTBC any issue, as long you are convinced that is the right thing and fixes the described problem.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ce842f8 and pushed to 8.0.x. Thanks!

  • alexpott committed ce842f8 on 8.0.x
    Issue #2202493 by Xano, dawehner, longwave, tim.plunkett: Fixed...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.