diff --git a/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php index 6b9ceae618..cd3b4a6bcf 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php @@ -127,6 +127,23 @@ class TwigServiceProvider implements ServiceProviderInterface ); }, ['needs_environment' => true, 'is_safe' => ['html']])); + $twig->addFilter(new \Twig_SimpleFilter('parseColor', function (\Twig_Environment $twig, $string) use ($app) { + $re = '/^(.*)\[#([0-9a-fA-F]{6})]$/m'; + $stringArr = explode(';', $string); + + foreach ($stringArr as $key => $value) { + preg_match_all($re, $value, $matches); + if ($matches && $matches[1] != null && $matches[2] != null) { + $colorCode = '#' . $matches[2][0]; + $colorName = $matches[1][0]; + + $stringArr[$key] = '' . trim($colorName) . '
'; + } + } + + return implode('', $stringArr); + }, ['needs_environment' => true, 'is_safe' => ['html']])); + $twig->addFilter(new \Twig_SimpleFilter('bounce', function (\Twig_Environment $twig, $fieldValue, $fieldName, $searchRequest, $sbasId) { // bounce value if it is present in thesaurus as well diff --git a/templates/web/common/macros.html.twig b/templates/web/common/macros.html.twig index a8abb904d6..ecbcd92f6f 100644 --- a/templates/web/common/macros.html.twig +++ b/templates/web/common/macros.html.twig @@ -128,7 +128,7 @@
{% for name, value in record.getCaption(caption_field_order(record, can_see_business)) %}
{{ caption_field_label(record, name) }}
-
{{ caption_field(record, name, value)|e|highlight }}
+
{{ caption_field(record, name, value)|e|highlight|parseColor }}
{% endfor %}
{% if display_exif|default(true) and app.getAuthenticator().user is not none and user_setting('technical_display') == 'group' %}