0
votes

I am working on laravel project where in i have to make CMS which requires tinyMCE , in tinyMCE while adding contents like uploading images,links,change color of fonts works perfect and gets store the way it should be in database but when i fetch the record from database and put it in tinymce all html tags are removed or stripped and it displays the plain content that is text , I have tried all possible solutions but none of them have given me desired result

Any Kind of Help would be appreciated !!

this is my TinyMCE Config file

var editor_config = {

    selector: "textarea#page_content",
    plugins: [
      " advlist autolink lists link image charmap print preview hr anchor pagebreak",
      "searchreplace wordcount visualblocks visualchars code fullscreen",
      "insertdatetime media nonbreaking save table contextmenu directionality",
      "emoticons template paste textcolor colorpicker textpattern bbcode"
    ],
    toolbar1: `insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify 
    | bullist numlist outdent indent | link image media`,
    toolbar2: 'print preview media | forecolor backcolor emoticons | fontsizeselect',

   style_formats: [
            {title: 'Open Sans', inline: 'span', styles: { 'font-family':'Open Sans'}},
            {title: 'Arial', inline: 'span', styles: { 'font-family':'arial'}},
            {title: 'Book Antiqua', inline: 'span', styles: { 'font-family':'book antiqua'}},
            {title: 'Comic Sans MS', inline: 'span', styles: { 'font-family':'comic sans ms,sans-serif'}},
            {title: 'Courier New', inline: 'span', styles: { 'font-family':'courier new,courier'}},
            {title: 'Georgia', inline: 'span', styles: { 'font-family':'georgia,palatino'}},
            {title: 'Helvetica', inline: 'span', styles: { 'font-family':'helvetica'}},
            {title: 'Impact', inline: 'span', styles: { 'font-family':'impact,chicago'}},
            {title: 'Symbol', inline: 'span', styles: { 'font-family':'symbol'}},
            {title: 'Tahoma', inline: 'span', styles: { 'font-family':'tahoma'}},
            {title: 'Terminal', inline: 'span', styles: { 'font-family':'terminal,monaco'}},
            {title: 'Times New Roman', inline: 'span', styles: { 'font-family':'times new roman,times'}},
            {title: 'Verdana', inline: 'span', styles: { 'font-family':'Verdana'}}
        ],
      valid_elements : 'img[src]',
      entity_encoding: "raw",
        extended_valid_elements : "em[class|name|id]",
        valid_children : "+body[style], +style[type]",
        apply_source_formatting : false,               
        verify_html : false,                           
     file_browser_callback : function(field_name, url, type, win) {
      var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
      var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;

      var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
      if (type == 'image') {
        console.log("Hip Hip Hurray");
        cmsURL = cmsURL + "&type=Images";
      } else {
        cmsURL = cmsURL + "&type=Files";
      }

      tinyMCE.activeEditor.windowManager.open({
        file : cmsURL,
        title : 'Filemanager',
        width : x * 0.8,
        height : y * 0.8,
        resizable : "yes",
        close_previous : "no"
      });
    }
  };

  tinymce.init(editor_config);

and in blade html file

 <textarea name="page_content" class="form-control" id="page_content" >
  {!!$page->page_content!!}
 </textarea>

and if this content is put outside tinymce then it displays exactly the way i want i.e the image ,links does not get stripped off !!

1

1 Answers

0
votes

You are using the option valid_elements which overrides the existing valid elements. You config makes it so that only img[src] tags are allowed. So when saved, all tags that are not img[src] are removed from your content.

You should use extend_valid_elements to add more valid elements to the existing object.