custom/plugins/KsAttachments/src/Resources/views/storefront/component/ks-attachments-list.html.twig line 1

Open in your IDE?
  1. {% block ks_attachments_list %}
  2.     {% set url = url('frontend.attachment.execute') %}
  3.     {% set atachmentsPluginOptions = {
  4.         url: url
  5.     } %}
  6.     {% set maxItems = maxItems ? maxItems : 100 %}
  7.     {% set iconSize = iconSize is null ? 'w40' : iconSize %}
  8.     {# initial ID array #}
  9.     {% set attachmentsMediaIds = [] %}
  10.     {% for attachment in attachmentsDisplay %}
  11.         {# merge IDs to a single array #}
  12.         {% set attachmentsMediaIds = attachmentsMediaIds|merge([attachment.mediaIconId]) %}
  13.         {% set attachmentsMediaIds = attachmentsMediaIds|merge([attachment.mediaFileId ? attachment.mediaFileId : attachment.translated.mediaFileId]) %}
  14.     {% endfor %}
  15.     {# do a single fetch from database #}
  16.     {% set mediaFileCollection = searchMedia(attachmentsMediaIds, context.context) %}
  17.     {% if displayOn == '3' %}
  18.         <div class="ks-attachment-container{% if containerClass %} {{ containerClass }}{% endif %}" data-ks-attachments data-attachments-plugin-options='{{ atachmentsPluginOptions|json_encode }}' data-product-id="{{ page.product.id }}">
  19.             <ul class="ks-attachments-list ks-attachments-list--product-icons">
  20.                 {% if attachmentsDisplay %}
  21.                     {% for attachment in attachmentsDisplay %}
  22.                         {% if loop.index - 1 < maxItems %}
  23.                             <li>
  24.                                 {% set mediaFileId = attachment.mediaFileId ? attachment.mediaFileId : attachment.translated.mediaFileId %}
  25.                                 {% set mediaFile = mediaFileCollection.get(mediaFileId) %}
  26.                                 <img src="{{ mediaFile.url }}" alt="{{ attachment.title }}" title="{{ attachment.title }}" width="50" height="50">
  27.                             </li>
  28.                         {% endif %}
  29.                     {% endfor %}
  30.                 {% endif %}
  31.             </ul>
  32.         </div>
  33.     {% else %}
  34.         <div class="ks-attachment-container{% if containerClass %} {{ containerClass }}{% endif %}" data-ks-attachments data-attachments-plugin-options='{{ atachmentsPluginOptions|json_encode }}' data-product-id="{{ page.product.id }}">
  35.             <ul class="ks-attachments-list">
  36.                 {% if attachmentsDisplay %}
  37.                     {% for attachment in attachmentsDisplay %}
  38.                         <li>
  39.                             {% set IconAttachment = mediaFileCollection.get(attachment.mediaIconId) %}
  40.                             {% set displayAttachment = attachment.display|split(',') %}
  41.                             {% set limited = attachment.limited %}
  42.                             {% set downloadsRemaining = attachment.downloadsRemaining %}
  43.                             {% if limited and downloadsRemaining > 0 %}
  44.                                 {% set downloadsRemaining = downloadsRemaining %}
  45.                             {% elseif limited == false %}
  46.                                 {% set downloadsRemaining = "" %}
  47.                             {% else %}
  48.                                 {% set downloadsRemaining = "Out of " %}
  49.                             {% endif %}
  50.                             {% set mediaFile = mediaFileCollection.get(attachment.mediaFileId) %}
  51.                             {% set mediaFileExtension = mediaFile.fileExtension %}
  52.                             {% set mediaFileIcon = mediaFileExtension %}
  53.                             <div class="ks-media-attachment" data-attachment-id="{{ attachment.id }}" data-attachment-file-icon="{{ mediaFileIcon }}">
  54.                                 {% if IconAttachment %}
  55.                                     {% sw_thumbnails 'minimal-image-thumbnails' with {
  56.                                         media: IconAttachment,
  57.                                         sizes: {
  58.                                             'default': '30px'
  59.                                         },
  60.                                         attributes: {
  61.                                             'class': 'ks-icon-attachment',
  62.                                             'alt': ( attachment.title ?: ''),
  63.                                             'title': (attachment.title ?: '')
  64.                                         }
  65.                                     } %}
  66.                                 {% else %}
  67.                                     {% if mediaFileIcon == 'jpeg' %}
  68.                                         {% set mediaFileIcon = 'jpg' %}
  69.                                     {% endif %}
  70.                                     {% set mediaFileIconArray = ['pdf', 'png', 'txt', 'doc', 'xls', 'jpg', 'svg'] %}
  71.                                     {% set iconName = 'file-icon' %}
  72.                                     {% if mediaFileIcon in mediaFileIconArray %}
  73.                                         {% set iconName = mediaFileIcon ~ '-icon' %}
  74.                                     {% endif %}
  75.                                     {% sw_include "@Storefront/storefront/utilities/icon.html.twig" with {
  76.                                         'name' : iconName,
  77.                                         'pack' : 'ks',
  78.                                         'namespace' : 'KsAttachments',
  79.                                     } %}
  80.                                     {% set mediaImageFileIconArray = ['jpg', 'jpeg', 'png', 'svg'] %}
  81.                                     {% if mediaFileIcon in mediaImageFileIconArray %}
  82.                                         <span class="ks-attachments-popup"></span>
  83.                                     {% endif %}
  84.                                 {% endif %}
  85.                                 <span class="ks-title-attachment">{{ attachment.title }}
  86.                                     {% if limited %}
  87.                                         (<span class="download-remaining-{{ attachment.ids }}">{{ downloadsRemaining }}</span>
  88.                                         downloads)
  89.                                     {% else %}
  90.                                         <span class="download-remaining-{{ attachment.ids }}">{{ downloadsRemaining }}</span>
  91.                                     {% endif %}
  92.                                 </span>
  93.                             </div>
  94.                         </li>
  95.                     {% endfor %}
  96.                 {% endif %}
  97.             </ul>
  98.         </div>
  99.     {% endif %}
  100. {% endblock %}