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:
Dávid Szabó
2017-06-27 20:43:12 +02:00
committed by Andy Miller
parent 2a3fef0435
commit ee2051eba6
6 changed files with 64 additions and 4 deletions

View File

@@ -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;
}
}