Entities using alias patterns with tokens of referenced entities are not updated.

Created on 26 April 2024, 12 months ago
Updated 1 August 2024, 9 months ago

Problem/Motivation

When a pattern is configured using tokens related to entity reference fields or menu's, the alias is not updated if the referenced entity or menu is updated.

Steps to reproduce

Create a vocabulary (tags).
Create a content type (article) with a (taxonomy) entity reference field (example: field_tags).
Create a pathauto patterns for the content type using the reference field:
/articles/[node:field_tags:entity:parents]/[node:field_tags:entity:name]/[node:title]

Create a couple of tags terms "Term A", "Term B" at the vocabulary root.
Create some content "Some article" and assign it to 'Term B', it will get the url:
/articles/term-b/some-article

Now edit the term hierarchy and drag "Term B" under "Term A":

Term A
+- Term B

The url of "Some article" is not updated.

We expect "Some article" to have this url:
/articles/term-a/term-b/some-article

Proposed resolution

Check if there are pathauto patterns using field references to the entity whose alias is being updated and update those entities where the pattern can be applied too.

Remaining tasks

Provide a fix in PathautoGenerator::updateEntityAlias

User interface changes

none

API changes

none

Data model changes

none

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇧🇪Belgium kriboogh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kriboogh
  • Merge request !76Issue #3443665: Update related entities. → (Open) created by kriboogh
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 12 months ago
    8 pass, 20 fail
  • Pipeline finished with Failed
    12 months ago
    Total: 251s
    #157471
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 12 months ago
    46 pass, 2 fail
  • Status changed to Needs review 12 months ago
  • 🇧🇪Belgium kriboogh

    This seems to be working for us. So if someone can review, maybe add some more tests?

  • Pipeline finished with Failed
    12 months ago
    #157479
  • 🇧🇪Belgium kriboogh

    Just discovered that this patch actually needs the core patch mentioned in https://www.drupal.org/project/drupal/issues/2727667
    This core patch solves the problem that when a batch is set in a submit handler for a form entity, the subsequent calls to entity save are not callable.

  • Status changed to Needs work 9 months ago
  • 🇨🇭Switzerland berdir Switzerland

    Nice work on this, left a few comments. I have some serious concerns about performance here.

    I maintain and help maintain sites with 100'000+ nodes (multiple times that, actually). imagine a term getting renamed that has 10'000 nodes referencing it. that will not end well, to put it nicely.

    This is a hard problem to solve.

    It also relies on batch and assumes all changes happen through the user interface.

    An alternative might be to switch to queue based processing, that would take longer to process for cases with only a few references. So maybe a mix, if you detect more than lets say 10 references then push it to queue or something.

    One option would be to publish and maintain this as as a separate project. While right now everything is add within the existing methods, there isn't really a need for that, this logic can live anywhere, it can just listen to entity saves on its own and call out to Pathauto. That would allow to document those limitations and people that are OK with that can install and try out the module, it could also be an alpha/beta release or whatever. As maintainer of Paragraphs with many, many installations, I need to be a lot more careful.

Production build 0.71.5 2024