You are here

protected function DataProviderEntity::getFieldsInfoFromPublicName in RESTful 7.2

Transform the nested public name into an array of Drupal field information.

Parameters

string $name: The dot separated public name.

Return value

array An array of fields with name and type.

Throws

ServerConfigurationException When the required resource information is not available.

BadRequestException When the nested field is invalid.

1 call to DataProviderEntity::getFieldsInfoFromPublicName()
DataProviderEntity::addNestedFilter in src/Plugin/resource/DataProvider/DataProviderEntity.php
Add relational filters to EFQ.

File

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

Class

DataProviderEntity
Class DataProviderEntity.

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

protected function getFieldsInfoFromPublicName($name) {
  $public_field_names = explode('.', $name);
  $last_public_field_name = array_pop($public_field_names);
  $fields = array();

  // The first field is in the current resource, but not the other ones.
  $definitions = $this->fieldDefinitions;
  foreach ($public_field_names as $index => $public_field_name) {

    /* @var ResourceFieldEntity $resource_field */
    $resource_field = $definitions
      ->get($public_field_name);

    // Get the resource for the field, so we can get information for the next
    // iteration.
    if (!$resource_field || !($resource = $resource_field
      ->getResource())) {
      throw new ServerConfigurationException(sprintf('The nested field %s cannot be accessed because %s has no resource associated to it.', $name, $public_field_name));
    }
    list($item, $definitions) = $this
      ->getFieldsFromPublicNameItem($resource_field);
    $fields[] = $item;
  }
  if (!($resource_field = $definitions
    ->get($last_public_field_name))) {
    throw new BadRequestException(sprintf('Invalid nested field provided %s', $last_public_field_name));
  }
  $property = $resource_field
    ->getProperty();
  $item = array(
    'name' => $property,
    'type' => ResourceFieldEntity::propertyIsField($property) ? RelationalFilterInterface::TYPE_FIELD : RelationalFilterInterface::TYPE_PROPERTY,
    'entity_type' => NULL,
    'bundles' => array(),
    'target_column' => NULL,
  );
  $item['column'] = $item['type'] == RelationalFilterInterface::TYPE_FIELD ? $resource_field
    ->getColumn() : NULL;
  $fields[] = $item;
  return $fields;
}