Skip to content

Commit

Permalink
Add the "option" function.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilov committed Feb 6, 2017
1 parent 2c02e7d commit 1157a69
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Extension/CmsTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Glavweb\CmsTwigExtension\Extension;

use Glavweb\CmsContentBlock\Service\OptionService;
use Glavweb\CmsContentBlock\Service\OptionServiceService;
use Symfony\Component\HttpFoundation\Session\Session;
use Glavweb\CmsRestClient\CmsRestClient;
use Glavweb\CmsContentBlock\Service\ContentBlockService;
Expand Down Expand Up @@ -39,6 +41,11 @@ class CmsTwigExtension extends \Twig_Extension
*/
private $contentBlockService;

/**
* @var OptionService
*/
private $optionService;

/**
* @var CompositeObjectService
*/
Expand Down Expand Up @@ -70,16 +77,18 @@ class CmsTwigExtension extends \Twig_Extension
* @param Session $session
* @param CmsRestClient $cmsRestClient
* @param ContentBlockService $contentBlockService
* @param OptionService $optionService
* @param CompositeObjectService $compositeObjectService
* @param string $cmsBaseUrl
* @param bool $editable
* @param bool $markupMode
*/
public function __construct(Session $session, CmsRestClient $cmsRestClient, ContentBlockService $contentBlockService, CompositeObjectService $compositeObjectService, $cmsBaseUrl, $apiBaseUrl, $editable = false, $markupMode = false)
public function __construct(Session $session, CmsRestClient $cmsRestClient, ContentBlockService $contentBlockService, OptionService $optionService, CompositeObjectService $compositeObjectService, $cmsBaseUrl, $apiBaseUrl, $editable = false, $markupMode = false)
{
$this->session = $session;
$this->cmsRestClient = $cmsRestClient;
$this->contentBlockService = $contentBlockService;
$this->optionService = $optionService;
$this->compositeObjectService = $compositeObjectService;
$this->cmsBaseUrl = $cmsBaseUrl;
$this->apiBaseUrl = $apiBaseUrl;
Expand All @@ -98,6 +107,7 @@ public function getFunctions()
new \Twig_SimpleFunction('editable', [$this, 'editable'], ['is_safe' => ['html']]),
new \Twig_SimpleFunction('editable_object', [$this, 'editableObject'], ['is_safe' => ['html']]),
new \Twig_SimpleFunction('objects', [$this, 'getObjects']),
new \Twig_SimpleFunction('option', [$this, 'option']),
new \Twig_SimpleFunction('cms_asset', [$this, 'cmsAsset']),
new \Twig_SimpleFunction('cms_object_url', [$this, 'cmsObjectUrl']),
new \Twig_SimpleFunction('spaceless', [$this, 'spaceless']),
Expand Down Expand Up @@ -176,6 +186,21 @@ public function editableObject($id)
return '';
}

/**
* Get option
*
* @param string $category
* @param string $optionName
* @param string $default
* @return string
*/
public function option($category, $optionName, $default = null)
{
$optionService = $this->optionService;

return $optionService->getOption($category, $optionName, $default);
}

/**
* @return bool
*/
Expand Down

0 comments on commit 1157a69

Please sign in to comment.