updated core to 8.6.3
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Determines the settings property and translation for boolean fields.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* 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) {
|
||||
list($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 = isset($tmp[0]) ? $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,59 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Determines the allowed values translation for select lists.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* 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) {
|
||||
list($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 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,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d6;
|
||||
|
||||
/**
|
||||
* Gets field instance option label translations.
|
||||
*
|
||||
* @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', 'cnf.field_name = cnfi.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,60 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Gets field label and description translations.
|
||||
*
|
||||
* @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')
|
||||
->isNotNull('language')
|
||||
->isNotNull('translation');
|
||||
$condition = $query->orConditionGroup()
|
||||
->condition('property', 'widget_label')
|
||||
->condition('property', 'widget_description');
|
||||
$query->condition($condition);
|
||||
$query->leftJoin('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,78 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d6;
|
||||
|
||||
/**
|
||||
* Gets field option label translations.
|
||||
*
|
||||
* @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',
|
||||
'i18n_status',
|
||||
])
|
||||
->condition('i18n.type', 'field')
|
||||
->condition('property', 'option\_%', 'LIKE')
|
||||
->isNotNull('translation');
|
||||
$query->leftJoin('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');
|
||||
// Minimise 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');
|
||||
|
||||
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'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,63 +2,18 @@
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait as nonDeprecatedEntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* Provides common functionality for the EntityReference test classes.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.2 for removal before 9.0.0. Use
|
||||
* Drupal\Tests\field\Traits\EntityReferenceTestTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2998888
|
||||
*/
|
||||
trait EntityReferenceTestTrait {
|
||||
|
||||
/**
|
||||
* Creates a field of an entity reference field storage on the specified bundle.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The type of entity the field will be attached to.
|
||||
* @param string $bundle
|
||||
* The bundle name of the entity the field will be attached to.
|
||||
* @param string $field_name
|
||||
* The name of the field; if it already exists, a new instance of the existing
|
||||
* field will be created.
|
||||
* @param string $field_label
|
||||
* The label of the field.
|
||||
* @param string $target_entity_type
|
||||
* The type of the referenced entity.
|
||||
* @param string $selection_handler
|
||||
* The selection handler used by this field.
|
||||
* @param array $selection_handler_settings
|
||||
* An array of settings supported by the selection handler specified above.
|
||||
* (e.g. 'target_bundles', 'sort', 'auto_create', etc).
|
||||
* @param int $cardinality
|
||||
* The cardinality of the field.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm()
|
||||
*/
|
||||
protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1) {
|
||||
// Look for or add the specified field to the requested entity bundle.
|
||||
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'type' => 'entity_reference',
|
||||
'entity_type' => $entity_type,
|
||||
'cardinality' => $cardinality,
|
||||
'settings' => [
|
||||
'target_type' => $target_entity_type,
|
||||
],
|
||||
])->save();
|
||||
}
|
||||
if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
|
||||
FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $entity_type,
|
||||
'bundle' => $bundle,
|
||||
'label' => $field_label,
|
||||
'settings' => [
|
||||
'handler' => $selection_handler,
|
||||
'handler_settings' => $selection_handler_settings,
|
||||
],
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
use nonDeprecatedEntityReferenceTestTrait;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user