You are here

function template_preprocess_fine_image_widget_multiple in Fine Image Upload 8

Same name and namespace in other branches
  1. 8.2 fiu.field.inc \template_preprocess_fine_image_widget_multiple()

Prepares variables for multi fine image file form widget templates.

Default template: fine-image-widget-multiple.html.twig.

Parameters

array $variables: An associative array containing:

  • element: A render element representing the widgets.

File

./fiu.field.inc, line 108
Implement a fine image field, based on the file module's file field.

Code

function template_preprocess_fine_image_widget_multiple(array &$variables) {
  $element = $variables['element'];

  // Get our list of widgets in order (needed when the form comes back after
  // preview or failed validation).
  $widgets = [];
  foreach (Element::children($element) as $key) {
    $widgets[] =& $element[$key];
  }
  usort($widgets, '_field_multiple_value_form_sort_helper');
  $list = [];
  foreach ($widgets as $key => &$widget) {

    // Save the uploading row for last.
    if (empty($widget['#files'])) {
      $widget['#title'] = $element['#file_upload_title'];
      $widget['#description'] = \Drupal::service('renderer')
        ->renderPlain($element['#file_upload_description']);
      continue;
    }
    if ($element['#display_field']) {
      hide($widget['display']);
    }
    hide($widget['_weight']);
    $widget['#theme_wrappers'] = [];
    $information = \Drupal::service('renderer')
      ->render($widget, FALSE);
    $display = '';
    if ($element['#display_field']) {
      unset($widget['display']['#title']);
      $display = [
        'data' => render($widget['display']),
        'class' => [
          'checkbox',
        ],
      ];
    }
    if (isset($widget['_weight']['#title'])) {
      unset($widget['_weight']['#title']);
    }
    $weight = render($widget['_weight']);
    $row = [];
    $row[] = $information;
    if ($element['#display_field']) {
      $row[] = $display;
    }
    $row[] = $weight;
    $list[] = [
      '#type' => 'inline_template',
      '#template' => implode('', $row),
    ];
  }
  $variables['list'] = [
    '#theme' => 'item_list',
    '#items' => $list,
    '#attributes' => [
      'id' => 'sortable',
      'class' => [
        'fiu-sortable-list',
      ],
    ],
    '#access' => !empty($list),
  ];
  if (!isset($element['#file_upload_description']['#markup']) || empty($element['#file_upload_description']['#markup'])) {
    $element = '';
  }
  $variables['id'] = $element['#id'];
  $variables['element'] = $element;
}