Browse Source

Merge branch '3280672-use-variables-in' into '3.x'

3280672 : Use settings variables in template

See merge request project/twig_tweak!14
merge-requests/14/merge
Jérôme Dehorter 2 years ago
parent
commit
f39728e90b
  1. 18
      src/TwigTweakExtension.php

18
src/TwigTweakExtension.php

@ -87,6 +87,7 @@ class TwigTweakExtension extends AbstractExtension {
new TwigFunction('drupal_breakpoint', [self::class, 'drupalBreakpoint'], $all_options),
// @phpcs:ignore Drupal.Arrays.Array.LongLineDeclaration
new TwigFunction('drupal_contextual_links', [self::class, 'drupalContextualLinks']),
new TwigFunction('drupal_settings', [self::class, 'drupalSettings']),
];
$this->moduleHandler->alter('twig_tweak_functions', $functions);
@ -726,4 +727,21 @@ class TwigTweakExtension extends AbstractExtension {
return $output;
}
/**
* Retrieves data from settings.
*
* @param string $key
* A string that maps to a key within the settings data.
*
* @return string
* The settings string value or an error message.
*/
public static function drupalSettings(string $key) {
if (Settings::get($key) && is_string(Settings::get($key))) {
return Settings::get($key);
} else {
return 'Settings value is not a string';
}
}
}

Loading…
Cancel
Save