Closed (fixed)
Project:
Pathauto
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
6 Aug 2019 at 09:20 UTC
Updated:
12 Mar 2026 at 18:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jeroentComment #3
idebr commentedPathauto patterns are a little different compared to Rabbit hole behavior settings in the way that a Pathauto pattern without a node type condition is still a valid pattern, since the bundle field is optional and can have multiple values as well. This means it cannot outright be deleted when a node type is removed.
That being said, the pathauto pattern still requires updating when a dependency is removed. HEAD already merges the dependencies of its plugins, but the CTools node_type and entity_bundle plugins currently return an empty array in their
::calculateDependencies()method.That leaves us with two options for adding these configuration dependencies:
\Drupal\pathauto\Entity\PathautoPattern::calculateDependencies()Option #2 has my preference, so we don't have a do additional work in Pathauto and remove it later when the condition plugins are correctly listing their dependencies.
Attached patch provides a proof-of-concept for #2 assuming a correct implementation of ::calculateDependencies() of the node_type condition plugin. I'll try to flesh this out a bit more at a later time.
Comment #4
berdir> This means it cannot outright be deleted when a node type is removed.
That is technically true, but this is problematic. what happens if it's the last/only bundle? Does it mean the pattern is applied to no bundles or all bundles? entity reference fields in core now make a difference between NULL (all) and [] (none) for that.
An explicit test might be useful?
Comment #7
mably commentedFirst try at throwing this issue at Claude.
Here's a summary of what was implemented:
PathautoPattern::calculateDependencies()— Now adds config dependencies for bundle entities referenced in entity_bundle selection conditions (e.g., node.type.article). Uses the standardEntityType::getBundleConfigDependency()method.PathautoPattern::onDependencyRemoval()— New method that handles bundle deletion:4 kernel tests in
PathautoPatternDependencyTest:Comment #8
mably commentedMay be we could at least disable the pattern if no condition are left.
All ideas welcome.
Comment #9
berdirA pattern without conditions must be deleted or disabled, without condition it would be applied to anything. I think it would be fine to disable it, the UI should warn you that this is going to happen, doesn't seem different than other depending configuration, such the view/form displays and fields of a node type.
Comment #10
mably commentedPattern is now disabled and a warning message displayed to the user.
Comment #11
mably commentedGlobal summary
Pathauto patterns were not cleaned up when their corresponding content type (or other bundle entity) was deleted, leaving orphaned configuration in the system.
Problem
Pathauto patterns did not declare configuration dependencies on the bundles they reference in their selection conditions. This meant Drupal's configuration dependency system had no way to notify the pattern when a bundle was removed. Deleting a content type like "article" left its Pathauto pattern intact — and worse, the pattern silently became a catch-all applying to all nodes, since it no longer had any bundle condition to restrict it.
Fix
entity_bundle:*andnode_typecondition plugins, retrieves each referenced bundle's config dependency (e.g.node.type.article), and registers it. This hooks the pattern into Drupal's dependency tracking system.Test coverage
testCalculateDependenciesIncludesBundles()— verifiesnode.type.articleandnode.type.pageappear in the pattern's config dependencies.testRemoveSingleBundleFromMultiple()— deletes article from a two-bundle pattern, asserts only page remains in the condition and dependencies are updated.testRemoveLastBundleRemovesCondition()— deletes the only bundle, asserts the condition is removed entirely.testPatternNotDeletedOnBundleRemoval()— asserts the pattern still exists but is disabled after losing all bundle conditions.Comment #12
berdirReviewed.
Comment #14
mably commentedThanks a lot @berdir for the review.
Implemented all your suggestions.
Created a new MR 163 to enable Tugboat and facilitate testing.
Added the newly created "Entity condition dependencies" core issue #3573747 to the list of related issue.
Review fixes
Addresses @berdir's review comments on MR !128:
PathautoPattern.php — calculateDependencies():
node_typecondition check — this plugin was removed in Drupal 10.getSelectionConditions()loop instead of iterating twice. Added a@todonoting that condition plugins should implementcalculateDependencies()themselves (filed as #3573747).PathautoPattern.php — onDependencyRemoval():
node_typecondition check (same reason).messenger()->addWarning()call that informed the user the pattern had been disabled. The delete confirmation form shows the pattern under "Configuration updates" before deletion, but this only indicates the pattern will be modified — not that it will be disabled. This is a trade-off: cleaner UX (no extra status message) at the cost of less explicit feedback. The user can still see the pattern is disabled on the patterns list page afterwards.New test — PathautoPatternDependencyWebTest:
testDeleteBundleShowsPatternAsAffected()that creates a pattern with an article bundle condition, visits the article content type delete form, and asserts the pattern appears under "Configuration updates".Comment #16
anybodyNice @mably LGTM! Thanks for pushing all these important thins forward here that much!
Comment #17
berdirOne minor note on the test. I'll leave it to you if you want to address that, then fine to merge.
FWIW, I still think it would be OK to delete this, but if you prefer disabling, that's fine with me. core has various issues on views being deleted being a pain for users, but this isn't really a view that takes you possibly a long time to re-create and the dependency chain is pretty clear.
Comment #19
mably commented