Skip to content
Snippets Groups Projects
Commit ca425a29 authored by David Galeano's avatar David Galeano Committed by Alvaro Hurtado
Browse files

Issue #3450543 by gxleano: Add external link settings to Iconify icon widget and formatter

parent 9626058d
No related branches found
No related tags found
1 merge request!7Issue #3450543 by gxleano: Add external link settings to Iconify icon widget and formatter
Pipeline #184979 passed
......@@ -36,6 +36,7 @@ function iconify_icons_theme($existing, $type, $theme, $path) {
'variables' => [
'icon_name' => '',
'icon_svg' => '',
'settings' => '',
],
],
];
......
......@@ -76,11 +76,12 @@ class IconifyIconFormatter extends FormatterBase implements ContainerFactoryPlug
// Loop over each icon and build data.
$icons = [];
foreach ($items as $item) {
$settings = unserialize($item->get('settings')->getValue() ?? '', ['allowed_classes']);
$icons[] = [
'#theme' => 'iconifyicon',
'#icon_name' => $item->get('icon_name')->getValue(),
'#icon_svg' => $item->get('icon_svg')->getValue(),
'#settings' => $item->get('settings')->getValue(),
'#settings' => $settings,
];
}
......
......@@ -252,6 +252,21 @@ class IconifyIconWidget extends WidgetBase {
'#default_value' => $settings['rotate'] ?? '',
];
$element['settings']['link_url'] = [
'#type' => 'textfield',
'#title' => $this->t('URL'),
'#description' => $this->t('The URL to which the user should be redirected. This can be an internal URL like /node/1234 or an external URL like @url.', ['@url' => 'http://example.com']),
'#default_value' => $settings['link_url'],
'#pattern' => '^(https?:\/\/[^\s]+|www\.[^\s]+|\/[^\s]+)$',
];
$element['settings']['link_text'] = [
'#type' => 'textfield',
'#title' => $this->t('Link Text'),
'#description' => $this->t('It will show a text close to the icon.'),
'#default_value' => $settings['link_text'] ?? '',
];
return $element;
}
......
......@@ -4,18 +4,24 @@
* Default implementation for Iconify Icon field.
*
* Available variables:
* - icon_name: TBD.
* - icon_svg: TBD.
* - settings: TBD.
* - icon_name: The name of the icon.
* - icon_svg: The SVG markup of the icon.
* - settings: An array of settings which includes:
* - link_url: The URL to link the icon to (optional).
* - link_text: The text to display below the icon (optional).
*
* @ingroup themeable
*/
#}
{%
set classes = [
settings,
]
%}
<div class="iconify-icon">
{{ icon_svg | raw}}
</div>
{% if settings.link_url %}
<a class="iconify-icon-link" href="{{ settings.link_url }}" target="_blank">
{{ icon_svg | raw }}
{% if settings.link_text %}
<p class="iconify-icon-link-title">{{ settings.link_text }}</p>
{% endif %}
</a>
{% else %}
{{ icon_svg | raw }}
{% endif %}
</div>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment