Skip to content
Snippets Groups Projects

Adding to condition

1 file
+ 4
0
Compare changes
  • Side-by-side
  • Inline
@@ -201,6 +201,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);
}
Loading