diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php
index 883db1b..da3cd77 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php
@@ -8,6 +8,7 @@
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\AllowedTagsXssTrait;
+use Drupal\Core\Field\FieldFilteredString;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
@@ -75,10 +76,8 @@ public function viewElements(FieldItemListInterface $items) {
// Account for prefix and suffix.
if ($this->getSetting('prefix_suffix')) {
- $prefixes = isset($settings['prefix']) ? array_map(array('Drupal\Core\Field\FieldFilteredString', 'create'), explode('|', $settings['prefix'])) : array('');
- $suffixes = isset($settings['suffix']) ? array_map(array('Drupal\Core\Field\FieldFilteredString', 'create'), explode('|', $settings['suffix'])) : array('');
- $prefix = (count($prefixes) > 1) ? $this->formatPlural($item->value, $prefixes[0], $prefixes[1]) : $prefixes[0];
- $suffix = (count($suffixes) > 1) ? $this->formatPlural($item->value, $suffixes[0], $suffixes[1]) : $suffixes[0];
+ $prefix = isset($settings['prefix']) ? FieldFilteredString::create($settings['prefix']) : '';
+ $suffix = isset($settings['suffix']) ? FieldFilteredString::create($settings['suffix']) : '';
$output = $prefix . $output . $suffix;
}
// Output the raw value in a content attribute if the text of the HTML
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php
index 9f9bd0b..377f88f 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php
@@ -51,14 +51,14 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
'#title' => t('Prefix'),
'#default_value' => $settings['prefix'],
'#size' => 60,
- '#description' => t("Define a string that should be prefixed to the value, like '$ ' or '€ '. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."),
+ '#description' => t("Define a string that should be prefixed to the value, like '$ ' or '€ '. Leave blank for none."),
);
$element['suffix'] = array(
'#type' => 'textfield',
'#title' => t('Suffix'),
'#default_value' => $settings['suffix'],
'#size' => 60,
- '#description' => t("Define a string that should be suffixed to the value, like ' m', ' kb/s'. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."),
+ '#description' => t("Define a string that should be suffixed to the value, like ' m', ' kb/s'. Leave blank for none."),
);
return $element;
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php
index 86c17b6..cad5fa4 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php
@@ -101,12 +101,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
// Add prefix and suffix.
if ($field_settings['prefix']) {
- $prefixes = explode('|', $field_settings['prefix']);
- $element['#field_prefix'] = FieldFilteredString::create(array_pop($prefixes));
+ $element['#field_prefix'] = FieldFilteredString::create($field_settings['prefix']);
}
if ($field_settings['suffix']) {
- $suffixes = explode('|', $field_settings['suffix']);
- $element['#field_suffix'] = FieldFilteredString::create(array_pop($suffixes));
+ $element['#field_suffix'] = FieldFilteredString::create($field_settings['suffix']);
}
return array('value' => $element);
diff --git a/core/modules/field/field.install b/core/modules/field/field.install
new file mode 100644
index 0000000..1d18b4b
--- /dev/null
+++ b/core/modules/field/field.install
@@ -0,0 +1,65 @@
+listAll('field.field.');
+ foreach ($list as $field_config_name) {
+ $field = $config_factory->getEditable($field_config_name);
+ if($field_settings = $field->get('settings')) {
+ if(isset($field_settings['prefix']) && strstr($field_settings['prefix'], '|')) {
+ $prefixes = explode('|', $field_settings['prefix']);
+ $field_settings['prefix'] = array_pop($prefixes);
+ $field->set('settings', $field_settings);
+ $field->save();
+ $adjusted_prefix[] = $field->getName();
+ }
+ if(isset($field_settings['suffix']) && strstr($field_settings['suffix'], '|')) {
+ $suffixes = explode('|', $field_settings['suffix']);
+ $field_settings['suffix'] = array_pop($suffixes);
+ $field->set('settings', $field_settings);
+ $field->save();
+ $adjusted_suffix[] = $field->getName();
+ }
+ }
+ }
+
+ // Give the user the name of the prefix/suffix fields that where adjusted.
+ if (!empty($adjusted_prefix) || !empty($adjusted_suffix)) {
+ $args = [
+ '@prefixes' => implode(', ', $adjusted_prefix) ?: 'none',
+ '@suffixes' => implode(', ', $adjusted_suffix) ?: 'none',
+ ];
+ $msg = 'Some of your prefix/suffix fields configured pipe symbols to format singular/plural form. This is no longer supported, so the fields were adjusted. See the change record https://www.drupal.org/node/2552871 for more information.';
+ $msg .= '
Prefix fields adjusted: @prefixes';
+ $msg .= '
Suffix fields adjusted: @suffixes';
+ $message = \Drupal::translation()->translate($msg, $args);
+ return $message;
+ }
+
+}
+
+/**
+ * @} End of "addtogroup updates-8.0.0-beta".
+ */
diff --git a/core/modules/field/src/Tests/Update/FieldConfigUpdateTest.php b/core/modules/field/src/Tests/Update/FieldConfigUpdateTest.php
new file mode 100644
index 0000000..d872410
--- /dev/null
+++ b/core/modules/field/src/Tests/Update/FieldConfigUpdateTest.php
@@ -0,0 +1,49 @@
+databaseDumpFiles = [
+ __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
+ __DIR__ . '/../../../../system/tests/fixtures/update/2545730/drupal-8.field-field-config-data.php',
+ ];
+
+ parent::setUp();
+ }
+
+ /**
+ * Tests that field configurations are updated properly.
+ */
+ public function testUpdateHookN() {
+ $active = $this->container->get('config.storage');
+ $field = $active->read('field.field.node.article.field_decimal_test');
+ $this->assertEqual($field['settings']['prefix'], 'p-singular|prefix-plural', 'Prefix field was found as expected.');
+ $this->assertEqual($field['settings']['suffix'], 's-singular|suffix-plural', 'Suffix field was found as expected.');
+
+ $this->runUpdates();
+
+ $field = $active->read('field.field.node.article.field_decimal_test');
+ $this->assertEqual($field['settings']['prefix'], 'prefix-plural', 'Prefix field was updated correctly.');
+ $this->assertEqual($field['settings']['suffix'], 'suffix-plural', 'Suffix field was updated correctly.');
+ }
+
+}
diff --git a/core/modules/system/tests/fixtures/update/2545730/drupal-8.field-field-config-data.php b/core/modules/system/tests/fixtures/update/2545730/drupal-8.field-field-config-data.php
new file mode 100644
index 0000000..46e9d54
--- /dev/null
+++ b/core/modules/system/tests/fixtures/update/2545730/drupal-8.field-field-config-data.php
@@ -0,0 +1,30 @@
+insert('config')
+ ->fields(array(
+ 'collection',
+ 'name',
+ 'data',
+ ))
+ ->values(array(
+ 'collection' => '',
+ 'name' => 'field.field.' . $fields_config['id'],
+ 'data' => serialize($fields_config),
+ ))
+ ->execute();
+}
diff --git a/core/modules/system/tests/fixtures/update/2545730/field.field.2545730.yml b/core/modules/system/tests/fixtures/update/2545730/field.field.2545730.yml
new file mode 100644
index 0000000..fd628d5
--- /dev/null
+++ b/core/modules/system/tests/fixtures/update/2545730/field.field.2545730.yml
@@ -0,0 +1,23 @@
+uuid: 12cee519-c921-43f1-a400-c5b046ff56b4
+langcode: en
+status: true
+dependencies:
+ config:
+ - field.storage.node.field_decimal_test
+ - node.type.article
+id: node.article.field_decimal_test
+field_name: field_decimal_test
+entity_type: node
+bundle: article
+label: Decimal test
+description: ''
+required: false
+translatable: false
+default_value: { }
+default_value_callback: ''
+settings:
+ min: null
+ max: null
+ prefix: p-singular|prefix-plural
+ suffix: s-singular|suffix-plural
+field_type: decimal