Skip to content

Events

PHP Events

The following events are available in PHP.

Partial

These events are used to work with available Partials.

offline.boxes.beforeFilterPartials

Called once are partials have been processed.

php
\Event::listen(
    \OFFLINE\Boxes\Classes\Events::BEFORE_FILTER_PARTIALS,
    function (\Illuminate\Support\Collection $partials) {
        info('before filter partials', [
            'count' => $partials->count()
        ]);
    }
);

offline.boxes.filterPartials

Use this event to remove or add partials to the list of available partials.

php
\Event::listen(
    \OFFLINE\Boxes\Classes\Events::FILTER_PARTIALS,
    function (\Illuminate\Support\Collection $partials) {
        // Remove a partial.
        $partials->forget('some-handle');
    }
);

Box

These events are used to interact with a rendered Box.

offline.boxes.beforeBoxRender

Called before a Box model is rendered.

php
Event::listen(
    \OFFLINE\Boxes\Classes\Events::BEFORE_BOX_RENDER,
    function(\OFFLINE\Boxes\Models\Box $box, \OFFLINE\Boxes\Classes\Partial\RenderContext $context) {}
);

offline.boxes.afterBoxRender

Called after a Box model was rendered.

php
Event::listen(
    \OFFLINE\Boxes\Classes\Events::AFTER_BOX_RENDER,
    function(\OFFLINE\Boxes\Models\Box $box, \OFFLINE\Boxes\Classes\Partial\RenderContext $context, string &$contents) {}
);

offline.boxes.extendBoxScaffoldingClasses

Use this event to add custom classes to the Box scaffolding (.oc-box elements).

php
Event::listen(
    \OFFLINE\Boxes\Classes\Events::EXTEND_BOX_SCAFFOLDING_CLASSES,
    function(\OFFLINE\Boxes\Models\Box $box, \OFFLINE\Boxes\Classes\Partial\RenderContext $context) {
        return ['my-custom-class'];
    }
);

Page

These events are used to interact with a rendered Page.

offline.boxes.beforePageRender

Called before a Page model is rendered.

The $nestedBoxes variable holds the effective Box structure that will be rendered. You can use this to add or remove Boxes from the page before it is rendered.

php
Event::listen(
    \OFFLINE\Boxes\Classes\Events::BEFORE_PAGE_RENDER,
    function(\OFFLINE\Boxes\Models\Page $page, \OFFLINE\Boxes\Classes\Partial\RenderContext $context, \October\Rain\Database\Collection $nestedBoxes) {}
);

offline.boxes.afterPageRender

Called after a Page model was rendered.

php
Event::listen(
    \OFFLINE\Boxes\Classes\Events::AFTER_PAGE_RENDER,
    function(\OFFLINE\Boxes\Models\Page $page, \OFFLINE\Boxes\Classes\Partial\RenderContext $context, \October\Rain\Database\Collection $nestedBoxes, string &$contents) {}
);

Editor

These events allow you to change the backend Editor behavior.

offline.boxes.editorRender

Called when the Boxes Editor is rendered.

php
Event::listen(
    \OFFLINE\Boxes\Classes\Events::EDITOR_RENDER,
    function(\OFFLINE\Boxes\Components\BoxesPageEditor $editor) {}
);

offline.boxes.editorExtendPages

Called when the Boxes Editor is set up. The event can be used to filter or extend the pages list. It receives a Collection instance with the nested pages structure.

php
Event::listen(
    \OFFLINE\Boxes\Classes\Events::EDITOR_EXTEND_PAGES,
    function (&$pages) {
        // Only display pages that are hidden in the navigation.
        $pages = $pages->where('is_hidden_in_navigation', true);
    }
);

offline.boxes.filterLayouts

Use this event to remove or add certain layouts from the dropdown when editing a Page.

php
\Event::listen(
    \OFFLINE\Boxes\Classes\Events::FILTER_LAYOUTS,
    function (\October\Rain\Support\Collection $partials) {
        // Remove a layout.
        $partials->forget('some-layout');
    }
);

JS Events

The following events are available in JS.

Editor

offline.boxes.editorRefreshed (JS)

Called, when the preview of the Boxes Editor was refreshed.

js
window.document.addEventListener('offline.boxes.editorRefreshed', function (e) {
    console.log('The editor was refreshed');
});