You are here

image-widget.html.twig in Open Social 8.2

Default theme implementation for an image field widget.

Available variables:

  • attributes: HTML attributes for the containing element.
  • data: Render elements of the image widget.

File

themes/socialbase/templates/file/image-widget.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for an image field widget.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes for the containing element.
  8. * - data: Render elements of the image widget.
  9. *
  10. * @see template_preprocess_image_widget()
  11. *
  12. * @ingroup themeable
  13. */
  14. #}
  15. {% if data.upload['#id'] starts with "edit-field-post-image-0-upload" %}
  16. {% set in_post = true %}
  17. {% else %}
  18. {% set in_post = false %}
  19. {% endif %}
  20. {% if data.preview %}
  21. {{ attach_library('socialbase/image-widget') }}
  22. <div{{ attributes.addClass('image-widget').removeClass('clearfix') }}>
  23. <div class="preview">
  24. {{ data.preview }}
  25. </div>
  26. <div class="data image-widget-data">
  27. {% if in_post %}
  28. {# Render widget data for photo's in posts without the file fields, image preview and remove button. #}
  29. {{ data|without('preview', 'image_crop', 'file_' ~ data.fids['#value'][0], 'remove_button' ) }}
  30. {% else %}
  31. {# Render widget data without the image preview that was output already. #}
  32. {{ data|without('preview', 'image_crop') }}
  33. {% endif %}
  34. </div>
  35. </div>
  36. {% if in_post %}
  37. {# Render a "fake" remove button that triggers the actual (hidden) remove button. #}
  38. <div class="hidden">{{ data.remove_button }}</div>
  39. <button type="button" id="post-photo-remove" class="btn--post-remove-image">
  40. <svg class="btn-icon">
  41. <use id="btnicon" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-close"></use>
  42. </svg>
  43. <span class="sr-only">
  44. {% trans %}Remove image{% endtrans %}
  45. </span>
  46. </button>
  47. {% else %}
  48. {{ attach_library('image_widget_crop/cropper') }}
  49. {{ data.image_crop }}
  50. {% endif %}
  51. {% else %}
  52. {% if in_post %}
  53. {# Render a "fake" image add button that triggers the actual (hidden) upload field. #}
  54. <div{{ attributes.addClass(classes, 'hidden') }}>
  55. {{ data }}
  56. </div>
  57. <button type="button" id="post-photo-add" class="btn btn-default">
  58. <svg class="btn-icon">
  59. <use id="btnicon" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-plus"></use>
  60. </svg>
  61. <span>
  62. {% trans %}Add image{% endtrans %}
  63. </span>
  64. </button>
  65. {% else %}
  66. <div{{ attributes.addClass(classes) }}>
  67. {{ data }}
  68. </div>
  69. {% endif %}
  70. {% endif %}