1. 8.5.x core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php EditEntityFieldAccessCheck
  2. 8.0.x core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php EditEntityFieldAccessCheck
  3. 8.1.x core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php EditEntityFieldAccessCheck
  4. 8.2.x core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php EditEntityFieldAccessCheck
  5. 8.3.x core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php EditEntityFieldAccessCheck
  6. 8.4.x core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php EditEntityFieldAccessCheck
  7. 8.6.x core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php EditEntityFieldAccessCheck

Access check for editing entity fields.

Hierarchy

Expanded class hierarchy of EditEntityFieldAccessCheck

1 file declares its use of EditEntityFieldAccessCheck
EditEntityFieldAccessCheckTest.php in core/modules/quickedit/tests/src/Unit/Access/EditEntityFieldAccessCheckTest.php
1 string reference to 'EditEntityFieldAccessCheck'
quickedit.services.yml in core/modules/quickedit/quickedit.services.yml
core/modules/quickedit/quickedit.services.yml

File

core/modules/quickedit/src/Access/EditEntityFieldAccessCheck.php, line 13

Namespace

Drupal\quickedit\Access
View source
class EditEntityFieldAccessCheck implements AccessInterface, EditEntityFieldAccessCheckInterface {

  /**
   * Checks Quick Edit access to the field.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity containing the field.
   * @param string $field_name
   *   The field name.
   * @param string $langcode
   *   The langcode.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   *
   * @todo Use the $account argument: https://www.drupal.org/node/2266809.
   */
  public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) {
    if (!$this
      ->validateRequestAttributes($entity, $field_name, $langcode)) {
      return AccessResult::forbidden();
    }
    return $this
      ->accessEditEntityField($entity, $field_name);
  }

  /**
   * {@inheritdoc}
   */
  public function accessEditEntityField(EntityInterface $entity, $field_name) {
    return $entity
      ->access('update', NULL, TRUE)
      ->andIf($entity
      ->get($field_name)
      ->access('edit', NULL, TRUE));
  }

  /**
   * Validates request attributes.
   */
  protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode) {

    // Validate the field name and language.
    if (!$field_name || !$entity
      ->hasField($field_name)) {
      return FALSE;
    }
    if (!$langcode || !$entity
      ->hasTranslation($langcode)) {
      return FALSE;
    }
    return TRUE;
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
EditEntityFieldAccessCheck::access public function Checks Quick Edit access to the field.
EditEntityFieldAccessCheck::accessEditEntityField public function Checks access to edit the requested field of the requested entity. Overrides EditEntityFieldAccessCheckInterface::accessEditEntityField
EditEntityFieldAccessCheck::validateRequestAttributes protected function Validates request attributes.