Skip to content

Commit

Permalink
MDL-75260 tiny_media: Adjust Menu configuration
Browse files Browse the repository at this point in the history
Part of MDL-75966
  • Loading branch information
andrewnicols committed Nov 10, 2022
1 parent 75ebfb7 commit 92765e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 37 additions & 8 deletions lib/editor/tiny/plugins/media/amd/src/configuration.js
Expand Up @@ -29,20 +29,49 @@ import {
import uploadHandler from "./upload-handler";
import {
addContextmenuItem,
addMenubarItem,
addToolbarButtons,
} from 'editor_tiny/utils';

const configureMenu = (menu) => {
// Replace the standard Media plugin with the Moodle embed.
if (menu.insert.items.match(/\bmedia\b/)) {
menu.insert.items = menu.insert.items.replace(/\bmedia\b/, videoButtonName);
} else {
menu.insert.items = `${videoButtonName} ${menu.insert.items}`;
}

// Replace the standard image plugin with the Moodle image.
if (menu.insert.items.match(/\bimage\b/)) {
menu.insert.items = menu.insert.items.replace(/\bimage\b/, imageButtonName);
} else {
menu.insert.items = `${imageButtonName} ${menu.insert.items}`;
}

// Add the Media Manager to the end of the Tools menu.
menu.tools.items += ` ${mediaManagerButtonName}`;

return menu;
};

const configureToolbar = (toolbar) => {
// The toolbar contains an array of named sections.
// The Moodle integration ensures that there is a section called 'content'.

return toolbar.map((section) => {
if (section.name === 'content') {
// Insert the image, and embed, buttons at the start of it.
section.items.unshift(imageButtonName, videoButtonName);
}

return section;
});
};

export const configure = (instanceConfig) => {
// Update the instance configuration to add the Media menu option to the menus and toolbars and upload_handler.
return {
contextmenu: addContextmenuItem(instanceConfig.contextmenu, imageButtonName, videoButtonName),
toolbar: addToolbarButtons(instanceConfig.toolbar, 'content', [imageButtonName, videoButtonName]),
menu: addMenubarItem(
addMenubarItem(instanceConfig.menu, 'insert', `${imageButtonName} ${videoButtonName}`),
'tools',
mediaManagerButtonName
),
menu: configureMenu(instanceConfig.menu),
toolbar: configureToolbar(instanceConfig.toolbar),

// eslint-disable-next-line camelcase
images_upload_handler: (blobInfo, progress) => uploadHandler(window.tinymce.activeEditor, blobInfo, progress)
Expand Down
6 changes: 3 additions & 3 deletions lib/editor/tiny/plugins/media/lang/en/tiny_media.php
Expand Up @@ -63,8 +63,8 @@
$string['filemanager'] = 'File manager';
$string['hasmissingfiles'] = 'Warning! The following files that are referenced in the text area appear to be missing:';
$string['height'] = 'Height';
$string['helplinktext'] = 'Moodle Media Helper';
$string['imagebuttontitle'] = 'Moodle Image';
$string['helplinktext'] = 'Media Helper';
$string['imagebuttontitle'] = 'Image';
$string['imageproperties'] = 'Image properties';
$string['imageurlrequired'] = 'An image must have a URL.';
$string['label'] = 'Label';
Expand Down Expand Up @@ -98,6 +98,6 @@
$string['unusedfilesheader'] = 'Unused files';
$string['unusedfilesremovalnotice'] = 'Any unused files will be automatically deleted when saving changes.';
$string['video'] = 'Video';
$string['videobuttontitle'] = 'Moodle Video';
$string['videobuttontitle'] = 'Video';
$string['videosourcelabel'] = 'Video source URL';
$string['width'] = 'Width';

0 comments on commit 92765e9

Please sign in to comment.