Browse Source

3280672 : Use settings variables in template

merge-requests/14/head
Dehorter 4 years ago
parent
commit
40f31c55a2
  1. 18
      src/TwigTweakExtension.php

18
src/TwigTweakExtension.php

@ -86,6 +86,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);
@ -707,4 +708,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