function ViewsUiThemeHooks::preprocessStylePluginTable

Prepares variables for style plugin table templates.

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

Parameters

array $variables: An associative array containing:

  • form: A render element representing the form.

File

core/modules/views_ui/src/Hook/ViewsUiThemeHooks.php, line 495

Class

ViewsUiThemeHooks
Hook implementations for views_ui.

Namespace

Drupal\views_ui\Hook

Code

public function preprocessStylePluginTable(array &$variables) : void {
  $form = $variables['form'];
  $header = [
    $this->t('Field'),
    $this->t('Column'),
    $this->t('Align'),
    $this->t('Separator'),
    [
      'data' => $this->t('Sortable'),
      'align' => 'center',
    ],
    [
      'data' => $this->t('Default order'),
      'align' => 'center',
    ],
    [
      'data' => $this->t('Default sort'),
      'align' => 'center',
    ],
    [
      'data' => $this->t('Hide empty column'),
      'align' => 'center',
    ],
    [
      'data' => $this->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'];
    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[] = '';
      $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' => $this->t('None'),
      'colspan' => 6,
    ],
    [
      '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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.