From 40f31c55a2dcbee6e5dd86513b286cff76e38cee Mon Sep 17 00:00:00 2001 From: Dehorter Date: Mon, 16 May 2022 15:01:38 +0200 Subject: [PATCH] 3280672 : Use settings variables in template --- src/TwigTweakExtension.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/TwigTweakExtension.php b/src/TwigTweakExtension.php index 00671bb..d52aca1 100644 --- a/src/TwigTweakExtension.php +++ b/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'; + } + } + }