@ -419,6 +419,18 @@ class TwigTweakExtension extends AbstractExtension {
public static function drupalContextualLinks(string $id): array {
public static function drupalContextualLinks(string $id): array {
$build['#cache']['contexts'] = ['user.permissions'];
$build['#cache']['contexts'] = ['user.permissions'];
if (\Drupal::currentUser()->hasPermission('access contextual links')) {
if (\Drupal::currentUser()->hasPermission('access contextual links')) {
// Pre-check the format of $id, as expected by Drupal core without further checks:
$contexts = explode('|', $id);
foreach ($contexts as $context) {
// Drupal core expects exactly three parameters:
// [$group, $route_parameters_raw, $metadata_raw] = explode(':', $context);
// in _contextual_id_to_links($id):
$contextParamCount = substr_count($context, ':')+1;
if ($contextParamCount !== 3) {
trigger_error("Wrong {{ drupal_contextual_links() }} parameter given. 3 parameters expected separated by colon (\":\"), but {$contextParamCount} given in \"{$id}\"", E_USER_WARNING);
}
}
$build['#type'] = 'contextual_links_placeholder';
$build['#type'] = 'contextual_links_placeholder';
$build['#id'] = $id;
$build['#id'] = $id;
}
}