Media Content editor tinyMCE for cakephp 3.7 - cakephp

I'm using cakephp 3.7. I tried to get tinymce working, by 2 differents ways but it doesn't work. First I tried to adapte the former cakephp 2 steps to make it work as shown in the cakephp documentation here "https://bakery.cakephp.org/2012/04/11/Helper-TinyMCE-for-CakePHP-2.html", it worked in a previous project where i used cakephp 2, but here it didn't work. Secondly I followed an other tutorial suggesting toenter code here use tinymce inside cakephp 3.7 's plugin folder just like a plugin, but still not working. Any help about how to install tinymce for cakephp 3.7?
N.B: I got my cakephp 3.7 through composer as well as all the other plugins i used, except tinymce that i can't get with composer.
I'm having this error : Method App\View\Helper\TinymceHelper::domId does not exist [CORE/src/View/Helper.php, line.
Thanks in advance.
I downloaded tinymce and set it up in the webroot/js folder
In the AppController.php I added public $helpers = ['tinymce.tinymce'];
In the view where to display the tinymce editor I added in the relevant text area
<?php echo $this->Tinymce->input('content',
array('label' =>
'Content'),array('language'=>'en'),'bbcode');
?>
This my the head in tinymceHelper.php
use Cake\View\Helper;
use Cake\View\StringTemplateTrait;
class TinymceHelper extends Helper
{
// Take advantage of other helpers
public $helpers = array('Js', 'Html', 'Form');
...}
Or may be you also know another content editor more relevant to cakephp 3.7. Thanks you guys !

I switched from TinyMCE to CKEDITOR. I don't have any kind of helper, just:
load the JS in the layout (echo $this->Html->script('https://cdn.ckeditor.com/4.8.0/full/ckeditor.js');)
put relevant classes (e.g. wysiwyg_simple or wysiwyg_advanced) on inputs as required (echo $this->Form->input('description', ['class' => 'wysiwyg_simple']);)
have an initialization function as below, called from onReady (and also whenever dynamic content that might contain a textarea is loaded into the page)
if (typeof CKEDITOR !== 'undefined') {
for(name in CKEDITOR.instances) {
CKEDITOR.instances[name].destroy(true);
}
CKEDITOR.replaceAll(function (textarea, config) {
if (jQuery(textarea).hasClass('wysiwyg_advanced')) {
config.toolbar = [
{
name: 'clipboard',
items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']
},
{name: 'editing', items: ['SpellChecker', 'Scayt']},
{name: 'links', items: ['Link', 'Unlink', 'Anchor']},
{name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar', 'PageBreak']},
'/',
{
name: 'basicstyles',
items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']
},
{
name: 'paragraph',
items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv',
'-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
},
'/',
{name: 'styles', items: ['Format', 'Font', 'FontSize']},
{name: 'colors', items: ['TextColor', 'BGColor']},
{name: 'tools', items: ['Maximize', 'ShowBlocks', '-', 'About']},
{name: 'document', items: ['Source']}
];
} else if (jQuery(textarea).hasClass('wysiwyg_simple')) {
config.toolbar = [
{name: 'clipboard', items: ['Cut', 'Copy', 'PasteText', '-', 'Undo', 'Redo']},
{
name: 'basicstyles',
items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']
},
{name: 'paragraph', items: ['NumberedList', 'BulletedList']},
{name: 'styles', items: ['Format']}
];
} else {
return false;
}
config.resize_dir = 'both';
});
}

After a certain time of research and with the suggestion of #Greg Schmidt, I got the Ckeditor not as a plugin but inside the js folder.
1- I refered to it in the AppController.php with
public $helpers = ['CkEditor.Ck'];
2- In the media.ctp I called the Ckeditor in the head of the file by "
<?php echo $this->Html->script('ckeditor/ckeditor');?>
(This is very mandatory because without this call cakephp 3.x will only display a
blank textarea).
3- In the relevant form element where to load the ckeditor I used the syntax
enter image description here
<?= echo $this->Ck->input('Media_Content', array('class', 'ckeditor); ?>
4- In the relevant layout I added
Html->script('https://cdn.ckeditor.com/4.8.0/full/ckeditor.js'); ?> just as Greg Schmidt suggested.
And the Ckeditor shows up !!!

Related

React Quill - How do I show the differences between two text versions?

I'm currently designing a website with React where the user will work with a text editor. The text editor will already have text in it. The user will make some changes to the text and submit it. I would like to add a button that will show the user the differences between the original text and his new text, like Git but down to individual characters.
I'm currently trying to use Quill for that. I've found a lovely solution to my problem, but it's written in plain JavaScript. I've tried translating it to React by setting the Quill objects in the state:
const [quill_old, set_quill_old] = React.useState(new Quill('#old', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
}))
const [quill_new, set_quill_new] = React.useState(new Quill('#new', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
}))
const [quill_diff, set_quill_diff] = React.useState(new Quill('#diff', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
}))
but when initializing the code it gets stuck on the "findDiff" function, on this line:
var oldContent = quill_old.getContents();
and returns an error:
TypeError: Cannot read property 'length' of undefined
Where "undefined" is "quill_old".
When trying to run the page without the function, the page shows properly, but I get multiple errors in the console like this:
quill Invalid Quill container #old
Does somebody know how to properly implement this solution in React? Or has a suggestion on some other library I can use?
Thank you for your time

