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

Add twig extension to update seo page #263

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Changelog
=========

* **2015-09-30**: Add `cmf_seo_update_metadata` twig function for updating seo metadata from templates using
* **2015-09-08**: Add meta tag for language information
* **2015-08-20**: Added templates configuration and `exclusion_rules` (based on the request matcher) to
the error handling configuration
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<parameter key="cmf_seo.cache.file.class">Symfony\Cmf\Bundle\SeoBundle\Cache\FileCache</parameter>
<parameter key="cmf_seo.presentation.class">Symfony\Cmf\Bundle\SeoBundle\SeoPresentation</parameter>
<parameter key="cmf_seo.error.suggestion_provider.controller.class">Symfony\Cmf\Bundle\SeoBundle\Controller\SuggestionProviderController</parameter>
<parameter key="cmf_seo.twig.extension.class">Symfony\Cmf\Bundle\SeoBundle\Twig\Extension\CmfSeoExtension</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -58,6 +59,11 @@
/>

<service id="cmf_seo.error.exclusion_matcher" class="Symfony\Cmf\Bundle\SeoBundle\Matcher\ExclusionMatcher" />

<service id="cmf_seo.twig.extension" class="%cmf_seo.twig.extension.class%" public="false">
<tag name="twig.extension" />
<argument type="service" id="cmf_seo.presentation" />
</service>
</services>

</container>
57 changes: 57 additions & 0 deletions Twig/Extension/CmfSeoExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2015 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Ben Glassman <[email protected]>
*/

namespace Symfony\Cmf\Bundle\SeoBundle\Twig\Extension;

use Symfony\Cmf\Bundle\SeoBundle\SeoPresentationInterface;

class CmfSeoExtension extends \Twig_Extension
{
/**
* @var SeoPresentationInterface
*/
protected $seoPresentation;

/**
* @param SeoPresentationInterface $seoPresentation
*/
public function __construct(SeoPresentationInterface $seoPresentation)
{
$this->seoPresentation = $seoPresentation;
}

/**
* @{inheritdoc}
*/
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('cmf_seo_update_metadata',
array($this, 'updateMetadata')
),
);
}

/**
* @see SeoPresentationInterface
*/
public function updateMetadata($content)
{
$this->seoPresentation->updateSeoPage($content);
}

public function getName()
{
return 'cmf_seo';
}
}