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

Commit 8e49370

Browse files
committed
WIP rewrite quick tour to sandbox
1 parent 1db138f commit 8e49370

File tree

7 files changed

+135
-106
lines changed

7 files changed

+135
-106
lines changed
-29.5 KB
Binary file not shown.
13.8 KB
Loading

big-picture-home.png

83.3 KB
Loading

quick_tour/the_big_picture.rst

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ 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
3333
can decide to only use one of them (e.g. only the RoutingBundle or the SeoBundle).
3434

35-
Downloading the Symfony CMF Standard Edition
36-
--------------------------------------------
35+
Downloading the Symfony CMF Sandbox
36+
-----------------------------------
3737

38-
When you want to start using the CMF for a new project, you can download the
38+
To explore the CMF, it is best to download the Symfony CMF Sandbox. The sandbox
39+
contains demonstrations for many of the CMF features and is a good playground
40+
to familiarize yourself with the CMF.
41+
42+
When you want to start an actual project with the CMF, best download the
3943
Symfony CMF Standard Edition. The Symfony CMF Standard Edition is similar to
4044
the `Symfony Standard Edition`_, but contains and configures essential Symfony
41-
CMF bundles. It also adds a very simple bundle to show some of the basic
42-
Symfony CMF features.
45+
CMF bundles.
4346

44-
The best way to download the Symfony CMF Standard Edition is using Composer_:
47+
The best way to download the Symfony CMF Sandbox is using Composer_:
4548

4649
.. code-block:: bash
4750
48-
$ composer create-project symfony-cmf/standard-edition cmf
51+
$ composer create-project symfony-cmf/sandbox cmf-sandbox
4952
5053
Setting up the Database
5154
~~~~~~~~~~~~~~~~~~~~~~~
@@ -60,11 +63,12 @@ extension. After that, run these commands:
6063

6164
.. code-block:: bash
6265
66+
$ cd cmf-sandbox
67+
$ cp app/config/phpcr_doctrine_dbal.yml.dist app/config/phpcr.yml
6368
$ php bin/console doctrine:database:create
6469
$ php bin/console doctrine:phpcr:init:dbal --force
6570
$ php bin/console doctrine:phpcr:repository:init
66-
# TODO there are no fixtures in the standard edition anymore...
67-
$ php bin/console doctrine:phpcr:fixtures:load
71+
$ php bin/console doctrine:phpcr:fixtures:load -n
6872
6973
.. tip::
7074

@@ -87,9 +91,11 @@ The Request Flow
8791
inside the Symfony project, if that is not already the root folder of your
8892
server).
8993

90-
Now, the Standard Edition is ready to use. Navigate to the homepage
94+
Now, the Sandbox is ready to use. Navigate to the homepage
9195
(``http://localhost:8000/``) to see the demo:
9296

97+
redo image with current sandbox
98+
9399
.. image:: ../_images/quick_tour/big-picture-home.png
94100

95101
You see that we already have a complete website in our demo. Let's take a
@@ -165,33 +171,24 @@ this template.
165171
A view also uses a Menu, provided by the KnpMenuBundle_, and it can have
166172
integration with Create.js, for live editing.
167173

168-
Adding a New Page
169-
-----------------
170-
171-
Now you know the request flow, you can start adding a new page. In the Symfony
172-
CMF Standard Edition, the data is stored in data files, which are loaded when
173-
executing the ``doctrine:phpcr:fixtures:load`` command. To add a new page, edit
174-
one of the data files located in the
175-
``src/AppBundle/Resources/data`` directory:
176-
177-
TODO: replace example, simplecms bundle is not maintained anymore
178-
179-
.. code-block:: yaml
180-
181-
# src/AppBundle/Resources/data/pages.yml
182-
Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page:
183-
# ...
174+
The Fixtures
175+
------------
184176

185-
quick_tour:
186-
id: /cms/simple/quick_tour
187-
label: "Quick Tour"
188-
title: "Reading the Quick Tour"
189-
body: "I've added this page while reading the quick tour"
177+
Now you know the request flow, you can start editing content. While the normal
178+
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+
purposes.
190181

191-
After this, you need to run the ``doctrine:phpcr:fixtures:load`` to reflect
192-
the changes on the database and after refreshing, you can see your new page!
182+
The fixtures are loaded with the ``doctrine:phpcr:fixtures:load`` command. To
183+
edit the home page, edit the first entry in
184+
``src/AppBundle/Resources/data/page.yml`` to say something different. Then, run
185+
the ``doctrine:phpcr:fixtures:load`` command to get the changes into the
186+
content repository. After refreshing the browser, you can see your
187+
modifications!
193188

194-
.. image:: ../_images/quick_tour/big-picture-new-page.png
189+
Don't worry, editing fixture files is only done for developing and testing. The
190+
CMF comes with a Sonata admin integration for convenient online editing, or you
191+
can build your own editing systems.
195192

196193
Final Thoughts
197194
--------------

quick_tour/the_model.rst

Lines changed: 79 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data stored with PHPCR has a relationship with at least one other data: its
2323
parent. The inverse relation also exists, you can also get the children of a
2424
data element.
2525

26-
Let's take a look at the dump of the tree of the Standard Edition you
26+
Let's take a look at the dump of the tree of the CMF Sandbox you
2727
downloaded in the previous chapter. Go to your directory and execute the
2828
following command:
2929

@@ -36,30 +36,43 @@ The result will be the PHPCR tree:
3636
.. code-block:: text
3737
3838
ROOT:
39-
cms:
40-
simple:
41-
about:
42-
contact:
43-
map:
44-
team:
45-
quick_tour:
46-
dynamic:
47-
docs:
48-
demo:
49-
demo_redirect:
50-
hardcoded_dynamic:
51-
hardcoded_static:
52-
53-
Each data is called a *node* in PHPCR. In this tree, there are 13 nodes and
54-
one ROOT node (created by PHPCR). You may have already seen the document you
55-
created in the previous section, it's called ``quick_tour`` (and it's path is
56-
``/cms/simple/quick_tour``). When using the SimpleCmsBundle, all nodes are
57-
stored in the ``/cms/simple`` path.
39+
cms:
40+
menu:
41+
main:
42+
admin-item:
43+
projects-item:
44+
cmf-item:
45+
company-item:
46+
team-item:
47+
...
48+
content:
49+
home:
50+
phpcr_locale:en:
51+
phpcr_locale:fr:
52+
phpcr_locale:de:
53+
seoMetadata:
54+
additionalInfoBlock:
55+
child1:
56+
...
57+
routes:
58+
en:
59+
company:
60+
team:
61+
more:
62+
about:
63+
...
64+
65+
Each data is called a *node* in PHPCR. Everything is attached under the ROOT
66+
node (created by PHPCR itself).
5867

