winter/modules/cms/ServiceProvider.php

207 lines
8.2 KiB
PHP
Raw Normal View History

<?php namespace Cms;
2014-05-14 23:24:20 +10:00
use Lang;
use Event;
2014-05-14 23:24:20 +10:00
use Backend;
use BackendMenu;
use BackendAuth;
use Backend\Classes\WidgetManager;
use October\Rain\Support\ModuleServiceProvider;
2014-07-19 13:05:50 +11:00
use System\Classes\SettingsManager;
use System\Classes\CombineAssets;
use Cms\Classes\ComponentManager;
use Cms\Classes\Page as CmsPage;
class ServiceProvider extends ModuleServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
parent::register('cms');
2014-05-14 23:24:20 +10:00
/*
* Register navigation
*/
2014-10-11 01:56:53 +02:00
BackendMenu::registerCallback(function ($manager) {
2014-05-14 23:24:20 +10:00
$manager->registerMenuItems('October.Cms', [
'cms' => [
'label' => 'cms::lang.cms.menu_label',
'icon' => 'icon-magic',
'url' => Backend::url('cms'),
'permissions' => ['cms.*'],
'order' => 10,
'sideMenu' => [
'pages' => [
'label' => 'cms::lang.page.menu_label',
'icon' => 'icon-copy',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'pages'],
'permissions' => ['cms.manage_pages'],
2015-01-22 09:06:30 +01:00
'counterLabel' => 'cms::lang.page.unsaved_label'
2014-05-14 23:24:20 +10:00
],
'partials' => [
'label' => 'cms::lang.partial.menu_label',
'icon' => 'icon-tags',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'partials'],
'permissions' => ['cms.manage_partials'],
2015-01-22 09:06:30 +01:00
'counterLabel' => 'cms::lang.partial.unsaved_label'
2014-05-14 23:24:20 +10:00
],
'layouts' => [
'label' => 'cms::lang.layout.menu_label',
'icon' => 'icon-th-large',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'layouts'],
'permissions' => ['cms.manage_layouts'],
2015-01-22 09:06:30 +01:00
'counterLabel' => 'cms::lang.layout.unsaved_label'
2014-05-14 23:24:20 +10:00
],
'content' => [
'label' => 'cms::lang.content.menu_label',
'icon' => 'icon-file-text-o',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'content'],
'permissions' => ['cms.manage_content'],
2015-01-22 09:06:30 +01:00
'counterLabel' => 'cms::lang.content.unsaved_label'
2014-05-14 23:24:20 +10:00
],
'assets' => [
'label' => 'cms::lang.asset.menu_label',
'icon' => 'icon-picture-o',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'assets'],
'permissions' => ['cms.manage_assets'],
2015-01-22 09:06:30 +01:00
'counterLabel' => 'cms::lang.asset.unsaved_label'
2014-05-14 23:24:20 +10:00
],
'components' => [
'label' => 'cms::lang.component.menu_label',
'icon' => 'icon-puzzle-piece',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'components'],
'permissions' => ['cms.manage_pages', 'cms.manage_layouts', 'cms.manage_partials']
2014-05-14 23:24:20 +10:00
]
]
],
'media' => [
'label' => 'cms::lang.media.menu_label',
'icon' => 'icon-folder',
'url' => Backend::url('cms/media'),
'permissions' => ['cms.*'],
'order' => 20
2014-05-14 23:24:20 +10:00
]
]);
});
/*
* Register permissions
*/
2014-10-11 01:56:53 +02:00
BackendAuth::registerCallback(function ($manager) {
2014-05-14 23:24:20 +10:00
$manager->registerPermissions('October.Cms', [
'cms.manage_content' => [
'label' => 'cms::lang.permissions.manage_content',
'tab' => 'cms::lang.permissions.name'
],
'cms.manage_assets' => [
'label' => 'cms::lang.permissions.manage_assets',
'tab' => 'cms::lang.permissions.name'
],
'cms.manage_pages' => [
'label' => 'cms::lang.permissions.manage_pages',
'tab' => 'cms::lang.permissions.name'
],
'cms.manage_layouts' => [
'label' => 'cms::lang.permissions.manage_layouts',
'tab' => 'cms::lang.permissions.name'
],
'cms.manage_partials' => [
'label' => 'cms::lang.permissions.manage_partials',
'tab' => 'cms::lang.permissions.name'
],
'cms.manage_themes' => [
'label' => 'cms::lang.permissions.manage_themes',
'tab' => 'cms::lang.permissions.name'
]
2014-05-14 23:24:20 +10:00
]);
});
/*
* Register widgets
*/
2014-10-11 01:56:53 +02:00
WidgetManager::instance()->registerFormWidgets(function ($manager) {
2014-05-14 23:24:20 +10:00
$manager->registerFormWidget('Cms\FormWidgets\Components');
});
2014-07-19 13:05:50 +11:00
/*
* Register settings
*/
2014-10-11 01:56:53 +02:00
SettingsManager::instance()->registerCallback(function ($manager) {
2014-07-19 13:05:50 +11:00
$manager->registerSettingItems('October.Cms', [
'theme' => [
'label' => 'cms::lang.theme.settings_menu',
'description' => 'cms::lang.theme.settings_menu_description',
'category' => SettingsManager::CATEGORY_CMS,
2014-07-19 13:05:50 +11:00
'icon' => 'icon-picture-o',
'url' => Backend::URL('cms/themes'),
'permissions' => ['system.manage_themes'],
'order' => 300
],
'maintenance_settings' => [
'label' => 'cms::lang.maintenance.settings_menu',
'description' => 'cms::lang.maintenance.settings_menu_description',
'category' => SettingsManager::CATEGORY_CMS,
'icon' => 'icon-plug',
'class' => 'Cms\Models\MaintenanceSettings',
'permissions' => ['system.manage_themes'],
2015-01-22 09:06:30 +01:00
'order' => 400
],
2014-07-19 13:05:50 +11:00
]);
});
/*
* Register components
*/
2014-10-11 01:56:53 +02:00
ComponentManager::instance()->registerComponents(function ($manager) {
$manager->registerComponent('Cms\Classes\ViewBag', 'viewBag');
});
/*
* Register asset bundles
*/
CombineAssets::registerCallback(function($combiner) {
$combiner->registerBundle('~/modules/cms/widgets/mediamanager/assets/js/mediamanager-global.js');
$combiner->registerBundle('~/modules/cms/widgets/mediamanager/assets/js/mediamanager-browser.js');
});
}
/**
* Bootstrap the module events.
*
* @return void
*/
public function boot()
{
parent::boot('cms');
2014-10-11 01:56:53 +02:00
Event::listen('pages.menuitem.listTypes', function () {
return [
2014-11-09 15:22:03 +11:00
'cms-page' => 'CMS Page'
];
});
2014-10-11 01:56:53 +02:00
Event::listen('pages.menuitem.getTypeInfo', function ($type) {
if ($type == 'cms-page') {
return CmsPage::getMenuTypeInfo($type);
2014-10-11 01:56:53 +02:00
}
});
2014-10-11 01:56:53 +02:00
Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
if ($type == 'cms-page') {
return CmsPage::resolveMenuItem($item, $url, $theme);
2014-10-11 01:56:53 +02:00
}
});
}
}