Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EWPP-2937: Add translation from context for contact entity. #1229

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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