You are here

GatherContentReferenceRevision.php in GatherContent 8.5

File

src/Plugin/migrate/process/GatherContentReferenceRevision.php
View source
<?php

namespace Drupal\gathercontent\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Perform custom value transformation.
 *
 * Converts simple arrays to multidimensional so we can use extract plugin.
 *
 * @MigrateProcessPlugin(
 *   id = "gather_content_reference_revision",
 *   handle_multiples = TRUE
 * )
 *
 * @code
 * reference_revision_field:
 *   plugin: gather_content_reference_revision
 *   source: field
 * @endcode
 */
class GatherContentReferenceRevision extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    if (!is_array($value)) {
      $value = [
        $value,
      ];
    }
    $return = [];
    foreach ($value as $data) {
      $return[] = [
        'id' => $data,
      ];
    }
    return $return;
  }

  /**
   * {@inheritdoc}
   */
  public function multiple() {
    return TRUE;
  }

}

Classes

Namesort descending Description
GatherContentReferenceRevision Perform custom value transformation.