Mercurial > hg > cmmr2012-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
14 use Symfony\Component\DependencyInjection\ContainerInterface; | 14 use Symfony\Component\DependencyInjection\ContainerInterface; |
15 | 15 |
16 /** | 16 /** |
17 * This plugin looks for existing entities. | 17 * This plugin looks for existing entities. |
18 * | 18 * |
19 * @MigrateProcessPlugin( | |
20 * id = "entity_lookup", | |
21 * handle_multiples = TRUE | |
22 * ) | |
23 * | |
24 * In its most simple form, this plugin needs no configuration. However, if the | 19 * In its most simple form, this plugin needs no configuration. However, if the |
25 * lookup properties cannot be determined through introspection, define them via | 20 * lookup properties cannot be determined through introspection, define them via |
26 * configuration. | 21 * configuration. |
22 * | |
23 * Available configuration keys: | |
24 * - access_check: (optional) Indicates if access to the entity for this user | |
25 * will be checked. Default is true. | |
26 * | |
27 * @codingStandardsIgnoreStart | |
27 * | 28 * |
28 * Example usage with minimal configuration: | 29 * Example usage with minimal configuration: |
29 * @code | 30 * @code |
30 * destination: | 31 * destination: |
31 * plugin: 'entity:node' | 32 * plugin: 'entity:node' |
33 * type: | 34 * type: |
34 * plugin: default_value | 35 * plugin: default_value |
35 * default_value: page | 36 * default_value: page |
36 * field_tags: | 37 * field_tags: |
37 * plugin: entity_lookup | 38 * plugin: entity_lookup |
39 * access_check: false | |
38 * source: tags | 40 * source: tags |
39 * @endcode | 41 * @endcode |
42 * In this example above, the access check is disabled. | |
40 * | 43 * |
41 * Example usage with full configuration: | 44 * Example usage with full configuration: |
42 * @code | 45 * @code |
43 * field_tags: | 46 * field_tags: |
44 * plugin: entity_lookup | 47 * plugin: entity_lookup |
47 * bundle_key: vid | 50 * bundle_key: vid |
48 * bundle: tags | 51 * bundle: tags |
49 * entity_type: taxonomy_term | 52 * entity_type: taxonomy_term |
50 * ignore_case: true | 53 * ignore_case: true |
51 * @endcode | 54 * @endcode |
55 * | |
56 * @codingStandardsIgnoreEnd | |
57 * | |
58 * @MigrateProcessPlugin( | |
59 * id = "entity_lookup", | |
60 * handle_multiples = TRUE | |
61 * ) | |
52 */ | 62 */ |
53 class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface { | 63 class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface { |
54 | 64 |
55 /** | 65 /** |
56 * The entity manager. | 66 * The entity manager. |
119 * The destination property or field. | 129 * The destination property or field. |
120 * | 130 * |
121 * @var string | 131 * @var string |
122 */ | 132 */ |
123 protected $destinationProperty; | 133 protected $destinationProperty; |
134 | |
135 /** | |
136 * The access check flag. | |
137 * | |
138 * @var string | |
139 */ | |
140 protected $accessCheck = TRUE; | |
124 | 141 |
125 /** | 142 /** |
126 * {@inheritdoc} | 143 * {@inheritdoc} |
127 */ | 144 */ |
128 public function __construct(array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration, EntityManagerInterface $entityManager, SelectionPluginManagerInterface $selectionPluginManager) { | 145 public function __construct(array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration, EntityManagerInterface $entityManager, SelectionPluginManagerInterface $selectionPluginManager) { |
175 * @param string $destinationProperty | 192 * @param string $destinationProperty |
176 * The destination property currently worked on. This is only used together | 193 * The destination property currently worked on. This is only used together |
177 * with the $row above. | 194 * with the $row above. |
178 */ | 195 */ |
179 protected function determineLookupProperties($destinationProperty) { | 196 protected function determineLookupProperties($destinationProperty) { |
197 if (isset($this->configuration['access_check'])) { | |
198 $this->accessCheck = $this->configuration['access_check']; | |
199 } | |
180 if (!empty($this->configuration['value_key'])) { | 200 if (!empty($this->configuration['value_key'])) { |
181 $this->lookupValueKey = $this->configuration['value_key']; | 201 $this->lookupValueKey = $this->configuration['value_key']; |
182 } | 202 } |
183 if (!empty($this->configuration['bundle_key'])) { | 203 if (!empty($this->configuration['bundle_key'])) { |
184 $this->lookupBundleKey = $this->configuration['bundle_key']; | 204 $this->lookupBundleKey = $this->configuration['bundle_key']; |
258 | 278 |
259 $multiple = is_array($value); | 279 $multiple = is_array($value); |
260 | 280 |
261 $query = $this->entityManager->getStorage($this->lookupEntityType) | 281 $query = $this->entityManager->getStorage($this->lookupEntityType) |
262 ->getQuery() | 282 ->getQuery() |
283 ->accessCheck($this->accessCheck) | |
263 ->condition($this->lookupValueKey, $value, $multiple ? 'IN' : NULL); | 284 ->condition($this->lookupValueKey, $value, $multiple ? 'IN' : NULL); |
264 // Sqlite and possibly others returns data in a non-deterministic order. | 285 // Sqlite and possibly others returns data in a non-deterministic order. |
265 // Make it deterministic. | 286 // Make it deterministic. |
266 if ($multiple) { | 287 if ($multiple) { |
267 $query->sort($this->lookupValueKey, 'DESC'); | 288 $query->sort($this->lookupValueKey, 'DESC'); |