@@ -22,6 +22,36 @@ the lightweight `hallo.js`_ editor bundled with the create.js distribution.
22
22
your HTML for `create.js `_ and map back from the JSON-LD sent by backbone.js
23
23
to your model classes.
24
24
25
+ Concepts
26
+ --------
27
+
28
+ CreatePHP uses `RDFa `_ metadata about your model classes. This metadata is
29
+ used to map between your model and the RDFa information. If you know Doctrine,
30
+ you have seen the idea of metadata to know how class fields map to database
31
+ columns.
32
+
33
+ The CreatePHP metadata is modelled by the ``Type `` class. CreatePHP provides
34
+ metadata loaders that read XML, php arrays and one that just introspects
35
+ objects and creates non-semantical metadata that will be enough for create.js
36
+ to edit.
37
+
38
+ An ``RdfMapper `` is used to translate between your storage layer and CreatePHP.
39
+ It is passed the model instance and the relevant metadata object.
40
+
41
+ With the metadata and the twig helper, the content is rendered with RDFa
42
+ annotations. create.js is loaded and enables editing the content. Note that
43
+ you may have several objects editable on a single page. Save operations happen
44
+ through backbone.js with ajax calls containing JSON-LD data. There is one
45
+ request per editable content that was actually modified. The CreateBundle REST
46
+ controller handles those ajax calls and maps the JSON-LD data back onto your
47
+ model classes and stores them in the database.
48
+
49
+ For image support, CKEditor can use elfinder to upload, browse and insert
50
+ images into the content. See the
51
+ :doc: `MediaBundle elfinder adapter documentation<../media/adapters/elfinder> `
52
+ to enable this powerful image browser.
53
+
54
+
25
55
.. index :: CreateBundle
26
56
27
57
Dependencies
@@ -136,7 +166,7 @@ You also need to configure the FOSRestBundle to handle json:
136
166
Routing
137
167
~~~~~~~
138
168
139
- Finally, you need to register the routing configuration file to your master
169
+ You need to register the routing configuration file in your main
140
170
routing configuration to enable the REST end point for saving content:
141
171
142
172
.. configuration-block ::
@@ -159,155 +189,68 @@ routing configuration to enable the REST end point for saving content:
159
189
160
190
return $collection;
161
191
162
- Access Control
163
- ~~~~~~~~~~~~~~
164
-
165
- In order to limit who can edit content, the provided controllers as well as the
166
- javascript loader check if the current user is granted the configured
167
- ``cmf_create.role ``. By default the role is ROLE_ADMIN.
168
-
169
- If you need more fine grained access control, look into the CreatePHP
170
- ``RdfMapperInterface `` ``isEditable `` method. You can extend a mapper and
171
- overwrite ``isEditable `` to answer whether the passed domain object is
172
- editable.
173
-
174
- Concepts
175
- --------
176
-
177
- CreatePHP uses `RDFa `_ metadata about your model classes. If you know Doctrine,
178
- you should be familiar with this concept, as Doctrine uses such metadata to
179
- know how your class fields map to database columns.
180
-
181
- The metadata is modelled by the ``Type `` class. CreatePHP provides metadata
182
- loaders that read XML, php arrays and one that just introspects objects and
183
- creates non-semantical metadata that will be enough for create.js to edit.
184
-
185
- An ``RdfMapper `` is used to translate between your storage layer and CreatePHP.
186
- It is passed the model instance and the relevant metadata object.
187
-
188
- With the metadata and the twig helper, the content is rendered with RDFa
189
- annotations. create.js is loaded and enables editing the content. Note that
190
- you may have several objects editable on a single page. Save operations happen
191
- through backbone.js with ajax calls containing JSON-LD data. There is one
192
- request per editable content that was actually modified. The CreateBundle REST
193
- controller handles those ajax calls and maps the JSON-LD data back onto your
194
- model classes and stores them in the database.
195
-
196
- For image support, CKEditor can use elfinder to upload, browse and insert
197
- images into the content. See the
198
- :doc: `MediaBundle elfinder adapter documentation<../media/adapters/elfinder> `
199
- to enable this powerful image browser.
200
-
201
- Metadata
202
- ~~~~~~~~
203
-
204
- CreatePHP needs metadata information for each class of your domain model. By
205
- default, the create bundle uses the XML metadata driver and looks for metadata
206
- in every bundles at ``<Bundle>/Resources/rdf-mappings ``. If you use a third
207
- party bundle that does not come with RDFa mapping, you can simply include a
208
- mapping file for it in any of your bundles, or specify a directory containing
209
- mapping files with the ``rdf_config_dirs `` option.
210
-
211
- The mapping file name needs to be the fully qualified class name of your model
212
- class, having the backslash (``\\ ``) replaced by a dot (``. ``), i.e.
213
- ``Symfony.Cmf.Bundle.ContentBundle.Doctrine.Phpcr.StaticContent.xml ``.
214
-
215
- A basic mapping look as follows:
192
+ If you have the :doc: `MediaBundle <../media/index >` present in your project as well, you
193
+ additionally need to register the route for the image upload handler:
216
194
217
195
.. configuration-block ::
218
196
219
- .. code-block :: xml
220
-
221
- <!-- Resources/rdf-mappings/Symfony.Cmf.Bundle.ContentBundle.Doctrine.Phpcr.StaticContent.xml -->
222
- <type
223
- xmlns : schema =" http://schema.org/"
224
- typeof =" schema:WebPage"
225
- >
226
- <children >
227
- <property property =" schema:headline" identifier =" title" />
228
- <property property =" schema:text" identifier =" body" />
229
- </children >
230
- </type >
231
-
232
- The most relevant parts are the ``property `` telling the RDF type, and the
233
- ``identifier `` telling the field of the class you map. If you use namespaces
234
- like schema.org, your annotations will actually make semantically sense. But
235
- you can also ignore this and use your own annotations, as long as you declare
236
- the namespaces you use.
237
-
238
- .. tip ::
239
-
240
- You need to clear the cache when adding a new mapping XML file, even in
241
- the dev environment. The CreateBundle caches where it found mapping files
242
- to avoid scanning all folders on every request. Once a file is known, edits
243
- will be picked automatically, without the need to clear the cache again.
244
-
245
- You can additionally specify the HTML tag to be used when automatically
246
- rendering this field (see below). The default tag is ``div ``. And you can
247
- specify additional HTML attributes like the ``class `` attribute. A full example
248
- reads like this:
197
+ .. code-block :: yaml
249
198
250
- .. configuration-block ::
199
+ create_image :
200
+ resource : " @CmfCreateBundle/Resources/config/routing/image.xml"
251
201
252
202
.. code-block :: xml
253
203
254
- <!-- Resources/rdf-mappings/Symfony.Cmf.Bundle.ContentBundle.Doctrine.Phpcr.StaticContent.xml -->
255
- <type
256
- xmlns : schema =" http://schema.org/"
257
- typeof =" schema:WebPage"
258
- >
259
- <children >
260
- <property property =" schema:headline" identifier =" title" tag-name =" h1" />
261
- <property property =" schema:text" identifier =" body" >
262
- <attribute key =" class" value =" my-css-class" />
263
- </property >
264
- </children >
265
- </type >
204
+ <import resource =" @CmfCreateBundle/Resources/config/routing/image.xml" />
266
205
267
- .. note ::
206
+ .. code-block :: php
268
207
269
- The metadata support in CreatePHP is not as powerful as in Doctrine. There
270
- are currently no drivers for annotation or yml mappings. Mappings are not
271
- inherited from a parent class but need to be repeated each time. And the
272
- mapping file must include the full namespace in the filename to be found.
208
+ use Symfony\Component\Routing\RouteCollection;
273
209
274
- All of these issues will hopefully be fixed in later versions if people
275
- step up and contribute pull requests.
210
+ $collection = new RouteCollection();
211
+ $collection->addCollection($loader->import("@CmfCreateBundle/Resources/config/routing/image.xml"));
276
212
277
- Mapping Requests to Objects
278
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
213
+ return $collection;
279
214
280
- In version 1.0, the CreateBundle only provides a service to map to Doctrine
281
- PHPCR-ODM. If you do not enable the phpcr persistence layer, you need to
282
- configure the ``cmf_create.object_mapper_service_id ``.
215
+ Access Control
216
+ ~~~~~~~~~~~~~~
217
+
218
+ In order to limit who can edit content, the provided controllers as well as the
219
+ javascript loader check if the current user is granted the configured
220
+ ``cmf_create.role ``. By default the role is ``ROLE_ADMIN ``.
283
221
284
222
.. tip ::
285
223
286
- Doctrine ORM support is coming soon. There is an open pull request on the
287
- CreatePHP library to add such a mapper. This mapper will also be provided
288
- as a service by the CreateBundle 1.1.
224
+ In order to have security in place, you need to configure a
225
+ "Symfony2 firewall". Read more in the `Symfony2 security chapter `_.
289
226
290
- CreatePHP would support specific mappers per RDFa type. If you need that, dig
291
- into the CreatePHP and CreateBundle and do a pull request to enable this feature.
227
+ If you need more fine grained access control, look into the CreatePHP
228
+ ``RdfMapperInterface `` ``isEditable `` method. You can extend a mapper and
229
+ overwrite ``isEditable `` to answer whether the passed domain object is
230
+ editable.
292
231
293
- .. _bundle-create-usage-embed :
232
+ Load create.js Javascript and CSS
233
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
294
234
295
- Rendering Content
296
- -----------------
235
+ This bundle provides templates that load the required Javascript and CSS files
236
+ based on Assetic. The Javascript loader also parametrizes the configuration
237
+ for create.js and the chosen editor.
297
238
298
- Rendering the content for create.js consists of adjusting how you output your
299
- model classes and of loading the necessary javascript and css files .
239
+ Alternatively, you can of course use your own templates to include the assets
240
+ needed by create.js .
300
241
301
242
In the page header, include the base CSS files (and add your own CSS files
302
- after those to be able to customize as needed) with
243
+ after those to be able to customize as needed) with:
244
+
245
+ .. configuration-block ::
303
246
304
- .. code-block :: jinja
247
+ .. code-block :: jinja
305
248
306
- {% include "CmfCreateBundle::includecssfiles.html.twig" %}
249
+ {% include "CmfCreateBundle::includecssfiles.html.twig" %}
307
250
308
- .. code-block :: php
251
+ .. code-block :: php
309
252
310
- <?php echo $view->render("CmfCreateBundle::includecssfiles.html.twig"); ?>
253
+ <?php echo $view->render("CmfCreateBundle::includecssfiles.html.twig"); ?>
311
254
312
255
.. caution ::
313
256
@@ -357,16 +300,27 @@ For Symfony 2.1, the syntax is:
357
300
configuration further, you will need to use a
358
301
:ref: `custom template to load the editor<bundle-create-custom> `.
359
302
360
- If you provided RDFa mappings for your model classes as explained above, you
361
- can now adjust your templates to render the RDFa annotations so that create.js
362
- knows what content is editable.
363
303
364
- To render your model named ``page `` with a handle you call ``rdf ``, use the
304
+ .. _bundle-create-usage-embed :
305
+
306
+ Rendering Content
307
+ -----------------
308
+
309
+ Create.js needs to identify what is editable in your content. To do this,
310
+ it needs the RDF attributes in the HTML. Now that everything is prepared,
311
+ you need to adjust your templates to output that information.
312
+
313
+ .. note ::
314
+
315
+ If you use custom models that did not come with RDFa mapping files, see
316
+ the remainder of this page to learn how to define the mappings.
317
+
318
+ To render your model named ``cmfMainContent `` with a handle you call ``rdf ``, use the
365
319
``createphp `` twig tag as follows:
366
320
367
321
.. code-block :: html+jinja
368
322
369
- {% createphp page as="rdf" noautotag %}
323
+ {% createphp cmfMainContent as="rdf" noautotag %}
370
324
<div {{ createphp_attributes(rdf) }}>
371
325
<h1 class="my-title" {{ createphp_attributes( rdf.title ) }}>{{ createphp_content( rdf.title ) }}</h1>
372
326
<div {{ createphp_attributes( rdf.body ) }}>{{ createphp_content( rdf.body ) }}</div>
@@ -386,7 +340,7 @@ automatically:
386
340
387
341
.. code-block :: html+jinja
388
342
389
- {% createphp page as="rdf" %}
343
+ {% createphp cmfMainContent as="rdf" %}
390
344
{{ rdf|raw }}
391
345
{% endcreatephp %}
392
346
@@ -396,10 +350,106 @@ replace the default ``<div>`` tag with your own choice. And using an
396
350
``<attribute> `` child to specify CSS classes, you can let CreatePHP generate
397
351
your HTML structure if you want.
398
352
353
+ Metadata
354
+ --------
355
+
356
+ CreatePHP needs metadata information for each class of your domain model. By
357
+ default, the create bundle uses the XML metadata driver and looks for metadata
358
+ in every bundles at ``<Bundle>/Resources/rdf-mappings ``. If you use a third
359
+ party bundle that does not come with RDFa mapping, you can simply include a
360
+ mapping file for it in any of your bundles, or specify a directory containing
361
+ mapping files with the ``rdf_config_dirs `` option.
362
+
363
+ The mapping file name needs to be the fully qualified class name of your model
364
+ class, having the backslash (``\\ ``) replaced by a dot (``. ``), i.e.
365
+ ``Symfony.Cmf.Bundle.ContentBundle.Doctrine.Phpcr.StaticContent.xml ``.
366
+
367
+ A basic mapping look as follows:
368
+
369
+ .. configuration-block ::
370
+
371
+ .. code-block :: xml
372
+
373
+ <!-- Resources/rdf-mappings/Symfony.Cmf.Bundle.ContentBundle.Doctrine.Phpcr.StaticContent.xml -->
374
+ <type
375
+ xmlns : schema =" http://schema.org/"
376
+ typeof =" schema:WebPage"
377
+ >
378
+ <children >
379
+ <property property =" schema:headline" identifier =" title" />
380
+ <property property =" schema:text" identifier =" body" />
381
+ </children >
382
+ </type >
383
+
384
+ The most relevant parts are the ``property `` telling the RDF type, and the
385
+ ``identifier `` telling the field of the class you map. If you use namespaces
386
+ like schema.org, your annotations will actually make semantically sense. But
387
+ you can also ignore this and use your own annotations, as long as you declare
388
+ the namespaces you use.
389
+
390
+ .. tip ::
391
+
392
+ You need to clear the cache when adding a new mapping XML file, even in
393
+ the dev environment. The CreateBundle caches where it found mapping files
394
+ to avoid scanning all folders on every request. Once a file is known, edits
395
+ will be picked automatically, without the need to clear the cache again.
396
+
397
+ You can additionally specify the HTML tag to be used when automatically
398
+ rendering this field (see below). The default tag is ``div ``. And you can
399
+ specify additional HTML attributes like the ``class `` attribute. A full example
400
+ reads like this:
401
+
402
+ .. configuration-block ::
403
+
404
+ .. code-block :: xml
405
+
406
+ <!-- Resources/rdf-mappings/Symfony.Cmf.Bundle.ContentBundle.Doctrine.Phpcr.StaticContent.xml -->
407
+ <type
408
+ xmlns : schema =" http://schema.org/"
409
+ typeof =" schema:WebPage"
410
+ >
411
+ <children >
412
+ <property property =" schema:headline" identifier =" title" tag-name =" h1" />
413
+ <property property =" schema:text" identifier =" body" >
414
+ <attribute key =" class" value =" my-css-class" />
415
+ </property >
416
+ </children >
417
+ </type >
418
+
419
+ .. note ::
420
+
421
+ The metadata support in CreatePHP is not as powerful as in Doctrine. There
422
+ are currently no drivers for annotation or yml mappings. Mappings are not
423
+ inherited from a parent class but need to be repeated each time. And the
424
+ mapping file must include the full namespace in the filename to be found.
425
+
426
+ All of these issues will hopefully be fixed in later versions if people
427
+ step up and contribute pull requests.
428
+
429
+ Mapping Requests to Domain Model
430
+ --------------------------------
431
+
432
+ One last piece is the mapping between CreatePHP data and the application
433
+ domain model. Data needs to be stored back into the database.
434
+
435
+ In version 1.0, the CreateBundle only provides a service to map to Doctrine
436
+ PHPCR-ODM. If you do not enable the phpcr persistence layer, you need to
437
+ configure the ``cmf_create.object_mapper_service_id ``.
438
+
439
+ .. tip ::
440
+
441
+ Doctrine ORM support is coming soon. There is an open pull request on the
442
+ CreatePHP library to add such a mapper. This mapper will also be provided
443
+ as a service by the CreateBundle 1.1.
444
+
445
+ CreatePHP would support specific mappers per RDFa type. If you need that, dig
446
+ into the CreatePHP and CreateBundle and do a pull request to enable this feature.
447
+
399
448
400
449
.. _`create.js` : http://createjs.org
401
450
.. _`hallo.js` : http://hallojs.org
402
451
.. _`CreatePHP` : https://github.com/flack/createphp
403
452
.. _`with composer` : http://getcomposer.org
404
453
.. _`symfony-cmf/create-bundle` : https://packagist.org/packages/symfony-cmf/create-bundle
405
454
.. _`RDFa` : http://en.wikipedia.org/wiki/RDFa
455
+ .. _`Symfony2 security chapter` : http://symfony.com/doc/current/book/security.html
0 commit comments