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

Commit 3f4c277

Browse files
committed
clarify the workings of the SeoBundle
1 parent 10447ec commit 3f4c277

File tree

2 files changed

+66
-32
lines changed

2 files changed

+66
-32
lines changed

bundles/seo/configuration.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ content_key
100100

101101
**type**: ``string`` **default**: ``null`` (or ``DynamicRouter::CONTENT_KEY`` when RoutingBundle is enabled)
102102

103-
The name of the Request attribute which contains the content object. This is
104-
required when the RoutingBundle is not enabled, otherwise it defaults to
105-
``DynamicRouter::CONTENT_KEY`` (which evaluates to ``contentDocument``).
103+
The name of the request attribute which contains the content object. This is
104+
used by the ContentListener to exctract SEO information automatically. If the
105+
RoutingBundle is present, this defaults to ``DynamicRouter::CONTENT_KEY``
106+
(which evaluates to ``contentDocument``), otherwise you must define this
107+
manually.
106108

107109
sonata_admin_extension
108110
~~~~~~~~~~~~~~~~~~~~~~

bundles/seo/introduction.rst

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ Both the CmfSeoBundle and SonataSeoBundle must be registered in the
3232
Usage
3333
~~~~~
3434

35+
SEO data tracks some or all of the following:
36+
37+
* The title;
38+
* The meta keywords;
39+
* The meta description;
40+
* The original URL (when more than one URL contains the same content).
41+
* Anything else that uses the ``<meta>`` tag with the ``property``, ``name``
42+
or ``http-equiv`` type (e.g. Open Graph data).
43+
3544
The simplest use of this bundle would be to just set some configuration to the
3645
``sonata_seo`` configuration section and use the twig helper in your templates.
3746

@@ -62,8 +71,12 @@ The simplest use of this bundle would be to just set some configuration to the
6271
),
6372
),
6473
));
65-
66-
The only thing to do now is to use the twig helper in your templates:
74+
75+
This sets default values for the ``SeoPage`` value object. You can later update
76+
that object with more precise information. It is available as service
77+
``sonata.seo.page.default``.
78+
79+
To render the information, use the following twig functions in your templates:
6780

6881
.. code-block:: html+jinja
6982

@@ -80,54 +93,73 @@ The only thing to do now is to use the twig helper in your templates:
8093
</body>
8194
</html>
8295

83-
This will render a page with the default title ("Page's default title") as
84-
title element. The information defined for description and keywords will go
85-
into the correct metatags.
96+
This will render the last title set on the ``SeoPage`` ("Page's default title"
97+
if you did not add calls to the value object in your code). The information
98+
added for description and keywords will render as ``<meta>`` HTML tags.
8699

87100
.. seealso::
88101

89102
To get a deeper look into the SonataSeoBundle, you should visit the
90103
`Sonata documentation`_.
91104

92-
Using SeoMetadata
93-
-----------------
105+
Using the CmfSeoBundle
106+
----------------------
94107

95108
The basic example shown above works perfectly without the CmfSeoBundle. The
96-
CmfSeoBundle provides more extension points to configure the SEO data with
97-
data from the document (e.g. a ``StaticContent`` document). This is done by
98-
using SEO metadata. This is SEO data which will be used for a particular
99-
document. This metadata can hold:
109+
CmfSeoBundle provides extension points to extract the SEO data from
110+
content documents, e.g. a ``StaticContent``, along with utility systems
111+
to automatically extract the information.
100112

101-
* The title;
102-
* The meta keywords;
103-
* The meta description;
104-
* The original URL (when more than one URL contains the same content).
105-
* Anything else that uses the ``<meta>`` tag with the ``property``, ``name``
106-
or ``http-equiv`` type (e.g. Open Graph data).
113+
The process is:
114+
115+
1. The content listener checks for a document in the request
116+
2. It invokes ``SeoPresentationInterface::updateSeoPage``
117+
3. The presentation checks of the document provides a ``SeoMetadata`` value
118+
object and runs the metadata extractors.
119+
4. The presentation updates the Sonata ``SeoPage`` with the gathered meta data.
120+
121+
.. _bundles-seo-content-listener:
107122

108-
The content object is retrieved from the request attributes. By default, it
109-
uses the ``DynamicRouter::CONTENT_KEY`` constant when the
110-
:doc:`RoutingBundle <../routing/introduction>` is installed. To change this,
111-
or if you don't use the RoutingBundle, you can configure it with
123+
The ContentListener
124+
~~~~~~~~~~~~~~~~~~~
125+
126+
The ``Symfony\Cmf\Bundle\SeoBundle\EventListener\ContentListener`` looks for a
127+
content document in the request attributes. If it finds a document, it calls
128+
``SeoPresentationInterface::updateSeoPage``.
129+
130+
If the :doc:`RoutingBundle <../routing/introduction>` is installed, the default
131+
attribute name is defined by the constant ``DynamicRouter::CONTENT_KEY``. When
132+
not using the RoutingBundle, you need to configure a key in
112133
``cmf_seo.content_key``.
113-
This bundle provides two ways of using this metadata:
134+
135+
Extracting Metadata
136+
~~~~~~~~~~~~~~~~~~~
137+
138+
A service implementing ``SeoPresentationInterface`` is responsible for
139+
determining metadata from an object and updating the Sonata ``SeoPage`` with that
140+
information. A default implementation is provided as ``cmf_seo.presentation``.
141+
142+
Defining Metadata
143+
~~~~~~~~~~~~~~~~~
144+
145+
This bundle provides two ways to define metadata on objects:
114146

115147
#. Implementing the ``SeoAwareInterface`` and persisting the ``SeoMetadata``
116148
with the object.
117-
#. Using the extractors, to extract the ``SeoMetadata`` from already existing
118-
values (e.g. the title of the page).
149+
#. Using ``ExtractorInterface`` instances, to extract the ``SeoMetadata`` from
150+
already existing values (e.g. the title of the page).
119151

120152
You can also combine both ways, even on the same document. In that case, the
121153
persisted ``SeoMetadata`` can be changed by the extractors, to add or tweak
122154
the current available SEO information. For instance, if you are writing a
123155
``BlogPost`` class, you want the SEO keywords to be set to the tags/category
124-
of the post and any additional tags set by the admin.
156+
of the post and any additional tags set by the editor.
125157

126-
Persisting the ``SeoMetadata`` with the document makes it easy to edit for the
127-
admin, while using the extractors are perfect to easily use values from the
128-
displayed content.
158+
Persisting the ``SeoMetadata`` with the document makes it easy to override SEO
159+
information for the editor, while using the extractors adds the convenience
160+
that values from the normal content of the document can be reused.
129161

130-
Both ways are documented in detail in separate sections:
162+
Both methods are documented in detail in separate sections:
131163

132164
* :doc:`seo_aware`
133165
* :doc:`extractors`

0 commit comments

Comments
 (0)