Update to Drupal 8.1.5. For more information, see https://www.drupal.org/project/drupal/releases/8.1.5
This commit is contained in:
parent
13b6ca7cc2
commit
38ba7c357d
342 changed files with 7814 additions and 1534 deletions
|
@ -1,6 +1,6 @@
|
|||
services:
|
||||
plugin.manager.migrate.cckfield:
|
||||
class: Drupal\migrate\Plugin\MigratePluginManager
|
||||
class: Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager
|
||||
arguments:
|
||||
- cckfield
|
||||
- '@container.namespaces'
|
||||
|
|
|
@ -8,9 +8,10 @@ use Drupal\Component\Annotation\Plugin;
|
|||
* Defines a cckfield plugin annotation object.
|
||||
*
|
||||
* cckfield plugins are variously responsible for handling the migration of
|
||||
* CCK fields from Drupal 6 to Drupal 8. They are allowed to alter CCK-related
|
||||
* migrations when migrations are being generated, and can compute destination
|
||||
* field types for individual fields during the actual migration process.
|
||||
* CCK fields from Drupal 6 to Drupal 8, and Field API fields from Drupal 7
|
||||
* to Drupal 8. They are allowed to alter CCK-related migrations when migrations
|
||||
* are being generated, and can compute destination field types for individual
|
||||
* fields during the actual migration process.
|
||||
*
|
||||
* Plugin Namespace: Plugin\migrate\cckfield
|
||||
*
|
||||
|
@ -18,6 +19,17 @@ use Drupal\Component\Annotation\Plugin;
|
|||
*/
|
||||
class MigrateCckField extends Plugin {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct($values) {
|
||||
parent::__construct($values);
|
||||
// Provide default value for core property, in case it's missing.
|
||||
if (empty($this->definition['core'])) {
|
||||
$this->definition['core'] = [6];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
|
@ -32,4 +44,11 @@ class MigrateCckField extends Plugin {
|
|||
*/
|
||||
public $type_map = [];
|
||||
|
||||
/**
|
||||
* The Drupal core version(s) this plugin applies to.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
public $core = [];
|
||||
|
||||
}
|
||||
|
|
170
core/modules/migrate_drupal/src/MigrationConfigurationTrait.php
Normal file
170
core/modules/migrate_drupal/src/MigrationConfigurationTrait.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
|
||||
/**
|
||||
* Configures the appropriate migrations for a given source Drupal database.
|
||||
*/
|
||||
trait MigrationConfigurationTrait {
|
||||
|
||||
/**
|
||||
* Gets the database connection for the source Drupal database.
|
||||
*
|
||||
* @param array $database
|
||||
* Database array representing the source Drupal database.
|
||||
*
|
||||
* @return \Drupal\Core\Database\Connection
|
||||
* The database connection for the source Drupal database.
|
||||
*/
|
||||
protected function getConnection(array $database) {
|
||||
// Set up the connection.
|
||||
Database::addConnectionInfo('upgrade', 'default', $database);
|
||||
$connection = Database::getConnection('default', 'upgrade');
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the system data from the system table of the source Drupal database.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* Database connection to the source Drupal database.
|
||||
*
|
||||
* @return array
|
||||
* The system data from the system table of the source Drupal database.
|
||||
*/
|
||||
protected function getSystemData(Connection $connection) {
|
||||
$system_data = [];
|
||||
try {
|
||||
$results = $connection->select('system', 's', [
|
||||
'fetch' => \PDO::FETCH_ASSOC,
|
||||
])
|
||||
->fields('s')
|
||||
->execute();
|
||||
foreach ($results as $result) {
|
||||
$system_data[$result['type']][$result['name']] = $result;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// The table might not exist for example in tests.
|
||||
}
|
||||
return $system_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the necessary state entries for SqlBase::getDatabase() to work.
|
||||
*
|
||||
* The state entities created here have to exist before migration plugin
|
||||
* instances are created so that derivers such as
|
||||
* \Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver can access the source
|
||||
* database.
|
||||
*
|
||||
* @param array $database
|
||||
* The source database settings.
|
||||
* @param string $drupal_version
|
||||
* The Drupal version.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase()
|
||||
*/
|
||||
protected function createDatabaseStateSettings(array $database, $drupal_version) {
|
||||
$database_state['key'] = 'upgrade';
|
||||
$database_state['database'] = $database;
|
||||
$database_state_key = 'migrate_drupal_' . $drupal_version;
|
||||
\Drupal::state()->set($database_state_key, $database_state);
|
||||
\Drupal::state()->set('migrate.fallback_state_key', $database_state_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the migrations for import.
|
||||
*
|
||||
* @param string $database_state_key
|
||||
* The state key.
|
||||
* @param int $drupal_version
|
||||
* The version of Drupal we're getting the migrations for.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The migrations for import.
|
||||
*/
|
||||
protected function getMigrations($database_state_key, $drupal_version) {
|
||||
$version_tag = 'Drupal ' . $drupal_version;
|
||||
$plugin_manager = \Drupal::service('plugin.manager.migration');
|
||||
/** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
|
||||
$all_migrations = $plugin_manager->createInstancesByTag($version_tag);
|
||||
$migrations = [];
|
||||
foreach ($all_migrations as $migration) {
|
||||
try {
|
||||
// @todo https://drupal.org/node/2681867 We should be able to validate
|
||||
// the entire migration at this point.
|
||||
$source_plugin = $migration->getSourcePlugin();
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
$source_plugin->checkRequirements();
|
||||
}
|
||||
$destination_plugin = $migration->getDestinationPlugin();
|
||||
if ($destination_plugin instanceof RequirementsInterface) {
|
||||
$destination_plugin->checkRequirements();
|
||||
}
|
||||
$migrations[] = $migration;
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// Migrations which are not applicable given the source and destination
|
||||
// site configurations (e.g., what modules are enabled) will be silently
|
||||
// ignored.
|
||||
}
|
||||
}
|
||||
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines what version of Drupal the source database contains.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection object.
|
||||
*
|
||||
* @return int|FALSE
|
||||
* An integer representing the major branch of Drupal core (e.g. '6' for
|
||||
* Drupal 6.x), or FALSE if no valid version is matched.
|
||||
*/
|
||||
protected function getLegacyDrupalVersion(Connection $connection) {
|
||||
// Don't assume because a table of that name exists, that it has the columns
|
||||
// we're querying. Catch exceptions and report that the source database is
|
||||
// not Drupal.
|
||||
// Drupal 5/6/7 can be detected by the schema_version in the system table.
|
||||
if ($connection->schema()->tableExists('system')) {
|
||||
try {
|
||||
$version_string = $connection
|
||||
->query('SELECT schema_version FROM {system} WHERE name = :module', [':module' => 'system'])
|
||||
->fetchField();
|
||||
if ($version_string && $version_string[0] == '1') {
|
||||
if ((int) $version_string >= 1000) {
|
||||
$version_string = '5';
|
||||
}
|
||||
else {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\PDOException $e) {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
}
|
||||
// For Drupal 8 (and we're predicting beyond) the schema version is in the
|
||||
// key_value store.
|
||||
elseif ($connection->schema()->tableExists('key_value')) {
|
||||
$result = $connection
|
||||
->query("SELECT value FROM {key_value} WHERE collection = :system_schema and name = :module", [':system_schema' => 'system.schema', ':module' => 'system'])
|
||||
->fetchField();
|
||||
$version_string = unserialize($result);
|
||||
}
|
||||
else {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
|
||||
return $version_string ? substr($version_string, 0, 1) : FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,172 +2,12 @@
|
|||
|
||||
namespace Drupal\migrate_drupal;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
|
||||
/**
|
||||
* Creates the appropriate migrations for a given source Drupal database.
|
||||
*
|
||||
* @todo https://www.drupal.org/node/2682585 The trait no longer creates
|
||||
* migrations.
|
||||
* @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\migrate_drupal\MigrationConfigurationTrait instead.
|
||||
*/
|
||||
trait MigrationCreationTrait {
|
||||
|
||||
/**
|
||||
* Gets the database connection for the source Drupal database.
|
||||
*
|
||||
* @param array $database
|
||||
* Database array representing the source Drupal database.
|
||||
*
|
||||
* @return \Drupal\Core\Database\Connection
|
||||
* The database connection for the source Drupal database.
|
||||
*/
|
||||
protected function getConnection(array $database) {
|
||||
// Set up the connection.
|
||||
Database::addConnectionInfo('upgrade', 'default', $database);
|
||||
$connection = Database::getConnection('default', 'upgrade');
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the system data from the system table of the source Drupal database.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* Database connection to the source Drupal database.
|
||||
*
|
||||
* @return array
|
||||
* The system data from the system table of the source Drupal database.
|
||||
*/
|
||||
protected function getSystemData(Connection $connection) {
|
||||
$system_data = [];
|
||||
try {
|
||||
$results = $connection->select('system', 's', [
|
||||
'fetch' => \PDO::FETCH_ASSOC,
|
||||
])
|
||||
->fields('s')
|
||||
->execute();
|
||||
foreach ($results as $result) {
|
||||
$system_data[$result['type']][$result['name']] = $result;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// The table might not exist for example in tests.
|
||||
}
|
||||
return $system_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the necessary state entries for SqlBase::getDatabase() to work.
|
||||
*
|
||||
* The state entities created here have to exist before migration plugin
|
||||
* instances are created so that derivers such as
|
||||
* \Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver can access the source
|
||||
* database.
|
||||
*
|
||||
* @param array $database
|
||||
* The source database settings.
|
||||
* @param string $drupal_version
|
||||
* The Drupal version.
|
||||
*
|
||||
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase()
|
||||
*/
|
||||
protected function createDatabaseStateSettings(array $database, $drupal_version) {
|
||||
$database_state['key'] = 'upgrade';
|
||||
$database_state['database'] = $database;
|
||||
$database_state_key = 'migrate_drupal_' . $drupal_version;
|
||||
\Drupal::state()->set($database_state_key, $database_state);
|
||||
\Drupal::state()->set('migrate.fallback_state_key', $database_state_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the migrations for import.
|
||||
*
|
||||
* @param string $database_state_key
|
||||
* The state key.
|
||||
* @param int $drupal_version
|
||||
* The version of Drupal we're getting the migrations for.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The migrations for import.
|
||||
*/
|
||||
protected function getMigrations($database_state_key, $drupal_version) {
|
||||
$version_tag = 'Drupal ' . $drupal_version;
|
||||
$plugin_manager = \Drupal::service('plugin.manager.migration');
|
||||
/** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
|
||||
$all_migrations = $plugin_manager->createInstancesByTag($version_tag);
|
||||
$migrations = [];
|
||||
foreach ($all_migrations as $migration) {
|
||||
try {
|
||||
// @todo https://drupal.org/node/2681867 We should be able to validate
|
||||
// the entire migration at this point.
|
||||
$source_plugin = $migration->getSourcePlugin();
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
$source_plugin->checkRequirements();
|
||||
}
|
||||
$destination_plugin = $migration->getDestinationPlugin();
|
||||
if ($destination_plugin instanceof RequirementsInterface) {
|
||||
$destination_plugin->checkRequirements();
|
||||
}
|
||||
$migrations[] = $migration;
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// Migrations which are not applicable given the source and destination
|
||||
// site configurations (e.g., what modules are enabled) will be silently
|
||||
// ignored.
|
||||
}
|
||||
}
|
||||
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines what version of Drupal the source database contains.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection object.
|
||||
*
|
||||
* @return int|FALSE
|
||||
* An integer representing the major branch of Drupal core (e.g. '6' for
|
||||
* Drupal 6.x), or FALSE if no valid version is matched.
|
||||
*/
|
||||
protected function getLegacyDrupalVersion(Connection $connection) {
|
||||
// Don't assume because a table of that name exists, that it has the columns
|
||||
// we're querying. Catch exceptions and report that the source database is
|
||||
// not Drupal.
|
||||
// Drupal 5/6/7 can be detected by the schema_version in the system table.
|
||||
if ($connection->schema()->tableExists('system')) {
|
||||
try {
|
||||
$version_string = $connection
|
||||
->query('SELECT schema_version FROM {system} WHERE name = :module', [':module' => 'system'])
|
||||
->fetchField();
|
||||
if ($version_string && $version_string[0] == '1') {
|
||||
if ((int) $version_string >= 1000) {
|
||||
$version_string = '5';
|
||||
}
|
||||
else {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\PDOException $e) {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
}
|
||||
// For Drupal 8 (and we're predicting beyond) the schema version is in the
|
||||
// key_value store.
|
||||
elseif ($connection->schema()->tableExists('key_value')) {
|
||||
$result = $connection
|
||||
->query("SELECT value FROM {key_value} WHERE collection = :system_schema and name = :module", [':system_schema' => 'system.schema', ':module' => 'system'])
|
||||
->fetchField();
|
||||
$version_string = unserialize($result);
|
||||
}
|
||||
else {
|
||||
$version_string = FALSE;
|
||||
}
|
||||
|
||||
return $version_string ? substr($version_string, 0, 1) : FALSE;
|
||||
}
|
||||
use MigrationConfigurationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Plugin manager for migrate cckfield plugins.
|
||||
*
|
||||
* @see \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
* @see \Drupal\migrate\Annotation\MigrateCckField
|
||||
* @see plugin_api
|
||||
*
|
||||
* @ingroup migration
|
||||
*/
|
||||
class MigrateCckFieldPluginManager extends MigratePluginManager {
|
||||
|
||||
/**
|
||||
* The default version of core to use for cck field plugins.
|
||||
*
|
||||
* These plugins were initially only built and used for Drupal 6 fields.
|
||||
* Having been extended for Drupal 7 with a "core" annotation, we fall back to
|
||||
* Drupal 6 where none exists.
|
||||
*/
|
||||
const DEFAULT_CORE_VERSION = 6;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstance($field_type, array $configuration = array(), MigrationInterface $migration = NULL) {
|
||||
$core = static::DEFAULT_CORE_VERSION;
|
||||
if (!empty($configuration['core'])) {
|
||||
$core = $configuration['core'];
|
||||
}
|
||||
elseif (!empty($migration->getPluginDefinition()['migration_tags'])) {
|
||||
foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) {
|
||||
if ($tag == 'Drupal 7') {
|
||||
$core = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->getDefinitions() as $plugin_id => $definition) {
|
||||
if (in_array($core, $definition['core'])) {
|
||||
if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) {
|
||||
return parent::createInstance($plugin_id, $configuration, $migration);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new PluginNotFoundException($field_type);
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@ use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface;
|
|||
/**
|
||||
* The base class for all cck field plugins.
|
||||
*
|
||||
* @see \Drupal\migrate_drupal\Plugin\MigratePluginManager
|
||||
* @see \Drupal\migrate\Plugin\MigratePluginManager
|
||||
* @see \Drupal\migrate_drupal\Annotation\MigrateCckField
|
||||
* @see \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
* @see plugin_api
|
||||
|
|
|
@ -3089,24 +3089,6 @@ $connection->schema()->createTable('content_type_page', array(
|
|||
'mysql_character_set' => 'utf8',
|
||||
));
|
||||
|
||||
$connection->insert('content_type_page')
|
||||
->fields(array(
|
||||
'vid',
|
||||
'nid',
|
||||
'field_text_field_value',
|
||||
))
|
||||
->values(array(
|
||||
'vid' => '1',
|
||||
'nid' => '1',
|
||||
'field_text_field_value' => NULL,
|
||||
))
|
||||
->values(array(
|
||||
'vid' => '3',
|
||||
'nid' => '1',
|
||||
'field_text_field_value' => NULL,
|
||||
))
|
||||
->execute();
|
||||
|
||||
$connection->schema()->createTable('content_type_story', array(
|
||||
'fields' => array(
|
||||
'nid' => array(
|
||||
|
@ -3420,9 +3402,9 @@ $connection->insert('content_type_story')
|
|||
'field_test_three_value' => '101.00',
|
||||
'field_test_identical1_value' => NULL,
|
||||
'field_test_identical2_value' => NULL,
|
||||
'field_test_link_url' => 'http://www.example.com/buy-one-upon-a-time',
|
||||
'field_test_link_url' => 'node/10',
|
||||
'field_test_link_title' => 'Buy it now',
|
||||
'field_test_link_attributes' => 'a:1:{s:6:"target";s:6:"_blank";}',
|
||||
'field_test_link_attributes' => 's:32:"a:1:{s:6:"target";s:6:"_blank";}";',
|
||||
'field_test_date_value' => NULL,
|
||||
'field_test_datestamp_value' => NULL,
|
||||
'field_test_datetime_value' => NULL,
|
||||
|
@ -45551,6 +45533,14 @@ $connection->insert('variable')
|
|||
'name' => 'language_content_type_article',
|
||||
'value' => 's:1:"2";',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'language_content_type_employee',
|
||||
'value' => 's:1:"2";',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'i18n_lock_node_article',
|
||||
'value' => 'i:1;',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'language_count',
|
||||
'value' => 'i:11;',
|
||||
|
|
|
@ -40789,7 +40789,7 @@ $connection->insert('users')
|
|||
->values(array(
|
||||
'uid' => '2',
|
||||
'name' => 'Odo',
|
||||
'pass' => '$S$DZ4P7zZOh92vgrgZDBbv8Pu6lQB337OJ1wsOy21602G4A5F7.M9K',
|
||||
'pass' => '$S$DGFZUE.FhrXbe4y52eC7p0ZVRGD/gOPtVctDlmC89qkujnBokAlJ',
|
||||
'mail' => 'odo@local.host',
|
||||
'theme' => '',
|
||||
'signature' => '',
|
||||
|
@ -41322,6 +41322,10 @@ $connection->insert('variable')
|
|||
'name' => 'language_content_type_test_content_type',
|
||||
'value' => 's:1:"0";',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'i18n_node_options_blog',
|
||||
'value' => 'a:2:{i:0;s:8:"required";i:1;s:4:"lock";}',
|
||||
))
|
||||
->values(array(
|
||||
'name' => 'language_count',
|
||||
'value' => 'i:2;',
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate cck field plugin manager test'
|
||||
type: module
|
||||
description: 'Example module demonstrating the cck field plugin manager in the Migrate API.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_file",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "file" = "file"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class D6FileField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_no_core_version_specified"
|
||||
* )
|
||||
*/
|
||||
class D6NoCoreVersionSpecified extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
||||
/**
|
||||
* Tests the cck field plugin manager.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_cckfield_plugin_manager_test');
|
||||
|
||||
/**
|
||||
* Tests that the correct MigrateCckField plugins are used.
|
||||
*/
|
||||
public function testPluginSelection() {
|
||||
$plugin_manager = \Drupal::service('plugin.manager.migrate.cckfield');
|
||||
|
||||
$this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d6\\FileField', get_class($plugin_manager->createInstance('filefield', ['core' => 6])));
|
||||
|
||||
try {
|
||||
// If this test passes, createInstance will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->createInstance('filefield', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
|
||||
}
|
||||
|
||||
$this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d7\\ImageField', get_class($plugin_manager->createInstance('image', ['core' => 7])));
|
||||
$this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d7\\FileField', get_class($plugin_manager->createInstance('file', ['core' => 7])));
|
||||
$this->assertIdentical('Drupal\\migrate_cckfield_plugin_manager_test\\Plugin\\migrate\\cckfield\\D6FileField', get_class($plugin_manager->createInstance('file', ['core' => 6])));
|
||||
|
||||
$this->assertIdentical('Drupal\\text\\Plugin\\migrate\\cckfield\\TextField', get_class($plugin_manager->createInstance('text', ['core' => 6])));
|
||||
$this->assertIdentical('Drupal\\text\\Plugin\\migrate\\cckfield\\TextField', get_class($plugin_manager->createInstance('text', ['core' => 7])));
|
||||
|
||||
// Test fallback when no core version is specified.
|
||||
$this->assertIdentical('Drupal\\migrate_cckfield_plugin_manager_test\\Plugin\\migrate\\cckfield\\D6NoCoreVersionSpecified', get_class($plugin_manager->createInstance('d6_no_core_version_specified', ['core' => 6])));
|
||||
|
||||
try {
|
||||
// If this test passes, createInstance will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->createInstance('d6_no_core_version_specified', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertIdentical($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,14 @@ abstract class MigrateDrupal6TestBase extends MigrateDrupalTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadFixture( __DIR__ . '/../../../fixtures/drupal6.php');
|
||||
$this->loadFixture($this->getFixtureFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the fixture file.
|
||||
*/
|
||||
protected function getFixtureFilePath() {
|
||||
return __DIR__ . '/../../../fixtures/drupal6.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,7 +14,14 @@ abstract class MigrateDrupal7TestBase extends MigrateDrupalTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadFixture(__DIR__ . '/../../../fixtures/drupal7.php');
|
||||
$this->loadFixture($this->getFixtureFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the fixture file.
|
||||
*/
|
||||
protected function getFixtureFilePath() {
|
||||
return __DIR__ . '/../../../fixtures/drupal7.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue