lapis / opening-hours
Opening hours for Lapis CMS: a block type, closed days, a toolbar panel and schema.org JSON-LD
Requires
- php: ^8.5
- lapis/cms: ^1.0
Requires (Dev)
- carthage-software/mago: ^1.62
- pestphp/pest: ^5.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Opening hours for Lapis CMS: edited on the page like any other block, with closed days, a toolbar panel and schema.org JSON-LD for search engines.
composer require lapis/opening-hours
Lapis finds it by itself (every installed package that requires lapis/cms), and ./lapis plugins lists it. Then, in a template:
<x-block type="hours" name="opening_hours" global>Opening hours coming soon.</x-block> <p>{{ $site->hours_note }}</p>
It adds no pages: the hours go wherever the site puts the block (a contact page, the footer). The closed days are a data table, read like the site's own:
<?php $closed = $cms->data('closed-days')->where('day', '>=', date('Y-m-d'))->orderBy('day')->get(); ?> <ul><li :foreach="$closed as $day">{{ $day['day'] }}: {{ $day['reason'] }}</li></ul>
What it adds
| What | Where |
|---|---|
an hours block type: days with opening and closing times or "closed", edited in the editor's panel with fields (no JavaScript), rendered on the server, cleaned on save |
OpeningHoursPlugin::register(), src/Hours.php |
a setting (hours_note, e.g. "Closed in August") in the Settings panel, in its own group |
OpeningHoursPlugin::register() |
a toolbar panel for the note (More → Opening hours), declared with $lapis->panel() |
OpeningHoursPlugin::register() |
schema.org OpeningHoursSpecification on every page once hours are published |
src/AddOpeningHoursJsonLd.php |
a data table, closed-days (holidays, vacations), edited in the Data panel |
OpeningHoursPlugin::register() |
an X-Lapis-Plugin response header on every page, through middleware |
OpeningHoursPlugin::register() |
The texts go through Tempest's translator, under opening_hours.*: English and Hungarian are included (lang/messages.en.yml, lang/messages.hu.yml). A site translates them further, or changes single texts, in its own app/localization.<locale>.yml.
Switch it off without removing it: lapis.config.php → plugins: ['opening-hours' => false].
As an example
It uses most extension points of the plugin API, without a line of JavaScript: the editing is described in PHP with fields. That makes it a good start for your own plugin: copy it, rename the package, the namespace and name().
Development
Run the tests:
composer install
vendor/bin/pest # runs on a small site in tests/site, with this plugin installed
The tests use Lapis\Testing\LapisTestCase (assertPluginLoaded(), renderBlock(), editorState(), api()).
License
MIT