Aliases are incorrect on node->save() when pattern includes a taxonomy term field

Created on 19 February 2022, almost 3 years ago
Updated 10 April 2023, over 1 year ago

Problem/Motivation

I have a node content type with a pattern like this:

[node:field_ref_term:entity:field_text_url_path]/[node:field_text_url_path]

When I save a node manually, the URL alias is updated correctly.

When I import nodes with Feeds, the URL alias is updated correctly.

When I delete all aliases and use bulk regenerate to make more, the URL alias is updated correctly.

However, when I save a node programmatically like this:

      $node = Node::load($nid);
      $node->setChangedTime(\Drupal::time()->getRequestTime());
      $node->save();

Then the pathauto alias is "[node:field_ref_term:entity:field_text_url_path]-number", as there are several nodes with the same term reference, and the number is used to distinguish them.

Steps to reproduce

1. Create a content type with a taxonomy term reference.
2. Add a text field to the content type, "field_text_url_path".
3. Add a text field to the taxonomy vocabulary, "field_text_url_path".
4. Try saving a node of the content type with $node->save() as described above.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇯🇵Japan ptmkenny

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024