mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-14 09:16:05 +01:00
Feature/page types events (#1105)
* Add function which replaces types and modularTypes * Replace Pages statics with AdminPlugin statics * Use Event's built-in items rather than data member * Add configration for hiding page types
This commit is contained in:
50
admin.php
50
admin.php
@@ -823,4 +823,54 @@ class AdminPlugin extends Plugin
|
||||
$admin->addPermissions($permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to replace Pages::Types()
|
||||
* and to provide an event to manipulate the data
|
||||
*
|
||||
* Dispatches 'onAdminPageTypes' event
|
||||
* with 'types' data member which is a
|
||||
* reference to the data
|
||||
*/
|
||||
public static function pagesTypes()
|
||||
{
|
||||
$types = Pages::types();
|
||||
|
||||
// First filter by configuration
|
||||
$hideTypes = Grav::instance()['config']->get('plugins.admin.hide_page_types', []);
|
||||
foreach ($hideTypes as $type) {
|
||||
unset($types[$type]);
|
||||
}
|
||||
|
||||
// Allow manipulating of the data by event
|
||||
$e = new Event(['types' => &$types]);
|
||||
Grav::instance()->fireEvent('onAdminPageTypes', $e);
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to replace Pages::modularTypes()
|
||||
* and to provide an event to manipulate the data
|
||||
*
|
||||
* Dispatches 'onAdminModularPageTypes' event
|
||||
* with 'types' data member which is a
|
||||
* reference to the data
|
||||
*/
|
||||
public static function pagesModularTypes()
|
||||
{
|
||||
$types = Pages::modularTypes();
|
||||
|
||||
// First filter by configuration
|
||||
$hideTypes = Grav::instance()['config']->get('plugins.admin.hide_modular_page_types', []);
|
||||
foreach ($hideTypes as $type) {
|
||||
unset($types[$type]);
|
||||
}
|
||||
|
||||
// Allow manipulating of the data by event
|
||||
$e = new Event(['types' => &$types]);
|
||||
Grav::instance()->fireEvent('onAdminModularPageTypes', $e);
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user