|
|
@ -5,6 +5,7 @@ namespace Drupal\twig_tweak\View; |
|
|
|
use Drupal\Core\Access\AccessResult; |
|
|
|
use Drupal\Core\Access\AccessResult; |
|
|
|
use Drupal\Core\Cache\CacheableMetadata; |
|
|
|
use Drupal\Core\Cache\CacheableMetadata; |
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
|
|
|
|
|
|
use Drupal\Core\Entity\EntityRepositoryInterface; |
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -19,11 +20,19 @@ class EntityViewBuilder { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected $entityTypeManager; |
|
|
|
protected $entityTypeManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The entity repository service. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @var \Drupal\Core\Entity\EntityRepositoryInterface |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected $entityRepository; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Constructs an EntityViewBuilder object. |
|
|
|
* Constructs an EntityViewBuilder object. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function __construct(EntityTypeManagerInterface $entity_type_manager) { |
|
|
|
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository) { |
|
|
|
$this->entityTypeManager = $entity_type_manager; |
|
|
|
$this->entityTypeManager = $entity_type_manager; |
|
|
|
|
|
|
|
$this->entityRepository = $entity_repository; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -31,6 +40,7 @@ class EntityViewBuilder { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function build(EntityInterface $entity, string $view_mode = 'full', string $langcode = NULL, bool $check_access = TRUE): array { |
|
|
|
public function build(EntityInterface $entity, string $view_mode = 'full', string $langcode = NULL, bool $check_access = TRUE): array { |
|
|
|
$build = []; |
|
|
|
$build = []; |
|
|
|
|
|
|
|
$entity = $this->entityRepository->getTranslationFromContext($entity, $langcode); |
|
|
|
$access = $check_access ? $entity->access('view', NULL, TRUE) : AccessResult::allowed(); |
|
|
|
$access = $check_access ? $entity->access('view', NULL, TRUE) : AccessResult::allowed(); |
|
|
|
if ($access->isAllowed()) { |
|
|
|
if ($access->isAllowed()) { |
|
|
|
$build = $this->entityTypeManager |
|
|
|
$build = $this->entityTypeManager |
|
|
|