Skip to content
Snippets Groups Projects
Commit 5002f8f7 authored by catch's avatar catch
Browse files

Issue #3109795 by alexpott, Berdir: Entity plural label context is not set as expected

parent bffe9888
No related branches found
No related tags found
No related merge requests found
...@@ -776,8 +776,11 @@ public function getCountLabel($count) { ...@@ -776,8 +776,11 @@ public function getCountLabel($count) {
if (empty($this->label_count)) { if (empty($this->label_count)) {
return $this->formatPlural($count, '@count @label', '@count @label entities', ['@label' => $this->getSingularLabel()], ['context' => 'Entity type label']); return $this->formatPlural($count, '@count @label', '@count @label entities', ['@label' => $this->getSingularLabel()], ['context' => 'Entity type label']);
} }
$context = isset($this->label_count['context']) ? $this->label_count['context'] : 'Entity type label'; $options = [];
return $this->formatPlural($count, $this->label_count['singular'], $this->label_count['plural'], ['context' => $context]); if (isset($this->label_count['context'])) {
$options['context'] = $this->label_count['context'];
}
return $this->formatPlural($count, $this->label_count['singular'], $this->label_count['plural'], [], $options);
} }
/** /**
......
...@@ -397,6 +397,12 @@ public function testGetCountLabel() { ...@@ -397,6 +397,12 @@ public function testGetCountLabel() {
$this->assertEquals('one entity test', $entity_type->getCountLabel(1)); $this->assertEquals('one entity test', $entity_type->getCountLabel(1));
$this->assertEquals('2 entity test', $entity_type->getCountLabel(2)); $this->assertEquals('2 entity test', $entity_type->getCountLabel(2));
$this->assertEquals('200 entity test', $entity_type->getCountLabel(200)); $this->assertEquals('200 entity test', $entity_type->getCountLabel(200));
$this->assertArrayNotHasKey('context', $entity_type->getCountLabel(1)->getOptions());
// Test a custom context.
$entity_type = $this->setUpEntityType(['label_count' => ['singular' => 'one entity test', 'plural' => '@count entity test', 'context' => 'custom context']]);
$entity_type->setStringTranslation($this->getStringTranslationStub());
$this->assertSame('custom context', $entity_type->getCountLabel(1)->getOption('context'));
} }
/** /**
...@@ -408,6 +414,7 @@ public function testGetCountLabelDefault() { ...@@ -408,6 +414,7 @@ public function testGetCountLabelDefault() {
$this->assertEquals('1 entity test plural', $entity_type->getCountLabel(1)); $this->assertEquals('1 entity test plural', $entity_type->getCountLabel(1));
$this->assertEquals('2 entity test plural entities', $entity_type->getCountLabel(2)); $this->assertEquals('2 entity test plural entities', $entity_type->getCountLabel(2));
$this->assertEquals('200 entity test plural entities', $entity_type->getCountLabel(200)); $this->assertEquals('200 entity test plural entities', $entity_type->getCountLabel(200));
$this->assertSame('Entity type label', $entity_type->getCountLabel(1)->getOption('context'));
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment