Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit ba4955a

Browse files
committed
wrap up rewriting the quick tour
1 parent 8e49370 commit ba4955a

8 files changed

+136
-260
lines changed
Loading
Loading

quick_tour/the_big_picture.rst

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ other hand, when choosing to use a CMS, it's more difficult to build custom
2323
application functionality. It is impossible or at least very hard to customize
2424
the core parts of the CMS.
2525

26-
The CMF is created to solve this framework versus CMS dilemma. It provides
27-
bundles, so you can easily add CMS features to your project. But it also
28-
provides flexibility and you can use the underlying Symfony framework to
29-
build custom functionality the way you want. This is called a `decoupled CMS`_.
26+
The Symfony CMF is created to solve this framework versus CMS dilemma. It
27+
provides Symfony bundles to easily add CMS features to your project. Yet, as
28+
you're still using the Symfony framework, you can build any custom functionality
29+
you can think of. This flexibility is called a `decoupled CMS`_.
3030

3131
The bundles provided by the Symfony CMF can work together, but they are also
3232
able to work standalone. This means that you don't need to add all bundles, you
33-
can decide to only use one of them (e.g. only the RoutingBundle or the SeoBundle).
33+
can decide to only use one of them (e.g. only the RoutingBundle).
3434

3535
Downloading the Symfony CMF Sandbox
3636
-----------------------------------
@@ -65,6 +65,9 @@ extension. After that, run these commands:
6565

