protected function EditEntityFieldAccessCheck::validateAndUpcastRequestAttributes

Validates and upcasts request attributes.

1 call to EditEntityFieldAccessCheck::validateAndUpcastRequestAttributes()
EditEntityFieldAccessCheck::access in drupal/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php
Implements AccessCheckInterface::access().

File

drupal/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php, line 50
Contains \Drupal\edit\Access\EditEntityFieldAccessCheck.

Class

EditEntityFieldAccessCheck
Access check for editing entity fields.

Namespace

Drupal\edit\Access

Code

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();
  }
}