Source of file CodeBlockController.php
Size: 1,450 Bytes - Last Modified: 2018-07-24T11:27:20+00:00
/var/www/docs.ssmods.com/process/src/code/controllers/CodeBlockController.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 | <?php /** * Controller to respond to the javascript api call to populate the dropdown options * within the tinymce component that inserts codeblock shortcodes * * @author Michael Parkhill <mike@silverstripe.com> */ class CodeBlockController extends Controller { /** * @var array $allowed_actions whitelisting of public methods available in this Controller */ private static $allowed_actions = array( 'json' ); /** * Initialises the controller and ensures that only * ADMIN level users can access this controller */ public function init() { parent::init(); if (!Permission::check('ADMIN')) { return $this->httpError(403); } } /** * Returns a json encoded array of CodeBlock dataobjects in the format: (ID, Name) * Note: only objects with AdvertType of 'Embed Javascript' and Status of 'Active' are returned * * @param SS_HTTPRequest $request * @return SS_HTTPResonse A http response containing a json encoded array * @see: code-blocks/_config/routes.yml */ public function json(SS_HTTPRequest $request) { $this->response->addHeader('Content-Type', 'application/json'); if ($list = CodeBlock::get()->filter(array('Status' => 'Active'))->map('ID', 'Name')) { $this->response->setBody(json_encode($list->toArray())); return $this->response; } } } |