You are here

function template_preprocess_bibcite_reference__table in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/bibcite_entity.module \template_preprocess_bibcite_reference__table()

Prepares variables for reference, themed as table.

Default template: bibcite-reference--table.html.twig.

Parameters

array $variables: An associative array containing:

  • elements: An array of elements to display in view mode.
  • attributes: HTML attributes for the containing element.
  • bibcite_reference: The reference object.
  • view_mode: View mode; e.g., 'full', 'teaser', etc.
  • rows: Data rows for table view mode.

See also

template_preprocess_bibcite_reference()

File

modules/bibcite_entity/bibcite_entity.module, line 202
Module hooks.

Code

function template_preprocess_bibcite_reference__table(&$variables) {
  $variables['rows'] = [];
  foreach (Element::children($variables['elements']) as $key) {

    // Do not output empty values.
    if (Element::children($variables['elements'][$key])) {
      $title = '';
      if (isset($variables['elements'][$key]['#title']) && $variables['elements'][$key]['#label_display'] != 'hidden') {
        $title = $variables['elements'][$key]['#title'];
      }
      $variables['elements'][$key]['#title'] = '';
      $variables['rows'][] = [
        'title' => [
          '#markup' => $title,
        ],
        'element' => $variables['elements'][$key],
        'attributes' => new Attribute([]),
      ];
    }
  }
  $variables['attributes']['class'][] = 'bibcite-reference-table';
}