Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / menu_link_content / src / Plugin / migrate / process / LinkUri.php
index 175566eee403e22b1fc1a223d819555e6d1fe3f9..bd95a606f50efade95b1a6462db41ae8f0c7718d 100644 (file)
@@ -14,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 /**
  * Processes a link path into an 'internal:' or 'entity:' URI.
  *
+ * @todo: Add documentation in https://www.drupal.org/node/2954908
+ *
  * @MigrateProcessPlugin(
  *   id = "link_uri"
  * )
@@ -40,6 +42,9 @@ class LinkUri extends ProcessPluginBase implements ContainerFactoryPluginInterfa
    *   The entity type manager, used to fetch entity link templates.
    */
   public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
+    $configuration += [
+      'validate_route' => TRUE,
+    ];
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->entityTypeManager = $entity_type_manager;
   }
@@ -82,7 +87,15 @@ class LinkUri extends ProcessPluginBase implements ContainerFactoryPluginInterfa
         }
       }
       else {
-        throw new MigrateException(sprintf('The path "%s" failed validation.', $path));
+        // If the URL is not routed, we might want to get something back to do
+        // other processing. If this is the case, the "validate_route"
+        // configuration option can be set to FALSE to return the URI.
+        if (!$this->configuration['validate_route']) {
+          return $url->getUri();
+        }
+        else {
+          throw new MigrateException(sprintf('The path "%s" failed validation.', $path));
+        }
       }
     }
     return $path;