You are here

public function Resource::view in RESTful 7.2

Basic implementation for view.

Parameters

string $path: The resource path.

Return value

array An array of structured data for the things being viewed.

Overrides ResourceInterface::view

2 calls to Resource::view()
AccessToken__1_0::getOrCreateToken in modules/restful_token_auth/src/Plugin/resource/AccessToken__1_0.php
Create a token for a user, and return its value.
RefreshToken__1_0::refreshToken in modules/restful_token_auth/src/Plugin/resource/RefreshToken__1_0.php
Create a token for a user, and return its value.

File

src/Plugin/resource/Resource.php, line 357
Contains \Drupal\restful\Plugin\resource\Resource.

Class

Resource

Namespace

Drupal\restful\Plugin\resource

Code

public function view($path) {

  // TODO: Compare this with 1.x logic.
  $ids = explode(static::IDS_SEPARATOR, $path);

  // REST requires a canonical URL for every resource.
  $canonical_path = $this
    ->getDataProvider()
    ->canonicalPath($path);
  restful()
    ->getResponse()
    ->getHeaders()
    ->add(HttpHeader::create('Link', $this
    ->versionedUrl($canonical_path, array(), FALSE) . '; rel="canonical"'));

  // If there is only one ID then use 'view'. Else, use 'viewMultiple'. The
  // difference between the two is that 'view' allows access denied
  // exceptions.
  if (count($ids) == 1) {
    return array(
      $this
        ->getDataProvider()
        ->view($ids[0]),
    );
  }
  else {
    return $this
      ->getDataProvider()
      ->viewMultiple($ids);
  }
}