From 1157a69bbfab934da3673b6b462e00ec9c70f7a0 Mon Sep 17 00:00:00 2001 From: nilov Date: Mon, 6 Feb 2017 12:00:58 +0700 Subject: [PATCH] Add the "option" function. --- src/Extension/CmsTwigExtension.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Extension/CmsTwigExtension.php b/src/Extension/CmsTwigExtension.php index 6b46930..e4d6462 100644 --- a/src/Extension/CmsTwigExtension.php +++ b/src/Extension/CmsTwigExtension.php @@ -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; @@ -39,6 +41,11 @@ class CmsTwigExtension extends \Twig_Extension */ private $contentBlockService; + /** + * @var OptionService + */ + private $optionService; + /** * @var CompositeObjectService */ @@ -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; @@ -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']), @@ -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 */