Last active
March 27, 2018 03:07
-
-
Save simesy/755897d43b24e06afeed to your computer and use it in GitHub Desktop.
Revisions
-
simesy revised this gist
Dec 30, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ namespace Drupal\migrate_entity_lookup\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\Core\Entity\Query\QueryFactory; -
simesy revised this gist
Dec 30, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,7 +70,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable return null; } else { $query = $this->entityQuery->get($this->configuration['entity_type']); $entity_ids = $query->condition($this->configuration['property'], $value)->range(0, 1)->execute(); if (count($entity_ids)) { return reset($entity_ids); -
simesy revised this gist
Dec 30, 2015 . 1 changed file with 9 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,11 +10,11 @@ use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * This plugin changes the current value by using it for an entity property search * and returning an entity id. @@ -30,7 +30,7 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityQuery; /** * Constructs an EntityLookup object. @@ -41,12 +41,12 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query * The entity query factory. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryFactory $entity_query) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityQuery = $entity_query; } /** @@ -57,7 +57,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, $container->get('entity.query') ); } @@ -70,10 +70,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable return null; } else { $query = $this->entityQuery->get($this->configuration['entity_type']);// $this->entityTypeManager->getStorage($this->configuration['entity_type']); $entity_ids = $query->condition($this->configuration['property'], $value)->range(0, 1)->execute(); if (count($entity_ids)) { return reset($entity_ids); } -
simesy revised this gist
Dec 30, 2015 . No changes.There are no files selected for viewing
-
simesy revised this gist
Dec 30, 2015 . 3 changed files with 92 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ <?php /** * @file * Contains \Drupal\migrate_entity_lookup\Plugin\migrate\process\EntityLookup. */ namespace Drupal\migrate_entity_lookup\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * This plugin changes the current value by using it for an entity property search * and returning an entity id. * * @MigrateProcessPlugin( * id = "entity_lookup" * ) */ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface { /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs an EntityLookup object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param array $entity_type_manager * The entity type manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager') ); } /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if (empty($value)) { // @todo: allow a default_value if nothing in source. return null; } else { $storage = $this->entityTypeManager->getStorage($this->configuration['entity_type']); $query = $storage->getQuery(); $entity_ids = $query->condition($this->configuration['property'], $value)->range(0, 1)->execute(); // drush_print_r(array($this->configuration['entity_type'], $this->configuration['property'], $value, $entity_ids)); if (count($entity_ids)) { return reset($entity_ids); } else { // @todo: Return a default value if failed to retrieve one. return null; } } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ process: field_dest: plugin: entity_lookup source: source_field entity_type: taxonomy_term property: name -
simesy created this gist
Dec 30, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ process: field_blah: plugin: entity_lookup source: somedata entity_type: node property: title