5968
Each node has properties, which contain the data. The content, title and label
60-
you set for your page are saved in such properties for the ``quick_tour``
69+
you set for your page are saved in such properties for the ``home``
6170
node. You can view these properties by adding the ``--props`` switch to the
62-
dump command.
71+
dump command:
72+
73+
.. code-block:: bash
74+
75+
$ php bin/console doctrine:phpcr:node:dump --props /cms/content/home
6376
6477
.. note::
6578

@@ -74,20 +87,21 @@ Doctrine PHPCR-ODM
7487
The Symfony CMF uses the `Doctrine PHPCR-ODM`_ to interact with PHPCR.
7588
Doctrine allows a user to create objects (called *documents*) which are
7689
directly persisted into and retrieved from the PHPCR tree. This is similar to
77-
the Doctrine ORM used by the Symfony2 Framework, but then for PHPCR.
90+
the Doctrine ORM provided by default in the Symfony Standard Edition, but for
91+
PHPCR instead of SQL databases.
7892

7993
Creating a Page with code
8094
-------------------------
8195

8296
Now you know a little bit more about PHPCR and you know the tool to interact
83-
with it, you can start using it yourself. In the previous chapter, you created
84-
a page by using a yaml file which was parsed by the SimpleCmsBundle. This
85-
time, you'll create a page by doing it yourself.
97+
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.
86100

87101
First, you have to create a new DataFixture to add your new page. You do this
88102
by creating a new class in the AppBundle::
89103

90-
// src/AppBundle/DataFixtures/PHPCR/LoadPageData.php
104+
// src/AppBundle/DataFixtures/PHPCR/LoadQuickTourData.php
91105
namespace AppBundle\DataFixtures\PHPCR;
92106

93107
use Doctrine\Common\Persistence\ObjectManager;
@@ -100,7 +114,7 @@ by creating a new class in the AppBundle::
100114
{
101115
// refers to the order in which the class' load function is called
102116
// (lower return values are called first)
103-
return 10;
117+
return 100;
104118
}
105119

106120
public function load(ObjectManager $documentManager)
@@ -123,7 +137,10 @@ PHPCR. But first, you have to create a new Page document::
123137
}
124138

125139
$page = new Page(); // create a new Page object (document)
126-
$page->setName('new_page'); // the name of the node
140+
$page->setName('quick-tour'); // the name of the node
141+
142+
vno sandbox übernehmen
143+
127144
$page->setLabel('Another new Page');
128145
$page->setTitle('Another new Page');
129146
$page->setBody('I have added this page myself!');
@@ -133,16 +150,9 @@ Each document needs a parent. In this case, the parent should just be the root
133150
node. To do this, we first retrieve the root document from PHPCR and then set
134151
it as its parent::
135152

136-
// ...
137153
public function load(ObjectManager $documentManager)
138154
{
139-
if (!$documentManager instanceof DocumentManager) {
140-
$class = get_class($documentManager);
141-
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
142-
}
143-
144155
// ...
145-
146156
// get root document (/cms/simple)
147157
$simpleCmsRoot = $documentManager->find(null, '/cms/simple');
148158

@@ -152,21 +162,46 @@ it as its parent::
152162
And at last, we have to tell the Document Manager to persist our Page
153163
document using the Doctrine API::
154164

155-
// ...
156165
public function load(ObjectManager $documentManager)
157166
{
158-
if (!$documentManager instanceof DocumentManager) {
159-
$class = get_class($documentManager);
160-
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
161-
}
162-
163167
// ...
164168
$documentManager->persist($page); // add the Page in the queue
165169
$documentManager->flush(); // add the Page to PHPCR
166170
}
167171

168-
Now you need to execute the ``doctrine:phpcr:fixtures:load`` command again and
169-
then you can visit your website again. You'll see your new page you added!
172+
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!
170205

171206
.. image:: ../_images/quick_tour/the-model-new-page.png
172207

0 commit comments

Comments
 (0)