3 namespace Drupal\migrate_tools\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\Component\Utility\Xss;
8 use Drupal\Component\Utility\Html;
9 use Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager;
10 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * Returns responses for migrate_tools migration view routes.
16 class MigrationController extends ControllerBase implements ContainerInjectionInterface {
19 * Plugin manager for migration plugins.
21 * @var \Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager
23 protected $migrationConfigEntityPluginManager;
26 * Constructs a new MigrationController object.
28 * @param \Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager $migration_config_entity_plugin_manager
29 * The plugin manager for config entity-based migrations.
31 public function __construct(MigrationConfigEntityPluginManager $migration_config_entity_plugin_manager) {
32 $this->migrationConfigEntityPluginManager = $migration_config_entity_plugin_manager;
38 public static function create(ContainerInterface $container) {
40 $container->get('plugin.manager.config_entity_migration')
45 * Displays an overview of a migration entity.
47 * @param string $migration_group
48 * Machine name of the migration's group.
49 * @param string $migration
50 * Machine name of the migration.
53 * A render array as expected by drupal_render().
55 public function overview($migration_group, $migration) {
57 /** @var MigrationInterface $migration */
58 $migration = $this->migrationConfigEntityPluginManager->createInstance($migration);
60 $build['overview'] = [
61 '#type' => 'fieldset',
62 '#title' => $this->t('Overview'),
65 $build['overview']['group'] = [
66 '#title' => $this->t('Group:'),
67 '#markup' => Xss::filterAdmin($migration_group),
71 $build['overview']['description'] = [
72 '#title' => $this->t('Description:'),
73 '#markup' => Xss::filterAdmin($migration->label()),
77 $migration_dependencies = $migration->getMigrationDependencies();
78 if (!empty($migration_dependencies['required'])) {
79 $build['overview']['dependencies'] = [
80 '#title' => $this->t('Migration Dependencies') ,
81 '#markup' => Xss::filterAdmin(implode(', ', $migration_dependencies['required'])),
85 if (!empty($migration_dependencies['optional'])) {
86 $build['overview']['soft_dependencies'] = [
87 '#title' => $this->t('Soft Migration Dependencies'),
88 '#markup' => Xss::filterAdmin(implode(', ', $migration_dependencies['optional'])),
97 * Display source information of a migration entity.
99 * @param string $migration_group
100 * Machine name of the migration's group.
101 * @param string $migration
102 * Machine name of the migration.
105 * A render array as expected by drupal_render().
107 public function source($migration_group, $migration) {
109 /** @var MigrationInterface $migration */
110 $migration = $this->migrationConfigEntityPluginManager->createInstance($migration);
112 // Source field information.
114 '#type' => 'fieldset',
115 '#title' => $this->t('Source'),
116 '#group' => 'detail',
117 '#description' => $this->t('<p>These are the fields available from the source of this migration task. The machine names listed here may be used as sources in the process pipeline.</p>'),
119 'id' => 'migration-detail-source',
123 $source = $migration->getSourcePlugin();
124 $build['source']['query'] = [
126 '#title' => $this->t('Query'),
127 '#markup' => '<pre>' . Xss::filterAdmin($source) . '</pre>',
129 $header = [$this->t('Machine name'), $this->t('Description')];
131 foreach ($source->fields($migration) as $machine_name => $description) {
133 ['data' => Html::escape($machine_name)],
134 ['data' => Xss::filterAdmin($description)],
138 $build['source']['fields'] = [
140 '#header' => $header,
142 '#empty' => $this->t('No fields'),
149 * Display process information of a migration entity.
151 * @param string $migration_group
152 * Machine name of the migration's group.
153 * @param string $migration
154 * Machine name of the migration.
157 * A render array as expected by drupal_render().
159 public function process($migration_group, $migration) {
161 /** @var MigrationInterface $migration */
162 $migration = $this->migrationConfigEntityPluginManager->createInstance($migration);
164 // Process information.
165 $build['process'] = [
166 '#type' => 'fieldset',
167 '#title' => $this->t('Process'),
171 $this->t('Destination'),
173 $this->t('Process plugin'),
177 foreach ($migration->getProcess() as $destination_id => $process_line) {
179 $row[] = ['data' => Html::escape($destination_id)];
180 if (isset($process_line[0]['source'])) {
181 $row[] = ['data' => Xss::filterAdmin($process_line[0]['source'])];
186 if (isset($process_line[0]['plugin'])) {
187 $row[] = ['data' => Xss::filterAdmin($process_line[0]['plugin'])];
192 if (isset($process_line[0]['default_value'])) {
193 $row[] = ['data' => Xss::filterAdmin($process_line[0]['default_value'])];
201 $build['process']['fields'] = [
203 '#header' => $header,
205 '#empty' => $this->t('No process defined.'),
212 * Displays destination information of a migration entity.
214 * @param string $migration_group
215 * Machine name of the migration's group.
216 * @param string $migration
217 * Machine name of the migration.
220 * A render array as expected by drupal_render().
222 public function destination($migration_group, $migration) {
223 /** @var MigrationInterface $migration */
224 $migration = $this->migrationConfigEntityPluginManager->createInstance($migration);
226 // Destination field information.
227 $build['destination'] = [
228 '#type' => 'fieldset',
229 '#title' => $this->t('Destination'),
230 '#group' => 'detail',
231 '#description' => $this->t('<p>These are the fields available in the destination plugin of this migration task. The machine names are those available to be used as the keys in the process pipeline.</p>'),
233 'id' => 'migration-detail-destination',
236 $destination = $migration->getDestinationPlugin();
237 $build['destination']['type'] = [
239 '#title' => $this->t('Type'),
240 '#markup' => Xss::filterAdmin($destination->getPluginId()),
242 $header = [$this->t('Machine name'), $this->t('Description')];
244 $destination_fields = $destination->fields() ?: [];
245 foreach ($destination_fields as $machine_name => $description) {
247 ['data' => Html::escape($machine_name)],
248 ['data' => Xss::filterAdmin($description)],
252 $build['destination']['fields'] = [
254 '#header' => $header,
256 '#empty' => $this->t('No fields'),