getEnabledDefinitions example

 $filters->get($required_value)->getLabel()
              : $required_value;
            $this->context->buildViolation($constraint->filterRequiredMessage)
              ->setParameter('%toolbar_item', (string) $toolbar_item_label)
              ->setParameter('%filter', (string) $filter_label)
              ->setInvalidValue($toolbar_item)
              ->addViolation();
          }
          break;

        case 'plugins':
          $enabled_definitions = $this->pluginManager->getEnabledDefinitions($text_editor);
          if (!array_key_exists($definition->id()$enabled_definitions)) {
            $required_plugin_ids = $definition->getConditions()['plugins'];
            $missing_plugin_ids = array_diff($required_plugin_idsarray_keys($enabled_definitions));
            $all_plugins = $this->pluginManager->getDefinitions();
            $missing_plugin_labels = array_map(function Dstring $plugin_id) use ($all_plugins): TranslatableMarkup {
              return !array_key_exists($plugin_id$all_plugins)
                ? $plugin_id
                : $all_plugins[$plugin_id]->label();
            }$missing_plugin_ids);
            if (count($missing_plugin_ids) === 1) {
              $message = $constraint->singleMissingRequiredPluginMessage;
              

  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:
    $this->addDefaultSettingsForEnabledConfigurablePlugins($editor);
    $this->computeSubsetSettingForEnabledPluginsWithSubsets($editor$text_format);

    // In CKEditor 4, it's possible for settings to exist for plugins that are     // not actually enabled. During the upgrade path, these would then be mapped     // to equivalent CKEditor 5 configuration. But CKEditor 5 does not allow     // configuration to be stored for disabled plugins. Therefore determine     // which plugins actually are enabled, and omit the (upgraded) plugin     // configuration for disabled plugins.     // @see \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface::mapCKEditor4SettingsToCKEditor5Configuration()     if ($old_editor && $old_editor->getEditor() === 'ckeditor') {
      $enabled_definitions = $this->pluginManager->getEnabledDefinitions($editor);
      $enabled_configurable_definitions = array_filter($enabled_definitionsfunction DCKEditor5PluginDefinition $definition): bool {
        return is_a($definition->getClass(), CKEditor5PluginConfigurableInterface::class, TRUE);
      });
      $settings = $editor->getSettings();
      $settings['plugins'] = array_intersect_key($settings['plugins']$enabled_configurable_definitions);
      $editor->setSettings($settings);
    }

    if ($has_html_restrictions) {
      // Determine what tags/attributes are allowed in this text format that were       // not allowed previous to the switch.
    // have been checked above; whatever remains is expected.     if (isset($violations[''])) {
      unset($violations['']);
    }
    $this->assertSame([]$violations);

    // If the text format has HTML restrictions, ensure that a strict superset     // is allowed after switching to CKEditor 5.     $html_restrictions = $text_format->getHtmlRestrictions();
    if (is_array($html_restrictions) && array_key_exists('allowed', $html_restrictions)) {
      $allowed_tags = HTMLRestrictions::fromTextFormat($text_format);
      $enabled_plugins = array_keys($this->manager->getEnabledDefinitions($updated_text_editor));
      $updated_allowed_tags = new HTMLRestrictions($this->manager->getProvidedElements($enabled_plugins$updated_text_editor));
      $unsupported_tags_attributes = $allowed_tags->diff($updated_allowed_tags);
      $superset_tags_attributes = $updated_allowed_tags->diff($allowed_tags);
      $this->assertSame($expected_superset$superset_tags_attributes->toFilterHtmlAllowedTagsString());
      $this->assertTrue($unsupported_tags_attributes->allowsNothing(), "The following tags/attributes are not allowed in the updated text format:" . implode(' ', $unsupported_tags_attributes->toCKEditor5ElementsArray()));

      // Update the text format like ckeditor5_form_filter_format_form_alter()       // would.       $updated_text_format = clone $text_format;
      $filter_html_config = $text_format->filters('filter_html')->getConfiguration();
      $filter_html_config['settings']['allowed_html'] = $updated_allowed_tags->toFilterHtmlAllowedTagsString();
      

    ];
  }

  /** * Tests the enabling of plugins. */
  public function testEnabledPlugins() {
    $editor = Editor::load('basic_html');

    // Case 1: no extra CKEditor 5 plugins.     $definitions = array_keys($this->manager->getEnabledDefinitions($editor));
    $default_plugins = [
      'ckeditor5_autoformat',
      'ckeditor5_bold',
      'ckeditor5_emphasis',
      'ckeditor5_essentials',
      'ckeditor5_globalAttributeDir',
      'ckeditor5_globalAttributeLang',
      'ckeditor5_heading',
      'ckeditor5_paragraph',
      'ckeditor5_pasteFromOffice',
    ];
    

  }

  /** * Gets all configurable CKEditor 5 plugin definitions that are enabled. * * @return \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition[] * An array of enabled configurable CKEditor 5 plugin definitions. */
  private function getConfigurableEnabledDefinitions(): array {
    $text_editor = $this->createTextEditorObjectFromContext();
    $enabled_definitions = $this->pluginManager->getEnabledDefinitions($text_editor);
    $configurable_enabled_definitions = array_filter($enabled_definitionsfunction DCKEditor5PluginDefinition $definition): bool {
      return $definition->isConfigurable();
    });

    return $configurable_enabled_definitions;
  }

}
public function getAdminLibraries(): array {
    $list = $this->mergeDefinitionValues('getAdminLibrary', $this->getDefinitions());
    // Include main admin library.     array_unshift($list, 'ckeditor5/internal.admin');
    return $list;
  }

  /** * {@inheritdoc} */
  public function getEnabledLibraries(EditorInterface $editor): array {
    $list = $this->mergeDefinitionValues('getLibrary', $this->getEnabledDefinitions($editor));
    $list = array_unique($list);
    // Include main library.     array_unshift($list, 'ckeditor5/internal.drupal.ckeditor5');
    sort($list);
    return $list;
  }

  /** * {@inheritdoc} */
  public function getEnabledDefinitions(EditorInterface $editor): array {
    

  private function checkHtmlRestrictionsMatch(EditorInterface $text_editor, FundamentalCompatibilityConstraint $constraint): void {
    $html_restrictor_filters = static::getFiltersInFormatOfType(
      $text_editor->getFilterFormat(),
      FilterInterface::TYPE_HTML_RESTRICTOR
    );

    $enabled_plugins = array_keys($this->pluginManager->getEnabledDefinitions($text_editor));
    $provided_elements = $this->pluginManager->getProvidedElements($enabled_plugins$text_editor);
    $provided = new HTMLRestrictions($provided_elements);

    foreach ($html_restrictor_filters as $filter_plugin_id => $filter) {
      $allowed = HTMLRestrictions::fromFilterPluginInstance($filter);
      $diff_allowed = $allowed->diff($provided);
      $diff_elements = $provided->diff($allowed);

      if (!$diff_allowed->allowsNothing()) {
        $this->context->buildViolation($constraint->notSupportedElementsMessage)
          ->setParameter('@list', implode(' ', $provided->toCKEditor5ElementsArray()))
          

  private function getOtherEnabledPlugins(EditorInterface $text_editor, string $except): array {
    $enabled_plugins = $this->pluginManager->getEnabledDefinitions($text_editor);
    unset($enabled_plugins[$except]);
    return $enabled_plugins;
  }

  /** * Gets all disabled CKEditor 5 plugin definitions the user can enable. * * @param \Drupal\editor\EditorInterface $text_editor * A Text Editor config entity configured to use CKEditor 5. * * @return \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition[] * A list of CKEditor 5 plugin definitions keyed by plugin ID. */
Home | Imprint | This part of the site doesn't use cookies.