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

[content-bundle] change doc to best practices #795

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bundles/content/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ is the following configuration:

.. code-block:: php

$container->loadFromExtension('cmf_content', array(
'persistence' => array(
'phpcr' => array(
$container->loadFromExtension('cmf_content', [
'persistence' => [
'phpcr' => [
'enabled' => false,
'admin_class' => null,
'document_class' => null,
'content_basepath' => '/cms/content',
'use_sonata_admin' => 'auto',
));
],
],
]);

``enabled``
...........
Expand Down
44 changes: 23 additions & 21 deletions bundles/content/exposing_content_via_rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Here is an example configuration for the FOSRestBundle.

.. code-block:: yaml

# app/config/config.yml
fos_rest:
# configure the view handler
view:
Expand All @@ -72,6 +73,7 @@ Here is an example configuration for the FOSRestBundle.
.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
<!-- app/config/config.xml -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be before the doctype thing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, ok. if that is the convention, i can change. but that would mean its not valid xml anymore. the doctype must be the very first thing in an xml file afaik.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's correct. However, one is not supposed to copy the file comment (e.g. no PHP file is valid as well, as there is no <?php).

<container xmlns="http://symfony.com/schema/dic/services">

<config xmlns="http://example.org/schema/dic/fos_rest">
Expand All @@ -98,48 +100,48 @@ Here is an example configuration for the FOSRestBundle.

.. code-block:: php

$container->loadFromExtension('fos_rest', array(
// app/config/config.php
$container->loadFromExtension('fos_rest', [
// configure the view handler
'view' => array(
'force_redirects' => array(
'view' => [
'force_redirects' => [
'html' => true,
),
'formats' => array(
],
'formats' => [
'json' => true,
'xml' => true,
),
'templating_formats' => array(
],
'templating_formats' => [
'html' => true,
),
),
],
],
// add a content negotiation rule, enabling support for json/xml for the entire website
'format_listener' => array(
'rules' => array(
array(
'format_listener' => [
'rules' => [
[
'path' => '^/',
'priorities' => array('html', 'json', 'xml'),
'priorities' => ['html', 'json', 'xml'],
'fallback_format' => 'html',
'prefer_extension' => false,
),
),
),
));
],
],
],
]);

Using the REST API
------------------

After you configured the FOSRestBundle, you need to execute the following
commands:
This is all it takes to enable read support via JSON or XML!
Test if the setup works as expected with curl:

.. code-block:: bash

curl http://my-cmf.org/app_dev.php -H Accept:application/json
curl http://my-cmf.org/app_dev.php -H Accept:application/xml
curl http://my-cmf.org/app_dev.php -H Accept:text/html

This is all it takes to enable read support via JSON or XML!

The JMS serializer comes with sense defaults for Doctrine object mappers.
The JMS serializer comes with sensible defaults for Doctrine object mappers.
However it might be necessary to add additional mapping to more tightly
control what gets exposed. See the `documentation of the JMS serializer`_
for details.
Expand Down
22 changes: 11 additions & 11 deletions bundles/content/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ To configure a default template, use the ``default_template`` option:
// app/config/config.yml

// ...
$container->loadFromExtension('cmf_content', array(
$container->loadFromExtension('cmf_content', [
'default_template' => 'AppBundle:Content:static.html.twig',
));
]);

Whenever the content controller gets called without a specified template, it
will now use this template.
Expand Down Expand Up @@ -187,16 +187,16 @@ Lets assume that you want to handle ``StaticContent`` with the default

.. code-block:: php

// app/config/config.yml

// app/config/config.php
use Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContent;
// ...
$container->loadFromExtension('cmf_routing', array(
'dynamic' => array(
'controller_by_class' => array(
'Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContent' => 'cmf_content.controller:indexAction',
),
),
));
$container->loadFromExtension('cmf_routing', [
'dynamic' => [
'controller_by_class' => [
StaticContent::class => 'cmf_content.controller:indexAction',
],
],
]);

Now everything is configured correctly, navigating to ``/hello`` results in a
page displaying your content.
Expand Down