Commit 70d573c1 authored by webchick's avatar webchick

Issue #2415335 by phenaproxima, miguelc303, quietone, mikeryan: Migration...

Issue #2415335 by phenaproxima, miguelc303, quietone, mikeryan: Migration Files for Drupal 7 Custom Blocks
parent 695deff3
......@@ -28,3 +28,41 @@ function block_content_update_8001() {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('revision_translation_affected', 'block_content', 'block_content', $storage_definition);
}
/**
* Generalizes the d6_block_content_type and d6_block_content_body_field
* migrations.
*/
function block_content_update_8002() {
if (\Drupal::moduleHandler()->moduleExists('migrate')) {
$config = \Drupal::configFactory();
$templates = \Drupal::service('migrate.template_storage');
$migration = $config->getEditable('migrate.migration.d6_block_content_type');
if ($migration) {
$template = $templates->getTemplateByName('block_content_type');
$migration
->set('id', $template['id'])
->set('label', $template['label'])
->set('migration_tags', $template['migration_tags'])
->set('source', array_merge($migration->get('source'), $template['source']))
->clear('source.constants')
->set('process', $template['process'])
->save(TRUE);
}
$migration = $config->getEditable('migrate.migration.d6_block_content_body_field');
if ($migration) {
$template = $templates->getTemplateByName('block_content_body_field');
$migration
->set('id', $template['id'])
->set('label', $template['label'])
->set('migration_tags', $template['migration_tags'])
->set('source', array_merge($migration->get('source'), $template['source']))
->clear('source.constants')
->set('process', $template['process'])
->set('migration_dependencies', $template['migration_dependencies'])
->save(TRUE);
}
}
}
id: block_content_body_field
label: Block content body field configuration
migration_tags:
- Drupal 6
- Drupal 7
source:
plugin: embedded_data
data_rows:
-
entity_type: block_content
bundle: basic
field_name: body
label: Body
display_summary: false
ids:
entity_type:
type: string
bundle:
type: string
field_name:
type: string
process:
entity_type: entity_type
bundle: bundle
field_name: field_name
label: label
'settings/display_summary': display_summary
destination:
plugin: entity:field_config
migration_dependencies:
required:
- block_content_type
id: d6_block_content_type
id: block_content_type
label: Block content type
migration_tags:
- Drupal 6
- Drupal 7
source:
# We do an empty source and a proper destination to have an idmap for
# migration_dependencies.
plugin: md_empty
constants:
id: basic
label: Basic
plugin: embedded_data
data_rows:
-
id: basic
label: Basic
ids:
id:
type: string
process:
id: 'constants/id'
label: 'constants/label'
id: id
label: label
destination:
plugin: entity:block_content_type
id: d6_block_content_body_field
label: Block content body field configuration
migration_tags:
- Drupal 6
source:
# We do an empty source and a proper destination to have an idmap for
# migration_dependencies.
plugin: md_empty
constants:
entity_type: block_content
bundle: basic
name: body
label: Body
display_summary: false
process:
entity_type: 'constants/entity_type'
bundle: 'constants/bundle'
field_name: 'constants/name'
label: 'constants/label'
'settings/display_summary': 'constants/display_summary'
destination:
plugin: entity:field_config
migration_dependencies:
required:
- d6_block_content_type
......@@ -21,4 +21,4 @@ destination:
migration_dependencies:
required:
- d6_filter_format
- d6_block_content_body_field
- block_content_body_field
id: d7_custom_block
label: Custom blocks
migration_tags:
- Drupal 7
source:
plugin: d7_block_custom
constants:
type: basic
process:
id: bid
type: 'constants/type'
info: info
'body/format':
plugin: migration
migration: d7_filter_format
source: format
'body/value': body
destination:
plugin: entity:block_content
no_stub: true
migration_dependencies:
required:
- d7_filter_format
- block_content_body_field
<?php
/**
* @file
* Contains \Drupal\block_content\Plugin\migrate\source\d7\BlockCustom.
*/
namespace Drupal\block_content\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 custom block source from database.
*
* @MigrateSource(
* id = "d7_block_custom"
* )
*/
class BlockCustom extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('block_custom', 'b')->fields('b');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'bid' => $this->t('The numeric identifier of the block/box'),
'body' => $this->t('The block/box content'),
'info' => $this->t('Admin title of the block/box.'),
'format' => $this->t('Input format of the custom block/box content.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['bid']['type'] = 'integer';
return $ids;
}
}
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\Migrate\MigrateBlockContentBodyFieldTest.
*/
namespace Drupal\block_content\Tests\Migrate;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Attaches a body field to the custom block type.
*
* @group block_content
*/
class MigrateBlockContentBodyFieldTest extends MigrateDrupal7TestBase {
static $modules = array('block', 'block_content', 'filter', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['block_content']);
$this->installEntitySchema('block_content');
$this->executeMigration('block_content_type');
$this->executeMigration('block_content_body_field');
}
/**
* Tests the block content body field migration.
*/
public function testBlockContentBodyFieldMigration() {
/** @var \Drupal\field\FieldStorageConfigInterface $storage */
$storage = FieldStorageConfig::load('block_content.body');
$this->assertTrue($storage instanceof FieldStorageConfigInterface);
$this->assertIdentical('block_content', $storage->getTargetEntityTypeId());
$this->assertIdentical(['basic'], array_values($storage->getBundles()));
$this->assertIdentical('body', $storage->getName());
/** @var \Drupal\field\FieldConfigInterface $field */
$field = FieldConfig::load('block_content.basic.body');
$this->assertTrue($field instanceof FieldConfigInterface);
$this->assertIdentical('block_content', $field->getTargetEntityTypeId());
$this->assertIdentical('basic', $field->getTargetBundle());
$this->assertIdentical('body', $field->getName());
$this->assertIdentical('Body', $field->getLabel());
}
}
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\Migrate\MigrateBlockContentTypeTest.
*/
namespace Drupal\block_content\Tests\Migrate;
use Drupal\block_content\BlockContentTypeInterface;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Tests migration of the basic block content type.
*
* @group block_content
*/
class MigrateBlockContentTypeTest extends MigrateDrupal7TestBase {
static $modules = array('block', 'block_content', 'filter', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['block_content']);
$this->installEntitySchema('block_content');
$this->executeMigration('block_content_type');
}
/**
* Tests the block content type migration.
*/
public function testBlockContentTypeMigration() {
/** @var \Drupal\block_content\BlockContentTypeInterface $entity */
$entity = BlockContentType::load('basic');
$this->assertTrue($entity instanceof BlockContentTypeInterface);
$this->assertIdentical('Basic', $entity->label());
}
}
......@@ -27,8 +27,8 @@ protected function setUp() {
$this->installConfig(array('block_content'));
$this->installEntitySchema('block_content');
$this->executeMigration('d6_block_content_type');
$this->executeMigration('d6_block_content_body_field');
$this->executeMigration('block_content_type');
$this->executeMigration('block_content_body_field');
$this->prepareMigrations(array(
'd6_filter_format' => array(
......
<?php
/**
* @file
* Contains \Drupal\block_content\Tests\Migrate\d7\MigrateCustomBlockTest.
*/
namespace Drupal\block_content\Tests\Migrate\d7;
use Drupal\block_content\BlockContentInterface;
use Drupal\block_content\Entity\BlockContent;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Tests migration of custom blocks.
*
* @group block_content
*/
class MigrateCustomBlockTest extends MigrateDrupal7TestBase {
public static $modules = array(
'block_content',
'filter',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->installEntitySchema('block_content');
$this->executeMigration('d7_filter_format');
$this->executeMigration('block_content_type');
$this->executeMigration('block_content_body_field');
$this->executeMigration('d7_custom_block');
}
/**
* Tests migration of custom blocks from Drupal 7 to Drupal 8.
*/
public function testCustomBlockMigration() {
$block = BlockContent::load(1);
$this->assertTrue($block instanceof BlockContentInterface);
/** @var \Drupal\block_content\BlockContentInterface $block */
$this->assertIdentical('Limerick', $block->label());
$expected_body = "A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall";
$this->assertIdentical($expected_body, $block->body->value);
$this->assertIdentical('filtered_html', $block->body->format);
}
}
......@@ -684,8 +684,34 @@ public function load() {
'pages' => '',
'title' => '',
'cache' => '-1',
))->values(array(
'bid' => '45',
'module' => 'block',
'delta' => '1',
'theme' => 'bartik',
'status' => '0',
'weight' => '0',
'region' => '-1',
'custom' => '0',
'visibility' => '0',
'pages' => '',
'title' => 'Mildly amusing limerick of the day',
'cache' => '-1',
))->values(array(
'bid' => '46',
'module' => 'block',
'delta' => '1',
'theme' => 'seven',
'status' => '0',
'weight' => '0',
'region' => '',
'custom' => '0',
'visibility' => '0',
'pages' => '',
'title' => 'Mildly amusing limerick of the day',
'cache' => '-1',
))->execute();
}
}
#74042b5093754da56e33ac51a867f531
#1c70ba712296177505a2e00cfca073eb
......@@ -56,8 +56,13 @@ public function load() {
'info',
'format',
))
->execute();
->values(array(
'bid' => '1',
'body' => "A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall",
'info' => 'Limerick',
'format' => 'filtered_html',
))->execute();
}
}
#bcecada721307d09075575d51819ab41
#d317035ee9af9b69d78ab3dd0c7072b9
......@@ -73,8 +73,8 @@ class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
'd6_aggregator_feed',
'd6_aggregator_item',
'd6_block',
'd6_block_content_body_field',
'd6_block_content_type',
'block_content_body_field',
'block_content_type',
'd6_book',
'd6_book_settings',
'd6_comment_type',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment