D7EckDeriver.php in Entity Construction Kit (ECK) 8
File
src/Plugin/migrate/D7EckDeriver.php
View source
<?php
namespace Drupal\eck\Plugin\migrate;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationDeriverTrait;
use Drupal\migrate_drupal\FieldDiscoveryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class D7EckDeriver extends DeriverBase implements ContainerDeriverInterface {
use MigrationDeriverTrait;
protected $basePluginId;
protected $fieldDiscovery;
public function __construct($base_plugin_id, $translations, FieldDiscoveryInterface $field_discovery) {
$this->basePluginId = $base_plugin_id;
$this->includeTranslations = $translations;
$this->fieldDiscovery = $field_discovery;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('module_handler')
->moduleExists('content_translation'), $container
->get('migrate_drupal.field_discovery'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$eck_types = static::getSourcePlugin('d7_eck_entity_type');
$eck_bundles = static::getSourcePlugin('d7_eck_entity_bundle');
try {
$eck_types
->checkRequirements();
$eck_bundles
->checkRequirements();
} catch (RequirementsException $e) {
return $this->derivatives;
}
try {
foreach ($eck_types as $type_row) {
$entity_type = $type_row
->getSourceProperty('name');
foreach (static::getSourcePlugin('d7_eck_entity_bundle') as $bundle_row) {
$bundle = $bundle_row
->getSourceProperty('name');
$bundle_entity_type = $bundle_row
->getSourceProperty('entity_type');
if ($bundle_entity_type != $entity_type) {
continue;
}
$values = $base_plugin_definition;
$values['label'] = t('@label (@type)', [
'@label' => $bundle_row
->getSourceProperty('label'),
'@type' => $type_row
->getSourceProperty('name'),
]);
$values['source']['entity_type'] = $entity_type;
$values['source']['bundle'] = $bundle;
$values['destination']['plugin'] = "entity:{$entity_type}";
$values['destination']['default_bundle'] = $bundle;
$migration = \Drupal::service('plugin.manager.migration')
->createStubMigration($values);
$source_plugin = $migration
->getSourcePlugin();
$source_plugin
->rewind();
$row = $source_plugin
->current();
if (!$row) {
continue;
}
$this->fieldDiscovery
->addBundleFieldProcesses($migration, $entity_type, $bundle);
$this->derivatives[$entity_type . ':' . $bundle] = $migration
->getPluginDefinition();
}
}
} catch (DatabaseExceptionWrapper $e) {
}
return $this->derivatives;
}
}