This simple Drupal 10 module provides an Action plugin that enables the Pathauto "Generate automatic URL alias" flag for node entities. It is useful when migrated content retains existing aliases and you want to re-generate aliases for selected nodes.
- Provides a bulk action "Enable automatic URL alias (Pathauto)" for use in Content bulk operations.
- Sets the Pathauto
CREATEstate on selected nodes so aliases will be regenerated. - Requires the "Administer nodes" permission to execute.
-
Place this module in
web/modules/custom/pathauto_enable_action. -
Enable the module:
drush en pathauto_enable_action -y
Or via UI: Admin > Extend > (search for "Pathauto enable action") > Enable.
-
Clear caches:
drush cache:rebuild
- Go to Admin > Content (or any content listing page).
- Select one or more nodes using the checkboxes.
- Under "Action", select "Enable automatic URL alias (Pathauto)".
- Click "Apply to selected items".
- The action sets the Pathauto flag; then use Pathauto's Bulk generate feature to regenerate aliases:
- Go to Admin > Configuration > Search and metadata > URL aliases > Bulk generate.
- Or run
drush pathauto:generate-aliases.
- The action plugin sets
$node->path->pathauto = PathautoState::CREATEon each selected node. - This tells Pathauto to regenerate the alias the next time the node is saved or via bulk operations.
- The action does not immediately regenerate aliases—it only sets the flag. Use Pathauto bulk update afterward.
pathauto_enable_action.info.yml— Module metadata.src/Plugin/Action/PathautoEnableAction.php— The Action plugin implementation.config/install/system.action.pathauto_enable_action.yml— System action configuration entity.pathauto_enable_action.permissions.yml— Custom permissions (optional).
-
Action doesn't appear in the Actions dropdown:
- Ensure the module is enabled:
drush pml --status=enabled | grep pathauto_enable_action - Clear caches:
drush cache:rebuild - Confirm you have "Administer nodes" permission.
- Ensure the module is enabled:
-
Permission denied error:
- The action requires the "Administer nodes" permission. Assign this role to your user if needed.
To run the module tests using DDEV and PHPUnit, run:
ddev exec env SIMPLETEST_DB="mysql://db:db@db/db" \ vendor/bin/phpunit -c /var/www/html/web/core/phpunit.xml.dist \ /var/www/html/web/modules/custom/pathauto_enable_action/tests