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);
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user