D7NodeDeriver.php in Drupal 10
File
core/modules/node/src/Plugin/migrate/D7NodeDeriver.php
View source
<?php
namespace Drupal\node\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 D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface {
use MigrationDeriverTrait;
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;
}
$node_types = static::getSourcePlugin('d7_node_type');
try {
$node_types
->checkRequirements();
} catch (RequirementsException $e) {
return $this->derivatives;
}
try {
foreach ($node_types as $row) {
$node_type = $row
->getSourceProperty('type');
$values = $base_plugin_definition;
$values['label'] = t('@label (@type)', [
'@label' => $values['label'],
'@type' => $row
->getSourceProperty('name'),
]);
$values['source']['node_type'] = $node_type;
$values['destination']['default_bundle'] = $node_type;
$comment_type = 'comment_node_' . $node_type;
if ($node_type == 'forum') {
$comment_type = 'comment_forum';
}
$nested_key = $comment_type . '/0/status';
$values['process'][$nested_key] = 'comment';
if ($base_plugin_definition['id'] == [
'd7_node_revision',
] || in_array('translation', $base_plugin_definition['migration_tags'])) {
$values['migration_dependencies']['required'][] = 'd7_node:' . $node_type;
}
$migration = \Drupal::service('plugin.manager.migration')
->createStubMigration($values);
$this->fieldDiscovery
->addBundleFieldProcesses($migration, 'node', $node_type);
$this->derivatives[$node_type] = $migration
->getPluginDefinition();
}
} catch (DatabaseExceptionWrapper $e) {
}
return $this->derivatives;
}
}
Classes
Name |
Description |
D7NodeDeriver |
Deriver for Drupal 7 node and node revision migrations based on node types. |