You are here

public function ComputedFieldItemTrait::executeCode in Computed Field 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldType/ComputedFieldItemTrait.php \Drupal\computed_field\Plugin\Field\FieldType\ComputedFieldItemTrait::executeCode()

Performs the field value computation.

4 calls to ComputedFieldItemTrait::executeCode()
ComputedDecimalItem::executeCode in src/Plugin/Field/FieldType/ComputedDecimalItem.php
ComputedFieldItemTrait::preSave in src/Plugin/Field/FieldType/ComputedFieldItemTrait.php
ComputedIntegerItem::executeCode in src/Plugin/Field/FieldType/ComputedIntegerItem.php
ComputedStringItem::executeCode in src/Plugin/Field/FieldType/ComputedStringItem.php
This function does the computation of the field value.
3 methods override ComputedFieldItemTrait::executeCode()
ComputedDecimalItem::executeCode in src/Plugin/Field/FieldType/ComputedDecimalItem.php
ComputedIntegerItem::executeCode in src/Plugin/Field/FieldType/ComputedIntegerItem.php
ComputedStringItem::executeCode in src/Plugin/Field/FieldType/ComputedStringItem.php
This function does the computation of the field value.

File

src/Plugin/Field/FieldType/ComputedFieldItemTrait.php, line 36

Class

ComputedFieldItemTrait
Common methods for Computed Field FieldType plugins.

Namespace

Drupal\computed_field\Plugin\Field\FieldType

Code

public function executeCode() {
  $code = $this
    ->getSettings()['code'];
  $entity_type_manager = \Drupal::EntityTypeManager();
  $entity = $this
    ->getEntity();
  $fields = $entity
    ->toArray();
  $delta = $this->name;
  if ($this
    ->computeFunctionNameExists()) {
    $compute_function = $this
      ->getComputeFunctionName();
    $value = $compute_function($entity_type_manager, $entity, $fields, $delta);
  }
  else {
    $value = NULL;
    eval($code);
  }
  return $value;
}