More tidying.
[yaffs-website] / web / modules / contrib / views_bootstrap / src / ViewsBootstrap.php
1 <?php
2
3 namespace Drupal\views_bootstrap;
4
5 use Drupal\Component\Utility\Html;
6 use Drupal\views\ViewExecutable;
7
8 /**
9  * The primary class for the Views Bootstrap module.
10  *
11  * Provides many helper methods.
12  *
13  * @ingroup utility
14  */
15 class ViewsBootstrap {
16
17   /**
18    * Returns the theme hook definition information.
19    */
20   public static function getThemeHooks() {
21     $hooks['views_bootstrap_accordion'] = [
22       'preprocess functions' => [
23         'template_preprocess_views_bootstrap_accordion',
24         'template_preprocess_views_view_accordion',
25       ],
26       'file' => 'views_bootstrap.theme.inc',
27     ];
28     $hooks['views_bootstrap_carousel'] = [
29       'preprocess functions' => [
30         'template_preprocess_views_bootstrap_carousel',
31         'template_preprocess_views_view_carousel',
32       ],
33       'file' => 'views_bootstrap.theme.inc',
34     ];
35     $hooks['views_bootstrap_grid'] = [
36       'preprocess functions' => [
37         'template_preprocess_views_bootstrap_grid',
38         'template_preprocess_views_view_grid',
39       ],
40       'file' => 'views_bootstrap.theme.inc',
41     ];
42     $hooks['views_bootstrap_list_group'] = [
43       'preprocess functions' => [
44         'template_preprocess_views_bootstrap_list_group',
45         'template_preprocess_views_view_list_group',
46       ],
47       'file' => 'views_bootstrap.theme.inc',
48     ];
49     $hooks['views_bootstrap_media_object'] = [
50       'preprocess functions' => [
51         'template_preprocess_views_bootstrap_media_object',
52         'template_preprocess_views_view_media_object',
53       ],
54       'file' => 'views_bootstrap.theme.inc',
55     ];
56     $hooks['views_bootstrap_tab'] = [
57       'preprocess functions' => [
58         'template_preprocess_views_bootstrap_tab',
59         'template_preprocess_views_view_tab',
60       ],
61       'file' => 'views_bootstrap.theme.inc',
62     ];
63     $hooks['views_bootstrap_table'] = [
64       'preprocess functions' => [
65         'template_preprocess_views_bootstrap_table',
66         'template_preprocess_views_view_table',
67       ],
68       'file' => 'views_bootstrap.theme.inc',
69     ];
70
71     return $hooks;
72   }
73
74   /**
75    * Get unique element id.
76    *
77    * @param \Drupal\views\ViewExecutable $view
78    *   A ViewExecutable object.
79    *
80    * @return string
81    *   A unique id for an HTML element.
82    */
83   public static function getUniqueId(ViewExecutable $view) {
84     $id = $view->storage->id() . '-' . $view->current_display;
85     return Html::getUniqueId('views-bootstrap-' . $id);
86   }
87
88   /**
89    * Get the number of items from the column class string.
90    *
91    * @param string $size
92    *   Bootstrap grid size xs|sm|md|lg.
93    *
94    * @return int|false
95    *   Number of columns in a 12 column grid or false.
96    */
97   public static function getColSize($size) {
98     if (preg_match('~col-[a-z]{2}-([0-9]*)~', $size, $matches)) {
99       return 12 / $matches[1];
100     }
101
102     return FALSE;
103   }
104
105 }