Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% import "@SyliusBootstrapAdminUi/shared/helper/field/badge.html.twig" as badge %}

{{ badge.default(data, options|default({})) }}
53 changes: 53 additions & 0 deletions src/BootstrapAdminUi/templates/shared/helper/field/badge.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% macro default(data, options) %}
{% if data is not null %}

{# Set label, color, icon to null first #}
{% set label = null %}
{% set color = null %}
{% set icon = null %}
{% if data.name is defined %}
{% set value = data.value %}
{% else %}
{% set value = data %}
{% endif %}

{# Define label from enum if it exists or use the value directly if it's not an enum #}
{% if data.name is defined %}
{% if data.getLabel is defined %}
{% set label = data.getLabel() %}
{% else %}
{% set label = value %}
{% endif %}
{% if data.getColor is defined %}
{% set color = data.getColor() %}
{% endif %}
{% if data.getIcon is defined %}
{% set icon = data.getIcon() %}
{% endif %}
{% else %}
{% set label = value %}
{% endif %}

{# options.vars.*[value] overrides #}
{% if options.vars.colors[value] is defined %}
{% set color = options.vars.colors[value] %}
{% endif %}
{% if options.vars.labels[value] is defined %}
{% set label = options.vars.labels[value] %}
{% endif %}
{% if options.vars.icons[value] is defined %}
{% set icon = options.vars.icons[value] %}
{% endif %}

<span class="badge rounded-pill text-{{ color }}" {{ sylius_test_html_attribute('badge-' ~ color) }}>
{% if icon %}
{% if ':' in icon %}
{{ ux_icon(icon, {'class': 'icon icon-sm'}) }}
{% else %}
{{ icon }}
{% endif %}
{% endif %}
{{ label }}
</span>
{% endif %}
{% endmacro %}