You are here

public function AgreementSettings::transform in Agreement 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/migrate/process/AgreementSettings.php \Drupal\agreement\Plugin\migrate\process\AgreementSettings::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

src/Plugin/migrate/process/AgreementSettings.php, line 72

Class

AgreementSettings
Agreement settings process plugin.

Namespace

Drupal\agreement\Plugin\migrate\process

Code

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

  // Change property name for email recipient.
  $value['recipient'] = $value['email_recipient'];
  unset($value['email_recipient']);

  // Deal with roles which may not have been upgraded.
  if (!is_array($value['role'])) {
    $value['roles'] = [
      $this
        ->getRoleId($value['role'], $migrate_executable),
    ];
  }
  else {
    $value['roles'] = [];
    foreach ($value['role'] as $role) {
      $value['roles'][] = $this
        ->getRoleId($role, $migrate_executable);
    }
  }
  unset($value['role']);

  // Map visibility settings and pages.
  $value['visibility'] = [
    'settings' => (int) $value['visibility_settings'],
    'pages' => [],
  ];
  $pages = preg_split('/\\r?\\n/', $value['visibility_pages']);
  if (!empty($pages)) {
    foreach ($pages as $page) {
      if ($page) {
        $value['visibility']['pages'][] = '/' . $page;
      }
    }
  }
  unset($value['visibility_pages']);
  unset($value['visibility_settings']);

  // Set a reset date.
  $value['reset_date'] = 0;

  // Prefix destination path.
  $value['destination'] = !empty($value['destination']) ? '/' . $value['destination'] : '';
  return $value;
}