diff --git a/patterns/molecules/event-display/event-display.html.twig b/patterns/molecules/event-display/event-display.html.twig index e587d88249dcbd6a1859bbd01f8902f2f010e62d..976458ae8cbf3d3b9accce9c7acf4953cde03d67 100755 --- a/patterns/molecules/event-display/event-display.html.twig +++ b/patterns/molecules/event-display/event-display.html.twig @@ -110,16 +110,21 @@ {% if link | render %} <div class="event-node-full-content-place"> {% if link | render %} - {% if cern_node_type != "event_page" %} - <div class="hard-text"> - <p> - <a href="{{ link }}" target="_blank">{{ 'Go to Indico Event'|trans }}</a> - </p> - </div> - <div class="custom-text"> - <p></p> - </div> - {% endif %} + <div class="hard-text"> + {# If the link is a URL (not plain text)#} + {% if is_url(link) %} + <p> + <a href="{{ link | get_url_link }}" target="_blank">{{ 'Go to Indico Event'|trans }}</a> + </p> + {% else %} + <p> + <a href="{{ link }}" target="_blank">{{ 'Go to Indico Event'|trans }}</a> + </p> + {% endif %} + </div> + <div class="custom-text"> + <p></p> + </div> {% endif %} </div> {% endif %} @@ -136,7 +141,6 @@ <p>{{ 'Where: '|trans }} </p> </div> <div class="custom-text"> - {% if map_room | render %} <a href="{{ map_room }}"> {{ room }} </a> {% if room | render %} {% if place | render %} {{ 'at'|trans }} {% endif %} {% endif %} {{ place }} {% else %} diff --git a/src/TwigExtension/CernComponentsTwigExtension.php b/src/TwigExtension/CernComponentsTwigExtension.php index fef3331b1aa75bcc9ae9ccac14c7e118b73034a4..1f25905043923774d843325079f7531e0eb195be 100755 --- a/src/TwigExtension/CernComponentsTwigExtension.php +++ b/src/TwigExtension/CernComponentsTwigExtension.php @@ -54,6 +54,8 @@ class CernComponentsTwigExtension extends \Twig_Extension { */ public function getFilters() { return [ + new \Twig_SimpleFilter('is_url', [$this,'isURL']), + new \Twig_SimpleFilter('get_url_link', [$this,'getUrlLink']), new \Twig_SimpleFilter('addbasepath', [$this, 'addbasepath']), new \Twig_SimpleFilter('htmlspecialchars', [$this, 'htmlSpecialChars']), new \Twig_SimpleFilter('openlink', [$this, 'openLink']), @@ -77,7 +79,7 @@ class CernComponentsTwigExtension extends \Twig_Extension { new \Twig_SimpleFilter('get_tag_attribute', [$this,'getTagAttribute']), new \Twig_SimpleFilter('set_tag_attribute', [$this,'setTagAttribute']), new \Twig_SimpleFilter('get_path', [$this,'getPath']), - ]; + ]; } /** @@ -85,6 +87,8 @@ class CernComponentsTwigExtension extends \Twig_Extension { */ public function getFunctions() { return [ + new \Twig_SimpleFunction('is_url', [$this,'isURL']), + new \Twig_SimpleFunction('get_url_link', [$this,'getUrlLink']), new \Twig_SimpleFunction('get_current_language', [$this, 'getCurrentLanguage']), new \Twig_SimpleFunction('addbasepath', [$this, 'addBasePath']), new \Twig_SimpleFunction('htmlspecialchars', [$this, 'htmlSpecialChars']), @@ -109,10 +113,47 @@ class CernComponentsTwigExtension extends \Twig_Extension { new \Twig_SimpleFunction('get_cds_info', [$this,'getCdsInfo']), new \Twig_SimpleFunction('get_tag_attribute', [$this,'getTagAttribute']), new \Twig_SimpleFunction('set_tag_attribute', [$this,'setTagAttribute']), - new \Twig_SimpleFilter('get_path', [$this,'getPath']), - ]; + ]; } + /** + * Checks if the given variable is a URL + * + * @param $variable + * @return bool + */ + public function isURL($variable) { + reset($variable); + $first_key = key($variable); + + if (array_key_exists('#type', $variable[$first_key]['0']) && $variable[$first_key]['0']['#type'] == "link"){ + return true; + } + else{ + return false; + } + } + + /** + * Returns the URL of a link. Developed because for pattern I don't know in advance the field name so I get the first + * one. + * + * @param $link + * @return string + */ + public function getUrlLink($link){ + reset($link); + $first_key = key($link); + + if ( array_key_exists('#url', $link[$first_key]['0'])){ + return $link[$first_key]['0']['#url']; + } + else{ + return ''; + } + } + + /** * Returns the current language of the *