Browse Source

Adding to condition

merge-requests/41/head
prashantdsala 2 years ago
parent
commit
689d517ebf
  1. 4
      src/TwigTweakExtension.php

4
src/TwigTweakExtension.php

@ -198,6 +198,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…
Cancel
Save