Chris@0: basePluginId = $base_plugin_id; Chris@0: $this->cckPluginManager = $cck_manager; Chris@0: $this->fieldPluginManager = $field_manager; Chris@0: $this->includeTranslations = $translations; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container, $base_plugin_id) { Chris@0: // Translations don't make sense unless we have content_translation. Chris@0: return new static( Chris@0: $base_plugin_id, Chris@0: $container->get('plugin.manager.migrate.cckfield'), Chris@0: $container->get('plugin.manager.migrate.field'), Chris@0: $container->get('module_handler')->moduleExists('content_translation') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDerivativeDefinitions($base_plugin_definition) { Chris@0: if (in_array('translation', $base_plugin_definition['migration_tags']) && !$this->includeTranslations) { Chris@0: // Refuse to generate anything. Chris@0: return $this->derivatives; Chris@0: } Chris@0: Chris@0: $node_types = static::getSourcePlugin('d7_node_type'); Chris@0: try { Chris@0: $node_types->checkRequirements(); Chris@0: } Chris@0: catch (RequirementsException $e) { Chris@0: // If the d7_node_type requirements failed, that means we do not have a Chris@0: // Drupal source database configured - there is nothing to generate. Chris@0: return $this->derivatives; Chris@0: } Chris@0: Chris@0: $fields = []; Chris@0: try { Chris@0: $source_plugin = static::getSourcePlugin('d7_field_instance'); Chris@0: $source_plugin->checkRequirements(); Chris@0: Chris@0: // Read all field instance definitions in the source database. Chris@0: foreach ($source_plugin as $row) { Chris@0: if ($row->getSourceProperty('entity_type') == 'node') { Chris@0: $fields[$row->getSourceProperty('bundle')][$row->getSourceProperty('field_name')] = $row->getSource(); Chris@0: } Chris@0: } Chris@0: } Chris@0: catch (RequirementsException $e) { Chris@0: // If checkRequirements() failed then the field module did not exist and Chris@0: // we do not have any fields. Therefore, $fields will be empty and below Chris@0: // we'll create a migration just for the node properties. Chris@0: } Chris@0: Chris@0: try { Chris@0: foreach ($node_types as $row) { Chris@0: $node_type = $row->getSourceProperty('type'); Chris@0: $values = $base_plugin_definition; Chris@0: Chris@0: $values['label'] = t('@label (@type)', [ Chris@0: '@label' => $values['label'], Chris@0: '@type' => $row->getSourceProperty('name'), Chris@0: ]); Chris@0: $values['source']['node_type'] = $node_type; Chris@0: $values['destination']['default_bundle'] = $node_type; Chris@0: Chris@0: // Comment status must be mapped to correct comment type. Chris@0: // Comment type migration creates a separate comment type for each Chris@0: // node type except for Forum which uses 'comment_forum'. Chris@0: $comment_type = 'comment_node_' . $node_type; Chris@0: if ($node_type == 'forum') { Chris@0: $comment_type = 'comment_forum'; Chris@0: } Chris@0: $nested_key = $comment_type . '/0/status'; Chris@0: $values['process'][$nested_key] = 'comment'; Chris@0: Chris@0: // If this migration is based on the d7_node_revision migration or Chris@0: // is for translations of nodes, it should explicitly depend on the Chris@0: // corresponding d7_node variant. Chris@0: if ($base_plugin_definition['id'] == ['d7_node_revision'] || in_array('translation', $base_plugin_definition['migration_tags'])) { Chris@0: $values['migration_dependencies']['required'][] = 'd7_node:' . $node_type; Chris@0: } Chris@0: Chris@0: $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values); Chris@0: if (isset($fields[$node_type])) { Chris@0: foreach ($fields[$node_type] as $field_name => $info) { Chris@0: $field_type = $info['type']; Chris@0: try { Chris@0: $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration); Chris@0: if (!isset($this->fieldPluginCache[$field_type])) { Chris@0: $this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, ['core' => 7], $migration); Chris@0: } Chris@0: $this->fieldPluginCache[$field_type] Chris@0: ->processFieldValues($migration, $field_name, $info); Chris@0: } Chris@0: catch (PluginNotFoundException $ex) { Chris@0: try { Chris@0: $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration); Chris@0: if (!isset($this->cckPluginCache[$field_type])) { Chris@0: $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 7], $migration); Chris@0: } Chris@0: $this->cckPluginCache[$field_type] Chris@0: ->processCckFieldValues($migration, $field_name, $info); Chris@0: } Chris@0: catch (PluginNotFoundException $ex) { Chris@0: $migration->setProcessOfProperty($field_name, $field_name); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: $this->derivatives[$node_type] = $migration->getPluginDefinition(); Chris@0: } Chris@0: } Chris@0: catch (DatabaseExceptionWrapper $e) { Chris@0: // Once we begin iterating the source plugin it is possible that the Chris@0: // source tables will not exist. This can happen when the Chris@0: // MigrationPluginManager gathers up the migration definitions but we do Chris@0: // not actually have a Drupal 7 source database. Chris@0: } Chris@0: return $this->derivatives; Chris@0: } Chris@0: Chris@0: }