You are here

class FieldAccessCheck in FileField Sources 8

Access check for file field source routes.

NOTE: AccessInterface has no methods declared, so it might be removed in the future.

Hierarchy

Expanded class hierarchy of FieldAccessCheck

1 file declares its use of FieldAccessCheck
FieldAccessCheckTest.php in tests/src/Unit/FieldAccessCheckTest.php
1 string reference to 'FieldAccessCheck'
filefield_sources.services.yml in ./filefield_sources.services.yml
filefield_sources.services.yml
1 service uses FieldAccessCheck
access_check.filefield_sources.field in ./filefield_sources.services.yml
Drupal\filefield_sources\Access\FieldAccessCheck

File

src/Access/FieldAccessCheck.php, line 15

Namespace

Drupal\filefield_sources\Access
View source
class FieldAccessCheck implements AccessInterface {

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

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

  /**
   * Checks access.
   *
   * @param string $entity_type
   *   Entity type.
   * @param string $bundle_name
   *   Bundle name.
   * @param string $field_name
   *   Field name.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   AccessResult object
   */
  public function access(string $entity_type, string $bundle_name, string $field_name, AccountInterface $account) {
    $field = $this->entityTypeManager
      ->getStorage('field_config')
      ->load($entity_type . '.' . $bundle_name . '.' . $field_name);
    return $this->entityTypeManager
      ->getAccessControlHandler($entity_type)
      ->fieldAccess('edit', $field, $account, NULL, TRUE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldAccessCheck::$entityTypeManager protected property The entity type manager service.
FieldAccessCheck::access public function Checks access.
FieldAccessCheck::__construct public function Constructs an EntityCreateAccessCheck object.