Problem/Motivation

The crop.type_add route requires a permission explicitly.
It is a better practice to use the _entity_create_access requirement, this way access can be altered with hook_entity_create_access.

Steps to reproduce

Add this hook:

/**
 * Implements hook_entity_create_access().
 */
function test_entity_create_access() {
  return AccessResult::forbidden();
}

You can still create crop types.

Proposed resolution

Replace the _permission requirement with _entity_create_access.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 3584276-use-entity-create-access.patch407 bytesdkmishra

Issue fork crop-3584276

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

prudloff created an issue. See original summary.

dkmishra made their first commit to this issue’s fork.

dkmishra’s picture

Status: Active » Needs review
StatusFileSize
new407 bytes

Proposed fix replaces the crop.type_add route permission requirement with _entity_create_access.

<?php

/**
 * @file
 * Primary module hooks for demo module.
 */

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;

/**
 * Implements hook_entity_create_access().
 */
function demo_entity_create_access(AccountInterface $account, array $context, $entity_bundle = NULL) {
  // Check if the user is attempting to create a specific entity type
  if ($context['entity_type_id'] === 'crop_type') {
    return AccessResult::forbidden();
  }
  // Always return neutral if your condition is not met.
  return AccessResult::neutral();
}