Fix hooks and documentation to alter source path

Created on 11 December 2020, over 4 years ago
Updated 1 February 2024, about 1 year ago

Problem/Motivation

Documentation on hook_pathauto_alias_alter() suggests that the source path can be altered for a pattern. This works when creating the initial alias, but subsequent saves of the entity create duplicate aliases because the source hasn't been changed yet when checking for an existing alias.

Steps to reproduce

Implement hook_pathauto_alias_alter(), change $context['source'], and save an entity twice. Two duplicate aliases are created.

Proposed resolution

Move "This can be altered by reference." documentation for $source to hook_pathauto_pattern_alter(), and ensure $source is passed by reference.

API changes

Both hooks change, but it wouldn't affect anything that was previously working.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain akalam

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • Merge request !69Fixes to allow source path altering β†’ (Open) created by karlshea
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    48 pass
  • Pipeline finished with Success
    about 1 year ago
    Total: 304s
    #86271
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    I don't think a new alter hook is needed, I just think there's a bug here.

    The documentation for $context['source'] on hook_pathauto_alias_alter() states "This can be altered by reference." That is true, altering there will save an alias with a different source. However, re-saves of the same entity will create multiple aliases because the source hasn't been altered when checking for an existing alias.

    Moving that documentation to hook_pathauto_pattern_alter() and passing $source by reference to that hook works through multiple saves.

Production build 0.71.5 2024