Problem/Motivation

Unless I'm using the module incorrectly, it does not seem to work on a Drupal 9 site I'm building. I've also tried it on a bare-bones new installation, in order to rule out other factors.

Steps to reproduce

  • Perform a standard install of Drupal 9.4 (9.4.8 in my test site)
  • Install and enable Pathauto (with dependencies) and URL Alias Permissions
  • Create a user with the Content editor user role
  • As user 1, edit the Content editor user role:
    • revoke the "Administer URL aliases" and "Create and edit URL aliases" permissions
    • grant the "Create and edit Basic page content item URL alias" permission
  • As a user with the Content editor user role, create a Basic page node. The field widget to edit the URL alias, which should be on the node edit form if the user has permission, does not appear.

Thanks in advance for any help you can offer!

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

jmcintyre created an issue. See original summary.

macdev_drupal’s picture

Good to know. We had some issues with 9.3 already. Will test with 9.4 in a couple of days.

fernly’s picture

The cause is line 182 of file /core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
The access per widget is calculated after building the widget form element.

I think the form alter won't do it anymore. Perhaps the core plugin class PathFieldItemList will need to be extended and altered.

fernly’s picture

Status: Active » Needs review
StatusFileSize
new5.81 KB

Attached a patch that rewrites the module according to comment #3. Instead of altering a form, the core PathFieldItemList class is replaced and the new access rules are implemented there. The patch also plays nice with pathauto (which does a similar alteration).

The patch should fix the problems with Drupal 9.3.x as well.

Tests were not modified.

fernly’s picture

Category: Support request » Bug report
Priority: Normal » Major

I would urge to commit this sooner than later as the module is currently fully broken. Marking the issue as major.

it-cru’s picture

I'm not using the url_alias_permissions module, but for me I found out it could work also with implementation of hook_field_widget_WIDGET_TYPE_form_alter() for path widget type. Maybe this could also be used in url_alias_permissions module to simplify it a little bit more.

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter() for path widget.
 *
 * Only SEO and Administrator users could manually edit URL aliases
 * on news_article nodes.
 */
function custom_module_field_widget_path_form_alter(&$element, FormStateInterface $form_state, $context) {
  if ($context['items']->getEntity()->bundle() == 'news_article') {
    $currentUser = \Drupal::currentUser();

    if ($currentUser->id() === 1) {
      return;
    }

    if (!array_intersect(['seo', 'administrator'], $currentUser->getRoles())) {
      $element['pathauto']['#disabled'] = TRUE;
      $element['alias']['#disabled'] = TRUE;
    }
  }
}

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

  • JeroenT committed 1f191461 on 8.x-1.x
    Issue #3313956 by Fernly: Doesn't seem to work with D9.4
    
jeroent’s picture

Status: Needs review » Fixed

In Drupal 9.4 the permission create and edit url aliases was added, which broke this module.
I moved all logic to a hook_entity_field_access() hook and this module should work again correctly.

ayush.pandey’s picture

For the module URL Alias Permissions with version: 8.x-1.4, and the issue seems to be resolved by the patch https://www.drupal.org/files/issues/2022-11-15/3313956-4.patch .
Before patch
After patch

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.