0f4417096dffa739960a03e32900aea4ab15eb55
[yaffs-website] / web / modules / contrib / redirect / src / Plugin / migrate / process / d7 / PathRedirect.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\redirect\Plugin\migrate\process\d7\PathRedirect.
6  */
7
8 namespace Drupal\redirect\Plugin\migrate\process\d7;
9
10 use Drupal\migrate\MigrateExecutableInterface;
11 use Drupal\migrate\ProcessPluginBase;
12 use Drupal\migrate\Row;
13
14 /**
15  * @MigrateProcessPlugin(
16  *   id = "d7_path_redirect"
17  * )
18  */
19 class PathRedirect extends ProcessPluginBase {
20
21   /**
22    * {@inheritdoc}
23    *
24    * Transform the field as required for an iFrame field.
25    */
26   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
27
28     // Check if the url begins with http.
29     if (preg_match('#^http#', $value[0])) {
30       // Use it as is.
31       $uri = $value[0];
32     }
33     else {
34       // Make the link internal.
35       $uri = 'internal:/' . $value[0];
36     }
37
38     // Check if there are options.
39     if (!empty($value[1])) {
40       // Check if there is a query.
41       $options = unserialize($value[1]);
42       if (!empty($options['query'])) {
43         // Add it to the end of the url.
44         $uri .= '?' . http_build_query($options['query']);
45       }
46       if (!empty($options['fragment'])) {
47         $uri .= '#' . $options['fragment'];
48       }
49     }
50
51     return $uri;
52   }
53
54 }