You are here

function template_preprocess_views_secondary_row_style_plugin_table in Views Secondary Row 8

Prepares variables for style plugin table templates.

Copied from views_ui.theme.inc, and 3 columns inserted. This shows the Views UI OptionsForm. Version history: Aligned with Views 8.0.1.

Default template: views-ui-style-plugin-table.html.twig.

Parameters

array $variables: An associative array containing:

  • form: A render element representing the form.

File

./views_secondary_row.theme.inc, line 370
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_secondary_row_style_plugin_table(&$variables) {

  // @todo: First, call the default views_ui function, then change.
  // template_preprocess_views_ui_style_plugin_table($variables);
  $form = $variables['form'];
  $header = [
    t('Field'),
    t('Column'),
    t('Align'),
    t('Separator'),
    // Begin insert views_secondary_row
    [
      'data' => t('Secondary row'),
      'align' => 'center',
    ],
    [
      'data' => t('2nd row Separator'),
      'align' => 'center',
    ],
    [
      'data' => t('2nd row Colspan'),
      'align' => 'center',
    ],
    // End insert views_secondary_row
    [
      'data' => t('Sortable'),
      'align' => 'center',
    ],
    [
      'data' => t('Default order'),
      'align' => 'center',
    ],
    [
      'data' => t('Default sort'),
      'align' => 'center',
    ],
    [
      'data' => t('Hide empty column'),
      'align' => 'center',
    ],
    [
      'data' => t('Responsive'),
      'align' => 'center',
    ],
  ];
  $rows = [];
  foreach (Element::children($form['columns']) as $id) {
    $row = [];
    $row[]['data'] = $form['info'][$id]['name'];
    $row[]['data'] = $form['columns'][$id];
    $row[]['data'] = $form['info'][$id]['align'];
    $row[]['data'] = $form['info'][$id]['separator'];

    // Begin insert views_secondary_row.
    $row[]['data'] = $form['info'][$id]['break2'];
    $row[]['data'] = $form['info'][$id]['separator2'];
    $row[]['data'] = $form['info'][$id]['colspan2'];

    // End insert views_secondary_row.
    if (!empty($form['info'][$id]['sortable'])) {
      $row[] = [
        'data' => $form['info'][$id]['sortable'],
        'align' => 'center',
      ];
      $row[] = [
        'data' => $form['info'][$id]['default_sort_order'],
        'align' => 'center',
      ];
      $row[] = [
        'data' => $form['default'][$id],
        'align' => 'center',
      ];
    }
    else {
      $row[] = '';
    }
    $row[] = [
      'data' => $form['info'][$id]['empty_column'],
      'align' => 'center',
    ];
    $row[] = [
      'data' => $form['info'][$id]['responsive'],
      'align' => 'center',
    ];
    $rows[] = $row;
  }

  // Add the special 'None' row.
  $rows[] = [
    [
      'data' => t('None'),
      'colspan' => 9,
    ],
    [
      'align' => 'center',
      'data' => $form['default'][-1],
    ],
    [
      'colspan' => 2,
    ],
  ];

  // Unset elements from the form array that are used to build the table so that
  // they are not rendered twice.
  unset($form['default']);
  unset($form['info']);
  unset($form['columns']);
  $variables['table'] = [
    '#type' => 'table',
    '#theme' => 'table__views_ui_style_plugin_table',
    '#header' => $header,
    '#rows' => $rows,
  ];
  $variables['form'] = $form;
}