SuiteCRM 8.5.1 legacy/custom folder

I am currently using SuiteCRM version 8.5.1. I have tried cloning module files to the same path within the legacy/custom folder, performed a quick repair and rebuild, but the changes are not showing up. I am attempting to edit the tinyMCE toolbar on the email send page, as suggested in other posts for version 7, but it doesn’t seem to be working.

Hello Wrc ,

I am also face same problem, My all customization in tinyMCE has removed and try to do same things again but not reflected in Editor.

So this is priority Ticket for as per client delivered project, I changes in “public/legacy/include/SuiteEditor/SuiteEditorConnector.php” (


) . I know , it is not safe mode customizied. But it required to delivered the project, If any found any alternate solution. Please tag me , I will changes in future.

@wrc @nilesh2323pal When you clear symfony cache from CLI ./bin/console cache:clear and reload the page, is the web interface showing your changes to tinyMCE?

Hi @nilesh2323pal @chris001,

Thank you for your help.

The extra TinyMCE options will show if I perform the steps below.

1.1. Edit the file public/legacy/modules/Emails/include/ComposeView/EmailsComposeView.js to the below.

1.2. Change:

menubar: false,

plugins: [‘link’],

toolbar: [‘fontselect | fontsizeselect | bold italic underline | forecolor backcolor | styleselect | outdent indent | link’],

To:

menubar: true,

plugins: [‘fullscreen code print preview searchreplace autolink directionality visualblocks visualchars image link media template codesample charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern’],

toolbar: [‘undo redo | fontselect | fontsizeselect | forecolor backcolor | bold italic underline | indent outdent bullist numlist | styleselect’],

1.3. Delete the folders cache/ and public/legacy/cache/

1.4. Run ./bin/console cache:clear in the terminal.

1.5. Run a ‘Quick Repair and Rebuild’

1.6. Open a private browser window or clear the browser cache.

1.7. Visit /#/emails/compose?return_module=Emails&return_action=index

1.8. Click on an email on the contact or account page. For some reason, you have to visit /#/emails/compose?return_module=Emails&return_action=index first for it to show on these pages.

The extra TinyMCE options will not show if I perform the steps below to make it upgrade-safe.

2.1. Copy the file public/legacy/modules/Emails/include/ComposeView/EmailsComposeView.js to public/legacy/custom/modules/Emails/include/ComposeView/EmailsComposeView.js.

2.2. Change:

menubar: false,

plugins: [‘link’],

toolbar: [‘fontselect | fontsizeselect | bold italic underline | forecolor backcolor | styleselect | outdent indent | link’],

To:

menubar: true,

plugins: [‘fullscreen code print preview searchreplace autolink directionality visualblocks visualchars image link media template codesample charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern’],

toolbar: [‘undo redo | fontselect | fontsizeselect | forecolor backcolor | bold italic underline | indent outdent bullist numlist | styleselect’],

2.3. Delete the folders cache/ and public/legacy/cache/

2.4. Run ./bin/console cache:clear in the terminal.

2.5. Run a ‘Quick Repair and Rebuild’

2.6. Open a private browser window or clear the browser cache.

2.7. Visit /#/emails/compose?return_module=Emails&return_action=index

2.8. Click on an email on the contact or account page. For some reason, you have to visit /#/emails/compose?return_module=Emails&return_action=index first for it to show on these pages.

Why does the copy of the file in the custom folder not overwrite the working file in SuiteCRM 8?

Leave /public/legacy/cache untouched!
It contains many essential CRM user created data files that do not exist anywhere else in the system!
More: SugarCRM cache directory - it is NOT a cache directory! - Academe Computing

Good job I have a backup! :grimacing: Thank you.

No Cris, The tinyMCE UI has not changed. I follow up your process. My aim was change in common file and imapct all the module. Please check same code in your local System.

  1. Add custom file public/legacy/custom/include/SuiteEditor/SuiteEditorConnector.php
class SuiteEditorConnector
{
    public static function getSuiteSettings($html, $width)
    {
        return array(
            'contents' => $html,
            'textareaId' => 'body_text',
            'elementId' => 'email_template_editor',
            'width' => $width,
            'clickHandler' => "function(e){
                onClickTemplateBody();
            }",
            'tinyMCESetup' => "{
                setup: function(editor) {
                    editor.on('focus', function(e){
                        onClickTemplateBody();
                    });
                },
                height : '480',
                plugins: ['code', 'table', 'link', 'image','wordcount', 'media', 'template', 'anchor', 'codesample', 'fullscreen'],
                toolbar: ['fontselect | fontsizeselect | bold italic underline | forecolor backcolor | styleselect | fullscreen | outdent indent | link | code table | image media template link anchor codesample'],
                images_upload_url : 'postAcceptor.php'
            }"
        );
    }