6666
$ cd cmf-sandbox
6767
$ cp app/config/phpcr_doctrine_dbal.yml.dist app/config/phpcr.yml
68+
# Or when you're on a Windows PC:
69+
# $ copy app\config\phpcr_doctrine_dbal.yml.dist app\config\phpcr.yml
70+
6871
$ php bin/console doctrine:database:create
6972
$ php bin/console doctrine:phpcr:init:dbal --force
7073
$ php bin/console doctrine:phpcr:repository:init
@@ -94,8 +97,6 @@ The Request Flow
9497
Now, the Sandbox is ready to use. Navigate to the homepage
9598
(``http://localhost:8000/``) to see the demo:
9699

97-
redo image with current sandbox
98-
99100
.. image:: ../_images/quick_tour/big-picture-home.png
100101

101102
You see that we already have a complete website in our demo. Let's take a
@@ -176,7 +177,7 @@ The Fixtures
176177

177178
Now you know the request flow, you can start editing content. While the normal
178179
usage will be to edit content through a web interface, the CMF sandbox also
179-
supports loading content from static files. This is mainly useful for testing
180+
supports loading content from static files. This is mainly useful for testing
180181
purposes.
181182

182183
The fixtures are loaded with the ``doctrine:phpcr:fixtures:load`` command. To

quick_tour/the_model.rst

+26-61
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ dump command:
7777
.. note::
7878

7979
Previously, the PHPCR tree was compared with a Filesystem. While this
80-
gives you a good image of what happens, it's not the truth. You can
81-
better compare it to an XML file, where each node is an element and its
80+
gives you a good image of what happens, it's not the only truth. You can
81+
compare it to an XML file, where each node is an element and its
8282
properties are attributes.
8383

8484
Doctrine PHPCR-ODM
@@ -90,13 +90,13 @@ directly persisted into and retrieved from the PHPCR tree. This is similar to
9090
the Doctrine ORM provided by default in the Symfony Standard Edition, but for
9191
PHPCR instead of SQL databases.
9292

93-
Creating a Page with code
94-
-------------------------
93+
Creating Content from Code
94+
--------------------------
9595

96-
Now you know a little bit more about PHPCR and you know the tool to interact
96+
Now that you know a little bit more about PHPCR and you know the tool to interact
9797
with it, you can start using it yourself. In the previous chapter, you edited
98-
a page by using a yaml file which was parsed by the fixture loader of the
99-
sandbox. This time, you'll create a page by doing it yourself.
98+
a page by using a Yaml file which was parsed by the fixture loader of the
99+
sandbox. This time, you'll create a page with PHP code.
100100

101101
First, you have to create a new DataFixture to add your new page. You do this
102102
by creating a new class in the AppBundle::
@@ -108,7 +108,7 @@ by creating a new class in the AppBundle::
108108
use Doctrine\Common\DataFixtures\FixtureInterface;
109109
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
110110

111-
class LoadPageData implements FixtureInterface, OrderedFixtureInterface
111+
class LoadQuickTourData implements FixtureInterface, OrderedFixtureInterface
112112
{
113113
public function getOrder()
114114
{
@@ -119,91 +119,56 @@ by creating a new class in the AppBundle::
119119

120120
public function load(ObjectManager $documentManager)
121121
{
122+
// you will add code to this method in the next steps
122123
}
123124
}
124125

125126
The ``$documentManager`` is the object which will persist the document to
126127
PHPCR. But first, you have to create a new Page document::
127128

128129
use Doctrine\ODM\PHPCR\DocumentManager;
129-
use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
130+
use Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContent;
130131

131132
// ...
132133
public function load(ObjectManager $documentManager)
133134
{
134135
if (!$documentManager instanceof DocumentManager) {
135-
$class = get_class($documentManager);
136-
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
136+
throw new \RuntimeException(sprintf(
137+
'Fixture requires a PHPCR ODM DocumentManager instance, instance of "%s" given.',
138+
get_class($documentManager)
139+
));
137140
}
138141

139-
$page = new Page(); // create a new Page object (document)
140-
$page->setName('quick-tour'); // the name of the node
141-
142-
vno sandbox übernehmen
143-
144-
$page->setLabel('Another new Page');
145-
$page->setTitle('Another new Page');
146-
$page->setBody('I have added this page myself!');
142+
$content = new StaticContent();
143+
$content->setName('quick-tour'); // the name of the node
144+
$content->setTitle('Quick tour new Page');
145+
$content->setBody('I have added this page myself!');
147146
}
148147

149-
Each document needs a parent. In this case, the parent should just be the root
148+
Each document needs a parent. In this case, the parent should be the content root
150149
node. To do this, we first retrieve the root document from PHPCR and then set
151150
it as its parent::
152151

153152
public function load(ObjectManager $documentManager)
154153
{
155154
// ...
156-
// get root document (/cms/simple)
157-
$simpleCmsRoot = $documentManager->find(null, '/cms/simple');
158-
159-
$page->setParentDocument($simpleCmsRoot); // set the parent to the root
155+
// get the root document
156+
$contentRoot = $documentManager->find(null, '/cms/content');
157+
$content->setParentDocument($contentRoot); // set the parent to the root
160158
}
161159

162-
And at last, we have to tell the Document Manager to persist our Page
160+
And finally, we have to tell the Document Manager to persist our content
163161
document using the Doctrine API::
164162

165163
public function load(ObjectManager $documentManager)
166164
{
167165
// ...
168-
$documentManager->persist($page); // add the Page in the queue
169-
$documentManager->flush(); // add the Page to PHPCR
166+
$documentManager->persist($content); // tell the document manager to track the content
167+
$documentManager->flush(); // doctrine is like a toilet: never forget to flush
170168
}
171169

172170
Now you need to execute the ``doctrine:phpcr:fixtures:load`` command again.
173-
When dumping the nodes again, your new page should turn up under /cms/content.
174-
175-
To actually see this page in the browser, we need a route::
176-
177-
public function load(ObjectManager $documentManager)
178-
{
179-
// ...
180-
$route = new Route();
181-
$routeRoot = $documentManager->find(null, '/cms/routes/en');
182-
$route->setPosition($routeRoot, 'quick-tour');
183-
$route->setContent($page);
184-
$documentManager->persist($route);
185-
}
186-
187-
And we add a menu entry to link to this page, and flush the document manager
188-
at the end::
189-
190-
public function load(ObjectManager $documentManager)
191-
{
192-
$menu = new MenuNode();
193-
$menu->setName('new_page');
194-
$menu->setLabel('Quick Tour');
195-
$menu->setContent($page);
196-
$menuMain = $documentManager->find(null, '/cms/menu/main');
197-
$menu->setParentDocument($menuMain);
198-
$documentManager->persist($menu);
199-
200-
$documentManager->flush();
201-
}
202-
203-
Re-run the fixtures loading command and then refresh the web site. Your new
204-
page will be added, with a menu entry at the bottom of the menu!
205-
206-
.. image:: ../_images/quick_tour/the-model-new-page.png
171+
When dumping the nodes again, your new page should show up under ``/cms/content/quick-tour``!
207172

208173
.. seealso::
209174

0 commit comments

Comments
 (0)