Skip to content

Instantly share code, notes, and snippets.

@anhtuank7c
Created February 15, 2016 10:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anhtuank7c/9119cd8eca8fff409881 to your computer and use it in GitHub Desktop.
<?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,
]);
}
}
@anhtuank7c
Copy link
Author

widget

@anhtuank7c
Copy link
Author

usage

widget2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment