4 * Contains \Drupal\bootstrap\Plugin\Preprocess\FilterTips.
7 namespace Drupal\bootstrap\Plugin\Preprocess;
9 use Drupal\bootstrap\Annotation\BootstrapPreprocess;
10 use Drupal\bootstrap\Utility\Variables;
14 * Pre-processes variables for the "filter_tips" theme hook.
16 * @ingroup plugins_preprocess
18 * @BootstrapPreprocess("filter_tips",
19 * replace = "template_preprocess_filter_tips"
22 class FilterTips extends PreprocessBase implements PreprocessInterface {
27 public function preprocessVariables(Variables $variables) {
28 /** @var \Drupal\filter\FilterFormatInterface $current_format */
29 $current_format = \Drupal::routeMatch()->getParameter('filter_format');
30 $current_format_id = $current_format ? $current_format->id() : FALSE;
32 // Create a place holder for the tabs.
34 '#theme' => 'item_list__filter_tips__tabs',
37 'class' => ['nav', 'nav-tabs', 'filter-formats'],
42 // Create a placeholder for the panes.
44 '#theme_wrappers' => ['container__filter_tips__panes'],
46 'class' => ['tab-content'],
50 foreach (filter_formats(\Drupal::currentUser()) as $format_id => $format) {
51 // Set the current format ID to the first format.
52 if (!$current_format_id) {
53 $current_format_id = $format_id;
58 '#title' => $format->label(),
59 '#url' => Url::fromRoute('filter.tips', ['filter_format' => $format_id]),
62 'data-toggle' => 'tab',
63 'data-target' => "#$format_id",
66 if ($current_format_id === $format_id) {
67 $tab['#wrapper_attributes']['class'][] = 'active';
69 $build['tabs']['#items'][] = $tab;
73 // Iterate over each format's enabled filters.
74 /** @var \Drupal\filter\Plugin\FilterBase $filter */
75 foreach ($format->filters() as $name => $filter) {
76 // Ignore filters that are not enabled.
77 if (!$filter->status) {
81 $tip = $filter->tips(TRUE);
83 $tips[] = ['#markup' => $tip];
87 // Construct the pane.
89 '#theme_wrappers' => ['container__filter_tips'],
91 'class' => ['tab-pane', 'fade'],
95 '#theme' => 'item_list',
99 if ($current_format_id === $format_id) {
100 $pane['#attributes']['class'][] = 'active';
101 $pane['#attributes']['class'][] = 'in';
103 $build['panes'][] = $pane;
106 $variables['tips'] = $build;