Browse Source

Merge branch '3399028-access-check-param' into '3.x'

Adding  to condition

See merge request project/twig_tweak!41
merge-requests/41/merge
Prashant Chauhan 2 years ago
parent
commit
5435e31170
  1. 4
      src/TwigTweakExtension.php

4
src/TwigTweakExtension.php

@ -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);
}

Loading…
Cancel
Save