/** * Load data fixtures with the passed EntityManager * * @param ObjectManager|DocumentManager $manager */ public function load(ObjectManager $manager) { $contentParent = $manager->find(null, '/cms/content'); $routeParent = $manager->find(null, '/cms/routes'); $menuBase = $manager->find(null, '/cms/menu'); $enRoute = new Route(); $enRoute->setPosition($routeParent, 'en'); $manager->persist($enRoute); $deRoute = new Route(); $deRoute->setPosition($routeParent, 'de'); $manager->persist($deRoute); $enServiceRoute = new Route(); $enServiceRoute->setPosition($enRoute, 'services'); $manager->persist($enServiceRoute); $deServiceRoute = new Route(); $deServiceRoute->setPosition($deRoute, 'dienstleistungen'); $manager->persist($deServiceRoute); $content = new StaticContent(); $content->setParentDocument($contentParent); $content->setName('symfony-service'); $manager->persist($content); $content->setTitle('Symfony Service'); $content->setBody('A page about Symfony service'); $manager->bindTranslation($content, 'en'); $contentRoute = new Route(); $contentRoute->setPosition($enServiceRoute, 'symfony-service'); $contentRoute->setContent($content); $manager->persist($contentRoute); $content->setTitle('Symfony Dienstleistungen'); $content->setBody('Eine Seite über Symfony Dienstleistungen'); $manager->bindTranslation($content, 'de'); $contentRoute = new Route(); $contentRoute->setPosition($deServiceRoute, 'symfony-dienstleistungen'); $contentRoute->setContent($content); $manager->persist($contentRoute); $menu = new Menu(); $menu->setPosition($menuBase, 'footer'); $manager->persist($menu); $menuNode = new MenuNode(); $menuNode->setParentDocument($menu); $menuNode->setContent($content); $menuNode->setName('symfony-service'); $manager->persist($menuNode); $menuNode->setLabel('Symfony Services'); $manager->bindTranslation($menuNode, 'en'); $menuNode->setLabel('Symfony Dienstleistungen'); $manager->bindTranslation($menuNode, 'de'); $manager->flush(); }
/** * Load data fixtures with the passed EntityManager * * @param ObjectManager|DocumentManager $manager */ public function load(ObjectManager $manager) { $contentParent = $manager->find(null, '/cms/content'); $routeParent = $manager->find(null, '/cms/routes/en/services'); $menuBase = $manager->find(null, '/cms/menu/footer'); $content = new DemoSeoContent(); $content->setParentDocument($contentParent); $content->setName('seo-service'); $content->setTitle('SEO Service'); $content->setBody('A page about SEO service'); $metaData = new SeoMetadata(); $metaData->setMetaDescription('Description in Metadata'); $content->setSeoMetadata($metaData); $manager->persist($content); $manager->bindTranslation($content, 'en'); $contentRoute = new Route(); $contentRoute->setParentDocument($routeParent); $contentRoute->setName('seo-service'); $contentRoute->setContent($content); $manager->persist($contentRoute); $menuNode = new MenuNode(); $menuNode->setParentDocument($menuBase); $menuNode->setName('seo-service'); $menuNode->setLabel('SEO Services'); $menuNode->setContent($content); $manager->persist($menuNode); $manager->flush(); }
private function addTranslation(ObjectManager $manager, Category $category, $locale, $name, $description) { $category->setName($name); $category->setDescription($description); $manager->bindTranslation($category, $locale); $manager->flush(); }
private function blockCreator($parent, $name, $parentname, ObjectManager $manager) { $block = $manager->find(null, '/cms/content/blocks/' . $parentname . '/' . $name); if (null == $block) { $block = new SimpleBlock(array('add_locale_pattern' => true)); $block->setParentObject($parent); $block->setName($name); $block->setTitle($this->translator->trans($parentname . '.' . $name . '.title', array(), 'messages', 'da')); $block->setBody($this->translator->trans($parentname . '.' . $name . '.body', array(), 'messages', 'da')); $manager->persist($block); $manager->bindTranslation($block, 'da'); foreach (array('en', 'de', 'fr', 'es', 'it', 'po') as $locale) { $block->setTitle($this->translator->trans($parentname . '.' . $name . '.title', array(), 'messages', $locale)); $block->setBody($this->translator->trans($parentname . '.' . $name . '.body', array(), 'messages', $locale)); $manager->bindTranslation($block, $locale); } } }
/** * @param \Doctrine\Common\Persistence\ObjectManager $manager * @param string $name * @param string $url * * @return \ServerGrove\KbBundle\Document\Url */ private function addUrl(ObjectManager $manager, $name, $url) { $document = new Url(); $document->setName($name); $document->setUrl($url); $manager->persist($document); $manager->bindTranslation($document, 'en'); return $document; }
public function load(ObjectManager $manager) { NodeHelper::createPath($manager->getPhpcrSession(), '/test'); NodeHelper::createPath($manager->getPhpcrSession(), '/test/content'); NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes'); $contentRoot = $manager->find(null, '/test/content'); $routeRoot = $manager->find(null, '/test/routes'); $sitemapAwareContent = new SitemapAwareContent(); $sitemapAwareContent->setIsVisibleForSitemap(true)->setTitle('Sitemap Aware Content')->setName('sitemap-aware')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware'); $manager->persist($sitemapAwareContent); $manager->bindTranslation($sitemapAwareContent, 'en'); $sitemapAwareContent->setTitle('Content für die Sitemap')->setBody('Das sollte die Deutsche Version des Contents sein.'); $manager->bindTranslation($sitemapAwareContent, 'de'); $route = new Route(); $route->setPosition($routeRoot, 'sitemap-aware'); $route->setContent($sitemapAwareContent); $manager->persist($route); $nonPublishedContent = new SitemapAwareWithPublishWorkflowContent(); $nonPublishedContent->setIsVisibleForSitemap(true); $nonPublishedContent->setPublishable(false); $nonPublishedContent->setTitle('Sitemap Aware Content non publish')->setName('sitemap-aware-non-publish')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware, that is not publish'); $manager->persist($nonPublishedContent); $route = new Route(); $route->setPosition($routeRoot, 'sitemap-aware-non-publish'); $route->setContent($nonPublishedContent); $manager->persist($route); $publishedContent = new SitemapAwareWithPublishWorkflowContent(); $publishedContent->setIsVisibleForSitemap(true); $publishedContent->setPublishable(true); $publishedContent->setTitle('Sitemap Aware Content publish')->setName('sitemap-aware-publish')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware, that is publish'); $manager->persist($publishedContent); $route = new Route(); $route->setPosition($routeRoot, 'sitemap-aware-publish'); $route->setContent($publishedContent); $manager->persist($route); $lastModifiedContent = new SitemapAwareWithLastModifiedDateContent(); $lastModifiedContent->setIsVisibleForSitemap(true)->setLastModified(new \DateTime('2016-07-06', new \DateTimeZone('Europe/Berlin')))->setTitle('Sitemap Aware Content last mod date')->setName('sitemap-aware-last-mod-date')->setParentDocument($contentRoot)->setBody('Content for that is sitemap aware, that has last modified date.'); $manager->persist($lastModifiedContent); $route = new Route(); $route->setPosition($routeRoot, 'sitemap-aware-last-mod-date'); $route->setContent($lastModifiedContent); $manager->persist($route); $manager->flush(); }
/** * @return Page instance with the specified information */ protected function createPage(ObjectManager $dm, $parent, $name, $label, array $content) { $page = new MultilangPage(); $page->setPosition($parent, $name); $page->setLabel($label); $dm->persist($page); foreach ($content as $locale => $data) { $page->setTitle($data[0]); $page->setBody($data[1]); if ($locale) { $dm->bindTranslation($page, $locale); } } return $page; }
public function load(ObjectManager $manager) { $session = $manager->getPhpcrSession(); $basepath = '/cms/piccolo'; NodeHelper::createPath($session, $basepath); $yaml = new Parser(); $data = $yaml->parse(file_get_contents(__DIR__ . '/../../Resources/data/page.yml')); $parent = $manager->find(null, $basepath); foreach ($data['static'] as $overview) { $path = $basepath . '/' . $overview['name']; $page = $manager->find(null, $path); if (!$page) { $class = isset($overview['class']) ? $overview['class'] : 'ConnectHolland\\PiccoloContentBundle\\Document\\StandardPage'; $page = new $class(); $page->setName($overview['name']); $page->setParent($parent); // Routing $template = isset($overview['template']) ? $overview['template'] : 'ConnectHollandMainBundle:Page:Standard.html.twig'; $page->setTemplate($template); $manager->persist($page); } if (is_array($overview['title'])) { // Multilanguage foreach ($overview['title'] as $locale => $title) { $page->setTitle($title); $page->setBody($overview['body'][$locale]); $manager->bindTranslation($page, $locale); } } else { $page->setTitle($overview['title']); $page->setBody($overview['body']); if ($class == 'ConnectHolland\\PiccoloContentBundle\\Document\\NewsPage') { $page->setDate(new \DateTime($overview['date'])); } } if (isset($overview['blocks'])) { foreach ($overview['blocks'] as $name => $block) { $this->loadBlock($manager, $page, $name, $block); } } } $manager->flush(); //to get ref id populated }
public function load(ObjectManager $manager) { if (!$this->container) { throw new \Exception("This does not work without container"); } $basepath = $this->container->getParameter('symfony_cmf_content.static_basepath'); $this->createPath($basepath); $yaml = new Parser(); $data = $yaml->parse(file_get_contents(__DIR__ . '/../static/page.yml')); foreach ($data['static'] as $overview) { $path = $basepath . '/' . $overview['name']; $page = $manager->find(null, $path); if (!$page) { $class = isset($overview['class']) ? $overview['class'] : 'Sandbox\\MainBundle\\Document\\EditableStaticContent'; $page = new $class(); $page->setPath($path); $manager->persist($page); } $page->name = $overview['name']; if (is_array($overview['title'])) { foreach ($overview['title'] as $locale => $title) { $page->title = $title; $page->body = $overview['content'][$locale]; $manager->bindTranslation($page, $locale); } } else { $page->title = $overview['title']; $page->body = $overview['content']; } if (isset($overview['blocks'])) { foreach ($overview['blocks'] as $name => $block) { $this->loadBlock($manager, $page, $name, $block); } } } $manager->flush(); //to get ref id populated }
public function load(ObjectManager $manager) { NodeHelper::createPath($manager->getPhpcrSession(), '/test'); NodeHelper::createPath($manager->getPhpcrSession(), '/test/content'); NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes/content'); $contentRoot = $manager->find(null, '/test/content'); $routeRoot = $manager->find(null, '/test/routes/content'); $content = new SeoAwareContent(); $content->setName('content-1'); $content->setTitle('Content 1'); $content->setBody('Content 1'); $content->setParentDocument($contentRoot); $metadata = new SeoMetadata(); $metadata->setTitle('Title content 1'); $metadata->setMetaDescription('Description of content 1.'); $metadata->setMetaKeywords('content1, content'); $metadata->setOriginalUrl('/to/original'); $content->setSeoMetadata($metadata); $manager->persist($content); $route = new Route(); $route->setPosition($routeRoot, 'content-1'); $route->setContent($content); $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction'); $manager->persist($route); $content = new ContentWithExtractors(); $content->setName('strategy-title'); $content->setTitle('Strategy title'); $content->setBody('content of strategy test.'); $content->setParentDocument($contentRoot); $manager->persist($content); $route = new Route(); $route->setPosition($routeRoot, 'strategy-content'); $route->setContent($content); $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction'); $manager->persist($route); $content = new SeoAwareContent(); $content->setName('content-extra'); $content->setTitle('Content extra'); $content->setBody('Content for extra properties.'); $content->setParentDocument($contentRoot); $metadata = new SeoMetadata(); $metadata->addExtraProperty('og:title', 'extra title'); $metadata->addExtraName('robots', 'index, follow'); $metadata->addExtraHttp('Content-Type', 'text/html; charset=utf-8'); $content->setSeoMetadata($metadata); $manager->persist($content); $route = new Route(); $route->setPosition($routeRoot, 'content-extra'); $route->setContent($content); $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction'); $manager->persist($route); $alternateLocaleContent = new AlternateLocaleContent(); $alternateLocaleContent->setName('alternate-locale-content'); $alternateLocaleContent->setTitle('Alternate locale content'); $alternateLocaleContent->setBody('Body of some alternate locate content'); $alternateLocaleContent->setParentDocument($contentRoot); $manager->persist($alternateLocaleContent); $manager->bindTranslation($alternateLocaleContent, 'en'); // creating the locale base routes as generic for now NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes/de'); NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes/en'); $deRoute = $manager->find(null, '/test/routes/de'); $enRoute = $manager->find(null, '/test/routes/en'); $alternateLocaleRoute = new Route(); $alternateLocaleRoute->setPosition($enRoute, 'alternate-locale-content'); $alternateLocaleRoute->setContent($alternateLocaleContent); $alternateLocaleRoute->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction'); $manager->persist($alternateLocaleRoute); $alternateLocaleContent->setTitle('Alternative Sprachen'); $manager->bindTranslation($alternateLocaleContent, 'de'); $alternateLocaleRoute = new Route(); $alternateLocaleRoute->setPosition($deRoute, 'alternate-locale-content'); $alternateLocaleRoute->setContent($alternateLocaleContent); $alternateLocaleRoute->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction'); $manager->persist($alternateLocaleRoute); // create content in a deeper structure $content = new SeoAwareContent(); $content->setName('content-deeper'); $content->setTitle('Content deeper'); $content->setBody('Content deeper Body'); $content->setParentDocument($contentRoot); $manager->persist($content); $route = new Route(); $route->setPosition($manager->find(null, '/test/routes/content/content-1'), 'content-deeper'); $route->setContent($content); $route->setDefault('_controller', 'Symfony\\Cmf\\Bundle\\SeoBundle\\Tests\\Resources\\Controller\\TestController::indexAction'); $manager->persist($route); $manager->flush(); }
private function loadPage(ObjectManager $manager, $basepath, $pageData) { $class = isset($pageData['class']) ? $pageData['class'] : SeoPage::class; $format = isset($pageData['format']) ? $pageData['format'] : 'html'; $parent = isset($pageData['parent']) ? trim($pageData['parent'], '/') : ''; $name = isset($pageData['name']) ? trim($pageData['name'], '/') : ''; $path = $basepath . (empty($parent) ? '' : '/' . $parent) . (empty($name) ? '' : '/' . $name); $page = $manager->find($class, $path); if (!$page) { $page = new $class(); $page->setId($path); } if (isset($pageData['formats'])) { $page->setDefault('_format', reset($pageData['formats'])); $page->setRequirement('_format', implode('|', $pageData['formats'])); } if (!empty($pageData['template'])) { $page->setDefault(RouteObjectInterface::TEMPLATE_NAME, $pageData['template']); } if (!empty($pageData['controller'])) { $page->setDefault(RouteObjectInterface::CONTROLLER_NAME, $pageData['controller']); } if (!empty($pageData['options'])) { $page->setOptions($pageData['options']); } if (!empty($pageData['seo-metadata']) && $page instanceof SeoAwareInterface) { $seoMetadata = new SeoMetadata(); $seoMetadata->setMetaDescription(!empty($pageData['seo-metadata']['description']) ? $pageData['seo-metadata']['description'] : ''); $seoMetadata->setMetaKeywords(!empty($pageData['seo-metadata']['keywords']) ? $pageData['seo-metadata']['keywords'] : ''); $seoMetadata->setOriginalUrl(!empty($pageData['seo-metadata']['original-url']) ? $pageData['seo-metadata']['original-url'] : ''); $page->setSeoMetadata($seoMetadata); } if ($page instanceof SitemapAwareInterface) { $page->setIsVisibleForSitemap(true); } $manager->persist($page); if (is_array($pageData['title'])) { foreach ($pageData['title'] as $locale => $title) { $page->setTitle($title); if (isset($pageData['label'][$locale]) && $pageData['label'][$locale]) { $page->setLabel($pageData['label'][$locale]); } elseif (!isset($pageData['label'][$locale])) { $page->setLabel($title); } $page->setBody($this->parseBody($pageData['body'][$locale], $format)); $manager->bindTranslation($page, $locale); } } else { $page->setTitle($pageData['title']); if (isset($pageData['label'])) { if ($pageData['label']) { $page->setLabel($pageData['label']); } } elseif (!isset($pageData['label'])) { $page->setLabel($pageData['title']); } $page->setBody($this->parseBody($pageData['body'], $format)); } if (isset($pageData['create_date'])) { $page->setCreateDate(date_create_from_format('U', strtotime($pageData['create_date']))); } if (isset($pageData['publish_start_date'])) { $page->setPublishStartDate(date_create_from_format('U', strtotime($pageData['publish_start_date']))); } if (isset($pageData['publish_end_date'])) { $page->setPublishEndDate(date_create_from_format('U', strtotime($pageData['publish_end_date']))); } }
public function load(ObjectManager $dm) { $session = $dm->getPhpcrSession(); $basepath = $this->getBasePath(); NodeHelper::createPath($session, $basepath); $data = $this->getData(); $defaultClass = $this->getDefaultClass(); $paths = array('/' => $basepath); foreach ($data['static'] as $overview) { $class = isset($overview['class']) ? $overview['class'] : $defaultClass; $overview['parent'] = empty($overview['parent']) ? '/' : $overview['parent']; $path = $paths[$overview['parent']] . ($overview['name'] ? '/' . $overview['name'] : ''); $paths[$overview['parent'] . $overview['name']] = $path; $page = $dm->find($class, $path); if (!$page) { $page = $this->createPageInstance($class); $page->setPath($path); } if (isset($overview['formats'])) { $page->setDefault('_format', reset($overview['formats'])); $page->setRequirement('_format', implode('|', $overview['formats'])); } if (!empty($overview['template'])) { $page->setDefault(RouteObjectInterface::TEMPLATE_NAME, $overview['template']); } if (!empty($overview['controller'])) { $page->setDefault(RouteObjectInterface::CONTROLLER_NAME, $overview['controller']); } if (!empty($overview['options'])) { $page->setOptions($overview['options']); } $dm->persist($page); if (is_array($overview['title'])) { foreach ($overview['title'] as $locale => $title) { $page->setTitle($title); if (isset($overview['label'][$locale]) && $overview['label'][$locale]) { $page->setLabel($overview['label'][$locale]); } elseif (!isset($overview['label'][$locale])) { $page->setLabel($title); } $page->setBody($overview['body'][$locale]); $dm->bindTranslation($page, $locale); } } else { $page->setTitle($overview['title']); if (isset($overview['label'])) { if ($overview['label']) { $page->setLabel($overview['label']); } } elseif (!isset($overview['label'])) { $page->setLabel($overview['title']); } $page->setBody($overview['content']); } if (isset($overview['create_date'])) { $page->setCreateDate(date_create_from_format('U', strtotime($overview['create_date']))); } if (isset($overview['publish_start_date'])) { $page->setPublishStartDate(date_create_from_format('U', strtotime($overview['publish_start_date']))); } if (isset($overview['publish_end_date'])) { $page->setPublishEndDate(date_create_from_format('U', strtotime($overview['publish_end_date']))); } } $dm->flush(); }