function CKEditor5::shouldHaveVisiblePluginSettingsForm

Same name in other branches
  1. 10 core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::shouldHaveVisiblePluginSettingsForm()
  2. 11.x core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::shouldHaveVisiblePluginSettingsForm()

Determines whether the plugin settings form should be visible.

Parameters

\Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition $definition: The configurable CKEditor 5 plugin to assess the visibility for.

\Drupal\editor\EditorInterface $editor: A configured text editor object.

Return value

bool Whether this configurable plugin's settings form should be visible.

2 calls to CKEditor5::shouldHaveVisiblePluginSettingsForm()
CKEditor5::injectPluginSettingsForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Injects the CKEditor plugins settings forms as a vertical tabs subform.
CKEditor5::validateConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Form validation handler.

File

core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php, line 422

Class

CKEditor5
Defines a CKEditor 5-based text editor for Drupal.

Namespace

Drupal\ckeditor5\Plugin\Editor

Code

private function shouldHaveVisiblePluginSettingsForm(CKEditor5PluginDefinition $definition, EditorInterface $editor) : bool {
    assert($definition->isConfigurable());
    $enabled_plugins = $this->ckeditor5PluginManager
        ->getEnabledDefinitions($editor);
    $plugin_id = $definition->id();
    // Enabled plugins should be configurable.
    if (isset($enabled_plugins[$plugin_id])) {
        return TRUE;
    }
    // There are two circumstances where a plugin not listed in $enabled_plugins
    // due to isEnabled() returning false, that should still have its config
    // form provided:
    // 1 - A conditionally enabled plugin that does not depend on a toolbar item
    // to be active AND the plugins it depends on are enabled (if any) AND the
    // filter it depends on is enabled (if any).
    // 2 - A conditionally enabled plugin that does depend on a toolbar item,
    // and that toolbar item is active.
    if ($definition->hasConditions()) {
        $conditions = $definition->getConditions();
        if (!array_key_exists('toolbarItem', $conditions)) {
            $conclusion = TRUE;
            // The filter this plugin depends on must be enabled.
            if (array_key_exists('filter', $conditions)) {
                $required_filter = $conditions['filter'];
                $format_filters = $editor->getFilterFormat()
                    ->filters();
                $conclusion = $conclusion && $format_filters->has($required_filter) && $format_filters->get($required_filter)->status;
            }
            // The CKEditor 5 plugins this plugin depends on must be enabled.
            if (array_key_exists('plugins', $conditions)) {
                $all_plugins = $this->ckeditor5PluginManager
                    ->getDefinitions();
                $dependencies = array_intersect_key($all_plugins, array_flip($conditions['plugins']));
                $unmet_dependencies = array_diff_key($dependencies, $enabled_plugins);
                $conclusion = $conclusion && empty($unmet_dependencies);
            }
            return $conclusion;
        }
        elseif (in_array($conditions['toolbarItem'], $editor->getSettings()['toolbar']['items'], TRUE)) {
            return TRUE;
        }
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.