CKEditor Plugin manager.
Expanded class hierarchy of CKEditorPluginManager
class CKEditorPluginManager extends PluginManagerBase {
/**
* Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct().
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,
*/
public function __construct(\Traversable $namespaces) {
$annotation_namespaces = array(
'Drupal\\ckeditor\\Annotation' => $namespaces['Drupal\\ckeditor'],
);
$this->discovery = new AnnotatedClassDiscovery('CKEditorPlugin', $namespaces, $annotation_namespaces, 'Drupal\\ckeditor\\Annotation\\CKEditorPlugin');
$this->discovery = new AlterDecorator($this->discovery, 'ckeditor_plugin_info');
$this->discovery = new CacheDecorator($this->discovery, 'ckeditor_plugin');
$this->factory = new DefaultFactory($this->discovery);
}
/**
* Determines which plug-ins are enabled.
*
* For CKEditor plugins that implement:
* - CKEditorPluginButtonsInterface, not CKEditorPluginContextualInterface,
* a plugin is enabled if at least one of its buttons is in the toolbar;
* - CKEditorPluginContextualInterface, not CKEditorPluginButtonsInterface,
* a plugin is enabled if its isEnabled() method returns TRUE
* - both of these interfaces, a plugin is enabled if either is the case.
*
* Internal plugins (those that are part of the bundled build of CKEditor) are
* excluded by default, since they are loaded implicitly. If you need to know
* even implicitly loaded (i.e. internal) plugins, then set the optional
* second parameter.
*
* @param \Drupal\editor\Plugin\Core\Entity\Editor $editor
* A configured text editor object.
* @param bool $include_internal_plugins
* Defaults to FALSE. When set to TRUE, plugins whose isInternal() method
* returns TRUE will also be included.
* @return array
* A list of the enabled CKEditor plugins, with the plugin IDs as keys and
* the Drupal root-relative plugin files as values.
* For internal plugins, the value is NULL.
*/
public function getEnabledPlugins(Editor $editor, $include_internal_plugins = FALSE) {
$plugins = array_keys($this
->getDefinitions());
$toolbar_buttons = array_unique(NestedArray::mergeDeepArray($editor->settings['toolbar']['buttons']));
$enabled_plugins = array();
foreach ($plugins as $plugin_id) {
$plugin = $this
->createInstance($plugin_id);
if (!$include_internal_plugins && $plugin
->isInternal()) {
continue;
}
$enabled = FALSE;
if ($plugin instanceof CKEditorPluginButtonsInterface) {
$plugin_buttons = array_keys($plugin
->getButtons());
$enabled = count(array_intersect($toolbar_buttons, $plugin_buttons)) > 0;
}
if (!$enabled && $plugin instanceof CKEditorPluginContextualInterface) {
$enabled = $plugin
->isEnabled($editor);
}
if ($enabled) {
$enabled_plugins[$plugin_id] = $plugin
->isInternal() ? NULL : $plugin
->getFile();
}
}
// Always return plugins in the same order.
asort($enabled_plugins);
return $enabled_plugins;
}
/**
* Retrieves all plugins that implement CKEditorPluginButtonsInterface.
*
* @param \Drupal\editor\Plugin\Core\Entity\Editor $editor
* A configured text editor object.
* @return array
* A list of the CKEditor plugins that implement buttons, with the plugin
* IDs as keys and lists of button metadata (as implemented by getButtons())
* as values.
*
* @see CKEditorPluginButtonsInterface::getButtons()
*/
public function getButtonsPlugins(Editor $editor) {
$plugins = array_keys($this
->getDefinitions());
$buttons_plugins = array();
foreach ($plugins as $plugin_id) {
$plugin = $this
->createInstance($plugin_id);
if ($plugin instanceof CKEditorPluginButtonsInterface) {
$buttons_plugins[$plugin_id] = $plugin
->getButtons();
}
}
return $buttons_plugins;
}
/**
* Injects the CKEditor plugins settings forms as a vertical tabs subform.
*
* @param array &$form
* A reference to an associative array containing the structure of the form.
* @param array &$form_state
* A reference to a keyed array containing the current state of the form.
* @param \Drupal\editor\Plugin\Core\Entity\Editor $editor
* A configured text editor object.
*/
public function injectPluginSettingsForm(array &$form, array &$form_state, Editor $editor) {
$definitions = $this
->getDefinitions();
foreach (array_keys($definitions) as $plugin_id) {
$plugin = $this
->createInstance($plugin_id);
if ($plugin instanceof CKEditorPluginConfigurableInterface) {
$plugin_settings_form = array();
$form['plugins'][$plugin_id] = array(
'#type' => 'details',
'#title' => $definitions[$plugin_id]['label'],
'#group' => 'editor][settings][plugin_settings',
);
$form['plugins'][$plugin_id] += $plugin
->settingsForm($plugin_settings_form, $form_state, $editor);
}
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CKEditorPluginManager:: |
public | function | Retrieves all plugins that implement CKEditorPluginButtonsInterface. | |
CKEditorPluginManager:: |
public | function | Determines which plug-ins are enabled. | |
CKEditorPluginManager:: |
public | function | Injects the CKEditor plugins settings forms as a vertical tabs subform. | |
CKEditorPluginManager:: |
public | function | Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). | |
PluginManagerBase:: |
protected | property | A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. | 3 |
PluginManagerBase:: |
protected | property | The object that discovers plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that instantiates plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | |
PluginManagerBase:: |
public | function |
Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface:: |
|
PluginManagerBase:: |
public | function |
Returns a preconfigured instance of a plugin. Overrides FactoryInterface:: |
6 |
PluginManagerBase:: |
public | function |
Gets a specific plugin definition. Overrides DiscoveryInterface:: |
|
PluginManagerBase:: |
public | function |
Gets the definition of all plugins for this type. Overrides DiscoveryInterface:: |
|
PluginManagerBase:: |
public | function |
Returns a preconfigured instance of a plugin. Overrides MapperInterface:: |
6 |
PluginManagerBase:: |
public | function | Performs extra processing on plugin definitions. | 2 |