Permissions should be defined in a permission callback

Created on 6 September 2023, 10 months ago
Updated 2 October 2023, 9 months ago

Problem/Motivation

When using the Upgrade Status module to prepare for Drupal 10, it shows the following error message:

Invalid permissions will trigger runtime exceptions in Drupal 10. β†’ Permissions should be defined in a permissions.yml file or a permission callback.

All the shown permissions giving the error for me are the view any @type content and view own @type content permissions provided by this module.

The permissions are saved dynamically in the permissions form submit content_access_user_admin_perm_submit, but this isn't a way that is supported by Drupal. See PermissionHandler:

If your module needs to define dynamic permissions you can use the permission_callbacks key to declare a callable that will return an array of permissions, keyed by machine name. Each item in the array can contain the same keys as an entry in $module.permissions.yml.

Steps to reproduce

Make sure your website is running the most recent stable version of Drupal 9 (currently 9.5.11).

Install Upgrade Status and view the report.

Proposed resolution

Add permissions dynamically using the permissions callback. The example given by the Drupal documentation is FilterPermissions::permissions.

πŸ“Œ Task
Status

Closed: cannot reproduce

Version

2.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @solideogloria
  • First commit to issue fork.
  • Gaurav Gupta Jaipur, Rajasthsan

    Hi solideogloria i have installed d10 and installed upgrade status along with content_access module and i cant seem to find the problem you specified above
    It does show another error in a file which is not present in the module
    I dont know why?

  • πŸ‡³πŸ‡΄Norway gisle Norway

    Gaurav Gupta,
    your screenshot is not relevant here.

    The Upgrade Status module will check for compatibility with the next major version of Drupal. If you run it after having installed Drupal 10, it will check for compatibility with Drupal 11.

    The situation in the issue summary can be reproduced if you check this on a site running Drupal 9.5.11.

  • πŸ‡³πŸ‡΄Norway gisle Norway
  • πŸ‡³πŸ‡΄Norway gisle Norway
  • πŸ‡³πŸ‡΄Norway gisle Norway

    Remove

  • Status changed to Closed: cannot reproduce 9 months ago
  • πŸ‡³πŸ‡΄Norway gisle Norway

    When checking upgrade status for an legacy website that was initially installed with some Drupal version before version 9.3, then upgraded to 9.5.11, before running Upgrade Status, I was able to reproduce the issue.

    However, when testing this on a clean install of Drupal 9.5.11, with Content Access 2.0.0, I got no report about invalid permissions that will trigger runtime exceptions in Drupal 10 (and Content Access is flagged as ready for an upgrade to Drupal 10).

    So it looks like these invalid permissions are junk left in the database for some time, and that if they're blocking for an upgrade to Drupal 10, you should be able to clean things up by removing them from the database manually, as discussed here: ✨ Invalid permissions message should mention Drupal 9.3 update hook Active

Production build 0.69.0 2024