Skip to content

Commit 564275a

Browse files
committed
added more examples of mixed documents
1 parent c8d3b31 commit 564275a

File tree

9 files changed

+117
-33
lines changed

9 files changed

+117
-33
lines changed

app/config/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ symfony_cmf_simple_cms:
7979
routing:
8080
templates_by_class:
8181
Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page: SymfonyCmfSimpleCmsBundle:Page:index.html.twig
82+
controllers_by_class:
83+
Symfony\Cmf\Bundle\RoutingExtraBundle\Document\RedirectRoute: symfony_cmf_routing_extra.redirect_controller:redirectAction
8284
multilang:
8385
locales: %locales%
8486
use_sonata_admin: false

app/config/routing.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ home_redirect:
1010
route: /cms/simple
1111
permanent: true # this for 301
1212

13+
static:
14+
pattern: /{_locale}/static
15+
defaults:
16+
_controller: AcmeMainBundle:Demo:static
17+
requirements:
18+
_locale: en|de
19+
1320
cmf_create_rest:
1421
resource: "@SymfonyCmfCreateBundle/Resources/config/routing/rest.xml"
1522

app/tests/StaticPageTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function contentDataProvider()
4040
array('/en/contact/map', 'A map of a location in the US'),
4141
array('/de/contact/map', 'Eine Karte von einem Ort in Deutschland'),
4242
array('/en/contact/team', 'A team page'),
43+
array('/en/static', 'A hardcoded title'),
4344
);
4445
}
4546

@@ -53,11 +54,23 @@ public function testMenu()
5354

5455
$this->assertEquals('/en/contact/map', $crawler->selectLink('Map')->attr('href'), 'Page does not contain an a tag pointing to: /en/contact/map');
5556
$this->assertEquals('http://cmf.symfony.com', $crawler->selectLink('Website')->attr('href'), 'Page does not contain an a tag pointing to: cmf.symfony.com');
56-
$this->assertEquals('http://cmf.liip.ch', $crawler->selectLink('Demo')->attr('href'), 'Page does not contain an a tag pointing to: cmf.symfony.com');
57+
$this->assertEquals('/en/demo', $crawler->selectLink('Demo')->attr('href'), 'Page does not contain an a tag pointing to: /en/demo');
5758

5859
$crawler = $client->request('GET', '/de/about');
5960

6061
$this->assertEquals(200, $client->getResponse()->getStatusCode());
6162
$this->assertEquals('http://cmf.symfony.com', $crawler->selectLink('Webseite')->attr('href'), 'Page does not contain an a tag pointing to: cmf.symfony.com');
6263
}
64+
65+
public function testRedirectToDemo()
66+
{
67+
$client = $this->createClient();
68+
69+
$client->request('GET', '/en/demo');
70+
71+
$this->assertEquals(302, $client->getResponse()->getStatusCode());
72+
73+
$this->assertEquals('http://cmf.liip.ch', $client->getResponse()->headers->get('Location'));
74+
}
75+
6376
}

composer.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Acme\MainBundle\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
7+
class DemoController extends Controller
8+
{
9+
public function dynamicAction()
10+
{
11+
return $this->render('AcmeMainBundle:Demo:dynamic.html.twig');
12+
}
13+
14+
public function staticAction()
15+
{
16+
return $this->render('AcmeMainBundle:Demo:static.html.twig');
17+
}
18+
}

src/Acme/MainBundle/DataFixtures/PHPCR/LoadSimpleCmsData.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page;
1414
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangPage;
15+
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRoute;
16+
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangRedirectRoute;
1517
use Symfony\Cmf\Bundle\MenuBundle\Document\MultilangMenuItem;
1618

1719
class LoadSimpleCmsData extends ContainerAware implements FixtureInterface
@@ -38,7 +40,23 @@ public function load(ObjectManager $dm)
3840
$this->createPage($dm, $contact, 'team', 'Team', array('' => array('A team page', 'Our team consists of C, M and F.')));
3941

4042
$this->createMenuItem($dm, $root, 'link', 'http://cmf.symfony.com', array('en' => 'Website', 'de' => 'Webseite'));
41-
$this->createMenuItem($dm, $root, 'demo', 'http://cmf.liip.ch', array('en' => 'Demo', 'de' => 'Demo'));
43+
44+
$route = new MultilangRedirectRoute();
45+
$route->setPosition($root, 'demo');
46+
$route->setUri('http://cmf.liip.ch');
47+
$dm->persist($route);
48+
49+
$this->createMenuItem($dm, $root, 'demo_redirect', $route, array('en' => 'Demo', 'de' => 'Demo'));
50+
51+
$route = new MultilangRoute();
52+
$route->setPosition($root, 'dynamic');
53+
$route->setDefault('_controller', 'AcmeMainBundle:Demo:dynamic');
54+
55+
$dm->persist($route);
56+
57+
$this->createMenuItem($dm, $root, 'hardcoded_dynamic', $route, array('en' => 'Dynamic', 'de' => 'Dynamisch'));
58+
59+
$this->createMenuItem($dm, $root, 'hardcoded_static', 'static', array('en' => 'Static', 'de' => 'Statisch'));
4260

4361
$dm->flush();
4462
}
@@ -67,11 +85,15 @@ protected function createPage(ObjectManager $dm, $parent, $name, $label, array $
6785
/**
6886
* @return MenuItem instance with the specified information
6987
*/
70-
protected function createMenuItem(ObjectManager $dm, $parent, $name, $uri, array $content)
88+
protected function createMenuItem(ObjectManager $dm, $parent, $name, $target, array $content)
7189
{
7290
$menuItem = new MultilangMenuItem();
7391
$menuItem->setPosition($parent, $name);
74-
$menuItem->setUri($uri);
92+
if (is_object($target)) {
93+
$menuItem->setRoute($target->getPath());
94+
} else {
95+
$menuItem->setUri($target);
96+
}
7597

7698
$dm->persist($menuItem);
7799
foreach ($content as $locale => $label) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends "AcmeMainBundle::layout.html.twig" %}
2+
3+
{% set title = 'A hardcoded title' %}
4+
{% block title %}{{ title }}{% endblock %}
5+
6+
{% block content %}
7+
8+
<h1>{{ title }}</h1>
9+
10+
This is some hardcoded text on a dynamic route
11+
12+
{% endblock %}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends "AcmeMainBundle::layout.html.twig" %}
2+
3+
{% set title = 'A hardcoded title' %}
4+
{% block title %}{{ title }}{% endblock %}
5+
6+
{% block content %}
7+
8+
<h1>{{ title }}</h1>
9+
10+
This is some hardcoded text on a static route
11+
12+
{% endblock %}

src/Acme/MainBundle/Resources/views/layout.html.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
</div>
3131
<div id="language_selector" class="pull-right">
3232
{% block language_selector %}
33-
{% if cmfMainContent is defined %}
34-
{{ locale_switcher(cmfMainContent) }}
35-
{% endif %}
33+
{{ locale_switcher() }}
3634
{% endblock %}
3735
</div>
3836
</div>

0 commit comments

Comments
 (0)