Chris@0: $header) { Chris@0: $variables['headers'][$key]['attributes'] = new Attribute($header['#attributes']); Chris@0: } Chris@0: Chris@0: if (!empty($variables['rows'])) { Chris@0: foreach ($variables['rows'] as $key => $row) { Chris@0: $variables['rows'][$key]['attributes'] = new Attribute($row['#attributes']); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for Views UI display tab bucket templates. Chris@0: * Chris@0: * Default template: views-ui-display-tab-bucket.html.twig. Chris@0: * Chris@0: * @param array $variables Chris@0: * An associative array containing: Chris@0: * - element: An associative array containing the properties of the element. Chris@0: * Properties used: #name, #overridden, #children, #title, #actions. Chris@0: */ Chris@0: function template_preprocess_views_ui_display_tab_bucket(&$variables) { Chris@0: $element = $variables['element']; Chris@0: Chris@0: if (!empty($element['#overridden'])) { Chris@0: $variables['attributes']['title'][] = t('Overridden'); Chris@0: } Chris@0: Chris@0: $variables['name'] = isset($element['#name']) ? $element['#name'] : NULL; Chris@0: $variables['overridden'] = isset($element['#overridden']) ? $element['#overridden'] : NULL; Chris@0: $variables['content'] = $element['#children']; Chris@0: $variables['title'] = $element['#title']; Chris@0: $variables['actions'] = !empty($element['#actions']) ? $element['#actions'] : []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for Views UI build group filter form templates. Chris@0: * Chris@0: * Default template: views-ui-build-group-filter-form.html.twig. Chris@0: * Chris@0: * @param array $variables Chris@0: * An associative array containing: Chris@0: * - form: A render element representing the form. Chris@0: */ Chris@0: function template_preprocess_views_ui_build_group_filter_form(&$variables) { Chris@0: $form = $variables['form']; Chris@0: Chris@0: // Prepare table of options. Chris@0: $header = [ Chris@0: t('Default'), Chris@0: t('Weight'), Chris@0: t('Label'), Chris@0: t('Operator'), Chris@0: t('Value'), Chris@0: t('Operations'), Chris@0: ]; Chris@0: Chris@0: // Prepare default selectors. Chris@0: $form_state = new FormState(); Chris@0: $form['default_group'] = Radios::processRadios($form['default_group'], $form_state, $form); Chris@0: $form['default_group_multiple'] = Checkboxes::processCheckboxes($form['default_group_multiple'], $form_state, $form); Chris@0: $form['default_group']['All']['#title'] = ''; Chris@0: Chris@0: $rows[] = [ Chris@0: ['data' => $form['default_group']['All']], Chris@0: '', Chris@0: [ Chris@0: 'data' => \Drupal::config('views.settings')->get('ui.exposed_filter_any_label') == 'old_any' ? t('<Any>') : t('- Any -'), Chris@0: 'colspan' => 4, Chris@0: 'class' => ['class' => 'any-default-radios-row'], Chris@0: ], Chris@0: ]; Chris@0: // Remove the 'All' default_group form element because it's added to the Chris@0: // table row. Chris@0: unset($variables['form']['default_group']['All']); Chris@0: Chris@0: foreach (Element::children($form['group_items']) as $group_id) { Chris@0: $form['group_items'][$group_id]['value']['#title'] = ''; Chris@0: $default = [ Chris@0: $form['default_group'][$group_id], Chris@0: $form['default_group_multiple'][$group_id], Chris@0: ]; Chris@0: // Remove these fields from the form since they are moved into the table. Chris@0: unset($variables['form']['default_group'][$group_id]); Chris@0: unset($variables['form']['default_group_multiple'][$group_id]); Chris@0: Chris@0: $link = [ Chris@0: '#type' => 'link', Chris@0: '#url' => Url::fromRoute('', [], [ Chris@0: 'attributes' => [ Chris@0: 'id' => 'views-remove-link-' . $group_id, Chris@0: 'class' => [ Chris@0: 'views-hidden', Chris@0: 'views-button-remove', Chris@0: 'views-groups-remove-link', Chris@0: 'views-remove-link', Chris@0: ], Chris@0: 'alt' => t('Remove this item'), Chris@0: 'title' => t('Remove this item'), Chris@0: ], Chris@0: ]), Chris@17: '#title' => new FormattableMarkup('@text', ['@text' => t('Remove')]), Chris@0: ]; Chris@0: $remove = [$form['group_items'][$group_id]['remove'], $link]; Chris@0: $data = [ Chris@0: 'default' => ['data' => $default], Chris@0: 'weight' => ['data' => $form['group_items'][$group_id]['weight']], Chris@0: 'title' => ['data' => $form['group_items'][$group_id]['title']], Chris@0: 'operator' => ['data' => $form['group_items'][$group_id]['operator']], Chris@0: 'value' => ['data' => $form['group_items'][$group_id]['value']], Chris@0: 'remove' => ['data' => $remove], Chris@0: ]; Chris@0: $rows[] = ['data' => $data, 'id' => 'views-row-' . $group_id, 'class' => ['draggable']]; Chris@0: } Chris@0: $variables['table'] = [ Chris@0: '#type' => 'table', Chris@0: '#header' => $header, Chris@0: '#rows' => $rows, Chris@0: '#attributes' => [ Chris@0: 'class' => ['views-filter-groups'], Chris@0: 'id' => 'views-filter-groups', Chris@0: ], Chris@0: '#tabledrag' => [ Chris@0: [ Chris@0: 'action' => 'order', Chris@0: 'relationship' => 'sibling', Chris@0: 'group' => 'weight', Chris@17: ], Chris@0: ], Chris@0: ]; Chris@0: Chris@0: // Hide fields used in table. Chris@0: unset($variables['form']['group_items']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for Views UI rearrange filter form templates. Chris@0: * Chris@0: * Default template: views-ui-rearrange-filter-form.html.twig. Chris@0: * Chris@0: * @param array $variables Chris@0: * An associative array containing: Chris@0: * - form: A render element representing the form. Chris@0: */ Chris@0: function template_preprocess_views_ui_rearrange_filter_form(&$variables) { Chris@0: $form = &$variables['form']; Chris@0: $rows = $ungroupable_rows = []; Chris@0: // Enable grouping only if > 1 group. Chris@0: $variables['grouping'] = count(array_keys($form['#group_options'])) > 1; Chris@0: Chris@0: foreach ($form['#group_renders'] as $group_id => $contents) { Chris@0: // Header row for the group. Chris@0: if ($group_id !== 'ungroupable') { Chris@0: // Set up tabledrag so that it changes the group dropdown when rows are Chris@0: // dragged between groups. Chris@0: $options = [ Chris@0: 'table_id' => 'views-rearrange-filters', Chris@0: 'action' => 'match', Chris@0: 'relationship' => 'sibling', Chris@0: 'group' => 'views-group-select', Chris@0: 'subgroup' => 'views-group-select-' . $group_id, Chris@0: ]; Chris@0: drupal_attach_tabledrag($form['override'], $options); Chris@0: Chris@0: // Title row, spanning all columns. Chris@0: $row = []; Chris@0: // Add a cell to the first row, containing the group operator. Chris@0: $row[] = [ Chris@0: 'class' => ['group', 'group-operator', 'container-inline'], Chris@0: 'data' => $form['filter_groups']['groups'][$group_id], Chris@0: 'rowspan' => max([2, count($contents) + 1]), Chris@0: ]; Chris@0: // Title. Chris@0: $row[] = [ Chris@0: 'class' => ['group', 'group-title'], Chris@0: 'data' => [ Chris@0: '#prefix' => '', Chris@0: '#markup' => $form['#group_options'][$group_id], Chris@0: '#suffix' => '', Chris@0: ], Chris@0: 'colspan' => 4, Chris@0: ]; Chris@0: $rows[] = [ Chris@0: 'class' => ['views-group-title'], Chris@0: 'data' => $row, Chris@0: 'id' => 'views-group-title-' . $group_id, Chris@0: ]; Chris@0: Chris@0: // Row which will only appear if the group has nothing in it. Chris@0: $row = []; Chris@0: $class = 'group-' . (count($contents) ? 'populated' : 'empty'); Chris@0: $instructions = '' . t('No filters have been added.') . ' ' . t('Drag to add filters.') . ''; Chris@0: // When JavaScript is enabled, the button for removing the group (if it's Chris@0: // present) should be hidden, since it will be replaced by a link on the Chris@0: // client side. Chris@0: if (!empty($form['remove_groups'][$group_id]['#type']) && $form['remove_groups'][$group_id]['#type'] == 'submit') { Chris@0: $form['remove_groups'][$group_id]['#attributes']['class'][] = 'js-hide'; Chris@0: } Chris@0: $row[] = [ Chris@0: 'colspan' => 5, Chris@0: 'data' => [ Chris@0: ['#markup' => $instructions], Chris@0: $form['remove_groups'][$group_id], Chris@0: ], Chris@0: ]; Chris@0: $rows[] = [ Chris@0: 'class' => [ Chris@0: 'group-message', Chris@0: 'group-' . $group_id . '-message', Chris@0: $class, Chris@0: ], Chris@0: 'data' => $row, Chris@0: 'id' => 'views-group-' . $group_id, Chris@0: ]; Chris@0: } Chris@0: Chris@0: foreach ($contents as $id) { Chris@0: if (isset($form['filters'][$id]['name'])) { Chris@0: $row = []; Chris@0: $row[]['data'] = $form['filters'][$id]['name']; Chris@0: $form['filters'][$id]['weight']['#attributes']['class'] = ['weight']; Chris@0: $row[]['data'] = $form['filters'][$id]['weight']; Chris@0: $form['filters'][$id]['group']['#attributes']['class'] = ['views-group-select views-group-select-' . $group_id]; Chris@0: $row[]['data'] = $form['filters'][$id]['group']; Chris@0: $form['filters'][$id]['removed']['#attributes']['class'][] = 'js-hide'; Chris@0: Chris@0: $remove_link = [ Chris@0: '#type' => 'link', Chris@0: '#url' => Url::fromRoute(''), Chris@17: '#title' => new FormattableMarkup('@text', ['@text' => t('Remove')]), Chris@0: '#weight' => '1', Chris@0: '#options' => [ Chris@0: 'attributes' => [ Chris@0: 'id' => 'views-remove-link-' . $id, Chris@0: 'class' => [ Chris@0: 'views-hidden', Chris@0: 'views-button-remove', Chris@0: 'views-groups-remove-link', Chris@0: 'views-remove-link', Chris@0: ], Chris@0: 'alt' => t('Remove this item'), Chris@0: 'title' => t('Remove this item'), Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: $row[]['data'] = [ Chris@0: $form['filters'][$id]['removed'], Chris@0: $remove_link, Chris@0: ]; Chris@0: Chris@0: $row = [ Chris@0: 'data' => $row, Chris@0: 'class' => ['draggable'], Chris@0: 'id' => 'views-row-' . $id, Chris@0: ]; Chris@0: Chris@0: if ($group_id !== 'ungroupable') { Chris@0: $rows[] = $row; Chris@0: } Chris@0: else { Chris@0: $ungroupable_rows[] = $row; Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: if (!$variables['grouping']) { Chris@0: $form['filter_groups']['groups'][0]['#title'] = t('Operator'); Chris@0: } Chris@0: Chris@0: if (!empty($ungroupable_rows)) { Chris@0: $header = [ Chris@0: t('Ungroupable filters'), Chris@0: t('Weight'), Chris@0: [ Chris@0: 'data' => t('Group'), Chris@0: 'class' => ['views-hide-label'], Chris@0: ], Chris@0: [ Chris@0: 'data' => t('Remove'), Chris@0: 'class' => ['views-hide-label'], Chris@0: ], Chris@0: ]; Chris@0: $variables['ungroupable_table'] = [ Chris@0: '#type' => 'table', Chris@0: '#header' => $header, Chris@0: '#rows' => $ungroupable_rows, Chris@0: '#attributes' => [ Chris@0: 'id' => 'views-rearrange-filters-ungroupable', Chris@0: 'class' => ['arrange'], Chris@0: ], Chris@0: '#tabledrag' => [ Chris@0: [ Chris@0: 'action' => 'order', Chris@0: 'relationship' => 'sibling', Chris@0: 'group' => 'weight', Chris@17: ], Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: Chris@0: if (empty($rows)) { Chris@0: $rows[] = [['data' => t('No fields available.'), 'colspan' => '2']]; Chris@0: } Chris@0: Chris@0: // Set up tabledrag so that the weights are changed when rows are dragged. Chris@0: $variables['table'] = [ Chris@0: '#type' => 'table', Chris@0: '#rows' => $rows, Chris@0: '#attributes' => [ Chris@0: 'id' => 'views-rearrange-filters', Chris@0: 'class' => ['arrange'], Chris@0: ], Chris@0: '#tabledrag' => [ Chris@0: [ Chris@0: 'action' => 'order', Chris@0: 'relationship' => 'sibling', Chris@0: 'group' => 'weight', Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: Chris@0: // When JavaScript is enabled, the button for adding a new group should be Chris@0: // hidden, since it will be replaced by a link on the client side. Chris@0: $form['actions']['add_group']['#attributes']['class'][] = 'js-hide'; Chris@0: Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for style plugin table templates. Chris@0: * Chris@0: * Default template: views-ui-style-plugin-table.html.twig. Chris@0: * Chris@0: * @param array $variables Chris@0: * An associative array containing: Chris@0: * - form: A render element representing the form. Chris@0: */ Chris@0: function template_preprocess_views_ui_style_plugin_table(&$variables) { Chris@0: $form = $variables['form']; Chris@0: Chris@0: $header = [ Chris@0: t('Field'), Chris@0: t('Column'), Chris@0: t('Align'), Chris@0: t('Separator'), Chris@0: [ Chris@0: 'data' => t('Sortable'), Chris@0: 'align' => 'center', Chris@0: ], Chris@0: [ Chris@0: 'data' => t('Default order'), Chris@0: 'align' => 'center', Chris@0: ], Chris@0: [ Chris@0: 'data' => t('Default sort'), Chris@0: 'align' => 'center', Chris@0: ], Chris@0: [ Chris@0: 'data' => t('Hide empty column'), Chris@0: 'align' => 'center', Chris@0: ], Chris@0: [ Chris@0: 'data' => t('Responsive'), Chris@0: 'align' => 'center', Chris@0: ], Chris@0: ]; Chris@0: $rows = []; Chris@0: foreach (Element::children($form['columns']) as $id) { Chris@0: $row = []; Chris@0: $row[]['data'] = $form['info'][$id]['name']; Chris@0: $row[]['data'] = $form['columns'][$id]; Chris@0: $row[]['data'] = $form['info'][$id]['align']; Chris@0: $row[]['data'] = $form['info'][$id]['separator']; Chris@0: Chris@0: if (!empty($form['info'][$id]['sortable'])) { Chris@0: $row[] = [ Chris@0: 'data' => $form['info'][$id]['sortable'], Chris@0: 'align' => 'center', Chris@0: ]; Chris@0: $row[] = [ Chris@0: 'data' => $form['info'][$id]['default_sort_order'], Chris@0: 'align' => 'center', Chris@0: ]; Chris@0: $row[] = [ Chris@0: 'data' => $form['default'][$id], Chris@0: 'align' => 'center', Chris@0: ]; Chris@0: } Chris@0: else { Chris@0: $row[] = ''; Chris@0: $row[] = ''; Chris@0: $row[] = ''; Chris@0: } Chris@0: $row[] = [ Chris@0: 'data' => $form['info'][$id]['empty_column'], Chris@0: 'align' => 'center', Chris@0: ]; Chris@0: $row[] = [ Chris@0: 'data' => $form['info'][$id]['responsive'], Chris@0: 'align' => 'center', Chris@0: ]; Chris@0: $rows[] = $row; Chris@0: } Chris@0: Chris@0: // Add the special 'None' row. Chris@0: $rows[] = [['data' => t('None'), 'colspan' => 6], ['align' => 'center', 'data' => $form['default'][-1]], ['colspan' => 2]]; Chris@0: Chris@0: // Unset elements from the form array that are used to build the table so that Chris@0: // they are not rendered twice. Chris@0: unset($form['default']); Chris@0: unset($form['info']); Chris@0: unset($form['columns']); Chris@0: Chris@0: $variables['table'] = [ Chris@0: '#type' => 'table', Chris@0: '#theme' => 'table__views_ui_style_plugin_table', Chris@0: '#header' => $header, Chris@0: '#rows' => $rows, Chris@0: ]; Chris@0: $variables['form'] = $form; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares variables for views UI view preview section templates. Chris@0: * Chris@0: * Default template: views-ui-view-preview-section.html.twig. Chris@0: * Chris@0: * @param array $variables Chris@0: * An associative array containing: Chris@0: * - view: The view object. Chris@0: * - section: The section name of a View (e.g. title, rows or pager). Chris@0: */ Chris@0: function template_preprocess_views_ui_view_preview_section(&$variables) { Chris@0: switch ($variables['section']) { Chris@0: case 'title': Chris@0: $variables['title'] = t('Title'); Chris@0: $links = views_ui_view_preview_section_display_category_links($variables['view'], 'title', $variables['title']); Chris@0: break; Chris@0: case 'header': Chris@0: $variables['title'] = t('Header'); Chris@0: $links = views_ui_view_preview_section_handler_links($variables['view'], $variables['section']); Chris@0: break; Chris@0: case 'empty': Chris@0: $variables['title'] = t('No results behavior'); Chris@0: $links = views_ui_view_preview_section_handler_links($variables['view'], $variables['section']); Chris@0: break; Chris@0: case 'exposed': Chris@0: // @todo Sorts can be exposed too, so we may need a better title. Chris@0: $variables['title'] = t('Exposed Filters'); Chris@0: $links = views_ui_view_preview_section_display_category_links($variables['view'], 'exposed_form_options', $variables['title']); Chris@0: break; Chris@0: case 'rows': Chris@0: // @todo The title needs to depend on what is being viewed. Chris@0: $variables['title'] = t('Content'); Chris@0: $links = views_ui_view_preview_section_rows_links($variables['view']); Chris@0: break; Chris@0: case 'pager': Chris@0: $variables['title'] = t('Pager'); Chris@0: $links = views_ui_view_preview_section_display_category_links($variables['view'], 'pager_options', $variables['title']); Chris@0: break; Chris@0: case 'more': Chris@0: $variables['title'] = t('More'); Chris@0: $links = views_ui_view_preview_section_display_category_links($variables['view'], 'use_more', $variables['title']); Chris@0: break; Chris@0: case 'footer': Chris@0: $variables['title'] = t('Footer'); Chris@0: $links = views_ui_view_preview_section_handler_links($variables['view'], $variables['section']); Chris@0: break; Chris@0: case 'attachment_before': Chris@0: // @todo: Add links to the attachment configuration page. Chris@0: $variables['title'] = t('Attachment before'); Chris@0: break; Chris@0: case 'attachment_after': Chris@0: // @todo: Add links to the attachment configuration page. Chris@0: $variables['title'] = t('Attachment after'); Chris@0: break; Chris@0: } Chris@0: Chris@0: if (isset($links)) { Chris@0: $build = [ Chris@0: '#theme' => 'links__contextual', Chris@0: '#links' => $links, Chris@0: '#attributes' => ['class' => ['contextual-links']], Chris@0: '#attached' => [ Chris@0: 'library' => ['contextual/drupal.contextual-links'], Chris@0: ], Chris@0: ]; Chris@0: $variables['links'] = $build; Chris@0: } Chris@0: }