diff modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityLookup.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
line wrap: on
line diff
--- a/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityLookup.php	Thu Feb 28 13:11:55 2019 +0000
+++ b/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityLookup.php	Thu May 09 15:34:47 2019 +0100
@@ -16,15 +16,16 @@
 /**
  * This plugin looks for existing entities.
  *
- * @MigrateProcessPlugin(
- *   id = "entity_lookup",
- *   handle_multiples = TRUE
- * )
- *
  * In its most simple form, this plugin needs no configuration. However, if the
  * lookup properties cannot be determined through introspection, define them via
  * configuration.
  *
+ * Available configuration keys:
+ * - access_check: (optional) Indicates if access to the entity for this user
+ *   will be checked. Default is true.
+ *
+ * @codingStandardsIgnoreStart
+ *
  * Example usage with minimal configuration:
  * @code
  * destination:
@@ -35,8 +36,10 @@
  *     default_value: page
  *   field_tags:
  *     plugin: entity_lookup
+ *     access_check: false
  *     source: tags
  * @endcode
+ * In this example above, the access check is disabled.
  *
  * Example usage with full configuration:
  * @code
@@ -49,6 +52,13 @@
  *     entity_type: taxonomy_term
  *     ignore_case: true
  * @endcode
+ *
+ * @codingStandardsIgnoreEnd
+ *
+ * @MigrateProcessPlugin(
+ *   id = "entity_lookup",
+ *   handle_multiples = TRUE
+ * )
  */
 class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface {
 
@@ -123,6 +133,13 @@
   protected $destinationProperty;
 
   /**
+   * The access check flag.
+   *
+   * @var string
+   */
+  protected $accessCheck = TRUE;
+
+  /**
    * {@inheritdoc}
    */
   public function __construct(array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration, EntityManagerInterface $entityManager, SelectionPluginManagerInterface $selectionPluginManager) {
@@ -177,6 +194,9 @@
    *   with the $row above.
    */
   protected function determineLookupProperties($destinationProperty) {
+    if (isset($this->configuration['access_check'])) {
+      $this->accessCheck = $this->configuration['access_check'];
+    }
     if (!empty($this->configuration['value_key'])) {
       $this->lookupValueKey = $this->configuration['value_key'];
     }
@@ -260,6 +280,7 @@
 
     $query = $this->entityManager->getStorage($this->lookupEntityType)
       ->getQuery()
+      ->accessCheck($this->accessCheck)
       ->condition($this->lookupValueKey, $value, $multiple ? 'IN' : NULL);
     // Sqlite and possibly others returns data in a non-deterministic order.
     // Make it deterministic.