Skip to content
Snippets Groups Projects
Commit 3e59aced authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2575493 by Berdir, dawehner: Remove string cast of...

Issue #2575493 by Berdir, dawehner: Remove string cast of EntityType::getLabel() and getGroupLabel()
parent 04d331c6
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -696,7 +696,7 @@ public function getDataTable() { ...@@ -696,7 +696,7 @@ public function getDataTable() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getLabel() { public function getLabel() {
return (string) $this->label; return $this->label;
} }
/** /**
...@@ -733,7 +733,7 @@ public function getGroup() { ...@@ -733,7 +733,7 @@ public function getGroup() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getGroupLabel() { public function getGroupLabel() {
return !empty($this->group_label) ? (string) $this->group_label : $this->t('Other', array(), array('context' => 'Entity type group')); return !empty($this->group_label) ? $this->group_label : $this->t('Other', array(), array('context' => 'Entity type group'));
} }
/** /**
......
...@@ -83,7 +83,7 @@ public function getSettableOptions(AccountInterface $account = NULL) { ...@@ -83,7 +83,7 @@ public function getSettableOptions(AccountInterface $account = NULL) {
// The label does not need sanitizing since it is used as an optgroup // The label does not need sanitizing since it is used as an optgroup
// which is only supported by select elements and auto-escaped. // which is only supported by select elements and auto-escaped.
$bundle_label = $bundles[$bundle]['label']; $bundle_label = $bundles[$bundle]['label'];
$return[$bundle_label] = $entity_ids; $return[(string) $bundle_label] = $entity_ids;
} }
return count($return) == 1 ? reset($return) : $return; return count($return) == 1 ? reset($return) : $return;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
use Drupal\Core\Entity\EntityType; use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\TranslatableString;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
/** /**
...@@ -283,6 +285,44 @@ public function testId() { ...@@ -283,6 +285,44 @@ public function testId() {
$this->assertEquals($id, $entity_type->id()); $this->assertEquals($id, $entity_type->id());
} }
/**
* @covers ::getLabel
*/
public function testGetLabel() {
$translatable_label = new TranslatableString($this->randomMachineName());
$entity_type = $this->setUpEntityType(array('label' => $translatable_label));
$this->assertSame($translatable_label, $entity_type->getLabel());
$label = $this->randomMachineName();
$entity_type = $this->setUpEntityType(array('label' => $label));
$this->assertSame($label, $entity_type->getLabel());
}
/**
* @covers ::getGroupLabel
*/
public function testGetGroupLabel() {
$translatable_group_label = new TranslatableString($this->randomMachineName());
$entity_type = $this->setUpEntityType(array('group_label' => $translatable_group_label));
$this->assertSame($translatable_group_label, $entity_type->getGroupLabel());
$default_label = $this->randomMachineName();
$entity_type = $this->setUpEntityType(array('group_label' => $default_label));
$this->assertSame($default_label, $entity_type->getGroupLabel());
$default_label = new TranslatableString('Other', array(), array('context' => 'Entity type group'));
$entity_type = $this->setUpEntityType([]);
$string_translation = $this->getMock(TranslationInterface::class);
$string_translation->expects($this->atLeastOnce())
->method('translate')
->with('Other', array(), array('context' => 'Entity type group'))
->willReturn($default_label);
$entity_type->setStringTranslation($string_translation);
$this->assertSame($default_label, $entity_type->getGroupLabel());
}
/** /**
* Gets a mock controller class name. * Gets a mock controller class name.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment