Skip to content
Snippets Groups Projects
Commit 0a252688 authored by Eleo Basili's avatar Eleo Basili
Browse files

Issue #3347280 by saidatom, fathima.asmat, eleonel, anybody, naveenvalecha:...

Issue #3347280 by saidatom, fathima.asmat, eleonel, anybody, naveenvalecha: Translated entity doesn't show up for the referenced item 
parent eb881e14
No related branches found
No related tags found
1 merge request!10Issue #3445038: Fix schema error: variable type is integer but applied schema...
......@@ -2,15 +2,38 @@
namespace Drupal\entity_reference_display\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Plugin trait for the 'entity_reference_display' formatters.
*/
trait EntityReferenceDisplayFormatterTrait {
/**
* Constructs a new MyEntityReferenceDisplayFormatter.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository
* The entity repository service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* The entity field manager service.
*/
public function __construct(protected EntityRepositoryInterface $entityRepository, protected EntityFieldManagerInterface $entityFieldManager) {}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$container->get('entity.repository'),
$container->get('entity_field.manager')
);
}
/**
* {@inheritdoc}
*/
......@@ -68,6 +91,7 @@ trait EntityReferenceDisplayFormatterTrait {
$display_field = $this->getDisplayField($display_fields);
/** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
$entity = $items->getEntity();
$entity = $this->entityRepository->getTranslationFromContext($entity, $langcode);
// Only if entity has this field.
if ($entity->hasField($display_field)) {
// Get selected display mode value from field.
......@@ -90,8 +114,7 @@ trait EntityReferenceDisplayFormatterTrait {
$entity_type = $field_definition->getTargetEntityTypeId();
$entity_bundle = $field_definition->getTargetBundle();
if (!empty($entity_bundle)) {
$entity_fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions($entity_type, $entity_bundle);
$entity_fields = $this->entityFieldManager->getFieldDefinitions($entity_type, $entity_bundle);
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field */
foreach ($entity_fields as $field) {
// Formatter is only available for entity types with display mode field.
......@@ -111,8 +134,7 @@ trait EntityReferenceDisplayFormatterTrait {
// Get all fields associated with current entity.
$entity_type = $this->fieldDefinition->getTargetEntityTypeId();
$entity_bundle = $this->fieldDefinition->getTargetBundle();
$entity_fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions($entity_type, $entity_bundle);
$entity_fields = $this->entityFieldManager->getFieldDefinitions($entity_type, $entity_bundle);
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field */
foreach ($entity_fields as $key => $field) {
// Find display mode fields.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment