/** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $field_type = is_array($value) ? $value[0] : $value; try { $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration); return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row); } catch (PluginNotFoundException $e) { return parent::transform($value, $migrate_executable, $row, $destination_property); } }
/** * {@inheritdoc} */ public function getProcess() { if (!$this->init) { $this->init = TRUE; $source_plugin = $this->migrationPluginManager->createInstance($this->pluginId)->getSourcePlugin(); if ($source_plugin instanceof RequirementsInterface) { try { $source_plugin->checkRequirements(); } catch (RequirementsException $e) { // Kill the rest of the method. $source_plugin = []; } } foreach ($source_plugin as $row) { $field_type = $row->getSourceProperty('type'); try { $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this); } catch (PluginNotFoundException $ex) { continue; } if (!isset($this->processedFieldTypes[$field_type])) { $this->processedFieldTypes[$field_type] = TRUE; // Allow the cckfield plugin to alter the migration as necessary so // that it knows how to handle fields of this type. if (!isset($this->cckPluginCache[$field_type])) { $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, [], $this); } call_user_func([$this->cckPluginCache[$field_type], $this->pluginDefinition['cck_plugin_method']], $this); } } } return parent::getProcess(); }
/** * Gets the definition of all derivatives of a base plugin. * * @param array $base_plugin_definition * The definition array of the base plugin. * * @return array * An array of full derivative definitions keyed on derivative id. * * @see \Drupal\Component\Plugin\Derivative\DeriverBase::getDerivativeDefinition() */ public function getDerivativeDefinitions($base_plugin_definition) { if ($base_plugin_definition['id'] == 'd6_node_translation' && !$this->includeTranslations) { // Refuse to generate anything. return $this->derivatives; } // Read all CCK field instance definitions in the source database. $fields = array(); try { $source_plugin = static::getSourcePlugin('d6_field_instance'); $source_plugin->checkRequirements(); foreach ($source_plugin as $row) { $fields[$row->getSourceProperty('type_name')][$row->getSourceProperty('field_name')] = $row->getSource(); } } catch (RequirementsException $e) { // If checkRequirements() failed then the content module did not exist and // we do not have any CCK fields. Therefore, $fields will be empty and // below we'll create a migration just for the node properties. } try { foreach (static::getSourcePlugin('d6_node_type') as $row) { $node_type = $row->getSourceProperty('type'); $values = $base_plugin_definition; $values['label'] = t("@label (@type)", ['@label' => $values['label'], '@type' => $node_type]); $values['source']['node_type'] = $node_type; $values['destination']['default_bundle'] = $node_type; // If this migration is based on the d6_node_revision migration or // is for translations of nodes, it should explicitly depend on the // corresponding d6_node variant. if (in_array($base_plugin_definition['id'], ['d6_node_revision', 'd6_node_translation'])) { $values['migration_dependencies']['required'][] = 'd6_node:' . $node_type; } $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values); if (isset($fields[$node_type])) { foreach ($fields[$node_type] as $field_name => $info) { $field_type = $info['type']; try { $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration); if (!isset($this->cckPluginCache[$field_type])) { $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 6], $migration); } $this->cckPluginCache[$field_type]->processCckFieldValues($migration, $field_name, $info); } catch (PluginNotFoundException $ex) { $migration->setProcessOfProperty($field_name, $field_name); } } } $this->derivatives[$node_type] = $migration->getPluginDefinition(); } } catch (DatabaseExceptionWrapper $e) { // Once we begin iterating the source plugin it is possible that the // source tables will not exist. This can happen when the // MigrationPluginManager gathers up the migration definitions but we do // not actually have a Drupal 6 source database. } return $this->derivatives; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $fields = []; try { $source_plugin = static::getSourcePlugin('d7_field_instance'); $source_plugin->checkRequirements(); // Read all field instance definitions in the source database. foreach ($source_plugin as $row) { if ($row->getSourceProperty('entity_type') == 'node') { $fields[$row->getSourceProperty('bundle')][$row->getSourceProperty('field_name')] = $row->getSource(); } } } catch (RequirementsException $e) { // If checkRequirements() failed then the field module did not exist and // we do not have any fields. Therefore, $fields will be empty and below // we'll create a migration just for the node properties. } try { foreach (static::getSourcePlugin('d7_node_type') 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; $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values); if (isset($fields[$node_type])) { foreach ($fields[$node_type] as $field_name => $info) { $field_type = $info['type']; try { $plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 7], $migration); if (!isset($this->cckPluginCache[$field_type])) { $this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 7], $migration); } $this->cckPluginCache[$field_type]->processCckFieldValues($migration, $field_name, $info); } catch (PluginNotFoundException $ex) { $migration->setProcessOfProperty($field_name, $field_name); } } } $this->derivatives[$node_type] = $migration->getPluginDefinition(); } } catch (DatabaseExceptionWrapper $e) { // Once we begin iterating the source plugin it is possible that the // source tables will not exist. This can happen when the // MigrationPluginManager gathers up the migration definitions but we do // not actually have a Drupal 7 source database. } return $this->derivatives; }