Aliases not updated after saving entity in PHP

Created on 17 May 2023, about 1 year ago
Updated 16 February 2024, 4 months ago

Problem/Motivation

When you call "save()" function on an entity, Micro Path path is not updated.

Steps to reproduce

Enable Pathauto and Micro Path modules.
Create Basic Page node named "About".
Make a function where you load the node of "About" page to "$node".
Change the title of said node with "$node->setTitle('something new')".
Save node with "$node->save()".
Run the above code.
Check that the Micro Path path did not change.

Proposed resolution

When an entity is saved, check if it has a Pathauto pattern and if so, update the Micro Path path.

🐛 Bug report
Status

Active

Component

Code

Created by

🇸🇮Slovenia agile-mark-l

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

Comments & Activities

  • Issue created by @agile-mark-l
  • @agile-mark-l opened merge request.
  • Status changed to Needs review about 1 year ago
  • Status changed to Active 4 months ago
  • 🇫🇷France flocondetoile Lyon

    Hi, implementing this hook means the alias is saved / updated twice if the entity is saved from its form. The first time by the widget element, and the second time by this hook.

    What prevent you to run
    Drupal::service('micro_path.pathauto_generator')->updateEntitySiteAlias($entity, $site_id, 'update');
    just after programmatically call your node->save() ?

Production build 0.69.0 2024