Problem/Motivation

Looks useful to let to the user choose the bundles for what delete aliases. Currently there is only the option to delete all entities for some kind.

Issue fork pathauto-3284767

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vacho created an issue. See original summary.

vacho’s picture

StatusFileSize
new9.09 KB

This patch works for content types (nodes), is needed to extend for another entity kinds.

mably made their first commit to this issue’s fork.

mably’s picture

Status: Active » Needs review

Here's a summary of the changes made:

Files modified

1. src/Form/PathautoAdminDelete.php — Form UI + submit logic

  • Injected EntityTypeManagerInterface and Connection dependencies
  • Added per-bundle checkboxes in buildForm() for entity types with >1 bundles, with #states to show/hide based on parent checkbox or "All aliases"
  • Rewrote submitForm() to detect bundle filtering and route to the batch path when filtering is active
  • Updated batchProcess() to accept $bundles and $keep_custom parameters, passing them into $context['results']
  • Added countAliasesByBundle() helper to count aliases per bundle via a DB join
  • Added getSelectedBundles() helper to extract selected bundles from form state (returns NULL if all selected = no filtering)

2. src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php — Bundle filter in query

  • Updated batchDelete() to read bundles and keep_custom from $context['results']
  • When bundles is set, adds a WHERE bundle_key IN (...) condition to the query
  • When keep_custom is false, uses deleteMultiple() (deletes all) instead of PathautoState::bulkDelete() (respects auto/manual flag)
  • Fully backward compatible: defaults to NULL/TRUE when context values are absent

3. tests/src/Functional/PathautoMassDeleteTest.php — Test coverage

  • Added testBundleFilteredDelete(): creates 2 content types (page, article), generates aliases for both, deletes only article aliases via bundle filter, and verifies page aliases remain

Test results

  • testBundleFilteredDelete — 28 assertions passed
  • testDeleteAll (existing) — 947 assertions passed (no regression)
mably’s picture

Mandatory screenshot:

Bundle filtering

mably changed the visibility of the branch issue/pathauto-3284767-3284767-let-to-user to hidden.

mably’s picture

Here's a summary of the changes made to src/Drush/Commands/PathautoCommands.php:

  1. Added EntityTypeBundleInfoInterface dependency - imported the interface and added it as a constructor parameter for bundle validation
  2. Added bundles argument to deleteAliases() - new #[CLI\Argument] attribute and $bundles = NULL parameter. When bundles are specified (or custom aliases are kept), the batch path is used with the full batchProcess($type, $bundles, $keep_custom) signature. Added a usage example for canonical_entities:node article,page.
  3. Added validateBundles() validator - hooked to pathauto:aliases-delete, it:
    • Parses comma-separated bundles string into an array
    • Validates bundles are only used with exactly 1 alias type
    • Validates bundle names exist via getBundles()
  4. Added getBundles() helper - resolves the alias type's derivative entity type ID and returns bundle info from EntityTypeBundleInfoInterface
mably’s picture

Title: Let to user to choose bundles to delete aliases » Bulk delete path aliases for selected bundles

Global summary

Allow users to delete URL aliases for specific entity bundles rather than wiping all aliases of an entire entity type.

Problem

The "Delete aliases" form and the drush pathauto:aliases-delete command only allowed selecting entire entity types (e.g. all nodes). On sites with many content types, there was no way to delete aliases for just one bundle (e.g. only articles) without affecting other bundles (e.g. pages). This forced administrators to either delete everything or resort to manual database cleanup.

Changes

  • PathautoAdminDelete.php: Injected EntityTypeManagerInterface and Connection services. The form now renders per-bundle checkboxes (with alias counts) under each entity type that has bundles, shown/hidden via #states. On submit, when any bundle subset is selected (or custom aliases are being kept), the batch path is used with the bundle filter. Added helper methods countAliasesByBundle() and getSelectedBundles().
  • EntityAliasTypeBase.php: Injected AliasStorageHelperInterface. The batchDelete() method now reads $context['results']['bundles'] and applies an IN condition on the bundle key when set. It also respects a keep_custom flag — when FALSE, it deletes all matching aliases (including manual ones) via AliasStorageHelper::deleteMultiple() instead of PathautoState::bulkDelete().
  • PathautoCommands.php: Added an optional bundles argument to drush pathauto:aliases-delete (comma-separated, valid only with a single alias type). Includes a validateBundles() validator hook that checks the bundles exist and enforces the single-type constraint. Injected EntityTypeBundleInfoInterface for bundle discovery.
  • PathautoMassDeleteTest.php: Added testBundleFilteredDelete() — creates 5 article and 5 page nodes, deletes only article aliases via bundle checkbox, then asserts article aliases are gone while page aliases remain.
mably’s picture

Assigned: Unassigned » berdir