You are here

public function DataProvider::discover in RESTful 7.2

Return the discovery information for the given entity.

Parameters

string $path: The request path.

Return value

array An array of data for the thing being discovered.

Overrides DataProviderInterface::discover

File

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

Class

DataProvider

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

public function discover($path = NULL) {

  // Alter the field definition by adding a callback to get the auto
  // discover information in render time.
  foreach ($this->fieldDefinitions as $public_field_name => $resource_field) {

    /* @var ResourceFieldInterface $resource_field */
    if (method_exists($resource_field, 'autoDiscovery')) {

      // Adding the autoDiscover method to the resource field class will allow
      // you to be smarter about the auto discovery information.
      $callable = array(
        $resource_field,
        'autoDiscovery',
      );
    }
    else {

      // If the given field does not have discovery information, provide the
      // empty one instead of an error.
      $callable = array(
        '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldBase::emptyDiscoveryInfo',
        array(
          $public_field_name,
        ),
      );
    }
    $resource_field
      ->setCallback($callable);

    // Remove the process callbacks, those don't make sense during discovery.
    $resource_field
      ->setProcessCallbacks(array());
    $definition = $resource_field
      ->getDefinition();
    $discovery_info = empty($definition['discovery']) ? array() : $definition['discovery'];
    $resource_field
      ->setPublicFieldInfo(new PublicFieldInfoBase($resource_field
      ->getPublicName(), $discovery_info));
  }
  return $path ? $this
    ->viewMultiple(array(
    $path,
  )) : $this
    ->index();
}