{% import '@FoxHabbitBasis/Macro/wrap.html.twig' as wrap_macro %}
{% if editmode or foxhabbit_common_tool_url_is_published( pimcore_relation('h')) or config.show_unpublished_as_disabled|default(false) %}
{% if editmode %}
{{ pimcore_input('t',{placeholder:'Linktext'}) }}
{{ pimcore_relation('h',{'reload': true,types:config.configuration.types|default(null),subtypes:config.configuration.subtypes|default(null)}) }}
{{ pimcore_input('a',{placeholder:'#Anchor'}) }}
{% if pimcore_relation('h').getElement() and not foxhabbit_common_tool_url_is_published( pimcore_relation('h')) %}
<div class="alert alert-danger">Link-Ziel nicht gepflegt oder nicht veröffentlicht.</div>
{% endif %}
{% endif %}
{% if editmode or foxhabbit_common_tool_url_is_published( pimcore_relation('h')) or config.show_unpublished_as_disabled|default(false) %}
{% set href = foxhabbit_common_tool_url_get_href( pimcore_relation('h')) %}
{% set target = foxhabbit_common_tool_url_get_target( pimcore_relation('h')) %}
{% set attr = config.attr|default({}) %}
{% if target and target != '_self' and not attr.target|default(null) %}
{% set attr = attr|merge({target:target}) %}
{% endif %}
{% set anchor = pimcore_input('a').getValue() %}
{% if anchor and anchor matches('@^[^#].*@') %}
{% set anchor = '#' ~ anchor %}
{% endif %}
{% if href or anchor %}
{% set wrapper = [ {tag: 'a', href: href~anchor, class: config.class|default(''), attr: attr } ] %}
{% else %}
{% set wrapper = [ {tag: 'a', class: config.class|default(''), attr: attr } ] %}
{% endif %}
{{ wrap_macro.wrapperOpen( wrapper, _context) -}}
{{- pimcore_input('t').getValue() -}}
{{- wrap_macro.wrapperClose( wrapper, _context) }}
{% endif %}
{% endif %}