diff --git a/client/coral-framework/helpers/plugins.js b/client/coral-framework/helpers/plugins.js index e0aa05c80..bb21bef6c 100644 --- a/client/coral-framework/helpers/plugins.js +++ b/client/coral-framework/helpers/plugins.js @@ -7,17 +7,29 @@ import flatten from 'lodash/flatten'; import flattenDeep from 'lodash/flattenDeep'; import {getDefinitionName, mergeDocuments} from 'coral-framework/utils'; import {loadTranslations} from 'coral-framework/services/i18n'; -import {injectReducers} from 'coral-framework/services/store'; +import {injectReducers, getStore} from 'coral-framework/services/store'; import camelize from './camelize'; +function getSlotComponents(slot) { + const pluginConfig = getStore().getState().config.plugin_config; + return flatten(plugins + + // Filter out components that have been disabled in `plugin_config` + .filter((o) => !pluginConfig[o.plugin] || !pluginConfig[o.plugin].disable_components) + + .filter((o) => o.module.slots[slot]) + .map((o) => o.module.slots[slot])); +} + +export function isSlotEmpty(slot) { + return !!getSlotComponents(slot).length; +} + /** * Returns React Elements for given slot. */ export function getSlotElements(slot, props = {}) { - const components = flatten(plugins - .filter((o) => o.module.slots[slot]) - .map((o) => o.module.slots[slot])); - return components + return getSlotComponents(slot) .map((component, i) => React.createElement(component, {key: i, ...props})); } diff --git a/plugin-api/beta/client/services/index.js b/plugin-api/beta/client/services/index.js index 509d4f55c..ddaa346ab 100644 --- a/plugin-api/beta/client/services/index.js +++ b/plugin-api/beta/client/services/index.js @@ -1,2 +1,3 @@ export {t} from 'coral-framework/services/i18n'; export {can} from 'coral-framework/services/perms'; +export {isSlotEmpty} from 'coral-framework/helpers/plugins'; diff --git a/views/article.ejs b/views/article.ejs index c216f158d..d803b6295 100644 --- a/views/article.ejs +++ b/views/article.ejs @@ -31,6 +31,13 @@ asset_id: '<%= asset_id ? asset_id : '' %>', auth_token: '', plugin_config: { + /** + * You can disable rendering slot components of a plugin by doing: + * + * 'coral-plugin-love': { + * disable_components: true, + * }, + */ test: 'data', debug: false }