You are here

class HomeboxAddAccessCheck in Homebox 8

Determines access to for reference add pages.

Hierarchy

Expanded class hierarchy of HomeboxAddAccessCheck

1 string reference to 'HomeboxAddAccessCheck'
homebox.services.yml in ./homebox.services.yml
homebox.services.yml
1 service uses HomeboxAddAccessCheck
access_check.homebox_layout.add in ./homebox.services.yml
Drupal\homebox\Access\HomeboxAddAccessCheck

File

src/Access/HomeboxAddAccessCheck.php, line 16

Namespace

Drupal\homebox\Access
View source
class HomeboxAddAccessCheck implements AccessInterface {

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

  /**
   * Constructs a EntityCreateAccessCheck object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityManager = $entity_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\homebox\Entity\HomeboxInterface $homebox
   *   (optional) The homebox.
   *
   * @return string
   *   A \Drupal\Core\Access\AccessInterface constant value.
   */
  public function access(AccountInterface $account, HomeboxInterface $homebox = NULL) {
    $access_control_handler = $this->entityManager
      ->getAccessControlHandler('homebox_layout');

    // If checking whether a reference of a particular type may be created.
    if ($account
      ->hasPermission('administer homebox_layout')) {
      return AccessResult::allowed()
        ->cachePerPermissions();
    }
    if ($homebox) {
      return $access_control_handler
        ->createAccess($homebox
        ->id(), $account, [], TRUE);
    }

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

}

Members

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