You are here

public function FieldInheritancePluginBase::computeValue in Field Inheritance 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/FieldInheritance/FieldInheritancePluginBase.php \Drupal\field_inheritance\Plugin\FieldInheritance\FieldInheritancePluginBase::computeValue()

Compute the value of the field.

Overrides FieldInheritancePluginInterface::computeValue

File

src/Plugin/FieldInheritance/FieldInheritancePluginBase.php, line 186

Class

FieldInheritancePluginBase
Abstract class FieldInheritancePluginBase.

Namespace

Drupal\field_inheritance\Plugin\FieldInheritance

Code

public function computeValue() {
  $this
    ->validateArguments();
  $method = $this
    ->getMethod();
  $value = '';
  switch ($method) {
    case 'inherit':
      $value = $this
        ->inheritData();
      break;
    case 'prepend':
      $value = $this
        ->prependData();
      break;
    case 'append':
      $value = $this
        ->appendData();
      break;
    case 'fallback':
      $value = $this
        ->fallbackData();
      break;
  }
  $context = [
    'source_field' => $this
      ->getSourceField(),
    'source_entity' => $this
      ->getSourceEntity(),
    'destination_field' => $this
      ->getDestinationField(),
    'destination_entity' => $this
      ->getDestinationEntity(),
    'method' => $this
      ->getMethod(),
  ];
  \Drupal::moduleHandler()
    ->alter('field_inheritance_compute_value', $value, $context);
  return $value;
}