addfolder
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
name: 'Field Group Migrate'
|
||||
type: module
|
||||
description: 'Provides the ability to migrate field groups from D6/D7 to D8.'
|
||||
package: Migrate
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- field_group:field_group
|
||||
|
||||
# Information added by Drupal.org packaging script on 2016-11-28
|
||||
version: '8.x-1.0-rc6'
|
||||
core: '8.x'
|
||||
project: 'field_group'
|
||||
datestamp: 1480365490
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- migrate.migration.d6_field_instance
|
||||
module:
|
||||
- field_group_migrate
|
||||
- node
|
||||
id: d6_field_group_entity_form_display
|
||||
migration_tags:
|
||||
- 'Drupal 6'
|
||||
label: 'Field groups'
|
||||
source:
|
||||
plugin: d6_field_group
|
||||
constants:
|
||||
mode: entity_form_display
|
||||
entity_type: node
|
||||
form_mode: default
|
||||
third_party_settings: { }
|
||||
process:
|
||||
mode: constants/mode
|
||||
entity_type: constants/entity_type
|
||||
bundle: type_name
|
||||
form_mode: constants/form_mode
|
||||
id:
|
||||
plugin: concat
|
||||
source:
|
||||
- group_name
|
||||
delimiter: .
|
||||
field_group/label: label
|
||||
field_group/weight: weight
|
||||
field_group/children: children
|
||||
field_group/format_type: converted_settings/format_type
|
||||
field_group/format_settings: converted_settings/format_settings
|
||||
destination:
|
||||
plugin: field_group_entity_form_display
|
||||
template: d6_field_instance_widget_settings
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_field_instance
|
||||
migration_group: null
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- migrate.migration.d6_field_instance
|
||||
module:
|
||||
- field_group_migrate
|
||||
- node
|
||||
id: d6_field_group_entity_view_display
|
||||
migration_tags:
|
||||
- 'Drupal 6'
|
||||
label: 'Field groups'
|
||||
source:
|
||||
plugin: d6_field_group
|
||||
constants:
|
||||
mode: entity_view_display
|
||||
entity_type: node
|
||||
third_party_settings: { }
|
||||
process:
|
||||
mode: constants/mode
|
||||
entity_type: constants/entity_type
|
||||
bundle: type_name
|
||||
id:
|
||||
plugin: concat
|
||||
source:
|
||||
- group_name
|
||||
delimiter: .
|
||||
field_group/label: label
|
||||
field_group/weight: weight
|
||||
field_group/children: children
|
||||
field_group/format_type: converted_settings/format_type
|
||||
field_group/format_settings: converted_settings/format_settings
|
||||
destination:
|
||||
plugin: field_group_entity_view_display
|
||||
template: d6_field_instance_widget_settings
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_field_instance
|
||||
migration_group: null
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
id: d7_field_group
|
||||
label: Field groups
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d7_field_group
|
||||
process:
|
||||
entity_type: entity_type
|
||||
bundle: bundle
|
||||
mode:
|
||||
plugin: static_map
|
||||
source: mode
|
||||
bypass: true
|
||||
map:
|
||||
form: default
|
||||
type:
|
||||
plugin: static_map
|
||||
source: mode
|
||||
default_value: entity_view_display
|
||||
map:
|
||||
form: entity_form_display
|
||||
group_name: group_name
|
||||
settings: settings
|
||||
destination:
|
||||
plugin: d7_field_group
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_field_formatter_settings
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field_group_migrate\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\destination\PerComponentEntityFormDisplay;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This class imports one field_group of an entity form display.
|
||||
*
|
||||
* @MigrateDestination(
|
||||
* id = "field_group_entity_form_display"
|
||||
* )
|
||||
*/
|
||||
class FieldGroupEntityFormDisplay extends PerComponentEntityFormDisplay {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
$values = array();
|
||||
// array_intersect_key() won't work because the order is important because
|
||||
// this is also the return value.
|
||||
foreach (array_keys($this->getIds()) as $id) {
|
||||
$values[$id] = $row->getDestinationProperty($id);
|
||||
}
|
||||
$entity = $this->getEntity($values['entity_type'], $values['bundle'], $values[static::MODE_NAME]);
|
||||
if (!$entity->isNew()) {
|
||||
$settings = $row->getDestinationProperty('field_group');
|
||||
$entity->setThirdPartySetting('field_group', $row->getDestinationProperty('id'), $settings);
|
||||
if (isset($settings['format_type']) && ($settings['format_type'] == 'no_style' || $settings['format_type'] == 'hidden')) {
|
||||
$entity->unsetThirdPartySetting('field_group', $row->getDestinationProperty('id'));
|
||||
}
|
||||
$entity->save();
|
||||
}
|
||||
return array_values($values);
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field_group_migrate\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\destination\PerComponentEntityDisplay;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This class imports one field_group of an entity form display.
|
||||
*
|
||||
* @MigrateDestination(
|
||||
* id = "field_group_entity_view_display"
|
||||
* )
|
||||
*/
|
||||
class FieldGroupEntityViewDisplay extends PerComponentEntityDisplay {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
$values = array();
|
||||
// array_intersect_key() won't work because the order is important because
|
||||
// this is also the return value.
|
||||
foreach (array_keys($this->getIds()) as $id) {
|
||||
$values[$id] = $row->getDestinationProperty($id);
|
||||
}
|
||||
|
||||
foreach ($row->getSourceProperty('view_modes') as $view_mode => $settings) {
|
||||
$entity = $this->getEntity($values['entity_type'], $values['bundle'], $view_mode);
|
||||
if (!$entity->isNew()) {
|
||||
$settings = array_merge($row->getDestinationProperty('field_group'), $settings);
|
||||
$entity->setThirdPartySetting('field_group', $row->getDestinationProperty('id'), $settings);
|
||||
if (isset($settings['format_type']) && ($settings['format_type'] == 'no_style' || $settings['format_type'] == 'hidden')) {
|
||||
$entity->unsetThirdPartySetting('field_group', $row->getDestinationProperty('id'));
|
||||
}
|
||||
$entity->save();
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($values);
|
||||
}
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field_group_migrate\Plugin\migrate\destination\d7\FieldGroup.
|
||||
*/
|
||||
|
||||
namespace Drupal\field_group_migrate\Plugin\migrate\destination\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* This class imports one field_group of an entity form display.
|
||||
*
|
||||
* @MigrateDestination(
|
||||
* id = "d7_field_group"
|
||||
* )
|
||||
*/
|
||||
class FieldGroup extends DestinationBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import(Row $row, array $old_destination_id_values = array()) {
|
||||
$values = array();
|
||||
// array_intersect_key() won't work because the order is important because
|
||||
// this is also the return value.
|
||||
foreach (array_keys($this->getIds()) as $id) {
|
||||
$values[$id] = $row->getDestinationProperty($id);
|
||||
}
|
||||
|
||||
$entity = $this->getEntity($values['entity_type'], $values['bundle'], $values['mode'], $values['type']);
|
||||
if (!$entity->isNew()) {
|
||||
$settings = $row->getDestinationProperty('settings');
|
||||
$entity->setThirdPartySetting('field_group', $row->getDestinationProperty('group_name'), $settings);
|
||||
if (isset($settings['format_type']) && ($settings['format_type'] == 'hidden')) {
|
||||
$entity->unsetThirdPartySetting('field_group', $row->getDestinationProperty('group_name'));
|
||||
}
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
return array_values($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['entity_type']['type'] = 'string';
|
||||
$ids['bundle']['type'] = 'string';
|
||||
$ids['mode']['type'] = 'string';
|
||||
$ids['type']['type'] = 'string';
|
||||
$ids['group_name']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rollback(array $destination_identifier) {
|
||||
$entity = $this->getEntity($destination_identifier['entity_type'], $destination_identifier['bundle'], $destination_identifier['mode'], $destination_identifier['type']);
|
||||
if (!$entity->isNew()) {
|
||||
$entity->unsetThirdPartySetting('field_group', $destination_identifier['group_name']);
|
||||
$entity->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields(MigrationInterface $migration = NULL) {
|
||||
// This is intentionally left empty.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type to retrieve.
|
||||
* @param string $bundle
|
||||
* The entity bundle.
|
||||
* @param string $mode
|
||||
* The display mode.
|
||||
* @param string $type
|
||||
* The destination type.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\Display\EntityDisplayInterface
|
||||
* The entity display object.
|
||||
*/
|
||||
protected function getEntity($entity_type, $bundle, $mode, $type) {
|
||||
$function = $type == 'entity_form_display' ? 'entity_get_form_display' : 'entity_get_display';
|
||||
return $function($entity_type, $bundle, $mode);
|
||||
}
|
||||
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field_group_migrate\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 field_group source.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_field_group"
|
||||
* )
|
||||
*/
|
||||
class FieldGroup extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('content_group', 'g')
|
||||
->fields('g', [
|
||||
'group_type',
|
||||
'type_name',
|
||||
'group_name',
|
||||
'label',
|
||||
'settings',
|
||||
'weight',
|
||||
]);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$query = $this->select('content_group_fields', 'f');
|
||||
$query->fields('f', ['field_name'])
|
||||
->condition('type_name', $row->getSourceProperty('type_name'))
|
||||
->condition('group_name', $row->getSourceProperty('group_name'));
|
||||
$fields = $query->execute()->fetchCol();
|
||||
$row->setSourceProperty('children', $fields);
|
||||
$row->setSourceProperty('settings', unserialize($row->getSourceProperty('settings')));
|
||||
|
||||
switch ($row->getSourceProperty('constants/mode')) {
|
||||
case 'entity_form_display':
|
||||
$this->transformEntityFormDisplaySettings($row);
|
||||
break;
|
||||
|
||||
case 'entity_view_display':
|
||||
$this->transformEntityViewDisplaySettings($row);
|
||||
break;
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
protected function transformEntityFormDisplaySettings(Row $row) {
|
||||
$row->setSourceProperty('extracted_settings', $row->getSourceProperty('settings/form'));
|
||||
$source_settings = $row->getSourceProperty('extracted_settings');
|
||||
$settings = [
|
||||
'format_type' => 'details',
|
||||
'format_settings' => [],
|
||||
];
|
||||
|
||||
switch ($source_settings['style']) {
|
||||
case 'no_style':
|
||||
$settings['format_type'] = 'no_style';
|
||||
break;
|
||||
|
||||
case 'simple':
|
||||
$settings['format_type'] = 'html_element';
|
||||
$settings['format_settings']['element'] = 'div';
|
||||
$settings['format_settings']['label_element'] = 'h2';
|
||||
break;
|
||||
|
||||
case 'fieldset':
|
||||
$settings['format_type'] = 'fieldset';
|
||||
break;
|
||||
|
||||
case 'fieldset_collapsible':
|
||||
$settings['format_type'] = 'details';
|
||||
$settings['format_settings']['open'] = TRUE;
|
||||
break;
|
||||
|
||||
case 'fieldset_collapsed':
|
||||
$settings['format_type'] = 'details';
|
||||
$settings['format_settings']['open'] = FALSE;
|
||||
break;
|
||||
|
||||
case 'hidden':
|
||||
$settings['format_type'] = 'hidden';
|
||||
break;
|
||||
}
|
||||
|
||||
$row->setSourceProperty('converted_settings', $settings);
|
||||
}
|
||||
|
||||
protected function transformEntityViewDisplaySettings(Row $row) {
|
||||
$row->setSourceProperty('extracted_settings', $row->getSourceProperty('settings/display'));
|
||||
$view_modes = array_diff(array_keys($row->getSourceProperty('extracted_settings')), ['label', 'description', 'weight']);
|
||||
$view_modes = array_filter($view_modes, function ($value) {
|
||||
return !is_numeric($value);
|
||||
});
|
||||
$row->setSourceProperty('view_mode_keys', $view_modes);
|
||||
$view_modes = [];
|
||||
|
||||
foreach ($row->getSourceProperty('view_mode_keys') as $view_mode) {
|
||||
$source_settings = $row->getSourceProperty('extracted_settings/' . $view_mode);
|
||||
$row->setSourceProperty('view_modes', []);
|
||||
$settings = [
|
||||
'format_type' => 'details',
|
||||
'format_settings' => [],
|
||||
];
|
||||
|
||||
switch ($source_settings['format']) {
|
||||
case 'no_style':
|
||||
$settings['format_type'] = 'no_style';
|
||||
break;
|
||||
|
||||
case 'simple':
|
||||
$settings['format_type'] = 'html_element';
|
||||
$settings['format_settings']['element'] = 'div';
|
||||
$settings['format_settings']['label_element'] = 'h2';
|
||||
break;
|
||||
|
||||
case 'fieldset':
|
||||
$settings['format_type'] = 'fieldset';
|
||||
break;
|
||||
|
||||
case 'fieldset_collapsible':
|
||||
$settings['format_type'] = 'details';
|
||||
$settings['format_settings']['open'] = TRUE;
|
||||
break;
|
||||
|
||||
case 'fieldset_collapsed':
|
||||
$settings['format_type'] = 'details';
|
||||
$settings['format_settings']['open'] = FALSE;
|
||||
break;
|
||||
|
||||
case 'hidden':
|
||||
$settings['format_type'] = 'hidden';
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo: ?
|
||||
*/
|
||||
if ($view_mode == 'full') {
|
||||
$view_mode = 'default';
|
||||
}
|
||||
|
||||
// $row->setSourceProperty('view_modes/' . $view_mode, $settings);
|
||||
$view_modes[$view_mode] = $settings;
|
||||
}
|
||||
|
||||
$row->setSourceProperty('view_modes', $view_modes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['type_name']['type'] = 'string';
|
||||
$ids['type_name']['alias'] = 'g';
|
||||
|
||||
$ids['group_name']['type'] = 'string';
|
||||
$ids['group_name']['alias'] = 'g';
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = [
|
||||
'group_type',
|
||||
'type_name',
|
||||
'group_name',
|
||||
'label',
|
||||
'settings',
|
||||
'weight'
|
||||
];
|
||||
return array_combine($fields, $fields);
|
||||
}
|
||||
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field_group_migrate\Plugin\migrate\source\d7\FieldGroup.
|
||||
*/
|
||||
|
||||
namespace Drupal\field_group_migrate\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 7 field_group source.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_field_group"
|
||||
* )
|
||||
*/
|
||||
class FieldGroup extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('field_group', 'f')->fields('f');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$data = unserialize($row->getSourceProperty('data'));
|
||||
$format_settings = $data['format_settings'] + $data['format_settings']['instance_settings'];
|
||||
unset($format_settings['instance_settings']);
|
||||
$settings = array(
|
||||
'children' => $data['children'],
|
||||
'parent_name' => $row->getSourceProperty('parent_name'),
|
||||
'weight' => $data['weight'],
|
||||
'label' => $data['label'],
|
||||
'format_settings' => $format_settings,
|
||||
'format_type' => $data['format_type'],
|
||||
);
|
||||
switch ($data['format_type']) {
|
||||
case 'div':
|
||||
$settings['format_type'] = 'html_element';
|
||||
$settings['format_settings']['element'] = 'div';
|
||||
break;
|
||||
|
||||
case 'tabs':
|
||||
$settings['format_type'] = 'tabs';
|
||||
$settings['format_settings']['direction'] = 'vertical';
|
||||
break;
|
||||
|
||||
case 'htabs':
|
||||
$settings['format_type'] = 'tabs';
|
||||
$settings['format_settings']['direction'] = 'horizontal';
|
||||
break;
|
||||
|
||||
case 'htab':
|
||||
$settings['format_type'] = 'tab';
|
||||
break;
|
||||
|
||||
case 'multipage-group':
|
||||
// @todo Check if there is a better way to deal with this format type.
|
||||
$settings['format_type'] = 'tabs';
|
||||
break;
|
||||
|
||||
case 'multipage':
|
||||
// @todo Check if there is a better way to deal with this format type.
|
||||
$settings['format_type'] = 'tab';
|
||||
break;
|
||||
|
||||
}
|
||||
$row->setSourceProperty('settings', $settings);
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['id']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
'id' => $this->t('ID'),
|
||||
'identifier' => $this->t('Identifier'),
|
||||
'group_name' => $this->t('Group name'),
|
||||
'entity_type' => $this->t('Entity type'),
|
||||
'bundle' => $this->t('Bundle'),
|
||||
'mode' => $this->t('View mode'),
|
||||
'parent_name' => $this->t('Parent name'),
|
||||
'data' => $this->t('Data'),
|
||||
);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* A database agnostic dump for testing purposes.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
$connection->schema()->createTable('field_group', array(
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
),
|
||||
'identifier' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '255',
|
||||
'default' => '',
|
||||
),
|
||||
'group_name' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
),
|
||||
'entity_type' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
),
|
||||
'bundle' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '128',
|
||||
'default' => '',
|
||||
),
|
||||
'mode' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '128',
|
||||
'default' => '',
|
||||
),
|
||||
'parent_name' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
),
|
||||
'data' => array(
|
||||
'type' => 'blob',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
),
|
||||
),
|
||||
'primary key' => array(
|
||||
'id',
|
||||
),
|
||||
'unique keys' => array(
|
||||
'identifier' => array(
|
||||
'identifier',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'group_name' => array(
|
||||
'group_name',
|
||||
),
|
||||
),
|
||||
'mysql_character_set' => 'utf8',
|
||||
));
|
||||
|
||||
$connection->insert('field_group')
|
||||
->fields(array(
|
||||
'id',
|
||||
'identifier',
|
||||
'group_name',
|
||||
'entity_type',
|
||||
'bundle',
|
||||
'mode',
|
||||
'parent_name',
|
||||
'data',
|
||||
))
|
||||
->values(array(
|
||||
'id' => '1',
|
||||
'identifier' => 'group_page|node|page|default',
|
||||
'group_name' => 'group_page',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'mode' => 'default',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:10:"Node group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
))
|
||||
->values(array(
|
||||
'id' => '2',
|
||||
'identifier' => 'group_user|user|user|default',
|
||||
'group_name' => 'group_user',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'mode' => 'default',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:17:"User group parent";s:6:"weight";i:1;s:8:"children";a:0:{}s:11:"format_type";s:3:"div";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
))
|
||||
->values(array(
|
||||
'id' => '3',
|
||||
'identifier' => 'group_user_child|user|user|default',
|
||||
'group_name' => 'group_user_child',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'mode' => 'default',
|
||||
'parent_name' => 'group_user',
|
||||
'data' => 'a:5:{s:5:"label";s:16:"User group child";s:6:"weight";i:99;s:8:"children";a:1:{i:0;s:12:"user_picture";}s:11:"format_type";s:4:"tabs";s:15:"format_settings";a:2:{s:5:"label";s:16:"User group child";s:17:"instance_settings";a:2:{s:7:"classes";s:16:"user-group-child";s:2:"id";s:33:"group_article_node_article_teaser";}}}',
|
||||
))
|
||||
->values(array(
|
||||
'id' => '4',
|
||||
'identifier' => 'group_article|node|article|teaser',
|
||||
'group_name' => 'group_article',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'mode' => 'teaser',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:10:"htab group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:1:{s:7:"classes";s:10:"htab-group";}}}',
|
||||
))
|
||||
->values(array(
|
||||
'id' => '5',
|
||||
'identifier' => 'group_page|node|page|form',
|
||||
'group_name' => 'group_page',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'mode' => 'form',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:15:"Node form group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
))
|
||||
->values(array(
|
||||
'id' => '6',
|
||||
'identifier' => 'group_article|node|article|form',
|
||||
'group_name' => 'group_article',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'mode' => 'form',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:15:"htab form group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
))
|
||||
->execute();
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field_group_migrate\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests field group migration.
|
||||
*
|
||||
* @group field_group
|
||||
*/
|
||||
class MigrateFieldGroupTest extends MigrateDrupal7TestBase {
|
||||
|
||||
static $modules = [
|
||||
'field_group',
|
||||
'field_group_migrate',
|
||||
'comment',
|
||||
'datetime',
|
||||
'image',
|
||||
'link',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadFixture(__DIR__ . '/../../../../fixtures/drupal7.php');
|
||||
|
||||
$this->installConfig(static::$modules);
|
||||
|
||||
$this->executeMigrations([
|
||||
'd7_node_type',
|
||||
'd7_comment_type',
|
||||
'd7_view_modes',
|
||||
'd7_field',
|
||||
'd7_field_instance',
|
||||
'd7_field_formatter_settings',
|
||||
'd7_field_group',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a migrated field group.
|
||||
*
|
||||
* @param $id
|
||||
* The id of the entity display to which the field group applies.
|
||||
* @param $type
|
||||
* The destination type.
|
||||
* @param $group_name
|
||||
* The name of the field group.
|
||||
* @param $expected_label
|
||||
* The expected label.
|
||||
* @param int $expected_weight
|
||||
* The expected label.
|
||||
* @param array $expected_format_settings
|
||||
* The expected format settings.
|
||||
* @param string $expected_format_type
|
||||
* The expected format type.
|
||||
* @param array $expected_children
|
||||
* The expected children.
|
||||
* @param string $expected_parent_name
|
||||
* The expected parent name.
|
||||
*/
|
||||
protected function assertEntity($id, $type, $group_name, $expected_label, $expected_weight = 0, $expected_format_settings = [], $expected_format_type = 'tabs', $expected_children = [], $expected_parent_name = '') {
|
||||
/** @var EntityDisplayInterface $entity */
|
||||
$entity = \Drupal::entityTypeManager()
|
||||
->getStorage($type)
|
||||
->load($id);
|
||||
$field_group_settings = $entity->getThirdPartySettings('field_group');
|
||||
$this->assertNotEmpty($field_group_settings);
|
||||
$this->assertArrayHasKey($group_name, $field_group_settings);
|
||||
$field_group = $field_group_settings[$group_name];
|
||||
$this->assertEquals($expected_label, $field_group['label']);
|
||||
$this->assertEquals($expected_format_settings, $field_group['format_settings']);
|
||||
$this->assertEquals($expected_children, $field_group['children']);
|
||||
$this->assertEquals($expected_parent_name, $field_group['parent_name']);
|
||||
$this->assertEquals($expected_weight, $field_group['weight']);
|
||||
$this->assertEquals($expected_format_type, $field_group['format_type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test field group migration from Drupal 7 to 8.
|
||||
*/
|
||||
public function testFieldGroup() {
|
||||
$this->assertEntity('node.page.default', 'entity_view_display', 'group_page', 'Node group', 0, ['direction' => 'horizontal']);
|
||||
$this->assertEntity('user.user.default', 'entity_view_display', 'group_user', 'User group parent', 1, ['element' => 'div'], 'html_element');
|
||||
$this->assertEntity('user.user.default', 'entity_view_display', 'group_user_child', 'User group child', 99, ['direction' => 'vertical', 'label' => 'User group child', 'classes' => 'user-group-child', 'id' => 'group_article_node_article_teaser'], 'tabs', ['user_picture'], 'group_user');
|
||||
$this->assertEntity('node.article.teaser', 'entity_view_display', 'group_article', 'htab group', 2, ['classes' => 'htab-group'], 'tab', ['field_image']);
|
||||
|
||||
// Check an entity_view_display without a field group.
|
||||
/** @var EntityDisplayInterface $entity */
|
||||
$entity = \Drupal::entityTypeManager()
|
||||
->getStorage('entity_view_display')
|
||||
->load('node.page.teaser');
|
||||
$field_group_settings = $entity->getThirdPartySettings('field_group');
|
||||
$this->assertEmpty($field_group_settings);
|
||||
|
||||
$this->assertEntity('node.page.default', 'entity_form_display', 'group_page', 'Node form group', 0, ['direction' => 'horizontal']);
|
||||
$this->assertEntity('node.article.default', 'entity_form_display', 'group_article', 'htab form group', 2, [], 'tab', ['field_image']);
|
||||
|
||||
// Check an entity_form_display without a field group.
|
||||
$entity = \Drupal::entityTypeManager()
|
||||
->getStorage('entity_form_display')
|
||||
->load('node.blog.default');
|
||||
$field_group_settings = $entity->getThirdPartySettings('field_group');
|
||||
$this->assertEmpty($field_group_settings);
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field_group_migrate\Unit\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 field group source plugin.
|
||||
*
|
||||
* @group field_group
|
||||
*/
|
||||
class FieldGroupTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\field_group_migrate\Plugin\migrate\source\d7\FieldGroup';
|
||||
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
'source' => [
|
||||
'plugin' => 'd7_field_group',
|
||||
],
|
||||
];
|
||||
|
||||
protected $expectedResults = [
|
||||
[
|
||||
'id' => '1',
|
||||
'identifier' => 'group_page|node|page|default',
|
||||
'group_name' => 'group_page',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'mode' => 'default',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:10:"Node group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'identifier' => 'group_user|user|user|default',
|
||||
'group_name' => 'group_user',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'mode' => 'default',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:17:"User group parent";s:6:"weight";i:1;s:8:"children";a:0:{}s:11:"format_type";s:3:"div";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
],
|
||||
[
|
||||
'id' => '3',
|
||||
'identifier' => 'group_user_child|user|user|default',
|
||||
'group_name' => 'group_user_child',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'mode' => 'default',
|
||||
'parent_name' => 'group_user',
|
||||
'data' => 'a:5:{s:5:"label";s:16:"User group child";s:6:"weight";i:99;s:8:"children";a:1:{i:0;s:12:"user_picture";}s:11:"format_type";s:4:"tabs";s:15:"format_settings";a:2:{s:5:"label";s:16:"User group child";s:17:"instance_settings";a:2:{s:7:"classes";s:16:"user-group-child";s:2:"id";s:33:"group_article_node_article_teaser";}}}',
|
||||
],
|
||||
[
|
||||
'id' => '4',
|
||||
'identifier' => 'group_article|node|article|teaser',
|
||||
'group_name' => 'group_article',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'mode' => 'teaser',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:10:"htab group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:1:{s:7:"classes";s:10:"htab-group";}}}',
|
||||
],
|
||||
[
|
||||
'id' => '5',
|
||||
'identifier' => 'group_page|node|page|form',
|
||||
'group_name' => 'group_page',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'mode' => 'form',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:15:"Node form group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
],
|
||||
[
|
||||
'id' => '6',
|
||||
'identifier' => 'group_article|node|article|form',
|
||||
'group_name' => 'group_article',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'mode' => 'form',
|
||||
'parent_name' => '',
|
||||
'data' => 'a:5:{s:5:"label";s:15:"htab form group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['field_group'] = $this->expectedResults;
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user