Issue #2575493 by Berdir, dawehner: Remove string cast of EntityType::getLabel() and getGroupLabel()
parent
04d331c6ea
commit
3e59aced0c
|
@ -696,7 +696,7 @@ class EntityType implements EntityTypeInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getLabel() {
|
public function getLabel() {
|
||||||
return (string) $this->label;
|
return $this->label;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -733,7 +733,7 @@ class EntityType implements EntityTypeInterface {
|
||||||
* {@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 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements Opt
|
||||||
// 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 @@ namespace Drupal\Tests\Core\Entity;
|
||||||
|
|
||||||
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 @@ class EntityTypeTest extends UnitTestCase {
|
||||||
$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.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue