diff --git a/core/modules/link/config/schema/link.schema.yml b/core/modules/link/config/schema/link.schema.yml index 01a8a65..aa7226a 100644 --- a/core/modules/link/config/schema/link.schema.yml +++ b/core/modules/link/config/schema/link.schema.yml @@ -60,3 +60,27 @@ field.value.link: url: type: string label: 'URL' + options: + type: mapping + label: 'Link options' + mapping: + query: + type: string + label: 'Url query string' + fragment: + type: string + label: 'Url fragment' + absolute: + type: boolean + label: 'Is this Url absolute' + language: + type: string + label: 'The language' + https: + type: boolean + label: 'If the Url should use a secure protocol' + attributes: + type: sequence + label: 'Link attributes' + sequence: + - type: string diff --git a/core/modules/migrate_drupal/src/Plugin/CckFieldMigrateSourceInterface.php b/core/modules/migrate_drupal/src/Plugin/CckFieldMigrateSourceInterface.php new file mode 100644 index 0000000..469d29f --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/CckFieldMigrateSourceInterface.php @@ -0,0 +1,24 @@ +create($values); try { $migration->getSourcePlugin()->checkRequirements(); - $fields = array_keys($migration->getSourcePlugin()->fields()); - $migration->process += array_combine($fields, $fields); + + $source_plugin = $migration->getSourcePlugin(); + // Discuss simplifying per field type processing. + // @see https://www.drupal.org/node/2395993 + if ($source_plugin instanceof CckFieldMigrateSourceInterface) { + foreach ($source_plugin->fieldData() as $field_name => $data) { + // Specifically process the link field until core is fixed. + // @see https://www.drupal.org/node/2235457 + if ($data['type'] == 'link') { + $migration->process[$field_name] = [ + 'plugin' => 'd6_cck_link', + 'source' => [ + $field_name, + $field_name . '_title', + $field_name . '_attributes', + ], + ]; + } + else { + $migration->process[$field_name] = $field_name; + } + } + } + else { + $fields = array_keys($migration->getSourcePlugin()->fields()); + $migration->process += array_combine($fields, $fields); + } $migrations[$migration->id()] = $migration; } catch (RequirementsException $e) { diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/CckLink.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/CckLink.php new file mode 100644 index 0000000..d2ecd4b --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/CckLink.php @@ -0,0 +1,39 @@ + []]; } break; } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php index 5e606e2..7273691 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php @@ -10,6 +10,7 @@ use Drupal\migrate\Plugin\SourceEntityInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Drupal\migrate_drupal\Plugin\CckFieldMigrateSourceInterface; /** @@ -19,7 +20,7 @@ * id = "d6_cck_field_values" * ) */ -class CckFieldValues extends DrupalSqlBase implements SourceEntityInterface { +class CckFieldValues extends DrupalSqlBase implements SourceEntityInterface, CckFieldMigrateSourceInterface { /** * The join options between the node and the node_revisions table. @@ -264,6 +265,16 @@ public function fields() { /** * {@inheritdoc} */ + public function fieldData() { + $field_info = $this->getSourceFieldInfo($this->configuration['bundle']); + $field_info['nid'] = ['type' => 'number']; + $field_info['type'] = ['type' => 'text']; + return $field_info; + } + + /** + * {@inheritdoc} + */ public function getIds() { $ids['nid']['type'] = 'integer'; $ids['nid']['alias'] = 'n'; diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php index 7bf45c3..c04e71d 100644 --- a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php +++ b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php @@ -1021,7 +1021,7 @@ public function load() { 'global_settings' => 'a:7:{s:10:"attributes";a:4:{s:6:"target";s:7:"default";s:3:"rel";s:8:"nofollow";s:5:"class";s:0:"";s:5:"title";s:10:"Link Title";}s:7:"display";a:1:{s:10:"url_cutoff";s:2:"80";}s:3:"url";i:0;s:5:"title";s:8:"required";s:11:"title_value";s:0:"";s:13:"enable_tokens";s:0:"";s:12:"validate_url";i:1;}', 'multiple' => 0, 'db_storage' => 1, - 'db_columns' => 'a:0:{}', + 'db_columns' => 'a:3:{s:3:"url";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:2048;s:8:"not null";b:0;s:8:"sortable";b:1;}s:5:"title";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:255;s:8:"not null";b:0;s:8:"sortable";b:1;}s:10:"attributes";a:3:{s:4:"type";s:4:"text";s:4:"size";s:6:"medium";s:8:"not null";b:0;}}', 'active' => 1, )) ->values(array( diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php index 47b1330..55be0d4 100644 --- a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php +++ b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php @@ -513,6 +513,23 @@ public function load() { 'unsigned' => TRUE, 'not null' => FALSE ), + 'field_test_link_url' => array( + 'description' => 'The link field', + 'type' => 'varchar', + 'length' => 2048, + 'not null' => FALSE, + ), + 'field_test_link_title' => array( + 'description' => 'The link field', + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'field_test_link_attributes' => array( + 'description' => 'The link attributes', + 'type' => 'text', + 'not null' => FALSE, + ), ), 'primary key' => array('vid'), )); @@ -525,7 +542,10 @@ public function load() { 'field_test_three_value', 'field_test_integer_selectlist_value', 'field_test_identical1_value', - 'field_test_identical2_value' + 'field_test_identical2_value', + 'field_test_link_url', + 'field_test_link_title', + 'field_test_link_attributes', )) ->values(array( 'nid' => 1, @@ -535,6 +555,45 @@ public function load() { 'field_test_integer_selectlist_value' => '3412', 'field_test_identical1_value' => 1, 'field_test_identical2_value' => 1, + 'field_test_link_url' => 'http://drupal.org/project/drupal', + 'field_test_link_title' => 'Drupal project page', + 'field_test_link_attributes' => 's:32:"a:1:{s:6:"target";s:6:"_blank";}";";', + )) + ->values(array( + 'nid' => 1, + 'vid' => 2, + 'uid' => 1, + 'field_test_three_value' => '42.42', + 'field_test_integer_selectlist_value' => '3412', + 'field_test_identical1_value' => 1, + 'field_test_identical2_value' => 1, + 'field_test_link_url' => 'http://drupal.org/project/drupal', + 'field_test_link_title' => 'Drupal project page', + 'field_test_link_attributes' => 's:32:"a:1:{s:6:"target";s:6:"_blank";}";', + )) + ->values(array( + 'nid' => 2, + 'vid' => 3, + 'uid' => 1, + 'field_test_three_value' => '23.2', + 'field_test_integer_selectlist_value' => '1244', + 'field_test_identical1_value' => 1, + 'field_test_identical2_value' => 1, + 'field_test_link_url' => 'http://groups.drupal.org/', + 'field_test_link_title' => 'Drupal Groups', + 'field_test_link_attributes' => 's:6:"a:0:{}";', + )) + ->values(array( + 'nid' => 2, + 'vid' => 5, + 'uid' => 1, + 'field_test_three_value' => '23.2', + 'field_test_integer_selectlist_value' => '1244', + 'field_test_identical1_value' => 1, + 'field_test_identical2_value' => 1, + 'field_test_link_url' => 'http://groups.drupal.org/', + 'field_test_link_title' => 'Drupal Groups', + 'field_test_link_attributes' => 's:6:"a:0:{}";', )) ->execute(); $this->setModuleVersion('content', 6001); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php index 9d21794..ffbead0 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php @@ -22,7 +22,7 @@ class MigrateCckFieldValuesTest extends MigrateNodeTestBase { * * @var array */ - public static $modules = array('node', 'text'); + public static $modules = array('node', 'text', 'link'); /** * {@inheritdoc} @@ -105,6 +105,17 @@ protected function setUp() { 'bundle' => 'story', ))->save(); + entity_create('field_storage_config', array( + 'entity_type' => 'node', + 'field_name' => 'field_test_link', + 'type' => 'link', + ))->save(); + entity_create('field_config', array( + 'entity_type' => 'node', + 'field_name' => 'field_test_link', + 'bundle' => 'story', + ))->save(); + // Add some id mappings for the dependant migrations. $id_mappings = array( 'd6_field_formatter_settings' => array( @@ -143,10 +154,15 @@ public function testCckFields() { $this->assertEqual($node->field_test_identical1->value, '1', 'Integer value is correct'); $this->assertEqual($node->field_test_identical2->value, '1', 'Integer value is correct'); + // Test that link fields are migrated. + $this->assertIdentical($node->field_test_link->url, 'http://drupal.org/project/drupal'); + $this->assertIdentical($node->field_test_link->title, 'Drupal project page'); + $this->assertIdentical($node->field_test_link->route_parameters, []); + $this->assertIdentical($node->field_test_link->options['attributes'], ['target' => '_blank']); + $planet_node = Node::load(3); $this->assertEqual($planet_node->field_multivalue->value, 33); $this->assertEqual($planet_node->field_multivalue[1]->value, 44); - } } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php index 31f206d..3649ac0 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php @@ -144,6 +144,7 @@ public function testFieldInstanceSettings() { $this->assertEqual($field->getSettings(), $expected); $this->assertEqual('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.'); $this->assertEqual('http://drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.'); + $this->assertIdentical($entity->field_test_link->options['attributes'], []); } /**