Custom configuration in Moodle TinyMCE editor and relative URL/addressing to images

Viewed 20

How to custom set configuration in Moodle for TinyMCE editor to keep and save relative addresses/URLs? see image 1.

How to ensure how to enable/retain relative URL addresses in Moodle (TinyMCE editor)?

We use TinyMCE to edit content in the Moodle editor. We know Atto editor is default and was built specifically for Moodle, but we need TinyMCE editor.

We would like to use but relative addresses for images for more efficient maintenance and later migration to another server.

We found that the default Atto editor does not have problems with relative addresses, but the TinyMCE editor does.

We also found settings for changing parameters in the documentation https://www.tiny.cloud/docs/configure/url-handling/#convert_urls

In Moodle there should be a path for this: Administration > Site administration > Plugins > Text editors > Manage editors > custom configuration

We just don't know in which correct JSON format to find those parameters. How the right custom configuration should look in JSON format? Yes, we know the JSON format, but not one variant works completely correctly.

1st variant:

    tinyMCE.init({
          relative_url :false,
          remove_script_host : false,
          convert_urls: false
    });

2nd variant:

    {
    relative_url : 0,
    remove_script_host : 0
    }

[Moodle TinyMCE custom configuration][1] [1]: https://i.stack.imgur.com/QLBBs.png

1 Answers

You probably need to put the json elements in double quotes

{
    "relative_urls" : false,
    "remove_script_host" : false
}

The location for custom configuration

Site administration > Plugins > Text editors > TinyMCE HTML editor > General settings

Documentation for TinyMCE custom configuration

https://docs.moodle.org/400/en/TinyMCE_editor#Custom_configuration

Having said that, the default values for those 2 properties are already false

See function get_init_params

in lib/editor/tinymce/lib.php

$params = array(
    ...
    'relative_urls' => false,
    ...
    'remove_script_host' => false,
    ...
}

And having said that, maybe what you are looking for is a file repository?

You can create a repository on your server to store the images in a folder

See https://docs.moodle.org/400/en/File_system_repository

  • Create a folder called repository in your Moodle data folder
  • Create a subfolder to store the images, eg images
  • Upload images to the folder which should be moodledata/repository/images
  • Enable File system via Administration > Site administration > Plugins > Repositories > Manage Repositories
  • Save and then a settings link will appear next to the file system plugin
  • Go to settings, create a repository using the images folder and save

Now in any editor, click the "image" button, click on "find or upload an image", there is an option to select images from the images folder

Any images you upload to the moodledata/repository/images folder will be available site wide

The repositories are plugins, there are already some available for Google drive and DropBox via

Site administration > Plugins > Repositories > Manage repositories

Or you can download contributed plugins from here

https://moodle.org/plugins/?q=type:repository

Or you can develop your own repository plugin

https://docs.moodle.org/dev/Repository_plugins

Related