You are here

protected function CKEditor5PluginManager::isPluginDisabled in Drupal 10

Checks whether a plugin must be disabled due to unmet conditions.

Parameters

\Drupal\ckeditor5\Plugin\CKEditor5PluginInterface $plugin: A CKEditor 5 plugin instance.

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

Return value

bool Whether the plugin is disabled due to unmet conditions.

1 call to CKEditor5PluginManager::isPluginDisabled()
CKEditor5PluginManager::getEnabledDefinitions in core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php
Filter list of definitions by enabled plugins only.

File

core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php, line 423

Class

CKEditor5PluginManager
Provides a CKEditor5 plugin manager.

Namespace

Drupal\ckeditor5\Plugin

Code

protected function isPluginDisabled(CKEditor5PluginInterface $plugin, EditorInterface $editor) : bool {
  assert($plugin
    ->getPluginDefinition()
    ->hasConditions());
  foreach ($plugin
    ->getPluginDefinition()
    ->getConditions() as $condition_type => $required_value) {
    switch ($condition_type) {
      case 'toolbarItem':
        if (!in_array($required_value, $editor
          ->getSettings()['toolbar']['items'])) {
          return TRUE;
        }
        break;
      case 'imageUploadStatus':
        $image_upload_status = $editor
          ->getImageUploadSettings()['status'] ?? FALSE;
        if (!$image_upload_status) {
          return TRUE;
        }
        break;
      case 'filter':
        $filters = $editor
          ->getFilterFormat()
          ->filters();
        assert($filters instanceof FilterPluginCollection);
        if (!$filters
          ->has($required_value) || !$filters
          ->get($required_value)->status) {
          return TRUE;
        }
        break;
      case 'requiresConfiguration':
        $intersection = array_intersect($plugin
          ->getConfiguration(), $required_value);
        return $intersection !== $required_value;
      case 'plugins':

        // Tricky: this cannot yet be evaluated here. It will evaluated later.
        // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getEnabledDefinitions()
        return FALSE;
    }
  }
  return FALSE;
}