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

Issue #2542292 by stefan.r, borisson_: Use TranslationWrapper instead of t()...

Issue #2542292 by stefan.r, borisson_: Use TranslationWrapper instead of t() Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::propertyDefinitions
parent 52e5d45e
No related branches found
No related tags found
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
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\DataReferenceDefinition; use Drupal\Core\TypedData\DataReferenceDefinition;
...@@ -82,19 +83,19 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel ...@@ -82,19 +83,19 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
if ($target_id_data_type === 'integer') { if ($target_id_data_type === 'integer') {
$target_id_definition = DataDefinition::create('integer') $target_id_definition = DataDefinition::create('integer')
->setLabel(t('@label ID', array($target_type_info->getLabel()))) ->setLabel(new TranslationWrapper('@label ID', ['@label' => $target_type_info->getLabel()]))
->setSetting('unsigned', TRUE); ->setSetting('unsigned', TRUE);
} }
else { else {
$target_id_definition = DataDefinition::create('string') $target_id_definition = DataDefinition::create('string')
->setLabel(t('@label ID', array($target_type_info->getLabel()))); ->setLabel(new TranslationWrapper('@label ID', ['@label' => $target_type_info->getLabel()]));
} }
$target_id_definition->setRequired(TRUE); $target_id_definition->setRequired(TRUE);
$properties['target_id'] = $target_id_definition; $properties['target_id'] = $target_id_definition;
$properties['entity'] = DataReferenceDefinition::create('entity') $properties['entity'] = DataReferenceDefinition::create('entity')
->setLabel($target_type_info->getLabel()) ->setLabel($target_type_info->getLabel())
->setDescription(t('The referenced entity')) ->setDescription(new TranslationWrapper('The referenced entity'))
// The entity object is computed out of the entity ID. // The entity object is computed out of the entity ID.
->setComputed(TRUE) ->setComputed(TRUE)
->setReadOnly(FALSE) ->setReadOnly(FALSE)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait; use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTest;
...@@ -111,6 +112,10 @@ public function testContentEntityReferenceItem() { ...@@ -111,6 +112,10 @@ public function testContentEntityReferenceItem() {
$this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $this->term->getName()); $this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $this->term->getName());
$this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $tid); $this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $tid);
$this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid()); $this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid());
// Verify that the label for the target ID property definition is correct.
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
$this->assertTrue($label instanceof TranslationWrapper);
$this->assertEqual($label->render(), 'Taxonomy term ID');
// Change the name of the term via the reference. // Change the name of the term via the reference.
$new_name = $this->randomMachineName(); $new_name = $this->randomMachineName();
...@@ -178,6 +183,10 @@ public function testContentEntityReferenceItemWithStringId() { ...@@ -178,6 +183,10 @@ public function testContentEntityReferenceItemWithStringId() {
$storage = \Drupal::entityManager()->getStorage('entity_test'); $storage = \Drupal::entityManager()->getStorage('entity_test');
$storage->resetCache(); $storage->resetCache();
$this->assertEqual($this->entityStringId->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id); $this->assertEqual($this->entityStringId->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id);
// Verify that the label for the target ID property definition is correct.
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
$this->assertTrue($label instanceof TranslationWrapper);
$this->assertEqual($label->render(), 'Taxonomy term ID');
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment