Access check for editing entity fields.
Expanded class hierarchy of EditEntityFieldAccessCheck
class EditEntityFieldAccessCheck implements AccessCheckInterface, EditEntityFieldAccessCheckInterface {
/**
* Implements AccessCheckInterface::applies().
*/
public function applies(Route $route) {
return array_key_exists('_access_edit_entity_field', $route
->getRequirements());
}
/**
* Implements AccessCheckInterface::access().
*/
public function access(Route $route, Request $request) {
// @todo Request argument validation and object loading should happen
// elsewhere in the request processing pipeline:
// http://drupal.org/node/1798214.
$this
->validateAndUpcastRequestAttributes($request);
return $this
->accessEditEntityField($request->attributes
->get('entity'), $request->attributes
->get('field_name'));
}
/**
* Implements EntityFieldAccessCheckInterface::accessEditEntityField().
*/
public function accessEditEntityField(EntityInterface $entity, $field_name) {
return $entity
->access('update') && field_access('edit', $field_name, $entity
->entityType(), $entity);
}
/**
* Validates and upcasts request attributes.
*/
protected function validateAndUpcastRequestAttributes(Request $request) {
// Load the entity.
if (!is_object($entity = $request->attributes
->get('entity'))) {
$entity_id = $entity;
$entity_type = $request->attributes
->get('entity_type');
if (!$entity_type || !entity_get_info($entity_type)) {
throw new NotFoundHttpException();
}
$entity = entity_load($entity_type, $entity_id);
if (!$entity) {
throw new NotFoundHttpException();
}
$request->attributes
->set('entity', $entity);
}
// Validate the field name and language.
$field_name = $request->attributes
->get('field_name');
if (!$field_name || !field_info_instance($entity
->entityType(), $field_name, $entity
->bundle())) {
throw new NotFoundHttpException();
}
$langcode = $request->attributes
->get('langcode');
if (!$langcode || field_valid_language($langcode) !== $langcode) {
throw new NotFoundHttpException();
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessCheckInterface:: |
constant | Grant access. | ||
AccessCheckInterface:: |
constant | Deny access. | ||
AccessCheckInterface:: |
constant | Block access. | ||
EditEntityFieldAccessCheck:: |
public | function |
Implements AccessCheckInterface::access(). Overrides AccessCheckInterface:: |
|
EditEntityFieldAccessCheck:: |
public | function |
Implements EntityFieldAccessCheckInterface::accessEditEntityField(). Overrides EditEntityFieldAccessCheckInterface:: |
|
EditEntityFieldAccessCheck:: |
public | function |
Implements AccessCheckInterface::applies(). Overrides AccessCheckInterface:: |
|
EditEntityFieldAccessCheck:: |
protected | function | Validates and upcasts request attributes. |