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); $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;
}
} }

View File

@@ -207,6 +207,16 @@ form:
type: bool type: bool
help: Ask the user confirmation when deleting a page help: Ask the user confirmation when deleting a page
hide_page_types:
type: array
label: Hide page types in Admin
value_only: true
hide_modular_page_types:
type: array
label: Hide modular page types in Admin
value_only: true
Dashboard: Dashboard:
type: section type: section
title: Dashboard title: Dashboard

View File

@@ -38,7 +38,7 @@ form:
label: PLUGIN_ADMIN.MODULAR_TEMPLATE label: PLUGIN_ADMIN.MODULAR_TEMPLATE
help: PLUGIN_ADMIN.PAGE_FILE_HELP help: PLUGIN_ADMIN.PAGE_FILE_HELP
default: default default: default
data-options@: '\Grav\Common\Page\Pages::modularTypes' data-options@: '\Grav\Plugin\AdminPlugin::pagesModularTypes'
validate: validate:
required: true required: true

View File

@@ -86,7 +86,7 @@ form:
classes: fancy classes: fancy
label: PLUGIN_ADMIN.MODULAR_TEMPLATE label: PLUGIN_ADMIN.MODULAR_TEMPLATE
default: default default: default
data-options@: '\Grav\Common\Page\Pages::modularTypes' data-options@: '\Grav\Plugin\AdminPlugin::pagesModularTypes'
validate: validate:
required: true required: true

View File

@@ -39,7 +39,7 @@ form:
classes: fancy classes: fancy
label: PLUGIN_ADMIN.PAGE_FILE label: PLUGIN_ADMIN.PAGE_FILE
help: PLUGIN_ADMIN.PAGE_FILE_HELP help: PLUGIN_ADMIN.PAGE_FILE_HELP
data-options@: '\Grav\Common\Page\Pages::types' data-options@: '\Grav\Plugin\AdminPlugin::pagesTypes'
data-default@: '\Grav\Plugin\Admin\Admin::getLastPageName' data-default@: '\Grav\Plugin\Admin\Admin::getLastPageName'
validate: validate:
required: true required: true

View File

@@ -87,7 +87,7 @@ form:
label: PLUGIN_ADMIN.DISPLAY_TEMPLATE label: PLUGIN_ADMIN.DISPLAY_TEMPLATE
help: PLUGIN_ADMIN.DISPLAY_TEMPLATE_HELP help: PLUGIN_ADMIN.DISPLAY_TEMPLATE_HELP
default: default default: default
data-options@: '\Grav\Common\Page\Pages::types' data-options@: '\Grav\Plugin\AdminPlugin::pagesTypes'
validate: validate:
required: true required: true