return function () {
$intro = '<p class="docs-demo-intro">The <code>ckeditor</code> option of <code>textarea()</code>: CKEditor 4.21 (the
<code>ckeditor</code> asset, pinned) replaces the textarea. The option takes <code>[\'config\' => [...]]</code>, the
<code>CKEDITOR.replace()</code> options; without a <code>config</code> the editor is started by the site template
<code>ckeditor_config</code>, which only the admin theme has. This one has a small toolbar and no file browser or uploads
(images by URL only). CKEditor copies its HTML into the textarea when the form is sent; below, the server shows what it received,
escaped. CKEditor 4 has no dark skin: on a dark Bootstrap 5 page the editor stays light. The demo stores nothing.
TinyMCE 8, the newer editor: <a href="' . _prepare_html(url('/@object/@action/' . urlencode('form/tinymce')), 0) . '">form/tinymce</a>.
Classes: <code>yf_form2</code>, <code>yf_form2_ckeditor</code>.</p>';
$config = [
'toolbar' => [
['Undo', 'Redo'], ['Format'], ['Bold', 'Italic', 'Underline', 'RemoveFormat'],
['NumberedList', 'BulletedList', 'Blockquote'], ['Link', 'Unlink', 'Image', 'Table'], ['Source'],
],
'format_tags' => 'p;h2;h3;pre',
'height' => 220,
'language' => 'en',
// no config.js and styles.js of the CDN; no upload plugins, no file browser buttons, no spell checker service
'customConfig' => '',
'stylesSet' => false,
'removePlugins' => 'uploadimage,uploadfile,filebrowser,elementspath,scayt',
];
$result = '';
$form_id = 'docs_ckeditor_demo';
$value = '<h2>Release notes</h2><p>Hello <strong>world</strong>, this is <em>CKEditor</em>.</p><ul><li>one</li><li>two</li></ul>';
$form = form((array) $_POST + ['ck_text' => $value], ['csrf' => true, '__form_id__' => $form_id, 'id' => 'ckeditor_form']);
$form->validate(['__form_id__' => $form_id, 'ck_text' => 'trim|required'])
->on_validate_ok(function ($data) use (&$result) {
$html = (string) $data['ck_text'];
$result = '<div class="alert alert-success" id="ckeditor_result"><b>Received ' . strlen($html) . ' bytes</b> (nothing stored):'
. '<pre class="ckeditor-demo-received">' . _prepare_html($html, 0) . '</pre></div>';
})
->textarea('ck_text', 'Text', ['id' => 'ck_text', 'rows' => 8, 'ckeditor' => ['config' => $config]])
->save();
// A failed CSRF check logs into the log_csrf_errors table; the demo writes no rows
$guard = _class('csrf_guard');
$log_errors = $guard->LOG_ERRORS;
$guard->LOG_ERRORS = false;
try {
$html = (string) $form;
} finally {
$guard->LOG_ERRORS = $log_errors;
}
css('.ckeditor-demo-received { white-space: pre-wrap; margin: 8px 0 0; }');
return $intro . $result . $html;
};