"Update URL alias of an entity" causes error because its not getting account info?

Created on 21 December 2023, 6 months ago
Updated 26 December 2023, 6 months ago

I'm trying to use the Pathauto action "Update URL alias of an entity" on a node starting from "After a new entity got saved (persistently created)." though I also tried starting from presave. Regardless I get this error when I try to create a new node:

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\Core\Access\AccessResult::allowedIfHasPermission(): Argument #1 ($account) must be of type Drupal\Core\Session\AccountInterface, null given, called in /var/www/MYSITE/web/modules/contrib/pathauto/src/Plugin/Action/UpdateAction.php on line 32 in Drupal\Core\Access\AccessResult::allowedIfHasPermission() (line 114 of core/lib/Drupal/Core/Access/AccessResult.php).

Is there something I need to set so that its passing the user account?

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States fallenturtle

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

Comments & Activities

  • Issue created by @fallenturtle
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This looks like an issue in the pathauto module, so I'm moving that issue over.

    The method \Drupal\pathauto\Plugin\Action\UpdateAction::access looks like this:

      public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
        $result = AccessResult::allowedIfHasPermission($account, 'create url aliases');
        return $return_as_object ? $result : $result->isAllowed();
      }
    

    So, that allows $account to be NULL and it uses that to call AccessResult::allowedIfHasPermission which doesn't accept NULL for the account. So, before calling that method, the pathauto plugin needs to verify if account is NULL, and if so, load the current user.

  • 🇮🇳India Prashant.c Dharamshala

    @fallenturtle
    It seems the steps to reproduce are from the ECA module, Could you please add the steps to reproduce with Pathauto module only that would be helpful.

    @jurgenhaas

      public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
        $result = AccessResult::allowedIfHasPermission($account, 'create url aliases');
        return $return_as_object ? $result : $result->isAllowed();
      }
    

    In the following code snippet I do not see any check for when $account is NULL because the function allowedIfHasPermission has this argument as required https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Access%21...

    Thanks

Production build 0.69.0 2024