You are here

function template_preprocess_views_formatter_template in Field Formatter Template 8

Same name and namespace in other branches
  1. 8.2 modules/vff/vff.theme.inc \template_preprocess_views_formatter_template()

Prepares variables for views carousel template.

Default template: views-bootstrap-carousel.html.twig.

Parameters

array $variables: The array variables.

File

modules/vff/vff.theme.inc, line 59
Preprocess formatter template.

Code

function template_preprocess_views_formatter_template(array &$variables) {

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $variables['view'];
  $rows = $variables['rows'];

  /** @var \Drupal\vff\Plugin\views\style\ViewFormatterTemplate $style */
  $style = $view->style_plugin;
  $options = $style->options;
  $template_file = fft_storage_dir() . "/" . $options['template'];
  $variables['template_rendered'] = '';
  $langcode = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $langcode_content = \Drupal::languageManager()
    ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
    ->getId();
  $langcode_interface = \Drupal::languageManager()
    ->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)
    ->getId();
  if ($options['render_type'] === 'styled') {
    $variables['template_rendered'] = fft_render($template_file, [
      'data' => $rows,
      'langcode' => $langcode,
      'langcode_content' => $langcode_content,
      'langcode_interface' => $langcode_interface,
      '_variables' => $variables,
    ]);
  }
  else {
    $renderedField = $style
      ->getRenderedFields();
    if (!empty($renderedField) || !empty($options['show_empty'])) {
      if (!empty($options['vff_tree_field']) && !empty($options['vff_tree_parent_field'])) {
        foreach ($renderedField as $index => $row) {
          foreach ($renderedField[$index] as &$rendered_field) {
            if ($rendered_field instanceof MarkupInterface) {
              $rendered_field = $rendered_field
                ->__toString();
              if (\Drupal::service('twig')
                ->isDebug()) {
                $rendered_field = trim(preg_replace('/<!--(.|\\s)*?-->\\s*/', '', $rendered_field));
              }
            }
          }
        }
        $renderedField = vff_build_tree($renderedField, $options['vff_tree_field'], $options['vff_tree_parent_field']);
      }
      else {
        if (\Drupal::service('twig')
          ->isDebug()) {
          foreach ($renderedField as $index => $row) {
            foreach ($renderedField[$index] as &$rendered_field) {
              if ($rendered_field instanceof MarkupInterface) {
                $rendered_field = $rendered_field
                  ->__toString();
                $rendered_field = trim(preg_replace('/<!--(.|\\s)*?-->\\s*/', '', $rendered_field));
              }
            }
          }
        }
      }
      $variables['template_rendered'] = fft_render($template_file, [
        'data' => $renderedField,
        'view' => $view,
        'langcode' => $langcode,
        'langcode_content' => $langcode_content,
        'langcode_interface' => $langcode_interface,
        '_variables' => $variables,
      ]);
      if (\Drupal::service('twig')
        ->isDebug()) {
        $variables['template_rendered'] = preg_replace('/<!--(.|\\s)*?-->\\s*/', '', $variables['template_rendered']);
      }
    }
  }
}