getgrav / getgrav/grav-plugin-admin

Request: Send current selected page to plugins to add/hide page blueprints.

Open
#1,822 3 comments 0 reactions 1 assignee Claimed by @mahagr View on GitHub
question
Dominant language
PHP
Stars
377
Forks
225
Avg merge
11h 51m
Merged PRs (30d)
4

Description

It is quite common for a plugin to check whether it should activate or not by checking the current uri/path against an 'enable_on_routes' config variable.

In Admin, this technique is cumbersome to implement (but doable) because the translated route of the selected page is not easily available.

This leads to the following issues:
- When multiple plugins have page blueprints for the same page type, the tabs-bar get cluttered with tabs for each plugin.
- Also when saving the page, the default data for each plugin gets written into the page's header.

Solution:
- Pass the page selected for editing to the plugin. The Page::route() can then easily be tested against the array of 'enable_on_routes'. When valid, the plugin can call Types::scanBlueprints() to make its blueprints available in the page's tab-bar.

Suggestion:
- Use existing 'onAdminPage' event in AdminPlugin::onPagesInitialized() and add selected page to the event:
```
$event = new Event([
'page' => $page,
'selectedPage' => $this->admin->page(),
]);
$event = $this->grav->fireEvent('onAdminPage', $event);
```
- Or create new dedicated event when page is selected.
```
$event = $this->grav->fireEvent('onAdminPageSelected', $event);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.