You are here

public function UbercartFieldStorageGenerate::transform in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/ubercart/src/Plugin/migrate/process/uc6/UbercartFieldStorageGenerate.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\uc6\UbercartFieldStorageGenerate::transform()
  2. 3.0.x modules/ubercart/src/Plugin/migrate/process/uc6/UbercartFieldStorageGenerate.php \Drupal\commerce_migrate_ubercart\Plugin\migrate\process\uc6\UbercartFieldStorageGenerate::transform()

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/ubercart/src/Plugin/migrate/process/uc6/UbercartFieldStorageGenerate.php, line 28

Class

UbercartFieldStorageGenerate
Create field storage.

Namespace

Drupal\commerce_migrate_ubercart\Plugin\migrate\process\uc6

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  $return = FALSE;
  if ($value) {
    $field_name = $row
      ->getSourceProperty('field_name');
    $entity_type = $value;
    $name = $entity_type . '.' . $field_name;
    if (!FieldStorageConfig::load($name)) {
      $field_storage_definition = [
        'field_name' => $field_name,
        'entity_type' => $entity_type,
        'type' => $row
          ->getDestinationProperty('type'),
        'cardinality' => $row
          ->getDestinationProperty('cardinality'),
        'settings' => $row
          ->getDestinationProperty('settings'),
      ];
      $storage = FieldStorageConfig::create($field_storage_definition);
      try {
        $storage
          ->save();
        $return = $field_name;
      } catch (PluginNotFoundException $ex) {

        // Just return FALSE.
      } catch (FieldException $ex) {

        // Just return FALSE.
      }
    }
  }
  return $return;
}