Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
|
@ -78,7 +78,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
|
|||
*
|
||||
* @param array $values
|
||||
* An array of field properties, keyed by property name. The
|
||||
* storage associated to the field can be specified either with:
|
||||
* storage associated with the field can be specified either with:
|
||||
* - field_storage: the FieldStorageConfigInterface object,
|
||||
* or by referring to an existing field storage in the current configuration
|
||||
* with:
|
||||
|
|
@ -270,7 +270,8 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
|
|||
protected function urlRouteParameters($rel) {
|
||||
$parameters = parent::urlRouteParameters($rel);
|
||||
$entity_type = \Drupal::entityManager()->getDefinition($this->entity_type);
|
||||
$parameters[$entity_type->getBundleEntityType()] = $this->bundle;
|
||||
$bundle_parameter_key = $entity_type->getBundleEntityType() ?: 'bundle';
|
||||
$parameters[$bundle_parameter_key] = $this->bundle;
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
|
|
@ -288,7 +289,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
|
|||
if (!$this->fieldStorage) {
|
||||
$fields = $this->entityManager()->getFieldStorageDefinitions($this->entity_type);
|
||||
if (!isset($fields[$this->field_name])) {
|
||||
throw new FieldException('Attempt to create a field {$this->field_name} that does not exist on entity type {$this->entity_type}.');
|
||||
throw new FieldException("Attempt to create a field {$this->field_name} that does not exist on entity type {$this->entity_type}.");
|
||||
}
|
||||
if (!$fields[$this->field_name] instanceof FieldStorageConfigInterface) {
|
||||
throw new FieldException("Attempt to create a configurable field of non-configurable field storage {$this->field_name}.");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldFormatterSettingsDefaults.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Set the default field settings.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "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 = array('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 = array();
|
||||
}
|
||||
}
|
||||
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 isset($map[$type][$format]) ? $map[$type][$format] : [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldIdGenerator.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Generate the file name for field config entities.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "field_id_generator"
|
||||
* )
|
||||
*/
|
||||
class FieldIdGenerator extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
return $value[0] . "." . $value[1];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldInstanceDefaults.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "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) {
|
||||
list($widget_type, $widget_settings) = $value;
|
||||
$default = array();
|
||||
|
||||
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['url'] = $widget_settings['default_value'][0]['url'];
|
||||
$default['options'] = ['attributes' => []];
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!empty($default)) {
|
||||
$default = array($default);
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldInstanceSettings.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "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) {
|
||||
list($widget_type, $widget_settings, $field_settings) = $value;
|
||||
$settings = array();
|
||||
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 = array('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'] = 'public://';
|
||||
$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'];
|
||||
$settings['max_resolution'] = $widget_settings['max_resolution'];
|
||||
$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,86 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldInstanceWidgetSettings.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Get the field instance widget settings.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "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) {
|
||||
list($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 = isset($widget_settings['progress_indicator']) ? $widget_settings['progress_indicator'] : 'throbber';
|
||||
$size = isset($widget_settings['size']) ? $widget_settings['size'] : 60;
|
||||
$rows = isset($widget_settings['rows']) ? $widget_settings['rows'] : 5;
|
||||
|
||||
$settings = array(
|
||||
'text_textfield' => array(
|
||||
'size' => $size,
|
||||
'placeholder' => '',
|
||||
),
|
||||
'text_textarea' => array(
|
||||
'rows' => $rows,
|
||||
'placeholder' => '',
|
||||
),
|
||||
'number' => array(
|
||||
'placeholder' => '',
|
||||
),
|
||||
'email_textfield' => array(
|
||||
'placeholder' => '',
|
||||
),
|
||||
'link' => array(
|
||||
'placeholder_url' => '',
|
||||
'placeholder_title' => '',
|
||||
),
|
||||
'filefield_widget' => array(
|
||||
'progress_indicator' => $progress,
|
||||
),
|
||||
'imagefield_widget' => array(
|
||||
'progress_indicator' => $progress,
|
||||
'preview_image_style' => 'thumbnail',
|
||||
),
|
||||
'optionwidgets_onoff' => array(
|
||||
'display_label' => FALSE,
|
||||
),
|
||||
'phone_textfield' => array(
|
||||
'placeholder' => '',
|
||||
),
|
||||
);
|
||||
|
||||
return isset($settings[$widget_type]) ? $settings[$widget_type] : array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldSettings.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Get the field settings.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "field_settings"
|
||||
* )
|
||||
*/
|
||||
class FieldSettings 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, $widget_settings) = $value;
|
||||
return $this->getSettings($field_type, $global_settings, $widget_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the default D8 and specified D6 settings.
|
||||
*
|
||||
* @param string $field_type
|
||||
* The field type.
|
||||
* @param array $global_settings
|
||||
* The field settings.
|
||||
* @param array $widget_settings
|
||||
* The widget settings needed for some settings.
|
||||
*
|
||||
* @return array
|
||||
* A valid array of settings.
|
||||
*/
|
||||
public function getSettings($field_type, $global_settings, $widget_settings) {
|
||||
$max_length = isset($global_settings['max_length']) ? $global_settings['max_length'] : '';
|
||||
$max_length = empty($max_length) ? 255 : $max_length;
|
||||
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]] = isset($value[1]) ? $value[1] : $value[0];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$allowed_values = $list;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$allowed_values = '';
|
||||
}
|
||||
|
||||
$settings = array(
|
||||
'text' => array(
|
||||
'max_length' => $max_length,
|
||||
),
|
||||
'datetime' => array('datetime_type' => 'datetime'),
|
||||
'list_string' => array(
|
||||
'allowed_values' => $allowed_values,
|
||||
),
|
||||
'list_integer' => array(
|
||||
'allowed_values' => $allowed_values,
|
||||
),
|
||||
'list_float' => array(
|
||||
'allowed_values' => $allowed_values,
|
||||
),
|
||||
'boolean' => array(
|
||||
'allowed_values' => $allowed_values,
|
||||
),
|
||||
);
|
||||
|
||||
return isset($settings[$field_type]) ? $settings[$field_type] : array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d6\FieldTypeDefaults.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d6;
|
||||
|
||||
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.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "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 %s in the static map.', var_export($value, TRUE)));
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
41
core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php
Executable file
41
core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldInstanceDefaults.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d7;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d7_field_instance_defaults"
|
||||
* )
|
||||
*/
|
||||
class FieldInstanceDefaults extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($default_value, $widget_settings) = $value;
|
||||
$widget_type = $widget_settings['type'];
|
||||
|
||||
$default = array();
|
||||
|
||||
foreach ($default_value as $item) {
|
||||
switch ($widget_type) {
|
||||
// Add special processing here if needed.
|
||||
default:
|
||||
$default[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
}
|
||||
47
core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
Executable file
47
core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldInstanceSettings.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d7;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d7_field_instance_settings"
|
||||
* )
|
||||
*/
|
||||
class FieldInstanceSettings extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($instance_settings, $widget_settings) = $value;
|
||||
$widget_type = $widget_settings['type'];
|
||||
|
||||
switch ($widget_type) {
|
||||
case 'image_image':
|
||||
$settings = $instance_settings;
|
||||
$settings['default_image'] = array(
|
||||
'alt' => '',
|
||||
'title' => '',
|
||||
'width' => NULL,
|
||||
'height' => NULL,
|
||||
'uuid' => '',
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
$settings = $instance_settings;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
}
|
||||
36
core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php
Executable file
36
core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldSettings.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\process\d7;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d7_field_settings"
|
||||
* )
|
||||
*/
|
||||
class FieldSettings extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$value = $row->getSourceProperty('settings');
|
||||
|
||||
if ($row->getSourceProperty('type') == 'image' && !is_array($value['default_image'])) {
|
||||
$value['default_image'] = array(
|
||||
'uuid' => '',
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
93
core/modules/field/src/Plugin/migrate/source/d6/Field.php
Normal file
93
core/modules/field/src/Plugin/migrate/source/d6/Field.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d6\Field.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 field source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_field",
|
||||
* source_provider = "content"
|
||||
* )
|
||||
*/
|
||||
class Field extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('content_node_field', 'cnf')
|
||||
->fields('cnf', array(
|
||||
'field_name',
|
||||
'type',
|
||||
'global_settings',
|
||||
'required',
|
||||
'multiple',
|
||||
'db_storage',
|
||||
'module',
|
||||
'db_columns',
|
||||
'active',
|
||||
'locked',
|
||||
))
|
||||
->fields('cnfi', array(
|
||||
'widget_type',
|
||||
'widget_settings',
|
||||
));
|
||||
$query->join('content_node_field_instance', 'cnfi', 'cnfi.field_name = cnf.field_name');
|
||||
$query->orderBy('field_name');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'field_name' => $this->t('Field name'),
|
||||
'type' => $this->t('Type (text, integer, ....)'),
|
||||
'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) {
|
||||
// Unserialize data.
|
||||
$global_settings = unserialize($row->getSourceProperty('global_settings'));
|
||||
$widget_settings = unserialize($row->getSourceProperty('widget_settings'));
|
||||
$db_columns = unserialize($row->getSourceProperty('db_columns'));
|
||||
$row->setSourceProperty('global_settings', $global_settings);
|
||||
$row->setSourceProperty('widget_settings', $widget_settings);
|
||||
$row->setSourceProperty('db_columns', $db_columns);
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['field_name'] = array(
|
||||
'type' => 'string',
|
||||
'alias' => 'cnf',
|
||||
);
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d6\FieldInstance.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 field instances source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_field_instance",
|
||||
* source_provider = "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');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'field_name' => $this->t('The machine name of field.'),
|
||||
'type_name' => $this->t('Content type where is used this field.'),
|
||||
'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);
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids = array(
|
||||
'field_name' => array(
|
||||
'type' => 'string',
|
||||
'alias' => 'cnfi',
|
||||
),
|
||||
'type_name' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d6\FieldInstancePerFormDisplay.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* The field instance per form display source class.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_field_instance_per_form_display"
|
||||
* )
|
||||
*/
|
||||
class FieldInstancePerFormDisplay extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
$rows = array();
|
||||
$result = $this->prepareQuery()->execute();
|
||||
while ($field_row = $result->fetchAssoc()) {
|
||||
$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'];
|
||||
|
||||
$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'] = $field_row['widget_settings'];
|
||||
}
|
||||
|
||||
return new \ArrayIterator($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('content_node_field_instance', 'cnfi')
|
||||
->fields('cnfi', array(
|
||||
'field_name',
|
||||
'type_name',
|
||||
'weight',
|
||||
'label',
|
||||
'widget_type',
|
||||
'widget_settings',
|
||||
'display_settings',
|
||||
'description',
|
||||
'widget_module',
|
||||
'widget_active',
|
||||
))
|
||||
->fields('cnf', array(
|
||||
'type',
|
||||
'module',
|
||||
));
|
||||
$query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name');
|
||||
$query->orderBy('weight');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'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,107 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d6\FieldInstancePerViewMode.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\node\Plugin\migrate\source\d6\ViewModeBase;
|
||||
|
||||
/**
|
||||
* The field instance per view mode source class.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_field_instance_per_view_mode",
|
||||
* source_provider = "content"
|
||||
* )
|
||||
*/
|
||||
class FieldInstancePerViewMode extends ViewModeBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
$rows = array();
|
||||
$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) {
|
||||
if (isset($field_row['display_settings'][$view_mode]) && 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', array(
|
||||
'field_name',
|
||||
'type_name',
|
||||
'weight',
|
||||
'label',
|
||||
'display_settings',
|
||||
'widget_settings',
|
||||
))
|
||||
->fields('cnf', array(
|
||||
'type',
|
||||
'module',
|
||||
));
|
||||
$query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name');
|
||||
$query->orderBy('weight');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'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;
|
||||
}
|
||||
|
||||
}
|
||||
77
core/modules/field/src/Plugin/migrate/source/d7/Field.php
Executable file
77
core/modules/field/src/Plugin/migrate/source/d7/Field.php
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d7\Field.
|
||||
*/
|
||||
|
||||
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.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_field"
|
||||
* )
|
||||
*/
|
||||
class Field extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('field_config', 'fc')
|
||||
->fields('fc')
|
||||
->fields('fci', array('entity_type'))
|
||||
->condition('fc.active', 1)
|
||||
->condition('fc.deleted', 0)
|
||||
->condition('fc.storage_active', 1);
|
||||
$query->join('field_config_instance', 'fci', 'fc.id = fci.field_id');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'field_name' => $this->t('The name of this field.'),
|
||||
'type' => $this->t('The type of this field.'),
|
||||
'module' => $this->t('The module that implements the field type.'),
|
||||
'storage' => $this->t('The field storage.'),
|
||||
'locked' => $this->t('Locked'),
|
||||
'cardinality' => $this->t('Cardinality'),
|
||||
'translatable' => $this->t('Translatable'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row, $keep = TRUE) {
|
||||
foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
|
||||
$row->setSourceProperty($key, $value);
|
||||
}
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'field_name' => array(
|
||||
'type' => 'string',
|
||||
'alias' => 'fc',
|
||||
),
|
||||
'entity_type' => array(
|
||||
'type' => 'string',
|
||||
'alias' => 'fci',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
105
core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php
Executable file
105
core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php
Executable file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstance.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 7 field instances source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_field_instance",
|
||||
* )
|
||||
*/
|
||||
class FieldInstance extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('field_config_instance', 'fci')
|
||||
->fields('fci')
|
||||
->condition('fci.deleted', 0)
|
||||
->condition('fc.active', 1)
|
||||
->condition('fc.deleted', 0)
|
||||
->condition('fc.storage_active', 1);
|
||||
$query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
|
||||
|
||||
// Optionally filter by entity type and bundle.
|
||||
if (isset($this->configuration['entity_type'])) {
|
||||
$query->condition('entity_type', $this->configuration['entity_type']);
|
||||
|
||||
if (isset($this->configuration['bundle'])) {
|
||||
$query->condition('bundle', $this->configuration['bundle']);
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'field_name' => $this->t('The machine name of field.'),
|
||||
'entity_type' => $this->t('The entity type.'),
|
||||
'bundle' => $this->t('The entity bundle.'),
|
||||
'default_value' => $this->t('Default value'),
|
||||
'instance_settings' => $this->t('Field instance settings.'),
|
||||
'widget_settings' => $this->t('Widget settings.'),
|
||||
'display_settings' => $this->t('Display settings.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$data = unserialize($row->getSourceProperty('data'));
|
||||
|
||||
$row->setSourceProperty('label', $data['label']);
|
||||
$row->setSourceProperty('description', $data['description']);
|
||||
$row->setSourceProperty('required', $data['required']);
|
||||
|
||||
$default_value = !empty($data['default_value']) ? $data['default_value'] : array();
|
||||
if ($data['widget']['type'] == 'email_textfield' && $default_value) {
|
||||
$default_value[0]['value'] = $default_value[0]['email'];
|
||||
unset($default_value[0]['email']);
|
||||
}
|
||||
$row->setSourceProperty('default_value', $default_value);
|
||||
|
||||
// Settings.
|
||||
$row->setSourceProperty('instance_settings', $data['settings']);
|
||||
$row->setSourceProperty('widget_settings', $data['widget']);
|
||||
$row->setSourceProperty('display_settings', $data['display']);
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'entity_type' => array(
|
||||
'type' => 'string',
|
||||
'alias' => 'fci',
|
||||
),
|
||||
'bundle' => array(
|
||||
'type' => 'string',
|
||||
'alias' => 'fci',
|
||||
),
|
||||
'field_name' => array(
|
||||
'type' => 'string',
|
||||
'alias' => 'fci',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstancePerFormDisplay.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* The field instance per form display source class.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_field_instance_per_form_display"
|
||||
* )
|
||||
*/
|
||||
class FieldInstancePerFormDisplay extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('field_config_instance', 'fci')
|
||||
->fields('fci', array(
|
||||
'field_name',
|
||||
'bundle',
|
||||
'data',
|
||||
'entity_type'
|
||||
))
|
||||
->fields('fc', array(
|
||||
'type',
|
||||
'module',
|
||||
))
|
||||
->condition('fci.entity_type','node');
|
||||
$query->join('field_config', 'fc', 'fci.field_id = fc.id');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$data = unserialize($row->getSourceProperty('data'));
|
||||
$row->setSourceProperty('widget', $data['widget']);
|
||||
$row->setSourceProperty('widget_settings', $data['widget']['settings']);
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'field_name' => $this->t('The machine name of field.'),
|
||||
'bundle' => $this->t('Content type where this field is used.'),
|
||||
'data' => $this->t('Field configuration data.'),
|
||||
'entity_type' => $this->t('The entity type.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'bundle' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'field_name' => array(
|
||||
'type' => 'string',
|
||||
'alias' => 'fci',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstancePerViewMode.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* The field instance per view mode source class.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_field_instance_per_view_mode",
|
||||
* source_provider = "field"
|
||||
* )
|
||||
*/
|
||||
class FieldInstancePerViewMode extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
$rows = array();
|
||||
$result = $this->prepareQuery()->execute();
|
||||
foreach ($result as $field_instance) {
|
||||
$data = unserialize($field_instance['data']);
|
||||
// We don't need to include the serialized data in the returned rows.
|
||||
unset($field_instance['data']);
|
||||
foreach ($data['display'] as $view_mode => $info) {
|
||||
$rows[] = array_merge($field_instance, $info, array('view_mode' => $view_mode));
|
||||
}
|
||||
}
|
||||
return new \ArrayIterator($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('field_config_instance', 'fci')
|
||||
->fields('fci', array('entity_type', 'bundle', 'field_name', 'data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'entity_type' => $this->t('The entity type ID.'),
|
||||
'bundle' => $this->t('The bundle ID.'),
|
||||
'field_name' => $this->t('Machine name of the field.'),
|
||||
'view_mode' => $this->t('The original machine name of the view mode.'),
|
||||
'label' => $this->t('The display label of the field.'),
|
||||
'type' => $this->t('The formatter ID.'),
|
||||
'settings' => $this->t('Array of formatter-specific settings.'),
|
||||
'module' => $this->t('The module providing the formatter.'),
|
||||
'weight' => $this->t('Display weight of the field.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array(
|
||||
'entity_type' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'bundle' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'view_mode' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'field_name' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count() {
|
||||
return $this->initializeIterator()->count();
|
||||
}
|
||||
|
||||
}
|
||||
78
core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php
Normal file
78
core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Plugin\migrate\source\d7\ViewMode.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Annotation\MigrateSource;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* @MigrateSource(
|
||||
* id = "d7_view_mode"
|
||||
* )
|
||||
*/
|
||||
class ViewMode extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initializeIterator() {
|
||||
$rows = [];
|
||||
$result = $this->prepareQuery()->execute();
|
||||
foreach ($result as $field_instance) {
|
||||
$data = unserialize($field_instance['data']);
|
||||
foreach (array_keys($data['display']) as $view_mode) {
|
||||
$key = $field_instance['entity_type'] . '.' . $view_mode;
|
||||
$rows[$key] = [
|
||||
'entity_type' => $field_instance['entity_type'],
|
||||
'view_mode' => $view_mode,
|
||||
];
|
||||
}
|
||||
}
|
||||
return new \ArrayIterator($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'view_mode' => $this->t('The view mode ID.'),
|
||||
'entity_type' => $this->t('The entity type ID.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('field_config_instance', 'fci')
|
||||
->fields('fci', ['entity_type', 'data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [
|
||||
'entity_type' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
'view_mode' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count() {
|
||||
return $this->initializeIterator()->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ class BooleanFieldTest extends WebTestBase {
|
|||
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
|
||||
$content = $display->build($entity);
|
||||
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
|
||||
$this->assertRaw('<div class="field-item">' . $on . '</div>');
|
||||
$this->assertRaw('<div class="field__item">' . $on . '</div>');
|
||||
|
||||
// Test if we can change the on label.
|
||||
$on = $this->randomMachineName();
|
||||
|
|
|
|||
|
|
@ -119,6 +119,9 @@ class DisplayApiTest extends FieldUnitTestBase {
|
|||
function testFieldItemListView() {
|
||||
$items = $this->entity->get($this->fieldName);
|
||||
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
|
||||
// No display settings: check that default display settings are used.
|
||||
$build = $items->view();
|
||||
$this->render($build);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Entity\Update\SqlContentEntityStorageSchemaColumnTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Entity\Update;
|
||||
|
||||
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
|
||||
use Drupal\entity_test\Entity\EntityTestRev;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests that schema changes in fields with data are detected during updates.
|
||||
*
|
||||
* @group Entity
|
||||
*/
|
||||
class SqlContentEntityStorageSchemaColumnTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['entity_test', 'field', 'text', 'user'];
|
||||
|
||||
/**
|
||||
* The created entity.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Entity
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* The field.
|
||||
*
|
||||
* @var \Drupal\field\FieldConfigInterface
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* The field storage.
|
||||
*
|
||||
* @var \Drupal\field\FieldStorageConfigInterface
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_rev');
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
$field_name = 'test';
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test_rev',
|
||||
'type' => 'string',
|
||||
'cardinality' => 1,
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
|
||||
$this->field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test_rev',
|
||||
'bundle' => 'entity_test_rev',
|
||||
'required' => TRUE,
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
// Create an entity with field data.
|
||||
$this->entity = EntityTestRev::create([
|
||||
'user_id' => mt_rand(1, 10),
|
||||
'name' => $this->randomMachineName(),
|
||||
$field_name => $this->randomString(),
|
||||
]);
|
||||
$this->entity->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that column-level schema changes are detected for fields with data.
|
||||
*/
|
||||
public function testColumnUpdate() {
|
||||
// Change the field type in the stored schema.
|
||||
$schema = \Drupal::keyValue('entity.storage_schema.sql')->get('entity_test_rev.field_schema_data.test');
|
||||
$schema['entity_test_rev__test']['fields']['test_value']['type'] = 'varchar_ascii';
|
||||
\Drupal::keyValue('entity.storage_schema.sql')->set('entity_test_rev.field_schema_data.test', $schema);
|
||||
|
||||
// Now attempt to run automatic updates. An exception should be thrown
|
||||
// since there is data in the table.
|
||||
try {
|
||||
\Drupal::service('entity.definition_update_manager')->applyUpdates();
|
||||
$this->fail('Failed to detect a schema change in a field with data.');
|
||||
}
|
||||
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
|
||||
$this->pass('Detected a schema change in a field with data.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -72,6 +72,10 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Use Classy theme for testing markup output.
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
|
||||
// Grant the 'view test entity' permission.
|
||||
$this->installConfig(array('user'));
|
||||
Role::load(RoleInterface::ANONYMOUS_ID)
|
||||
|
|
@ -170,7 +174,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
|
|||
$formatter = 'entity_reference_entity_id';
|
||||
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
|
||||
|
||||
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->id(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
|
||||
$this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->id(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
|
||||
$this->assertEqual($build[0]['#cache']['tags'], $this->referencedEntity->getCacheTags(), sprintf('The %s formatter has the expected cache tags.', $formatter));
|
||||
$this->assertTrue(!isset($build[1]), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
|
||||
}
|
||||
|
|
@ -185,18 +189,14 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
|
|||
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
|
||||
|
||||
// Test the first field item.
|
||||
$expected_rendered_name_field_1 = '<div class="field field-entity-test--name field-name-name field-type-string field-label-hidden">
|
||||
<div class="field-items">
|
||||
<div class="field-item">' . $this->referencedEntity->label() . '</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
$expected_rendered_body_field_1 = '<div class="field field-entity-test--body field-name-body field-type-text field-label-above">
|
||||
<div class="field-label">Body</div>
|
||||
<div class="field-items">
|
||||
<div class="field-item"><p>Hello, world!</p></div>
|
||||
</div>
|
||||
</div>
|
||||
$expected_rendered_name_field_1 = '
|
||||
<div class="field field--name-name field--type-string field--label-hidden field__item">' . $this->referencedEntity->label() . '</div>
|
||||
';
|
||||
$expected_rendered_body_field_1 = '
|
||||
<div class="clearfix text-formatted field field--name-body field--type-text field--label-above">
|
||||
<div class="field__label">Body</div>
|
||||
<div class="field__item"><p>Hello, world!</p></div>
|
||||
</div>
|
||||
';
|
||||
$renderer->renderRoot($build[0]);
|
||||
$this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
|
||||
|
|
@ -244,7 +244,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
|
|||
// The second referenced entity is "autocreated", therefore not saved and
|
||||
// lacking any URL info.
|
||||
$expected_item_2 = array(
|
||||
'#markup' => $this->unsavedReferencedEntity->label(),
|
||||
'#plain_text' => $this->unsavedReferencedEntity->label(),
|
||||
'#cache' => array(
|
||||
'contexts' => [
|
||||
'user.permissions',
|
||||
|
|
@ -257,8 +257,8 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
|
|||
|
||||
// Test with the 'link' setting set to FALSE.
|
||||
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE));
|
||||
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
|
||||
$this->assertEqual($build[1]['#markup'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
|
||||
$this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
|
||||
$this->assertEqual($build[1]['#plain_text'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
|
||||
|
||||
// Test an entity type that doesn't have any link templates, which means
|
||||
// \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
|
||||
|
|
@ -273,7 +273,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
|
|||
$referenced_entity_with_no_link_template->save();
|
||||
|
||||
$build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE));
|
||||
$this->assertEqual($build[0]['#markup'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
|
||||
$this->assertEqual($build[0]['#plain_text'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace Drupal\field\Tests\EntityReference;
|
|||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\StringTranslation\TranslationWrapper;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
|
|
@ -111,6 +112,10 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
|
|||
$this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $this->term->getName());
|
||||
$this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $tid);
|
||||
$this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid());
|
||||
// Verify that the label for the target ID property definition is correct.
|
||||
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
|
||||
$this->assertTrue($label instanceof TranslationWrapper);
|
||||
$this->assertEqual($label->render(), 'Taxonomy term ID');
|
||||
|
||||
// Change the name of the term via the reference.
|
||||
$new_name = $this->randomMachineName();
|
||||
|
|
@ -178,6 +183,10 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
|
|||
$storage = \Drupal::entityManager()->getStorage('entity_test');
|
||||
$storage->resetCache();
|
||||
$this->assertEqual($this->entityStringId->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id);
|
||||
// Verify that the label for the target ID property definition is correct.
|
||||
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
|
||||
$this->assertTrue($label instanceof TranslationWrapper);
|
||||
$this->assertEqual($label->render(), 'Taxonomy term ID');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
namespace Drupal\field\Tests;
|
||||
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests counting field data records and the hasData() method on
|
||||
|
|
@ -146,6 +148,20 @@ class FieldDataCountTest extends FieldUnitTestBase {
|
|||
* Verify that we can count a table that contains an entry with index 0.
|
||||
*/
|
||||
public function testCountWithIndex0() {
|
||||
// Create a field that will require dedicated storage.
|
||||
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => 'field_int',
|
||||
'entity_type' => 'user',
|
||||
'type' => 'integer',
|
||||
'cardinality' => 2,
|
||||
));
|
||||
$field_storage->save();
|
||||
FieldConfig::create(array(
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'user',
|
||||
))->save();
|
||||
|
||||
// Create an entry for the anonymous user, who has user ID 0.
|
||||
$user = $this->storageUser
|
||||
->create(array(
|
||||
|
|
@ -153,11 +169,17 @@ class FieldDataCountTest extends FieldUnitTestBase {
|
|||
'name' => 'anonymous',
|
||||
'mail' => NULL,
|
||||
'status' => FALSE,
|
||||
'field_int' => 42,
|
||||
));
|
||||
$user->save();
|
||||
|
||||
// Test shared table storage.
|
||||
$storage = $user->getFieldDefinition('name')->getFieldStorageDefinition();
|
||||
$this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
|
||||
|
||||
// Test dedicated table storage.
|
||||
$storage = $user->getFieldDefinition('field_int')->getFieldStorageDefinition();
|
||||
$this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\field\Tests;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
|
@ -105,7 +105,7 @@ class FormTest extends FieldTestBase {
|
|||
$this->drupalGet('entity_test/add');
|
||||
|
||||
// Create token value expected for description.
|
||||
$token_description = SafeMarkup::checkPlain($this->config('system.site')->get('name')) . '_description';
|
||||
$token_description = Html::escape($this->config('system.site')->get('name')) . '_description';
|
||||
$this->assertText($token_description, 'Token replacement for description is displayed');
|
||||
$this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed');
|
||||
$this->assertNoField("{$field_name}[1][value]", 'No extraneous widget is displayed');
|
||||
|
|
@ -334,12 +334,12 @@ class FormTest extends FieldTestBase {
|
|||
// Display creation form -> 1 widget.
|
||||
$this->drupalGet('entity_test/add');
|
||||
// Check that the Required symbol is present for the multifield label.
|
||||
$this->assertRaw(SafeMarkup::format('<h4 class="label form-required">@label</h4>', array('@label' => $this->field['label'])),
|
||||
'Required symbol added field label.');
|
||||
$element = $this->xpath('//h4[contains(@class, "label") and contains(@class, "js-form-required") and contains(text(), :value)]', array(':value' => $this->field['label']));
|
||||
$this->assertTrue(isset($element[0]), 'Required symbol added field label.');
|
||||
// Check that the label of the field input is visually hidden and contains
|
||||
// the field title and an indication of the delta for a11y.
|
||||
$this->assertRaw(SafeMarkup::format('<label for="edit-field-unlimited-0-value" class="visually-hidden form-required">@label (value 1)</label>', array('@label' => $this->field['label'])),
|
||||
'Required symbol not added for field input.');
|
||||
$element = $this->xpath('//label[@for=:for and contains(@class, "js-form-required") and contains(text(), :value)]', array(':for' => 'edit-field-unlimited-0-value', ':value' => $this->field['label'] . ' (value 1)'));
|
||||
$this->assertTrue(isset($element[0]), 'Required symbol not added for field input.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,228 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldFormatterSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewMode;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade field formatter settings to entity.display.*.*.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'field', 'datetime', 'image', 'text', 'link', 'file', 'telephone');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['node']);
|
||||
|
||||
entity_create('node_type', array('type' => 'test_page'))->save();
|
||||
entity_create('node_type', array('type' => 'story'))->save();
|
||||
// Create the node preview view mode.
|
||||
EntityViewMode::create(array('id' => 'node.preview', 'targetEntityType' => 'node'))->save();
|
||||
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_view_modes' => array(
|
||||
array(array(1), array('node', 'preview')),
|
||||
array(array(4), array('node', 'rss')),
|
||||
array(array('teaser'), array('node', 'teaser')),
|
||||
array(array('full'), array('node', 'full')),
|
||||
),
|
||||
'd6_field_instance' => array(
|
||||
array(array('fieldname', 'page'), array('node', 'fieldname', 'page')),
|
||||
),
|
||||
'd6_field' => array(
|
||||
array(array('field_test'), array('node', 'field_test')),
|
||||
array(array('field_test_two'), array('node', 'field_test_two')),
|
||||
array(array('field_test_three'), array('node', 'field_test_three')),
|
||||
array(array('field_test_email'), array('node', 'field_test_email')),
|
||||
array(array('field_test_link'), array('node', 'field_test_link')),
|
||||
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
|
||||
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
|
||||
array(array('field_test_phone'), array('node', 'field_test_phone')),
|
||||
array(array('field_test_date'), array('node', 'field_test_date')),
|
||||
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
|
||||
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
|
||||
array(array('field_test_exclude_unset'), array('node', 'field_test_exclude_unset')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_field_formatter_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that migrated entity display settings can be loaded using D8 API's.
|
||||
*/
|
||||
public function testEntityDisplaySettings() {
|
||||
// Run tests.
|
||||
$field_name = "field_test";
|
||||
$expected = array(
|
||||
'label' => 'above',
|
||||
'weight' => 1,
|
||||
'type' => 'text_trimmed',
|
||||
'settings' => array('trim_length' => 600),
|
||||
'third_party_settings' => array(),
|
||||
);
|
||||
|
||||
// Can we load any entity display.
|
||||
$display = entity_load('entity_view_display', 'node.story.teaser');
|
||||
$this->assertIdentical($expected, $display->getComponent($field_name));
|
||||
|
||||
// Test migrate worked with multiple bundles.
|
||||
$display = entity_load('entity_view_display', 'node.test_page.teaser');
|
||||
$expected['weight'] = 35;
|
||||
$this->assertIdentical($expected, $display->getComponent($field_name));
|
||||
|
||||
// Test RSS because that has been converted from 4 to rss.
|
||||
$display = entity_load('entity_view_display', 'node.story.rss');
|
||||
$expected['weight'] = 1;
|
||||
$this->assertIdentical($expected, $display->getComponent($field_name));
|
||||
|
||||
// Test the default format with text_default which comes from a static map.
|
||||
$expected['type'] = 'text_default';
|
||||
$expected['settings'] = array();
|
||||
$display = entity_load('entity_view_display', 'node.story.default');
|
||||
$this->assertIdentical($expected, $display->getComponent($field_name));
|
||||
|
||||
// Check that we can migrate multiple fields.
|
||||
$content = $display->get('content');
|
||||
$this->assertTrue(isset($content['field_test']), 'Settings for field_test exist.');
|
||||
$this->assertTrue(isset($content['field_test_two']), "Settings for field_test_two exist.");
|
||||
|
||||
// Check that we can migrate a field where exclude is not set.
|
||||
$this->assertTrue(isset($content['field_test_exclude_unset']), "Settings for field_test_exclude_unset exist.");
|
||||
|
||||
// Test the number field formatter settings are correct.
|
||||
$expected['weight'] = 1;
|
||||
$expected['type'] = 'number_integer';
|
||||
$expected['settings'] = array(
|
||||
'thousand_separator' => ',',
|
||||
'prefix_suffix' => TRUE,
|
||||
);
|
||||
$component = $display->getComponent('field_test_two');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$expected['weight'] = 2;
|
||||
$expected['type'] = 'number_decimal';
|
||||
$expected['settings'] = array(
|
||||
'scale' => 2,
|
||||
'decimal_separator' => '.',
|
||||
'thousand_separator' => ',',
|
||||
'prefix_suffix' => TRUE,
|
||||
);
|
||||
$component = $display->getComponent('field_test_three');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test the email field formatter settings are correct.
|
||||
$expected['weight'] = 6;
|
||||
$expected['type'] = 'email_mailto';
|
||||
$expected['settings'] = array();
|
||||
$component = $display->getComponent('field_test_email');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test the link field formatter settings.
|
||||
$expected['weight'] = 7;
|
||||
$expected['type'] = 'link';
|
||||
$expected['settings'] = array(
|
||||
'trim_length' => 80,
|
||||
'url_only' => TRUE,
|
||||
'url_plain' => TRUE,
|
||||
'rel' => '0',
|
||||
'target' => '0',
|
||||
);
|
||||
$component = $display->getComponent('field_test_link');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$expected['settings']['url_only'] = FALSE;
|
||||
$expected['settings']['url_plain'] = FALSE;
|
||||
$display = entity_load('entity_view_display', 'node.story.teaser');
|
||||
$component = $display->getComponent('field_test_link');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test the file field formatter settings.
|
||||
$expected['weight'] = 8;
|
||||
$expected['type'] = 'file_default';
|
||||
$expected['settings'] = array();
|
||||
$component = $display->getComponent('field_test_filefield');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$display = entity_load('entity_view_display', 'node.story.default');
|
||||
$expected['type'] = 'file_url_plain';
|
||||
$component = $display->getComponent('field_test_filefield');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test the image field formatter settings.
|
||||
$expected['weight'] = 9;
|
||||
$expected['type'] = 'image';
|
||||
$expected['settings'] = array('image_style' => '', 'image_link' => '');
|
||||
$component = $display->getComponent('field_test_imagefield');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$display = entity_load('entity_view_display', 'node.story.teaser');
|
||||
$expected['settings']['image_link'] = 'file';
|
||||
$component = $display->getComponent('field_test_imagefield');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test phone field.
|
||||
$expected['weight'] = 13;
|
||||
$expected['type'] = 'basic_string';
|
||||
$expected['settings'] = array();
|
||||
$component = $display->getComponent('field_test_phone');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test date field.
|
||||
$defaults = array('format_type' => 'fallback', 'timezone_override' => '',);
|
||||
$expected['weight'] = 10;
|
||||
$expected['type'] = 'datetime_default';
|
||||
$expected['settings'] = array('format_type' => 'fallback') + $defaults;
|
||||
$component = $display->getComponent('field_test_date');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$display = entity_load('entity_view_display', 'node.story.default');
|
||||
$expected['settings']['format_type'] = 'long';
|
||||
$component = $display->getComponent('field_test_date');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test date stamp field.
|
||||
$expected['weight'] = 11;
|
||||
$expected['settings']['format_type'] = 'fallback';
|
||||
$component = $display->getComponent('field_test_datestamp');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$display = entity_load('entity_view_display', 'node.story.teaser');
|
||||
$expected['settings'] = array('format_type' => 'medium') + $defaults;
|
||||
$component = $display->getComponent('field_test_datestamp');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test datetime field.
|
||||
$expected['weight'] = 12;
|
||||
$expected['settings'] = array('format_type' => 'short') + $defaults;
|
||||
$component = $display->getComponent('field_test_datetime');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$display = entity_load('entity_view_display', 'node.story.default');
|
||||
$expected['settings']['format_type'] = 'fallback';
|
||||
$component = $display->getComponent('field_test_datetime');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Test a date field with a random format which should be mapped
|
||||
// to datetime_default.
|
||||
$display = entity_load('entity_view_display', 'node.story.rss');
|
||||
$expected['settings']['format_type'] = 'fallback';
|
||||
$component = $display->getComponent('field_test_datetime');
|
||||
$this->assertIdentical($expected, $component);
|
||||
// Test that our Id map has the correct data.
|
||||
$this->assertIdentical(array('node', 'story', 'teaser', 'field_test'), entity_load('migration', 'd6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test')));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldInstanceTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\link\LinkItemInterface;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Migrate field instances.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateFieldInstanceTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
'telephone',
|
||||
'link',
|
||||
'file',
|
||||
'image',
|
||||
'datetime',
|
||||
'node',
|
||||
'field',
|
||||
'text',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_field' => array(
|
||||
array(array('field_test'), array('node', 'field_test')),
|
||||
array(array('field_test_two'), array('node', 'field_test_two')),
|
||||
array(array('field_test_three'), array('node', 'field_test_three')),
|
||||
array(array('field_test_four'), array('node', 'field_test_four')),
|
||||
array(array('field_test_email'), array('node', 'field_test_email')),
|
||||
array(array('field_test_link'), array('node', 'field_test_link')),
|
||||
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
|
||||
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
|
||||
array(array('field_test_phone'), array('node', 'field_test_phone')),
|
||||
array(array('field_test_date'), array('node', 'field_test_date')),
|
||||
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
|
||||
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
|
||||
),
|
||||
'd6_node_type' => array(
|
||||
array(array('page'), array('page')),
|
||||
array(array('story'), array('story')),
|
||||
array(array('test_page'), array('test_page')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
entity_create('node_type', array('type' => 'page'))->save();
|
||||
entity_create('node_type', array('type' => 'story'))->save();
|
||||
entity_create('node_type', array('type' => 'test_page'))->save();
|
||||
|
||||
$this->createFields();
|
||||
$this->executeMigration('d6_field_instance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of file variables to file.settings.yml.
|
||||
*/
|
||||
public function testFieldInstanceSettings() {
|
||||
$entity = entity_create('node', array('type' => 'story'));
|
||||
// Test a text field.
|
||||
$field = FieldConfig::load('node.story.field_test');
|
||||
$this->assertIdentical('Text Field', $field->label());
|
||||
$expected = array('max_length' => 255);
|
||||
$this->assertIdentical($expected, $field->getSettings());
|
||||
$this->assertIdentical('text for default value', $entity->field_test->value);
|
||||
|
||||
// Test a number field.
|
||||
$field = FieldConfig::load('node.story.field_test_two');
|
||||
$this->assertIdentical('Integer Field', $field->label());
|
||||
$expected = array(
|
||||
'min' => 10,
|
||||
'max' => 100,
|
||||
'prefix' => 'pref',
|
||||
'suffix' => 'suf',
|
||||
'unsigned' => FALSE,
|
||||
'size' => 'normal',
|
||||
);
|
||||
$this->assertIdentical($expected, $field->getSettings());
|
||||
|
||||
$field = FieldConfig::load('node.story.field_test_four');
|
||||
$this->assertIdentical('Float Field', $field->label());
|
||||
$expected = array(
|
||||
'min' => 100.0,
|
||||
'max' => 200.0,
|
||||
'prefix' => 'id-',
|
||||
'suffix' => '',
|
||||
);
|
||||
$this->assertIdentical($expected, $field->getSettings());
|
||||
|
||||
// Test email field.
|
||||
$field = FieldConfig::load('node.story.field_test_email');
|
||||
$this->assertIdentical('Email Field', $field->label());
|
||||
$this->assertIdentical('benjy@example.com', $entity->field_test_email->value);
|
||||
|
||||
// Test a filefield.
|
||||
$field = FieldConfig::load('node.story.field_test_filefield');
|
||||
$this->assertIdentical('File Field', $field->label());
|
||||
$expected = array(
|
||||
'file_extensions' => 'txt pdf doc',
|
||||
'file_directory' => 'images',
|
||||
'description_field' => TRUE,
|
||||
'max_filesize' => '200KB',
|
||||
'target_type' => 'file',
|
||||
'display_field' => FALSE,
|
||||
'display_default' => FALSE,
|
||||
'uri_scheme' => 'public',
|
||||
// This value should be 'default:file' but the test does not migrate field
|
||||
// storages so we end up with the default value for this setting.
|
||||
'handler' => 'default:node',
|
||||
'handler_settings' => array(),
|
||||
'target_bundle' => NULL,
|
||||
);
|
||||
$field_settings = $field->getSettings();
|
||||
ksort($expected);
|
||||
ksort($field_settings);
|
||||
// This is the only way to compare arrays.
|
||||
$this->assertIdentical($expected, $field_settings);
|
||||
|
||||
// Test a link field.
|
||||
$field = FieldConfig::load('node.story.field_test_link');
|
||||
$this->assertIdentical('Link Field', $field->label());
|
||||
$expected = array('title' => 2, 'link_type' => LinkItemInterface::LINK_GENERIC);
|
||||
$this->assertIdentical($expected, $field->getSettings());
|
||||
$this->assertIdentical('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.');
|
||||
$this->assertIdentical('https://www.drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.');
|
||||
$this->assertIdentical([], $entity->field_test_link->options['attributes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create fields.
|
||||
*/
|
||||
protected function createFields() {
|
||||
$fields = array(
|
||||
'field_test' => 'text',
|
||||
'field_test_two' => 'integer',
|
||||
'field_test_three' => 'decimal',
|
||||
'field_test_four' => 'float',
|
||||
'field_test_email' => 'email',
|
||||
'field_test_link' => 'link',
|
||||
'field_test_filefield' => 'file',
|
||||
'field_test_imagefield' => 'image',
|
||||
'field_test_phone' => 'telephone',
|
||||
'field_test_date' => 'datetime',
|
||||
'field_test_datestamp' => 'datetime',
|
||||
'field_test_datetime' => 'datetime',
|
||||
);
|
||||
foreach ($fields as $name => $type) {
|
||||
entity_create('field_storage_config', array(
|
||||
'field_name' => $name,
|
||||
'entity_type' => 'node',
|
||||
'type' => $type,
|
||||
))->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
107
core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php
Normal file
107
core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Migrate fields.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateFieldTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('field', 'telephone', 'link', 'file', 'image', 'datetime', 'node', 'options', 'text');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d6_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 6 field to Drupal 8 migration.
|
||||
*/
|
||||
public function testFields() {
|
||||
// Text field.
|
||||
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
|
||||
$field_storage = FieldStorageConfig::load('node.field_test');
|
||||
$expected = array('max_length' => 255);
|
||||
$this->assertIdentical("text", $field_storage->getType(), t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->getType())));
|
||||
$this->assertIdentical($expected, $field_storage->getSettings(), "Field type text settings are correct");
|
||||
|
||||
// Integer field.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_two');
|
||||
$this->assertIdentical("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
// Float field.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_three');
|
||||
$this->assertIdentical("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
// Link field.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_link');
|
||||
$this->assertIdentical("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
// File field.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_filefield');
|
||||
$this->assertIdentical("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_imagefield');
|
||||
$this->assertIdentical("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->getType())));
|
||||
$settings = $field_storage->getSettings();
|
||||
$this->assertIdentical('file', $settings['target_type']);
|
||||
$this->assertIdentical('public', $settings['uri_scheme']);
|
||||
$this->assertIdentical(array(), array_filter($settings['default_image']));
|
||||
|
||||
// Phone field.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_phone');
|
||||
$this->assertIdentical("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
// Date field.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_datetime');
|
||||
$this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
// Decimal field with radio buttons.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons');
|
||||
$this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->getType())));
|
||||
$this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2'));
|
||||
$this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1'));
|
||||
$this->assertIdentical('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
|
||||
$this->assertIdentical('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
|
||||
|
||||
// Float field with a single checkbox.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
|
||||
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
// Integer field with a select list.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist');
|
||||
$this->assertIdentical("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->getType())));
|
||||
$this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234'));
|
||||
$this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341'));
|
||||
$this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412'));
|
||||
$this->assertNotNull($field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value key is set to 4123'));
|
||||
$this->assertIdentical('1234', $field_storage->getSetting('allowed_values')['1234'], t('First allowed value is set to 1234'));
|
||||
$this->assertIdentical('2341', $field_storage->getSetting('allowed_values')['2341'], t('Second allowed value is set to 2341'));
|
||||
$this->assertIdentical('3412', $field_storage->getSetting('allowed_values')['3412'], t('Third allowed value is set to 3412'));
|
||||
$this->assertIdentical('4123', $field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value is set to 4123'));
|
||||
|
||||
// Text field with a single checkbox.
|
||||
$field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox');
|
||||
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldWidgetSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Migrate field widget settings.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
'field',
|
||||
'telephone',
|
||||
'link',
|
||||
'file',
|
||||
'image',
|
||||
'datetime',
|
||||
'node',
|
||||
'text',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
entity_create('node_type', array('type' => 'test_page'))->save();
|
||||
entity_create('node_type', array('type' => 'story'))->save();
|
||||
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_field_instance' => array(
|
||||
array(array('fieldname', 'page'), array('node', 'fieldname', 'page')),
|
||||
),
|
||||
'd6_field' => array(
|
||||
array(array('field_test'), array('node', 'field_test')),
|
||||
array(array('field_test_two'), array('node', 'field_test_two')),
|
||||
array(array('field_test_three'), array('node', 'field_test_three')),
|
||||
array(array('field_test_email'), array('node', 'field_test_email')),
|
||||
array(array('field_test_link'), array('node', 'field_test_link')),
|
||||
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
|
||||
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
|
||||
array(array('field_test_phone'), array('node', 'field_test_phone')),
|
||||
array(array('field_test_date'), array('node', 'field_test_date')),
|
||||
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
|
||||
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_field_instance_widget_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that migrated view modes can be loaded using D8 API's.
|
||||
*/
|
||||
public function testWidgetSettings() {
|
||||
// Test the config can be loaded.
|
||||
$form_display = entity_load('entity_form_display', 'node.story.default');
|
||||
$this->assertIdentical(FALSE, is_null($form_display), "Form display node.story.default loaded with config.");
|
||||
|
||||
// Text field.
|
||||
$component = $form_display->getComponent('field_test');
|
||||
$expected = array('weight' => 1, 'type' => 'text_textfield');
|
||||
$expected['settings'] = array('size' => 60, 'placeholder' => '');
|
||||
$expected['third_party_settings'] = array();
|
||||
$this->assertIdentical($expected, $component, 'Text field settings are correct.');
|
||||
|
||||
// Integer field.
|
||||
$component = $form_display->getComponent('field_test_two');
|
||||
$expected['type'] = 'number';
|
||||
$expected['weight'] = 1;
|
||||
$expected['settings'] = array('placeholder' => '');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Float field.
|
||||
$component = $form_display->getComponent('field_test_three');
|
||||
$expected['weight'] = 2;
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Email field.
|
||||
$component = $form_display->getComponent('field_test_email');
|
||||
$expected['type'] = 'email_default';
|
||||
$expected['weight'] = 6;
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Link field.
|
||||
$component = $form_display->getComponent('field_test_link');
|
||||
$this->assertIdentical('link_default', $component['type']);
|
||||
$this->assertIdentical(7, $component['weight']);
|
||||
$this->assertFalse(array_filter($component['settings']));
|
||||
|
||||
// File field.
|
||||
$component = $form_display->getComponent('field_test_filefield');
|
||||
$expected['type'] = 'file_generic';
|
||||
$expected['weight'] = 8;
|
||||
$expected['settings'] = array('progress_indicator' => 'bar');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Image field.
|
||||
$component = $form_display->getComponent('field_test_imagefield');
|
||||
$expected['type'] = 'image_image';
|
||||
$expected['weight'] = 9;
|
||||
$expected['settings'] = array('progress_indicator' => 'bar', 'preview_image_style' => 'thumbnail');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Phone field.
|
||||
$component = $form_display->getComponent('field_test_phone');
|
||||
$expected['type'] = 'telephone_default';
|
||||
$expected['weight'] = 13;
|
||||
$expected['settings'] = array('placeholder' => '');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
// Date fields.
|
||||
$component = $form_display->getComponent('field_test_date');
|
||||
$expected['type'] = 'datetime_default';
|
||||
$expected['weight'] = 10;
|
||||
$expected['settings'] = array();
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
$component = $form_display->getComponent('field_test_datestamp');
|
||||
$expected['weight'] = 11;
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
$component = $form_display->getComponent('field_test_datetime');
|
||||
$expected['weight'] = 12;
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,283 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldFormatterSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Tests migration of D7 field formatter settings.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = [
|
||||
'comment',
|
||||
'datetime',
|
||||
'entity_reference',
|
||||
'file',
|
||||
'image',
|
||||
'link',
|
||||
'node',
|
||||
'telephone',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('comment');
|
||||
CommentType::create([
|
||||
'id' => 'comment_node_page',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
CommentType::create([
|
||||
'id' => 'comment_node_article',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
CommentType::create([
|
||||
'id' => 'comment_node_blog',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
CommentType::create([
|
||||
'id' => 'comment_node_book',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
CommentType::create([
|
||||
'id' => 'comment_node_forum',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
CommentType::create([
|
||||
'id' => 'comment_node_test_content_type',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
NodeType::create([
|
||||
'type' => 'page',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
NodeType::create([
|
||||
'type' => 'article',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
NodeType::create([
|
||||
'type' => 'blog',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
NodeType::create([
|
||||
'type' => 'book',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
NodeType::create([
|
||||
'type' => 'forum',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
NodeType::create([
|
||||
'type' => 'test_content_type',
|
||||
'label' => $this->randomMachineName(),
|
||||
])->save();
|
||||
|
||||
// Give one unfortunate field instance invalid display settings to ensure
|
||||
// that the migration provides an empty array as a default (thus avoiding
|
||||
// an "unsupported operand types" fatal).
|
||||
Database::getConnection('default', 'migrate')
|
||||
->update('field_config_instance')
|
||||
->fields(array(
|
||||
'data' => serialize(array (
|
||||
'label' => 'Body',
|
||||
'widget' =>
|
||||
array (
|
||||
'type' => 'text_textarea_with_summary',
|
||||
'settings' =>
|
||||
array (
|
||||
'rows' => 20,
|
||||
'summary_rows' => 5,
|
||||
),
|
||||
'weight' => -4,
|
||||
'module' => 'text',
|
||||
),
|
||||
'settings' =>
|
||||
array (
|
||||
'display_summary' => true,
|
||||
'text_processing' => 1,
|
||||
'user_register_form' => false,
|
||||
),
|
||||
'display' =>
|
||||
array (
|
||||
'default' =>
|
||||
array (
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_default',
|
||||
'settings' =>
|
||||
array (
|
||||
),
|
||||
'module' => 'text',
|
||||
'weight' => 0,
|
||||
),
|
||||
'teaser' =>
|
||||
array (
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_summary_or_trimmed',
|
||||
// settings is always expected to be an array. Making it NULL
|
||||
// causes a fatal.
|
||||
'settings' => NULL,
|
||||
'module' => 'text',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'required' => false,
|
||||
'description' => '',
|
||||
)),
|
||||
))
|
||||
->condition('entity_type', 'node')
|
||||
->condition('bundle', 'article')
|
||||
->condition('field_name', 'body')
|
||||
->execute();
|
||||
|
||||
$this->executeMigration('d7_field');
|
||||
$this->executeMigration('d7_field_instance');
|
||||
$this->executeMigration('d7_view_modes');
|
||||
$this->executeMigration('d7_field_formatter_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a view display.
|
||||
*
|
||||
* @param string $id
|
||||
* The view display ID.
|
||||
*/
|
||||
protected function assertEntity($id) {
|
||||
$display = EntityViewDisplay::load($id);
|
||||
$this->assertTrue($display instanceof EntityViewDisplayInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a particular component of a view display.
|
||||
*
|
||||
* @param string $display_id
|
||||
* The view display ID.
|
||||
* @param string $component_id
|
||||
* The component ID.
|
||||
* @param string $type
|
||||
* The expected component type (formatter plugin ID).
|
||||
* @param string $label
|
||||
* The expected label of the component.
|
||||
* @param int $weight
|
||||
* The expected weight of the component.
|
||||
*/
|
||||
protected function assertComponent($display_id, $component_id, $type, $label, $weight) {
|
||||
$component = EntityViewDisplay::load($display_id)->getComponent($component_id);
|
||||
$this->assertTrue(is_array($component));
|
||||
$this->assertIdentical($type, $component['type']);
|
||||
$this->assertIdentical($label, $component['label']);
|
||||
$this->assertIdentical($weight, $component['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a particular component is NOT included in a display.
|
||||
*
|
||||
* @param string $display_id
|
||||
* The display ID.
|
||||
* @param string $component_id
|
||||
* The component ID.
|
||||
*/
|
||||
protected function assertComponentNotExists($display_id, $component_id) {
|
||||
$component = EntityViewDisplay::load($display_id)->getComponent($component_id);
|
||||
$this->assertTrue(is_null($component));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of D7 field formatter settings.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertEntity('comment.comment_node_article.default');
|
||||
$this->assertComponent('comment.comment_node_article.default', 'comment_body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('comment.comment_node_blog.default');
|
||||
$this->assertComponent('comment.comment_node_blog.default', 'comment_body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('comment.comment_node_book.default');
|
||||
$this->assertComponent('comment.comment_node_book.default', 'comment_body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('comment.comment_node_forum.default');
|
||||
$this->assertComponent('comment.comment_node_forum.default', 'comment_body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('comment.comment_node_page.default');
|
||||
$this->assertComponent('comment.comment_node_page.default', 'comment_body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('comment.comment_node_test_content_type.default');
|
||||
$this->assertComponent('comment.comment_node_test_content_type.default', 'comment_body', 'text_default', 'hidden', 0);
|
||||
$this->assertComponent('comment.comment_node_test_content_type.default', 'field_integer', 'number_integer', 'above', 1);
|
||||
|
||||
$this->assertEntity('node.article.default');
|
||||
$this->assertComponent('node.article.default', 'body', 'text_default', 'hidden', 0);
|
||||
$this->assertComponent('node.article.default', 'field_tags', 'entity_reference_label', 'above', 10);
|
||||
$this->assertComponent('node.article.default', 'field_image', 'image', 'hidden', -1);
|
||||
|
||||
$this->assertEntity('node.article.teaser');
|
||||
$this->assertComponent('node.article.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
|
||||
$this->assertComponent('node.article.teaser', 'field_tags', 'entity_reference_label', 'above', 10);
|
||||
$this->assertComponent('node.article.teaser', 'field_image', 'image', 'hidden', -1);
|
||||
|
||||
$this->assertEntity('node.blog.default');
|
||||
$this->assertComponent('node.blog.default', 'body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('node.blog.teaser');
|
||||
$this->assertComponent('node.blog.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('node.book.default');
|
||||
$this->assertComponent('node.book.default', 'body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('node.book.teaser');
|
||||
$this->assertComponent('node.book.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('node.forum.default');
|
||||
$this->assertComponent('node.forum.default', 'body', 'text_default', 'hidden', 11);
|
||||
$this->assertComponent('node.forum.default', 'taxonomy_forums', 'entity_reference_label', 'above', 10);
|
||||
|
||||
$this->assertEntity('node.forum.teaser');
|
||||
$this->assertComponent('node.forum.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 11);
|
||||
$this->assertComponent('node.forum.teaser', 'taxonomy_forums', 'entity_reference_label', 'above', 10);
|
||||
|
||||
$this->assertEntity('node.page.default');
|
||||
$this->assertComponent('node.page.default', 'body', 'text_default', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('node.page.teaser');
|
||||
$this->assertComponent('node.page.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
|
||||
|
||||
$this->assertEntity('node.test_content_type.default');
|
||||
$this->assertComponent('node.test_content_type.default', 'field_boolean', 'list_default', 'above', 0);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_email', 'email_mailto', 'above', 1);
|
||||
// Phone formatters are not mapped and should default to basic_string.
|
||||
$this->assertComponent('node.test_content_type.default', 'field_phone', 'basic_string', 'above', 2);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_date', 'datetime_default', 'above', 3);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_date_with_end_time', 'datetime_default', 'above', 4);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_file', 'file_default', 'above', 5);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_float', 'number_decimal', 'above', 6);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_images', 'image', 'above', 7);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_integer', 'number_integer', 'above', 8);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_link', 'link', 'above', 9);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'list_default', 'above', 10);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'list_default', 'above', 11);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_default', 'above', 12);
|
||||
$this->assertComponentNotExists('node.test_content_type.default', 'field_term_reference');
|
||||
$this->assertComponentNotExists('node.test_content_type.default', 'field_text');
|
||||
|
||||
$this->assertEntity('user.user.default');
|
||||
$this->assertComponent('user.user.default', 'field_file', 'file_default', 'above', 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldInstanceTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Migrates Drupal 7 field instances.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* The modules to be enabled during the test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $modules = array(
|
||||
'comment',
|
||||
'datetime',
|
||||
'entity_reference',
|
||||
'file',
|
||||
'image',
|
||||
'link',
|
||||
'node',
|
||||
'system',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
'text',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->createType('page');
|
||||
$this->createType('article');
|
||||
$this->createType('blog');
|
||||
$this->createType('book');
|
||||
$this->createType('forum');
|
||||
$this->createType('test_content_type');
|
||||
$this->executeMigration('d7_field');
|
||||
$this->executeMigration('d7_field_instance');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node type with a corresponding comment type.
|
||||
*
|
||||
* @param string $id
|
||||
* The node type ID.
|
||||
*/
|
||||
protected function createType($id) {
|
||||
NodeType::create(array(
|
||||
'type' => $id,
|
||||
'label' => $this->randomString(),
|
||||
))->save();
|
||||
|
||||
CommentType::create(array(
|
||||
'id' => 'comment_node_' . $id,
|
||||
'label' => $this->randomString(),
|
||||
'target_entity_type_id' => 'node',
|
||||
))->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a field config entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
|
||||
* @param string $expected_label
|
||||
* The expected field label.
|
||||
* @param string $expected_field_type
|
||||
* The expected field type.
|
||||
* @param boolean $is_required
|
||||
* Whether or not the field is required.
|
||||
*/
|
||||
protected function assertEntity($id, $expected_label, $expected_field_type, $is_required) {
|
||||
list ($expected_entity_type, $expected_bundle, $expected_name) = explode('.', $id);
|
||||
|
||||
/** @var \Drupal\field\FieldConfigInterface $field */
|
||||
$field = FieldConfig::load($id);
|
||||
$this->assertTrue($field instanceof FieldConfigInterface);
|
||||
$this->assertIdentical($expected_label, $field->label());
|
||||
$this->assertIdentical($expected_field_type, $field->getType());
|
||||
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
|
||||
$this->assertIdentical($expected_bundle, $field->getTargetBundle());
|
||||
$this->assertIdentical($expected_name, $field->getName());
|
||||
$this->assertEqual($is_required, $field->isRequired());
|
||||
$this->assertIdentical($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migrating D7 field instances to field_config entities.
|
||||
*/
|
||||
public function testFieldInstances() {
|
||||
$this->assertEntity('comment.comment_node_page.comment_body', 'Comment', 'text_long', TRUE);
|
||||
$this->assertEntity('node.page.body', 'Body', 'text_with_summary', FALSE);
|
||||
$this->assertEntity('comment.comment_node_article.comment_body', 'Comment', 'text_long', TRUE);
|
||||
$this->assertEntity('node.article.body', 'Body', 'text_with_summary', FALSE);
|
||||
$this->assertEntity('node.article.field_tags', 'Tags', 'entity_reference', FALSE);
|
||||
$this->assertEntity('node.article.field_image', 'Image', 'image', FALSE);
|
||||
$this->assertEntity('comment.comment_node_blog.comment_body', 'Comment', 'text_long', TRUE);
|
||||
$this->assertEntity('node.blog.body', 'Body', 'text_with_summary', FALSE);
|
||||
$this->assertEntity('comment.comment_node_book.comment_body', 'Comment', 'text_long', TRUE);
|
||||
$this->assertEntity('node.book.body', 'Body', 'text_with_summary', FALSE);
|
||||
$this->assertEntity('node.forum.taxonomy_forums', 'Forums', 'entity_reference', TRUE);
|
||||
$this->assertEntity('comment.comment_node_forum.comment_body', 'Comment', 'text_long', TRUE);
|
||||
$this->assertEntity('node.forum.body', 'Body', 'text_with_summary', FALSE);
|
||||
$this->assertEntity('comment.comment_node_test_content_type.comment_body', 'Comment', 'text_long', TRUE);
|
||||
$this->assertEntity('node.test_content_type.field_boolean', 'Boolean', 'boolean', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_email', 'Email', 'email', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_phone', 'Phone', 'telephone', TRUE);
|
||||
$this->assertEntity('node.test_content_type.field_date', 'Date', 'datetime', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_date_with_end_time', 'Date With End Time', 'datetime', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_file', 'File', 'file', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_float', 'Float', 'float', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_images', 'Images', 'image', TRUE);
|
||||
$this->assertEntity('node.test_content_type.field_integer', 'Integer', 'integer', TRUE);
|
||||
$this->assertEntity('node.test_content_type.field_link', 'Link', 'link', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_text_list', 'Text List', 'list_string', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_text', 'Text', 'text', FALSE);
|
||||
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE);
|
||||
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldInstanceWidgetSettingsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Migrate field widget settings.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
'field',
|
||||
'telephone',
|
||||
'link',
|
||||
'file',
|
||||
'image',
|
||||
'datetime',
|
||||
'node',
|
||||
'text',
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a node type.
|
||||
*
|
||||
* @param string $id
|
||||
* The node type ID.
|
||||
*/
|
||||
protected function createNodeType($id) {
|
||||
NodeType::create(array(
|
||||
'type' => $id,
|
||||
'label' => $this->randomString(),
|
||||
))->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
|
||||
$this->createNodeType('page');
|
||||
$this->createNodeType('article');
|
||||
$this->createNodeType('blog');
|
||||
$this->createNodeType('book');
|
||||
$this->createNodeType('forum');
|
||||
$this->createNodeType('test_content_type');
|
||||
|
||||
// Add some id mappings for the dependent migrations.
|
||||
$id_mappings = [
|
||||
'd7_field' => [
|
||||
[['comment', 'comment_body'], ['comment', 'comment_body']],
|
||||
[['node', 'body'], ['node', 'body']],
|
||||
[['node', 'field_tags'], ['node', 'field_tags']],
|
||||
[['node', 'field_image'], ['node', 'field_image']],
|
||||
[['node', 'taxonomy_forums'], ['node', 'taxonomy_forums']],
|
||||
[['node', 'field_boolean'], ['node', 'field_boolean']],
|
||||
[['node', 'field_email'], ['node', 'field_email']],
|
||||
[['node', 'field_phone'], ['node', 'field_phone']],
|
||||
[['node', 'field_date'], ['node', 'field_date']],
|
||||
[['node', 'field_date_with_end_time'], ['node', 'field_date_with_end_time']],
|
||||
[['node', 'field_file'], ['node', 'field_file']],
|
||||
[['node', 'field_float'], ['node', 'field_float']],
|
||||
[['node', 'field_images'], ['node', 'field_images']],
|
||||
[['node', 'field_integer'], ['node', 'field_integer']],
|
||||
[['node', 'field_link'], ['node', 'field_link']],
|
||||
[['node', 'field_text_list'], ['node', 'field_text_list']],
|
||||
[['node', 'field_integer_list'], ['node', 'field_integer_list']],
|
||||
[['node', 'field_long_text'], ['node', 'field_long_text']],
|
||||
[['node', 'field_term_reference'], ['node', 'field_term_reference']],
|
||||
[['node', 'field_text'], ['node', 'field_text']],
|
||||
[['node', 'field_integer'], ['node', 'field_integer']],
|
||||
[['user', 'field_file'], ['user', 'field_file']],
|
||||
],
|
||||
// We don't actually need any ID lookups from the d7_field_instance
|
||||
// migration -- it's merely a sensible dependency.
|
||||
'd7_field_instance' => [],
|
||||
];
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d7_field_instance_widget_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a form display entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $expected_entity_type
|
||||
* The expected entity type to which the display settings are attached.
|
||||
* @param string $expected_bundle
|
||||
* The expected bundle to which the display settings are attached.
|
||||
*/
|
||||
protected function assertEntity($id, $expected_entity_type, $expected_bundle) {
|
||||
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity */
|
||||
$entity = EntityFormDisplay::load($id);
|
||||
$this->assertTrue($entity instanceof EntityFormDisplayInterface);
|
||||
$this->assertIdentical($expected_entity_type, $entity->getTargetEntityTypeId());
|
||||
$this->assertIdentical($expected_bundle, $entity->getTargetBundle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a particular component of a form display.
|
||||
*
|
||||
* @param string $display_id
|
||||
* The form display ID.
|
||||
* @param string $component_id
|
||||
* The component ID.
|
||||
* @param string $widget_type
|
||||
* The expected widget type.
|
||||
* @param string $weight
|
||||
* The expected weight of the component.
|
||||
*/
|
||||
protected function assertComponent($display_id, $component_id, $widget_type, $weight) {
|
||||
$component = EntityFormDisplay::load($display_id)->getComponent($component_id);
|
||||
$this->assertTrue(is_array($component));
|
||||
$this->assertIdentical($widget_type, $component['type']);
|
||||
$this->assertIdentical($weight, $component['weight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that migrated view modes can be loaded using D8 APIs.
|
||||
*/
|
||||
public function testWidgetSettings() {
|
||||
$this->assertEntity('node.page.default', 'node', 'page');
|
||||
$this->assertComponent('node.page.default', 'body', 'text_textarea_with_summary', -4);
|
||||
|
||||
$this->assertEntity('node.article.default', 'node', 'article');
|
||||
$this->assertComponent('node.article.default', 'body', 'text_textarea_with_summary', -4);
|
||||
$this->assertComponent('node.article.default', 'field_tags', 'taxonomy_autocomplete', -4);
|
||||
$this->assertComponent('node.article.default', 'field_image', 'image_image', -1);
|
||||
|
||||
$this->assertEntity('node.blog.default', 'node', 'blog');
|
||||
$this->assertComponent('node.blog.default', 'body', 'text_textarea_with_summary', -4);
|
||||
|
||||
$this->assertEntity('node.book.default', 'node', 'book');
|
||||
$this->assertComponent('node.book.default', 'body', 'text_textarea_with_summary', -4);
|
||||
|
||||
$this->assertEntity('node.forum.default', 'node', 'forum');
|
||||
$this->assertComponent('node.forum.default', 'body', 'text_textarea_with_summary', 1);
|
||||
$this->assertComponent('node.forum.default', 'taxonomy_forums', 'options_select', 0);
|
||||
|
||||
$this->assertEntity('node.test_content_type.default', 'node', 'test_content_type');
|
||||
$this->assertComponent('node.test_content_type.default', 'field_boolean', 'boolean_checkbox', 1);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_date', 'datetime_default', 2);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_date_with_end_time', 'datetime_default', 3);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_email', 'email_default', 4);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_file', 'file_generic', 5);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_float', 'number', 7);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_images', 'image_image', 8);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_integer', 'number', 9);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_link', 'link_default', 10);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'options_buttons', 12);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_textarea_with_summary', 13);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_phone', 'telephone_default', 6);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_term_reference', 'taxonomy_autocomplete', 14);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_text', 'text_textfield', 15);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'options_select', 11);
|
||||
}
|
||||
|
||||
}
|
||||
111
core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php
Normal file
111
core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Migrates Drupal 7 fields.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class MigrateFieldTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* The modules to be enabled during the test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $modules = array(
|
||||
'comment',
|
||||
'datetime',
|
||||
'entity_reference',
|
||||
'file',
|
||||
'image',
|
||||
'link',
|
||||
'node',
|
||||
'system',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
'text',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->executeMigration('d7_field');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a field_storage_config entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID in the form ENTITY_TYPE.FIELD_NAME.
|
||||
* @param string $expected_type
|
||||
* The expected field type.
|
||||
* @param boolean $expected_translatable
|
||||
* Whether or not the field is expected to be translatable.
|
||||
* @param integer $expected_cardinality
|
||||
* The expected cardinality of the field.
|
||||
*/
|
||||
protected function assertEntity($id, $expected_type, $expected_translatable, $expected_cardinality) {
|
||||
list ($expected_entity_type, $expected_name) = explode('.', $id);
|
||||
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface $field */
|
||||
$field = FieldStorageConfig::load($id);
|
||||
$this->assertTrue($field instanceof FieldStorageConfigInterface);
|
||||
$this->assertIdentical($expected_name, $field->getName());
|
||||
$this->assertIdentical($expected_type, $field->getType());
|
||||
// FieldStorageConfig::$translatable is TRUE by default, so it is useful
|
||||
// to test for FALSE here.
|
||||
$this->assertEqual($expected_translatable, $field->isTranslatable());
|
||||
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
|
||||
|
||||
if ($expected_cardinality === 1) {
|
||||
$this->assertFalse($field->isMultiple());
|
||||
}
|
||||
else {
|
||||
$this->assertTrue($field->isMultiple());
|
||||
}
|
||||
$this->assertIdentical($expected_cardinality, $field->getCardinality());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migrating D7 fields to field_storage_config entities.
|
||||
*/
|
||||
public function testFields() {
|
||||
$this->assertEntity('node.body', 'text_with_summary', FALSE, 1);
|
||||
$this->assertEntity('node.field_long_text', 'text_with_summary', FALSE, 1);
|
||||
$this->assertEntity('comment.comment_body', 'text_long', FALSE, 1);
|
||||
$this->assertEntity('node.field_file', 'file', FALSE, 1);
|
||||
$this->assertEntity('user.field_file', 'file', FALSE, 1);
|
||||
$this->assertEntity('node.field_float', 'float', FALSE, 1);
|
||||
$this->assertEntity('node.field_image', 'image', FALSE, 1);
|
||||
$this->assertEntity('node.field_images', 'image', FALSE, 1);
|
||||
$this->assertEntity('node.field_integer', 'integer', FALSE, 1);
|
||||
$this->assertEntity('comment.field_integer', 'integer', FALSE, 1);
|
||||
$this->assertEntity('node.field_integer_list', 'list_integer', FALSE, 1);
|
||||
$this->assertEntity('node.field_link', 'link', FALSE, 1);
|
||||
$this->assertEntity('node.field_tags', 'entity_reference', FALSE, -1);
|
||||
$this->assertEntity('node.field_term_reference', 'entity_reference', FALSE, 1);
|
||||
$this->assertEntity('node.taxonomy_forums', 'entity_reference', FALSE, 1);
|
||||
$this->assertEntity('node.field_text', 'text', FALSE, 1);
|
||||
$this->assertEntity('node.field_text_list', 'list_string', FALSE, 3);
|
||||
$this->assertEntity('node.field_boolean', 'boolean', FALSE, 1);
|
||||
$this->assertEntity('node.field_email', 'email', FALSE, -1);
|
||||
$this->assertEntity('node.field_phone', 'telephone', FALSE, 1);
|
||||
$this->assertEntity('node.field_date', 'datetime', FALSE, 1);
|
||||
$this->assertEntity('node.field_date_with_end_time', 'datetime', FALSE, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Migrate\d7\MigrateViewModesTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewMode;
|
||||
use Drupal\Core\Entity\EntityViewModeInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of D7 view modes.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class MigrateViewModesTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = ['comment', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('node');
|
||||
$this->executeMigration('d7_view_modes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a view mode entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $label
|
||||
* The expected label of the view mode.
|
||||
* @param string $entity_type
|
||||
* The expected entity type ID which owns the view mode.
|
||||
* @param bool $status
|
||||
* The expected status of the view mode.
|
||||
*/
|
||||
protected function assertEntity($id, $label, $entity_type) {
|
||||
/** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
|
||||
$view_mode = EntityViewMode::load($id);
|
||||
$this->assertTrue($view_mode instanceof EntityViewModeInterface);
|
||||
$this->assertIdentical($label, $view_mode->label());
|
||||
$this->assertIdentical($entity_type, $view_mode->getTargetType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of D7 view mode variables to D8 config entities.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$this->assertEntity('comment.full', 'Full', 'comment');
|
||||
$this->assertEntity('node.teaser', 'Teaser', 'node');
|
||||
$this->assertEntity('node.full', 'Full', 'node');
|
||||
$this->assertEntity('user.full', 'Full', 'user');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -284,7 +284,11 @@ class NumberFieldTest extends WebTestBase {
|
|||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
|
||||
$this->assertRaw(round($value, 2), 'Value is displayed.');
|
||||
|
||||
// Ensure that the 'number_decimal' formatter displays the number with the
|
||||
// expected rounding.
|
||||
$this->drupalGet('entity_test/' . $id);
|
||||
$this->assertRaw(round($value, 2));
|
||||
|
||||
// Try to create entries with more than one decimal separator; assert fail.
|
||||
$wrong_entries = array(
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\field\Tests\String;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
|
|
@ -119,11 +119,11 @@ class RawStringFormatterTest extends KernelTestBase {
|
|||
// Verify that all HTML is escaped and newlines are retained.
|
||||
$this->renderEntityFields($entity, $this->display);
|
||||
$this->assertNoRaw($value);
|
||||
$this->assertRaw(nl2br(SafeMarkup::checkPlain($value)));
|
||||
$this->assertRaw(nl2br(Html::escape($value)));
|
||||
|
||||
// Verify the cache tags.
|
||||
$build = $entity->{$this->fieldName}->view();
|
||||
$this->assertTrue(!isset($build[0]['#cache']), format_string('The string formatter has no cache tags.'));
|
||||
$this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\field\Tests\String;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
|
|
@ -119,11 +119,11 @@ class StringFormatterTest extends KernelTestBase {
|
|||
// Verify that all HTML is escaped and newlines are retained.
|
||||
$this->renderEntityFields($entity, $this->display);
|
||||
$this->assertNoRaw($value);
|
||||
$this->assertRaw(nl2br(SafeMarkup::checkPlain($value)));
|
||||
$this->assertRaw(nl2br(Html::escape($value)));
|
||||
|
||||
// Verify the cache tags.
|
||||
$build = $entity->{$this->fieldName}->view();
|
||||
$this->assertTrue(!isset($build[0]['#cache']), format_string('The string formatter has no cache tags.'));
|
||||
$this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
|
||||
|
||||
$value = $this->randomMachineName();
|
||||
$entity->{$this->fieldName}->value = $value;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class UuidFormatterTest extends KernelTestBase {
|
|||
|
||||
$render_array = $uuid_field->view(['settings' => ['link_to_entity' => TRUE]]);
|
||||
$this->assertIdentical($render_array[0]['#type'], 'link');
|
||||
$this->assertIdentical($render_array[0]['#title'], $entity->uuid());
|
||||
$this->assertIdentical($render_array[0]['#title']['#markup'], $entity->uuid());
|
||||
$this->assertIdentical($render_array[0]['#url']->toString(), $entity->url());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class TestItemWithDependenciesTest extends FieldUnitTestBase {
|
|||
$this->assertEqual([
|
||||
'content' => ['node:article:uuid'],
|
||||
'config' => ['field.storage.entity_test.field_test'],
|
||||
'module' => ['field_test', 'test_module']
|
||||
'module' => ['entity_test', 'field_test', 'test_module']
|
||||
], $field->getDependencies());
|
||||
}
|
||||
|
||||
|
|
|
|||
73
core/modules/field/src/Tests/Uri/UriItemTest.php
Normal file
73
core/modules/field/src/Tests/Uri/UriItemTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\field\Tests\Uri\UriItemTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\field\Tests\Uri;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Tests\FieldUnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests URI field functionality.
|
||||
*
|
||||
* @see \Drupal\Core\Field\Plugin\Field\FieldType\UriItem
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class UriItemTest extends FieldUnitTestBase {
|
||||
|
||||
/**
|
||||
* A field to use in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* The field used in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldConfig
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* Tests URI field.
|
||||
*/
|
||||
public function testUriField() {
|
||||
$label = $this->randomMachineName();
|
||||
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'uri',
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'label' => $label,
|
||||
'required' => TRUE,
|
||||
'settings' => [
|
||||
'size' => 123,
|
||||
'placeholder' => '',
|
||||
],
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
// Create a form display for the default form mode.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'uri',
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue