Created
February 15, 2016 10:03
-
-
Save anhtuank7c/9119cd8eca8fff409881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\View\Widget; | |
use Cake\Core\Configure; | |
use Cake\I18n\I18n; | |
use Cake\View\Form\ContextInterface; | |
use Cake\View\Widget\BasicWidget; | |
/** | |
* Input widget class for generating a textarea control. | |
* | |
* This class is intended as an internal implementation detail | |
* of Cake\View\Helper\FormHelper and is not intended for direct use. | |
*/ | |
class TinyMCEWidget extends BasicWidget | |
{ | |
/** | |
* Render a text area form widget. | |
* | |
* Data supports the following keys: | |
* | |
* - `name` - Set the input name. | |
* - `val` - A string of the option to mark as selected. | |
* - `escape` - Set to false to disable HTML escaping. | |
* | |
* All other keys will be converted into HTML attributes. | |
* | |
* @param array $data The data to build a textarea with. | |
* @param \Cake\View\Form\ContextInterface $context The current form context. | |
* @return string HTML elements. | |
*/ | |
public function render(array $data, ContextInterface $context) | |
{ | |
$access_key = Configure::read('data-get.biz.file_manager.access_key'); | |
$locale = I18n::locale(); | |
$mce = | |
"<script>tinymce.init({" . | |
"forced_root_block: false, relative_urls: false, mode : \"exact\", elements: \"" . $data['name'] . "\", theme: \"modern\", height : 300," . | |
"plugins: [" . | |
"\"advlist autolink link image lists charmap preview hr anchor pagebreak\"," . | |
"\"searchreplace wordcount visualblocks visualchars insertdatetime media nonbreaking\"," . | |
"\"table contextmenu directionality emoticons paste textcolor responsivefilemanager fullscreen\"]," . | |
"toolbar1: \"undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | styleselect\"," . | |
"toolbar2: \"| responsivefilemanager | link unlink anchor | image media | forecolor backcolor | fullscreen preview code \"," . | |
"image_advtab: true," . | |
"language: \"" . $locale . "\"," . | |
"external_filemanager_path: \"/filemanager/\"," . | |
"filemanager_access_key: \"" . $access_key . "\"," . | |
"filemanager_title: \"Responsive Filemanager\"," . | |
"external_plugins: {\"filemanager\": \"/filemanager/plugin.min.js\"}" . | |
"});</script>"; | |
$data += [ | |
'val' => '', | |
'name' => '', | |
'escape' => true, | |
'rows' => 5, | |
'templateVars' => [], | |
]; | |
return $this->_templates->format('editor', [ | |
'name' => $data['name'], | |
'value' => $data['escape'] ? h($data['val']) : $data['val'], | |
'templateVars' => $data['templateVars'], | |
'attrs' => $this->_templates->formatAttributes( | |
$data, | |
['name', 'val'] | |
), | |
'mce' => $mce, | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment