winter/modules/cms/ServiceProvider.php

301 lines
11 KiB
PHP
Raw Normal View History

<?php namespace Cms;
use App;
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;
use Cms\Classes\Theme as CmsTheme;
class ServiceProvider extends ModuleServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
parent::register('cms');
2014-05-14 23:24:20 +10:00
$this->registerComponents();
$this->registerAssetBundles();
2015-06-27 11:04:44 +10:00
/*
* Backend specific
*/
if (App::runningInBackend()) {
$this->registerBackendNavigation();
$this->registerBackendReportWidgets();
$this->registerBackendPermissions();
$this->registerBackendWidgets();
$this->registerBackendSettings();
2015-06-27 11:04:44 +10:00
}
}
/**
* Bootstrap the module events.
*
* @return void
*/
public function boot()
{
parent::boot('cms');
$this->bootMenuItemEvents();
2015-06-25 19:26:47 +10:00
$this->bootRichEditorEvents();
}
/**
* Register components
*/
protected function registerComponents()
{
ComponentManager::instance()->registerComponents(function ($manager) {
$manager->registerComponent('Cms\Classes\ViewBag', 'viewBag');
});
}
/**
* Register asset bundles
*/
protected function registerAssetBundles()
{
2014-05-14 23:24:20 +10:00
/*
* Register asset bundles
2014-05-14 23:24:20 +10:00
*/
CombineAssets::registerCallback(function($combiner) {
$combiner->registerBundle('~/modules/cms/widgets/mediamanager/assets/js/mediamanager-browser.js');
2016-02-28 19:52:21 -08:00
$combiner->registerBundle('~/modules/cms/widgets/mediamanager/assets/less/mediamanager.less');
});
}
/*
* Register navigation
*/
protected function registerBackendNavigation()
{
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',
2016-02-19 22:12:41 -08:00
'iconSvg' => 'modules/cms/assets/images/cms-icon.svg',
2014-05-14 23:24:20 +10:00
'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',
2016-02-19 22:12:41 -08:00
'iconSvg' => 'modules/cms/assets/images/media-icon.svg',
'url' => Backend::url('cms/media'),
'permissions' => ['media.*'],
'order' => 20
2014-05-14 23:24:20 +10:00
]
]);
});
}
2014-05-14 23:24:20 +10:00
/*
* Register report widgets
*/
protected function registerBackendReportWidgets()
{
WidgetManager::instance()->registerReportWidgets(function ($manager) {
$manager->registerReportWidget('Cms\ReportWidgets\ActiveTheme', [
'label' => 'cms::lang.dashboard.active_theme.widget_title_default',
'context' => 'dashboard'
]);
});
}
/*
* Register permissions
*/
protected function registerBackendPermissions()
{
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',
2015-05-21 22:54:44 +10:00
'tab' => 'cms::lang.permissions.name',
'order' => 100
],
'cms.manage_assets' => [
'label' => 'cms::lang.permissions.manage_assets',
2015-05-21 22:54:44 +10:00
'tab' => 'cms::lang.permissions.name',
'order' => 100
],
'cms.manage_pages' => [
'label' => 'cms::lang.permissions.manage_pages',
2015-05-21 22:54:44 +10:00
'tab' => 'cms::lang.permissions.name',
'order' => 100
],
'cms.manage_layouts' => [
'label' => 'cms::lang.permissions.manage_layouts',
2015-05-21 22:54:44 +10:00
'tab' => 'cms::lang.permissions.name',
'order' => 100
],
'cms.manage_partials' => [
'label' => 'cms::lang.permissions.manage_partials',
2015-05-21 22:54:44 +10:00
'tab' => 'cms::lang.permissions.name',
'order' => 100
],
'cms.manage_themes' => [
'label' => 'cms::lang.permissions.manage_themes',
2015-05-21 22:54:44 +10:00
'tab' => 'cms::lang.permissions.name',
'order' => 100
],
'media.manage_media' => [
'label' => 'cms::lang.permissions.manage_media',
'tab' => 'cms::lang.permissions.name',
'order' => 100
]
2014-05-14 23:24:20 +10:00
]);
});
}
2014-05-14 23:24:20 +10:00
/*
* Register widgets
*/
protected function registerBackendWidgets()
{
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');
$manager->registerFormWidget('Cms\FormWidgets\MediaFinder', [
'label' => 'Media Finder',
'code' => 'mediafinder'
]);
2014-05-14 23:24:20 +10:00
});
}
2014-05-14 23:24:20 +10:00
/*
* Register settings
*/
protected function registerBackendSettings()
{
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' => ['cms.manage_themes'],
2015-04-29 19:50:30 +10:00
'order' => 200
],
'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\MaintenanceSetting',
'permissions' => ['cms.manage_themes'],
2015-04-29 19:50:30 +10:00
'order' => 300
],
2014-07-19 13:05:50 +11:00
]);
});
}
/**
* Registers events for menu items.
*/
protected function bootMenuItemEvents()
{
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
}
});
}
2015-06-25 19:26:47 +10:00
/**
* Registers events for rich editor page links.
*/
protected function bootRichEditorEvents()
{
Event::listen('backend.richeditor.listTypes', function () {
return [
'cms-page' => 'CMS Page'
];
});
Event::listen('backend.richeditor.getTypeInfo', function ($type) {
if ($type == 'cms-page') {
return CmsPage::getRichEditorTypeInfo($type);
}
});
}
}