You are here

public function PathRedirect::transform in Redirect 8

Same name in this branch
  1. 8 src/Plugin/migrate/process/PathRedirect.php \Drupal\redirect\Plugin\migrate\process\PathRedirect::transform()
  2. 8 src/Plugin/migrate/process/d7/PathRedirect.php \Drupal\redirect\Plugin\migrate\process\d7\PathRedirect::transform()

Transform the field as required for an iFrame field.

Overrides ProcessPluginBase::transform

File

src/Plugin/migrate/process/d7/PathRedirect.php, line 26
Contains \Drupal\redirect\Plugin\migrate\process\d7\PathRedirect.

Class

PathRedirect
Plugin annotation @MigrateProcessPlugin( id = "d7_path_redirect" )

Namespace

Drupal\redirect\Plugin\migrate\process\d7

Code

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

  // Check if the url begins with http.
  if (preg_match('#^http#', $value[0])) {

    // Use it as is.
    $uri = $value[0];
  }
  else {

    // Make the link internal.
    $uri = 'internal:/' . $value[0];
  }

  // Check if there are options.
  if (!empty($value[1])) {

    // Check if there is a query.
    $options = unserialize($value[1]);
    if (!empty($options['query'])) {

      // Add it to the end of the url.
      $uri .= '?' . http_build_query($options['query']);
    }
    if (!empty($options['fragment'])) {
      $uri .= '#' . $options['fragment'];
    }
  }
  return $uri;
}