Calendar Block
The Calendar block renders a Carousel List of events with progressive enhancement powered by REST routes and modular templates. It pairs server-rendered HTML with scoped JavaScript so filtering, pagination, and navigation stay fast and accessible.
Carousel List Display
- Day grouping: Events are grouped by date using
date-group.phpso each brochure of upcoming or past days remains obvious. - Time gap separators:
time-gap-separator.phpinserts visual dividers when there are large gaps between event start times. - Horizontal scroll: CSS delivers native touch/trackpad scrolling with chevrons, dots, and active state indicators handled by the carousel module.
- Compact cards:
event-item.phprenders each event summary with taxonomy badges, time, and CTA buttons linked to more details.
Server Templates & Helpers
event-item.php,date-group.php,navigation.php,pagination.php,results-counter.php,no-events.php,filter-bar.php,time-gap-separator.php, andmodal/taxonomy-filter.phplive underinc/Blocks/Calendar/templatesand are orchestrated byinc/Core/Template_Loader.inc/Core/Taxonomy_Helperbuilds hierarchical term data and counts for each template, whileTaxonomy_Badgesrenders badge markup that respectsdatamachine_events_badge_wrapper_classes,datamachine_events_badge_classes, anddatamachine_events_more_info_button_classesfilters.- The filter modal uses taxonomy helpers to surface dynamic dependencies, counts, and active state indicators before handing control to the filter modal module.
REST API Support
GET /wp-json/datamachine/v1/events/calendar: Calendar controller returnshtml,pagination,navigation,counter, andsuccessfragments. It acceptsevent_search,date_start,date_end,tax_filter(object),archive_taxonomy,archive_term_id,paged, andpast.GET /wp-json/datamachine/v1/events/filters: Filters controller lists taxonomy terms with counts, dependency hints, and hierarchy metadata; acceptsactive,context,date_start,date_end, andpastso the modal shows accurate controls that respect the current date logic.- Progressive enhancement: server-rendered HTML works without JavaScript; when scripts run they fetch these routes for instant filtering while preserving their shareable URL state.
JavaScript Modules
inc/Blocks/Calendar/src/frontend.jsbootstraps each.datamachine-events-calendar, wiring the following modules:modules/api-client.jshandles REST requests and swaps fragments.modules/carousel.jsdetects overflow, updates dots, and powers chevrons (with click-and-hold support).modules/date-picker.jsintegrates Flatpickr for date range filters.modules/filter-modal.jskeeps the taxonomy modal accessible and debounced when filters change.modules/filter-state.jscentralizes filter state management across URL params, localStorage, and DOM with regex support for both indexed (tax_filter[taxonomy][0]) and non-indexed (tax_filter[taxonomy][]) array syntax.modules/navigation.jspowers past/upcoming toggles, calendar navigation, and pagination link handling.modules/state.jsserializes query parameters, manages history state, and debounces search input.
Filter Modal & Taxonomy Helpers
The modal is populated via Taxonomy_Helper, which computes term hierarchies, counts, and datamachine_events_excluded_taxonomies filters, ensuring the modal only shows the taxonomies the block exposes. When filters change, the modal calls the API client to refresh fragments without reloading the page.
Pagination
- Day-based pagination lives in
inc/Blocks/Calendar/Pagination.phpand produces five full days per page. - Filters
datamachine_events_pagination_wrapper_classesanddatamachine_events_pagination_argsallow theme or plugin code to modify wrapper classes or pass additionalpaginate_linksarguments. - Pagination fragments come from the REST calendar response so the JavaScript can replace controls while keeping server-rendered markup for non-JS contexts.
Progressive Enhancement
Calendar rendering works without any JavaScript; templates are server-rendered during the initial request, making the block SEO-friendly and accessible. JavaScript hooks into the REST API for smoother filtering, search debouncing (500ms), history support, and full control over pagination without forcing reloads.