function FieldLink::transform

Same name in other branches
  1. 9 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()
  3. 11.x core/modules/link/src/Plugin/migrate/process/FieldLink.php \Drupal\link\Plugin\migrate\process\FieldLink::transform()

Overrides ProcessPluginBase::transform

File

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

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.