You are here

public function CreateQuantity::transform in farmOS 2.x

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides ProcessPluginBase::transform

File

modules/core/quantity/src/Plugin/migrate/process/CreateQuantity.php, line 48

Class

CreateQuantity
Create quantity entities.

Namespace

Drupal\quantity\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {

  // Start array of entity values.
  $entity_values = [];

  // Gather any static default values for properties/fields.
  if (isset($this->configuration['default_values']) && is_array($this->configuration['default_values'])) {
    foreach ($this->configuration['default_values'] as $key => $value) {
      $entity_values[$key] = $value;
    }
  }

  // Gather any additional properties/fields.
  if (isset($this->configuration['values']) && is_array($this->configuration['values'])) {
    foreach ($this->configuration['values'] as $key => $property) {
      $source_value = $row
        ->get($property);
      NestedArray::setValue($entity_values, explode(Row::PROPERTY_SEPARATOR, $key), $source_value, TRUE);
    }
  }

  // Create the entity.
  $entity = $this->quantityStorage
    ->create($entity_values);

  // Save the entity so it has an ID.
  $entity
    ->save();

  // Return entity.
  return $entity;
}