Skip to content

Commit

Permalink
Add new functions captcha_image_src and api_url.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilov committed May 4, 2017
1 parent 4e14432 commit 9bc3e29
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/Extension/CmsTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public function getFunctions(): array
new \Twig_SimpleFunction('option', [$this, 'option']),
new \Twig_SimpleFunction('cms_asset', [$this, 'cmsAsset']),
new \Twig_SimpleFunction('cms_object_url', [$this, 'cmsObjectUrl']),
new \Twig_SimpleFunction('api_url', [$this, 'apiUrl']),
new \Twig_SimpleFunction('captcha_image_src', [$this, 'captchaImageSrc']),
new \Twig_SimpleFunction('spaceless', [$this, 'spaceless']),
];
}
Expand Down Expand Up @@ -238,7 +240,7 @@ public function isEditable(): bool
$this->editable &&
$session->has('api_token') &&
$cmsRestClient->validateToken($session->get('api_token'))
;
;
}

/**
Expand Down Expand Up @@ -304,7 +306,40 @@ public function cmsAsset(string $resource): string
*/
public function cmsObjectUrl(string $className): string
{
return $this->apiBaseUrl . '/composite-object/objects?className=' . $className;
return $this->apiBaseUrl . '/composite-objects/' . $className;
}

/**
* Get API URL
*
* @param string $url
* @return string
*/
public function apiUrl(string $url): string
{
return $this->apiBaseUrl . '/' . $url;
}

/**
* Get URL to Captcha image
*
* @param string $className
* @param string $token
* @param array $options
* @return string
*/
public function captchaImageSrc(string $className, string $token, array $options = []): string
{
$queryParts = [];
foreach ($options as $name => $value) {
$queryParts[] = $name . '=' . $value;
}

$queryString = implode('&', $queryParts);

return $this->apiBaseUrl . '/composite-object-captcha/' . $className . '/' . $token
. ($queryString ? '?' . $queryString : '')
;
}

/**
Expand Down

0 comments on commit 9bc3e29

Please sign in to comment.