RSS
Intro
The WfCmsRssBundle uses the Zend Feed Writer component to generate the RSS feeds. The output of the RSS can be tweaked by adding and using extensions.
Custom extensions
The WfCms automatically registers extensions for Zend Feed Writer based on parameters:
wf_rss.extension.__EXTENSION_NAME__.feed
- the class for feedwf_rss.extension.__EXTENSION_NAME__.entry
- the entry class for feed itemswf_rss.extension.__EXTENSION_NAME__.renderer_feed
- the renderer class for the feedwf_rss.extension.__EXTENSION_NAME__.renderer_entry
- the renderer class for each items
Default extension
WfCms automatically enables the extension with the name of the project. For example, if the wf_cms.bundle.public
parameter is XxxCmsBundle
, adding the parameter wf_rss.extension.xxx.renderer_entry
automatically registers that class as a renderer for the feed's entries.
If an extension should be enabled only in some cases:
Add the parameters for the extension:
wf_rss.extension.example.renderer_entry: XXX\Bundle\CmsBundle\...\ExampleRendererEntry
Overwrite the
wf_rss.extension_manager.class
with a custom classCheck if the extension should be enabled:
phpclass ExtensionManager extends Wf\Bundle\CmsRssBundle\ExtensionManager { public function registerExtensions(Symfony\Component\HttpFoundation\Request $request) { if ($request->get('example', false)) { //register the `example` extension only if `example` parameter is true in the request $this->registerExtension('example'); } } }
Implement the
ExampleRendererEntry
class:phpclass ExampleRendererEntry extends Wf\Bundle\CmsRssBundle\Feed\WfCmsFeedExtension\Renderer\BaseEntry { public function render() { $this->addTextNode('example_node', 'value'); } }
Accessing article data
In the entry renderer class, access the underlying data container (the Entry object) with $this->getDataContainer()
.
All the get
methods that don't exist in the Entry
class are forwarded to the corresponding PageArticle
object. So, if you define a method PageArticle:getSmiles
, in the entry renderer you could just:
$this->addText('smiles', $this->getDataContainer()->getSmiles());
Helper methods for entry renderer
The BaseEntry class from WfCmsRssBundle exposes some methods to ease dealing with the RSS:
$this->addText('text_node', 'text_value', array('attribute' => 'attributeValue'));
$nodes = array();
for ($i = 0; $i < 10; $i++) {
$nodes[] = $this->getTextNode('node_' . $i, 'value_' . $i);
}
$this->addArrayNode('array_node',$nodes, array('attribute' => 'attributeValue'));
$this->generateArticleUrl($this->getDataContainer()); //generate the absolute url to this entry's article