You are here

public static function TwigTweakExtension::drupalField in Twig Tweak 3.1.x

Same name and namespace in other branches
  1. 3.x src/TwigTweakExtension.php \Drupal\twig_tweak\TwigTweakExtension::drupalField()

Returns the render array for a single entity field.

File

src/TwigTweakExtension.php, line 195

Class

TwigTweakExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

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) {
    return \Drupal::service('twig_tweak.field_view_builder')
      ->build($entity, $field_name, $view_mode, $langcode, $check_access);
  }
  return [];
}