Skip to content

Commit

Permalink
Add support markup mode and implemets "cms_object_url" function.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilov committed Feb 3, 2017
1 parent 862bf3c commit 2c02e7d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/Extension/CmsTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class CmsTwigExtension extends \Twig_Extension
*/
private $editable;

/**
* @var bool
*/
private $markupMode;

/**
* @var
*/
private $apiBaseUrl;

/**
* TwigExtension constructor.
*
Expand All @@ -63,15 +73,18 @@ class CmsTwigExtension extends \Twig_Extension
* @param CompositeObjectService $compositeObjectService
* @param string $cmsBaseUrl
* @param bool $editable
* @param bool $markupMode
*/
public function __construct(Session $session, CmsRestClient $cmsRestClient, ContentBlockService $contentBlockService, CompositeObjectService $compositeObjectService, $cmsBaseUrl, $editable = false)
public function __construct(Session $session, CmsRestClient $cmsRestClient, ContentBlockService $contentBlockService, CompositeObjectService $compositeObjectService, $cmsBaseUrl, $apiBaseUrl, $editable = false, $markupMode = false)
{
$this->session = $session;
$this->cmsRestClient = $cmsRestClient;
$this->contentBlockService = $contentBlockService;
$this->compositeObjectService = $compositeObjectService;
$this->cmsBaseUrl = $cmsBaseUrl;
$this->apiBaseUrl = $apiBaseUrl;
$this->editable = $editable;
$this->markupMode = $markupMode;
}

/**
Expand All @@ -86,6 +99,7 @@ public function getFunctions()
new \Twig_SimpleFunction('editable_object', [$this, 'editableObject'], ['is_safe' => ['html']]),
new \Twig_SimpleFunction('objects', [$this, 'getObjects']),
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 @@ -174,7 +188,7 @@ public function isEditable()
$this->editable &&
$session->has('api_token') &&
$cmsRestClient->validateToken($session->get('api_token'))
;
;
}

/**
Expand Down Expand Up @@ -207,9 +221,24 @@ public function spaceless($value)
*/
public function cmsAsset($resource)
{
if ($this->markupMode) {
return '/' . $resource;
}

return $this->cmsBaseUrl . '/' . $resource;
}

/**
* CMS object URL
*
* @param string $className
* @return string
*/
public function cmsObjectUrl($className)
{
return $this->apiBaseUrl . '/composite-object/objects?className=' . $className;
}

/**
* @param array $list
* @param array $filters
Expand Down

0 comments on commit 2c02e7d

Please sign in to comment.