public function boot() { Event::listen('cms.router.beforeRoute', function ($url) { return Controller::instance()->initCmsPage($url); }); Event::listen('cms.page.beforeRenderPage', function ($controller, $page) { /* * Before twig renders */ $twig = $controller->getTwig(); $loader = $controller->getLoader(); Controller::instance()->injectPageTwig($page, $loader, $twig); /* * Get rendered content */ $contents = Controller::instance()->getPageContents($page); if (strlen($contents)) { return $contents; } }); Event::listen('cms.page.initComponents', function ($controller, $page) { Controller::instance()->initPageComponents($controller, $page); }); Event::listen('cms.block.render', function ($blockName, $blockContents) { $page = CmsController::getController()->getPage(); if (!isset($page->apiBag['staticPage'])) { return; } $contents = Controller::instance()->getPlaceholderContents($page, $blockName, $blockContents); if (strlen($contents)) { return $contents; } }); Event::listen('pages.menuitem.listTypes', function () { return ['static-page' => 'rainlab.pages::lang.menuitem.static_page', 'all-static-pages' => 'rainlab.pages::lang.menuitem.all_static_pages']; }); Event::listen('pages.menuitem.getTypeInfo', function ($type) { if ($type == 'url') { return []; } if ($type == 'static-page' || $type == 'all-static-pages') { return StaticPage::getMenuTypeInfo($type); } }); Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) { if ($type == 'static-page' || $type == 'all-static-pages') { return StaticPage::resolveMenuItem($item, $url, $theme); } }); Event::listen('backend.form.extendFieldsBefore', function ($formWidget) { if ($formWidget->model instanceof \Cms\Classes\Partial) { Snippet::extendPartialForm($formWidget); } }); Event::listen('cms.template.save', function ($controller, $template, $type) { Plugin::clearCache(); }); Event::listen('cms.template.processSettingsBeforeSave', function ($controller, $dataHolder) { $dataHolder->settings = Snippet::processTemplateSettingsArray($dataHolder->settings); }); Event::listen('cms.template.processSettingsAfterLoad', function ($controller, $template) { Snippet::processTemplateSettings($template); }); Event::listen('cms.template.processTwigContent', function ($template, $dataHolder) { if ($template instanceof \Cms\Classes\Layout) { $dataHolder->content = Controller::instance()->parseSyntaxFields($dataHolder->content); } }); Event::listen('backend.richeditor.listTypes', function () { return ['static-page' => 'rainlab.pages::lang.menuitem.static_page']; }); Event::listen('backend.richeditor.getTypeInfo', function ($type) { if ($type === 'static-page') { return StaticPage::getRichEditorTypeInfo($type); } }); }
/** * Initializes CMS components associated with the page. */ public function initCmsComponents($cmsController) { $snippetComponents = Snippet::listPageComponents($this->getFileName(), $this->theme, $this->markup . $this->code); $componentManager = ComponentManager::instance(); foreach ($snippetComponents as $componentInfo) { // Register components for snippet-based components // if they're not defined yet. This is required because // not all snippet components are registered as components, // but it's safe to register them in render-time. if (!$componentManager->hasComponent($componentInfo['class'])) { $componentManager->registerComponent($componentInfo['class'], $componentInfo['alias']); } $cmsController->addComponent($componentInfo['class'], $componentInfo['alias'], $componentInfo['properties']); } }
/** * Returns a list of snippets created from components. * @return array Returns an array of Snippet objects. */ protected function listComponentSnippets() { $result = []; $pluginManager = PluginManager::instance(); $plugins = $pluginManager->getPlugins(); foreach ($plugins as $id => $plugin) { if (!method_exists($plugin, 'registerPageSnippets')) { continue; } $snippets = $plugin->registerPageSnippets(); if (!is_array($snippets)) { continue; } foreach ($snippets as $componentClass => $componentCode) { // TODO: register snippet components later, during // the page life cycle. $snippet = new Snippet(); $snippet->initFromComponentInfo($componentClass, $componentCode); $result[] = $snippet; } } return $result; }