Skip to content

Commit

Permalink
Issue #32: Fix broken views preview (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoxela committed Sep 6, 2023
1 parent ded6e11 commit 8b75bbb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .github/phpstan/baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ parameters:
count: 1
path: ../../fullcalendar_views.module

-
message: "#^Function fullcalendar_views_preprocess_page\\(\\) has no return type specified\\.$#"
count: 1
path: ../../fullcalendar_views.module

-
message: "#^Function fullcalendar_views_preprocess_page\\(\\) has parameter \\$variables with no type specified\\.$#"
count: 1
path: ../../fullcalendar_views.module

-
message: "#^Function fullcalendar_views_preprocess_views_ui_view_preview_section\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
17 changes: 17 additions & 0 deletions fullcalendar_views.module
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ function fullcalendar_views_preprocess_views_ui_view_preview_section(&$variables
}
}

/**
* Implements hook_preprocess_HOOK().
*/
function fullcalendar_views_preprocess_page(&$variables) {
// Inject js and css for calendar previews on every potential candidate, even
// if not needed.
// @todo is there a smarter way (without breaking ajax)?
$pattern = '#admin/structure/views/view/.+/configure/page#';
$path = current_path();
if (preg_match($pattern, $path) === 1) {
$module_path = backdrop_get_path('module', 'fullcalendar_views');
backdrop_add_library('fullcalendar_lib', 'fullcalendar');
backdrop_add_js($module_path . '/js/fullcalendar-views.js');
backdrop_add_css($module_path . '/css/fullcalendar-views.css');
}
}

/**
* Helper function to return supported field API types.
*
Expand Down
13 changes: 9 additions & 4 deletions views/fullcalendar_views_style_calendar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,15 @@ class FullcalendarViewsStyleCalendar extends views_plugin_style {
backdrop_add_library('system', 'ui.tooltip');
$settings['hasTooltips'] = TRUE;
}
$module_path = backdrop_get_path('module', 'fullcalendar_views');
backdrop_add_library('fullcalendar_lib', 'fullcalendar');
backdrop_add_js($module_path . '/js/fullcalendar-views.js');
backdrop_add_css($module_path . '/css/fullcalendar-views.css');

// The ajax preview breaks when adding those in live preview.
// @see views_fullcalendar_preprocess_page
if (empty($this->view->live_preview)) {
$module_path = backdrop_get_path('module', 'fullcalendar_views');
backdrop_add_library('fullcalendar_lib', 'fullcalendar');
backdrop_add_js($module_path . '/js/fullcalendar-views.js');
backdrop_add_css($module_path . '/css/fullcalendar-views.css');
}

$id = $view->name . ucfirst($view->current_display);
$setup = array(
Expand Down

0 comments on commit 8b75bbb

Please sign in to comment.