Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Backend theme system #2639

Merged
merged 7 commits into from
Mar 20, 2021
Merged

WIP: Backend theme system #2639

merged 7 commits into from
Mar 20, 2021

Conversation

ssddanbrown
Copy link
Member

@ssddanbrown ssddanbrown commented Mar 16, 2021

Overview

This essentially allows customization of back-end components using the theme folder that we already have for views/translations/icons. Using this you'll be able to hook into specific back-end events to add & modify functionality for your own use-case.

This system will look for a functions.php file within your configure theme, and run that during application boot. Within this file you could register event handlers.

The events available, and their parameters and return options, will be documented within the codebase within a class that holds static references for the event names. This can be previewed here: https://github.com/BookStackApp/BookStack/blob/backend_theme_system/app/Theming/ThemeEvents.php

Multiple event handlers could be added per event, but if a handler returns a non-null value then no further handlers will be called during that event emission. This allows return values of handlers to be used where required with relative ease.

The initial implementation will be considered unstable with the intention of being open to feedback, then in the future we'll deem this semi-stable, with the core event system being maintained but the event details being subject to change over BookStack releases as to limit core project maintenance and development burden.

Usage Examples

  • Customization of the markdown renderer.
  • Custom logic implementation on boot.
  • Custom events on user login/register.
  • Custom middleware-style logic with ease.
  • Custom socialite provider additions.

Todo

  • Add and test events to match the above examples for an initial implementation.
  • Add some documentation for this system with a md file within the project devdocs folder.

Example theme functions.php file

<?php

use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;
use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Extension\Footnote\FootnoteExtension;

Theme::listen(ThemeEvents::APP_BOOT, function($app) {
    \Log::info('app-boot');
});

Theme::listen(ThemeEvents::COMMONMARK_ENVIRONMENT_CONFIGURE, function(ConfigurableEnvironmentInterface $environment) {
    $environment->addExtension(new FootnoteExtension());
});

Allows customization of back-end components via event-driven handling
from the theme folder.
@ssddanbrown ssddanbrown added this to the v0.32.0 milestone Mar 20, 2021
@ssddanbrown ssddanbrown merged commit 44a293f into master Mar 20, 2021
@ssddanbrown ssddanbrown deleted the backend_theme_system branch August 5, 2021 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant