Deleting a field that uses a permission_callback does not delete the permission

Created on 19 June 2023, about 2 years ago

Problem/Motivation

This may be the reason for, or a contributing factor to, the issue "After uninstalling the module the Anonymous and Authenticated user roles where deleted!"

Steps to reproduce

See the README for https://github.com/TolstoyDotCom/test_delete_field

Proposed resolution

TBD. Removing the permission on admin/people/permissions does work as expected.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Field 

Last updated 9 days ago

Created by

🇺🇸United States TolstoyDotCom L.A.

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

Comments & Activities

  • Issue created by @TolstoyDotCom
  • 🇸🇪Sweden peter törnstrand

    Using the instructions from the test module. If you add field.field.node.article.field_stillthere as a config dependency in the role you at least get a warning when you delete the file.

  • 🇸🇪Sweden peter törnstrand

    I did some digging and the way this is handled for node bundles in core is that a dependencies key is added to the permissions array declaring the dependency on the node bundle like this:

    dependencies:
      config:
        - node.type.article
    

    The dependencies key is added via trait Drupal\Core\Entity\BundlePermissionHandlerTrait which in turn calls these methods:

    Drupal\Core\Entity\EntityInterface::getConfigDependencyKey() // returns 'config' for a node bundle
    Drupal\Core\Entity\EntityInterface::getConfigDependencyName() // returns 'node.type.<BUNDLE>' for a node bundle
    

    So I guess the correct way to solve this issue is to add the dependencies key to the permissions array.

    I'm attaching a patch for the Test delete field module just to make it clear what I mean.

Production build 0.71.5 2024