You are here

public function ResourceFieldEntity::compoundDocumentId in RESTful 7.2

Fetches the embedded identifier(s) for the current resource field, if any.

Parameters

DataInterpreterInterface $interpreter: The data interpreter to get the compound ID.

Return value

string|string[] An identifier or an array of identifiers for cardinality > 1. NULL if there is no identifier to be found.

Overrides ResourceFieldInterface::compoundDocumentId

File

src/Plugin/resource/Field/ResourceFieldEntity.php, line 213
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntity

Class

ResourceFieldEntity
Class ResourceFieldEntity.

Namespace

Drupal\restful\Plugin\resource\Field

Code

public function compoundDocumentId(DataInterpreterInterface $interpreter) {
  $collections = $this
    ->render($interpreter);

  // Extract the document ID from the field resource collection.
  $process = function ($collection) {
    if (!$collection instanceof ResourceFieldCollectionInterface) {
      return $collection;
    }
    $id_field = $collection
      ->getIdField();
    return $id_field
      ->render($collection
      ->getInterpreter());
  };

  // If cardinality is 1, then we don't have an array.
  return $this
    ->getCardinality() == 1 ? $process($collections) : array_map($process, array_filter($collections));
}