It'd be really awesome to have an action available that could set the "Generate automatic URL alias" option to either checked or unchecked.

Issue fork pathauto-3068140

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

DamienMcKenna created an issue. See original summary.

jasonawant’s picture

Hi @DamienMcKenna!

Is this feature request related to #2870514: Disable the "Generate automatic URL alias" checkbox for entities with existing paths? As a solution to that ux issue?

mably’s picture

As asked in related issue #3394538, it could be great to be able to filter updates by content type.

mably’s picture

Adding a related issue about bulk deletion filtered by bundles.

Probably some generic solution to be defined for all bulk processes.

mably’s picture

Status: Active » Needs review

Here's a summary of what was implemented:

New files:

  • src/Form/PathautoBulkToggleStateForm.php — Admin form at /admin/config/search/path/toggle_state with:
    • Target state radios (CREATE / SKIP)
    • Entity type checkboxes with per-bundle filtering (visible when >1 bundle)
    • Safety checkbox to skip entities with no pathauto state but existing aliases (visible only when target = CREATE
    • Batch processing (100 entities per iteration) using cursor pagination and key-value store bulk read/write
    • tests/src/Functional/PathautoBulkToggleStateTest.php — 4 test methods covering toggle to SKIP, toggle to CREATE, bundle filtering, and safety skip logic

Modified files:

  • pathauto.routing.yml — Added pathauto.bulk.toggle_state route with administer pathauto+bulk toggle pathauto state permission
  • pathauto.links.task.yml — Added tab at weight 35 (between "Bulk generate" at 30 and "Delete aliases" at 40)
  • pathauto.permissions.yml — Added bulk toggle pathauto state permission

Test results:
All 4 new tests pass (52 assertions), and the 2 existing PathautoBulkUpdateTest tests pass with no regressions.

mably’s picture

I'm wondering if we shouldn't add an option to allow complete removal of state from the key-value store...

Will try to add that.

mably’s picture

Here's a summary of the latest changes:

PathautoBulkToggleStateForm.php

  • Added const REMOVE = -1 sentinel value (never persisted, only used as form/batch marker)
  • Added third radio option: "Remove (reset to default)" with description explaining behavior
  • batchStart() now initializes a removed counter
  • batchProcess() handles REMOVE by deleting key-value entries (skipping entities that already have no state)
  • batchFinished() shows "Removed pathauto state for N entities" message, and the "No pathauto states were changed" fallback only shows when both updated and removed are zero

PathautoBulkToggleStateTest.php

  • Added testRemoveState() — sets 2 nodes to SKIP, bulk removes, asserts entries are NULL and message shown
  • Added testRemoveStateSkipsNoState() — verifies entities with no stored state are skipped (only 1 of 2 removed)
mably’s picture

Assigned: Unassigned » berdir
mably’s picture

Could be interesting to add 3 new individual state actions (enable, disable, remove) that could be used with VBO.

Will see what I can do based on what has been done here: #3204586: "Update URL Alias" action is only available for nodes + users and does not work with views_bulk_operations

mably’s picture

VBO-compatible actions to toggle pathauto state on individual entities

This patch adds three bulk actions for toggling the pathauto state on individually selected entities (via Views Bulk Operations or core's bulk form on /admin/content):

  • Set pathauto to automatic — sets the state to CREATE
  • Set pathauto to manual — sets the state to SKIP
  • Remove pathauto state — deletes the stored state so pathauto re-evaluates dynamically

Architecture

Follows the same pattern as core's PublishAction / UnpublishAction / EntityPublishedActionDeriver:

  • A deriver (EntityPathautoActionDeriver) extends core's EntityActionDeriverBase and generates one derivative per path-enabled entity type (node, user, taxonomy_term). Uses the same detection logic as EntityAliasTypeDeriver — canonical link template + FieldableEntityInterface + path base field.
  • A base action class (PathautoStateActionBase) extends ActionBase and provides shared logic: KV store access, access check via bulk toggle pathauto state permission, and calculateDependencies().
  • Three simple action classes extend the base, each with its own #[Action] attribute and execute() method.

No VBO dependency — uses only core's ActionBase and ContainerFactoryPluginInterface. VBO discovers them automatically.

Files added

  • src/Plugin/Action/PathautoStateActionBase.php — shared base class
  • src/Plugin/Action/PathautoStateCreateAction.php — set to CREATE
  • src/Plugin/Action/PathautoStateSkipAction.php — set to SKIP
  • src/Plugin/Action/PathautoStateRemoveAction.php — remove stored state
  • src/Plugin/Derivative/EntityPathautoActionDeriver.php — deriver for path-enabled entity types
  • config/optional/system.action.pathauto_state_create_node.yml (+ user, taxonomy_term)
  • config/optional/system.action.pathauto_state_skip_node.yml (+ user, taxonomy_term)
  • config/optional/system.action.pathauto_state_remove_node.yml (+ user, taxonomy_term)
  • tests/src/Kernel/PathautoStateActionTest.php — 8 kernel tests

Files modified

  • config/schema/pathauto.schema.yml — added schema for the three action plugin IDs

Test coverage

Kernel test covers: deriver discovery (present for node, absent for non-path types), skip action, create action (including with existing alias), remove action (with/without existing state), idempotency, and access permission check.

Existing PathautoBulkToggleStateTest (6 tests, 74 assertions) continues to pass.

mably changed the visibility of the branch 3068140-add-action-to to hidden.

mably’s picture

Mandatory screenshot (Tugboat):

VBO Pathauto actions

mably’s picture

I'll work on the above issue once this one has been merged.

Most code can be reused there.

anybody’s picture

Great work @mably! Code LGTM, I'm just not totally sure about the wording of the actions, but I think this is very close to RTBC. Let's see what @berdir says. #3204586: "Update URL Alias" action is only available for nodes + users and does not work with views_bulk_operations is definitely important as a closely related follow-up that should get fixed afterwards soon. :)