upgrades core to 8.4.2

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-14 16:09:54 +01:00
parent bd60eff9b3
commit c2b4e25be4
3504 changed files with 140306 additions and 38684 deletions
+3 -3
View File
@@ -5,8 +5,8 @@ package: Core
# version: VERSION
# core: 8.x
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
# Information added by Drupal.org packaging script on 2017-11-03
version: '8.4.2'
core: '8.x'
project: 'drupal'
datestamp: 1502903957
datestamp: 1509719929
+1 -1
View File
@@ -74,7 +74,7 @@ function field_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('Terminology') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Entities and entity types') . '</dt>';
$output .= '<dd>' . t('The website\'s content and configuration is managed using <em>entities</em>, which are grouped into <em>entity types</em>. <em>Content entity types</em> are the entity types for site content (such as the main site content, comments, custom blocks, taxonomy terms, and user accounts). <em>Configuration entity types</em> are used to store configuration information for your site, such as individual views in the Views module, and settings for your main site content types.') . '</dd>';
$output .= '<dd>' . t("The website's content and configuration is managed using <em>entities</em>, which are grouped into <em>entity types</em>. <em>Content entity types</em> are the entity types for site content (such as the main site content, comments, custom blocks, taxonomy terms, and user accounts). <em>Configuration entity types</em> are used to store configuration information for your site, such as individual views in the Views module, and settings for your main site content types.") . '</dd>';
$output .= '<dt>' . t('Entity sub-types') . '</dt>';
$output .= '<dd>' . t('Some content entity types are further grouped into sub-types (for example, you could have article and page content types within the main site content entity type, and tag and category vocabularies within the taxonomy term entity type); other entity types, such as user accounts, do not have sub-types. Programmers use the term <em>bundle</em> for entity sub-types.') . '</dd>';
$output .= '<dt>' . t('Fields and field types') . '</dt>';
+24 -1
View File
@@ -6,10 +6,10 @@
*/
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
/**
* Re-save all field storage config objects to add 'custom_storage' property.
*/
@@ -59,3 +59,26 @@ function field_post_update_email_widget_size_setting() {
return t('The new size setting for email widgets has been added.');
}
/**
* Remove the stale 'handler_submit' setting for entity_reference fields.
*/
function field_post_update_remove_handler_submit_setting() {
$config = \Drupal::configFactory();
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
// Iterate on all field configs.
foreach ($config->listAll('field.field.') as $field_id) {
$field = $config->getEditable($field_id);
$class = $field_type_manager->getPluginClass($field->get('field_type'));
// Deal only with entity reference fields and descendants.
if ($class === EntityReferenceItem::class || is_subclass_of($class, EntityReferenceItem::class)) {
if ($field->get('settings.handler_submit')) {
// Remove 'handler_settings' from settings.
$field->clear('settings.handler_submit')->save();
}
}
}
}
@@ -2,8 +2,8 @@ id: d6_field
label: Field configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processField
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processField
source:
plugin: d6_field
constants:
@@ -2,8 +2,8 @@ id: d6_field_formatter_settings
label: Field formatter configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldFormatter
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldFormatter
source:
plugin: d6_field_instance_per_view_mode
constants:
@@ -2,8 +2,8 @@ id: d6_field_instance
label: Field instance configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldInstance
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldInstance
source:
plugin: d6_field_instance
constants:
@@ -2,8 +2,8 @@ id: d6_field_instance_widget_settings
label: Field instance widget configuration
migration_tags:
- Drupal 6
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldWidget
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldWidget
source:
plugin: d6_field_instance_per_form_display
constants:
@@ -2,8 +2,8 @@ id: d7_field
label: Field configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processField
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processField
source:
plugin: d7_field
constants:
@@ -15,26 +15,9 @@ process:
langcode: 'constants/langcode'
field_name: field_name
type:
plugin: field_type
plugin: process_field
source: type
map:
date: datetime
datestamp: datetime
datetime: datetime
email: email
entityreference: entity_reference
file: file
image: image
link_field: link
list_boolean: boolean
list_integer: list_integer
list_text: list_string
number_integer: integer
number_decimal: decimal
number_float: float
phone: telephone
text_long: text_long
text_with_summary: text_with_summary
method: getFieldType
# Translatable is not migrated and the Drupal 8 default of true is used.
# If translatable is false in field storage then the field can not be
# set to translatable via the UI.
@@ -2,8 +2,8 @@ id: d7_field_formatter_settings
label: Field formatter configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldFormatter
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldFormatter
source:
plugin: d7_field_instance_per_view_mode
constants:
@@ -26,7 +26,15 @@ process:
plugin: skip_on_empty
method: row
entity_type: entity_type
bundle: bundle
# The bundle needs to be statically mapped in order to support comment types
# that might already exist before this migration is run. See
# d7_comment_type.yml or more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
view_mode:
-
plugin: migration_lookup
@@ -44,14 +52,18 @@ process:
map:
full: default
field_name: field_name
"options/label": label
"options/weight": weight
"options/label": 'formatter/label'
"options/weight": 'formatter/weight'
# The formatter to use.
formatter_type:
plugin: process_field
source: type
method: getFieldFormatterType
"options/type":
-
plugin: static_map
bypass: true
source: formatter_type
source: '@formatter_type'
map:
date_default: datetime_default
email_default: email_mailto
@@ -69,7 +81,7 @@ process:
method: row
"options/settings":
plugin: default_value
source: settings
source: 'formatter/settings'
default_value: []
"options/third_party_settings": 'constants/third_party_settings'
destination:
@@ -2,16 +2,28 @@ id: d7_field_instance
label: Field instance configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldInstance
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldInstance
source:
plugin: d7_field_instance
constants:
status: true
process:
type:
plugin: process_field
source: type
method: getFieldType
entity_type: entity_type
field_name: field_name
bundle: bundle
# The bundle needs to be statically mapped in order to support comment types
# that might already exist before this migration is run. See
# d7_comment_type.yml for more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
label: label
description: description
required: required
@@ -19,15 +31,15 @@ process:
settings:
plugin: d7_field_instance_settings
source:
- instance_settings
- widget_settings
- field_settings
- settings
- widget
- field_definition
default_value_function: ''
default_value:
plugin: d7_field_instance_defaults
source:
- default_value
- widget_settings
- widget
translatable: translatable
destination:
plugin: entity:field_config
@@ -2,8 +2,8 @@ id: d7_field_instance_widget_settings
label: Field instance widget configuration
migration_tags:
- Drupal 7
class: Drupal\migrate_drupal\Plugin\migrate\CckMigration
cck_plugin_method: processFieldWidget
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
field_plugin_method: processFieldWidget
source:
plugin: d7_field_instance_per_form_display
constants:
@@ -26,16 +26,28 @@ process:
-
plugin: skip_on_empty
method: row
bundle: bundle
# The bundle needs to be statically mapped in order to support comment types
# that might already exist before this migration is run. See
# d7_comment_type.yml for more information.
bundle:
plugin: static_map
source: bundle
bypass: true
map:
comment_node_forum: comment_forum
form_mode: 'constants/form_mode'
field_name: field_name
entity_type: entity_type
'options/weight': 'widget/weight'
widget_type:
plugin: process_field
source: type
method: getFieldWidgetType
'options/type':
type:
plugin: static_map
bypass: true
source: 'widget/type'
source: '@widget_type'
map:
link_field: link_default
email_textfield: email_default
@@ -52,7 +64,7 @@ process:
plugin: field_instance_widget_settings
source:
- 'widget/type'
- widget_settings
- 'widget/settings'
'options/third_party_settings': 'constants/third_party_settings'
destination:
plugin: component_entity_form_display
@@ -3,6 +3,7 @@
namespace Drupal\field\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\FieldableEntityStorageInterface;
use Drupal\Core\Field\FieldConfigBase;
use Drupal\Core\Field\FieldException;
use Drupal\field\FieldStorageConfigInterface;
@@ -189,13 +190,19 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
*/
public static function preDelete(EntityStorageInterface $storage, array $fields) {
$state = \Drupal::state();
$entity_type_manager = \Drupal::entityTypeManager();
parent::preDelete($storage, $fields);
// Keep the field definitions in the state storage so we can use them
// later during field_purge_batch().
$deleted_fields = $state->get('field.field.deleted') ?: [];
/** @var \Drupal\field\FieldConfigInterface $field */
foreach ($fields as $field) {
if (!$field->deleted) {
// Only mark a field for purging if there is data. Otherwise, just remove
// it.
$target_entity_storage = $entity_type_manager->getStorage($field->getTargetEntityTypeId());
if (!$field->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field->getFieldStorageDefinition(), TRUE)) {
$config = $field->toArray();
$config['deleted'] = TRUE;
$config['field_storage_uuid'] = $field->getFieldStorageDefinition()->uuid();
@@ -6,6 +6,7 @@ use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\FieldableEntityStorageInterface;
use Drupal\Core\Field\FieldException;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\OptionsProviderInterface;
@@ -409,8 +410,12 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
// Keep the field definitions in the state storage so we can use them later
// during field_purge_batch().
$deleted_storages = $state->get('field.storage.deleted') ?: [];
/** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
foreach ($field_storages as $field_storage) {
if (!$field_storage->deleted) {
// Only mark a field for purging if there is data. Otherwise, just remove
// it.
$target_entity_storage = \Drupal::entityTypeManager()->getStorage($field_storage->getTargetEntityTypeId());
if (!$field_storage->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field_storage, TRUE)) {
$config = $field_storage->toArray();
$config['deleted'] = TRUE;
$config['bundles'] = $field_storage->getBundles();
@@ -628,7 +633,17 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
* {@inheritdoc}
*/
public function getCardinality() {
return $this->cardinality;
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$definition = $field_type_manager->getDefinition($this->getType());
$enforced_cardinality = isset($definition['cardinality']) ? $definition['cardinality'] : NULL;
// Enforced cardinality is a positive integer or -1.
if ($enforced_cardinality !== NULL && $enforced_cardinality < 1 && $enforced_cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
throw new FieldException("Invalid enforced cardinality '$enforced_cardinality'. Allowed values: a positive integer or -1.");
}
return $enforced_cardinality ?: $this->cardinality;
}
/**
@@ -0,0 +1,155 @@
<?php
namespace Drupal\field\Plugin\migrate\process;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Get the value from a method call on a field plugin instance.
*
* This process plugin will instantiate a field plugin based on the given
* field type and then call the given method on it for the return value.
*
* Available configuration keys:
* - source: The source field type to use to instantiate a field plugin.
* - method: The method to be called on the field plugin instance.
*
* If no field plugin for the given field type is found, NULL will be returned.
*
* Example:
*
* @code
* process:
* type:
* plugin: process_field
* source: type
* method: getFieldType
* @endcode
*
* @see \Drupal\migrate\Plugin\MigrateProcessInterface
* @see \Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
*
* @MigrateProcessPlugin(
* id = "process_field"
* )
*/
class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The cckfield plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
*/
protected $cckPluginManager;
/**
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $fieldPluginManager;
/**
* The migration being run.
*
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration;
/**
* Constructs a ProcessField plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_plugin_manager
* The cckfield plugin manager.
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The field plugin manager.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration being run.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_plugin_manager, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->cckPluginManager = $cck_plugin_manager;
$this->fieldPluginManager = $field_plugin_manager;
$this->migration = $migration;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.migrate.cckfield'),
$container->get('plugin.manager.migrate.field'),
$migration
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_string($value)) {
throw new MigrateException('The input value must be a string.');
}
if (empty($this->configuration['method'])) {
throw new MigrateException('You need to specify the name of a method to be called on the Field plugin.');
}
$method = $this->configuration['method'];
try {
return $this->callMethodOnFieldPlugin($this->fieldPluginManager, $value, $method, $row);
}
catch (PluginNotFoundException $e) {
try {
return $this->callMethodOnFieldPlugin($this->cckPluginManager, $value, $method, $row);
}
catch (PluginNotFoundException $e) {
return NULL;
}
}
}
/**
* Instantiate a field plugin and call a method on it.
*
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
* The field plugin manager.
* @param string $field_type
* The field type for which to get the field plugin.
* @param string $method
* The method to call on the field plugin.
* @param \Drupal\migrate\Row $row
* The row from the source to process.
*
* @return mixed
* The return value from the method called on the field plugin.
*/
protected function callMethodOnFieldPlugin(MigrateFieldPluginManagerInterface $field_plugin_manager, $field_type, $method, Row $row) {
$plugin_id = $field_plugin_manager->getPluginIdFromFieldType($field_type, [], $this->migration);
$plugin_instance = $field_plugin_manager->createInstance($plugin_id, [], $this->migration);
if (!is_callable([$plugin_instance, $method])) {
throw new MigrateException('The specified method does not exists or is not callable.');
}
return call_user_func_array([$plugin_instance, $method], [$row]);
}
}
@@ -19,6 +19,14 @@ class FieldInstanceDefaults extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($default_value, $widget_settings) = $value;
$widget_type = $widget_settings['type'];
$default_value = $default_value ?: [];
// In Drupal 7, the default value for email fields is stored in the key
// 'email' while in Drupal 8 it is stored in the key 'value'.
if ($widget_type == 'email_textfield' && $default_value) {
$default_value[0]['value'] = $default_value[0]['email'];
unset($default_value[0]['email']);
}
$default = [];
@@ -17,9 +17,12 @@ class FieldInstanceSettings extends ProcessPluginBase {
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($instance_settings, $widget_settings, $field_settings) = $value;
list($instance_settings, $widget_settings, $field_definition) = $value;
$widget_type = $widget_settings['type'];
$field_data = unserialize($field_definition['data']);
$field_settings = $field_data['settings'];
// Get entityreference handler settings from source field configuration.
if ($row->getSourceProperty('type') == "entityreference") {
$instance_settings['handler'] = 'default:' . $field_settings['target_type'];
@@ -10,7 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d6_field",
* source_provider = "content"
* source_module = "content"
* )
*/
class Field extends DrupalSqlBase {
@@ -10,7 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d6_field_instance",
* source_provider = "content"
* source_module = "content"
* )
*/
class FieldInstance extends DrupalSqlBase {
@@ -9,7 +9,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
*
* @MigrateSource(
* id = "d6_field_instance_per_form_display",
* source_provider = "content"
* source_module = "content"
* )
*/
class FieldInstancePerFormDisplay extends DrupalSqlBase {
@@ -9,7 +9,7 @@ use Drupal\node\Plugin\migrate\source\d6\ViewModeBase;
*
* @MigrateSource(
* id = "d6_field_instance_per_view_mode",
* source_provider = "content"
* source_module = "content"
* )
*/
class FieldInstancePerViewMode extends ViewModeBase {
@@ -8,8 +8,14 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 field source from database.
*
* @internal
*
* This class is marked as internal and should not be extended. Use
* Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase instead.
*
* @MigrateSource(
* id = "d7_field"
* id = "d7_field",
* source_module = "field"
* )
*/
class Field extends DrupalSqlBase {
@@ -23,8 +29,9 @@ class Field extends DrupalSqlBase {
->fields('fc')
->fields('fci', ['entity_type'])
->condition('fc.active', 1)
->condition('fc.storage_active', 1)
->condition('fc.deleted', 0)
->condition('fc.storage_active', 1);
->condition('fci.deleted', 0);
$query->join('field_config_instance', 'fci', 'fc.id = fci.field_id');
return $query;
@@ -35,13 +42,20 @@ class Field extends DrupalSqlBase {
*/
public function fields() {
return [
'field_name' => $this->t('The name of this field.'),
'type' => $this->t('The type of this field.'),
'id' => $this->t('The field ID.'),
'field_name' => $this->t('The field name.'),
'type' => $this->t('The field type.'),
'module' => $this->t('The module that implements the field type.'),
'storage' => $this->t('The field storage.'),
'active' => $this->t('The field status.'),
'storage_type' => $this->t('The field storage type.'),
'storage_module' => $this->t('The module that implements the field storage type.'),
'storage_active' => $this->t('The field storage status.'),
'locked' => $this->t('Locked'),
'data' => $this->t('The field data.'),
'cardinality' => $this->t('Cardinality'),
'translatable' => $this->t('Translatable'),
'deleted' => $this->t('Deleted'),
'instances' => $this->t('The field instances.'),
];
}
@@ -52,6 +66,15 @@ class Field extends DrupalSqlBase {
foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
$row->setSourceProperty($key, $value);
}
$instances = $this->select('field_config_instance', 'fci')
->fields('fci')
->condition('field_name', $row->getSourceProperty('field_name'))
->condition('entity_type', $row->getSourceProperty('entity_type'))
->execute()
->fetchAll();
$row->setSourceProperty('instances', $instances);
return parent::prepareRow($row);
}
@@ -8,9 +8,14 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 field instances source from database.
*
* @internal
*
* This class is marked as internal and should not be extended. Use
* Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase instead.
*
* @MigrateSource(
* id = "d7_field_instance",
* source_provider = "field"
* source_module = "field"
* )
*/
class FieldInstance extends DrupalSqlBase {
@@ -21,14 +26,12 @@ class FieldInstance extends DrupalSqlBase {
public function query() {
$query = $this->select('field_config_instance', 'fci')
->fields('fci')
->condition('fci.deleted', 0)
->fields('fc', ['type'])
->condition('fc.active', 1)
->condition('fc.deleted', 0)
->condition('fc.storage_active', 1)
->fields('fc', ['type']);
$query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
$query->addField('fc', 'data', 'field_data');
->condition('fc.deleted', 0)
->condition('fci.deleted', 0);
$query->join('field_config', 'fc', 'fci.field_id = fc.id');
// Optionally filter by entity type and bundle.
if (isset($this->configuration['entity_type'])) {
@@ -42,19 +45,43 @@ class FieldInstance extends DrupalSqlBase {
return $query;
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$results = $this->prepareQuery()->execute()->fetchAll();
// Group all instances by their base field.
$instances = [];
foreach ($results as $result) {
$instances[$result['field_id']][] = $result;
}
// Add the array of all instances using the same base field to each row.
$rows = [];
foreach ($results as $result) {
$result['instances'] = $instances[$result['field_id']];
$rows[] = $result;
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'field_name' => $this->t('The machine name of field.'),
'id' => $this->t('The field instance ID.'),
'field_id' => $this->t('The field ID.'),
'field_name' => $this->t('The field name.'),
'entity_type' => $this->t('The entity type.'),
'bundle' => $this->t('The entity bundle.'),
'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.'),
'field_settings' => $this->t('Field settings.'),
'data' => $this->t('The field instance data.'),
'deleted' => $this->t('Deleted'),
'type' => $this->t('The field type'),
'instances' => $this->t('The field instances.'),
'field_definition' => $this->t('The field definition.'),
];
}
@@ -62,29 +89,16 @@ class FieldInstance extends DrupalSqlBase {
* {@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'] : [];
if ($data['widget']['type'] == 'email_textfield' && $default_value) {
$default_value[0]['value'] = $default_value[0]['email'];
unset($default_value[0]['email']);
foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
$row->setSourceProperty($key, $value);
}
$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']);
// This is for parity with the d6_field_instance plugin.
$row->setSourceProperty('widget_type', $data['widget']['type']);
$field_data = unserialize($row->getSourceProperty('field_data'));
$row->setSourceProperty('field_settings', $field_data['settings']);
$field_definition = $this->select('field_config', 'fc')
->fields('fc')
->condition('id', $row->getSourceProperty('field_id'))
->execute()
->fetch();
$row->setSourceProperty('field_definition', $field_definition);
$translatable = FALSE;
if ($row->getSourceProperty('entity_type') == 'node') {
@@ -100,8 +114,8 @@ class FieldInstance extends DrupalSqlBase {
else {
// This is not a node entity. Get the translatable value from the source
// field_config table.
$data = unserialize($row->getSourceProperty('field_data'));
$translatable = $data['translatable'];
$field_data = unserialize($field_definition['data']);
$translatable = $field_data['translatable'];
}
$row->setSourceProperty('translatable', $translatable);
@@ -128,4 +142,11 @@ class FieldInstance extends DrupalSqlBase {
];
}
/**
* {@inheritdoc}
*/
public function count() {
return $this->initializeIterator()->count();
}
}
@@ -2,58 +2,15 @@
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"
* id = "d7_field_instance_per_form_display",
* source_module = "field"
* )
*/
class FieldInstancePerFormDisplay extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('field_config_instance', 'fci')
->fields('fci', [
'field_name',
'bundle',
'data',
'entity_type'
])
->fields('fc', [
'type',
'module',
]);
$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 [
'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.'),
];
}
class FieldInstancePerFormDisplay extends FieldInstance {
/**
* {@inheritdoc}
@@ -2,69 +2,43 @@
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"
* source_module = "field"
* )
*/
class FieldInstancePerViewMode extends DrupalSqlBase {
class FieldInstancePerViewMode extends FieldInstance {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$instances = parent::initializeIterator();
$rows = [];
$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) {
// Rename type to formatter_type in the info array.
$info['formatter_type'] = $info['type'];
unset($info['type']);
$rows[] = array_merge($field_instance, $info, [
foreach ($instances->getArrayCopy() as $instance) {
$data = unserialize($instance['data']);
foreach ($data['display'] as $view_mode => $formatter) {
$rows[] = array_merge($instance, [
'view_mode' => $view_mode,
'formatter' => $formatter,
]);
}
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('field_config_instance', 'fci')
->fields('fci', ['entity_type', 'bundle', 'field_name', 'data'])
->fields('fc', ['type']);
$query->join('field_config', 'fc', 'fc.field_name = fci.field_name');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'entity_type' => $this->t('The entity type ID.'),
'bundle' => $this->t('The bundle ID.'),
'field_name' => $this->t('Machine name of the field.'),
return array_merge(parent::fields(), [
'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 field ID.'),
'formatter_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.'),
];
'formatter' => $this->t('The formatter settings.'),
]);
}
/**
@@ -87,11 +61,4 @@ class FieldInstancePerViewMode extends DrupalSqlBase {
];
}
/**
* {@inheritdoc}
*/
public function count() {
return $this->initializeIterator()->count();
}
}
@@ -2,31 +2,33 @@
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* The view mode source class.
*
* @MigrateSource(
* id = "d7_view_mode"
* id = "d7_view_mode",
* source_module = "field"
* )
*/
class ViewMode extends DrupalSqlBase {
class ViewMode extends FieldInstance {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$instances = parent::initializeIterator();
$rows = [];
$result = $this->prepareQuery()->execute();
foreach ($result as $field_instance) {
$data = unserialize($field_instance['data']);
foreach ($instances->getArrayCopy() as $instance) {
$data = unserialize($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'],
$key = $instance['entity_type'] . '.' . $view_mode;
$rows[$key] = array_merge($instance, [
'view_mode' => $view_mode,
];
]);
}
}
return new \ArrayIterator($rows);
}
@@ -34,18 +36,9 @@ class ViewMode extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return [
return array_merge(parent::fields(), [
'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']);
]);
}
/**
@@ -62,11 +55,4 @@ class ViewMode extends DrupalSqlBase {
];
}
/**
* {@inheritdoc}
*/
public function count() {
return $this->initializeIterator()->count();
}
}
-56
View File
@@ -389,62 +389,6 @@ class FormTest extends FieldTestBase {
$this->assertNoField("{$field_name}[2][value]", 'No extraneous widget is displayed');
}
public function testFieldFormJSAddMore() {
$field_storage = $this->fieldStorageUnlimited;
$field_name = $field_storage['field_name'];
$this->field['field_name'] = $field_name;
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name)
->save();
// Display creation form -> 1 widget.
$this->drupalGet('entity_test/add');
// Press 'add more' button a couple times -> 3 widgets.
// drupalPostAjaxForm() will not work iteratively, so we add those through
// non-JS submission.
$this->drupalPostForm(NULL, [], t('Add another item'));
$this->drupalPostForm(NULL, [], t('Add another item'));
// Prepare values and weights.
$count = 3;
$delta_range = $count - 1;
$values = $weights = $pattern = $expected_values = $edit = [];
for ($delta = 0; $delta <= $delta_range; $delta++) {
// Assign unique random values and weights.
do {
$value = mt_rand(1, 127);
} while (in_array($value, $values));
do {
$weight = mt_rand(-$delta_range, $delta_range);
} while (in_array($weight, $weights));
$edit["{$field_name}[$delta][value]"] = $value;
$edit["{$field_name}[$delta][_weight]"] = $weight;
// We'll need three slightly different formats to check the values.
$values[$delta] = $value;
$weights[$delta] = $weight;
$field_values[$weight]['value'] = (string) $value;
$pattern[$weight] = "<input [^>]*value=\"$value\" [^>]*";
}
// Press 'add more' button through Ajax, and place the expected HTML result
// as the tested content.
$commands = $this->drupalPostAjaxForm(NULL, $edit, $field_name . '_add_more');
$this->setRawContent($commands[2]['data']);
for ($delta = 0; $delta <= $delta_range; $delta++) {
$this->assertFieldByName("{$field_name}[$delta][value]", $values[$delta], "Widget $delta is displayed and has the right value");
$this->assertFieldByName("{$field_name}[$delta][_weight]", $weights[$delta], "Widget $delta has the right weight");
}
ksort($pattern);
$pattern = implode('.*', array_values($pattern));
$this->assertPattern("|$pattern|s", 'Widgets are displayed in the correct order');
$this->assertFieldByName("{$field_name}[$delta][value]", '', "New widget is displayed");
$this->assertFieldByName("{$field_name}[$delta][_weight]", $delta, "New widget has the right weight");
$this->assertNoField("{$field_name}[" . ($delta + 1) . '][value]', 'No extraneous widget is displayed');
}
/**
* Tests widgets handling multiple values.
*/
@@ -1,6 +1,7 @@
<?php
namespace Drupal\field\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
@@ -45,9 +45,7 @@ class NumberFieldTest extends WebTestBase {
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'decimal',
'settings' => [
'precision' => 8, 'scale' => 4,
]
'settings' => ['precision' => 8, 'scale' => 4],
])->save();
FieldConfig::create([
'field_name' => $field_name,
@@ -143,8 +141,10 @@ class NumberFieldTest extends WebTestBase {
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'settings' => [
'min' => $minimum, 'max' => $maximum, 'prefix' => 'ThePrefix',
]
'min' => $minimum,
'max' => $maximum,
'prefix' => 'ThePrefix',
],
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
@@ -57,7 +57,7 @@ class FieldUITest extends FieldTestBase {
// Tests the available formatter options.
$result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-options-type']);
$options = array_map(function($item) {
$options = array_map(function ($item) {
return (string) $item->attributes()->value[0];
}, $result);
// @todo Replace this sort by assertArray once it's in.
@@ -111,7 +111,7 @@ class FieldUITest extends FieldTestBase {
// Test the click sort column options.
// Tests the available formatter options.
$result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-options-click-sort-column']);
$options = array_map(function($item) {
$options = array_map(function ($item) {
return (string) $item->attributes()->value[0];
}, $result);
sort($options, SORT_STRING);
@@ -0,0 +1,26 @@
<?php
/**
* @file
* Provides necessary database additions for testing
* field_post_update_remove_handler_submit_setting()
*/
use Drupal\Core\Database\Database;
$connection = Database::getConnection();
$config = unserialize($connection->select('config', 'c')
->fields('c', ['data'])
->condition('collection', '')
->condition('name', 'field.field.node.article.field_tags')
->execute()
->fetchField());
$config['settings']['handler_submit'] = 'Change handler';
$connection->update('config')
->fields(['data' => serialize($config)])
->condition('collection', '')
->condition('name', 'field.field.node.article.field_tags')
->execute();
@@ -7,8 +7,8 @@ package: Testing
dependencies:
- text
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
# Information added by Drupal.org packaging script on 2017-11-03
version: '8.4.2'
core: '8.x'
project: 'drupal'
datestamp: 1502903957
datestamp: 1509719929
@@ -7,8 +7,8 @@ package: Testing
dependencies:
- entity_test
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
# Information added by Drupal.org packaging script on 2017-11-03
version: '8.4.2'
core: '8.x'
project: 'drupal'
datestamp: 1502903957
datestamp: 1509719929
@@ -1,11 +1,11 @@
<?php
namespace Drupal\field_test\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
/**
* Plugin implementation of the 'field_test_applicable' formatter.
*
@@ -4,7 +4,6 @@ namespace Drupal\field_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Defines the 'test_field_with_dependencies' entity field item.
*
@@ -7,8 +7,8 @@ package: Testing
dependencies:
- field
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
# Information added by Drupal.org packaging script on 2017-11-03
version: '8.4.2'
core: '8.x'
project: 'drupal'
datestamp: 1502903957
datestamp: 1509719929
@@ -5,8 +5,8 @@ description: 'Support module for the Field API configuration tests.'
package: Testing
# version: VERSION
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
# Information added by Drupal.org packaging script on 2017-11-03
version: '8.4.2'
core: '8.x'
project: 'drupal'
datestamp: 1502903957
datestamp: 1509719929
@@ -7,8 +7,8 @@ package: Testing
dependencies:
- views
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
# Information added by Drupal.org packaging script on 2017-11-03
version: '8.4.2'
core: '8.x'
project: 'drupal'
datestamp: 1502903957
datestamp: 1509719929
@@ -8,8 +8,8 @@ dependencies:
- entity_test
- field_test
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
# Information added by Drupal.org packaging script on 2017-11-03
version: '8.4.2'
core: '8.x'
project: 'drupal'
datestamp: 1502903957
datestamp: 1509719929
@@ -213,17 +213,17 @@ class EntityReferenceAutoCreateTest extends BrowserTestBase {
// a way to catch and assert user-triggered errors.
// Test the case when the field config settings are inconsistent.
//unset($handler_settings['auto_create_bundle']);
//$field_config->setSetting('handler_settings', $handler_settings);
//$field_config->save();
// unset($handler_settings['auto_create_bundle']);
// $field_config->setSetting('handler_settings', $handler_settings);
// $field_config->save();
//
//$this->drupalGet('node/add/' . $this->referencingType);
//$error_message = sprintf(
// $this->drupalGet('node/add/' . $this->referencingType);
// $error_message = sprintf(
// "Create referenced entities if they don't already exist option is enabled but a specific destination bundle is not set. You should re-visit and fix the settings of the '%s' (%s) field.",
// $field_config->getLabel(),
// $field_config->getName()
//);
//$this->assertErrorLogged($error_message);
// );
// $this->assertErrorLogged($error_message);
}
}
@@ -3,11 +3,11 @@
namespace Drupal\Tests\field\Functional\EntityReference;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\config\Tests\AssertConfigEntityImportTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\config\Traits\AssertConfigEntityImportTrait;
/**
* Tests various Entity reference UI components.
@@ -62,7 +62,7 @@ class EntityReferenceXSSTest extends BrowserTestBase {
'title[0][value]' => $this->randomString(),
'entity_reference_test' => $referenced_node->id()
];
$this->drupalPostForm(NULL, $edit, 'Save and publish');
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertEscaped($referenced_node->getTitle());
// Test the options_buttons type.
@@ -0,0 +1,48 @@
<?php
namespace Drupal\Tests\field\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the update for the 'size' setting of the 'email_default' field widget.
*
* @group field
*/
class EmailWidgetSizeSettingUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.email_widget_size_setting-2578741.php',
];
}
/**
* Tests field_post_update_email_widget_size_setting().
*
* @see field_post_update_email_widget_size_setting()
*/
public function testFieldPostUpdateEmailWidgetSizeSetting() {
$configFactory = $this->container->get('config.factory');
// Load the 'node.article.default' entity form display and check that the
// widget for 'field_email_2578741' does not have a 'size' setting.
/** @var \Drupal\Core\Config\Config $config */
$config = $configFactory->get('core.entity_form_display.node.article.default');
$settings = $config->get('content.field_email_2578741.settings');
$this->assertTrue(!isset($settings['size']), 'The size setting does not exist prior to running the update functions.');
// Run updates.
$this->runUpdates();
// Reload the config and check that the 'size' setting has been populated.
$config = $configFactory->get('core.entity_form_display.node.article.default');
$settings = $config->get('content.field_email_2578741.settings');
$this->assertEqual($settings['size'], 60, 'The size setting exists and it has the correct default value.');
}
}
@@ -0,0 +1,47 @@
<?php
namespace Drupal\Tests\field\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the update for the entity reference 'handler' setting.
*
* @group field
*/
class EntityReferenceHandlerSettingUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
];
}
/**
* Tests field_post_update_entity_reference_handler_setting().
*
* @see field_post_update_entity_reference_handler_setting()
*/
public function testFieldPostUpdateERHandlerSetting() {
$configFactory = $this->container->get('config.factory');
// Load the 'node.article.field_image' field config, and check that its
// 'handler' setting is wrong.
/** @var \Drupal\Core\Config\Config */
$config = $configFactory->get('field.field.node.article.field_image');
$settings = $config->get('settings');
$this->assertEqual($settings['handler'], 'default:node');
// Run updates.
$this->runUpdates();
// Reload the config, and check that the 'handler' setting has been fixed.
$config = $configFactory->get('field.field.node.article.field_image');
$settings = $config->get('settings');
$this->assertEqual($settings['handler'], 'default:file');
}
}
@@ -0,0 +1,162 @@
<?php
namespace Drupal\Tests\field\Functional\Update;
use Drupal\Core\Config\Config;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\node\Entity\Node;
/**
* Tests that field settings are properly updated during database updates.
*
* @group field
*/
class FieldUpdateTest extends UpdatePathTestBase {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->configFactory = $this->container->get('config.factory');
}
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.views_entity_reference_plugins-2429191.php',
__DIR__ . '/../../../fixtures/update/drupal-8.remove_handler_submit_setting-2715589.php',
];
}
/**
* Tests field_update_8001().
*
* @see field_update_8001()
*/
public function testFieldUpdate8001() {
// Load the 'node.field_image' field storage config, and check that is has
// a 'target_bundle' setting.
$config = $this->configFactory->get('field.storage.node.field_image');
$settings = $config->get('settings');
$this->assertTrue(array_key_exists('target_bundle', $settings));
// Run updates.
$this->runUpdates();
// Reload the config, and check that the 'target_bundle' setting has been
// removed.
$config = $this->configFactory->get('field.storage.node.field_image');
$settings = $config->get('settings');
$this->assertFalse(array_key_exists('target_bundle', $settings));
}
/**
* Tests field_update_8002().
*
* @see field_update_8002()
*/
public function testFieldUpdate8002() {
// Check that 'entity_reference' is the provider and a dependency of the
// test field storage .
$field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191');
$this->assertIdentical($field_storage->get('module'), 'entity_reference');
$this->assertEntityRefDependency($field_storage, TRUE);
// Check that 'entity_reference' is a dependency of the test field.
$field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191');
$this->assertEntityRefDependency($field, TRUE);
// Check that 'entity_reference' is a dependency of the test view.
$view = $this->configFactory->get('views.view.entity_reference_plugins_2429191');
$this->assertEntityRefDependency($view, TRUE);
// Run updates.
$this->runUpdates();
// Check that 'entity_reference' is no longer a dependency of the test field
// and view.
$field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191');
$this->assertIdentical($field_storage->get('module'), 'core');
$this->assertEntityRefDependency($field_storage, FALSE);
$field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191');
$this->assertEntityRefDependency($field, FALSE);
$view = $this->configFactory->get('views.view.entity_reference_plugins_2429191');
$this->assertEntityRefDependency($view, FALSE);
// Check that field selection, based on the view, still works. It only
// selects nodes whose title contains 'foo'.
$node_1 = Node::create(['type' => 'article', 'title' => 'foobar']);
$node_1->save();
$node_2 = Node::create(['type' => 'article', 'title' => 'barbaz']);
$node_2->save();
$field = FieldConfig::load('node.article.field_ref_views_select_2429191');
$selection = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
$referencable = $selection->getReferenceableEntities();
$this->assertEqual(array_keys($referencable['article']), [$node_1->id()]);
}
/**
* Tests field_update_8003().
*
* @see field_update_8003()
*/
public function testFieldUpdate8003() {
// Run updates.
$this->runUpdates();
// Check that the new 'auto_create_bundle' setting is populated correctly.
$field = $this->configFactory->get('field.field.node.article.field_ref_autocreate_2412569');
$handler_settings = $field->get('settings.handler_settings');
$expected_target_bundles = ['tags' => 'tags', 'test' => 'test'];
$this->assertEqual($handler_settings['target_bundles'], $expected_target_bundles);
$this->assertTrue($handler_settings['auto_create']);
$this->assertEqual($handler_settings['auto_create_bundle'], 'tags');
}
/**
* Asserts that a config depends on 'entity_reference' or not
*
* @param \Drupal\Core\Config\Config $config
* The config to test.
* @param bool $present
* TRUE to test that entity_reference is present, FALSE to test that it is
* absent.
*/
protected function assertEntityRefDependency(Config $config, $present) {
$dependencies = $config->get('dependencies');
$dependencies += ['module' => []];
$this->assertEqual(in_array('entity_reference', $dependencies['module']), $present);
}
/**
* Tests field_post_update_remove_handler_submit_setting().
*
* @see field_post_update_remove_handler_submit_setting()
*/
public function testEntityReferenceFieldConfigCleanUpdate() {
$field_config = $this->config('field.field.node.article.field_tags');
// Check that 'handler_submit' key exists in field config settings.
$this->assertEquals('Change handler', $field_config->get('settings.handler_submit'));
$this->runUpdates();
$field_config = $this->config('field.field.node.article.field_tags');
// Check that 'handler_submit' has been removed from field config settings.
$this->assertArrayNotHasKey('handler_submit', $field_config->get('settings'));
}
}
@@ -0,0 +1,123 @@
<?php
namespace Drupal\Tests\field\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests add more behavior for a multiple value field.
*
* @group field
*/
class FormJSAddMoreTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['field_test', 'entity_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$account = $this->drupalCreateUser([
'view test entity',
'administer entity_test content',
]);
$this->drupalLogin($account);
$field = [
'field_name' => 'field_unlimited',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
'description' => '[site:name]_description',
'weight' => mt_rand(0, 127),
'settings' => [
'test_field_setting' => $this->randomMachineName(),
],
];
FieldStorageConfig::create([
'field_name' => 'field_unlimited',
'entity_type' => 'entity_test',
'type' => 'test_field',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
])->save();
FieldConfig::create($field)->save();
$entity_form_display = EntityFormDisplay::load($field['entity_type'] . '.' . $field['bundle'] . '.default');
$entity_form_display->setComponent($field['field_name'])->save();
}
/**
* Tests the 'Add more' functionality.
*/
public function testFieldFormJsAddMore() {
$this->drupalGet('entity_test/add');
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$add_more_button = $page->findButton('field_unlimited_add_more');
// First set a value on the first input field.
$field_0 = $page->findField('field_unlimited[0][value]');
$field_0->setValue('1');
// Add another item.
$add_more_button->click();
$field_1 = $assert_session->waitForField('field_unlimited[1][value]');
$this->assertNotEmpty($field_1, 'Successfully added another item.');
// Validate the value of the first field has not changed.
$this->assertEquals('1', $field_0->getValue(), 'Value for the first item has not changed.');
// Validate the value of the second item is empty.
$this->assertEmpty($field_1->getValue(), 'Value for the second item is currently empty.');
// Add another item.
$add_more_button->click();
$field_2 = $assert_session->waitForField('field_unlimited[2][value]');
$this->assertNotEmpty($field_2, 'Successfully added another item.');
// Set values for the 2nd and 3rd fields to validate dragging.
$field_1->setValue('2');
$field_2->setValue('3');
$field_weight_0 = $page->findField('field_unlimited[0][_weight]');
$field_weight_1 = $page->findField('field_unlimited[1][_weight]');
$field_weight_2 = $page->findField('field_unlimited[2][_weight]');
// Assert starting situation matches expectations.
$this->assertGreaterThan($field_weight_0->getValue(), $field_weight_1->getValue());
$this->assertGreaterThan($field_weight_1->getValue(), $field_weight_2->getValue());
// Drag the first row after the third row.
$dragged = $field_0->find('xpath', 'ancestor::tr[contains(@class, "draggable")]//a[@class="tabledrag-handle"]');
$target = $field_2->find('xpath', 'ancestor::tr[contains(@class, "draggable")]');
$dragged->dragTo($target);
// Assert the order of items is updated correctly after dragging.
$this->assertGreaterThan($field_weight_2->getValue(), $field_weight_0->getValue());
$this->assertGreaterThan($field_weight_1->getValue(), $field_weight_2->getValue());
// Validate the order of items conforms to the last drag action after a
// updating the form via the server.
$add_more_button->click();
$field_3 = $assert_session->waitForField('field_unlimited[3][value]');
$this->assertNotEmpty($field_3);
$this->assertGreaterThan($field_weight_2->getValue(), $field_weight_0->getValue());
$this->assertGreaterThan($field_weight_1->getValue(), $field_weight_2->getValue());
// Validate no extraneous widget is displayed.
$element = $page->findField('field_unlimited[4][value]');
$this->assertEmpty($element);
}
}
@@ -23,7 +23,6 @@ use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\User;
/**
* Tests the new entity API for the entity reference field type.
*
@@ -34,7 +34,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
'test_entity_reference_entity_test_mul_view',
'test_entity_reference_reverse_entity_test_mul_view',
'test_entity_reference_group_by_empty_relationships',
];
];
/**
* Modules to install.
@@ -272,7 +272,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
$this->assertEqual($row->_entity->id(), $this->entities[$index]->id());
// Test the forward relationship.
//$this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1);
// $this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1);
// Test that the correct relationship entity is on the row.
$this->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']->id(), 1);
@@ -1,6 +1,7 @@
<?php
namespace Drupal\Tests\field\Kernel;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
@@ -269,12 +269,11 @@ class FieldCrudTest extends FieldKernelTestBase {
}
/**
* Test the deletion of a field.
* Test the deletion of a field with no data.
*/
public function testDeleteField() {
// TODO: Test deletion of the data stored in the field also.
// Need to check that data for a 'deleted' field / storage doesn't get loaded
// Need to check data marked deleted is cleaned on cron (not implemented yet...)
public function testDeleteFieldNoData() {
// Deleting and purging fields with data is tested in
// \Drupal\Tests\field\Kernel\BulkDeleteTest.
// Create two fields for the same field storage so we can test that only one
// is deleted.
@@ -289,17 +288,18 @@ class FieldCrudTest extends FieldKernelTestBase {
$this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.');
$field->delete();
// Make sure the field is marked as deleted when it is specifically loaded.
$field = current(entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]));
$this->assertTrue($field->isDeleted(), 'A deleted field is marked for deletion.');
// Make sure the field was deleted without being marked for purging as there
// was no data.
$fields = entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]);
$this->assertEquals(0, count($fields), 'A deleted field is marked for deletion.');
// Try to load the field normally and make sure it does not show up.
$field = FieldConfig::load('entity_test.' . '.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
$this->assertTrue(empty($field), 'A deleted field is not loaded by default.');
$this->assertTrue(empty($field), 'Field was deleted');
// Make sure the other field is not deleted.
$another_field = FieldConfig::load('entity_test.' . $another_field_definition['bundle'] . '.' . $another_field_definition['field_name']);
$this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.');
$this->assertTrue(!empty($another_field) && !$another_field->isDeleted(), 'A non-deleted field is not marked for deletion.');
}
/**
@@ -3,6 +3,7 @@
namespace Drupal\Tests\field\Kernel;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
@@ -50,6 +51,14 @@ class FieldImportDeleteTest extends FieldKernelTestBase {
$field_config_name_2a = "field.field.$field_id_2a";
$field_config_name_2b = "field.field.$field_id_2b";
// Create an entity with data in the first field to make sure that field
// needs to be purged.
$entity_test = EntityTest::create([
'type' => 'entity_test',
]);
$entity_test->set($field_name, 'test data');
$entity_test->save();
// Create a second bundle for the 'Entity test' entity type.
entity_test_create_bundle('test_bundle');
@@ -97,10 +106,10 @@ class FieldImportDeleteTest extends FieldKernelTestBase {
$this->assertIdentical($active->listAll($field_config_name_2a), []);
$this->assertIdentical($active->listAll($field_config_name_2b), []);
// Check that the storage definition is preserved in state.
// Check that only the first storage definition is preserved in state.
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: [];
$this->assertTrue(isset($deleted_storages[$field_storage_uuid]));
$this->assertTrue(isset($deleted_storages[$field_storage_uuid_2]));
$this->assertFalse(isset($deleted_storages[$field_storage_uuid_2]));
// Purge field data, and check that the storage definition has been
// completely removed once the data is purged.
@@ -284,8 +284,9 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
/**
* Test the deletion of a field storage.
*/
public function testDelete() {
// TODO: Also test deletion of the data stored in the field ?
public function testDeleteNoData() {
// Deleting and purging field storages with data is tested in
// \Drupal\Tests\field\Kernel\BulkDeleteTest.
// Create two fields (so we can test that only one is deleted).
$field_storage_definition = [
@@ -317,23 +318,22 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
$this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage is not marked for deletion.');
FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete();
// Make sure that the field is marked as deleted when it is specifically
// loaded.
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]));
$this->assertTrue($field_storage->isDeleted(), 'A deleted storage is marked for deletion.');
// Make sure that the field storage is deleted as it had no data.
$field_storages = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]);
$this->assertEquals(0, count($field_storages), 'Field storage was deleted');
// Make sure that this field is marked as deleted when it is
// specifically loaded.
$field = current(entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE]));
$this->assertTrue($field->isDeleted(), 'A field whose storage was deleted is marked for deletion.');
$fields = entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE]);
$this->assertEquals(0, count($fields), 'Field storage was deleted');
// Try to load the storage normally and make sure it does not show up.
$field_storage = FieldStorageConfig::load('entity_test.' . $field_storage_definition['field_name']);
$this->assertTrue(empty($field_storage), 'A deleted storage is not loaded by default.');
$this->assertTrue(empty($field_storage), 'Field storage was deleted');
// Try to load the field normally and make sure it does not show up.
$field = FieldConfig::load('entity_test.' . '.' . $field_definition['bundle'] . '.' . $field_definition['field_name']);
$this->assertTrue(empty($field), 'A field whose storage was deleted is not loaded by default.');
$this->assertTrue(empty($field), 'Field was deleted');
// Make sure the other field and its storage are not deleted.
$another_field_storage = FieldStorageConfig::load('entity_test.' . $another_field_storage_definition['field_name']);
@@ -347,7 +347,7 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
FieldConfig::create($field_definition)->save();
$field_storage = FieldStorageConfig::load('entity_test.' . $field_storage_definition['field_name']);
$this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage with a previously used name is created.');
$field = FieldConfig::load('entity_test.' . $field_definition['bundle'] . '.' . $field_definition['field_name'] );
$field = FieldConfig::load('entity_test.' . $field_definition['bundle'] . '.' . $field_definition['field_name']);
$this->assertTrue(!empty($field) && !$field->isDeleted(), 'A new field for a previously used field name is created.');
// Save an entity with data for the field
@@ -433,8 +433,9 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
'type' => 'test_field',
'settings' => [
'changeable' => 0,
'unchangeable' => 0
]]);
'unchangeable' => 0,
],
]);
$field_storage->save();
$field_storage->setSetting('changeable', $field_storage->getSetting('changeable') + 1);
try {
@@ -56,7 +56,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_forum',
'id' => 'comment_forum',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
@@ -97,7 +97,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
Database::getConnection('default', 'migrate')
->update('field_config_instance')
->fields([
'data' => serialize( [
'data' => serialize([
'label' => 'Body',
'widget' =>
[
@@ -122,9 +122,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
[
'label' => 'hidden',
'type' => 'text_default',
'settings' =>
[
],
'settings' => [],
'module' => 'text',
'weight' => 0,
],
@@ -215,8 +213,8 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
$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_forum.default');
$this->assertComponent('comment.comment_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);
@@ -229,6 +227,11 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
$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->assertComponent('node.article.default', 'field_text_plain', 'string', 'above', 11);
$this->assertComponent('node.article.default', 'field_text_filtered', 'text_default', 'above', 12);
$this->assertComponent('node.article.default', 'field_text_long_plain', 'basic_string', 'above', 14);
$this->assertComponent('node.article.default', 'field_text_long_filtered', 'text_default', 'above', 15);
$this->assertComponent('node.article.default', 'field_text_sum_filtered', 'text_default', 'above', 18);
$this->assertEntity('node.article.teaser');
$this->assertComponent('node.article.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
@@ -257,6 +260,11 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
$this->assertEntity('node.page.default');
$this->assertComponent('node.page.default', 'body', 'text_default', 'hidden', 0);
$this->assertComponent('node.page.default', 'field_text_plain', 'string', 'above', 1);
$this->assertComponent('node.page.default', 'field_text_filtered', 'text_default', 'above', 2);
$this->assertComponent('node.page.default', 'field_text_long_plain', 'basic_string', 'above', 4);
$this->assertComponent('node.page.default', 'field_text_long_filtered', 'text_default', 'above', 5);
$this->assertComponent('node.page.default', 'field_text_sum_filtered', 'text_default', 'above', 8);
$this->assertEntity('node.page.teaser');
$this->assertComponent('node.page.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
@@ -2,12 +2,11 @@
namespace Drupal\Tests\field\Kernel\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\migrate\Kernel\NodeCommentCombinationTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Migrates Drupal 7 field instances.
@@ -16,10 +15,10 @@ use Drupal\node\Entity\NodeType;
*/
class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
use NodeCommentCombinationTrait;
/**
* The modules to be enabled during the test.
*
* @var array
* {@inheritdoc}
*/
public static $modules = [
'comment',
@@ -40,35 +39,16 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
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->createNodeCommentCombination('page');
$this->createNodeCommentCombination('article');
$this->createNodeCommentCombination('blog');
$this->createNodeCommentCombination('book');
$this->createNodeCommentCombination('forum', 'comment_forum');
$this->createNodeCommentCombination('test_content_type');
Vocabulary::create(['vid' => 'test_vocabulary'])->save();
$this->executeMigrations(['d7_field', '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([
'type' => $id,
'label' => $this->randomString(),
])->save();
CommentType::create([
'id' => 'comment_node_' . $id,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
])->save();
}
/**
* Asserts various aspects of a field config entity.
*
@@ -88,15 +68,15 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
/** @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());
$this->assertSame($expected_translatable, $field->isTranslatable());
$this->assertInstanceOf(FieldConfigInterface::class, $field);
$this->assertEquals($expected_label, $field->label());
$this->assertEquals($expected_field_type, $field->getType());
$this->assertEquals($expected_entity_type, $field->getTargetEntityTypeId());
$this->assertEquals($expected_bundle, $field->getTargetBundle());
$this->assertEquals($expected_name, $field->getName());
$this->assertEquals($is_required, $field->isRequired());
$this->assertEquals($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
$this->assertEquals($expected_translatable, $field->isTranslatable());
}
/**
@@ -127,14 +107,14 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
$this->assertEntity('comment.comment_node_book.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('node.book.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('node.forum.taxonomy_forums', 'Forums', 'entity_reference', TRUE, FALSE);
$this->assertEntity('comment.comment_node_forum.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('comment.comment_forum.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('node.forum.body', 'Body', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('comment.comment_node_test_content_type.comment_body', 'Comment', 'text_long', TRUE, FALSE);
$this->assertEntity('node.test_content_type.field_boolean', 'Boolean', 'boolean', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_email', 'Email', 'email', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_phone', 'Phone', 'telephone', TRUE, FALSE);
$this->assertEntity('node.test_content_type.field_date', 'Date', 'datetime', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_date_with_end_time', 'Date With End Time', 'datetime', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_date_with_end_time', 'Date With End Time', 'timestamp', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_file', 'File', 'file', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_float', 'Float', 'float', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_images', 'Images', 'image', TRUE, FALSE);
@@ -144,7 +124,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'text', FALSE, FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'string', FALSE, FALSE);
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE, FALSE);
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE, FALSE);
@@ -154,4 +134,63 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
$this->assertLinkFields('node.blog.field_link', DRUPAL_REQUIRED);
}
/**
* Tests the migration of text field instances with different text processing.
*/
public function testTextFieldInstances() {
// All text and text_long field instances using a field base that has only
// plain text instances should be migrated to string and string_long fields.
// All text_with_summary field instances using a field base that has only
// plain text instances should not have been migrated since there's no such
// thing as a string_with_summary field.
$this->assertEntity('node.page.field_text_plain', 'Text plain', 'string', FALSE, FALSE);
$this->assertEntity('node.article.field_text_plain', 'Text plain', 'string', FALSE, TRUE);
$this->assertEntity('node.page.field_text_long_plain', 'Text long plain', 'string_long', FALSE, FALSE);
$this->assertEntity('node.article.field_text_long_plain', 'Text long plain', 'string_long', FALSE, TRUE);
$this->assertNull(FieldConfig::load('node.page.field_text_sum_plain'));
$this->assertNull(FieldConfig::load('node.article.field_text_sum_plain'));
// All text, text_long and text_with_summary field instances using a field
// base that has only filtered text instances should be migrated to text,
// text_long and text_with_summary fields.
$this->assertEntity('node.page.field_text_filtered', 'Text filtered', 'text', FALSE, FALSE);
$this->assertEntity('node.article.field_text_filtered', 'Text filtered', 'text', FALSE, TRUE);
$this->assertEntity('node.page.field_text_long_filtered', 'Text long filtered', 'text_long', FALSE, FALSE);
$this->assertEntity('node.article.field_text_long_filtered', 'Text long filtered', 'text_long', FALSE, TRUE);
$this->assertEntity('node.page.field_text_sum_filtered', 'Text summary filtered', 'text_with_summary', FALSE, FALSE);
$this->assertEntity('node.article.field_text_sum_filtered', 'Text summary filtered', 'text_with_summary', FALSE, TRUE);
// All text, text_long and text_with_summary field instances using a field
// base that has both plain text and filtered text instances should not have
// been migrated.
$this->assertNull(FieldConfig::load('node.page.field_text_plain_filtered'));
$this->assertNull(FieldConfig::load('node.article.field_text_plain_filtered'));
$this->assertNull(FieldConfig::load('node.page.field_text_long_plain_filtered'));
$this->assertNull(FieldConfig::load('node.article.field_text_long_plain_filtered'));
$this->assertNull(FieldConfig::load('node.page.field_text_sum_plain_filtered'));
$this->assertNull(FieldConfig::load('node.article.field_text_sum_plain_filtered'));
// For each text field instances that were skipped, there should be a log
// message with the required steps to fix this.
$migration = $this->getMigration('d7_field_instance');
$messages = $migration->getIdMap()->getMessageIterator()->fetchAll();
$errors = array_map(function ($message) {
return $message->message;
}, $messages);
$this->assertCount(8, $errors);
sort($errors);
$message = 'Can\'t migrate source field field_text_long_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[0], $message);
$this->assertEquals($errors[1], $message);
$message = 'Can\'t migrate source field field_text_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[2], $message);
$this->assertEquals($errors[3], $message);
$message = 'Can\'t migrate source field field_text_sum_plain of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[4], $message);
$this->assertEquals($errors[5], $message);
$message = 'Can\'t migrate source field field_text_sum_plain_filtered of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text';
$this->assertEquals($errors[6], $message);
$this->assertEquals($errors[7], $message);
}
}
@@ -96,11 +96,21 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
public function testWidgetSettings() {
$this->assertEntity('node.page.default', 'node', 'page');
$this->assertComponent('node.page.default', 'body', 'text_textarea_with_summary', -4);
$this->assertComponent('node.page.default', 'field_text_plain', 'string_textfield', -2);
$this->assertComponent('node.page.default', 'field_text_filtered', 'text_textfield', 0);
$this->assertComponent('node.page.default', 'field_text_long_plain', 'string_textarea', 4);
$this->assertComponent('node.page.default', 'field_text_long_filtered', 'text_textarea', 6);
$this->assertComponent('node.page.default', 'field_text_sum_filtered', 'text_textarea_with_summary', 12);
$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', 'entity_reference_autocomplete', -4);
$this->assertComponent('node.article.default', 'field_image', 'image_image', -1);
$this->assertComponent('node.article.default', 'field_text_plain', 'string_textfield', 11);
$this->assertComponent('node.article.default', 'field_text_filtered', 'text_textfield', 12);
$this->assertComponent('node.article.default', 'field_text_long_plain', 'string_textarea', 14);
$this->assertComponent('node.article.default', 'field_text_long_filtered', 'text_textarea', 15);
$this->assertComponent('node.article.default', 'field_text_sum_filtered', 'text_textarea_with_summary', 18);
$this->assertEntity('node.blog.default', 'node', 'blog');
$this->assertComponent('node.blog.default', 'body', 'text_textarea_with_summary', -4);
@@ -129,7 +139,7 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
$this->assertComponent('node.test_content_type.default', 'field_node_entityreference', 'entity_reference_autocomplete', 16);
$this->assertComponent('node.test_content_type.default', 'field_user_entityreference', 'options_buttons', 17);
$this->assertComponent('node.test_content_type.default', 'field_term_entityreference', 'entity_reference_autocomplete_tags', 18);
$this->assertComponent('node.test_content_type.default', 'field_text', 'text_textfield', 15);
$this->assertComponent('node.test_content_type.default', 'field_text', 'string_textfield', 15);
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'options_select', 11);
$this->assertEntity('user.user.default', 'user', 'user');
@@ -57,11 +57,11 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
/** @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());
$this->assertEqual($expected_translatable, $field->isTranslatable());
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
$this->assertInstanceOf(FieldStorageConfigInterface::class, $field);
$this->assertEquals($expected_name, $field->getName());
$this->assertEquals($expected_type, $field->getType());
$this->assertEquals($expected_translatable, $field->isTranslatable());
$this->assertEquals($expected_entity_type, $field->getTargetEntityTypeId());
if ($expected_cardinality === 1) {
$this->assertFalse($field->isMultiple());
@@ -69,7 +69,7 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
else {
$this->assertTrue($field->isMultiple());
}
$this->assertIdentical($expected_cardinality, $field->getCardinality());
$this->assertEquals($expected_cardinality, $field->getCardinality());
}
/**
@@ -91,13 +91,13 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
$this->assertEntity('node.field_tags', 'entity_reference', TRUE, -1);
$this->assertEntity('node.field_term_reference', 'entity_reference', TRUE, 1);
$this->assertEntity('node.taxonomy_forums', 'entity_reference', TRUE, 1);
$this->assertEntity('node.field_text', 'text', TRUE, 1);
$this->assertEntity('node.field_text', 'string', TRUE, 1);
$this->assertEntity('node.field_text_list', 'list_string', TRUE, 3);
$this->assertEntity('node.field_boolean', 'boolean', TRUE, 1);
$this->assertEntity('node.field_email', 'email', TRUE, -1);
$this->assertEntity('node.field_phone', 'telephone', TRUE, 1);
$this->assertEntity('node.field_date', 'datetime', TRUE, 1);
$this->assertEntity('node.field_date_with_end_time', 'datetime', TRUE, 1);
$this->assertEntity('node.field_date_with_end_time', 'timestamp', TRUE, 1);
$this->assertEntity('node.field_node_entityreference', 'entity_reference', TRUE, -1);
$this->assertEntity('node.field_user_entityreference', 'entity_reference', TRUE, 1);
$this->assertEntity('node.field_term_entityreference', 'entity_reference', TRUE, -1);
@@ -105,24 +105,59 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
// Assert that the taxonomy term reference fields are referencing the
// correct entity type.
$field = FieldStorageConfig::load('node.field_term_reference');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.taxonomy_forums');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
// Assert that the entityreference fields are referencing the correct
// entity type.
$field = FieldStorageConfig::load('node.field_node_entityreference');
$this->assertIdentical('node', $field->getSetting('target_type'));
$this->assertEquals('node', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_user_entityreference');
$this->assertIdentical('user', $field->getSetting('target_type'));
$this->assertEquals('user', $field->getSetting('target_type'));
$field = FieldStorageConfig::load('node.field_term_entityreference');
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
}
// Validate that the source count and processed count match up.
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
/**
* Tests the migration of text fields with different text processing.
*/
public function testTextFields() {
// All text and text_long field bases that have only plain text instances
// should be migrated to string and string_long fields.
// All text_with_summary field bases that have only plain text instances
// should not have been migrated since there's no such thing as a
// string_with_summary field.
$this->assertEntity('node.field_text_plain', 'string', TRUE, 1);
$this->assertEntity('node.field_text_long_plain', 'string_long', TRUE, 1);
$this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain'));
// All text, text_long and text_with_summary field bases that have only
// filtered text instances should be migrated to text, text_long and
// text_with_summary fields.
$this->assertEntity('node.field_text_filtered', 'text', TRUE, 1);
$this->assertEntity('node.field_text_long_filtered', 'text_long', TRUE, 1);
$this->assertEntity('node.field_text_sum_filtered', 'text_with_summary', TRUE, 1);
// All text, text_long and text_with_summary field bases that have both
// plain text and filtered text instances should not have been migrated.
$this->assertNull(FieldStorageConfig::load('node.field_text_plain_filtered'));
$this->assertNull(FieldStorageConfig::load('node.field_text_long_plain_filtered'));
$this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain_filtered'));
// For each text field bases that were skipped, there should be a log
// message with the required steps to fix this.
$migration = $this->getMigration('d7_field');
$this->assertSame($migration->getSourcePlugin()
->count(), $migration->getIdMap()->processedCount());
$messages = $migration->getIdMap()->getMessageIterator()->fetchAll();
$errors = array_map(function ($message) {
return $message->message;
}, $messages);
sort($errors);
$this->assertCount(4, $errors);
$this->assertEquals($errors[0], 'Can\'t migrate source field field_text_long_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
$this->assertEquals($errors[1], 'Can\'t migrate source field field_text_plain_filtered configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
$this->assertEquals($errors[2], 'Can\'t migrate source field field_text_sum_plain of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
$this->assertEquals($errors[3], 'Can\'t migrate source field field_text_sum_plain_filtered of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text');
}
}
@@ -34,8 +34,6 @@ class MigrateViewModesTest extends MigrateDrupal7TestBase {
* 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 */
@@ -35,7 +35,7 @@ class RollbackFieldInstanceTest extends MigrateFieldInstanceTest {
'comment.comment_node_book.comment_body',
'node.book.body',
'node.forum.taxonomy_forums',
'comment.comment_node_forum.comment_body',
'comment.comment_forum.comment_body',
'node.forum.body',
'comment.comment_node_test_content_type.comment_body',
'node.test_content_type.field_boolean',
@@ -93,7 +93,7 @@ class NumberItemTest extends FieldKernelTestBase {
$this->assertEqual($entity->field_float->value, $new_float);
$this->assertEqual($entity->field_decimal->value, $new_decimal);
/// Test sample item generation.
// Test sample item generation.
$entity = EntityTest::create();
$entity->field_integer->generateSampleItems();
$entity->field_float->generateSampleItems();
@@ -133,33 +133,184 @@ class FieldInstancePerFormDisplayTest extends MigrateSqlSourceTestBase {
// The expected results.
$tests[0]['expected_data'] = [
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'widget_settings' => [
'rows' => 20,
'summary_rows' => 5,
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
'widget' => [
'module' => 'text',
'settings' => [
'rows' => 20,
'summary_rows' => 5,
],
'type' => 'text_textarea_with_summary',
'weight' => -4,
],
'field_definition' => [
'id' => '2',
'field_name' => 'body',
'type' => 'text_with_summary',
'module' => 'text',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:6:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:12:"translatable";b:0;s:8:"settings";a:0:{}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";i:1;}s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
'instances' => [
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
],
],
],
[
'id' => '33',
'field_id' => '11',
'field_name' => 'field_file',
'entity_type' => 'user',
'bundle' => 'user',
'widget_settings' => [
'progress_indicator' => 'throbber',
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"8";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:3:"txt";s:12:"max_filesize";s:0:"";s:17:"description_field";i:0;s:18:"user_register_form";i:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:8:"settings";a:0:{}s:6:"module";s:4:"file";s:6:"weight";i:0;}}s:8:"required";i:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'file',
'widget' => [
'active' => 1,
'module' => 'file',
'settings' => [
'progress_indicator' => 'throbber',
],
'type' => 'file_generic',
'weight' => '8',
],
'field_definition' => [
'id' => '11',
'field_name' => 'field_file',
'type' => 'file',
'module' => 'file',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
'instances' => [
[
'id' => '33',
'field_id' => '11',
'field_name' => 'field_file',
'entity_type' => 'user',
'bundle' => 'user',
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"8";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:3:"txt";s:12:"max_filesize";s:0:"";s:17:"description_field";i:0;s:18:"user_register_form";i:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:8:"settings";a:0:{}s:6:"module";s:4:"file";s:6:"weight";i:0;}}s:8:"required";i:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'file',
],
],
],
[
'id' => '32',
'field_id' => '14',
'field_name' => 'field_integer',
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'widget_settings' => [],
'data' => 'a:7:{s:5:"label";s:7:"Integer";s:6:"widget";a:5:{s:6:"weight";s:1:"2";s:4:"type";s:6:"number";s:6:"module";s:6:"number";s:6:"active";i:0;s:8:"settings";a:0:{}}s:8:"settings";a:5:{s:3:"min";s:0:"";s:3:"max";s:0:"";s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:14:"number_integer";s:8:"settings";a:4:{s:18:"thousand_separator";s:1:" ";s:17:"decimal_separator";s:1:".";s:5:"scale";i:0;s:13:"prefix_suffix";b:1;}s:6:"module";s:6:"number";s:6:"weight";i:1;}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}',
'deleted' => '0',
'type' => 'number_integer',
'widget' => [
'weight' => '2',
'type' => 'number',
'module' => 'number',
'active' => 0,
'settings' => [],
],
'field_definition' => [
'id' => '14',
'field_name' => 'field_integer',
'type' => 'number_integer',
'module' => 'number',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:0:{}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:24:"field_data_field_integer";a:1:{s:5:"value";s:19:"field_integer_value";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:28:"field_revision_field_integer";a:1:{s:5:"value";s:19:"field_integer_value";}}}}}s:12:"foreign keys";a:0:{}s:7:"indexes";a:0:{}s:2:"id";s:2:"14";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
'instances' => [
[
'id' => '32',
'field_id' => '14',
'field_name' => 'field_integer',
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
'data' => 'a:7:{s:5:"label";s:7:"Integer";s:6:"widget";a:5:{s:6:"weight";s:1:"2";s:4:"type";s:6:"number";s:6:"module";s:6:"number";s:6:"active";i:0;s:8:"settings";a:0:{}}s:8:"settings";a:5:{s:3:"min";s:0:"";s:3:"max";s:0:"";s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:14:"number_integer";s:8:"settings";a:4:{s:18:"thousand_separator";s:1:" ";s:17:"decimal_separator";s:1:".";s:5:"scale";i:0;s:13:"prefix_suffix";b:1;}s:6:"module";s:6:"number";s:6:"weight";i:1;}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}',
'deleted' => '0',
'type' => 'number_integer',
]
],
],
[
'id' => '25',
'field_id' => '15',
'field_name' => 'field_link',
'entity_type' => 'taxonomy_term',
'bundle' => 'test_vocabulary',
'widget_settings' => [],
'data' => 'a:7:{s:5:"label";s:4:"Link";s:6:"widget";a:5:{s:6:"weight";s:2:"10";s:4:"type";s:10:"link_field";s:6:"module";s:4:"link";s:6:"active";i:0;s:8:"settings";a:0:{}}s:8:"settings";a:12:{s:12:"absolute_url";i:1;s:12:"validate_url";i:1;s:3:"url";i:0;s:5:"title";s:8:"optional";s:11:"title_value";s:19:"Unused Static Title";s:27:"title_label_use_field_label";i:0;s:15:"title_maxlength";s:3:"128";s:7:"display";a:1:{s:10:"url_cutoff";s:2:"81";}s:10:"attributes";a:6:{s:6:"target";s:6:"_blank";s:3:"rel";s:8:"nofollow";s:18:"configurable_class";i:0;s:5:"class";s:7:"classes";s:18:"configurable_title";i:1;s:5:"title";s:0:"";}s:10:"rel_remove";s:19:"rel_remove_external";s:13:"enable_tokens";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"link_default";s:6:"weight";s:1:"9";s:8:"settings";a:0:{}s:6:"module";s:4:"link";}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}',
'deleted' => '0',
'type' => 'link_field',
'widget' => [
'weight' => '10',
'type' => 'link_field',
'module' => 'link',
'active' => 0,
'settings' => [],
],
'field_definition' => [
'id' => '15',
'field_name' => 'field_link',
'type' => 'link_field',
'module' => 'link',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:7:{s:10:"attributes";a:3:{s:6:"target";s:7:"default";s:5:"class";s:0:"";s:3:"rel";s:0:"";}s:3:"url";i:0;s:5:"title";s:8:"optional";s:11:"title_value";s:0:"";s:15:"title_maxlength";i:128;s:13:"enable_tokens";i:1;s:7:"display";a:1:{s:10:"url_cutoff";i:80;}}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_link";a:3:{s:3:"url";s:14:"field_link_url";s:5:"title";s:16:"field_link_title";s:10:"attributes";s:21:"field_link_attributes";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_link";a:3:{s:3:"url";s:14:"field_link_url";s:5:"title";s:16:"field_link_title";s:10:"attributes";s:21:"field_link_attributes";}}}}}s:12:"foreign keys";a:0:{}s:7:"indexes";a:0:{}s:2:"id";s:2:"15";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
'instances' => [
[
'id' => '25',
'field_id' => '15',
'field_name' => 'field_link',
'entity_type' => 'taxonomy_term',
'bundle' => 'test_vocabulary',
'data' => 'a:7:{s:5:"label";s:4:"Link";s:6:"widget";a:5:{s:6:"weight";s:2:"10";s:4:"type";s:10:"link_field";s:6:"module";s:4:"link";s:6:"active";i:0;s:8:"settings";a:0:{}}s:8:"settings";a:12:{s:12:"absolute_url";i:1;s:12:"validate_url";i:1;s:3:"url";i:0;s:5:"title";s:8:"optional";s:11:"title_value";s:19:"Unused Static Title";s:27:"title_label_use_field_label";i:0;s:15:"title_maxlength";s:3:"128";s:7:"display";a:1:{s:10:"url_cutoff";s:2:"81";}s:10:"attributes";a:6:{s:6:"target";s:6:"_blank";s:3:"rel";s:8:"nofollow";s:18:"configurable_class";i:0;s:5:"class";s:7:"classes";s:18:"configurable_title";i:1;s:5:"title";s:0:"";}s:10:"rel_remove";s:19:"rel_remove_external";s:13:"enable_tokens";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"link_default";s:6:"weight";s:1:"9";s:8:"settings";a:0:{}s:6:"module";s:4:"link";}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}',
'deleted' => '0',
'type' => 'link_field',
],
],
],
];
@@ -62,30 +62,96 @@ class FieldInstancePerViewModeTest extends MigrateSqlSourceTestBase {
// The expected results.
$tests[0]['expected_data'] = [
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => 'body',
'label' => 'hidden',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
'formatter_type' => 'text_default',
'settings' => [],
'module' => 'text',
'weight' => 0,
'view_mode' => 'default',
'formatter' => [
'label' => 'hidden',
'type' => 'text_default',
'settings' => [],
'module' => 'text',
'weight' => 0,
],
'field_definition' => [
'id' => '2',
'field_name' => 'body',
'type' => 'text_with_summary',
'module' => 'text',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}s:8:"settings";a:0:{}s:12:"translatable";i:0;s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";}s:2:"id";s:2:"25";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
'instances' => [
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
],
],
],
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => 'body',
'label' => 'hidden',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
'formatter_type' => 'text_summary_or_trimmed',
'settings' => [
'trim_length' => 600,
'formatter' => [
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
'settings' => [
'trim_length' => 600,
],
'module' => 'text',
'weight' => 0,
],
'module' => 'text',
'weight' => 0,
'view_mode' => 'teaser',
'field_definition' => [
'id' => '2',
'field_name' => 'body',
'type' => 'text_with_summary',
'module' => 'text',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}s:8:"settings";a:0:{}s:12:"translatable";i:0;s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";}s:2:"id";s:2:"25";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
'instances' => [
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
],
],
],
];
@@ -61,20 +61,30 @@ class FieldInstanceTest extends MigrateSqlSourceTestBase {
// The expected results.
$tests[0]['expected_data'] = [
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
'label' => 'Body',
'widget_settings' => [
'module' => 'text',
'widget' => [
'type' => 'text_textarea_with_summary',
'settings' => [
'rows' => 20,
'summary_rows' => 5,
],
'type' => 'text_textarea_with_summary',
'weight' => -4,
'module' => 'text',
],
'display_settings' => [
'settings' => [
'display_summary' => TRUE,
'text_processing' => '1',
'user_register_form' => FALSE,
],
'display' => [
'default' => [
'label' => 'hidden',
'type' => 'text_default',
@@ -92,9 +102,35 @@ class FieldInstanceTest extends MigrateSqlSourceTestBase {
'weight' => 0,
],
],
'description' => '',
'required' => FALSE,
'field_data' => 'a:6:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:12:"translatable";b:0;s:8:"settings";a:0:{}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";i:1;}s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}}',
'description' => '',
'field_definition' => [
'id' => '2',
'field_name' => 'body',
'type' => 'text_with_summary',
'module' => 'text',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:6:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:12:"translatable";b:0;s:8:"settings";a:0:{}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";i:1;}s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
'instances' => [
[
'id' => '2',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
'deleted' => '0',
'type' => 'text_with_summary',
],
],
],
];
@@ -70,9 +70,29 @@ class FieldTest extends MigrateSqlSourceTestBase {
// The expected results.
$tests[0]['expected_data'] = [
[
'id' => '11',
'field_name' => 'field_file',
'type' => 'file',
'module' => 'file',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
'entity_types' => [],
'settings' => [
'display_field' => '0',
'display_default' => '0',
'uri_scheme' => 'public',
],
'storage' => [
'type' => 'field_sql_storage',
'settings' => [],
'module' => 'field_sql_storage',
'active' => 1,
'details' => [
'sql' => [
@@ -92,18 +112,44 @@ class FieldTest extends MigrateSqlSourceTestBase {
],
],
],
'module' => 'field_sql_storage',
'settings' => [],
'type' => 'field_sql_storage',
],
'module' => 'file',
'locked' => 0,
'entity_type' => 'node',
'instances' => [
[
'id' => '21',
'field_id' => '11',
'field_name' => 'field_file',
'entity_type' => 'node',
'bundle' => 'test_content_type',
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"5";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:15:"txt pdf ods odf";s:12:"max_filesize";s:5:"10 MB";s:17:"description_field";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:6:"weight";s:1:"5";s:8:"settings";a:0:{}s:6:"module";s:4:"file";}}s:8:"required";i:0;s:11:"description";s:0:"";}',
'deleted' => '0',
],
],
],
[
'id' => '11',
'field_name' => 'field_file',
'type' => 'file',
'module' => 'file',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
'entity_types' => [],
'settings' => [
'display_field' => '0',
'display_default' => '0',
'uri_scheme' => 'public',
],
'storage' => [
'type' => 'field_sql_storage',
'settings' => [],
'module' => 'field_sql_storage',
'active' => 1,
'details' => [
'sql' => [
@@ -123,13 +169,19 @@ class FieldTest extends MigrateSqlSourceTestBase {
],
],
],
'module' => 'field_sql_storage',
'settings' => [],
'type' => 'field_sql_storage',
],
'module' => 'file',
'locked' => 0,
'entity_type' => 'user',
'instances' => [
[
'id' => '33',
'field_id' => '11',
'field_name' => 'field_file',
'entity_type' => 'user',
'bundle' => 'user',
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"8";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:3:"txt";s:12:"max_filesize";s:0:"";s:17:"description_field";i:0;s:18:"user_register_form";i:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:8:"settings";a:0:{}s:6:"module";s:4:"file";s:6:"weight";i:0;}}s:8:"required";i:0;s:11:"description";s:0:"";}',
'deleted' => '0',
],
],
],
];
@@ -50,14 +50,46 @@ class ViewModeTest extends MigrateSqlSourceTestBase {
],
[
'id' => '12',
'field_id' => '1',
'field_name' => 'comment_body',
'field_id' => '2',
'field_name' => 'body',
'entity_type' => 'comment',
'bundle' => 'comment_node_forum',
'data' => 'a:6:{s:5:"label";s:7:"Comment";s:8:"settings";a:2:{s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:8:"required";b:1;s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:6:"weight";i:0;s:8:"settings";a:0:{}s:6:"module";s:4:"text";}}s:6:"widget";a:4:{s:4:"type";s:13:"text_textarea";s:8:"settings";a:1:{s:4:"rows";i:5;}s:6:"weight";i:0;s:6:"module";s:4:"text";}s:11:"description";s:0:"";}',
'deleted' => '0',
],
];
$tests[0]['source_data']['field_config'] = [
[
'id' => '2',
'field_name' => 'body',
'type' => 'text_with_summary',
'module' => 'text',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:6:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:12:"translatable";b:0;s:8:"settings";a:0:{}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";i:1;}s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
[
'id' => '11',
'field_name' => 'field_file',
'type' => 'file',
'module' => 'file',
'active' => '1',
'storage_type' => 'field_sql_storage',
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
],
];
// The expected results.
$tests[0]['expected_data'] = [
@@ -0,0 +1,91 @@
<?php
namespace Drupal\Tests\field\Kernel\Timestamp;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
/**
* Tests the timestamp fields.
*
* @group field
*/
class TimestampItemTest extends FieldKernelTestBase {
/**
* A field storage 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;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_timestamp',
'type' => 'timestamp',
'entity_type' => 'entity_test',
]);
$this->fieldStorage->save();
$this->field = FieldConfig::create([
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
]);
$this->field->save();
}
/**
* Tests using entity fields of the datetime field type.
*/
public function testDateTime() {
// Verify entity creation.
$entity = EntityTest::create();
$value = 1488914208;
$entity->field_timestamp = $value;
$entity->name->value = $this->randomMachineName();
$this->entityValidateAndSave($entity);
// Verify entity has been created properly.
$id = $entity->id();
$entity = EntityTest::load($id);
$this->assertTrue($entity->field_timestamp instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_timestamp[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEquals($entity->field_timestamp->value, $value);
$this->assertEquals($entity->field_timestamp[0]->value, $value);
// Verify changing the date value.
$new_value = 1488914000;
$entity->field_timestamp->value = $new_value;
$this->assertEquals($entity->field_timestamp->value, $new_value);
// Read changed entity and assert changed values.
$this->entityValidateAndSave($entity);
$entity = EntityTest::load($id);
$this->assertEquals($entity->field_timestamp->value, $new_value);
// Test sample item generation.
$entity = EntityTest::create();
$entity->field_timestamp->generateSampleItems();
$this->entityValidateAndSave($entity);
// Ensure there is sample value a generated for the field.
$this->assertNotNull($entity->field_timestamp->value);
}
}
@@ -1,6 +1,7 @@
<?php
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Field\BaseFieldDefinition;
/**
@@ -8,6 +8,7 @@
namespace Drupal\Tests\field\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Field\FieldException;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\field\Entity\FieldStorageConfig;
@@ -110,6 +111,104 @@ class FieldStorageConfigEntityUnitTest extends UnitTestCase {
$this->assertEquals(['stark'], $dependencies['theme']);
}
/**
* Tests stored cardinality.
*
* @covers ::getCardinality
*/
public function testStoredCardinality() {
$this->fieldTypeManager->expects($this->any())
->method('getDefinition')
->with('test_field_type')
->willReturn([
'class' => TestFieldType::class,
// The field type definition has no enforced cardinality.
'cardinality' => NULL,
]);
$field_storage = new FieldStorageConfig([
'entity_type' => 'entity_test',
'field_name' => 'test_field',
'type' => 'test_field_type',
'module' => 'test_module',
]);
$field_storage->setCardinality(8);
// Check that the stored cardinality is returned.
$this->assertEquals(8, $field_storage->getCardinality());
}
/**
* Tests enforced cardinality.
*
* @covers ::getCardinality
*/
public function testEnforcedCardinality() {
$this->fieldTypeManager->expects($this->any())
->method('getDefinition')
->with('test_field_type')
->willReturn([
'class' => TestFieldType::class,
// This field type defines an enforced cardinality.
'cardinality' => 21,
]);
$field_storage = new FieldStorageConfig([
'entity_type' => 'entity_test',
'field_name' => 'test_field',
'type' => 'test_field_type',
'module' => 'test_module',
]);
// Custom cardinality tentative.
$field_storage->setCardinality(8);
// Check that the enforced cardinality is returned.
$this->assertEquals(21, $field_storage->getCardinality());
}
/**
* Tests invalid enforced cardinality.
*
* @covers ::getCardinality
* @dataProvider providerInvalidEnforcedCardinality
*
* @param mixed $enforced_cardinality
* Enforced cardinality
*/
public function testInvalidEnforcedCardinality($enforced_cardinality) {
$this->fieldTypeManager->expects($this->any())
->method('getDefinition')
->with('test_field_type')
->willReturn([
'class' => TestFieldType::class,
'cardinality' => $enforced_cardinality,
]);
$field_storage = new FieldStorageConfig([
'entity_type' => 'entity_test',
'field_name' => 'test_field',
'type' => 'test_field_type',
'module' => 'test_module',
]);
$this->setExpectedException(FieldException::class, "Invalid enforced cardinality '$enforced_cardinality'. Allowed values: a positive integer or -1.");
$field_storage->getCardinality();
}
/**
* Data provider for ::testInvalidEnforcedCardinality()
*
* @return array
* Test cases.
*/
public function providerInvalidEnforcedCardinality() {
return [
'zero' => [0],
'negative_other_than_-1' => [-70],
'non_numeric' => ['abc%$#@!'],
];
}
}
/**
@@ -0,0 +1,134 @@
<?php
namespace Drupal\Tests\field\Unit\Plugin\migrate\process;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\field\Plugin\migrate\process\ProcessField;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
use Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
/**
* Tests the ProcessField migrate process plugin.
*
* @coversDefaultClass \Drupal\field\Plugin\migrate\process\ProcessField
* @group field
* @group legacy
*/
class ProcessFieldTest extends MigrateTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->cckFieldManager = $this->prophesize(MigrateCckFieldPluginManagerInterface::class);
$this->fieldManager = $this->prophesize(MigrateFieldPluginManagerInterface::class);
$this->fieldPlugin = $this->prophesize(MigrateFieldInterface::class);
$this->migrateExecutable = $this->prophesize(MigrateExecutable::class);
$this->migration = $this->prophesize(MigrationInterface::class);
$this->row = $this->prophesize(Row::class);
$this->fieldManager->getPluginIdFromFieldType('foo', [], $this->migration->reveal())->willReturn('foo');
$this->fieldManager->createInstance('foo', [], $this->migration->reveal())->willReturn($this->fieldPlugin);
parent::setUp();
}
/**
* Tests the transform method.
*
* @param string $method
* The method to call.
* @param string $value
* The value to process.
* @param mixed $expected_value
* The expected transformed value.
* @param string $migrate_exception
* The MigrateException message to expect.
* @param bool $plugin_not_found
* Whether the field plugin is not found.
*
* @covers ::transform
* @dataProvider providerTestTransform
*/
public function testTransform($method, $value, $expected_value, $migrate_exception = '', $plugin_not_found = FALSE) {
if ($method) {
$this->fieldPlugin->$method($this->row->reveal())->willReturn($expected_value);
}
$this->plugin = new ProcessField(['method' => $method], $value, [], $this->cckFieldManager->reveal(), $this->fieldManager->reveal(), $this->migration->reveal());
if ($migrate_exception) {
$this->setExpectedException(MigrateException::class, $migrate_exception);
}
if ($plugin_not_found) {
$exception = new PluginNotFoundException('foo');
$this->cckFieldManager->getPluginIdFromFieldType()->willThrow($exception);
$this->fieldManager->getPluginIdFromFieldType()->willThrow($exception);
}
$transformed_value = $this->plugin->transform($value, $this->migrateExecutable->reveal(), $this->row->reveal(), 'foo');
$this->assertSame($transformed_value, $expected_value);
}
/**
* Provides data for the transform method test.
*
* @return array
* - The method to call.
* - The value to process.
* - The expected transformed value.
* - The MigrateException message to expect.
* - Whether the field plugin is not found.
*/
public function providerTestTransform() {
return [
// Tests the getFieldType() method.
[
'method' => 'getFieldType',
'value' => 'foo',
'expected_value' => 'bar',
],
// Tests the getFieldFormatterMap() method.
[
'method' => 'getFieldFormatterMap',
'value' => 'foo',
'expected_value' => ['foo' => 'bar'],
],
// Tests the getFieldWidgetMap() method.
[
'method' => 'getFieldWidgetMap',
'value' => 'foo',
'expected_value' => ['foo' => 'bar'],
],
// Tests that an exception is thrown if the value is not a string.
[
'method' => 'getFieldType',
'value' => ['foo'],
'expected_value' => '',
'migrate_exception' => 'The input value must be a string.',
],
// Tests that an exception is thrown if no method name is provided.
[
'method' => '',
'value' => '',
'expected_value' => '',
'migrate_exception' => 'You need to specify the name of a method to be called on the Field plugin.',
],
// Tests that NULL is returned if no field plugin is found.
[
'method' => 'getFieldType',
'value' => 'foo',
'expected_value' => NULL,
'migrate_exception' => '',
'plugin_not_found' => TRUE,
],
];
}
}
@@ -28,7 +28,7 @@ class FieldInstanceSettingsTest extends MigrateTestCase {
->disableOriginalConstructor()
->getMock();
$value = $plugin->transform([[], ['type' => 'image_image'], []], $executable, $row, 'foo');
$value = $plugin->transform([[], ['type' => 'image_image'], ['data' => '']], $executable, $row, 'foo');
$this->assertInternalType('array', $value['default_image']);
$this->assertSame('', $value['default_image']['alt']);
$this->assertSame('', $value['default_image']['title']);