You are here

public static function TwigTweakExtension::drupalContextualLinks in Twig Tweak 3.x

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

Builds contextual links.

Parameters

string $id: A serialized representation of a #contextual_links property value array.

Return value

array A renderable array representing contextual links.

See also

https://www.drupal.org/node/2133283

File

src/TwigTweakExtension.php, line 406

Class

TwigTweakExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public static function drupalContextualLinks(string $id) : array {
  $build['#cache']['contexts'] = [
    'user.permissions',
  ];
  if (\Drupal::currentUser()
    ->hasPermission('access contextual links')) {
    $build['#type'] = 'contextual_links_placeholder';
    $build['#id'] = $id;
  }
  return $build;
}