diff --git a/core/lib/Drupal/Core/Config/Entity/EntityBundleWithPluralLabelsTrait.php b/core/lib/Drupal/Core/Config/Entity/EntityBundleWithPluralLabelsTrait.php index 4f2e1d93bd..4a5a242352 100644 --- a/core/lib/Drupal/Core/Config/Entity/EntityBundleWithPluralLabelsTrait.php +++ b/core/lib/Drupal/Core/Config/Entity/EntityBundleWithPluralLabelsTrait.php @@ -31,25 +31,31 @@ * * Unlimited definite singular/plural count labels can be defined in order to * cover various contexts where they are used. The array keys are strings, - * identifying the context. For example, a site may need two versions of count - * labels "@count items" and "Items (@count)". In this case the value of this - * property is: + * identifying the context. For example, a site might need two or more + * versions of the count labels: + * - singular '1 item', plural '@count items', + * - singular '1 item was found', plural '@count items were found'. + * For this case the value of this property is: * @code * [ - * 'default' => '1 item\x03@count items', - * 'with_count_in_parenthesis' => 'Item (1)\x03Items (@count)', + * 'default' => "1 item\x03@count items", + * 'items_found' => "1 item was found\x03@count items were found", * ] * @endcode - * If there's only one context, then the key can be omitted: + * Note that the context ('default', 'items_found') is an arbitrary string + * identifier used to retrieve the desired version. If there's only one + * context, the context identifier can be omitted: * @code * [ - * '1 item\x03@count items', + * "1 item\x03@count items", * ] - * @endcode * in the same way they + * @endcode * Each value is definite singular/plural count label with the plural variants * separated by ETX (PluralTranslatableMarkup::DELIMITER). * * @var string[]|null + * + * @see \Drupal\Core\StringTranslation\PluralTranslatableMarkup::DELIMITER */ protected $label_count; diff --git a/core/modules/node/tests/src/Unit/NodeTypePluralLabelTest.php b/core/modules/node/tests/src/Unit/NodeTypePluralLabelTest.php index 0ca811fede..ef8ed7b9b1 100644 --- a/core/modules/node/tests/src/Unit/NodeTypePluralLabelTest.php +++ b/core/modules/node/tests/src/Unit/NodeTypePluralLabelTest.php @@ -85,7 +85,7 @@ public function providerForTestGetSingularAndPLuralLabel() { * @covers ::getCountLabel * @dataProvider providerForTestGetCountLabel * - * @param string[]|null $count_labels + * @param array[]|null $count_labels * The count label array. * @param string|null $entity_label * The entity label. @@ -94,8 +94,8 @@ public function providerForTestGetSingularAndPLuralLabel() { * @param string|null $plural_label * The plural label. * @param array $expectation - * An associative array keyed where each value is the expected result given - * a count integer which is the item key. + * An array of associative arrays where each value is the expected result + * given a count integer which is the item key. */ public function testGetCountLabel(array $count_labels = NULL, $entity_label, $singular_label, $plural_label, array $expectation) { $count_labels = $count_labels ?: [NULL]; @@ -194,6 +194,7 @@ public function providerForTestGetCountLabel() { 'contextualized count labels' => [ [ 'default' => "1 blue eye\x3@count blue eyes", + 'items found' => "1 blue eye was found\x3@count blue eyes were found", 'no count' => "blue eye\x3" . 'blue eyes', 'with markup' => "1 blue eye\x3@count blue eyes", 'with parenthesis' => "blue eye\x3" . 'blue eyes (@count)', @@ -203,6 +204,7 @@ public function providerForTestGetCountLabel() { NULL, [ 'default' => [1 => '1 blue eye', 2 => '2 blue eyes'], + 'items found' => [1 => '1 blue eye was found', 2 => '2 blue eyes were found'], 'no count' => [1 => 'blue eye', 2 => 'blue eyes'], 'with markup' => [1 => '1 blue eye', 2 => '2 blue eyes'], 'with parenthesis' => [1 => 'blue eye', 2 => 'blue eyes (2)'], diff --git a/core/profiles/demo_umami/config/install/node.type.article.yml b/core/profiles/demo_umami/config/install/node.type.article.yml index 1fd439ce71..13de4e6d33 100644 --- a/core/profiles/demo_umami/config/install/node.type.article.yml +++ b/core/profiles/demo_umami/config/install/node.type.article.yml @@ -8,3 +8,7 @@ help: '' new_revision: true preview_mode: 1 display_submitted: true +label_singular: article +label_plural: articles +label_count: + - "1 article\x03@count articles" diff --git a/core/profiles/demo_umami/config/install/node.type.page.yml b/core/profiles/demo_umami/config/install/node.type.page.yml index 57dcc0c992..01dd16a83d 100644 --- a/core/profiles/demo_umami/config/install/node.type.page.yml +++ b/core/profiles/demo_umami/config/install/node.type.page.yml @@ -8,3 +8,7 @@ help: '' new_revision: true preview_mode: 1 display_submitted: false +label_singular: page +label_plural: pages +label_count: + - "1 page\x03@count pages" diff --git a/core/profiles/demo_umami/config/install/node.type.recipe.yml b/core/profiles/demo_umami/config/install/node.type.recipe.yml index 89ed3215c7..6076968d0c 100644 --- a/core/profiles/demo_umami/config/install/node.type.recipe.yml +++ b/core/profiles/demo_umami/config/install/node.type.recipe.yml @@ -14,3 +14,7 @@ help: '' new_revision: true preview_mode: 1 display_submitted: false +label_singular: recipe +label_plural: recipes +label_count: + - "1 recipe\x03@count recipes"