Commit daea0bf7 authored by alexpott's avatar alexpott
Browse files

Issue #2864020 by Maouna, amateescu, alexpott: Entity autocomplete displays...

Issue #2864020 by Maouna, amateescu, alexpott: Entity autocomplete displays default value's entity labels only in the default entity language
parent dd7d7e59
......@@ -317,8 +317,14 @@ protected static function matchEntityByTitle(SelectionInterface $handler, $input
* A string of entity labels separated by commas.
*/
public static function getEntityLabels(array $entities) {
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$entity_labels = [];
foreach ($entities as $entity) {
// Set the entity in the correct language for display.
$entity = $entity_repository->getTranslationFromContext($entity);
// Use the special view label, since some entities allow the label to be
// viewed, even if the entity is not allowed to be viewed.
$label = ($entity->access('view label')) ? $entity->label() : t('- Restricted access -');
......
......@@ -106,6 +106,13 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase {
*/
protected $translatedLabel;
/**
* An user with permission to edit the referrer entity.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* Modules to enable.
*
......@@ -134,6 +141,8 @@ protected function setUp() {
$this->enableTranslation();
$this->setUpEntityReferenceField();
$this->createContent();
$this->webUser = $this->drupalCreateUser(['edit any ' . $this->referrerType->id() . ' content']);
}
/**
......@@ -143,14 +152,17 @@ public function testEntityReferenceDisplay() {
// Create a translated referrer entity.
$this->referrerEntity = $this->createReferrerEntity();
$this->assertEntityReferenceDisplay();
$this->assertEntityReferenceFormDisplay();
// Disable translation for referrer content type.
$this->drupalLogin($this->rootUser);
$this->drupalPostForm('admin/config/regional/content-language', ['settings[node][referrer][translatable]' => FALSE], t('Save configuration'));
$this->drupalLogout();
// Create a referrer entity without translation.
$this->referrerEntity = $this->createReferrerEntity(FALSE);
$this->assertEntityReferenceDisplay();
$this->assertEntityReferenceFormDisplay();
}
/**
......@@ -170,6 +182,23 @@ protected function assertEntityReferenceDisplay() {
$this->assertText($this->translatedLabel, 'The translated label of translated reference is displayed.');
}
/**
* Assert entity reference form display.
*/
protected function assertEntityReferenceFormDisplay() {
$this->drupalLogin($this->webUser);
$url = $this->referrerEntity->urlInfo('edit-form');
$translation_url = $this->referrerEntity->urlInfo('edit-form', ['language' => ConfigurableLanguage::load($this->translateToLangcode)]);
$this->drupalGet($url);
$this->assertSession()->fieldValueEquals('test_reference_field[0][target_id]', $this->originalLabel . ' (1)');
$this->assertSession()->fieldValueEquals('test_reference_field[1][target_id]', $this->labelOfNotTranslatedReference . ' (2)');
$this->drupalGet($translation_url);
$this->assertSession()->fieldValueEquals('test_reference_field[0][target_id]', $this->translatedLabel . ' (1)');
$this->assertSession()->fieldValueEquals('test_reference_field[1][target_id]', $this->labelOfNotTranslatedReference . ' (2)');
$this->drupalLogout();
}
/**
* Adds additional languages.
*/
......
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