D7FieldablePanelsPaneDeriver.php in Fieldable Panels Panes (FPP) 1.0.x
File
src/Plugin/migrate/D7FieldablePanelsPaneDeriver.php
View source
<?php
namespace Drupal\fieldable_panels_panes\Plugin\migrate;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationDeriverTrait;
use Drupal\migrate_drupal\FieldDiscoveryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class D7FieldablePanelsPaneDeriver extends DeriverBase implements ContainerDeriverInterface {
use MigrationDeriverTrait;
use StringTranslationTrait;
protected $basePluginId;
protected $includeTranslations;
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) {
if (in_array('translation', $base_plugin_definition['migration_tags']) && !$this->includeTranslations) {
return $this->derivatives;
}
$types = static::getSourcePlugin('d7_fieldable_panels_pane_type');
try {
$types
->checkRequirements();
} catch (RequirementsException $e) {
return $this->derivatives;
}
try {
foreach ($types as $row) {
$bundle = $row
->getSourceProperty('name');
$values = $base_plugin_definition;
$values['label'] = $this
->t('@label (@type)', [
'@label' => $values['label'],
'@type' => $row
->getSourceProperty('name'),
]);
$values['source']['bundle'] = $bundle;
$values['destination']['default_bundle'] = $bundle;
if ($base_plugin_definition['id'] == [
'd7_fieldable_panels_pane_revision',
] || in_array('translation', $base_plugin_definition['migration_tags'])) {
$values['migration_dependencies']['required'][] = 'd7_fieldable_panels_pane:' . $bundle;
}
$migration = \Drupal::service('plugin.manager.migration')
->createStubMigration($values);
$this->fieldDiscovery
->addBundleFieldProcesses($migration, 'fieldable_panels_pane', $bundle);
$this->derivatives[$bundle] = $migration
->getPluginDefinition();
}
} catch (DatabaseExceptionWrapper $e) {
}
return $this->derivatives;
}
}