You are here

public function DataProviderEntity::view in RESTful 7.2

Read operation.

Parameters

mixed $identifier: The ID of thing being viewed.

Return value

array An array of data for the thing being viewed.

Overrides CrudInterface::view

4 calls to DataProviderEntity::view()
DataProviderEntity::create in src/Plugin/resource/DataProvider/DataProviderEntity.php
Create operation.
DataProviderEntity::update in src/Plugin/resource/DataProvider/DataProviderEntity.php
Update operation.
DataProviderEntity::viewMultiple in src/Plugin/resource/DataProvider/DataProviderEntity.php
Read operation.
DataProviderFile::create in src/Plugin/resource/DataProvider/DataProviderFile.php
Create operation.

File

src/Plugin/resource/DataProvider/DataProviderEntity.php, line 231
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProviderEntity.

Class

DataProviderEntity
Class DataProviderEntity.

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

public function view($identifier) {
  $entity_id = $this
    ->getEntityIdByFieldId($identifier);
  if (!$this
    ->isValidEntity('view', $entity_id)) {
    throw new InaccessibleRecordException(sprintf('The current user cannot access entity "%s".', $entity_id));
  }
  $field_collection = $this
    ->initResourceFieldCollection($identifier);

  // Defer sparse fieldsets to the formatter. That way we can minimize cache
  // fragmentation because we have a unique cache record for all the sparse
  // fieldsets combinations.
  // When caching is enabled and we get a cache MISS we want to generate
  // output for the cache entry for the whole entity. That way we can use that
  // cache record independently of the sparse fieldset.
  // On the other hand, if cache is not enabled we don't want to output for
  // the whole entity, only the bits that we are going to need. For
  // performance reasons.
  $input = $this
    ->getRequest()
    ->getParsedInput();
  $limit_fields = !empty($input['fields']) ? explode(',', $input['fields']) : array();
  $field_collection
    ->setLimitFields($limit_fields);
  foreach ($this->fieldDefinitions as $resource_field) {

    // Create an empty field collection and populate it with the appropriate
    // resource fields.

    /* @var \Drupal\restful\Plugin\resource\Field\ResourceFieldEntityInterface $resource_field */
    if (!$this
      ->methodAccess($resource_field) || !$resource_field
      ->access('view', $field_collection
      ->getInterpreter())) {

      // The field does not apply to the current method or has denied access.
      continue;
    }
    $field_collection
      ->set($resource_field
      ->id(), $resource_field);
  }
  return $field_collection;
}