Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
    /**
     * @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
    }