public function TemplateController::listJson in Wysiwyg API template plugin 8.2
Same name and namespace in other branches
- 3.0.x src/Controller/TemplateController.php \Drupal\wysiwyg_template\Controller\TemplateController::listJson()
A list of available templates based on the content type.
Parameters
\Drupal\node\NodeTypeInterface $node_type: (optional) The content type. If set, only templates available for this node type will be returned.
Return value
\Symfony\Component\HttpFoundation\Response The template callback JS.
See also
https://www.drupal.org/node/2693221
1 string reference to 'TemplateController::listJson'
File
- src/
Controller/ TemplateController.php, line 28
Class
- TemplateController
- Default controller for the wysiwyg_template module.
Namespace
Drupal\wysiwyg_template\ControllerCode
public function listJson(NodeTypeInterface $node_type = NULL) : Response {
$templates = [
// @todo Support images.
'imagesPath' => FALSE,
];
foreach (Template::loadByNodeType($node_type) as $template) {
$json_template = new stdClass();
$json_template->title = $template
->label();
// @todo Images.
// @see https://www.drupal.org/node/2692469
$json_template->description = $template
->getDescription();
$json_template->html = $template
->getBody();
$templates['templates'][] = $json_template;
}
$templates = json_encode($templates);
$script = <<<EOL
CKEDITOR.addTemplates( 'default', {<span class="php-variable">$templates</span>});
EOL;
$response = new Response($script);
$response->headers
->set('Content-Type', 'text/javascript');
return $response;
}