class QuickEditEntityFieldAccessCheck
Same name in other branches
- 9 core/modules/quickedit/src/Access/QuickEditEntityFieldAccessCheck.php \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck
Access check for in-place editing entity fields.
Hierarchy
- class \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck implements \Drupal\Core\Routing\Access\AccessInterface, \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface
Expanded class hierarchy of QuickEditEntityFieldAccessCheck
1 file declares its use of QuickEditEntityFieldAccessCheck
- QuickEditEntityFieldAccessCheckTest.php in core/
modules/ quickedit/ tests/ src/ Unit/ Access/ QuickEditEntityFieldAccessCheckTest.php
1 string reference to 'QuickEditEntityFieldAccessCheck'
- quickedit.services.yml in core/
modules/ quickedit/ quickedit.services.yml - core/modules/quickedit/quickedit.services.yml
1 service uses QuickEditEntityFieldAccessCheck
- access_check.quickedit.entity_field in core/
modules/ quickedit/ quickedit.services.yml - Drupal\quickedit\Access\QuickEditEntityFieldAccessCheck
File
-
core/
modules/ quickedit/ src/ Access/ QuickEditEntityFieldAccessCheck.php, line 13
Namespace
Drupal\quickedit\AccessView source
class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntityFieldAccessCheckInterface {
/**
* 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
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
QuickEditEntityFieldAccessCheck::access | public | function | Checks Quick Edit access to the field. | |
QuickEditEntityFieldAccessCheck::accessEditEntityField | public | function | Checks access to edit the requested field of the requested entity. | Overrides QuickEditEntityFieldAccessCheckInterface::accessEditEntityField |
QuickEditEntityFieldAccessCheck::validateRequestAttributes | protected | function | Validates request attributes. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.