toGeneralHtmlSupportConfig example

    // all expected HTML elements truly are supported.     // The `ckeditor5_wildcardHtmlSupport` is automatically enabled when     // necessary, and only when necessary.     // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getEnabledDefinitions()     if (isset($definitions['ckeditor5_wildcardHtmlSupport'])) {
      $allowed_elements = new HTMLRestrictions($this->getProvidedElements(array_keys($definitions)$editor, FALSE));
      // Compute the net new elements that the wildcard tags resolve into.       $concrete_allowed_elements = $allowed_elements->getConcreteSubset();
      $net_new_elements = $allowed_elements->diff($concrete_allowed_elements);
      $config['ckeditor5_wildcardHtmlSupport'] = [
        'htmlSupport' => [
          'allow' => $net_new_elements->toGeneralHtmlSupportConfig(),
        ],
      ];
    }

    return [
      'plugins' => $this->mergeDefinitionValues('getCKEditor5Plugins', $definitions),
      'config' => NestedArray::mergeDeepArray($config),
    ];
  }

  /** * {@inheritdoc} */


  /** * @covers ::toCKEditor5ElementsArray * @covers ::toFilterHtmlAllowedTagsString * @covers ::toGeneralHtmlSupportConfig * @dataProvider providerRepresentations */
  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' => [
      
/** * {@inheritdoc} */
  public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor): array {
    $restrictions = HTMLRestrictions::fromString(implode(' ', $this->configuration['allowed_tags']));
    // Only handle concrete HTML elements to allow the Wildcard HTML support     // plugin to handle wildcards.     // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getCKEditor5PluginConfig()     $concrete_restrictions = $restrictions->getConcreteSubset();
    return [
      'htmlSupport' => [
        'allow' => $concrete_restrictions->toGeneralHtmlSupportConfig(),
        // Any manually created elements are explicitly allowed to be empty.         'allowEmpty' => array_keys($concrete_restrictions->getAllowedElements()),
      ],
    ];
  }

}

      // HTMLRestrictions does not accept a tag with an empty array, make sure       // to remove them here.       if (empty($b_without_class_wildcard[$allowedElement])) {
        unset($b_without_class_wildcard[$allowedElement]);
      }
    }
    $intersection = $a->intersect(new HTMLRestrictions($b_without_class_wildcard));

    // Leverage the "GHS configuration" representation to easily find whether     // there is an intersection for classes. Other implementations are possible.     $intersection_as_ghs_config = $intersection->toGeneralHtmlSupportConfig();
    $ghs_config_classes = array_column($intersection_as_ghs_config, 'classes');
    return !empty($ghs_config_classes);
  }

  /** * Finds the plugin with elements that conflict with the style element. * * @param \Drupal\ckeditor5\HTMLRestrictions $needle * A style definition element: a single tag, plus the 'class' attribute, * plus >=1 allowed 'class' attribute values. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The label of the plugin that is conflicting with this style. * * @throws \OutOfBoundsException * When a $needle is provided which does not exist among the other plugins. */
Home | Imprint | This part of the site doesn't use cookies.