You are here

public function ResourceFieldEntity::value in RESTful 7.2

Gets the value for the field given a data source.

Parameters

DataInterpreterInterface $interpreter: The data source object. Interacts with the data storage.

Return value

mixed The value for the public field.

Throws

IncompatibleFieldDefinitionException

Overrides ResourceFieldInterface::value

2 calls to ResourceFieldEntity::value()
ResourceFieldEntity::render in src/Plugin/resource/Field/ResourceFieldEntity.php
Gets the value of a field and applies all process callbacks to it.
ResourceFieldEntityReference::value in src/Plugin/resource/Field/ResourceFieldEntityReference.php
Gets the value for the field given a data source.
1 method overrides ResourceFieldEntity::value()
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 184
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntity

Class

ResourceFieldEntity
Class ResourceFieldEntity.

Namespace

Drupal\restful\Plugin\resource\Field

Code

public function value(DataInterpreterInterface $interpreter) {
  $value = $this->decorated
    ->value($interpreter);
  if (isset($value)) {

    // Let the decorated resolve callbacks.
    return $value;
  }

  // Check user has access to the property.
  if (!$this
    ->access('view', $interpreter)) {
    return NULL;
  }
  $property_wrapper = $this
    ->propertyWrapper($interpreter);
  $wrapper = $interpreter
    ->getWrapper();
  if ($property_wrapper instanceof \EntityListWrapper) {
    $values = array();

    // Multiple values.
    foreach ($property_wrapper
      ->getIterator() as $item_wrapper) {
      $values[] = $this
        ->singleValue($item_wrapper, $wrapper, $interpreter
        ->getAccount());
    }
    return $values;
  }
  return $this
    ->singleValue($property_wrapper, $wrapper, $interpreter
    ->getAccount());
}