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 c30a9d2..442d6de 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php @@ -77,9 +77,7 @@ public function viewElements(FieldItemListInterface $items) { if ($this->getSetting('prefix_suffix')) { $prefixes = isset($settings['prefix']) ? array_map(array($this, 'fieldFilterXss'), explode('|', $settings['prefix'])) : array(''); $suffixes = isset($settings['suffix']) ? array_map(array($this, 'fieldFilterXss'), 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]; - $output = $prefix . $output . $suffix; + $output = $prefixes[0] . $output . $suffixes[0]; } // Output the raw value in a content attribute if the text of the HTML // element differs from the raw value (for example when a prefix is used). 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 50f8006..d2ab50c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php @@ -101,11 +101,18 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Add prefix and suffix. if ($field_settings['prefix']) { $prefixes = explode('|', $field_settings['prefix']); - $element['#field_prefix'] = $this->fieldFilterXss(array_pop($prefixes)); + $element['#field_prefix'] = $this->fieldFilterXss(array_shift($prefixes)); } if ($field_settings['suffix']) { $suffixes = explode('|', $field_settings['suffix']); - $element['#field_suffix'] = $this->fieldFilterXss(array_pop($suffixes)); + $element['#field_suffix'] = $this->fieldFilterXss(array_shift($suffixes)); + } + + // @TODO: Remove this warning once we have decent support for plural + // formatting of the prefix/suffix field. + // @see https://www.drupal.org/node/2449597 + if (strstr($field_settings['prefix'], '|') || strstr($field_settings['suffix'], '|')) { + drupal_set_message($this->t('The prefix and/or suffix setting of the field "@title" contain a pipe symbol. Everything after the pipe, including the pipe itself, will be ignored.', ['@title' => $element['#title']]), 'warning'); } return array('value' => $element);