From 12fc9344d4aac7595a87f80b342060033bf8dc36 Mon Sep 17 00:00:00 2001 From: mike-esokia Date: Fri, 18 May 2018 17:36:19 +0400 Subject: [PATCH 1/2] show hex as icon in technical data --- .../Core/Provider/TwigServiceProvider.php | 17 +++++++++++++++++ templates/web/common/macros.html.twig | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) 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' %} From 6a323a31892bba9cf9712fab474e268957b2e80e Mon Sep 17 00:00:00 2001 From: mike-esokia Date: Mon, 21 May 2018 11:23:43 +0400 Subject: [PATCH 2/2] add trim before matching value to regex --- lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php index cd3b4a6bcf..4dddd878ad 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php @@ -130,14 +130,13 @@ class TwigServiceProvider implements ServiceProviderInterface $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); + preg_match_all($re, trim($value), $matches); if ($matches && $matches[1] != null && $matches[2] != null) { $colorCode = '#' . $matches[2][0]; $colorName = $matches[1][0]; - $stringArr[$key] = '' . trim($colorName) . '
'; + $stringArr[$key] = '' . $colorName . '
'; } }