Skip to content

Commit

Permalink
added a new check for the markdown buttons to check dependency module…
Browse files Browse the repository at this point in the history
…s within the YML configs, updated the JS to check whether the asset-admin module is installed.
  • Loading branch information
fonsekaean committed Dec 22, 2017
1 parent 16c1aa9 commit 4f01b8a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions _config/editorconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ SilverStripers\markdown\forms\MarkdownEditorConfig:
action: ssEmbed
className: 'fa fa-play'
title: 'Embed Media'
dependsOn: 'silverstripe/asset-admin'
-
name: image
action: ssImage
className: 'fa fa-picture-o'
title: 'Insert Image'
dependsOn: 'silverstripe/asset-admin'
- '|'
-
name: preview
Expand Down
4 changes: 2 additions & 2 deletions client/dist/bundle.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion client/src/entwine/Markdown_ssembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ReactDOM from 'react-dom';

import { ApolloProvider } from 'react-apollo';
import { provideInjector } from 'lib/Injector';
const InjectableInsertEmbedModal = provideInjector(window.InsertEmbedModal.default);
const InjectableInsertEmbedModal = window.InsertEmbedModal ? provideInjector(window.InsertEmbedModal.default) : null;

jQuery.entwine('ss', ($) => {

Expand Down Expand Up @@ -40,6 +40,9 @@ jQuery.entwine('ss', ($) => {
* @private
*/
_renderModal(show) {
if(!InjectableInsertEmbedModal) {
throw new Error('Embed is not supported, Install silverstripe/asset-admin');
}
const handleHide = () => this.close();
const handleInsert = (...args) => this._handleInsert(...args);
const handleCreate = (...args) => this._handleCreate(...args);
Expand Down
5 changes: 4 additions & 1 deletion client/src/entwine/Markdown_ssmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom';

import { ApolloProvider } from 'react-apollo';
import { provideInjector } from 'lib/Injector';
const InjectableInsertMediaModal = provideInjector(window.InsertMediaModal.default);
const InjectableInsertMediaModal = window.InsertMediaModal ? provideInjector(window.InsertMediaModal.default) : null;


jQuery.entwine('ss', ($) => {
Expand Down Expand Up @@ -34,6 +34,9 @@ jQuery.entwine('ss', ($) => {
* @private
*/
_renderModal(show) {
if(!InjectableInsertMediaModal) {
throw new Error('Embed is not supported, Install silverstripe/asset-admin');
}
const handleHide = () => this.close();
const handleInsert = (...args) => this._handleInsert(...args);
const store = window.ss.store;
Expand Down
19 changes: 18 additions & 1 deletion src/forms/MarkdownEditorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Core\Manifest\ModuleResourceLoader;
use SilverStripe\View\SSViewer;
use SilverStripe\View\ThemeResourceLoader;
Expand Down Expand Up @@ -178,6 +179,22 @@ public function getEditorCSS()
return $editor;
}

/**
* @param $toolbar
* @return array
*/
private function checkSettingsDependencies($toolbar)
{
$moduleLoader = ModuleLoader::inst();
$modules = array_keys($moduleLoader->getManifest()->getModules());
$approved = [];
foreach ($toolbar as $item) {
if(empty($item['dependsOn']) || (isset($item['dependsOn']) && in_array($item['dependsOn'], $modules))) {
$approved[] = $item;
}
}
return $approved;
}

/**
* @return array
Expand All @@ -196,7 +213,7 @@ public function getSettings()
}

return [
'toolbar' => $toolbar,
'toolbar' => $this->checkSettingsDependencies($toolbar),
'editor_css' => $this->getEditorCSS(),
'identifier' => $this->getIdentifier()
];
Expand Down

0 comments on commit 4f01b8a

Please sign in to comment.