|
|
|
|
@ -200,6 +200,10 @@ class TwigTweakExtension extends AbstractExtension {
|
|
|
|
|
public static function drupalField(string $field_name, string $entity_type, string $id, $view_mode = 'full', string $langcode = NULL, bool $check_access = TRUE): array { |
|
|
|
|
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($id); |
|
|
|
|
if ($entity) { |
|
|
|
|
// Restrict anonymous user to view unpublished entities. |
|
|
|
|
if ($check_access && \Drupal::currentUser()->isAnonymous() && !$entity->isPublished()) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
return \Drupal::service('twig_tweak.field_view_builder') |
|
|
|
|
->build($entity, $field_name, $view_mode, $langcode, $check_access); |
|
|
|
|
} |
|
|
|
|
|