You are here

class ReferenceAddAccessCheck in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/Access/ReferenceAddAccessCheck.php \Drupal\bibcite_entity\Access\ReferenceAddAccessCheck

Determines access to for reference add pages.

Hierarchy

Expanded class hierarchy of ReferenceAddAccessCheck

1 string reference to 'ReferenceAddAccessCheck'
bibcite_entity.services.yml in modules/bibcite_entity/bibcite_entity.services.yml
modules/bibcite_entity/bibcite_entity.services.yml
1 service uses ReferenceAddAccessCheck
access_check.bibcite_reference.add in modules/bibcite_entity/bibcite_entity.services.yml
Drupal\bibcite_entity\Access\ReferenceAddAccessCheck

File

modules/bibcite_entity/src/Access/ReferenceAddAccessCheck.php, line 16

Namespace

Drupal\bibcite_entity\Access
View source
class ReferenceAddAccessCheck implements AccessInterface {

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a EntityCreateAccessCheck object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * Checks access to the reference add page for the reference type.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   * @param \Drupal\bibcite_entity\Entity\ReferenceTypeInterface $bibcite_reference_type
   *   (optional) The reference type.
   *
   * @return string
   *   A \Drupal\Core\Access\AccessInterface constant value.
   */
  public function access(AccountInterface $account, ReferenceTypeInterface $bibcite_reference_type = NULL) {
    $access_control_handler = $this->entityTypeManager
      ->getAccessControlHandler('bibcite_reference');

    // If checking whether a reference of a particular type may be created.
    if ($bibcite_reference_type) {
      return $access_control_handler
        ->createAccess($bibcite_reference_type
        ->id(), $account, [], TRUE);
    }

    // No opinion.
    return AccessResult::neutral();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReferenceAddAccessCheck::$entityTypeManager protected property The entity manager.
ReferenceAddAccessCheck::access public function Checks access to the reference add page for the reference type.
ReferenceAddAccessCheck::__construct public function Constructs a EntityCreateAccessCheck object.