You are here

public function FieldLink::transform in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/link/src/Plugin/migrate/process/FieldLink.php \Drupal\link\Plugin\migrate\process\FieldLink::transform()
  2. 10 core/modules/link/src/Plugin/migrate/process/FieldLink.php \Drupal\link\Plugin\migrate\process\FieldLink::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

core/modules/link/src/Plugin/migrate/process/FieldLink.php, line 121

Class

FieldLink
Transform a pre-Drupal 8 formatted link for use in Drupal 8.

Namespace

Drupal\link\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  $attributes = unserialize($value['attributes']);

  // Drupal 6/7 link attributes might be double serialized.
  if (!is_array($attributes)) {
    $attributes = unserialize($attributes);
  }

  // In rare cases Drupal 6/7 link attributes are triple serialized. To avoid
  // further problems with them we set them to an empty array in this case.
  if (!is_array($attributes)) {
    $attributes = [];
  }

  // Massage the values into the correct form for the link.
  $route['uri'] = $this
    ->canonicalizeUri($value['url']);
  $route['options']['attributes'] = $attributes;
  $route['title'] = $value['title'];
  return $route;
}