{% set classes = [
  'media',
  'media--image',
] %}
{% set attributes = attributes|default(create_attribute()) %}
{% set attributes = attributes.setAttribute('data-js', 'media-image') %}

{% if not media_field_caption %}
  {% set media_tag = 'div' %}
{% endif %}

{% if not attributes.class %}
  {% set attributes = attributes.setAttribute('class', classes) %}
{% endif %}

{# merge classes into attributes.class #}
{% if attributes.class %}
  {% set attributes = attributes.setAttribute('class', attributes.class|merge(classes)) %}
{% endif %}

{% extends "@ui-media/media.html.twig" %}

{% block media_content %}
  {{ media_field_media_image }}

  {% if media_caption %}
    <figcaption class="media__figcaption">
      {{ media_caption }}
    </figcaption>
  {% endif %}
{% endblock %}
