clean install

This commit is contained in:
matze committed 2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 files changed
+3555714

No files matched your search

@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace Drupal\field\Plugin\ConfigAction;
use Drupal\Core\Config\Action\Attribute\ConfigAction;
use Drupal\Core\Config\Action\ConfigActionException;
use Drupal\Core\Config\Action\ConfigActionPluginInterface;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\field\FieldStorageConfigInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Adds a field to all bundles of its target entity type.
*
* @internal
* This API is experimental.
*/
#[ConfigAction(
id: 'field_storage_config:addToAllBundles',
admin_label: new TranslatableMarkup('Add a field to all bundles'),
entity_types: ['field_storage_config'],
)]
final class AddToAllBundles implements ConfigActionPluginInterface, ContainerFactoryPluginInterface {
public function __construct(
private readonly EntityTypeManagerInterface $entityTypeManager,
private readonly EntityTypeBundleInfoInterface $entityTypeBundleInfo,
private readonly ConfigManagerInterface $configManager,
) {}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
return new static(
$container->get(EntityTypeManagerInterface::class),
$container->get(EntityTypeBundleInfoInterface::class),
$container->get(ConfigManagerInterface::class),
);
}
/**
* {@inheritdoc}
*/
public function apply(string $configName, mixed $value): void {
assert(is_array($value));
$field_storage = $this->configManager->loadConfigEntityByName($configName);
assert($field_storage instanceof FieldStorageConfigInterface);
$storage = $this->entityTypeManager->getStorage('field_config');
$entity_type_id = $field_storage->getTargetEntityTypeId();
$field_name = $field_storage->getName();
$existing_fields = $storage->getQuery()
->condition('entity_type', $entity_type_id)
->condition('field_name', $field_name)
->execute();
// Get all bundles of the target entity type.
$bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));
foreach ($bundles as $bundle) {
$id = "$entity_type_id.$bundle.$field_name";
if (in_array($id, $existing_fields, TRUE)) {
if (empty($value['fail_if_exists'])) {
continue;
}
throw new ConfigActionException(sprintf('Field %s already exists.', $id));
}
$storage->create([
'label' => $value['label'],
'bundle' => $bundle,
'description' => $value['description'],
'field_storage' => $field_storage,
])->save();
}
}
}
@@ -0,0 +1,63 @@
<?php
namespace Drupal\field\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Attribute\MigrateField;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
// cspell:ignore spamspan
/**
* MigrateField Plugin for Drupal 6 and 7 email fields.
*/
#[MigrateField(
id: 'email',
core: [6, 7],
type_map: [
'email' => 'email',
],
source_module: 'email',
destination_module: 'core',
)]
class Email extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'email_textfield' => 'email_default',
];
}
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'email_formatter_default' => 'email_mailto',
'email_formatter_contact' => 'basic_string',
'email_formatter_plain' => 'basic_string',
'email_formatter_spamspan' => 'basic_string',
'email_default' => 'email_mailto',
'email_contact' => 'basic_string',
'email_plain' => 'basic_string',
'email_spamspan' => 'basic_string',
];
}
/**
* {@inheritdoc}
*/
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'sub_process',
'source' => $field_name,
'process' => [
'value' => 'email',
],
];
$migration->setProcessOfProperty($field_name, $process);
}
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\field\Plugin\migrate\field\d7;
use Drupal\migrate_drupal\Attribute\MigrateField;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
// cspell:ignore entityreference
/**
* MigrateField plugin for Drupal 7 entity_reference fields.
*/
#[MigrateField(
id: 'entityreference',
core: [7],
type_map: [
'entityreference' => 'entity_reference',
],
source_module: 'entityreference',
destination_module: 'core',
)]
class EntityReference extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'entityreference_label' => 'entity_reference_label',
'entityreference_entity_id' => 'entity_reference_entity_id',
'entityreference_entity_view' => 'entity_reference_entity_view',
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace Drupal\field\Plugin\migrate\field\d7;
use Drupal\migrate_drupal\Attribute\MigrateField;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* MigrateField plugin for Drupal 7 number fields.
*/
#[MigrateField(
id: 'number_default',
core: [7],
type_map: [
'number_integer' => 'integer',
'number_decimal' => 'decimal',
'number_float' => 'float',
],
source_module: 'number',
destination_module: 'core',
)]
class NumberField extends FieldPluginBase {}
@@ -0,0 +1,79 @@
<?php
namespace Drupal\field\Plugin\migrate\process;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\process\StaticMap;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
#[MigrateProcess('field_type')]
class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
/**
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $fieldPluginManager;
/**
* The migration object.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* Constructs a FieldType plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The field plugin manager.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration being run.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateFieldPluginManagerInterface $field_plugin_manager, ?MigrationInterface $migration = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->fieldPluginManager = $field_plugin_manager;
$this->migration = $migration;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.migrate.field'),
$migration
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$field_type = is_array($value) ? $value[0] : $value;
try {
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration);
return $this->fieldPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
}
catch (PluginNotFoundException $e) {
return parent::transform($value, $migrate_executable, $row, $destination_property);
}
}
}
@@ -0,0 +1,136 @@
<?php
namespace Drupal\field\Plugin\migrate\process;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Get the value from a method call on a field plugin instance.
*
* This process plugin will instantiate a field plugin based on the given
* field type and then call the given method on it for the return value.
*
* Available configuration keys:
* - source: The source field type to use to instantiate a field plugin.
* - method: The method to be called on the field plugin instance.
*
* If no field plugin for the given field type is found, NULL will be returned.
*
* Example:
*
* @code
* process:
* type:
* plugin: process_field
* source: type
* method: getFieldType
* @endcode
*
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
* @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
*/
#[MigrateProcess('process_field')]
class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $fieldPluginManager;
/**
* The migration being run.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* Constructs a ProcessField plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The field plugin manager.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration being run.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateFieldPluginManagerInterface $field_plugin_manager, ?MigrationInterface $migration = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->fieldPluginManager = $field_plugin_manager;
$this->migration = $migration;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.migrate.field'),
$migration
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_string($value)) {
throw new MigrateException('The input value must be a string.');
}
if (empty($this->configuration['method'])) {
throw new MigrateException('You need to specify the name of a method to be called on the Field plugin.');
}
$method = $this->configuration['method'];
try {
return $this->callMethodOnFieldPlugin($this->fieldPluginManager, $value, $method, $row);
}
catch (PluginNotFoundException $e) {
return NULL;
}
}
/**
* Instantiate a field plugin and call a method on it.
*
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The field plugin manager.
* @param string $field_type
* The field type for which to get the field plugin.
* @param string $method
* The method to call on the field plugin.
* @param \Drupal\migrate\Row $row
* The row from the source to process.
*
* @return mixed
* The return value from the method called on the field plugin.
*/
protected function callMethodOnFieldPlugin(MigrateFieldPluginManagerInterface $field_plugin_manager, $field_type, $method, Row $row) {
$plugin_id = $field_plugin_manager->getPluginIdFromFieldType($field_type, [], $this->migration);
$plugin_instance = $field_plugin_manager->createInstance($plugin_id, [], $this->migration);
if (!is_callable([$plugin_instance, $method])) {
throw new MigrateException('The specified method does not exist or is not callable.');
}
return call_user_func_array([$plugin_instance, $method], [$row]);
}
}
@@ -0,0 +1,130 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* Set the default field settings.
*/
#[MigrateProcess('field_formatter_settings_defaults')]
class FieldFormatterSettingsDefaults extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Set field formatter settings when the map didn't map: for date
* formatters, the fallback format, for everything else, empty array.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// If the 1 index is set then the map missed.
if (isset($value[1])) {
$module = $row->getSourceProperty('module');
if ($module === 'date') {
$value = ['format_type' => 'fallback'];
}
elseif ($module === 'number') {
// We have to do the lookup here in the process plugin because for
// number we need to calculated the settings based on the type not just
// the module which works well for other field types.
return $this->numberSettings($row->getDestinationProperty('options/type'), $value[1]);
}
else {
$value = [];
}
}
return $value;
}
/**
* @param string $type
* The field type.
* @param $format
* The format selected for the field on the display.
*
* @return array
* The correct default settings.
*
* @throws \Drupal\migrate\MigrateException
*/
protected function numberSettings($type, $format) {
$map = [
'number_decimal' => [
'us_0' => [
'scale' => 0,
'decimal_separator' => '.',
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
],
'us_1' => [
'scale' => 1,
'decimal_separator' => '.',
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
],
'us_2' => [
'scale' => 2,
'decimal_separator' => '.',
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
],
'be_0' => [
'scale' => 0,
'decimal_separator' => ',',
'thousand_separator' => '.',
'prefix_suffix' => TRUE,
],
'be_1' => [
'scale' => 1,
'decimal_separator' => ',',
'thousand_separator' => '.',
'prefix_suffix' => TRUE,
],
'be_2' => [
'scale' => 2,
'decimal_separator' => ',',
'thousand_separator' => '.',
'prefix_suffix' => TRUE,
],
'fr_0' => [
'scale' => 0,
'decimal_separator' => ',',
'thousand_separator' => ' ',
'prefix_suffix' => TRUE,
],
'fr_1' => [
'scale' => 1,
'decimal_separator' => ',',
'thousand_separator' => ' ',
'prefix_suffix' => TRUE,
],
'fr_2' => [
'scale' => 2,
'decimal_separator' => ',',
'thousand_separator' => ' ',
'prefix_suffix' => TRUE,
],
],
'number_integer' => [
'us_0' => [
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
],
'be_0' => [
'thousand_separator' => '.',
'prefix_suffix' => TRUE,
],
'fr_0' => [
'thousand_separator' => ' ',
'prefix_suffix' => TRUE,
],
],
];
return $map[$type][$format] ?? [];
}
}
@@ -0,0 +1,68 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
// cspell:ignore imagefield
/**
* Determines the default field settings.
*/
#[MigrateProcess('d6_field_instance_defaults')]
class FieldInstanceDefaults extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Set the field instance defaults.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$widget_type, $widget_settings] = $value;
$default = [];
switch ($widget_type) {
case 'text_textfield':
case 'number':
case 'phone_textfield':
if (!empty($widget_settings['default_value'][0]['value'])) {
$default['value'] = $widget_settings['default_value'][0]['value'];
}
break;
case 'imagefield_widget':
// @todo load the image and populate the defaults.
// $default['default_image'] = $widget_settings['default_image'];
break;
case 'date_select':
if (!empty($widget_settings['default_value'])) {
$default['default_date_type'] = 'relative';
$default['default_date'] = $widget_settings['default_value'];
}
break;
case 'email_textfield':
if (!empty($widget_settings['default_value'][0]['email'])) {
$default['value'] = $widget_settings['default_value'][0]['email'];
}
break;
case 'link':
if (!empty($widget_settings['default_value'][0]['url'])) {
$default['title'] = $widget_settings['default_value'][0]['title'];
$default['uri'] = $widget_settings['default_value'][0]['url'];
$default['options'] = ['attributes' => []];
}
break;
}
if (!empty($default)) {
$default = [$default];
}
return $default;
}
}
@@ -0,0 +1,53 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Determines the settings property and translation for boolean fields.
*/
#[MigrateProcess(
id: "d6_field_instance_option_translation",
handle_multiples: TRUE,
)]
class FieldInstanceOptionTranslation extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$field_type, $global_settings] = $value;
$option_key = 0;
$translation = '';
if (isset($global_settings['allowed_values'])) {
$list = explode("\n", $global_settings['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
switch ($field_type) {
case 'boolean';
$option = preg_replace('/^option_/', '', $row->getSourceProperty('property'));
for ($i = 0; $i < 2; $i++) {
$value = $list[$i];
$tmp = explode("|", $value);
$original_option_key = $tmp[0] ?? NULL;
$option_key = ($i === 0) ? 'off_label' : 'on_label';
// Find property with name matching the original option.
if ($option == $original_option_key) {
$translation = $row->getSourceProperty('translation');
break;
}
}
break;
default:
}
}
return ['settings.' . $option_key, $translation];
}
}
@@ -0,0 +1,87 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
// cspell:ignore filefield imagefield
/**
* Determines the field instance settings.
*/
#[MigrateProcess('d6_field_field_settings')]
class FieldInstanceSettings extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Set the field instance defaults.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$widget_type, $widget_settings, $field_settings] = $value;
$settings = [];
switch ($widget_type) {
case 'number':
$settings['min'] = $field_settings['min'];
$settings['max'] = $field_settings['max'];
$settings['prefix'] = $field_settings['prefix'];
$settings['suffix'] = $field_settings['suffix'];
break;
case 'link':
// $settings['url'] = $widget_settings['default_value'][0]['url'];
// D6 has optional, required, value and none. D8 only has disabled (0)
// optional (1) and required (2).
$map = ['disabled' => 0, 'optional' => 1, 'required' => 2];
$settings['title'] = $map[$field_settings['title']];
break;
case 'filefield_widget':
$settings['file_extensions'] = $widget_settings['file_extensions'];
$settings['file_directory'] = $widget_settings['file_path'];
$settings['description_field'] = $field_settings['description_field'];
$settings['max_filesize'] = $this->convertSizeUnit($widget_settings['max_filesize_per_file']);
break;
case 'imagefield_widget':
$settings['file_extensions'] = $widget_settings['file_extensions'];
$settings['file_directory'] = $widget_settings['file_path'];
$settings['max_filesize'] = $this->convertSizeUnit($widget_settings['max_filesize_per_file'] ?? '');
$settings['alt_field'] = $widget_settings['alt'];
$settings['alt_field_required'] = $widget_settings['custom_alt'];
$settings['title_field'] = $widget_settings['title'];
$settings['title_field_required'] = $widget_settings['custom_title'];
// With nothing entered for min or max resolution in Drupal 6, zero is
// stored. For Drupal 8 this should be an empty string.
$settings['max_resolution'] = !empty($widget_settings['max_resolution']) ? $widget_settings['max_resolution'] : '';
$settings['min_resolution'] = !empty($widget_settings['min_resolution']) ? $widget_settings['min_resolution'] : '';
break;
}
return $settings;
}
/**
* Convert file size strings into their D8 format.
*
* D6 stores file size using a "K" for kilobytes and "M" for megabytes where
* as D8 uses "KB" and "MB" respectively.
*
* @param string $size_string
* The size string, eg 10M
*
* @return string
* The D8 version of the size string.
*/
protected function convertSizeUnit($size_string) {
$size_unit = substr($size_string, strlen($size_string) - 1);
if ($size_unit == "M" || $size_unit == "K") {
return $size_string . "B";
}
return $size_string;
}
}
@@ -0,0 +1,81 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
// cspell:ignore filefield imagefield optionwidgets
/**
* Get the field instance widget settings.
*/
#[MigrateProcess('field_instance_widget_settings')]
class FieldInstanceWidgetSettings extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Get the field instance default/mapped widget settings.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$widget_type, $widget_settings] = $value;
return $this->getSettings($widget_type, $widget_settings);
}
/**
* Merge the default D8 and specified D6 settings for a widget type.
*
* @param string $widget_type
* The widget type.
* @param array $widget_settings
* The widget settings from D6 for this widget.
*
* @return array
* A valid array of settings.
*/
public function getSettings($widget_type, $widget_settings) {
$progress = $widget_settings['progress_indicator'] ?? 'throbber';
$size = $widget_settings['size'] ?? 60;
$rows = $widget_settings['rows'] ?? 5;
$settings = [
'text_textfield' => [
'size' => $size,
'placeholder' => '',
],
'text_textarea' => [
'rows' => $rows,
'placeholder' => '',
],
'number' => [
'placeholder' => '',
],
'email_textfield' => [
'placeholder' => '',
],
'link' => [
'placeholder_url' => '',
'placeholder_title' => '',
],
'filefield_widget' => [
'progress_indicator' => $progress,
],
'imagefield_widget' => [
'progress_indicator' => $progress,
'preview_image_style' => 'thumbnail',
],
'optionwidgets_onoff' => [
'display_label' => FALSE,
],
'phone_textfield' => [
'placeholder' => '',
],
];
return $settings[$widget_type] ?? [];
}
}
@@ -0,0 +1,59 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Determines the allowed values translation for select lists.
*/
#[MigrateProcess(
id: "d6_field_option_translation",
handle_multiples: TRUE,
)]
class FieldOptionTranslation extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Get the field default/mapped settings.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$field_type, $global_settings] = $value;
$allowed_values = '';
$i = 0;
if (isset($global_settings['allowed_values'])) {
$list = explode("\n", $global_settings['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
switch ($field_type) {
case 'list_string':
case 'list_integer':
case 'list_float':
// Remove the prefix used in the i18n_strings table for field options
// to get the option value.
$option = preg_replace('/^option_/', '', $row->getSourceProperty('property'));
$i = 0;
foreach ($list as $allowed_value) {
// Get the key for this allowed value which may be a key|label pair
// or just key.
$value = explode("|", $allowed_value);
if (isset($value[0]) && ($value[0] == $option)) {
$allowed_values = ['label' => $row->getSourceProperty('translation')];
break;
}
$i++;
}
break;
default:
}
}
return ["settings.allowed_values.$i", $allowed_values];
}
}
@@ -0,0 +1,96 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
// cspell:ignore userreference
/**
* Get the field settings.
*/
#[MigrateProcess('field_settings')]
class FieldSettings extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Get the field default/mapped settings.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// To maintain backwards compatibility, ensure that $value contains at least
// three elements.
if (count($value) == 2) {
$value[] = NULL;
}
[$field_type, $global_settings, $original_field_type] = $value;
return $this->getSettings($field_type, $global_settings, $original_field_type);
}
/**
* Merge the default D8 and specified D6 settings.
*
* @param string $field_type
* The destination field type.
* @param array $global_settings
* The field settings.
* @param string $original_field_type
* (optional) The original field type before migration.
*
* @return array
* A valid array of settings.
*/
public function getSettings($field_type, $global_settings, $original_field_type = NULL) {
$max_length = $global_settings['max_length'] ?? '';
$max_length = empty($max_length) ? 255 : $max_length;
$allowed_values = [];
if (isset($global_settings['allowed_values'])) {
$list = explode("\n", $global_settings['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
switch ($field_type) {
case 'list_string':
case 'list_integer':
case 'list_float':
foreach ($list as $value) {
$value = explode("|", $value);
$allowed_values[$value[0]] = $value[1] ?? $value[0];
}
break;
default:
$allowed_values = $list;
}
}
$settings = [
'text' => [
'max_length' => $max_length,
],
'datetime' => ['datetime_type' => 'datetime'],
'list_string' => [
'allowed_values' => $allowed_values,
],
'list_integer' => [
'allowed_values' => $allowed_values,
],
'list_float' => [
'allowed_values' => $allowed_values,
],
'boolean' => [
'allowed_values' => $allowed_values,
],
];
if ($original_field_type == 'userreference') {
return ['target_type' => 'user'];
}
else {
return $settings[$field_type] ?? [];
}
}
}
@@ -0,0 +1,32 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d6;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateException;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* Gives us a chance to set per field defaults.
*/
#[MigrateProcess('d6_field_type_defaults')]
class FieldTypeDefaults extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_array($value)) {
if ($row->getSourceProperty('module') == 'date') {
$value = 'datetime_default';
}
else {
throw new MigrateException(sprintf('Failed to lookup field type %s in the static map.', var_export($value, TRUE)));
}
}
return $value;
}
}
@@ -0,0 +1,116 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Determines the bundle for a field.
*
* The field bundle process plugin is used to get the destination bundle name
* for a field. This is necessary because the bundle names used for comments in
* legacy versions of Drupal are no longer used.
*
* Available configuration keys:
* - source: The input value - must be an array.
*
* Examples:
*
* @code
* process:
* bundle:
* plugin: field_bundle
* source
* - entity_type
* - bundle
* @endcode
*
* If 'bundle' is 'article' and 'entity_type' is node then 'article' is
* returned.
*
* @code
* process:
* bundle:
* plugin: field_bundle
* source
* - entity_type
* - bundle
* @endcode
*
* If 'bundle' is 'comment_node_a_thirty_two_character_name' and 'entity_type'
* is blog then a lookup is performed on the comment type migration so that the
* migrated bundle name for 'comment_node_a_thirty_two_character_name' is
* returned. That name will be truncated to 'comment_node_a_thirty_two_char'.
*
* @see core/modules/comment/migrations/d7_comment_type.yml
* @see core/modules/field/migrations/d7_field_instance.yml
*/
#[MigrateProcess('field_bundle')]
class FieldBundle extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migrate lookup service.
*
* @var \Drupal\migrate\MigrateLookupInterface
*/
protected $migrateLookup;
/**
* Constructs a ProcessField plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate\MigrateLookupInterface $migrate_lookup
* The migrate lookup service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateLookupInterface $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrateLookup = $migrate_lookup;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('migrate.lookup')
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$entity_type, $bundle] = $value;
$lookup_result = NULL;
// For comment entity types get the destination bundle from the
// d7_comment_type migration, if it exists.
if ($entity_type === 'comment' && $bundle != 'comment_forum') {
$lookup_result = $row->get('@_comment_type');
// Legacy generated migrations will not have the destination property
// '_comment_type'.
if (!$row->hasDestinationProperty('_comment_type')) {
$value = str_replace('comment_node_', '', $bundle);
$migration = 'd7_comment_type';
$lookup_result = $this->migrateLookup->lookup($migration, [$value]);
$lookup_result = empty($lookup_result) ? NULL : reset($lookup_result[0]);
}
}
return $lookup_result ? $lookup_result : $bundle;
}
}
@@ -0,0 +1,36 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
#[MigrateProcess('d7_field_instance_defaults')]
class FieldInstanceDefaults extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$default_value, $widget_settings] = $value;
$widget_type = $widget_settings['type'];
$default_value = $default_value ?: [];
// In Drupal 7, the default value for email fields is stored in the key
// 'email' while in Drupal 8 it is stored in the key 'value'.
if ($widget_type == 'email_textfield' && $default_value) {
$default_value[0]['value'] = $default_value[0]['email'];
unset($default_value[0]['email']);
}
if ($widget_type == 'link_field' && $default_value) {
$default_value[0]['uri'] = $default_value[0]['url'];
$default_value[0]['options'] = ['attributes' => []];
unset($default_value[0]['url']);
}
return $default_value;
}
}
@@ -0,0 +1,45 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Determines the settings property and translation for boolean fields.
*/
#[MigrateProcess(
id: "d7_field_instance_option_translation",
handle_multiples: TRUE,
)]
class FieldInstanceOptionTranslation extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$type, $data] = $value;
$data = unserialize($data);
$property = $row->getSourceProperty('property');
$option_key = ($property == 0) ? 'off_label' : 'on_label';
$translation = '';
if (isset($data['settings']['allowed_values'])) {
$allowed_values = $data['settings']['allowed_values'];
switch ($type) {
case 'boolean';
if (isset($allowed_values[$property])) {
$translation = $row->getSourceProperty('translation');
break;
}
break;
default:
}
}
return ['settings.' . $option_key, $translation];
}
}
@@ -0,0 +1,139 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
// cspell:ignore entityreference
/**
* Determines the field instance settings.
*/
#[MigrateProcess(
id: "d7_field_instance_settings"
)]
class FieldInstanceSettings extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$instance_settings, $widget_settings, $field_definition] = $value;
$widget_type = $widget_settings['type'];
$field_data = unserialize($field_definition['data']);
// Get taxonomy term reference handler settings from allowed values.
if ($row->getSourceProperty('type') == 'taxonomy_term_reference') {
$instance_settings['handler_settings']['sort'] = [
'field' => '_none',
];
$allowed_values = $row->get('@allowed_values');
foreach ($allowed_values as $allowed_value) {
foreach ($allowed_value as $vocabulary) {
$instance_settings['handler_settings']['target_bundles'][$vocabulary] = $vocabulary;
}
}
}
// Get entityreference handler settings from source field configuration.
if ($row->getSourceProperty('type') == "entityreference") {
$field_settings = $field_data['settings'];
$instance_settings['handler'] = 'default:' . $field_settings['target_type'];
// Transform the sort settings to D8 structure.
$sort = [
'field' => '_none',
'direction' => 'ASC',
];
if (!empty(array_filter($field_settings['handler_settings']['sort']))) {
if ($field_settings['handler_settings']['sort']['type'] == "property") {
$sort = [
'field' => $field_settings['handler_settings']['sort']['property'],
'direction' => $field_settings['handler_settings']['sort']['direction'],
];
}
elseif ($field_settings['handler_settings']['sort']['type'] == "field") {
$sort = [
'field' => $field_settings['handler_settings']['sort']['field'],
'direction' => $field_settings['handler_settings']['sort']['direction'],
];
}
}
if (empty($field_settings['handler_settings']['target_bundles'])) {
$field_settings['handler_settings']['target_bundles'] = NULL;
}
$field_settings['handler_settings']['sort'] = $sort;
$instance_settings['handler_settings'] = $field_settings['handler_settings'];
}
if ($row->getSourceProperty('type') == 'node_reference') {
$instance_settings['handler'] = 'default:node';
$instance_settings['handler_settings'] = [
'sort' => [
'field' => '_none',
'direction' => 'ASC',
],
'target_bundles' => array_filter($field_data['settings']['referenceable_types'] ?? []),
];
}
if ($row->getSourceProperty('type') == 'user_reference') {
$instance_settings['handler'] = 'default:user';
$instance_settings['handler_settings'] = [
'include_anonymous' => TRUE,
'filter' => [
'type' => '_none',
],
'sort' => [
'field' => '_none',
'direction' => 'ASC',
],
'auto_create' => FALSE,
];
if ($row->hasSourceProperty('roles')) {
$instance_settings['handler_settings']['filter']['type'] = 'role';
foreach ($row->get('roles') as $role) {
$instance_settings['handler_settings']['filter']['role'] = [
$role['name'] => $role['name'],
];
}
}
}
// Get the labels for the list_boolean type.
if ($row->getSourceProperty('type') === 'list_boolean') {
if (isset($field_data['settings']['allowed_values'][1])) {
$instance_settings['on_label'] = $field_data['settings']['allowed_values'][1];
}
if (isset($field_data['settings']['allowed_values'][0])) {
$instance_settings['off_label'] = $field_data['settings']['allowed_values'][0];
}
}
switch ($widget_type) {
case 'image_image':
case 'image_miw':
$settings = $instance_settings;
$settings['default_image'] = [
'alt' => '',
'title' => '',
'width' => NULL,
'height' => NULL,
'uuid' => '',
];
break;
default:
$settings = $instance_settings;
}
return $settings;
}
}
@@ -0,0 +1,51 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Determines the allowed values translation for select lists.
*/
#[MigrateProcess(
id: "d7_field_option_translation",
handle_multiples: TRUE,
)]
class FieldOptionTranslation extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Get the field default/mapped settings.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
[$type, $data] = $value;
$data = unserialize($data);
$new_allowed_values = '';
$translation_key = $row->getSourceProperty('property');
if (isset($data['settings']['allowed_values'])) {
$allowed_values = $data['settings']['allowed_values'];
switch ($type) {
case 'list_string':
case 'list_integer':
case 'list_float':
case 'list_text':
if (isset($allowed_values[$translation_key])) {
$new_allowed_values = ['label' => $row->getSourceProperty('translation')];
$translation_key = array_search($translation_key, array_keys($allowed_values));
break;
}
break;
default:
$new_allowed_values = $allowed_values;
}
}
return ["settings.allowed_values.$translation_key", $new_allowed_values];
}
}
@@ -0,0 +1,52 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
#[MigrateProcess('d7_field_settings')]
class FieldSettings extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$value = $row->getSourceProperty('settings');
switch ($row->getSourceProperty('type')) {
case 'image':
if (!is_array($value['default_image'])) {
$value['default_image'] = ['uuid' => ''];
}
break;
case 'date':
case 'datetime':
case 'datestamp':
$collected_date_attributes = is_numeric(array_keys($value['granularity'])[0])
? $value['granularity']
: array_keys(array_filter($value['granularity']));
if (empty(array_intersect($collected_date_attributes, ['hour', 'minute', 'second']))) {
$value['datetime_type'] = 'date';
}
break;
case 'taxonomy_term_reference':
$value['target_type'] = 'taxonomy_term';
break;
case 'user_reference':
$value['target_type'] = 'user';
break;
default:
break;
}
return $value;
}
}
@@ -0,0 +1,26 @@
<?php
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\Attribute\MigrateProcess;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* Gives us a chance to set per field defaults.
*/
#[MigrateProcess('d7_field_type_defaults')]
class FieldTypeDefaults extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_array($value) && isset($value[1])) {
return $value[1];
}
return $value;
}
}
@@ -0,0 +1,114 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
// cspell:ignore cnfi
/**
* Drupal 6 field source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d6_field",
* source_module = "content"
* )
*/
class Field extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('content_node_field', 'cnf')
->fields('cnf', [
'field_name',
'type',
'global_settings',
'required',
'multiple',
'db_storage',
'module',
'db_columns',
'active',
'locked',
])
->distinct();
// Only import fields which are actually being used.
$query->innerJoin('content_node_field_instance', 'cnfi', '[cnfi].[field_name] = [cnf].[field_name]');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'field_name' => $this->t('Field name'),
'type' => $this->t('Type (text, integer, ....)'),
'widget_type' => $this->t('An instance-specific widget type'),
'global_settings' => $this->t('Global settings. Shared with every field instance.'),
'required' => $this->t('Required'),
'multiple' => $this->t('Multiple'),
'db_storage' => $this->t('DB storage'),
'module' => $this->t('Module'),
'db_columns' => $this->t('DB Columns'),
'active' => $this->t('Active'),
'locked' => $this->t('Locked'),
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// The instance widget_type helps determine what D8 field type we'll use.
// Identify the distinct widget_types being used in D6.
$widget_types = $this->select('content_node_field_instance', 'cnfi')
->fields('cnfi', ['widget_type'])
->condition('field_name', $row->getSourceProperty('field_name'))
->distinct()
->orderBy('widget_type')
->execute()
->fetchCol();
// Arbitrarily use the first widget_type - if there are multiples, let the
// migrator know.
$row->setSourceProperty('widget_type', $widget_types[0]);
if (count($widget_types) > 1) {
$this->migration->getIdMap()->saveMessage(
['field_name' => $row->getSourceProperty('field_name')],
$this->t('Widget types @types are used in Drupal 6 field instances: widget type @selected_type applied to the Drupal 8 base field', [
'@types' => implode(', ', $widget_types),
'@selected_type' => $widget_types[0],
])
);
}
// Unserialize data.
$global_settings = unserialize($row->getSourceProperty('global_settings'));
$db_columns = $row->getSourceProperty('db_columns');
$db_columns = is_string($db_columns) ? unserialize($db_columns) : FALSE;
$row->setSourceProperty('global_settings', $global_settings);
$row->setSourceProperty('db_columns', $db_columns);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['field_name'] = [
'type' => 'string',
'alias' => 'cnf',
];
return $ids;
}
}
@@ -0,0 +1,117 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
// cspell:ignore cnfi nodeapi nsync
/**
* Drupal 6 field instances source from database.
*
* Available configuration keys:
* - node_type: (optional) The content type (machine name) to filter field
* instances retrieved from the source. If omitted, all field instances are
* retrieved.
*
* Example:
*
* @code
* source:
* plugin: d6_field_instance
* node_type: page
* @endcode
*
* In this example field instances of type page are retrieved from the source
* database.
*
* For additional configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d6_field_instance",
* source_module = "content"
* )
*/
class FieldInstance extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('content_node_field_instance', 'cnfi')->fields('cnfi');
if (isset($this->configuration['node_type'])) {
$query->condition('cnfi.type_name', $this->configuration['node_type']);
}
$query->join('content_node_field', 'cnf', '[cnf].[field_name] = [cnfi].[field_name]');
$query->fields('cnf');
$query->orderBy('cnfi.field_name');
$query->orderBy('cnfi.type_name');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'field_name' => $this->t('The machine name of field.'),
'type_name' => $this->t('Content type where this field is in use.'),
'weight' => $this->t('Weight.'),
'label' => $this->t('A name to show.'),
'widget_type' => $this->t('Widget type.'),
'widget_settings' => $this->t('Serialize data with widget settings.'),
'display_settings' => $this->t('Serialize data with display settings.'),
'description' => $this->t('A description of field.'),
'widget_module' => $this->t('Module that implements widget.'),
'widget_active' => $this->t('Status of widget'),
'module' => $this->t('The module that provides the field.'),
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// Unserialize data.
$widget_settings = unserialize($row->getSourceProperty('widget_settings'));
$display_settings = unserialize($row->getSourceProperty('display_settings'));
$global_settings = unserialize($row->getSourceProperty('global_settings'));
$row->setSourceProperty('widget_settings', $widget_settings);
$row->setSourceProperty('display_settings', $display_settings);
$row->setSourceProperty('global_settings', $global_settings);
// Determine the translatable setting.
$translatable = TRUE;
$synchronized_fields = $this->variableGet('i18nsync_nodeapi_' . $row->getSourceProperty('type_name'), NULL);
if ($synchronized_fields) {
if (in_array($row->getSourceProperty('field_name'), $synchronized_fields)) {
$translatable = FALSE;
}
}
$row->setSourceProperty('translatable', $translatable);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids = [
'field_name' => [
'type' => 'string',
'alias' => 'cnfi',
],
'type_name' => [
'type' => 'string',
],
];
return $ids;
}
}
@@ -0,0 +1,42 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
// cspell:ignore cnfi
/**
* Drupal 6 i18n field instance option labels source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d6_field_instance_option_translation",
* source_module = "i18ncck"
* )
*/
class FieldInstanceOptionTranslation extends FieldOptionTranslation {
/**
* {@inheritdoc}
*/
public function query() {
$query = parent::query();
$query->join('content_node_field_instance', 'cnfi', '[cnfi].[field_name] = [cnf].[field_name]');
$query->addField('cnfi', 'type_name');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'type_name' => $this->t('Type (article, page, ....)'),
];
return parent::fields() + $fields;
}
}
@@ -0,0 +1,103 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
// cspell:ignore cnfi
/**
* Drupal 6 field instance per form display source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d6_field_instance_per_form_display",
* source_module = "content"
* )
*/
class FieldInstancePerFormDisplay extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$rows = [];
$result = $this->prepareQuery()->execute();
while ($field_row = $result->fetchAssoc()) {
$bundle = $field_row['type_name'];
$field_name = $field_row['field_name'];
$index = "$bundle.$field_name";
$rows[$index]['type_name'] = $bundle;
$rows[$index]['widget_active'] = (bool) $field_row['widget_active'];
$rows[$index]['field_name'] = $field_name;
$rows[$index]['type'] = $field_row['type'];
$rows[$index]['module'] = $field_row['module'];
$rows[$index]['weight'] = $field_row['weight'];
$rows[$index]['widget_type'] = $field_row['widget_type'];
$rows[$index]['widget_settings'] = unserialize($field_row['widget_settings']);
$rows[$index]['display_settings'] = unserialize($field_row['display_settings']);
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('content_node_field_instance', 'cnfi')
->fields('cnfi', [
'field_name',
'type_name',
'weight',
'label',
'widget_type',
'widget_settings',
'display_settings',
'description',
'widget_module',
'widget_active',
])
->fields('cnf', [
'type',
'module',
]);
$query->join('content_node_field', 'cnf', '[cnfi].[field_name] = [cnf].[field_name]');
$query->orderBy('cnfi.weight');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'field_name' => $this->t('The machine name of field.'),
'type_name' => $this->t('Content type where this field is used.'),
'weight' => $this->t('Weight.'),
'label' => $this->t('A name to show.'),
'widget_type' => $this->t('Widget type.'),
'widget_settings' => $this->t('Serialize data with widget settings.'),
'display_settings' => $this->t('Serialize data with display settings.'),
'description' => $this->t('A description of field.'),
'widget_module' => $this->t('Module that implements widget.'),
'widget_active' => $this->t('Status of widget'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['type_name']['type'] = 'string';
$ids['field_name']['type'] = 'string';
return $ids;
}
}
@@ -0,0 +1,112 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\node\Plugin\migrate\source\d6\ViewModeBase;
// cspell:ignore cnfi
/**
* Drupal 6 field instance per view mode source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d6_field_instance_per_view_mode",
* source_module = "content"
* )
*/
class FieldInstancePerViewMode extends ViewModeBase {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$rows = [];
$result = $this->prepareQuery()->execute();
while ($field_row = $result->fetchAssoc()) {
// These are added to every view mode row.
$field_row['display_settings'] = unserialize($field_row['display_settings']);
$field_row['widget_settings'] = unserialize($field_row['widget_settings']);
$bundle = $field_row['type_name'];
$field_name = $field_row['field_name'];
foreach ($this->getViewModes() as $view_mode) {
// Append to the return value if the row has display settings for this
// view mode and the view mode is neither hidden nor excluded.
// @see \Drupal\node\Plugin\migrate\source\d6\ViewMode::initializeIterator()
if (isset($field_row['display_settings'][$view_mode]) && $field_row['display_settings'][$view_mode]['format'] != 'hidden' && empty($field_row['display_settings'][$view_mode]['exclude'])) {
$index = $view_mode . "." . $bundle . "." . $field_name;
$rows[$index]['entity_type'] = 'node';
$rows[$index]['view_mode'] = $view_mode;
$rows[$index]['type_name'] = $bundle;
$rows[$index]['field_name'] = $field_name;
$rows[$index]['type'] = $field_row['type'];
$rows[$index]['module'] = $field_row['module'];
$rows[$index]['weight'] = $field_row['weight'];
$rows[$index]['label'] = $field_row['display_settings']['label']['format'];
$rows[$index]['display_settings'] = $field_row['display_settings'][$view_mode];
$rows[$index]['widget_settings'] = $field_row['widget_settings'];
}
}
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('content_node_field_instance', 'cnfi')
->fields('cnfi', [
'field_name',
'type_name',
'weight',
'label',
'display_settings',
'widget_settings',
])
->fields('cnf', [
'type',
'module',
]);
$query->join('content_node_field', 'cnf', '[cnfi].[field_name] = [cnf].[field_name]');
$query->orderBy('cnfi.weight');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'field_name' => $this->t('The machine name of field.'),
'type_name' => $this->t('Content type where this field is used.'),
'weight' => $this->t('Weight.'),
'label' => $this->t('A name to show.'),
'widget_type' => $this->t('Widget type.'),
'widget_settings' => $this->t('Serialize data with widget settings.'),
'display_settings' => $this->t('Serialize data with display settings.'),
'description' => $this->t('A description of field.'),
'widget_module' => $this->t('Module that implements widget.'),
'widget_active' => $this->t('Status of widget'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['type_name']['type'] = 'string';
$ids['view_mode']['type'] = 'string';
$ids['entity_type']['type'] = 'string';
$ids['field_name']['type'] = 'string';
return $ids;
}
}
@@ -0,0 +1,65 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
// cspell:ignore objectid
/**
* Drupal 6 i18n field label and description source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d6_field_instance_label_description_translation",
* source_module = "i18ncck"
* )
*/
class FieldLabelDescriptionTranslation extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
// Get translations for field labels and descriptions.
$query = $this->select('i18n_strings', 'i18n')
->fields('i18n', ['property', 'objectid', 'type'])
->fields('lt', ['lid', 'translation', 'language'])
->condition('i18n.type', 'field');
$condition = $query->orConditionGroup()
->condition('property', 'widget_label')
->condition('property', 'widget_description');
$query->condition($condition);
$query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'property' => $this->t('Profile field ID.'),
'lid' => $this->t('Locales target language ID.'),
'language' => $this->t('Language for this field.'),
'translation' => $this->t('Translation of either the title or explanation.'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['property']['type'] = 'string';
$ids['language']['type'] = 'string';
$ids['lid']['type'] = 'integer';
$ids['lid']['alias'] = 'lt';
return $ids;
}
}
@@ -0,0 +1,92 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d6;
// cspell:ignore objectid objectindex plid
/**
* Drupal 6 i18n field option labels source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d6_field_option_translation",
* source_module = "i18ncck"
* )
*/
class FieldOptionTranslation extends Field {
/**
* {@inheritdoc}
*/
public function query() {
// Get the fields that have field options translations.
$query = $this->select('i18n_strings', 'i18n')
->fields('i18n')
->fields('lt', [
'translation',
'language',
'plid',
'plural',
])
->condition('i18n.type', 'field')
->condition('property', 'option\_%', 'LIKE');
$query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
$query->leftJoin('content_node_field', 'cnf', '[cnf].[field_name] = [i18n].[objectid]');
$query->addField('cnf', 'field_name');
$query->addField('cnf', 'global_settings');
// Minimize changes to the d6_field_option_translation.yml, which is copied
// from d6_field.yml, by ensuring the 'type' property is from
// content_node_field table.
$query->addField('cnf', 'type');
$query->addField('i18n', 'type', 'i18n_type');
// The i18n_string module adds a status column to locale_target. It was
// originally 'status' in a later revision it was named 'i18n_status'.
/** @var \Drupal\Core\Database\Schema $db */
if ($this->getDatabase()->schema()->fieldExists('locales_target', 'status')) {
$query->addField('lt', 'status', 'i18n_status');
}
if ($this->getDatabase()->schema()->fieldExists('locales_target', 'i18n_status')) {
$query->addField('lt', 'i18n_status');
}
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'property' => $this->t('Option ID.'),
'objectid' => $this->t('Object ID'),
'objectindex' => $this->t('Integer value of Object ID'),
'format' => $this->t('The input format used by this string'),
'lid' => $this->t('Source string ID'),
'language' => $this->t('Language code'),
'translation' => $this->t('Translation of the option'),
'plid' => $this->t('Parent lid'),
'plural' => $this->t('Plural index number in case of plural strings'),
];
return parent::fields() + $fields;
}
/**
* {@inheritdoc}
*/
/**
* {@inheritdoc}
*/
public function getIds() {
return parent::getIds() +
[
'language' => ['type' => 'string'],
'property' => ['type' => 'string'],
];
}
}
@@ -0,0 +1,113 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 field source from database.
*
* If the Drupal 7 Title module is enabled, the fields it provides are not
* migrated. The values of those fields will be migrated to the base fields they
* were replacing.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d7_field",
* source_module = "field_sql_storage"
* )
*/
class Field extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('field_config', 'fc')
->distinct()
->fields('fc')
->fields('fci', ['entity_type'])
->condition('fc.active', 1)
->condition('fc.storage_active', 1)
->condition('fc.deleted', 0)
->condition('fci.deleted', 0);
$query->join('field_config_instance', 'fci', '[fc].[id] = [fci].[field_id]');
// The Title module fields are not migrated.
if ($this->moduleExists('title')) {
$title_fields = [
'title_field',
'name_field',
'description_field',
'subject_field',
];
$query->condition('fc.field_name', $title_fields, 'NOT IN');
}
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'id' => $this->t('The field ID.'),
'field_name' => $this->t('The field name.'),
'entity_type' => $this->t('Entity type'),
'type' => $this->t('The field type.'),
'module' => $this->t('The module that implements the field type.'),
'active' => $this->t('The field status.'),
'storage_type' => $this->t('The field storage type.'),
'storage_module' => $this->t('The module that implements the field storage type.'),
'storage_active' => $this->t('The field storage status.'),
'locked' => $this->t('Locked'),
'data' => $this->t('The field data.'),
'cardinality' => $this->t('Cardinality'),
'translatable' => $this->t('Translatable'),
'deleted' => $this->t('Deleted'),
'instances' => $this->t('The field instances.'),
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row, $keep = TRUE) {
foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
$row->setSourceProperty($key, $value);
}
$instances = $this->select('field_config_instance', 'fci')
->fields('fci')
->condition('field_name', $row->getSourceProperty('field_name'))
->condition('entity_type', $row->getSourceProperty('entity_type'))
->execute()
->fetchAll();
$row->setSourceProperty('instances', $instances);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'field_name' => [
'type' => 'string',
'alias' => 'fc',
],
'entity_type' => [
'type' => 'string',
'alias' => 'fci',
],
];
}
}
@@ -0,0 +1,262 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
// cspell:ignore localizable
/**
* Drupal 7 field instances source from database.
*
* If the Drupal 7 Title module is enabled, the fields it provides are not
* migrated. The values of those fields will be migrated to the base fields they
* were replacing.
*
* Available configuration keys:
* - entity_type: (optional) The entity type (machine name) to filter field
* instances retrieved from the source. If omitted, all field instances are
* retrieved.
* - bundle: (optional) The bundle machine name to filter field instances
* retrieved from the source. It should be used in combination with
* entity_type property and will be ignored otherwise.
*
* Examples:
*
* @code
* source:
* plugin: d7_field_instance
* entity_type: node
* @endcode
*
* In this example field instances of node entity type are retrieved from the
* source database.
*
* @code
* source:
* plugin: d7_field_instance
* entity_type: node
* bundle: page
* @endcode
*
* In this example field instances of page content type are retrieved from the
* source database.
*
* For additional configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d7_field_instance",
* source_module = "field"
* )
*/
class FieldInstance extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('field_config_instance', 'fci')
->fields('fci')
->fields('fc', ['type', 'translatable'])
->condition('fc.active', 1)
->condition('fc.storage_active', 1)
->condition('fc.deleted', 0)
->condition('fci.deleted', 0);
$query->join('field_config', 'fc', '[fci].[field_id] = [fc].[id]');
// Optionally filter by entity type and bundle.
if (isset($this->configuration['entity_type'])) {
$query->condition('fci.entity_type', $this->configuration['entity_type']);
if (isset($this->configuration['bundle'])) {
$query->condition('fci.bundle', $this->configuration['bundle']);
}
}
// The Title module fields are not migrated.
if ($this->moduleExists('title')) {
$title_fields = [
'title_field',
'name_field',
'description_field',
'subject_field',
];
$query->condition('fc.field_name', $title_fields, 'NOT IN');
}
return $query;
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$results = $this->prepareQuery()->execute()->fetchAll();
// Group all instances by their base field.
$instances = [];
foreach ($results as $result) {
$instances[$result['field_id']][] = $result;
}
// Add the array of all instances using the same base field to each row.
$rows = [];
foreach ($results as $result) {
$result['instances'] = $instances[$result['field_id']];
$rows[] = $result;
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'id' => $this->t('The field instance ID.'),
'field_id' => $this->t('The field ID.'),
'field_name' => $this->t('The field name.'),
'entity_type' => $this->t('The entity type.'),
'bundle' => $this->t('The entity bundle.'),
'data' => $this->t('The field instance data.'),
'deleted' => $this->t('Deleted'),
'type' => $this->t('The field type'),
'instances' => $this->t('The field instances.'),
'field_definition' => $this->t('The field definition.'),
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
$row->setSourceProperty($key, $value);
}
$field_definition = $this->select('field_config', 'fc')
->fields('fc')
->condition('id', $row->getSourceProperty('field_id'))
->execute()
->fetch();
$row->setSourceProperty('field_definition', $field_definition);
// Determine the translatable setting.
$translatable = FALSE;
if ($row->getSourceProperty('entity_type') == 'node') {
$language_content_type_bundle = (int) $this->variableGet('language_content_type_' . $row->getSourceProperty('bundle'), 0);
// language_content_type_[bundle] may be
// - 0: no language support
// - 1: language assignment support
// - 2: node translation support
// - 4: entity translation support
if ($language_content_type_bundle === 2 || ($language_content_type_bundle === 4 && $row->getSourceProperty('translatable'))) {
$translatable = TRUE;
}
}
else {
// This is not a node entity. Get the translatable value from the source
// field_config table.
$field_data = unserialize($field_definition['data']);
$translatable = $field_data['translatable'];
}
// Check if this is an i18n synchronized field.
$synchronized_fields = $this->variableGet('i18n_sync_node_type_' . $row->getSourceProperty('bundle'), NULL);
if ($synchronized_fields) {
if (in_array($row->getSourceProperty('field_name'), $synchronized_fields)) {
$translatable = FALSE;
}
}
$row->setSourceProperty('translatable', $translatable);
// Get the vid for each allowed value for taxonomy term reference fields
// which is used in a migration_lookup in the process pipeline.
if ($row->getSourceProperty('type') == 'taxonomy_term_reference') {
$vocabulary = [];
$data = unserialize($field_definition['data']);
foreach ($data['settings']['allowed_values'] as $allowed_value) {
$vocabulary[] = $allowed_value['vocabulary'];
}
$query = $this->select('taxonomy_vocabulary', 'v')
->fields('v', ['vid'])
->condition('machine_name', $vocabulary, 'IN');
$allowed_vid = $query->execute()->fetchAllAssoc('vid');
$row->setSourceProperty('allowed_vid', $allowed_vid);
// If there is an i18n_mode use it to determine if this field is
// translatable. It is TRUE for i18n_modes 'Vocab Fixed' and 'Translate',
// for all others it is FALSE. When there is a term reference field with
// two vocabularies where one vocabulary is translatable and other is not
// the field itself is set to not translatable. Note mode '5' is not used
// for taxonomy but is listed here for completeness.
// - 0: No multilingual options.
// - 1: Localize. Localizable object.
// - 2: Fixed Language.
// - 4: Translate. Multilingual objects.
// - 5: Objects are translatable, if they have language or localizable
// if not)
if ($this->getDatabase()
->schema()
->fieldExists('taxonomy_vocabulary', 'i18n_mode')) {
$query = $this->select('taxonomy_vocabulary', 'v')
->fields('v', ['i18n_mode'])
->condition('machine_name', $vocabulary, 'IN');
$results = $query->execute()->fetchAllAssoc('i18n_mode');
$translatable = FALSE;
foreach ($results as $result) {
if ($result['i18n_mode'] == '2' || $result['i18n_mode'] == '4') {
$translatable = TRUE;
}
}
$row->setSourceProperty('translatable', $translatable);
}
}
// Get the user roles for user reference fields.
if ($row->getSourceProperty('type') == 'user_reference') {
$data = unserialize($field_definition['data']);
if (!empty($data['settings']['referenceable_roles'])) {
$rid = $data['settings']['referenceable_roles'];
$query = $this->select('role', 'r')->fields('r')
->condition('rid', $rid, 'IN');
$results = $query->execute()->fetchAll();
$row->setSourceProperty('roles', $results);
}
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'entity_type' => [
'type' => 'string',
'alias' => 'fci',
],
'bundle' => [
'type' => 'string',
'alias' => 'fci',
],
'field_name' => [
'type' => 'string',
'alias' => 'fci',
],
];
}
/**
* {@inheritdoc}
*/
protected function doCount() {
return $this->initializeIterator()->count();
}
}
@@ -0,0 +1,36 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
/**
* Drupal 7 field instance per form display source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\field\Plugin\migrate\source\d7\FieldInstance
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d7_field_instance_per_form_display",
* source_module = "field"
* )
*/
class FieldInstancePerFormDisplay extends FieldInstance {
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'bundle' => [
'type' => 'string',
],
'field_name' => [
'type' => 'string',
'alias' => 'fci',
],
];
}
}
@@ -0,0 +1,70 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
/**
* Drupal 7 field instance per view mode source class.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\field\Plugin\migrate\source\d7\FieldInstance
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d7_field_instance_per_view_mode",
* source_module = "field"
* )
*/
class FieldInstancePerViewMode extends FieldInstance {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$instances = parent::initializeIterator();
$rows = [];
foreach ($instances->getArrayCopy() as $instance) {
$data = unserialize($instance['data']);
foreach ($data['display'] as $view_mode => $formatter) {
$rows[] = array_merge($instance, [
'view_mode' => $view_mode,
'formatter' => $formatter,
]);
}
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function fields() {
return array_merge(parent::fields(), [
'view_mode' => $this->t('The original machine name of the view mode.'),
'formatter' => $this->t('The formatter settings.'),
]);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'entity_type' => [
'type' => 'string',
],
'bundle' => [
'type' => 'string',
],
'view_mode' => [
'type' => 'string',
],
'field_name' => [
'type' => 'string',
],
];
}
}
@@ -0,0 +1,98 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
// cspell:ignore objectid objectindex plid textgroup
/**
* Drupal 7 i18n field label and description source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d7_field_instance_label_description_translation",
* source_module = "i18n_field"
* )
*/
class FieldLabelDescriptionTranslation extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
// Get translations for field labels and descriptions.
$query = $this->select('i18n_string', 'i18n')
->fields('i18n')
->fields('lt', [
'lid',
'translation',
'language',
'plid',
'plural',
'i18n_status',
])
->fields('fci', [
'id',
'field_id',
'field_name',
'entity_type',
'bundle',
'data',
'deleted',
])
->condition('i18n.textgroup', 'field');
$condition = $query->orConditionGroup()
->condition('textgroup', 'field')
->condition('objectid', '#allowed_values', '!=');
$query->condition($condition);
$query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
$query->leftJoin('field_config_instance', 'fci', '[fci].[bundle] = [i18n].[objectid] AND [fci].[field_name] = [i18n].[type]');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'lid' => $this->t('Locales target language ID.'),
'textgroup' => $this->t('A module defined group of translations'),
'context' => $this->t('Full string ID for quick search: type:objectid:property.'),
'objectid' => $this->t('Object ID'),
'type' => $this->t('Object type for this string'),
'property' => $this->t('Object property for this string'),
'objectindex' => $this->t('Integer value of Object ID'),
'format' => $this->t('The {filter_format}.format of the string'),
'translation' => $this->t('Translation'),
'language' => $this->t('Language code'),
'plid' => $this->t('Parent lid'),
'plural' => $this->t('Plural index number'),
'i18n_status' => $this->t('Translation needs update'),
'id' => $this->t('The field instance ID.'),
'field_id' => $this->t('The field ID.'),
'field_name' => $this->t('The field name.'),
'entity_type' => $this->t('The entity type.'),
'bundle' => $this->t('The entity bundle.'),
'data' => $this->t('The field instance data.'),
'deleted' => $this->t('Deleted'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['property']['type'] = 'string';
$ids['language']['type'] = 'string';
$ids['lid']['type'] = 'integer';
$ids['lid']['alias'] = 'lt';
return $ids;
}
}
@@ -0,0 +1,85 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
// cspell:ignore objectid objectindex plid textgroup
/**
* Drupal 7 i18n field option label source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d7_field_option_translation",
* source_module = "i18n_field"
* )
*/
class FieldOptionTranslation extends Field {
/**
* {@inheritdoc}
*/
public function query() {
$query = parent::query();
$query->leftJoin('i18n_string', 'i18n', '[i18n].[type] = [fc].[field_name]');
$query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
$query->condition('i18n.textgroup', 'field')
->condition('objectid', '#allowed_values');
// Add all i18n and locales_target fields.
$query
->fields('i18n', [
// All table fields except lid and type.
'textgroup',
'context',
'objectid',
'property',
'objectindex',
'format',
])
->fields('lt');
$query->addField('fci', 'bundle');
$query->addField('i18n', 'lid', 'i18n_lid');
$query->addField('i18n', 'type', 'i18n_type');
$query->orderBy('i18n.lid');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'bundle' => $this->t('Entity bundle'),
'lid' => $this->t('Source string ID'),
'textgroup' => $this->t('A module defined group of translations'),
'context' => $this->t('Full string ID'),
'objectid' => $this->t('Object ID'),
'property' => $this->t('Object property for this string'),
'objectindex' => $this->t('Integer value of Object ID'),
'format' => $this->t('The input format used by this string'),
'translation' => $this->t('Translation of the option'),
'language' => $this->t('Language code'),
'plid' => $this->t('Parent lid'),
'plural' => $this->t('Plural index number in case of plural strings'),
'i18n_status' => $this->t('A boolean indicating whether this translation needs to be updated'),
];
return parent::fields() + $fields;
}
/**
* {@inheritdoc}
*/
public function getIds() {
return parent::getIds() +
[
'language' => ['type' => 'string'],
'property' => ['type' => 'string'],
'bundle' => ['type' => 'string'],
];
}
}
@@ -0,0 +1,63 @@
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
/**
* Drupal 7 view mode source from database.
*
* For available configuration keys, refer to the parent classes.
*
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "d7_view_mode",
* source_module = "field"
* )
*/
class ViewMode extends FieldInstance {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$instances = parent::initializeIterator();
$rows = [];
foreach ($instances->getArrayCopy() as $instance) {
$data = unserialize($instance['data']);
foreach (array_keys($data['display']) as $view_mode) {
$key = $instance['entity_type'] . '.' . $view_mode;
$rows[$key] = array_merge($instance, [
'view_mode' => $view_mode,
]);
}
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function fields() {
return array_merge(parent::fields(), [
'view_mode' => $this->t('The view mode ID.'),
]);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'entity_type' => [
'type' => 'string',
],
'view_mode' => [
'type' => 'string',
],
];
}
}