Skip to content

Commit

Permalink
EWPP-2937: Add translation from context for contact entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergepavle authored and upchuk committed Feb 6, 2023
1 parent 19bb433 commit 4cbfbad
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase;
Expand All @@ -32,6 +33,13 @@ class TeaserDetailsExtraField extends ExtraFieldDisplayFormattedBase implements
*/
protected $entityTypeManager;

/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;

/**
* TeaserDetailsExtraField constructor.
*
Expand All @@ -43,10 +51,13 @@ class TeaserDetailsExtraField extends ExtraFieldDisplayFormattedBase implements
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->entityRepository = $entity_repository;
}

/**
Expand All @@ -57,7 +68,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager')
$container->get('entity_type.manager'),
$container->get('entity.repository')
);
}

Expand All @@ -78,6 +90,7 @@ public function viewElements(ContentEntityInterface $entity) {
if (!$contact) {
continue;
}
$contact = $this->entityRepository->getTranslationFromContext($contact);
$contact_access = $contact->access('view', NULL, TRUE);
$cache->addCacheableDependency($contact);
$cache->addCacheableDependency($contact_access);
Expand Down

0 comments on commit 4cbfbad

Please sign in to comment.