3 namespace Drupal\bootstrap\Plugin\Preprocess;
5 use Drupal\bootstrap\Utility\Variables;
9 * Pre-processes variables for the "filter_tips" theme hook.
11 * @ingroup plugins_preprocess
13 * @BootstrapPreprocess("filter_tips",
14 * replace = "template_preprocess_filter_tips"
17 class FilterTips extends PreprocessBase implements PreprocessInterface {
22 public function preprocessVariables(Variables $variables) {
23 /** @var \Drupal\filter\FilterFormatInterface $current_format */
24 $current_format = \Drupal::routeMatch()->getParameter('filter_format');
25 $current_format_id = $current_format ? $current_format->id() : FALSE;
27 // Create a place holder for the tabs.
29 '#theme' => 'item_list__filter_tips__tabs',
32 'class' => ['nav', 'nav-tabs', 'filter-formats'],
37 // Create a placeholder for the panes.
39 '#theme_wrappers' => ['container__filter_tips__panes'],
41 'class' => ['tab-content'],
45 foreach (filter_formats(\Drupal::currentUser()) as $format_id => $format) {
46 // Set the current format ID to the first format.
47 if (!$current_format_id) {
48 $current_format_id = $format_id;
53 '#title' => $format->label(),
54 '#url' => Url::fromRoute('filter.tips', ['filter_format' => $format_id]),
57 'data-toggle' => 'tab',
58 'data-target' => "#$format_id",
61 if ($current_format_id === $format_id) {
62 $tab['#wrapper_attributes']['class'][] = 'active';
64 $build['tabs']['#items'][] = $tab;
68 // Iterate over each format's enabled filters.
69 /** @var \Drupal\filter\Plugin\FilterBase $filter */
70 foreach ($format->filters() as $name => $filter) {
71 // Ignore filters that are not enabled.
72 if (!$filter->status) {
76 $tip = $filter->tips(TRUE);
78 $tips[] = ['#markup' => $tip];
82 // Construct the pane.
84 '#theme_wrappers' => ['container__filter_tips'],
86 'class' => ['tab-pane', 'fade'],
90 '#theme' => 'item_list',
94 if ($current_format_id === $format_id) {
95 $pane['#attributes']['class'][] = 'active';
96 $pane['#attributes']['class'][] = 'in';
98 $build['panes'][] = $pane;
101 $variables['tips'] = $build;