diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index bdeeba1..b3b51c2 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -110,7 +110,7 @@ public function get($key = '') { * {@inheritdoc} */ public function setData(array $data) { - $this->data = $data; + parent::setData($data); $this->resetOverriddenData(); return $this; } diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index 3508611..37e0d80 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -160,13 +160,39 @@ public function get($key = '') { * * @return $this * The configuration object. + * + * @throws \Drupal\Core\Config\ConfigValueException + * If any key in $data in any depth contains a dot. */ public function setData(array $data) { + $this->validateKeys($data); $this->data = $data; return $this; } /** + * Validate all keys in a passed in config array structure. + * + * @param array $data + * Configuration array structure. + * + * @return null + * + * @throws \Drupal\Core\Config\ConfigValueException + * If any key in $data in any depth contains a dot. + */ + protected function validateKeys(array $data) { + foreach ($data as $key => $value) { + if (strpos($key, '.') !== FALSE) { + throw new ConfigValueException(String::format('@key key contains a dot which is not supported.', array('@key' => $key))); + } + if (is_array($value)) { + $this->validateKeys($value); + } + } + } + + /** * Sets a value in this configuration object. * * @param string $key @@ -176,10 +202,16 @@ public function setData(array $data) { * * @return $this * The configuration object. + * + * @throws \Drupal\Core\Config\ConfigValueException + * If $value is an array and any of its keys in any depth contains a dot. */ public function set($key, $value) { // The dot/period is a reserved character; it may appear between keys, but // not within keys. + if (is_array($value)) { + $this->validateKeys($value); + } $parts = explode('.', $key); if (count($parts) == 1) { $this->data[$key] = $value; diff --git a/core/lib/Drupal/Core/Config/ConfigValueException.php b/core/lib/Drupal/Core/Config/ConfigValueException.php new file mode 100644 index 0000000..9802228 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigValueException.php @@ -0,0 +1,13 @@ +setDescription(t('The length of time between feed updates. Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status')))) ->setSetting('unsigned', TRUE) ->setRequired(TRUE) - ->setSetting('allowed_values', $period) + ->setSetting('allowed_values', ListItemBase::structureAllowedValues($period)) ->setDisplayOptions('form', array( 'type' => 'options_select', 'weight' => -2, diff --git a/core/modules/config/src/Tests/ConfigCRUDTest.php b/core/modules/config/src/Tests/ConfigCRUDTest.php index dc6de36..5358c06 100644 --- a/core/modules/config/src/Tests/ConfigCRUDTest.php +++ b/core/modules/config/src/Tests/ConfigCRUDTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigNameException; +use Drupal\Core\Config\ConfigValueException; use Drupal\Core\Config\InstallStorage; use Drupal\simpletest\DrupalUnitTestBase; use Drupal\Core\Config\FileStorage; @@ -190,6 +191,31 @@ function testNameValidation() { } /** + * Tests the validation of configuration object values. + */ + function testValueValidation() { + // Verify that setData() will catch dotted keys. + $message = 'Expected ConfigValueException was thrown from setData() for value with dotted keys.'; + try { + \Drupal::config('namespace.object')->setData(array('key.value' => 12))->save(); + $this->fail($message); + } + catch (ConfigValueException $e) { + $this->pass($message); + } + + // Verify that set() will catch dotted keys. + $message = 'Expected ConfigValueException was thrown from set() for value with dotted keys.'; + try { + \Drupal::config('namespace.object')->set('foo', array('key.value' => 12))->save(); + $this->fail($message); + } + catch (ConfigValueException $e) { + $this->pass($message); + } + } + + /** * Tests data type handling. */ public function testDataTypes() { diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index 255c19d..c4bbf47 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -358,7 +358,7 @@ function testFieldFormMultivalueWithRequiredRadio() { 'entity_type' => 'entity_test', 'type' => 'list_text', 'settings' => array( - 'allowed_values' => array('yes' => 'yes', 'no' => 'no'), + 'allowed_values' => array(array('value' => 'yes', 'label' => 'yes'), array('value' => 'no', 'label' => 'no')), ), ))->save(); $instance = array( diff --git a/core/modules/forum/config/install/field.field.taxonomy_term.forum_container.yml b/core/modules/forum/config/install/field.field.taxonomy_term.forum_container.yml index a666915..d9f5631 100644 --- a/core/modules/forum/config/install/field.field.taxonomy_term.forum_container.yml +++ b/core/modules/forum/config/install/field.field.taxonomy_term.forum_container.yml @@ -4,9 +4,7 @@ langcode: en name: forum_container type: list_boolean settings: - allowed_values: - - '' - - '' + allowed_values: { } allowed_values_function: '' module: options entity_type: taxonomy_term diff --git a/core/modules/migrate/src/Plugin/migrate/destination/Config.php b/core/modules/migrate/src/Plugin/migrate/destination/Config.php index f842259..a7b5de2 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/Config.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/Config.php @@ -70,7 +70,7 @@ public static function create(ContainerInterface $container, array $configuratio public function import(Row $row, array $old_destination_id_values = array()) { foreach ($row->getRawDestination() as $key => $value) { if (isset($value) || !empty($this->configuration['store null'])) { - $this->config->set($key, $value); + $this->config->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $key), $value); } } $this->config->save(); diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php index e788939..3205898 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php @@ -75,7 +75,7 @@ public function getIds() { */ protected function updateEntity(EntityInterface $entity, Row $row) { foreach ($row->getRawDestination() as $property => $value) { - $this->updateEntityProperty($entity, explode('.', $property), $value); + $this->updateEntityProperty($entity, explode(Row::PROPERTY_SEPARATOR, $property), $value); } } diff --git a/core/modules/migrate/src/Row.php b/core/modules/migrate/src/Row.php index 60cb02f..b96f1ac 100644 --- a/core/modules/migrate/src/Row.php +++ b/core/modules/migrate/src/Row.php @@ -37,6 +37,11 @@ class Row { protected $destination = array(); /** + * Level separator of destination and source properties. + */ + const PROPERTY_SEPARATOR = '/'; + + /** * The mapping between source and destination identifiers. * * @var array @@ -119,7 +124,7 @@ public function getSourceIdValues() { * TRUE if the source has property; FALSE otherwise. */ public function hasSourceProperty($property) { - return NestedArray::keyExists($this->source, explode('.', $property)); + return NestedArray::keyExists($this->source, explode(static::PROPERTY_SEPARATOR, $property)); } /** @@ -132,7 +137,7 @@ public function hasSourceProperty($property) { * The found returned property or NULL if not found. */ public function getSourceProperty($property) { - $return = NestedArray::getValue($this->source, explode('.', $property), $key_exists); + $return = NestedArray::getValue($this->source, explode(static::PROPERTY_SEPARATOR, $property), $key_exists); if ($key_exists) { return $return; } @@ -165,7 +170,7 @@ public function setSourceProperty($property, $data) { throw new \Exception("The source is frozen and can't be changed any more"); } else { - NestedArray::setValue($this->source, explode('.', $property), $data, TRUE); + NestedArray::setValue($this->source, explode(static::PROPERTY_SEPARATOR, $property), $data, TRUE); } } @@ -186,7 +191,7 @@ public function freezeSource() { * TRUE if the destination property exists. */ public function hasDestinationProperty($property) { - return NestedArray::keyExists($this->destination, explode('.', $property)); + return NestedArray::keyExists($this->destination, explode($this::PROPERTY_SEPARATOR, $property)); } /** @@ -199,7 +204,7 @@ public function hasDestinationProperty($property) { */ public function setDestinationProperty($property, $value) { $this->rawDestination[$property] = $value; - NestedArray::setValue($this->destination, explode('.', $property), $value, TRUE); + NestedArray::setValue($this->destination, explode($this::PROPERTY_SEPARATOR, $property), $value, TRUE); } /** @@ -215,10 +220,10 @@ public function getDestination() { /** * Returns the raw destination. Rarely necessary. * - * For example calling setDestination('foo:bar', 'baz') results in + * For example calling setDestination('foo/bar', 'baz') results in * @code * $this->destination['foo']['bar'] = 'baz'; - * $this->rawDestination['foo.bar'] = 'baz'; + * $this->rawDestination['foo/bar'] = 'baz'; * @encode * * @return array @@ -238,7 +243,7 @@ public function getRawDestination() { * The destination value. */ public function getDestinationProperty($property) { - return NestedArray::getValue($this->destination, explode('.', $property)); + return NestedArray::getValue($this->destination, explode($this::PROPERTY_SEPARATOR, $property)); } /** diff --git a/core/modules/migrate/tests/src/RowTest.php b/core/modules/migrate/tests/src/RowTest.php index c30375c..6ccfd6e 100644 --- a/core/modules/migrate/tests/src/RowTest.php +++ b/core/modules/migrate/tests/src/RowTest.php @@ -248,8 +248,8 @@ public function testDestination() { public function testMultipleDestination() { $row = new Row($this->testValues, $this->testSourceIds); // Set some deep nested values. - $row->setDestinationProperty('image.alt', 'alt text'); - $row->setDestinationProperty('image.fid', 3); + $row->setDestinationProperty('image/alt', 'alt text'); + $row->setDestinationProperty('image/fid', 3); $this->assertTrue($row->hasDestinationProperty('image')); $this->assertFalse($row->hasDestinationProperty('alt')); @@ -258,8 +258,8 @@ public function testMultipleDestination() { $destination = $row->getDestination(); $this->assertEquals('alt text', $destination['image']['alt']); $this->assertEquals(3, $destination['image']['fid']); - $this->assertEquals('alt text', $row->getDestinationProperty('image.alt')); - $this->assertEquals(3, $row->getDestinationProperty('image.fid')); + $this->assertEquals('alt text', $row->getDestinationProperty('image/alt')); + $this->assertEquals(3, $row->getDestinationProperty('image/fid')); } } diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_aggregator_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_aggregator_settings.yml index 25dd674..1f9c015 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_aggregator_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_aggregator_settings.yml @@ -14,10 +14,10 @@ process: fetcher: aggregator_fetcher parser: aggregator_parser processors: aggregator_processors - 'items.allowed_html': aggregator_allowed_html_tags - 'items.teaser_length': aggregator_teaser_length - 'items.expire': aggregator_clear - 'source.list_max': aggregator_summary_items + 'items/allowed_html': aggregator_allowed_html_tags + 'items/teaser_length': aggregator_teaser_length + 'items/expire': aggregator_clear + 'source/list_max': aggregator_summary_items destination: plugin: config config_name: aggregator.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml index 4fa9ea7..55448b8 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_block.yml @@ -54,8 +54,8 @@ process: - delta - settings - visibility - 'settings.visibility.request_path.pages': pages - 'settings.visibility.user_role.roles': roles + 'settings/visibility/request_path/pages': pages + 'settings/visibility/user_role/roles': roles destination: plugin: entity:block migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_book.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_book.yml index 03758d5..c67f957 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_book.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_book.yml @@ -4,9 +4,9 @@ source: plugin: d6_book process: nid: nid - book.bid: bid - book.weight: weight - book.pid: + 'book/bid': bid + 'book/weight': weight + 'book/pid': - plugin: skip_process_on_empty source: plid diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_book_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_book_settings.yml index 0da3a45..82405a1 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_book_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_book_settings.yml @@ -8,7 +8,7 @@ source: - book_allowed_types process: child_type: book_child_type - 'block.navigation.mode': book_block_mode + 'block/navigation/mode': book_block_mode allowed_types: book_allowed_types destination: plugin: config diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml index 34e681e..0ccec0f 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment.yml @@ -19,9 +19,9 @@ process: plugin: migration migration: d6_node source: nid - entity_type: constants.entity_type - field_name: constants.field_name - comment_type: constants.comment_type + entity_type: 'constants/entity_type' + field_name: 'constants/field_name' + comment_type: 'constants/comment_type' subject: subject uid: - @@ -38,8 +38,8 @@ process: changed: timestamp status: status #In D6, published=0. We reverse the value in prepareRow. thread: thread - 'comment_body.value': comment - 'comment_body.format': + 'comment_body/value': comment + 'comment_body/format': plugin: migration migration: d6_filter_format source: format diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_display.yml index a99f84e..f9c4743 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_display.yml @@ -11,10 +11,10 @@ source: type: comment_default weight: 20 process: - entity_type: constants.entity_type - field_name: constants.field_name - view_mode: constants.view_mode - options: constants.options + entity_type: 'constants/entity_type' + field_name: 'constants/field_name' + view_mode: 'constants/view_mode' + options: 'constants/options' bundle: node_type destination: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_form_display.yml index d82c812..a845b84 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_entity_form_display.yml @@ -10,10 +10,10 @@ source: type: comment_default weight: 20 process: - entity_type: constants.entity_type - field_name: constants.field_name - form_mode: constants.form_mode - options: constants.options + entity_type: 'constants/entity_type' + field_name: 'constants/field_name' + form_mode: 'constants/form_mode' + options: 'constants/options' bundle: node_type destination: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml index 2a5ccc4..175ac8c 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field.yml @@ -10,10 +10,10 @@ source: settings: content_type: comment process: - entity_type: constants.entity_type - id: constants.id - name: constants.name - type: constants.type - settings: constants.settings + entity_type: 'constants/entity_type' + id: 'constants/id' + name: 'constants/name' + type: 'constants/type' + settings: 'constants/settings' destination: plugin: entity:field_config diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml index c7631c2..6d9b14c 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_field_instance.yml @@ -8,19 +8,19 @@ source: label: Comment settings required: true process: - entity_type: constants.entity_type - field_name: constants.field_name - label: constants.label - required: constants.required + entity_type: 'constants/entity_type' + field_name: 'constants/field_name' + label: 'constants/label' + required: 'constants/required' bundle: node_type - 'default_value.0.status': comment - 'settings.default_mode': comment_default_mode - 'settings.per_page': comment_default_per_page - 'settings.anonymous': comment_anonymous - 'settings.subject': comment_subject_field - 'settings.form_location': comment_form_location - 'settings.preview': comment_preview + 'default_value/0/status': comment + 'settings/default_mode': comment_default_mode + 'settings/per_page': comment_default_per_page + 'settings/anonymous': comment_anonymous + 'settings/subject': comment_subject_field + 'settings/form_location': comment_form_location + 'settings/preview': comment_preview destination: plugin: entity:field_instance_config migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml index 6bd490b..26cef49 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml @@ -17,9 +17,9 @@ source: label: comment description: comment process: - target_entity_type_id: constants.entity_type - id: constants.id - label: constants.label - description: constants.description + target_entity_type_id: 'constants/entity_type' + id: 'constants/id' + label: 'constants/label' + description: 'constants/description' destination: plugin: entity:comment_type diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml index e45dde1..e77d096 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_contact_settings.yml @@ -7,7 +7,7 @@ source: - contact_hourly_threshold process: user_default_enabled: contact_default_status - 'flood.limit': contact_hourly_threshold + 'flood/limit': contact_hourly_threshold default_category: plugin: migration migration: d6_contact_category diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_custom_block.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_custom_block.yml index c7dd4ab..bbaa2fb 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_custom_block.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_custom_block.yml @@ -6,13 +6,13 @@ source: type: basic process: id: bid - type: constants.type + type: 'constants/type' info: info - 'body.format': + 'body/format': plugin: migration migration: d6_filter_format source: format - 'body.value': body + 'body/value': body destination: plugin: entity:block_content migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_date_formats.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_date_formats.yml index 734149b..f5564ef 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_date_formats.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_date_formats.yml @@ -14,6 +14,6 @@ process: date_format_long: long date_format_short: short date_format_medium: medium - 'pattern.php': value + pattern: value destination: plugin: entity:date_format diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml index 3e6edbf..b4aea5b 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field.yml @@ -6,9 +6,9 @@ source: entity_type: node langcode: und process: - entity_type: constants.entity_type + entity_type: 'constants/entity_type' status: active - langcode: constants.langcode + langcode: 'constants/langcode' name: field_name type: - diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml index 2d76591..a849f67 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_formatter_settings.yml @@ -21,7 +21,7 @@ process: - 1 - plugin: skip_row_on_empty - entity_type: constants.entity_type + entity_type: 'constants/entity_type' bundle: type_name view_mode: - @@ -34,15 +34,15 @@ process: index: - 1 field_name: field_name - "options.label": label - "options.weight": weight - "options.type": + "options/label": label + "options/weight": weight + "options/type": - plugin: static_map bypass: true source: - type - - "display_settings.format" + - 'display_settings/format' map: text: default: text_default @@ -164,13 +164,13 @@ process: default: string - plugin: field_type_defaults - "options.settings": + "options/settings": - plugin: static_map bypass: true source: - module - - "display_settings.format" + - 'display_settings/format' map: number: us_0: @@ -291,7 +291,7 @@ process: trim_length: 600 - plugin: field_formatter_settings_defaults - "options.third_party_settings": constants.third_party_settings + "options/third_party_settings": 'constants/third_party_settings' destination: plugin: component_entity_display diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance.yml index 74e3536..9c34a72 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance.yml @@ -20,7 +20,7 @@ process: - 1 - plugin: skip_row_on_empty - entity_type: constants.entity_type + entity_type: 'constants/entity_type' field_name: field_name bundle: type_name label: label diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml index 9f169e1..eebe967 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_field_instance_widget_settings.yml @@ -23,11 +23,11 @@ process: - plugin: skip_row_on_empty bundle: type_name - form_mode: constants.form_mode + form_mode: 'constants/form_mode' field_name: field_name - entity_type: constants.entity_type - "options.weight": weight - "options.type": + entity_type: 'constants/entity_type' + 'options/weight': weight + 'options/type': type: plugin: static_map bypass: true @@ -45,13 +45,13 @@ process: optionwidgets_onoff: options_onoff optionwidgets_buttons: options_buttons optionwidgets_select: options_select - "options.settings": + 'options/settings': - plugin: field_instance_widget_settings source: - widget_type - widget_settings - "options.third_party_settings": constants.third_party_settings + 'options/third_party_settings': 'constants/third_party_settings' destination: plugin: component_entity_form_display diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_file_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_file_settings.yml index 0b7522e..9c2fc14 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_file_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_file_settings.yml @@ -7,9 +7,9 @@ source: - file_description_length - file_icon_directory process: - 'description.type': file_description_type - 'description.length': file_description_length - 'icon.directory': file_icon_directory + 'description/type': file_description_type + 'description/length': file_description_length + 'icon/directory': file_icon_directory destination: plugin: config config_name: file.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_forum_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_forum_settings.yml index b46cca5..66697f3 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_forum_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_forum_settings.yml @@ -9,11 +9,11 @@ source: - forum_block_num_0 - forum_block_num_1 process: - 'block.active.limit': forum_block_num_0 - 'block.new.limit': forum_block_num_1 - 'topics.hot_threshold': forum_hot_topic - 'topics.page_limit': forum_per_page - 'topics.order': forum_order + 'block/active/limit': forum_block_num_0 + 'block/new/limit': forum_block_num_1 + 'topics/hot_threshold': forum_hot_topic + 'topics/page_limit': forum_per_page + 'topics/order': forum_order destination: plugin: config config_name: forum.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_locale_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_locale_settings.yml index de9063b..82d3e00 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_locale_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_locale_settings.yml @@ -7,7 +7,7 @@ source: - locale_js_directory process: cache_strings: locale_cache_strings - 'javascript.directory': locale_js_directory + 'javascript/directory': locale_js_directory destination: plugin: config config_name: locale.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node.yml index b74df84..ac9cd36 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node.yml @@ -14,11 +14,11 @@ process: changed: changed promote: promote sticky: sticky - body.format: + 'body/format': plugin: migration migration: d6_filter_format source: format - body.value: body + 'body/value': body # unmapped d6 fields. # tnid diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_revision.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_revision.yml index 537b255..5010ce9 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_revision.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_revision.yml @@ -14,11 +14,11 @@ process: changed: changed promote: promote sticky: sticky - body.format: + 'body/format': plugin: migration migration: d6_filter_format source: format - body.value: body + 'body/value': body # unmapped d6 fields. # tnid diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml index fe91810..0681135 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_node_type.yml @@ -12,7 +12,7 @@ process: description: description help: help title_label: title_label - preview: constants.preview + preview: 'constants/preview' submitted: submitted options: options create_body: has_body diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_page.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_page.yml index 87e1805..38977e8 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_page.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_page.yml @@ -14,10 +14,10 @@ source: path: node plugin: node_search process: - id: constants.id - path: constants.path - plugin: constants.plugin - configuration.rankings: + id: 'constants/id' + path: 'constants/path' + plugin: 'constants/plugin' + 'configuration/rankings': plugin: d6_search_configuration_rankings destination: plugin: entity:search_page diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_settings.yml index 00a886e..be1d9ea 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_search_settings.yml @@ -9,9 +9,9 @@ source: - search_tag_weights - search_and_or_limit process: - 'index.minimum_word_size': minimum_word_size - 'index.overlap_cjk': overlap_cjk - 'index.cron_limit': search_cron_limit + 'index/minimum_word_size': minimum_word_size + 'index/overlap_cjk': overlap_cjk + 'index/cron_limit': search_cron_limit destination: plugin: config config_name: search.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_simpletest_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_simpletest_settings.yml index 30b85d9..c6320ea 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_simpletest_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_simpletest_settings.yml @@ -10,9 +10,9 @@ source: - simpletest_verbose process: clear_results: simpletest_clear_results - 'httpauth.method': simpletest_httpauth_method - 'httpauth.password': simpletest_httpauth_password - 'httpauth.username': simpletest_httpauth_username + 'httpauth/method': simpletest_httpauth_method + 'httpauth/password': simpletest_httpauth_password + 'httpauth/username': simpletest_httpauth_username verbose: simpletest_verbose destination: plugin: config diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_statistics_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_statistics_settings.yml index 63dc976..73d1f0b 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_statistics_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_statistics_settings.yml @@ -10,12 +10,12 @@ source: - statistics_block_top_all_num - statistics_block_top_last_num process: - 'access_log.enabled': statistics_enable_access_log - 'access_log.max_lifetime': statistics_flush_accesslog_timer + 'access_log/enabled': statistics_enable_access_log + 'access_log/max_lifetime': statistics_flush_accesslog_timer 'count_content_views': statistics_count_content_views - 'block.popular.top_day_limit': statistics_block_top_day_num - 'block.popular.top_all_limit': statistics_block_top_all_num - 'block.popular.top_recent_limit': statistics_block_top_last_num + 'block/popular/top_day_limit': statistics_block_top_day_num + 'block/popular/top_all_limit': statistics_block_top_all_num + 'block/popular/top_recent_limit': statistics_block_top_last_num destination: plugin: config config_name: statistics.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_cron.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_cron.yml index 1807732..96d9d16 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_cron.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_cron.yml @@ -7,8 +7,8 @@ source: - cron_threshold_error - cron_last process: - 'threshold.warning': cron_threshold_warning - 'threshold.error': cron_threshold_error + 'threshold/warning': cron_threshold_warning + 'threshold/error': cron_threshold_error destination: plugin: config config_name: system.cron diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_file.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_file.yml index 3fdb86f..61777f9 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_file.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_file.yml @@ -6,8 +6,8 @@ source: - file_directory_path - file_directory_temp process: - 'path.private': file_directory_path - 'path.temporary': file_directory_temp + 'path/private': file_directory_path + 'path/temporary': file_directory_temp destination: plugin: config config_name: system.file diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_performance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_performance.yml index 25bf122..a7f94d0 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_performance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_performance.yml @@ -7,9 +7,9 @@ source: - preprocess_js - cache_lifetime process: - 'css.preprocess': preprocess_css - 'js.preprocess': preprocess_js - 'cache.page.max_age': cache_lifetime + 'css/preprocess': preprocess_css + 'js/preprocess': preprocess_js + 'cache/page/max_age': cache_lifetime destination: plugin: config config_name: system.performance diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_rss.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_rss.yml index 0325553..1209531 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_rss.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_rss.yml @@ -5,7 +5,7 @@ source: variables: - feed_default_items process: - 'items.limit': feed_default_items + 'items/limit': feed_default_items destination: plugin: config config_name: system.rss diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_site.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_site.yml index f3b5b08..59f6598 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_site.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_system_site.yml @@ -15,9 +15,9 @@ process: name: site_name mail: site_mail slogan: site_slogan - 'page.front': site_frontpage - 'page.403': site_403 - 'page.404': site_404 + 'page/front': site_frontpage + 'page/403': site_403 + 'page/404': site_404 weight_select_max: drupal_weight_select_max admin_compact_mode: admin_compact_mode destination: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_update_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_update_settings.yml index 924c166..e707aed 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_update_settings.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_update_settings.yml @@ -8,10 +8,10 @@ source: - update_notification_threshold - update_notify_emails process: - 'fetch.max_attempts': update_max_fetch_attempts - 'fetch.url': update_fetch_url - 'notification.threshold': update_notification_threshold - 'notification.emails': update_notify_emails + 'fetch/max_attempts': update_max_fetch_attempts + 'fetch/url': update_fetch_url + 'notification/threshold': update_notification_threshold + 'notification/emails': update_notify_emails destination: plugin: config config_name: update.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml index f915411..b29a1ca 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_display.yml @@ -11,13 +11,13 @@ source: label: hidden settings: {} process: - entity_type: constants.entity_type + entity_type: 'constants/entity_type' bundle: node_type - view_mode: constants.view_mode - field_name: constants.name - type: constants.type - options: constants.options - 'options.type': @type + view_mode: 'constants/view_mode' + field_name: 'constants/name' + type: 'constants/type' + options: 'constants/options' + 'options/type': @type destination: plugin: component_entity_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml index f6d8ef9..1a098ae 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_entity_form_display.yml @@ -13,13 +13,13 @@ source: settings: progress_indicator: throbber process: - entity_type: constants.entity_type + entity_type: 'constants/entity_type' bundle: node_type - field_name: constants.name - form_mode: constants.form_mode - type: constants.type - options: constants.options - 'options.type': @type + field_name: 'constants/name' + form_mode: 'constants/form_mode' + type: 'constants/type' + options: 'constants/options' + 'options/type': @type destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field.yml index 05cd8e2..f055f95 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field.yml @@ -12,10 +12,10 @@ source: cardinality: -1 display_field: true process: - entity_type: constants.entity_type - name: constants.name - type: constants.type - cardinality: constants.cardinality - settings.display_field: constants.display_field + entity_type: 'constants/entity_type' + name: 'constants/name' + type: 'constants/type' + cardinality: 'constants/cardinality' + 'settings/display_field': 'constants/display_field' destination: plugin: entity:field_config diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field_instance.yml index 8a85b40..5aa5179 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field_instance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload_field_instance.yml @@ -8,12 +8,12 @@ source: settings: description_field: 1 process: - entity_type: constants.entity_type + entity_type: 'constants/entity_type' bundle: node_type - field_name: constants.name - settings: constants.settings - 'settings.file_extensions': file_extensions - 'settings.max_filesize': max_filesize + field_name: 'constants/name' + settings: 'constants/settings' + 'settings/file_extensions': file_extensions + 'settings/max_filesize': max_filesize destination: plugin: entity:field_instance_config migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_mail.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_mail.yml index 9716bef..5f20f17 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_mail.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_mail.yml @@ -18,20 +18,20 @@ source: - user_mail_status_blocked_subject - user_mail_status_blocked_body process: - 'status_activated.subject': user_mail_status_activated_subject - 'status_activated.body': user_mail_status_activated_body - 'password_reset.subject': user_mail_password_reset_subject - 'password_reset.body': user_mail_password_reset_body - 'cancel_confirm.subject': user_mail_status_deleted_subject - 'cancel_confirm.body': user_mail_status_deleted_body - 'register_admin_created.subject': user_mail_register_admin_created_subject - 'register_admin_created.body': user_mail_register_admin_created_body - 'register_no_approval_required.subject': user_mail_register_no_approval_required_subject - 'register_no_approval_required.body': user_mail_register_no_approval_required_body - 'register_pending_approval.subject': user_mail_user_mail_register_pending_approval_subject - 'register_pending_approval.body': user_mail_user_mail_register_pending_approval_body - 'status_blocked.subject': user_mail_status_blocked_subject - 'status_blocked.body': user_mail_status_blocked_body + 'status_activated/subject': user_mail_status_activated_subject + 'status_activated/body': user_mail_status_activated_body + 'password_reset/subject': user_mail_password_reset_subject + 'password_reset/body': user_mail_password_reset_body + 'cancel_confirm/subject': user_mail_status_deleted_subject + 'cancel_confirm/body': user_mail_status_deleted_body + 'register_admin_created/subject': user_mail_register_admin_created_subject + 'register_admin_created/body': user_mail_register_admin_created_body + 'register_no_approval_required/subject': user_mail_register_no_approval_required_subject + 'register_no_approval_required/body': user_mail_register_no_approval_required_body + 'register_pending_approval/subject': user_mail_user_mail_register_pending_approval_subject + 'register_pending_approval/body': user_mail_user_mail_register_pending_approval_body + 'status_blocked/subject': user_mail_status_blocked_subject + 'status_blocked/body': user_mail_status_blocked_body destination: plugin: config config_name: user.mail diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml index ae74352..adfdd83 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_display.yml @@ -14,13 +14,13 @@ source: image_style: '' image_link: content process: - entity_type: constants.entity_type - bundle: constants.bundle - view_mode: constants.view_mode - field_name: constants.name - type: constants.type - options: constants.options - options.type: @type + entity_type: 'constants/entity_type' + bundle: 'constants/bundle' + view_mode: 'constants/view_mode' + field_name: 'constants/name' + type: 'constants/type' + options: 'constants/options' + 'options/type': @type destination: plugin: component_entity_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml index a91e2b4..39c2a81 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_entity_form_display.yml @@ -14,13 +14,13 @@ source: progress_indicator: throbber preview_image_style: thumbnail process: - entity_type: constants.entity_type - bundle: constants.bundle - field_name: constants.name - form_mode: constants.form_mode - type: constants.type - options: constants.options - options.type: @type + entity_type: 'constants/entity_type' + bundle: 'constants/bundle' + field_name: 'constants/name' + form_mode: 'constants/form_mode' + type: 'constants/type' + options: 'constants/options' + 'options/type': @type destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field.yml index ed53dd1..5a4a992 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field.yml @@ -10,9 +10,9 @@ source: name: user_picture cardinality: 1 process: - entity_type: constants.entity_type - name: constants.name - type: constants.type - cardinality: constants.cardinality + entity_type: 'constants/entity_type' + name: 'constants/name' + type: 'constants/type' + cardinality: 'constants/cardinality' destination: plugin: entity:field_config diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field_instance.yml index 22962bf..74b4838 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field_instance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_field_instance.yml @@ -14,13 +14,13 @@ source: alt_field_required: false title_field_required: false process: - entity_type: constants.entity_type - bundle: constants.bundle - field_name: constants.name - settings: constants.settings - 'settings.file_directory': file_directory - 'settings.max_filesize': max_filesize - 'settings.max_resolution': max_resolution + entity_type: 'constants/entity_type' + bundle: 'constants/bundle' + field_name: 'constants/name' + settings: 'constants/settings' + 'settings/file_directory': file_directory + 'settings/max_filesize': max_filesize + 'settings/max_resolution': max_resolution destination: plugin: entity:field_instance_config migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_file.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_file.yml index b97950b..21c53e1 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_file.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_picture_file.yml @@ -11,7 +11,7 @@ process: source: - picture - file_directory_path - - constants.is_public + - 'constants/is_public' destination: plugin: entity:file source_path_property: picture diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml index 0e026dc..57146a5 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_display.yml @@ -10,9 +10,9 @@ source: label: hidden settings: {} process: - entity_type: constants.entity_type - bundle: constants.bundle - view_mode: constants.view_mode + entity_type: 'constants/entity_type' + bundle: 'constants/bundle' + view_mode: 'constants/view_mode' field_name: name type: plugin: static_map @@ -25,8 +25,8 @@ process: textfield: text_default textarea: text_default url: link_default - options: constants.options - 'options.type': @type + options: 'constants/options' + 'options/type': @type hidden: plugin: static_map source: visibility diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml index 6dc6148..0ace57a 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_entity_form_display.yml @@ -10,10 +10,10 @@ source: options: label: hidden process: - entity_type: constants.entity_type - bundle: constants.bundle + entity_type: 'constants/entity_type' + bundle: 'constants/bundle' field_name: name - form_mode: constants.form_mode + form_mode: 'constants/form_mode' type: plugin: static_map source: type @@ -25,14 +25,14 @@ process: textfield: text_textfield textarea: text_textarea url: link_default - options: constants.options - 'options.type': @type - 'options.settings': + options: 'constants/options' + 'options/type': @type + 'options/settings': plugin: field_instance_widget_settings source: - @type - - constants.empty # we don't have any settings. - 'options.settings.display_label': # Single on/off checkboxes need to have display_label = true otherwise their label doesn't show. + - 'constants/empty' # we don't have any settings. + 'options/settings/display_label': # Single on/off checkboxes need to have display_label = true otherwise their label doesn't show. plugin: static_map default_value: false source: type diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml index 183a265..a075708 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field.yml @@ -5,7 +5,7 @@ source: constants: entity_type: user process: - entity_type: constants.entity_type + entity_type: 'constants/entity_type' name: name type: plugin: static_map diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field_instance.yml index 34a77ac..443d0ec 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field_instance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_user_profile_field_instance.yml @@ -6,8 +6,8 @@ source: entity_type: user bundle: user process: - entity_type: constants.entity_type - bundle: constants.bundle + entity_type: 'constants/entity_type' + bundle: 'constants/bundle' label: title description: explanation field_name: name diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_view_modes.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_view_modes.yml index 3bc9131..a2474c2 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_view_modes.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_view_modes.yml @@ -31,8 +31,8 @@ process: 5: "Print" teaser: "Teaser" full: "Full" - targetEntityType: constants.targetEntityType - status: constants.status + targetEntityType: 'constants/targetEntityType' + status: 'constants/status' destination: plugin: entity:view_mode diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_display.yml index a81af39..65d1fa0 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_display.yml @@ -11,9 +11,9 @@ source: weight: 20 process: - entity_type: constants.entity_type - view_mode: constants.view_mode - options: constants.options + entity_type: 'constants/entity_type' + view_mode: 'constants/view_mode' + options: 'constants/options' bundle: type field_name: plugin: migration diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_form_display.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_form_display.yml index 249b3b3..945f89d 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_form_display.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_entity_form_display.yml @@ -9,9 +9,9 @@ source: type: options_select weight: 20 process: - entity_type: constants.entity_type - form_mode: constants.form_mode - options: constants.options + entity_type: 'constants/entity_type' + form_mode: 'constants/form_mode' + options: 'constants/options' bundle: type field_name: plugin: migration diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml index 13d3bf6..93cacd9 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field.yml @@ -8,15 +8,15 @@ source: parent: 0 cardinality: -1 process: - entity_type: constants.entity_type - type: constants.type + entity_type: 'constants/entity_type' + type: 'constants/type' name: plugin: migration migration: d6_taxonomy_vocabulary source: vid - 'settings.allowed_values.0.vocabulary': @name - 'settings.allowed_values.0.parent': constants.parent - cardinality: constants.cardinality + 'settings/allowed_values/0/vocabulary': @name + 'settings/allowed_values/0/parent': 'constants/parent' + cardinality: 'constants/cardinality' destination: plugin: entity:field_config migration_dependencies: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field_instance.yml index c7fc497..6427f84 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field_instance.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_vocabulary_field_instance.yml @@ -6,7 +6,7 @@ source: entity_type: node parent: 0 process: - entity_type: constants.entity_type + entity_type: 'constants/entity_type' bundle: type field_name: plugin: migration diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php index be8788a..4e3e2d0 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/CckFieldValues.php @@ -148,15 +148,15 @@ public function prepareRow(Row $row) { foreach ($field_query->execute() as $field_row) { foreach ($field_info['columns'] as $display_name => $column_name) { list ( , $column) = explode(':', $display_name); - $propery_path = $field_name . '.' . $field_row['delta'] . '.' . $column; - $row->setSourceProperty($propery_path, $field_row[$column_name]); + $property_path = $field_name . Row::PROPERTY_SEPARATOR . $field_row['delta'] . Row::PROPERTY_SEPARATOR . $column; + $row->setSourceProperty($property_path, $field_row[$column_name]); } } } else { if ($field_row = $field_query->execute()->fetchAssoc()) { foreach ($field_info['columns'] as $display_name => $column_name) { - $row->setSourceProperty(str_replace(':', '.', $display_name), $field_row[$column_name]); + $row->setSourceProperty(str_replace(':', Row::PROPERTY_SEPARATOR, $display_name), $field_row[$column_name]); } } } diff --git a/core/modules/options/config/schema/options.schema.yml b/core/modules/options/config/schema/options.schema.yml index 8c90839..b81080e 100644 --- a/core/modules/options/config/schema/options.schema.yml +++ b/core/modules/options/config/schema/options.schema.yml @@ -8,8 +8,15 @@ field.list_integer.settings: type: sequence label: 'Allowed values list' sequence: - - type: string - label: 'Value' + - type: mapping + label: 'Allowed value with label' + mapping: + value: + type: integer + label: 'Value' + label: + type: label + label: 'Label' allowed_values_function: type: string label: 'Allowed values function' @@ -35,8 +42,18 @@ field.list_float.settings: label: 'List (float) settings' mapping: allowed_values: - type: ignore + type: sequence label: 'Allowed values list' + sequence: + - type: mapping + label: 'Allowed value with label' + mapping: + value: + type: float + label: 'Value' + label: + type: label + label: 'Label' allowed_values_function: type: string label: 'Allowed values function' @@ -65,8 +82,15 @@ field.list_text.settings: type: sequence label: 'Allowed values list' sequence: - - type: string - label: 'Value' + - type: mapping + label: 'Allowed value with label' + mapping: + value: + type: string + label: 'Value' + label: + type: label + label: 'Label' allowed_values_function: type: string label: 'Allowed values function' @@ -95,8 +119,15 @@ field.list_boolean.settings: type: sequence label: 'Allowed values list' sequence: - - type: string - label: 'Value' + - type: mapping + label: 'Allowed value with label' + mapping: + value: + type: boolean + label: 'Value' + label: + type: label + label: 'Label' allowed_values_function: type: string label: 'Allowed values function' diff --git a/core/modules/options/options.module b/core/modules/options/options.module index d9a1b24..d0b6c00 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -11,6 +11,7 @@ use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException; use Drupal\field\FieldConfigInterface; use Drupal\field\FieldConfigUpdateForbiddenException; +use Drupal\options\Plugin\Field\FieldType\ListItemBase; /** * Implements hook_help(). @@ -60,8 +61,9 @@ function options_field_config_delete(FieldConfigInterface $field) { * The entity object. * * @return - * The array of allowed values. Keys of the array are the raw stored values - * (number or text), values of the array are the display labels. + * The array of allowed values. Each array element is an associative + * array with 'value' and 'label' keys. The 'value' key stores the raw stored + * value (number or text), the 'label' key stores the display labels. */ function options_allowed_values(FieldDefinitionInterface $field_definition, EntityInterface $entity) { $allowed_values = &drupal_static(__FUNCTION__, array()); @@ -99,7 +101,11 @@ function options_field_config_update_forbid(FieldConfigInterface $field, FieldCo // Forbid any update that removes allowed values with actual data. $allowed_values = $field->getSetting('allowed_values'); $prior_allowed_values = $prior_field->getSetting('allowed_values'); - $lost_keys = array_diff(array_keys($prior_allowed_values), array_keys($allowed_values)); + $type_definition = \Drupal::typedDataManager()->getDefinition('field_item:' . $field->getType()); + $lost_keys = array_diff( + array_keys($type_definition['class']::simplifyAllowedValues($prior_allowed_values)), + array_keys($type_definition['class']::simplifyAllowedValues($allowed_values)) + ); if (_options_values_in_use($field->entity_type, $field->getName(), $lost_keys)) { throw new FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field->getName()))); } diff --git a/core/modules/options/src/Plugin/Field/FieldFormatter/OptionsDefaultFormatter.php b/core/modules/options/src/Plugin/Field/FieldFormatter/OptionsDefaultFormatter.php index 5c0b0d2..c7ee86d 100644 --- a/core/modules/options/src/Plugin/Field/FieldFormatter/OptionsDefaultFormatter.php +++ b/core/modules/options/src/Plugin/Field/FieldFormatter/OptionsDefaultFormatter.php @@ -7,8 +7,12 @@ namespace Drupal\options\Plugin\Field\FieldFormatter; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\TypedData\TypedDataManager; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'list_default' formatter. @@ -24,7 +28,48 @@ * } * ) */ -class OptionsDefaultFormatter extends FormatterBase { +class OptionsDefaultFormatter extends FormatterBase implements ContainerFactoryPluginInterface { + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('typed_data_manager') + ); + } + + /** + * Constructs a new OptionsDefaultFormatter. + * + * @param string $plugin_id + * The plugin_id for the formatter. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * The definition of the field to which the formatter is associated. + * @param array $settings + * The formatter settings. + * @param string $label + * The formatter label display setting. + * @param string $view_mode + * The view mode. + * @param array $third_party_settings + * Third party settings. + * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager + * The typed data manager. + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, TypedDataManager $typed_data_manager) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); + $this->typedDataManager = $typed_data_manager; + } /** * {@inheritdoc} @@ -33,7 +78,8 @@ public function viewElements(FieldItemListInterface $items) { $elements = array(); $entity = $items->getEntity(); - $allowed_values = options_allowed_values($this->fieldDefinition, $entity); + $type_definition = $this->typedDataManager->getDefinition('field_item:' . $this->fieldDefinition->getType()); + $allowed_values = $type_definition['class']::simplifyAllowedValues(options_allowed_values($this->fieldDefinition, $entity)); foreach ($items as $delta => $item) { if (isset($allowed_values[$item->value])) { diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListBooleanItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListBooleanItem.php index 5d16585..6446017 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListBooleanItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListBooleanItem.php @@ -27,6 +27,8 @@ */ class ListBooleanItem extends FieldItemBase implements AllowedValuesInterface { + use ListItemAllowedValuesTrait; + /** * {@inheritdoc} */ @@ -62,7 +64,7 @@ public function getSettableValues(AccountInterface $account = NULL) { * {@inheritdoc} */ public function getSettableOptions(AccountInterface $account = NULL) { - return options_allowed_values($this->getFieldDefinition(), $this->getEntity()); + return static::simplifyAllowedValues(options_allowed_values($this->getFieldDefinition(), $this->getEntity())); } /** @@ -107,8 +109,8 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { $allowed_values_function = $this->getSetting('allowed_values_function'); $values = $allowed_values; - $off_value = array_shift($values); - $on_value = array_shift($values); + $off_item = array_shift($values); + $on_item = array_shift($values); $element['allowed_values'] = array( '#type' => 'value', @@ -119,7 +121,7 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { $element['allowed_values']['on'] = array( '#type' => 'textfield', '#title' => t('On value'), - '#default_value' => $on_value, + '#default_value' => $on_item['label'], '#required' => FALSE, '#description' => t('If left empty, "1" will be used.'), // Change #parents to make sure the element is not saved into field @@ -129,7 +131,7 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { $element['allowed_values']['off'] = array( '#type' => 'textfield', '#title' => t('Off value'), - '#default_value' => $off_value, + '#default_value' => $off_item['label'], '#required' => FALSE, '#description' => t('If left empty, "0" will be used.'), // Change #parents to make sure the element is not saved into field @@ -160,7 +162,7 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { public static function optionsBooleanAllowedValues($element, $input, $form_state) { $on = NestedArray::getValue($form_state['input'], $element['#on_parents']); $off = NestedArray::getValue($form_state['input'], $element['#off_parents']); - return array($off, $on); + return array(array('value' => false, 'label' => $off), array('value' => true, 'label' => $on)); } } diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php index 30cd382..195e1c7 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php @@ -69,16 +69,13 @@ protected function allowedValuesDescription() { protected static function extractAllowedValues($string, $has_data) { $values = parent::extractAllowedValues($string, $has_data); if ($values) { - $keys = array_keys($values); - $labels = array_values($values); - $keys = array_map(function ($key) { + foreach ($values as $item) { // Float keys are represented as strings and need to be disambiguated // ('.5' is '0.5'). - return is_numeric($key) ? (string) (float) $key : $key; - }, $keys); - - return array_combine($keys, $labels); + $item['value'] = is_numeric($item['value']) ? (string) (float) $item['value'] : $item['value']; + } } + return $values; } /** @@ -90,4 +87,24 @@ protected static function validateAllowedValue($option) { } } + /** + * {@inheritdoc} + */ + public static function simplifyAllowedValues(array $structured_values) { + $values = array(); + foreach ($structured_values as $item) { + // Nested elements are embedded in the label. + // See ListItemBase::structureAllowedValues(). + if (is_array($item['label'])) { + $item['label'] = static::simplifyAllowedValues($item['label']); + } + // Cast the value to a float first so that .5 and 0.5 are the same value + // and then cast to a string so that values like 0.5 can be used as array + // keys. + // @see http://php.net/manual/en/language.types.array.php + $values[(string) (float) $item['value']] = $item['label']; + } + return $values; + } + } diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListItemAllowedValuesTrait.php b/core/modules/options/src/Plugin/Field/FieldType/ListItemAllowedValuesTrait.php new file mode 100644 index 0000000..d10e303 --- /dev/null +++ b/core/modules/options/src/Plugin/Field/FieldType/ListItemAllowedValuesTrait.php @@ -0,0 +1,64 @@ + $label) { + if (is_array($label)) { + $label = static::structureAllowedValues($label); + } + $structured_values[] = array( + 'value' => $value, + 'label' => $label, + ); + } + return $structured_values; + } + +} diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php index d61aef1..194b3f5 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php @@ -17,6 +17,8 @@ */ abstract class ListItemBase extends FieldItemBase implements AllowedValuesInterface { + use ListItemAllowedValuesTrait; + /** * {@inheritdoc} */ @@ -59,7 +61,7 @@ public function getSettableValues(AccountInterface $account = NULL) { */ public function getSettableOptions(AccountInterface $account = NULL) { $allowed_options = options_allowed_values($this->getFieldDefinition(), $this->getEntity()); - return $allowed_options; + return static::simplifyAllowedValues($allowed_options); } /** @@ -129,16 +131,25 @@ public static function validateAllowedValues($element, &$form_state) { } else { // Check that keys are valid for the field type. - foreach ($values as $key => $value) { - if ($error = static::validateAllowedValue($key)) { + $keys_in_use = array(); + foreach ($values as $item) { + if ($error = static::validateAllowedValue($item['value'])) { \Drupal::formBuilder()->setError($element, $form_state, $error); break; } + if (in_array($item['value'], $keys_in_use)) { + \Drupal::formBuilder()->setError($element, $form_state, t('One key can only be used once.')); + break; + } + $keys_in_use[] = $item['value']; } // Prevent removing values currently in use. if ($element['#field_has_data']) { - $lost_keys = array_diff(array_keys($element['#allowed_values']), array_keys($values)); + $lost_keys = array_diff( + array_keys(static::simplifyAllowedValues($element['#allowed_values'])), + array_keys(static::simplifyAllowedValues($values)) + ); if (_options_values_in_use($element['#entity_type'], $element['#field_name'], $lost_keys)) { \Drupal::formBuilder()->setError($element, $form_state, t('Allowed values list: some values are being removed while currently in use.')); } @@ -193,7 +204,7 @@ protected static function extractAllowedValues($string, $has_data) { return; } - $values[$key] = $value; + $values[] = array('value' => $key, 'label' => $value); } // We generate keys only if the list contains no explicit key at all. @@ -220,19 +231,19 @@ protected static function validateAllowedValue($option) { } * * This string format is suitable for edition in a textarea. * - * @param array $values - * An array of values, where array keys are values and array values are - * labels. + * @param array $structured_values + * An array of values, where elements are arrays with 'value' and 'label' + * keys. * * @return string * The string representation of the $values array: * - Values are separated by a carriage return. - * - Each value is in the format "value|label" or "value". + * - Each value is in the format "value|label". */ - protected function allowedValuesString($values) { + protected function allowedValuesString($structured_values) { $lines = array(); - foreach ($values as $key => $value) { - $lines[] = "$key|$value"; + foreach ($structured_values as $item) { + $lines[] = $item['value'] . '|' . $item['label']; } return implode("\n", $lines); } diff --git a/core/modules/options/src/Tests/OptionsFieldTest.php b/core/modules/options/src/Tests/OptionsFieldTest.php index ed775b4..aad59bf 100644 --- a/core/modules/options/src/Tests/OptionsFieldTest.php +++ b/core/modules/options/src/Tests/OptionsFieldTest.php @@ -45,7 +45,7 @@ function testUpdateAllowedValues() { $entity = entity_create('entity_test'); $entity->{$this->fieldName}->value = 1; $entity->save(); - $this->field->settings['allowed_values'] = array(2 => 'Two'); + $this->field->settings['allowed_values'] = array(array('value' => 2, 'label' => 'Two')); try { $this->field->save(); $this->fail(t('Cannot update a list field to not include keys with existing data.')); @@ -58,7 +58,7 @@ function testUpdateAllowedValues() { $entity->save(); // Removed options do not appear. - $this->field->settings['allowed_values'] = array(2 => 'Two'); + $this->field->settings['allowed_values'] = array(array('value' => 2, 'label' => 'Two')); $this->field->save(); $entity = entity_create('entity_test'); $form = \Drupal::service('entity.form_builder')->getForm($entity); @@ -67,7 +67,7 @@ function testUpdateAllowedValues() { $this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist'); // Completely new options appear. - $this->field->settings['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); + $this->field->settings['allowed_values'] = array(array('value' => 10, 'label' => 'Update'), array('value' => 20, 'label' => 'Twenty')); $this->field->save(); // The entity holds an outdated field object with the old allowed values // setting, so we need to reintialize the entity object. diff --git a/core/modules/options/src/Tests/OptionsFieldUITest.php b/core/modules/options/src/Tests/OptionsFieldUITest.php index baecfca..bf01335 100644 --- a/core/modules/options/src/Tests/OptionsFieldUITest.php +++ b/core/modules/options/src/Tests/OptionsFieldUITest.php @@ -60,15 +60,24 @@ function testOptionsAllowedValuesInteger() { // Flat list of textual values. $string = "Zero\nOne"; - $array = array('0' => 'Zero', '1' => 'One'); + $array = array( + array('value' => 0, 'label' => 'Zero'), + array('value' => 1, 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are accepted.'); // Explicit integer keys. $string = "0|Zero\n2|Two"; - $array = array('0' => 'Zero', '2' => 'Two'); + $array = array( + array('value' => 0, 'label' => 'Zero'), + array('value' => 2, 'label' => 'Two'), + ); $this->assertAllowedValuesInput($string, $array, 'Integer keys are accepted.'); // Check that values can be added and removed. $string = "0|Zero\n1|One"; - $array = array('0' => 'Zero', '1' => 'One'); + $array = array( + array('value' => 0, 'label' => 'Zero'), + array('value' => 1, 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Values can be added and removed.'); // Non-integer keys. $this->assertAllowedValuesInput("1.1|One", 'keys must be integers', 'Non integer keys are rejected.'); @@ -88,18 +97,31 @@ function testOptionsAllowedValuesInteger() { // Check that values can be added but values in use cannot be removed. $string = "0|Zero\n1|One\n2|Two"; - $array = array('0' => 'Zero', '1' => 'One', '2' => 'Two'); + $array = array( + array('value' => 0, 'label' => 'Zero'), + array('value' => 1, 'label' => 'One'), + array('value' => 2, 'label' => 'Two'), + ); $this->assertAllowedValuesInput($string, $array, 'Values can be added.'); $string = "0|Zero\n1|One"; - $array = array('0' => 'Zero', '1' => 'One'); + $array = array( + array('value' => 0, 'label' => 'Zero'), + array('value' => 1, 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); $this->assertAllowedValuesInput("0|Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.'); // Delete the node, remove the value. $node->delete(); $string = "0|Zero"; - $array = array('0' => 'Zero'); + $array = array( + array('value' => 0, 'label' => 'Zero'), + ); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); + + // Check that the same key can only be used once. + $string = "0|Zero\n0|One"; + $this->assertAllowedValuesInput($string, 'One key can only be used once.', 'Same value cannot be used multiple times.'); } /** @@ -111,15 +133,25 @@ function testOptionsAllowedValuesFloat() { // Flat list of textual values. $string = "Zero\nOne"; - $array = array('0' => 'Zero', '1' => 'One'); + $array = array( + array('value' => (float) 0, 'label' => 'Zero'), + array('value' => (float) 1, 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are accepted.'); // Explicit numeric keys. $string = "0|Zero\n.5|Point five"; - $array = array('0' => 'Zero', '0.5' => 'Point five'); + $array = array( + array('value' => (float) 0, 'label' => 'Zero'), + array('value' => (float) 0.5, 'label' => 'Point five'), + ); $this->assertAllowedValuesInput($string, $array, 'Integer keys are accepted.'); // Check that values can be added and removed. $string = "0|Zero\n.5|Point five\n1.0|One"; - $array = array('0' => 'Zero', '0.5' => 'Point five', '1' => 'One'); + $array = array( + array('value' => (float) 0, 'label' => 'Zero'), + array('value' => (float) 0.5, 'label' => 'Point five'), + array('value' => (float) 1, 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Values can be added and removed.'); // Non-numeric keys. $this->assertAllowedValuesInput("abc|abc\n", 'each key must be a valid integer or decimal', 'Non numeric keys are rejected.'); @@ -129,7 +161,7 @@ function testOptionsAllowedValuesFloat() { // Create a node with actual data for the field. $settings = array( 'type' => $this->type, - $this->field_name => array(array('value' => .5)), + $this->field_name => array(array('value' => (float) 0.5)), ); $node = $this->drupalCreateNode($settings); @@ -138,18 +170,35 @@ function testOptionsAllowedValuesFloat() { // Check that values can be added but values in use cannot be removed. $string = "0|Zero\n.5|Point five\n2|Two"; - $array = array('0' => 'Zero', '0.5' => 'Point five', '2' => 'Two'); + $array = array( + array('value' => (float) 0, 'label' => 'Zero'), + array('value' => (float) 0.5, 'label' => 'Point five'), + array('value' => (float) 2, 'label' => 'Two'), + ); $this->assertAllowedValuesInput($string, $array, 'Values can be added.'); $string = "0|Zero\n.5|Point five"; - $array = array('0' => 'Zero', '0.5' => 'Point five'); + $array = array( + array('value' => (float) 0, 'label' => 'Zero'), + array('value' => (float) 0.5, 'label' => 'Point five'), + ); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); $this->assertAllowedValuesInput("0|Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.'); // Delete the node, remove the value. $node->delete(); $string = "0|Zero"; - $array = array('0' => 'Zero'); + $array = array( + array('value' => (float) 0, 'label' => 'Zero'), + ); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); + + // Check that the same key can only be used once. + $string = "0.5|Point five\n0.5|Half"; + $this->assertAllowedValuesInput($string, 'One key can only be used once.', 'Same value cannot be used multiple times.'); + + // Check that different forms of the same float value cannot be used. + $string = "0|Zero\n.5|Point five\n0.5|Half"; + $this->assertAllowedValuesInput($string, 'One key can only be used once.', 'Different forms of the same value cannot be used.'); } /** @@ -161,19 +210,31 @@ function testOptionsAllowedValuesText() { // Flat list of textual values. $string = "Zero\nOne"; - $array = array('Zero' => 'Zero', 'One' => 'One'); + $array = array( + array('value' => 'Zero', 'label' => 'Zero'), + array('value' => 'One', 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are accepted.'); // Explicit keys. $string = "zero|Zero\none|One"; - $array = array('zero' => 'Zero', 'one' => 'One'); + $array = array( + array('value' => 'zero', 'label' => 'Zero'), + array('value' => 'one', 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Explicit keys are accepted.'); // Check that values can be added and removed. $string = "zero|Zero\ntwo|Two"; - $array = array('zero' => 'Zero', 'two' => 'Two'); + $array = array( + array('value' => 'zero', 'label' => 'Zero'), + array('value' => 'two', 'label' => 'Two'), + ); $this->assertAllowedValuesInput($string, $array, 'Values can be added and removed.'); // Mixed list of keyed and unkeyed values. $string = "zero|Zero\nOne\n"; - $array = array('zero' => 'Zero', 'One' => 'One'); + $array = array( + array('value' => 'zero', 'label' => 'Zero'), + array('value' => 'One', 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Mixed lists are accepted.'); // Overly long keys. $this->assertAllowedValuesInput("zero|Zero\n" . $this->randomName(256) . "|One", 'each key must be a string at most 255 characters long', 'Overly long keys are rejected.'); @@ -188,23 +249,48 @@ function testOptionsAllowedValuesText() { // Check that flat lists of values are still accepted once the field has // data. $string = "Zero\nOne"; - $array = array('Zero' => 'Zero', 'One' => 'One'); + $array = array( + array('value' => 'Zero', 'label' => 'Zero'), + array('value' => 'One', 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are still accepted once the field has data.'); // Check that values can be added but values in use cannot be removed. $string = "Zero\nOne\nTwo"; - $array = array('Zero' => 'Zero', 'One' => 'One', 'Two' => 'Two'); + $array = array( + array('value' => 'Zero', 'label' => 'Zero'), + array('value' => 'One', 'label' => 'One'), + array('value' => 'Two', 'label' => 'Two'), + ); $this->assertAllowedValuesInput($string, $array, 'Values can be added.'); $string = "Zero\nOne"; - $array = array('Zero' => 'Zero', 'One' => 'One'); + $array = array( + array('value' => 'Zero', 'label' => 'Zero'), + array('value' => 'One', 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); $this->assertAllowedValuesInput("Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.'); // Delete the node, remove the value. $node->delete(); $string = "Zero"; - $array = array('Zero' => 'Zero'); + $array = array( + array('value' => 'Zero', 'label' => 'Zero'), + ); $this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.'); + + // Check that string values with dots can be used. + $node->delete(); + $string = "Zero\nexample.com|Example"; + $array = array( + array('value' => 'Zero', 'label' => 'Zero'), + array('value' => 'example.com', 'label' => 'Example'), + ); + $this->assertAllowedValuesInput($string, $array, 'String value with dot is supported.'); + + // Check that the same key can only be used once. + $string = "Zero\nZero"; + $this->assertAllowedValuesInput($string, 'One key can only be used once.', 'Same value cannot be used multiple times.'); } /** @@ -217,7 +303,10 @@ function testOptionsAllowedValuesBoolean() { // Check that the separate 'On' and 'Off' form fields work. $on = $this->randomName(); $off = $this->randomName(); - $allowed_values = array(1 => $on, 0 => $off); + $allowed_values = array( + array('value' => false, 'label' => $off), + array('value' => true, 'label' => $on), + ); $edit = array( 'on' => $on, 'off' => $off, @@ -244,8 +333,15 @@ function testOptionsTrimmedValuesText() { // Explicit keys. $string = "zero |Zero\none | One"; - $array = array('zero' => 'Zero', 'one' => 'One'); + $array = array( + array('value' => 'zero', 'label' => 'Zero'), + array('value' => 'one', 'label' => 'One'), + ); $this->assertAllowedValuesInput($string, $array, 'Explicit keys are accepted and trimmed.'); + + // Check that the same key can only be used once. + $string = " Zero \n Zero "; + $this->assertAllowedValuesInput($string, 'One key can only be used once.', 'Same value cannot be used multiple times.'); } /** diff --git a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php index 272e026..2c97d2e 100644 --- a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php +++ b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php @@ -63,7 +63,11 @@ public function setUp() { 'type' => 'list_integer', 'cardinality' => 1, 'settings' => array( - 'allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'), + 'allowed_values' => array( + array('value' => 1, 'label' => 'One'), + array('value' => 2, 'label' => 'Two'), + array('value' => 3, 'label' => 'Three') + ), ), ); $this->field = entity_create('field_config', $this->fieldDefinition); diff --git a/core/modules/options/src/Tests/OptionsWidgetsTest.php b/core/modules/options/src/Tests/OptionsWidgetsTest.php index bcec12c..05bc1e5 100644 --- a/core/modules/options/src/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/src/Tests/OptionsWidgetsTest.php @@ -70,12 +70,12 @@ function setUp() { 'settings' => array( 'allowed_values' => array( // Make sure that 0 works as an option. - 0 => 'Zero', - 1 => 'One', + array('value' => 0, 'label' => 'Zero'), + array('value' => 1, 'label' => 'One'), // Make sure that option text is properly sanitized. - 2 => 'Some & unescaped markup', + array('value' => 2, 'label' => 'Some & unescaped markup'), // Make sure that HTML entities in option text are not double-encoded. - 3 => 'Some HTML encoded markup with < & >', + array('value' => 3, 'label' => 'Some HTML encoded markup with < & >'), ), ), )); @@ -90,10 +90,10 @@ function setUp() { 'settings' => array( 'allowed_values' => array( // Make sure that 0 works as an option. - 0 => 'Zero', - 1 => 'One', + array('value' => 0, 'label' => 'Zero'), + array('value' => 1, 'label' => 'One'), // Make sure that option text is properly sanitized. - 2 => 'Some & unescaped markup', + array('value' => 2, 'label' => 'Some & unescaped markup'), ), ), )); @@ -108,9 +108,9 @@ function setUp() { 'settings' => array( 'allowed_values' => array( // Make sure that 0 works as an option. - 0 => 'Zero', + array('value' => 0, 'label' => 'Zero'), // Make sure that option text is properly sanitized. - 1 => 'Some & unescaped markup', + array('value' => 1, 'label' => 'Some & unescaped markup'), ), ), )); @@ -170,7 +170,7 @@ function testRadioButtons() { $this->assertFieldValues($entity_init, 'card_1', array()); // Check that required radios with one option is auto-selected. - $this->card_1->settings['allowed_values'] = array(99 => 'Only allowed value'); + $this->card_1->settings['allowed_values'] = array(array('value' => 99, 'label' => 'Only allowed value')); $this->card_1->save(); $instance->required = TRUE; $instance->save(); @@ -259,7 +259,7 @@ function testCheckBoxes() { $this->assertFieldValues($entity_init, 'card_2', array()); // Required checkbox with one option is auto-selected. - $this->card_2->settings['allowed_values'] = array(99 => 'Only allowed value'); + $this->card_2->settings['allowed_values'] = array(array('value' => 99, 'label' => 'Only allowed value')); $this->card_2->save(); $instance->required = TRUE; $instance->save(); diff --git a/core/modules/options/tests/options_test.module b/core/modules/options/tests/options_test.module index 1416fa0..ba56132 100644 --- a/core/modules/options/tests/options_test.module +++ b/core/modules/options/tests/options_test.module @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\options\Plugin\Field\FieldType\ListItemBase; /** * Allowed values callback. @@ -22,7 +23,7 @@ function options_test_allowed_values_callback(FieldDefinitionInterface $field_de ), ); - return $values; + return ListItemBase::structureAllowedValues($values); } /** @@ -37,5 +38,5 @@ function options_test_dynamic_values_callback(FieldDefinitionInterface $field_de $entity->bundle(), ); // We need the values of the entity as keys. - return array_combine($values, $values); + return ListItemBase::structureAllowedValues(array_combine($values, $values)); }