3 namespace Drupal\views_bootstrap;
5 use Drupal\Component\Utility\Html;
6 use Drupal\views\ViewExecutable;
9 * The primary class for the Views Bootstrap module.
11 * Provides many helper methods.
15 class ViewsBootstrap {
18 * Returns the theme hook definition information.
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',
26 'file' => 'views_bootstrap.theme.inc',
28 $hooks['views_bootstrap_carousel'] = [
29 'preprocess functions' => [
30 'template_preprocess_views_bootstrap_carousel',
31 'template_preprocess_views_view_carousel',
33 'file' => 'views_bootstrap.theme.inc',
35 $hooks['views_bootstrap_grid'] = [
36 'preprocess functions' => [
37 'template_preprocess_views_bootstrap_grid',
38 'template_preprocess_views_view_grid',
40 'file' => 'views_bootstrap.theme.inc',
42 $hooks['views_bootstrap_list_group'] = [
43 'preprocess functions' => [
44 'template_preprocess_views_bootstrap_list_group',
45 'template_preprocess_views_view_list_group',
47 'file' => 'views_bootstrap.theme.inc',
49 $hooks['views_bootstrap_media_object'] = [
50 'preprocess functions' => [
51 'template_preprocess_views_bootstrap_media_object',
52 'template_preprocess_views_view_media_object',
54 'file' => 'views_bootstrap.theme.inc',
56 $hooks['views_bootstrap_tab'] = [
57 'preprocess functions' => [
58 'template_preprocess_views_bootstrap_tab',
59 'template_preprocess_views_view_tab',
61 'file' => 'views_bootstrap.theme.inc',
63 $hooks['views_bootstrap_table'] = [
64 'preprocess functions' => [
65 'template_preprocess_views_bootstrap_table',
66 'template_preprocess_views_view_table',
68 'file' => 'views_bootstrap.theme.inc',
75 * Get unique element id.
77 * @param \Drupal\views\ViewExecutable $view
78 * A ViewExecutable object.
81 * A unique id for an HTML element.
83 public static function getUniqueId(ViewExecutable $view) {
84 $id = $view->storage->id() . '-' . $view->current_display;
85 return Html::getUniqueId('views-bootstrap-' . $id);
89 * Get the number of items from the column class string.
92 * Bootstrap grid size xs|sm|md|lg.
95 * Number of columns in a 12 column grid or false.
97 public static function getColSize($size) {
98 if (preg_match('~col-[a-z]{2}-([0-9]*)~', $size, $matches)) {
99 return 12 / $matches[1];