* @copyright Copyright (c) Frank Förster (http://frankfoerster.com) * @license http://www.opensource.org/licenses/mit-license.php MIT License */ use Cake\Cache\Cache; use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Event\EventManager; use Cake\Filesystem\Folder; use Wasabi\Cms\Event\DispatcherListener; use Wasabi\Cms\Event\MenuListener; use Wasabi\Cms\Event\RouteListener; use Wasabi\Cms\Event\ThemeListener; use Wasabi\Cms\View\Module\ModuleManager; try { // Load and apply the Wasabi Core cache config. Configure::load('Wasabi/Cms.cache', 'default'); foreach (Configure::consume('Cache') as $key => $config) { new Folder($config['path'], true, 0775); Cache::config($key, $config); } } catch (\Exception $e) { die($e->getMessage() . "\n"); } // Configure plugin translation paths. Configure::write('App.paths.locales', array_merge(Configure::read('App.paths.locales'), [Plugin::path('Wasabi/Cms') . 'src' . DS . 'Locale' . DS])); // Register module path. ModuleManager::registerModulePath(Plugin::path('Wasabi/Cms') . 'src' . DS . 'View' . DS . 'Module' . DS); EventManager::instance()->on(new RouteListener()); EventManager::instance()->on(new ThemeListener()); EventManager::instance()->on(new DispatcherListener()); EventManager::instance()->on(new MenuListener());
/** * Edit Action * GET | PUT * * @param $id */ public function edit($id) { $this->request->allowMethod(['get', 'put']); /** @var Page $page */ $page = $this->Pages->get($id, ['contain' => ['Current', 'Attributes', 'Collections']]); ThemeManager::theme(Wasabi::setting('Cms.Theme.id')); if ($this->request->is('put')) { $page = $this->Pages->patchEntity($page, $this->request->data); if ($this->Pages->save($page)) { $this->Flash->success(__d('wasabi_cms', 'The page <strong>{0}</strong> has been saved.', $page->name)); $this->redirect(['action' => 'index']); return; } else { $this->Flash->error($this->formErrorMessage); } } else { /** @var Content $current */ $current = $page->current; if (!is_array($current) && get_class($current) === 'Wasabi\\Cms\\Model\\Entity\\Content' && $current->isNew()) { $defaultLayout = ThemeManager::theme()->getLayout('Default'); $page->current = [(new Content())->set('content', json_encode($defaultLayout->content()))]; } } if ($page->meta_robots_index === null) { $page->meta_robots_index = (bool) Configure::read('Settings.Cms.SEO.meta-robots-index'); } if ($page->meta_robots_follow === null) { $page->meta_robots_follow = (bool) Configure::read('Settings.Cms.SEO.meta-robots-follow'); } $routes = $this->Routes->findAllFor('Wasabi/Cms.Pages', $id, Wasabi::contentLanguage()->id)->order([$this->Routes->aliasField('url') => 'asc']); $this->set(['page' => $page, 'layouts' => ThemeManager::theme()->getLayoutsForSelect(), 'availableModules' => ModuleManager::getAvailableModules(), 'changeAttributesUrl' => Router::url(['plugin' => 'Wasabi/Cms', 'controller' => 'Pages', 'action' => 'attributes']), 'attributes' => $page->getLayout()->attributes(), 'routes' => $routes, 'routeTypes' => RouteTypes::getForSelect(), 'formRoute' => $this->Routes->newEntity(['type' => $routes->count() >= 1 ? RouteTypes::TYPE_REDIRECT_ROUTE : RouteTypes::TYPE_DEFAULT_ROUTE])]); $this->render('add'); }