RelationLookup.php in CRM Core 8.3
File
modules/crm_core_user_sync/src/Plugin/migrate/process/RelationLookup.php
View source
<?php
namespace Drupal\crm_core_user_sync\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\crm_core_user_sync\CrmCoreUserSyncRelationInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RelationLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
protected $migration;
protected $selectionPluginManager;
protected $crmCoreUserSyncRelation;
public function __construct(array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration, CrmCoreUserSyncRelationInterface $crmCoreUserSyncRelation) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->migration = $migration;
$this->crmCoreUserSyncRelation = $crmCoreUserSyncRelation;
}
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration = NULL) {
return new static($configuration, $pluginId, $pluginDefinition, $migration, $container
->get('crm_core_user_sync.relation'));
}
public function transform($value, MigrateExecutableInterface $migrateExecutable, Row $row, $destinationProperty) {
if (is_array($value) && count($value) === 0) {
return [];
}
return $this
->query($value);
}
protected function query($value) {
$multiple = is_array($value);
$results = [];
if ($multiple) {
foreach ($value as $id) {
$results[] = $this->crmCoreUserSyncRelation
->getIndividualIdFromUserId($id);
}
}
else {
$results[] = $this->crmCoreUserSyncRelation
->getIndividualIdFromUserId($value);
}
return $multiple ? array_values($results) : reset($results);
}
}
Classes
Name |
Description |
RelationLookup |
This plugin looks up relations of users to CRM individuals. |