Declare type of entity variable in ::accessCheck

Created on 24 May 2024, 7 months ago
Updated 7 June 2024, 6 months ago

This is a follow up of https://git.drupalcode.org/project/email_contact/-/commit/969aa62c0ced18... that was added 2 days ago. It is breaking our instance because we are using an entity type with an encoded string ID, i.e. the ID is encoded in the URI, and then we depend on a route parameter converter in order to handle the routes with an {entity_type} parameter.

Of course, we can always workaround by overriding the ::accessCheck and decode it, but since the route is defined as

email_contact.form:
  path: 'email-contact/{entity_type}/{entity}/{field_name}/{view_mode}'
  options:
    parameters:
      entity:
        type: entity:{entity_type}
.
.

it means that it already expects an entity ID to be passed to the route.

Simply changing

  public function accessCheck($entity_type, $entity, $field_name, $view_mode, AccountInterface $account) {

to

  public function accessCheck($entity_type, EntityInterface $entity, $field_name, $view_mode, AccountInterface $account) {

allows to recognize automatically the entity and also return a 404 if it is an invalid ID.

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇬🇷Greece idimopoulos

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024