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

Commit 37f5a69

Browse files
committed
Merge pull request #442 from symfony-cmf/ElectricMaxxx-seo-bundle-documentation
[WIP] Documenting the SeoBundle
2 parents e6cfd5c + 2e0c0cd commit 37f5a69

File tree

10 files changed

+887
-12
lines changed

10 files changed

+887
-12
lines changed

bundles/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Bundles
1515
routing_auto/index
1616
routing/index
1717
search/index
18+
seo/index
1819
simple_cms/index
1920
tree_browser/index
2021

bundles/map.rst.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ library or they introduce a complete new concept.
5959

6060
* :doc:`search/introduction`
6161

62+
* :doc:`seo/index`
63+
64+
* :doc:`seo/introduction`
65+
* :doc:`seo/seo_aware`
66+
* :doc:`seo/extractors`
67+
6268
* :doc:`tree_browser/index`
6369

6470
* :doc:`tree_browser/introduction`

bundles/seo/extractors.rst

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
Using Extractors to Retrieve the Seo Metadata
2+
=============================================
3+
4+
Instead of setting every value to the ``SeoMetadata`` manually, an extractor
5+
can do the work for you. Extractors are executed when the content object
6+
implements a specific interface. The method required by that interface will
7+
return the value for the specific SEO data. The extractor will then update the
8+
``SeoMetadata`` object for the current object with the returned value.
9+
10+
Available Extractors
11+
--------------------
12+
13+
+--------------------------------+---------------------------+----------------------------------------------+
14+
| ExtractorInterface | Method | Type |
15+
+================================+===========================+==============================================+
16+
| ``DescriptionReadInterface`` | ``getSeoDescription()`` | Returns the meta description |
17+
+--------------------------------+---------------------------+----------------------------------------------+
18+
| ``TitleReadInterface`` | ``getSeoTitle()`` | Returns the page title |
19+
+--------------------------------+---------------------------+----------------------------------------------+
20+
| - | ``getTitle()`` | If the document has a ``getTitle()`` method, |
21+
| | | it'll be used as the page title |
22+
+--------------------------------+---------------------------+----------------------------------------------+
23+
| ``OriginalUrlReadInterface`` | ``getSeoOriginalUrl()`` | Returns a absolute url object to redirect to |
24+
| | | or create a canonical link from |
25+
+--------------------------------+---------------------------+----------------------------------------------+
26+
| ``OriginalRouteReadInterface`` | ``getSeoOriginalRoute()`` | Return a ``Route`` object to redirect to |
27+
| | | or create a canonical link from |
28+
+--------------------------------+---------------------------+----------------------------------------------+
29+
| ``ExtrasReadInterface`` | ``getSeoExtras()`` | Returns an associative array using |
30+
| | | ``property``, ``http-equiv`` and ``name`` |
31+
| | | as keys (see below from an example). |
32+
+--------------------------------+---------------------------+----------------------------------------------+
33+
34+
.. note::
35+
36+
The interfaces life in the ``Symfony\Cmf\Bundle\SeoBundle\Extractor``
37+
namespace.
38+
39+
An Example
40+
----------
41+
42+
Assume you have an ``Article`` object and you want to use both the ``$title``
43+
and ``$date`` properties as page title and the ``$intro`` property as
44+
description, you can implement both interfaces and your result will be::
45+
46+
// src/Acme/BlogBundle/Document/Article.php
47+
namespace Acme\BlogBundle\Document;
48+
49+
use Symfony\Cmf\Bundle\SeoBundle\Extractor\TitleReadInterface;
50+
use Symfony\Cmf\Bundle\SeoBundle\Extractor\DescriptionReadInterface;
51+
use Symfony\Cmf\Bundle\SeoBundle\Extractor\ExtrasReadInterface;
52+
53+
class Article implements TitleReadInterface, DescriptionReadInterface, ExtraReadInterface
54+
{
55+
protected $title;
56+
protected $publishDate;
57+
protected $intro;
58+
59+
// ...
60+
public function getSeoTitle()
61+
{
62+
return $this->title.' ~ '.date($this->publishDate, 'm-Y');
63+
}
64+
65+
public function getSeoDescription()
66+
{
67+
return $this->intro;
68+
}
69+
70+
public function getSeoExtras()
71+
{
72+
return array(
73+
'property' => array(
74+
'og:title' => $this->title,
75+
'og:description' => $this->description,
76+
),
77+
);
78+
}
79+
}
80+
81+
Creating Your Own Extractor
82+
---------------------------
83+
84+
To customize the extraction process, you can create your own extractor. Just
85+
create a class which implements the ``SeoExtractorInterface`` and tag it with
86+
``cmf_seo.extractor``:
87+
88+
.. configuration-block::
89+
90+
.. code-block:: yaml
91+
92+
parameters:
93+
acme_demo.extractor.custom.class: Acme\DemoBundle\Extractor\MyCustomExtractor
94+
95+
services:
96+
acme_demo.extractor.custom:
97+
class: "%acme_demo.extractor.custom.class%"
98+
tags:
99+
- { name: cmf_seo.extractor }
100+
101+
.. code-block:: xml
102+
103+
<?xml version="1.0" ?>
104+
<container xmlns="http://symfony.com/schema/dic/services"
105+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
106+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
107+
<parameters>
108+
<parameter key="acme_demo.extractor.custom.class">Acme\DemoBundle\Extractor\MyCustomExtractor</parameter>
109+
</parameters>
110+
111+
<services>
112+
<service id="acme_demo.extractor.custom" class="%acme_demo.extractor.custom.class%">
113+
<tag name="cmf_seo.extractor"/>
114+
</service>
115+
</services>
116+
</container>
117+
118+
.. code-block:: php
119+
120+
$container->addParameter(
121+
'acme_demo.extractor.custom.class',
122+
'Acme\DemoBundle\Extractor\MyCustomExtractor'
123+
);
124+
125+
$container->register('acme_demo.extractor.custom', '%acme_demo.extractor.custom.class%')
126+
->addTag('cmf_seo.extractor')
127+
;

bundles/seo/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SeoBundle
2+
=========
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
introduction
8+
seo_aware
9+
extractors

0 commit comments

Comments
 (0)