/** * Initializes the DataManager object from the database entities * * @param Language $language * @param Page $page */ public function fromEntities(Language $language = null, Page $page = null) { $this->language = $language; $this->page = $page; if (null !== $this->language && null !== $this->page) { $options = array("languageId" => $this->language->getId(), "pageId" => $this->page->getId()); $this->seo = $this->setupSeo($options); } }
/** * Generates the template's subsections and the full template itself */ protected function generatePageTemplate(PageTree $pageTree, ThemeInterface $theme, array $options) { if (!$this->page->getIsPublished()) { $this->twigTemplate = "{% extends 'RedKiteLabsThemeEngineBundle:Frontend:unpublished.html.twig' %}"; return $this; } $options["filter"] = array('page'); $this->twigTemplate = sprintf("{%% extends '%s:%s:%s/base/%s.html.twig' %%}" . PHP_EOL, $options["deployBundle"], $options["templatesDir"], $this->language->getLanguageName(), $this->page->getTemplateName()); $this->twigTemplate .= $this->metatagsSection->generateSection($pageTree, $theme, $options); $this->twigTemplate .= $this->assetsSection->generateSection($pageTree, $theme, $options); $this->twigTemplate .= $this->contentSection->generateSection($pageTree, $theme, $options); return $this; }
/** * Edits the managed language object * * @param array $values * @throws \Exception * @return boolean * * @api */ protected function edit(array $values) { $values = $this->dispatchBeforeOperationEvent('\\RedKiteLabs\\RedKiteCms\\RedKiteCmsBundle\\Core\\Event\\Content\\Language\\BeforeLanguageEditingEvent', LanguageEvents::BEFORE_EDIT_LANGUAGE, $values, array('message' => 'exception_language_editing_aborted', 'domain' => 'exceptions')); try { $this->validator->checkEmptyParams($values); $this->validator->checkOnceValidParamExists(array('LanguageName' => '', 'MainLanguage' => ''), $values); $result = true; $this->languageRepository->startTransaction(); $requireToChangeName = array_key_exists('LanguageName', $values); if (isset($values["MainLanguage"]) && $values["MainLanguage"] == 1) { $result = $this->resetMain(); } else { unset($values["MainLanguage"]); if (!$requireToChangeName) { throw new LanguageException\MainLanguageCannotBeDegradedException('exception_main_language_cannot_be_degraded'); } } if (false !== $result) { if ($requireToChangeName && !empty($values['LanguageName']) && $this->alLanguage->getLanguageName() == $values['LanguageName']) { unset($values['LanguageName']); } if (empty($values)) { $this->languageRepository->rollBack(); return false; } $result = $this->languageRepository->setRepositoryObject($this->alLanguage)->save($values); if (false != $result) { $eventName = LanguageEvents::BEFORE_EDIT_LANGUAGE_COMMIT; $result = !$this->eventsHandler->createEvent($eventName, '\\RedKiteLabs\\RedKiteCms\\RedKiteCmsBundle\\Core\\Event\\Content\\Language\\BeforeEditLanguageCommitEvent', array($this, $values))->dispatch()->getEvent($eventName)->isAborted(); } } if (false !== $result) { $this->languageRepository->commit(); $this->eventsHandler->createEvent(LanguageEvents::AFTER_EDIT_LANGUAGE, '\\RedKiteLabs\\RedKiteCms\\RedKiteCmsBundle\\Core\\Event\\Content\\Language\\AfterLanguageEditedEvent', array($this))->dispatch(); return $result; } $this->languageRepository->rollBack(); return $result; } catch (\Exception $e) { if (isset($this->languageRepository) && $this->languageRepository !== null) { $this->languageRepository->rollBack(); } throw $e; } }
/** * Fetches the base language used to copy the entities * * @return \RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Model\Language */ protected function getBaseLanguage() { $languageRepository = $this->languageManager->getLanguageRepository(); // Tries to fetch the current language from the request if (null !== $this->request) { $languages = $this->request->getLanguages(); $alLanguage = $languageRepository->fromLanguageName($languages[1]); if (null !== $alLanguage) { return $alLanguage; } // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd // Fetches the current language from the main language when the adding one is not the main language if ($this->mainLanguage->getId() != $this->languageManager->get()->getId()) { return $this->mainLanguage; } return $languageRepository->firstOne(); }
/** * Generates an internal route name, from the language and the page * * @param Language $language * @param Page $page * @return string */ protected function generateRoute(Language $language, Page $page) { return sprintf('_%s_%s', $language->getLanguageName(), str_replace("-", "_", $page->getPageName())); }