/**
  * 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();
 }
 public function testSeoMetadataMapping()
 {
     $content = new SeoAwareContent();
     $content->setTitle('Seo Aware test')->setName('seo-aware')->setParentDocument($this->dm->find(null, '/test'))->setBody('Content for SeoAware Test');
     $seoMetadata = new SeoMetadata();
     $seoMetadata->setTitle('Seo Title')->setMetaDescription('Seo Description')->setMetaKeywords('Seo, Keys')->setOriginalUrl('/test')->setExtraProperties(array('og:title' => 'Extra title'))->setExtraNames(array('robots' => 'index, follow'))->setExtraHttp(array('content-type' => 'text/html'));
     $content->setSeoMetadata($seoMetadata);
     $this->dm->persist($content);
     $this->dm->flush();
     $this->dm->clear();
     $content = $this->dm->find(null, '/test/seo-aware');
     $this->assertNotNull($content);
     $persistedSeoMetadata = $content->getSeoMetadata();
     $this->assertEquals($seoMetadata->getTitle(), $persistedSeoMetadata->getTitle());
     $this->assertEquals($seoMetadata->getMetaDescription(), $persistedSeoMetadata->getMetaDescription());
     $this->assertEquals($seoMetadata->getMetaKeywords(), $persistedSeoMetadata->getMetaKeywords());
     $this->assertEquals($seoMetadata->getOriginalUrl(), $persistedSeoMetadata->getOriginalUrl());
     $this->assertEquals($seoMetadata->getExtraProperties(), $persistedSeoMetadata->getExtraProperties());
     $this->assertEquals($seoMetadata->getExtraNames(), $persistedSeoMetadata->getExtraNames());
     $this->assertEquals($seoMetadata->getExtraHttp(), $persistedSeoMetadata->getExtraHttp());
 }
 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);
     $manager->persist($route);
     $manager->flush();
 }
 public function testDataClassCreationForPhpcr()
 {
     $this->validator->expects($this->any())->method('validate')->will($this->returnValue(array()));
     $formData = array('title' => 'Title', 'originalUrl' => 'original/url', 'extraProperties' => array(), 'extraNames' => array(), 'extraHttp' => array());
     $form = $this->factory->create(SeoMetadataType::class);
     $this->assertTrue($form->getConfig()->getByReference());
     $object = new SeoMetadata();
     $object->setTitle($formData['title']);
     $object->setOriginalUrl($formData['originalUrl']);
     $object->setExtraNames($formData['extraNames']);
     $object->setExtraHttp($formData['extraHttp']);
     $object->setExtraProperties($formData['extraProperties']);
     // submit the data to the form directly
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($object, $form->getData());
 }
 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();
 }
    /**
     * @param DocumentManager $manager
     */
    public function load(ObjectManager $manager)
    {
        if (!$manager instanceof DocumentManager) {
            $class = get_class($manager);
            throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '{$class}' given.");
        }
        $session = $manager->getPhpcrSession();
        $basepath = $this->container->getParameter('cmf_media.persistence.phpcr.media_basepath');
        NodeHelper::createPath($session, $basepath);
        $basepath = $this->container->getParameter('cmf_content.persistence.phpcr.content_basepath');
        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'] : 'AppBundle\\Document\\DemoSeoContent';
                /** @var $page DemoSeoContent */
                $page = new $class();
                $page->setName($overview['name']);
                $page->setParentDocument($parent);
                $manager->persist($page);
            }
            if (is_array($overview['title'])) {
                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 (isset($overview['publishable']) && $overview['publishable'] === false) {
                $page->setPublishable(false);
            }
            if (!empty($overview['publishStartDate'])) {
                $page->setPublishStartDate(new \DateTime($overview['publishStartDate']));
            }
            if (!empty($overview['publishEndDate'])) {
                $page->setPublishEndDate(new \DateTime($overview['publishEndDate']));
            }
            if (isset($overview['blocks'])) {
                foreach ($overview['blocks'] as $name => $block) {
                    $this->loadBlock($manager, $page, $name, $block);
                }
            }
        }
        //add a loading for a simple seo aware page
        $seoDemo = new DemoSeoContent();
        $seoDemo->setName('simple-seo-example');
        $seoDemo->setTitle('Simple seo example');
        $seoDemo->setBody(<<<'EOH'
<p>
    When implementing the SeoAwareInterface,
    you get a chance to configure SEO data
    (title, description, keywords and original url)
    of the document using <code>SeoMetadata</code>.
    The SonataAdminBundle integration allows admins to update this data.
</p>

<a class="docref" href="http://symfony.com/doc/current/cmf/bundles/seo/seo_aware.html"><i class="glyphicon glyphicon-chevron-right"></i>Read about this feature in the CMF documentation.</a>
EOH
);
        $seoDemo->setParentDocument($parent);
        $seoMetadata = new SeoMetadata();
        $seoMetadata->setTitle('Simple seo example');
        $seoMetadata->setOriginalUrl('/home');
        $seoMetadata->setMetaDescription('This is a simple example of an seo aware document in the sandbox.');
        $seoMetadata->setMetaKeywords('Seo');
        $seoDemo->setSeoMetadata($seoMetadata);
        $manager->persist($seoDemo);
        $manager->bindTranslation($seoDemo, 'en');
        //add a loading for a simple seo aware page
        $seoDemo = new DemoSeoContent();
        $seoDemo->setName('simple-seo-property');
        $seoDemo->setTitle('Simple seo property');
        $seoDemo->setBody('<p>
                SeoMetadata have got the possibility to
                to add custom properties for custom
                meta tags. You just to set a type, key
                and value
            </p>');
        $seoDemo->setParentDocument($parent);
        $seoMetadata = new SeoMetadata();
        $seoMetadata->setTitle('Simple seo property');
        $seoMetadata->setMetaKeywords('Seo, Properties');
        $seoMetadata->addExtraHttp('content-type', 'text/html');
        $seoMetadata->addExtraName('robots', 'index, follow');
        $seoMetadata->addExtraProperty('og:title', 'extra title');
        $seoDemo->setSeoMetadata($seoMetadata);
        $manager->persist($seoDemo);
        $manager->bindTranslation($seoDemo, 'en');
        $manager->flush();
        //to get ref id populated
    }
 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'])));
     }
 }