diff -u b/core/modules/link/src/Plugin/migrate/process/FieldLink.php b/core/modules/link/src/Plugin/migrate/process/FieldLink.php --- b/core/modules/link/src/Plugin/migrate/process/FieldLink.php +++ b/core/modules/link/src/Plugin/migrate/process/FieldLink.php @@ -10,6 +10,30 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** + * Transform a pre-Drupal 8 formatted link for use in Drupal 8. + * + * Previous to Drupal 8, URLs didn't need to have a URI scheme assigned. The + * contrib link module would auto-prefix the URL with a URI scheme. A link in + * Drupal 8 has more validation and external links must include the URI scheme. + * All external URIs need to be converted to use a URI scheme. + * + * Available configuration keys + * - uri_scheme: The URI scheme prefix to use for missing scheme urls. Defaults + * to 'http://', which was the default in Drupal 6 and Drupal 7. + * + * Examples: + * + * Consider a link field migration, where you want to use https:// as the + * prefix: + * + * @code + * process: + * field_link: + * plugin: field_link + * uri_scheme: 'https://' + * source: field_link + * @endcode + * * @MigrateProcessPlugin( * id = "field_link" * ) diff -u b/core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php b/core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php --- b/core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php +++ b/core/modules/link/src/Plugin/migrate/process/d6/FieldLink.php @@ -2,12 +2,7 @@ namespace Drupal\link\Plugin\migrate\process\d6; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\ProcessPluginBase; -use Drupal\migrate\Row; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\link\Plugin\migrate\process\FieldLink as GeneralPurposeFieldLink; @trigger_error('FieldLink is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\process\FieldLink instead.', E_USER_DEPRECATED); @@ -22,70 +17,2 @@ -class FieldLink extends ProcessPluginBase implements ContainerFactoryPluginInterface { +class FieldLink extends GeneralPurposeFieldLink { } - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->migration = $migration; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $migration - ); - } - - /** - * Turn a Drupal 6 URI into a Drupal 8-compatible format. - * - * @param string $uri - * The 'url' value from Drupal 6. - * - * @return string - * The Drupal 8-compatible URI. - * - * @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri() - */ - protected function canonicalizeUri($uri) { - // If we already have a scheme, we're fine. - if (empty($uri) || !is_null(parse_url($uri, PHP_URL_SCHEME))) { - return $uri; - } - - // Remove the component of the URL. - if (strpos($uri, '') === 0) { - $uri = substr($uri, strlen('')); - } - - // Add the internal: scheme and ensure a leading slash. - return 'internal:/' . ltrim($uri, '/'); - } - - /** - * {@inheritdoc} - */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - $attributes = unserialize($value['attributes']); - // Drupal 6 link attributes might be double serialized. - if (!is_array($attributes)) { - $attributes = unserialize($attributes); - } - - if (!$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; - } - -}