You are here

protected function ResourceFieldEntity::propertyWrapper in RESTful 7.2

Get the wrapper for the property associated to the current field.

Parameters

DataInterpreterInterface $interpreter: The data source.

Return value

\EntityMetadataWrapper Either a \EntityStructureWrapper or a \EntityListWrapper.

Throws

ServerConfigurationException

3 calls to ResourceFieldEntity::propertyWrapper()
ResourceFieldEntity::access in src/Plugin/resource/Field/ResourceFieldEntity.php
ResourceFieldEntity::value in src/Plugin/resource/Field/ResourceFieldEntity.php
Gets the value for the field given a data source.
ResourceFieldEntityReference::value in src/Plugin/resource/Field/ResourceFieldEntityReference.php
Gets the value for the field given a data source.

File

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

Class

ResourceFieldEntity
Class ResourceFieldEntity.

Namespace

Drupal\restful\Plugin\resource\Field

Code

protected function propertyWrapper(DataInterpreterInterface $interpreter) {

  // This is the first method that gets called for all fields after loading
  // the entity. We'll use that opportunity to set the actual bundle of the
  // field.
  $this
    ->setBundle($interpreter
    ->getWrapper()
    ->getBundle());

  // Exposing an entity field.
  $wrapper = $interpreter
    ->getWrapper();

  // For entity fields the DataInterpreter needs to contain an EMW.
  if (!$wrapper instanceof \EntityDrupalWrapper) {
    throw new ServerConfigurationException('Cannot get a value without an entity metadata wrapper data source.');
  }
  $property = $this
    ->getProperty();
  try {
    return $property && !$this
      ->isWrapperMethodOnEntity() ? $wrapper->{$property} : $wrapper;
  } catch (\EntityMetadataWrapperException $e) {
    throw new UnprocessableEntityException(sprintf('The property %s could not be found in %s:%s.', $property, $wrapper
      ->type(), $wrapper
      ->getBundle()));
  }
}