Add file on root directory postAcceptor.php

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
    if(!defined('sugarEntry'))define('sugarEntry', true);
    require_once('include/entryPoint.php');
  /***************************************************
   * Only these origins are allowed to upload images *
   ***************************************************/
  global $sugar_config;
  $accepted_origins = $sugar_config['valid_origin'];
  /*********************************************
   * Change this line to set the upload folder *
   *********************************************/
  $imageFolder = "public/";

  if (isset($_SERVER['HTTP_ORIGIN'])) {
    // same-origin requests won't set an origin. If the origin is set, it must be valid.
    if (in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)) {
      header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
    } else {
      header("HTTP/1.1 403 Origin Denied");
      return;
    }
  }

  // Don't attempt to process the upload on an OPTIONS request
  if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    header("Access-Control-Allow-Methods: POST, OPTIONS");
    return;
  }

  reset ($_FILES);
  $temp = current($_FILES);
  if (is_uploaded_file($temp['tmp_name'])){
    /*
      If your script needs to receive cookies, set images_upload_credentials : true in
      the configuration and enable the following two headers.
    */
    // header('Access-Control-Allow-Credentials: true');
    // header('P3P: CP="There is no P3P policy."');

    // Sanitize input
    if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) {
        header("HTTP/1.1 400 Invalid file name.");
        return;
    }

    // Verify extension
    if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png","jpeg"))) {
        header("HTTP/1.1 400 Invalid extension.");
        return;
    }
    $ext = strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION));
    
    $guid = guid();
    // Accept upload if there was no origin, or if it is an accepted origin
    $filetowrite = $imageFolder . $guid.".".$ext;
    move_uploaded_file($temp['tmp_name'], $filetowrite);
    
    // Determine the base URL
    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https://" : "http://";
    $baseurl = $protocol . $_SERVER["HTTP_HOST"] . rtrim(dirname($_SERVER['REQUEST_URI']), "/") . "/";

    // Respond to the successful upload with JSON.
    // Use a location key to specify the path to the saved image resource.
    // { location : '/your/uploaded/image/file'}
    echo json_encode(array('location' => $baseurl . $filetowrite));
  } else {
    // Notify editor that the upload failed
    header("HTTP/1.1 500 Server Error");
  }

  function guid(){
    if (function_exists('com_create_guid') === true)
        return trim(com_create_guid(), '{}');
    
    $data = openssl_random_pseudo_bytes(16);
    $data[6] = chr(ord($data[6]) & 0x0f | 0x40);
    $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
    return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    }
?>

Earlier this code working on 7.14 but after upgrade 8.5 my custom code is not working. But when i add code on this path “public/legacy/include/SuiteEditor/SuiteEditorConnector.php” My editor upload functionality working fine.

Currently are changes happen on main file which is not upgrade safe.

1 Like

Hi @nilesh2323pal @chris001,

Yes, same here. Why does the copy of the file in the custom folder not overwrite the working file in SuiteCRM 8? Where do you put changed files in SuiteCRM 8?

You probably have a FATAL error in your php_errors.log telling you what is wrong about your custom file…

Thank you @pgr. I’ve checked the logs and there is nothing about the clone file in the legacy/custom folder. It’s just not being recognised at all.

Which post or tutorial are you following? Are you sure you followed all the steps?

I would expect a previous step to be necessary, at the point where the SuiteEditorConnector class is being loaded.

Any way, just to get this straight - exactly which screen are you loading this from? If it’s Email compose window, from Emails module (not Campaigns), then forget it, the SuiteEditor class is not used there.

(I added it there for my PowerReplacer add-on because I needed it to be able to specify DirectHTML editor in Compose window).

@pgr, thank you for your help; I think you have mixed my original question and the @nilesh2323pal issue.

I have changed the file public/legacy/modules/Emails/include/ComposeView/EmailsComposeView.js to show the extra TinyMCE options, but it’s not upgrade-safe. In the documentation, it says if you want to keep a change after an update, you need to clone the file to the custom folder and make your changes. When I do this, e.g. move public/legacy/modules/Emails/include/ComposeView/EmailsComposeView.js to public/legacy/custom/modules/Emails/include/ComposeView/EmailsComposeView.js it does not overwrite the original file public/legacy/modules/Emails/include/ComposeView/EmailsComposeView.js

You have to run the JS rebuilds from Admin / Repairs, and force a hard-refresh on the browser.