diff -u b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php --- b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php @@ -43,8 +43,8 @@ $length = max(count($prefixes), count($suffixes)); $strings = []; for ($i = 0; $i < $length; $i++) { - $prefix = isset($prefixes[$i]) ?: $prefixes[count($prefixes) - 1]; - $suffix = isset($suffixes[$i]) ?: $suffixes[count($suffixes) - 1]; + $prefix = isset($prefixes[$i]) ? $prefixes[$i] : $prefixes[count($prefixes) - 1]; + $suffix = isset($suffixes[$i]) ? $suffixes[$i] : $suffixes[count($suffixes) - 1]; $strings[] = $prefix . '@count' . $suffix; } $settings['format_plural_string'] = implode(PluralTranslatableMarkup::DELIMITER, $strings); diff -u b/core/modules/field/src/Tests/Number/NumberFieldTest.php b/core/modules/field/src/Tests/Number/NumberFieldTest.php --- b/core/modules/field/src/Tests/Number/NumberFieldTest.php +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php @@ -157,7 +157,7 @@ 'type' => 'number', 'settings' => array( 'placeholder' => '4', - 'plural_format' => TRUE, + 'format_plural' => TRUE, ), )) ->save(); @@ -198,7 +198,7 @@ 'type' => 'number', 'settings' => array( 'placeholder' => '7', - 'plural_format' => FALSE, + 'format_plural' => FALSE, ), )) ->save(); diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1889,8 +1889,8 @@ $length = max(count($prefixes), count($suffixes)); $strings = []; for ($i = 0; $i < $length; $i++) { - $prefix = isset($prefixes[$i]) ?: $prefixes[count($prefixes) - 1]; - $suffix = isset($suffixes[$i]) ?: $suffixes[count($suffixes) - 1]; + $prefix = isset($prefixes[$i]) ? $prefixes[$i] : $prefixes[count($prefixes) - 1]; + $suffix = isset($suffixes[$i]) ? $suffixes[$i] : $suffixes[count($suffixes) - 1]; $strings[] = $prefix . '@count' . $suffix; } $settings['format_plural_string'] = implode(PluralTranslatableMarkup::DELIMITER, $strings); only in patch2: unchanged: --- /dev/null +++ b/core/modules/field_ui/src/Tests/NumericFieldsUiTest.php @@ -0,0 +1,113 @@ +drupalPlaceBlock('system_breadcrumb_block'); + $this->drupalPlaceBlock('local_actions_block'); + $this->drupalPlaceBlock('local_tasks_block'); + $this->drupalPlaceBlock('page_title_block'); + + // Create a test user. + $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access')); + $this->drupalLogin($admin_user); + + $this->fieldName = 'my_int_test'; + + // Create Article node type. + $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); + + } + + /** + * Tests the UI for numeric fields and formatters. + */ + public function testNumericFieldUI() { + // Add an integer field using the UI with plural prefix/suffix forms. + $this->fieldUIAddNewField('admin/structure/types/manage/article', + $this->fieldName, NULL, 'integer', [], + ['settings[format_plural_values][0]' => 'SingularPrefix@countSingularSuffix', 'settings[format_plural_values][1]' => 'PluralPrefix@countPluralSuffix']); + + // Set the display to use the plural formatting from field settings. + $this->drupalGet('admin/structure/types/manage/article/display'); + $settings_button = 'field_' . $this->fieldName . '_settings_edit'; + $this->drupalPostAjaxForm(NULL, array(), $settings_button); + $formatter_settings_prefix = 'fields[' . $this->fieldName . '][settings_edit_form][settings]'; + $edit = [$formatter_settings_prefix . '[format_plural]' => 'field']; + $this->drupalPostForm(NULL, array(), t('Save')); + + // Create a node with field value 1. + $this->drupalGet('node/add/article'); + // While doing that, verify that on the editing form, the plural form + // prefix/suffix are shown. We don't need to test all the variations here, + // since \Drupal\field\Tests\Number\NumberFieldTest verifies that if you + // turn the setting for prefix display on/off on the widget, the + // prefix/suffix are/are not shown. + $this->assertText('PluralPrefix'); + $this->assertText('PluralSuffix'); + $this->drupalPostForm(NULL, ['title' => 'foobar', $this->fieldName => 1], t('Save and publish')); + + // We should be on the node page. Verify that the singular + // prefix/suffix are shown. + $this->assertText('SingularPrefix1SingularSuffix'); + + // Change the setting on the formatter to override the prefix/suffix. + $this->drupalGet('admin/structure/types/manage/article/display'); + $this->drupalPostAjaxForm(NULL, array(), $settings_button); + $edit = array( + $formatter_settings_prefix . '[format_plural]' => 'formatter', + $formatter_settings_prefix . '[format_plural_values][0]' => 'OverrideSingularP@count@OverrideSingularS', + $formatter_settings_prefix . '[format_plural_values][1]' => 'OverridePluralP@count@OverridePluralS', + ); + $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh'))); + $this->drupalPostForm(NULL, t('Save')); + + // Create another node, this time with a plural value, and verify the + // formatting. + $this->drupalGet('node/add/article'); + $this->drupalPostForm(NULL, ['title' => 'barbaz', $this->fieldName => 2], t('Save and publish')); + $this->assertText('OverridePluralP2OverridePluralS'); + + } + +}