emptySet example

    /** @var \Drupal\editor\Entity\Editor $editor */
    $editor = $text_editor !== NULL
      ? clone $text_editor
      : Editor::create([
        'format' => $text_format->id(),
        // @see \Drupal\editor\Entity\Editor::__construct()         // @see \Drupal\ckeditor5\Plugin\Editor\CKEditor5::getDefaultSettings()         'editor' => 'ckeditor5',
      ]);
    $editor->setEditor('ckeditor5');

    $source_editing_additions = HTMLRestrictions::emptySet();
    // Compute the appropriate settings based on the CKEditor 4 configuration     // if it exists.     $old_editor = $editor->id() ? Editor::load($editor->id()) : NULL;
    $old_editor_restrictions = $old_editor ? HTMLRestrictions::fromTextFormat($old_editor->getFilterFormat()) : HTMLRestrictions::emptySet();
    // @todo Remove in https://www.drupal.org/project/drupal/issues/3245351     if ($old_editor) {
      $editor->setImageUploadSettings($old_editor->getImageUploadSettings());
    }
    if ($old_editor && $old_editor->getEditor() === 'ckeditor') {
      [$upgraded_settings$messages] = $this->createSettingsFromCKEditor4($old_editor->getSettings(), HTMLRestrictions::fromTextFormat($old_editor->getFilterFormat()));
      $editor->setSettings($upgraded_settings);
      

  public static function fromTextFormat(FilterFormatInterface $text_format): HTMLRestrictions {
    return self::fromObjectWithHtmlRestrictions($text_format);
  }

  /** * Constructs an unrestricted set of HTML restrictions. * * @return \Drupal\ckeditor5\HTMLRestrictions */
  private static function unrestricted(): self {
    $restrictions = HTMLRestrictions::emptySet();
    $restrictions->unrestricted = TRUE;
    return $restrictions;
  }

  /** * Constructs a set of HTML restrictions matching the given object. * * Note: there is no interface for the ::getHTMLRestrictions() method that * both text filter plugins and the text format configuration entity type * implement. To avoid duplicating this logic, this private helper method * exists: to simplify the two public static methods that each accept one of * those two interfaces. * * @param \Drupal\filter\Plugin\FilterInterface|\Drupal\filter\FilterFormatInterface $object * A text format or filter plugin instance to construct a HTML restrictions * object for. * * @return \Drupal\ckeditor5\HTMLRestrictions * * @see ::fromFilterPluginInstance() * @see ::fromTextFormat() */
// 2. Even though `sourceEditing` may not be enabled before this update, it     // must be after, at least if image uploads are disabled: extra mark-up will     // be added to its configuration to avoid breaking backwards compatibility.     if (!$image_uploads_are_enabled) {
      if (!$source_editing_is_already_enabled) {
        $this->assertNotContains('sourceEditing', $editor_before->getSettings()['toolbar']['items']);
      }
      $this->assertContains('sourceEditing', $editor_after->getSettings()['toolbar']['items']);
      $source_editing_before = $source_editing_is_already_enabled
        ? static::getSourceEditingRestrictions($editor_before)
        : HTMLRestrictions::emptySet();
      $source_editing_after = static::getSourceEditingRestrictions($editor_after);
      if ($source_editing_is_already_enabled) {
        // Nothing has been removed from the allowed source editing tags.         $this->assertFalse($source_editing_before->allowsNothing());
        $this->assertTrue($source_editing_before->diff($source_editing_after)
          ->allowsNothing());
      }
      $this->assertSame($expected_source_editing_additions$source_editing_after->diff($source_editing_before)
        ->toCKEditor5ElementsArray());
    }
    // Otherwise verify that sourceEditing configuration remains unchanged.

  }

  /** * {@inheritdoc} */
  public function getProvidedElements(array $plugin_ids = [], EditorInterface $editor = NULL, bool $resolve_wildcards = TRUE, bool $creatable_elements_only = FALSE): array {
    $plugins = $this->getDefinitions();
    if (!empty($plugin_ids)) {
      $plugins = array_intersect_key($pluginsarray_flip($plugin_ids));
    }
    $elements = HTMLRestrictions::emptySet();

    foreach ($plugins as $id => $definition) {
      // Some CKEditor 5 plugins only provide functionality, not additional       // elements.       if (!$definition->hasElements()) {
        continue;
      }

      $defined_elements = $definition->getElements();
      if (is_a($definition->getClass(), CKEditor5PluginElementsSubsetInterface::class, TRUE)) {
        // ckeditor5_sourceEditing is the edge case here: it is the only plugin

  public function testRepresentations(HTMLRestrictions $restrictions, array $expected_elements_array, string $expected_allowed_html_string, array $expected_ghs_config): void {
    $this->assertSame($expected_elements_array$restrictions->toCKEditor5ElementsArray());
    $this->assertSame($expected_allowed_html_string$restrictions->toFilterHtmlAllowedTagsString());
    $this->assertSame($expected_ghs_config$restrictions->toGeneralHtmlSupportConfig());
  }

  public function providerRepresentations(): \Generator {
    yield 'empty set' => [
      HTMLRestrictions::emptySet(),
      [],
      '',
      [],
    ];

    yield 'only tags' => [
      new HTMLRestrictions(['a' => FALSE, 'p' => FALSE, 'br' => FALSE]),
      ['<a>', '<p>', '<br>'],
      '<a> <p> <br>',
      [
        ['name' => 'a'],
        [
'ckeditor5' => ['plugins' => []],
      ];
      foreach ($overrides as $path => $value) {
        NestedArray::setValue($annotationexplode('.', $path)$value);
      }
      $annotation_instance = new CKEditor5Plugin($annotation);
      $definition = $annotation_instance->get();
      return $definition;
    };

    yield 'Tag needed, no match due to no plugin supporting it' => [
      HTMLRestrictions::emptySet(),
      HTMLRestrictions::fromString('<foo>'),
      [
        $generate_definition('foo', ['drupal.elements' => FALSE]),
      ],
      [],
      [],
    ];

    yield 'Tag needed, single match without surplus' => [
      HTMLRestrictions::emptySet(),
      HTMLRestrictions::fromString('<foo>'),
      [
Home | Imprint | This part of the site doesn't use cookies.