checkAccess() throws an exception "Invalid specifier 'type'" with non node entities

Created on 13 March 2023, over 1 year ago
Updated 24 July 2024, 4 months ago

Problem/Motivation

The checkAccess() method of both the roleLimit and userLimit assumes that the bundle key is always 'type' This is fine for nodes but most other entities are using 'bundle' (for example, with media entities) But this can be anything in a custom entity type.

This throws an exception when trying to create an entity that does not use 'type' as the bundle key.

This is/was also true for the owner (uid) which was addressed in #2940498: Does not work for custom entities created with drupal console but in that fix it only checks for uid or user_id after looking at the field definition. The owner key could be something other than those two as well.

Steps to reproduce

I noticed this while trying to limit media entities.
Create a limit for a media type then try to create an instance of that media type using a restricted role.

Proposed resolution

Use the getKey() method of the entity type definition for 'bundle' and 'owner' to retrieve the keys used for owner and bundle for the entity being checked

🐛 Bug report
Status

RTBC

Version

3.0

Component

Code

Created by

🇺🇸United States loze Los Angeles

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

Comments & Activities

Production build 0.71.5 2024