You are here

function template_preprocess_views_view_fieldset in Views fieldset style plugin 8

Same name and namespace in other branches
  1. 7 views_fieldset.module \template_preprocess_views_view_fieldset()

File

./views_fieldset.module, line 16
Views fieldset style plugin code.

Code

function template_preprocess_views_view_fieldset(&$variables) {

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $variables['view'];
  $rows = $variables['rows'];
  $style = $view->style_plugin;
  $options = $style->options;
  $group = $view->storage
    ->id() . '-' . $view->current_display;
  foreach ($rows as $id => $row) {
    $html_id = Html::getUniqueId($group . '-row-' . ($id + 1));
    $classes = array();
    if ($row_class = $view->style_plugin
      ->getRowClass($id)) {
      $classes[] = $row_class;
    }
    $field = $options['title'];
    $title = '';
    if (isset($view->field[$field])) {
      $title = $style
        ->getField($id, $field);
      if ($view->field[$field]->options['label']) {
        $title = $view->field[$field]->options['label'] . ': ' . $title;
      }
      $title = strip_tags(htmlspecialchars_decode($title));
    }
    $field = $options['description'];
    $description = '';
    if (isset($view->field[$field])) {
      $description = $style
        ->getField($id, $field);
      if ($view->field[$field]->options['label']) {
        $description = $view->field[$field]->options['label'] . ': ' . $description;
      }
      $description = strip_tags(htmlspecialchars_decode($description));
    }
    $element = array(
      '#title' => $title,
      '#type' => 'fieldset',
      '#children' => $row,
      '#parents' => array(),
      '#description' => $description,
      '#attributes' => array(
        'class' => $classes,
        'id' => $html_id,
      ),
    );
    $form = array();
    $form_state = new FormState();
    $element = RenderElement::processGroup($element, $form_state, $form);
    $variables['fieldsets'][] = $element;
  }
}