|
| 1 | +<?php |
| 2 | + |
| 3 | +use SilverStripe\Core\Manifest\ModuleLoader; |
| 4 | +use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig; |
| 5 | +use SilverStripe\TinyMCE\TinyMCEConfig; |
| 6 | + |
| 7 | +// Avoid creating global variables |
| 8 | +call_user_func(function () { |
| 9 | + $editorConfig = HTMLEditorConfig::get('cms'); |
| 10 | + |
| 11 | + if (!$editorConfig instanceof TinyMCEConfig) { |
| 12 | + return; |
| 13 | + } |
| 14 | + |
| 15 | + $editorConfig->setOptions([ |
| 16 | + 'friendly_name' => 'Default CMS', |
| 17 | + 'priority' => '50', |
| 18 | + 'skin' => 'silverstripe', |
| 19 | + 'contextmenu' => "searchreplace | sslink anchor ssmedia ssembed inserttable | cell row column deletetable", |
| 20 | + 'use_native_selects' => false, |
| 21 | + ]); |
| 22 | + $editorConfig->insertButtonsAfter('table', 'anchor'); |
| 23 | + |
| 24 | + // Prepare list of plugins to enable |
| 25 | + $moduleManifest = ModuleLoader::inst()->getManifest(); |
| 26 | + $module = $moduleManifest->getModule('silverstripe/htmleditor-tinymce'); |
| 27 | + $plugins = []; |
| 28 | + |
| 29 | + // Add link plugins if silverstripe/admin is installed. |
| 30 | + // The JS in these relies on some of the admin code e.g. modals. |
| 31 | + if ($moduleManifest->moduleExists('silverstripe/admin')) { |
| 32 | + $plugins += [ |
| 33 | + 'sslink' => $module->getResource('client/dist/js/TinyMCE_sslink.js'), |
| 34 | + 'sslinkexternal' => $module->getResource('client/dist/js/TinyMCE_sslink-external.js'), |
| 35 | + 'sslinkemail' => $module->getResource('client/dist/js/TinyMCE_sslink-email.js'), |
| 36 | + ]; |
| 37 | + // Move anchor button to be after the link button |
| 38 | + $editorConfig->removeButtons('anchor'); |
| 39 | + $editorConfig->insertButtonsAfter('sslink', 'anchor'); |
| 40 | + } |
| 41 | + |
| 42 | + // Add plugins for managing assets if silverstripe/asset-admin is installed |
| 43 | + if ($moduleManifest->moduleExists('silverstripe/asset-admin')) { |
| 44 | + $plugins += [ |
| 45 | + 'ssmedia' => $module->getResource('client/dist/js/TinyMCE_ssmedia.js'), |
| 46 | + 'ssembed' => $module->getResource('client/dist/js/TinyMCE_ssembed.js'), |
| 47 | + 'sslinkfile' => $module->getResource('client/dist/js/TinyMCE_sslink-file.js'), |
| 48 | + ]; |
| 49 | + $editorConfig->insertButtonsAfter('table', 'ssmedia'); |
| 50 | + $editorConfig->insertButtonsAfter('ssmedia', 'ssembed'); |
| 51 | + } |
| 52 | + |
| 53 | + // Add internal link plugins if silverstripe/cms is installed |
| 54 | + if ($moduleManifest->moduleExists('silverstripe/cms')) { |
| 55 | + $plugins += [ |
| 56 | + 'sslinkinternal' => $module->getResource('client/dist/js/TinyMCE_sslink-internal.js'), |
| 57 | + 'sslinkanchor' => $module->getResource('client/dist/js/TinyMCE_sslink-anchor.js'), |
| 58 | + ]; |
| 59 | + } |
| 60 | + |
| 61 | + if (!empty($plugins)) { |
| 62 | + $editorConfig->enablePlugins($plugins); |
| 63 | + } |
| 64 | +}); |
0 commit comments