Problem/Motivation

When using a user-path: URI for a menu link, we want to respond to changes to aliases and update the plugin definition if a formerly unrouted path matches a routed alias.

Proposed resolution

Respond to the hook

Remaining tasks

User interface changes

API changes

Comments

pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new3.09 KB

Waiting for: https://www.drupal.org/node/2417877 but rolling that patch in together for now.

Status: Needs review » Needs work

The last submitted patch, 1: 2417837-1.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB
new805 bytes
pwolanin’s picture

Issue tags: +Needs tests
dawehner’s picture

+++ b/core/modules/menu_link_content/menu_link_content.module
@@ -36,3 +36,30 @@ function menu_link_content_menu_delete(MenuInterface $menu) {
+  }
+}
\ No newline at end of file

Looks reasonsable.

pwolanin’s picture

Needs to handle alias deletion and add tests, at least.

pwolanin’s picture

Priority: Normal » Critical

Marking critical, since it's going to be a regression in behavior otherwise.

kgoel’s picture

Working on this issue.

effulgentsia’s picture

if a formerly unrouted path matches a routed alias

Per #2417793-46: Allow entity: URIs to be entered in link fields, the update also needs to happen the other way: a formerly matched alias changing to an unrouted path.

webchick’s picture

Well. Other than it was kind of awesome that my link didn't break. ;D

kgoel’s picture

StatusFileSize
new1.85 KB
new1.9 KB

Status: Needs review » Needs work

The last submitted patch, 11: 2417837-11.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.85 KB
new1009 bytes

needed to rename other function calls.

dawehner’s picture

Working on some tests now.

dawehner’s picture

pwolanin’s picture

@webchick - it only didn't break until someone triggered a menu rebuild (menu link discovery), so this avoids a greater WTF of having it still work for while and then break.

dawehner’s picture

StatusFileSize
new5.95 KB
new5.59 KB

"It worked, until we tested it" :P

pwolanin’s picture

Looks like painful, but good, progress. Some small feedback:

  1. +++ b/core/modules/menu_link_content/menu_link_content.install
    @@ -0,0 +1,15 @@
    +  // system_path_uodate().
    

    typo in function name

  2. +++ b/core/modules/menu_link_content/menu_link_content.module
    @@ -36,3 +36,54 @@ function menu_link_content_menu_delete(MenuInterface $menu) {
    +  /* @var $entities  \Drupal\menu_link_content\MenuLinkContentInterface[] */
    

    needs to be reformatted

  3. +++ b/core/modules/menu_link_content/menu_link_content.module
    @@ -36,3 +36,54 @@ function menu_link_content_menu_delete(MenuInterface $menu) {
    +  if ($path['source'] != $path['original']['source']) {
    +    _menu_link_content_update_path_alias($path['alias']);
    +    _menu_link_content_update_path_alias($path['source']);
    +    _menu_link_content_update_path_alias($path['original']['source']);
    

    Should this be elseif() ?

    Do we need to run the helper on the source and original source also?

  4. +++ b/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
    @@ -0,0 +1,89 @@
    +    module_set_weight('menu_link_content', 1);
    

    Maybe a todo on whether we could remove this hack if we cache the UrlGenerator and stop caching path aliases?

pwolanin’s picture

Issue tags: -Needs tests
StatusFileSize
new6.08 KB
new4.44 KB
+++ b/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
@@ -0,0 +1,89 @@
+      'link' => ['uri' => 'user-path:destination'],

this path is sort of confusing (at least when I'm also looking at the issue about the destination query string). Fixing that too.

larowlan’s picture

  1. +++ b/core/modules/menu_link_content/menu_link_content.module
    @@ -36,3 +36,54 @@ function menu_link_content_menu_delete(MenuInterface $menu) {
    +    ->loadByProperties(['link__uri' => 'user-path:' . $path]);
    

    I think we need an index on that column too.

  2. +++ b/core/modules/menu_link_content/menu_link_content.module
    @@ -36,3 +36,54 @@ function menu_link_content_menu_delete(MenuInterface $menu) {
    +  //
    

    Empty comment?

larowlan’s picture

larowlan’s picture

If we know that user-path: and entity: are given prefixes, even a key on the first dozen characters would help

pwolanin’s picture

StatusFileSize
new6.6 KB
new1.14 KB

considering a pathauto-like URI like: user-path:content/about-us

The more variable part is only after 18 characters, so a 25 or 30 char index seems more reasonable.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, assuming bot agrees - I think this is ready too

larowlan’s picture

manual testing

larowlan’s picture

Adding a node with alias to my-blog

And another alias for same node

Showing alias

Updating alias to point to node

Cleared cache
Verifying link still works (note the active state of the link)

manual tests fine√

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Manual testing results look great. Code does as well. Nice catch on the index length.

Committed and pushed to 8.0.x. Thanks!

  • webchick committed 0079723 on 8.0.x
    Issue #2417837 by pwolanin, larowlan, dawehner, kgoel: Update menu link...

Status: Fixed » Closed (fixed)

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