Cannot create a custom operation for menu_link_content entities

Created on 22 February 2019, over 5 years ago
Updated 31 January 2023, over 1 year ago

Problem/Motivation

When i tried to add a custom operation for menu_link_content entities

/**
 * Implements hook_entity_operation().
 */
function entity_clone_entity_operation(EntityInterface $entity) {
  if ($entity->getEntityTypeId() === 'menu_link_content') {
    return [
      'custom_operation' => [
        'title' => t('Custom operation'),
        'weight' => 50,
        'url' => $entity->toUrl('custom-operation-form'),
      ],
    ];
  }

  return [];
}

and use this operation menu_link_content.custom_operation in a route _entity_access requirement, I got this error :

TypeError: Argument 1 passed to Drupal\Core\Access\AccessResult::orIf() must implement interface Drupal\Core\Access\AccessResultInterface, null given"

The problem is the \Drupal\menu_link_content\MenuLinkContentAccessControlHandler::checkAccess does not provide a default AccessResult return for all other permission than view, update and delete.

Proposed resolution

Add a default AccessResult::neutral() return.

πŸ› Bug report
Status

Closed: outdated

Version

10.1 ✨

Component
Menu systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡«πŸ‡·France vpeltot

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • First commit to issue fork.
  • Status changed to Closed: outdated over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain rodrigoaguilera Barcelona

    The access controller now relies on the generic EntityAccessControlHandler that returns neutral by default

Production build 0.71.5 2024