HTML format of data retreived from the database is messed up

I have some HTML data in my database (newsletter) which I would like to display inside the CK Editor, however for some reason, the CKEditor is "messing" up the format of this HTML. For example, this is part of the original data in the db
<P style="FONT-SIZE: 2pt; MARGIN-BOTTOM: 0pt; MARGIN-TOP: 0pt">
<SPAN style="FONT-FAMILY: Verdana"> </SPAN>
</P>
<DIV style="TEXT-ALIGN: center">
<TABLE style="WIDTH: 408.8pt; BORDER-COLLAPSE: collapse; MARGIN-LEFT: auto; MARGIN-RIGHT: auto" cellSpacing=0 cellPadding=0>
<TBODY>
and this is how it is displayed inside the CKEditor :-
<p><span style="font-family:Verdana"> </span></p>
<div>
<table cellspacing="0" cellpadding="0" style="width:408.8pt" class=" cke_show_border">
<tbody>
with the result that the text is not centre aligned and also not the same format.
So I was wondering, is there any setting for the CKEditor that leaves everything as it is without touching the HTML?
My exisiting config is as follows:-
const GetDefaultConfig = {
toolbar: [
{ name: 'document', items: ['Save', 'NewPage', 'Preview', 'Print', '-', 'Templates'] },
{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
{ name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', 'Scayt'] },
{ name: 'forms', items: ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'] },
{ name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
{ name: 'colors', items: ['TextColor', 'BGColor'] },
{ name: 'tools', items: ['Maximize', 'ShowBlocks'] },
'/',
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language'] },
{ name: 'links', items: ['Link', 'Unlink', 'Anchor'] },
{ name: 'insert', items: ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe'] }
],
extraPlugins: 'font',
font_names: 'Arial;Comic Sans MS;Courier New;Georgia;Lucida Sans Unicode;Open Sans Regular;Tahoma;Times New Roman;Trebuchet MS;Verdana;',
language: 'en', //if ommitted the language of the users' browser is taken
removeDialogTabs: 'link:advanced;link:target;table:advanced', // Simplify the dialog windows.
format_tags: 'p;h1;h2;h3;h4', // Set the most common block elements.
fontSize_sizes: '8/8pt;9/9pt;10/10pt;11/11pt;12/12pt;14/14pt;16/16pt;18/18pt;20/20pt',
extraAllowedContent: 'div[id, contenteditable]',
enterMode: 2,
font_defaultLabel: 'Verdana',
fontSize_defaultLabel: '9',
disableNativeSpellChecker: false,
scayt_autoStartup: true,
// remove this line below for disabling browser spellcheck
removePlugins : 'scayt,menubutton,contextmenu,htmldataprocessor',
// HOW TO USE THE BROWSER SPELLCHECK
// To use the browser spellcheck, the user has to CTRL+RightClick on an empty space in the text area, so that he can choose the Language he
// wants to work with for checking the spelling of his text.
// To change a word that is wrong (red underlined), CTLR+RightClick on the actual word to get suggestions to change it to a different word
scayt_uiTabs : '0,1,0',
};
I would like to have some kind of setting that leaves all the HTML tags as they are originally.
Is it possible?
Thanks for your help and time
I solved this by adding
allowedContent: true,
to the config of the CKEditor.

CKEditor4-react : add EasyImage plugin without cloud url

I am using CKEditor4-react and want to add EasyImage plugin but without using cloudservice URL. As an alternate I have a folder hosted on server where it should upload the image. But it doesn't work.
I followed the documentation to use EasyImage plugin -
https://ckeditor.com/docs/ckeditor4/latest/examples/easyimage.html
https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-cloudServices_uploadUrl
and as per it "cloudServices_uploadUrl" is mandatory for EasyImage plugin.
Can I provide an alternate URL which is hosted on our server so the images can be saved and fetched from there?
The old version of CKEditor4 was used in one of our legacy apps built in Knockout.js where it is being used in a similar way consuming the ckeditor/plugin/simpleuploads.
But i didn't find any such plugin in the current CKEditor4.12 version
config: {
toolbar: [
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike'] },
{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
{ name: 'insert', items: ['Link', 'EasyImageUpload', 'Table'] },
{ name: 'styles', items: ['Styles', 'FontSize', 'Font', 'Format', 'TextColor', 'BGColor'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', 'Blockquote', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] }
],
height: 600,
width: 950,
extraPlugins: 'easyimage',
removePlugins: 'image',
//cloudServices_uploadUrl: 'https://33333.cke-cs.com/easyimage/upload/', //this is a demo ckeditor cloud service URL
cloudServices_uploadUrl: '/app/Data' //this is folder hosted on our server which is accessible as localhost/app/data
},
Easy Image plugin for CKEditor 4 only supports Cloud Services for uploading images at the moment, so cloudServices_uploadUrl is mandatory and should point to CKEditor Cloud Services endpoint as the documentation says.
If you would like to upload and store images on your own server you may use CKFinder, your custom upload adapter or look for any 3rd-party solution which satisfy your needs.

Error: [CKEDITOR.dialog.openDialog] Dialog Image failed when loading definition in Angularjs

Only in production, when i try to insert image in CKEditor i get the Error:
[CKEDITOR.dialog.openDialog] Dialog Image failed when loading definition
and when i try to add tables i get:
[CKEDITOR.dialog.openDialog] Dialog table failed when loading definition.
The other options of editor work correctly and the version in bower.json is: "ckeditor": "#full/4.5.4",
My toolbar configuration is:
$ckEditorProvider.setDefaults({
toolbar: [
{
name: 'editing',
items: ['Find', 'Replace', '-', 'SelectAll', '-', 'Scayt', '-']
},
{
name: 'insert',
items: ['Image','Table']
},
'/',
{
name: 'styles',
items: ['Bold', 'Italic', 'Underline', 'Styles', 'Format', 'Font', 'FontSize']
}
]
});
CKEDITOR.basePath = location.href.substr(0, location.href.indexOf(location.hash)) + 'bower_components/ckeditor/';
CKEDITOR.plugins.basePath = location.href.substr(0, location.href.indexOf(location.hash)) + 'bower_components/ckeditor/plugins';
}
Does anyone have a clue why this happens?

How do add <legend> to a backbone form? Where in the schema does it go?

Scout.models.Equipment = Backbone.RelationalModel.extend({
schema:{
asset_number:{ type:'Text' },
notes: 'TextArea',
tag:{ type: 'Text', validators: ['required']}
},
defaults: {
id: null,
name: null,
}
});
I want to add a legend to the scheme but the examples dont have a legend.
While the main examples do not have any, There is some in the code
Here
For example
It is working in the page if you view it (it will run tests as well)

Resources