/** * Perform the structure node action */ public function indexAction(Cms $cms, NodeStructureParser $parser, $locale, $site, $revision) { $node = $site; if (!$cms->resolveNode($site, $revision, $node, null, true)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $translator = $this->getTranslator(); $referer = $this->request->getQueryParameter('referer'); $structure = $parser->getStructure($locale, $node); $form = $this->createFormBuilder(array('structure' => $structure)); $form->addRow('structure', 'text', array('label' => $translator->translate('label.node.structure'), 'description' => $translator->translate('label.node.structure.description'), 'attributes' => array('rows' => 10), 'filters' => array('trim' => array()), 'validators' => array('required' => array()))); $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $parser->setStructure($locale, $node, $cms->getNodeModel(), $data['structure']); $this->addSuccess('success.node.saved', array('node' => $site->getName($locale))); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $this->setTemplateView('cms/backend/site.structure', array('site' => $site, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales())); }
/** * Perform the advanced node action */ public function indexAction(Cms $cms, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $referer = $this->request->getQueryParameter('referer'); $ini = $this->getIniFromNodeProperties($node->getProperties()); $translator = $this->getTranslator(); $form = $this->createFormBuilder(array('properties' => $ini)); $form->addRow('properties', 'text', array('label' => $translator->translate('label.node.properties'), 'description' => $translator->translate('label.node.properties.description'), 'attributes' => array('rows' => 10), 'filters' => array('trim' => array()))); $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $nodeProperties = $this->getNodePropertiesFromIni($data['properties']); $node->setProperties($nodeProperties); $cms->saveNode($node, 'Edited advanced properties of node ' . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $this->setTemplateView('cms/backend/node.advanced', array('site' => $site, 'node' => $node, 'nodeProperties' => $this->getHtmlFromNode($node), 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales())); }
/** * Perform the structure node action */ public function indexAction(Cms $cms, CmsVarnishService $varnishService, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node, null, true)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $referer = $this->request->getQueryParameter('referer'); if (!$referer) { $referer = $this->getUrl('cms.node.varnish', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $site->getRevision(), 'node' => $node->getId())); } $translator = $this->getTranslator(); $cache = $node->get('cache.target', 'inherit', false); $data = array('cacheTarget' => $cache, 'sharedMaxAge' => in_array($cache, array('intermediate', 'all')) ? $node->getHeader($locale, 's-maxage') : null, 'maxAge' => $cache == 'all' ? $node->getHeader($locale, 'max-age') : ($cache == 'intermediate' ? 0 : null)); $formHeaders = null; if ($this->isPermissionGranted('cms.node.varnish.manage')) { $formHeaders = $this->createFormBuilder($data); $formHeaders->setAction('headers'); $formHeaders->addRow('cacheTarget', 'option', array('label' => $translator->translate('label.cache.target'), 'options' => $this->getCacheOptions($node, $translator, $locale), 'attributes' => array('data-toggle-dependant' => 'option-cachetarget'), 'validators' => array('required' => array()))); $formHeaders->addRow('maxAge', 'select', array('label' => $translator->translate('label.header.maxage'), 'description' => $translator->translate('label.header.maxage.description'), 'options' => $this->getTimeOptions($translator, 0, 3600), 'attributes' => array('class' => 'option-cachetarget option-cachetarget-all'))); $formHeaders->addRow('sharedMaxAge', 'select', array('label' => $translator->translate('label.header.smaxage'), 'description' => $translator->translate('label.header.smaxage.description'), 'options' => $this->getTimeOptions($translator, 0, 31536000), 'attributes' => array('class' => 'option-cachetarget option-cachetarget-intermediate option-cachetarget-all'))); $formHeaders = $formHeaders->build(); if ($formHeaders->isSubmitted()) { try { $formHeaders->validate(); $data = $formHeaders->getData(); $node->set('cache.target', $data['cacheTarget']); $node->setHeader($locale, 'max-age', $data['cacheTarget'] == 'all' ? $data['maxAge'] : ($data['cacheTarget'] == 'intermediate' ? 0 : ($data['cacheTarget'] == 'inherit' ? null : ''))); $node->setHeader($locale, 's-maxage', in_array($data['cacheTarget'], array('intermediate', 'all')) ? $data['sharedMaxAge'] : ($data['cacheTarget'] == 'inherit' ? null : '')); $node->setHeader($locale, 'Expires', 'Wed, 06 Jul 1983 5:00:00 GMT'); $cms->saveNode($node, "Set cache properties for " . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $site->getName($locale))); $this->response->setRedirect($referer); return; } catch (ValidationException $exception) { $this->setValidationException($exception, $formHeaders); } } $formHeaders = $formHeaders->getView(); } $formClear = $this->createFormBuilder(); $formClear->setAction('clear'); $formClear->addRow('recursive', 'option', array('label' => '', 'description' => $translator->translate('label.confirm.varnish.clear.recursive'))); $formClear = $formClear->build(); if ($formClear->isSubmitted()) { $baseUrl = $site->getBaseUrl($locale); if (!$baseUrl) { $baseUrl = $this->request->getBaseUrl(); } $data = $formClear->getData(); $varnishService->banNode($node, $baseUrl, $locale, $data['recursive']); $this->addSuccess('success.node.varnish.cleared', array('node' => $node->getName($locale))); $this->response->setRedirect($referer); return; } $referer = $this->request->getQueryParameter('referer'); $this->setTemplateView('cms/backend/node.varnish', array('site' => $site, 'node' => $node, 'formHeaders' => $formHeaders, 'formClear' => $formClear->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales())); }
/** * Perform the template node action */ public function indexAction(TemplateFacade $templateFacade, FileBrowser $fileBrowser, $locale, $site, $revision, $node) { if (!$this->cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $this->cms->setLastAction(self::NAME); $referer = $this->request->getQueryParameter('referer'); $templateFacade->setThemeModel($this->cms->getThemeModel()); $templates = array('index' => 'cms/frontend/index'); if ($node->getId() == $site->getId()) { $id = null; } else { $id = $node->getId(); } $component = new TemplatesComponent(); $data = $component->createData($templateFacade, $templates, $node->getTheme(), $id); $form = $this->buildForm($component, $data); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $applicationDirectory = $fileBrowser->getApplicationDirectory(); foreach ($templates as $name => $template) { $file = $applicationDirectory->getChild($data['path'][$name]); $file->getParent()->create(); $file->write($data['content'][$name]); } $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $this->setTemplateView('cms/backend/node.templates', array('site' => $site, 'node' => $node, 'templates' => $templates, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $this->cms->getLocales())); }
public function formAction(Cms $cms, $locale, $site, $revision = null, $node = null) { if ($node) { if (!$cms->resolveNode($site, $revision, $node, 'folder')) { return; } $cms->setLastAction('edit'); } else { if (!$cms->resolveNode($site, $revision)) { return; } $node = $cms->createNode('folder', $site); } $this->setContentLocale($locale); $translator = $this->getTranslator(); $locales = $cms->getLocales(); $themes = $cms->getThemes(); $data = array('name' => $node->getName($locale), 'theme' => $this->getThemeValueFromNode($node), 'availableLocales' => $this->getLocalesValueFromNode($node)); $form = $this->createFormBuilder($data); $form->addRow('name', 'string', array('label' => $translator->translate('label.folder'), 'description' => $translator->translate('label.folder.description'), 'filters' => array('trim' => array()), 'validators' => array('required' => array()))); $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($node, $translator, $themes))); if ($site->isLocalizationMethodCopy()) { $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array()))); } $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $node->setName($locale, $data['name']); $node->setTheme($this->getOptionValueFromForm($data['theme'])); if ($site->isLocalizationMethodCopy()) { $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales'])); } else { $node->setAvailableLocales($locale); } $cms->saveNode($node, (!$node->getId() ? 'Created new folder ' : 'Updated folder ') . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $this->response->setRedirect($this->getUrl('cms.folder.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId()))); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $referer = $this->request->getQueryParameter('referer'); $this->setTemplateView('cms/backend/folder.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales)); }
/** * Detects the current region and redirects to the region page * @param \ride\web\cms\Cms $cms Facade to the CMS * @param string $locale Code of the locale * @param string $site Id of the site * @param string $revision Name of the revision * @param string $node Id of the node * @return null */ public function indexAction(Cms $cms, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $theme = $cms->getTheme($node->getTheme()); $form = $this->buildRegionForm($node, $theme); if ($form->isSubmitted()) { $data = $form->getData(); $region = $data['region']; } else { $region = $cms->getLastRegion(); } if (!$region || $region && !$theme->hasRegion($region)) { $regions = $theme->getRegions(); $region = array_shift($regions); } $this->response->setRedirect($this->getUrl('cms.node.content.region', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId(), 'region' => $region))); }
/** * Perform the error node action */ public function indexAction(Cms $cms, $locale, $site, $revision) { $node = $site; if (!$cms->resolveNode($site, $revision, $node, null, true)) { return; } $cms->setLastAction(self::NAME); $this->setContentLocale($locale); $translator = $this->getTranslator(); $referer = $this->request->getQueryParameter('referer'); $nodeList = $cms->getNodeList($node, $locale); $data = array('node404' => $site->get('error.404'), 'node403' => $site->get('error.403')); $form = $this->createFormBuilder($data); $form->addRow('node404', 'select', array('label' => $translator->translate('label.node.404'), 'options' => $nodeList)); $form->addRow('node403', 'select', array('label' => $translator->translate('label.node.403'), 'options' => $nodeList)); $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); foreach ($data as $statusCode => $errorNode) { $statusCode = str_replace('node', '', $statusCode); $site->set('error.' . $statusCode, $errorNode); } $cms->saveNode($site, "Set error pages for " . $site->getName()); $this->addSuccess('success.node.saved', array('node' => $site->getName($locale))); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $this->setTemplateView('cms/backend/site.error', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales())); }
/** * Perform the publish node action */ public function indexAction(Cms $cms, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $translator = $this->getTranslator(); $defaultRevision = $cms->getDefaultRevision(); $data = array('revision' => $defaultRevision, 'recursive' => true); $revisions = $site->getRevisions(); if (!isset($revisions[$defaultRevision])) { $revisions[$defaultRevision] = $defaultRevision; } unset($revisions[$node->getRevision()]); $form = $this->createFormBuilder($data); $form->addRow('revision', 'select', array('label' => $translator->translate('label.revision'), 'description' => $translator->translate('label.revision.publish.description'), 'options' => $revisions, 'validators' => array('required' => array()))); $form->addRow('recursive', 'option', array('label' => $translator->translate('label.recursive'), 'description' => $translator->translate('label.recursive.publish.description'))); $referer = $this->request->getQueryParameter('referer'); $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $cms->publishNode($node, $data['revision'], $data['recursive']); $this->addSuccess('success.node.published', array('node' => $node->getName($locale), 'revision' => $data['revision'])); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $this->setTemplateView('cms/backend/node.publish', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales())); }
/** * Action to add or edit a site * @param \ride\web\cms\Cms $cms Facade to the CMS * @param string $locale Code of the locale * @param string $site Id of the site * @param string $revision Name of the revision * @return null */ public function formAction(Cms $cms, $locale, $site = null, $revision = null) { if ($site) { if (!$cms->resolveNode($site, $revision)) { return; } $cms->setLastAction('edit'); } else { $site = $cms->createNode('site'); } $this->setContentLocale($locale); $translator = $this->getTranslator(); $locales = $cms->getLocales(); $themes = $cms->getThemes(); $referer = $this->request->getQueryParameter('referer'); $data = array('name' => $site->getName($locale), 'localizationMethod' => $site->getLocalizationMethod(), 'baseUrl' => $site->getBaseUrl($locale), 'theme' => $site->getTheme(), 'availableLocales' => $this->getLocalesValueFromNode($site), 'autoPublish' => $site->isAutoPublish()); $form = $this->createFormBuilder($data); $form->addRow('name', 'string', array('label' => $translator->translate('label.site'), 'description' => $translator->translate('label.site.description'), 'attributes' => array('autofocus' => 'true'), 'filters' => array('trim' => array()), 'validators' => array('required' => array()))); $form->addRow('baseUrl', 'website', array('label' => $translator->translate('label.url.base'), 'description' => $translator->translate('label.url.base.description'), 'filters' => array('trim' => array()))); $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($site, $translator, $themes), 'validators' => array('required' => array()))); $form->addRow('autoPublish', 'boolean', array('label' => $translator->translate('label.publish.auto'), 'description' => $translator->translate('label.publish.auto.description'))); $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($site, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array()))); $form->addRow('localizationMethod', 'select', array('label' => $translator->translate('label.method.localization'), 'description' => $translator->translate('label.method.localization.description'), 'readonly' => $site->getId(), 'options' => array(SiteNode::LOCALIZATION_METHOD_COPY => $translator->translate('label.copy.translated'), SiteNode::LOCALIZATION_METHOD_UNIQUE => $translator->translate('label.tree.unique')), 'validators' => array('required' => array()))); $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $oldIsAutoPublish = $data['autoPublish']; $data = $form->getData(); $site->setName($locale, $data['name']); if (!$site->getId()) { $locales = $cms->getLocales(); foreach ($locales as $l) { if ($l == $locale) { continue; } $site->setName($l, $data['name']); } } $site->setLocalizationMethod($data['localizationMethod']); $site->setBaseUrl($locale, $data['baseUrl']); $site->setTheme($data['theme']); $site->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales'])); $site->setIsAutoPublish($data['autoPublish']); $cms->saveNode($site, (!$site->getId() ? 'Created new site ' : 'Updated site ') . $site->getName()); if (!$oldIsAutoPublish && $site->isAutoPublish()) { $cms->publishNode($site); } $this->addSuccess('success.node.saved', array('node' => $site->getName($locale))); $url = $this->getUrl('cms.site.edit', array('site' => $site->getId(), 'revision' => $site->getRevision(), 'locale' => $locale)); if ($referer) { $url .= '?referer=' . urlencode($url); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $this->setTemplateView('cms/backend/site.form', array('node' => $site, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales)); }
/** * Perform the advanced node action */ public function indexAction(Cms $cms, SecurityManager $securityManager, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $translator = $this->getTranslator(); $referer = $this->request->getQueryParameter('referer'); $security = $node->get(Node::PROPERTY_SECURITY, 'inherit', false); switch ($security) { case 'inherit': case Node::AUTHENTICATION_STATUS_EVERYBODY: case Node::AUTHENTICATION_STATUS_ANONYMOUS: $permissions = null; break; case Node::AUTHENTICATION_STATUS_AUTHENTICATED: default: $permissions = array_flip(explode(',', $security)); $security = Node::AUTHENTICATION_STATUS_AUTHENTICATED; break; } $data = array('published' => $node->get(Node::PROPERTY_PUBLISH, 'inherit', false), 'publishStart' => $node->get(Node::PROPERTY_PUBLISH_START, null, false), 'publishStop' => $node->get(Node::PROPERTY_PUBLISH_STOP, null, false), 'security' => $security, 'permissions' => $permissions); $permissions = $securityManager->getSecurityModel()->getPermissions(); $nodeType = $cms->getNodeType($node); $isFrontendNode = $nodeType->getFrontendCallback() || $node->getLevel() === 0 ? true : false; if ($isFrontendNode) { $data['hide'] = array(); if ($node->hideInMenu()) { $data['hide']['menu'] = 'menu'; } if ($node->hideInBreadcrumbs()) { $data['hide']['breadcrumbs'] = 'breadcrumbs'; } if ($node->hideForAnonymousUsers()) { $data['hide']['anonymous'] = 'anonymous'; } if ($node->hideForAuthenticatedUsers()) { $data['hide']['authenticated'] = 'authenticated'; } } $form = $this->createFormBuilder($data); $form->addRow('published', 'option', array('label' => $translator->translate('label.publish'), 'options' => $this->getPublishedOptions($node, $translator))); $form->addRow('publishStart', 'string', array('label' => $translator->translate('label.publish.start'), 'description' => $translator->translate('label.publish.start.description'), 'filters' => array('trim' => array()), 'validators' => array('regex' => array('required' => false, 'regex' => '/2([0-9]){3}-([0-9]){2}-([0-9]){2} ([0-9]){2}:([0-9]){2}:([0-9]){2}/', 'error.regex' => 'error.validation.date.cms')))); $form->addRow('publishStop', 'string', array('label' => $translator->translate('label.publish.stop'), 'filters' => array('trim' => array()), 'validators' => array('regex' => array('required' => false, 'regex' => '/2([0-9]){3}-([0-9]){2}-([0-9]){2} ([0-9]){2}:([0-9]){2}:([0-9]){2}/', 'error.regex' => 'error.validation.date.cms')))); $form->addRow('security', 'option', array('label' => $translator->translate('label.allow'), 'attributes' => array('data-toggle-dependant' => 'option-security'), 'options' => $this->getSecurityOptions($node, $translator), 'validators' => array('required' => array()))); if ($permissions) { $form->addRow('permissions', 'option', array('label' => $translator->translate('label.permissions.required'), 'attributes' => array('class' => 'option-security option-security-authenticated'), 'multiple' => true, 'options' => $permissions)); } if ($isFrontendNode) { $form->addRow('hide', 'option', array('label' => $translator->translate('label.hide'), 'options' => array('menu' => $translator->translate('label.hide.menu'), 'breadcrumbs' => $translator->translate('label.hide.breadcrumbs'), 'anonymous' => $translator->translate('label.hide.anonymous'), 'authenticated' => $translator->translate('label.hide.authenticated')), 'multiple' => true)); } $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $security = $this->getSecurityValue($data['security']); if ($security == Node::AUTHENTICATION_STATUS_AUTHENTICATED && $permissions && $data['permissions']) { $security = implode(',', $data['permissions']); } $node->set(Node::PROPERTY_PUBLISH, $this->getPublishedValue($data['published'])); $node->set(Node::PROPERTY_PUBLISH_START, $data['publishStart']); $node->set(Node::PROPERTY_PUBLISH_STOP, $data['publishStop']); $node->set(Node::PROPERTY_SECURITY, $security); if ($isFrontendNode) { if ($node->getLevel() === 0) { $inherit = false; } else { $inherit = null; } $node->setHideInMenu(isset($data['hide']['menu']), $inherit); $node->setHideInBreadcrumbs(isset($data['hide']['breadcrumbs']), $inherit); $node->setHideForAnonymousUsers(isset($data['hide']['anonymous']), $inherit); $node->setHideForAuthenticatedUsers(isset($data['hide']['authenticated']), $inherit); } $cms->saveNode($node, 'Set visibility of ' . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $exception) { $validationException = new ValidationException(); $errors = $exception->getAllErrors(); foreach ($errors as $field => $fieldErrors) { if ($field == Node::PROPERTY_PUBLISH) { $validationException->addErrors('published', $fieldErrors); } elseif ($field == Node::PROPERTY_PUBLISH_START) { $validationException->addErrors('publishStart', $fieldErrors); } elseif ($field == Node::PROPERTY_PUBLISH_STOP) { $validationException->addErrors('publishStop', $fieldErrors); } else { $validationException->addErrors($field, $fieldErrors); } } $this->setValidationException($validationException, $form); } } $view = $this->setTemplateView('cms/backend/node.visibility', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales())); $form->processView($view); }
public function formAction(Cms $cms, $locale, ImageUrlGenerator $imageUrlGenerator, $site, $revision, $node = null) { if ($node) { if (!$cms->resolveNode($site, $revision, $node, 'page')) { return; } $cms->setLastAction('edit'); } else { if (!$cms->resolveNode($site, $revision)) { return; } $node = $cms->createNode('page', $site); } $this->setContentLocale($locale); $translator = $this->getTranslator(); $locales = $cms->getLocales(); $themes = $cms->getThemes(); $referer = $this->request->getQueryParameter('referer'); // gather data $data = array('name' => $node->getName($locale), 'name-title' => $node->get('name.' . $locale . '.title', null, false), 'name-menu' => $node->get('name.' . $locale . '.menu', null, false), 'name-breadcrumb' => $node->get('name.' . $locale . '.breadcrumb', null, false), 'description' => $node->getDescription($locale), 'image' => $node->getImage($locale), 'route' => $node->getRoute($locale, false), 'theme' => $this->getThemeValueFromNode($node), 'availableLocales' => $this->getLocalesValueFromNode($node)); // build form $form = $this->createFormBuilder($data); $form->addRow('name', 'string', array('label' => $translator->translate('label.page'), 'description' => $translator->translate('label.page.description'), 'filters' => array('trim' => array()), 'validators' => array('required' => array()))); $form->addRow('name-title', 'string', array('label' => $translator->translate('label.name.title'), 'description' => $translator->translate('label.name.title.description'), 'filters' => array('trim' => array()))); $form->addRow('name-menu', 'string', array('label' => $translator->translate('label.name.menu'), 'description' => $translator->translate('label.name.menu.description'), 'filters' => array('trim' => array()))); $form->addRow('name-breadcrumb', 'string', array('label' => $translator->translate('label.name.breadcrumb'), 'description' => $translator->translate('label.name.breadcrumb.description'), 'filters' => array('trim' => array()))); $form->addRow('route', 'string', array('label' => $translator->translate('label.route'), 'description' => $translator->translate('label.route.description'), 'filters' => array('trim' => array()))); $form->addRow('description', 'text', array('label' => $translator->translate('label.description'), 'description' => $translator->translate('label.description.node.description'), 'filters' => array('trim' => array()))); $form->addRow('image', 'image', array('label' => $translator->translate('label.image'), 'description' => $translator->translate('label.image.node.description'))); $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($node, $translator, $themes))); if ($site->isLocalizationMethodCopy()) { $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array()))); } // process form $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $node->setName($locale, $data['name']); $node->setName($locale, $data['name-title'], 'title'); $node->setName($locale, $data['name-menu'], 'menu'); $node->setName($locale, $data['name-breadcrumb'], 'breadcrumb'); $node->setDescription($locale, $data['description']); $node->setImage($locale, $data['image']); $node->setRoute($locale, $data['route']); $node->setTheme($this->getOptionValueFromForm($data['theme'])); if ($site->isLocalizationMethodCopy()) { $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales'])); } else { $node->setAvailableLocales($locale); } $cms->saveNode($node, (!$node->getId() ? 'Created new page ' : 'Updated page ') . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $url = $this->getUrl('cms.page.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } // show view $this->setTemplateView('cms/backend/page.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales)); }
public function formAction(Cms $cms, $locale, $site, $revision = null, $node = null) { if ($node) { if (!$cms->resolveNode($site, $revision, $node, 'redirect')) { return; } $cms->setLastAction('edit'); } else { if (!$cms->resolveNode($site, $revision)) { return; } $node = $cms->createNode('redirect', $site); } $this->setContentLocale($locale); $translator = $this->getTranslator(); $locales = $cms->getLocales(); $referer = $this->request->getQueryParameter('referer'); // get available nodes $nodeList = $cms->getNodeList($site, $locale, true, false); if ($node && isset($nodeList[$node->getId()])) { unset($nodeList[$node->getId()]); } // gather data $data = array('name' => $node->getName($locale), 'redirect-node' => $node->getRedirectNode($locale), 'redirect-url' => $node->getRedirectUrl($locale), 'route' => $node->getRoute($locale, false), 'availableLocales' => $this->getLocalesValueFromNode($node)); if ($data['redirect-url']) { $data['redirect-type'] = 'url'; } else { $data['redirect-type'] = 'node'; } // build form $form = $this->createFormBuilder($data); $form->addRow('name', 'string', array('label' => $translator->translate('label.redirect'), 'description' => $translator->translate('label.redirect.name.description'), 'filters' => array('trim' => array()), 'validators' => array('required' => array()))); $form->addRow('redirect-type', 'option', array('label' => $translator->translate('label.redirect.to'), 'options' => array('node' => $translator->translate('label.node'), 'url' => $translator->translate('label.url')), 'validators' => array('required' => array()))); $form->addRow('redirect-node', 'select', array('label' => $translator->translate('label.redirect.node'), 'description' => $translator->translate('label.redirect.node.description'), 'options' => $nodeList)); $form->addRow('redirect-url', 'string', array('label' => $translator->translate('label.redirect.url'), 'description' => $translator->translate('label.redirect.url.description'), 'filters' => array('trim' => array()))); $form->addRow('route', 'string', array('label' => $translator->translate('label.route'), 'description' => $translator->translate('label.route.description'), 'filters' => array('trim' => array()))); if ($site->isLocalizationMethodCopy()) { $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array()))); } // process form $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $node->setName($locale, $data['name']); $node->setRoute($locale, $data['route']); if ($site->isLocalizationMethodCopy()) { $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales'])); } else { $node->setAvailableLocales($locale); } if ($data['redirect-type'] == 'node') { $node->setRedirectNode($locale, $data['redirect-node']); $node->setRedirectUrl($locale, null); } else { $node->setRedirectNode($locale, null); $node->setRedirectUrl($locale, $data['redirect-url']); } $cms->saveNode($node, (!$node->getId() ? 'Created new redirect ' : 'Updated redirect ') . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $url = $this->getUrl('cms.redirect.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } // show view $this->setTemplateView('cms/backend/redirect.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales)); }
public function formAction(Cms $cms, ImageUrlGenerator $imageUrlGenerator, $locale, OrmManager $orm, $site, $revision = null, $node = null) { if ($node) { if (!$cms->resolveNode($site, $revision, $node, 'entry')) { return; } $cms->setLastAction('edit'); } else { if (!$cms->resolveNode($site, $revision)) { return; } $node = $cms->createNode('entry', $site); } $translator = $this->getTranslator(); $locales = $cms->getLocales(); $themes = $cms->getThemes(); // gather data $data = array('name' => $node->getName($locale), 'model' => $node->getEntryModel(), 'entry' => $node->getEntryId(), 'route' => $node->getRoute($locale, false), 'theme' => $this->getThemeValueFromNode($node), 'availableLocales' => $this->getLocalesValueFromNode($node)); $entryOptions = array('' => '---'); if ($data['model']) { $model = $orm->getModel($data['model']); $entries = $model->find(null, $locale); $entryOptions += $model->getOptionsFromEntries($entries); } // build form $form = $this->createFormBuilder($data); $form->addRow('model', 'select', array('label' => $translator->translate('label.model'), 'description' => $translator->translate('label.model.description'), 'options' => $this->getModelOptions($orm), 'validators' => array('required' => array()))); $form->addRow('entry', 'select', array('label' => $translator->translate('label.entry'), 'description' => $translator->translate('label.entry.description'), 'options' => $entryOptions, 'validators' => array('required' => array()))); $form->addRow('name', 'string', array('label' => $translator->translate('label.name'), 'description' => $translator->translate('label.entry.name.description'), 'filters' => array('trim' => array()))); $form->addRow('route', 'string', array('label' => $translator->translate('label.route'), 'description' => $translator->translate('label.route.description'), 'filters' => array('trim' => array()))); $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($node, $translator, $themes))); if ($site->isLocalizationMethodCopy()) { $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array()))); } // process form $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); if (!$data['name']) { $data['name'] = $entryOptions[$data['entry']]; } $node->setName($locale, $data['name']); $node->setRoute($locale, $data['route']); $node->setTheme($this->getOptionValueFromForm($data['theme'])); if ($site->isLocalizationMethodCopy()) { $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales'])); } else { $node->setAvailableLocales($locale); } $node->setEntry($data['model'], $data['entry']); $cms->saveNode($node, (!$node->getId() ? 'Created new entry ' : 'Updated entry ') . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $this->response->setRedirect($this->getUrl('cms.entry.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId()))); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $referer = $this->request->getQueryParameter('referer'); if (!$referer) { $referer = $this->getUrl('cms.site.detail.locale', array('site' => $site->getId(), 'revision' => $site->getRevision(), 'locale' => $locale)); } // show view $view = $this->setTemplateView('cms/backend/entry.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales)); $view->addJavascript('js/cms/orm.js'); $view->addInlineJavascript('initializeNodeEntryForm("' . $this->getUrl('api.orm.list', array('model' => '%model%')) . '");'); }
/** * Perform the meta node action */ public function indexAction(Cms $cms, MetaComponent $metaComponent, $locale, $site, $revision, $node) { if (!$cms->resolveNode($site, $revision, $node)) { return; } $this->setContentLocale($locale); $cms->setLastAction(self::NAME); $translator = $this->getTranslator(); $referer = $this->request->getQueryParameter('referer'); $data = array('meta' => array()); if ($site->getId() != $node->getId()) { $parentMeta = $node->getParentNode()->getMeta($locale); } else { $parentMeta = array(); } $meta = $node->getMeta($locale, null, false); foreach ($meta as $property => $content) { switch ($property) { case 'title': $data['title'] = $content; break; case 'description': $data['description'] = $content; break; case 'keywords': $data['keywords'] = $content; break; case 'og:title': $data['og-title'] = $content; break; case 'og:description': $data['og-description'] = $content; break; case 'og:image': $data['og-image'] = $content; break; default: $data['meta'][] = $property . '=' . $content; break; } } $form = $this->createFormBuilder($data); $form->addRow('title', 'string', array('label' => $translator->translate('label.title'), 'filters' => array('trim' => array()))); $form->addRow('description', 'text', array('label' => $translator->translate('label.description'), 'filters' => array('trim' => array()))); $form->addRow('keywords', 'string', array('label' => $translator->translate('label.keywords'), 'filters' => array('trim' => array()))); $form->addRow('og-title', 'string', array('label' => $translator->translate('label.title'), 'filters' => array('trim' => array()))); $form->addRow('og-description', 'text', array('label' => $translator->translate('label.description'), 'filters' => array('trim' => array()))); $form->addRow('og-image', 'image', array('label' => $translator->translate('label.image'))); $form->addRow('meta', 'collection', array('label' => $translator->translate('label.meta'), 'type' => 'component', 'options' => array('component' => $metaComponent))); $form = $form->build(); if ($form->isSubmitted()) { try { $form->validate(); $data = $form->getData(); $meta = array(); if ($data['title']) { $meta['title'] = $data['title']; } if ($data['description']) { $meta['description'] = $data['description']; } if ($data['keywords']) { $meta['keywords'] = $data['keywords']; } if ($data['og-title']) { $meta['og:title'] = $data['og-title']; } if ($data['og-description']) { $meta['og:description'] = $data['og-description']; } if ($data['og-image']) { $meta['og:image'] = $data['og-image']; } foreach ($data['meta'] as $property) { list($property, $content) = explode('=', $property, 2); $meta[$property] = $content; } $node->setMeta($locale, $meta); $cms->saveNode($node, 'Set meta tags to ' . $node->getName()); $this->addSuccess('success.node.saved', array('node' => $node->getName($locale))); $url = $this->getUrl(self::ROUTE, array('site' => $site->getId(), 'revision' => $node->getRevision(), 'locale' => $locale, 'node' => $node->getId())); if ($referer) { $url .= '?referer=' . urlencode($referer); } $this->response->setRedirect($url); return; } catch (ValidationException $validationException) { $this->setValidationException($validationException, $form); } } $this->setTemplateView('cms/backend/node.meta', array('site' => $site, 'node' => $node, 'form' => $form->getView(), 'referer' => $referer, 'locale' => $locale, 'locales' => $cms->getLocales(), 'parentMeta' => $parentMeta)); }