Commit b8ac53f1 authored by alexpott's avatar alexpott

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
......@@ -13,6 +13,7 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\DataReferenceDefinition;
......@@ -82,19 +83,19 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
if ($target_id_data_type === '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);
}
else {
$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);
$properties['target_id'] = $target_id_definition;
$properties['entity'] = DataReferenceDefinition::create('entity')
->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.
->setComputed(TRUE)
->setReadOnly(FALSE)
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\entity_test\Entity\EntityTest;
......@@ -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->id(), $tid);
$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.
$new_name = $this->randomMachineName();
......@@ -178,6 +183,10 @@ public function testContentEntityReferenceItemWithStringId() {
$storage = \Drupal::entityManager()->getStorage('entity_test');
$storage->resetCache();
$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');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment