diff --git a/src/TwigTweakExtension.php b/src/TwigTweakExtension.php index 36e3004..8b543ed 100644 --- a/src/TwigTweakExtension.php +++ b/src/TwigTweakExtension.php @@ -419,6 +419,18 @@ class TwigTweakExtension extends AbstractExtension { public static function drupalContextualLinks(string $id): array { $build['#cache']['contexts'] = ['user.permissions']; 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, ':') + if ($contextParamCount !== 3) { + trigger_error("Wrong {{ drupal_contextual_links() }} parameters. 3 parameters expected, separated by colon (\":\"), but {$contextParamCount} given in: \"{$id}\"", E_USER_WARNING); + } + } + $build['#type'] = 'contextual_links_placeholder'; $build['#id'] = $id; }