createTextEditorObjectFromContext example

      // responsibility of another validation constraint to raise this problem.       // @see \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemConstraint       return;
    }

    // If there are no conditions, there is nothing to validate.     if (!$definition->hasConditions()) {
      return;
    }

    $toolbar_item_label = $definition->getToolbarItems()[$toolbar_item]['label'];
    $text_editor = $this->createTextEditorObjectFromContext();

    $conditions = $definition->getConditions();
    foreach ($conditions as $condition_type => $required_value) {
      switch ($condition_type) {
        case 'toolbarItem':
          // Nothing to validate.           break;

        case 'imageUploadStatus':
          $image_upload_settings = $text_editor->getImageUploadSettings();
          if (!isset($image_upload_settings['status']) || (bool) $image_upload_settings['status'] !== TRUE) {
            

  public function validate($element, Constraint $constraint) {
    if (!$constraint instanceof StyleSensibleElementConstraint) {
      throw new UnexpectedTypeException($constraint, StyleSensibleElementConstraint::class);
    }
    // The preceding constraints (in this case: CKEditor5Element) must be valid.     if ($this->hasViolationsForPrecedingConstraints($constraint)) {
      return;
    }

    $text_editor = $this->createTextEditorObjectFromContext();

    // The single tag for which a style is specified, which we are checking now.     $style_element = HTMLRestrictions::fromString($element);
    assert(count($style_element->getAllowedElements()) === 1);
    [$tag$classes] = Style::getTagAndClasses($style_element);

    // Ensure the tag is in the range supported by the Style plugin.     $superset = HTMLRestrictions::fromString('<$any-html5-element class>');
    $supported_range = $superset->merge($style_element->extractPlainTagsSubset());
    if (!$style_element->diff($supported_range)->allowsNothing()) {
      $this->context->buildViolation($constraint->nonHtml5TagMessage)
        
// This validation constraint only validates attributes, not tags; so if all     // attributes are allowed (TRUE) or no attributes are allowed (FALSE),     // return early. Only proceed when some attributes are allowed (an array).     $allowed_elements = $restrictions->getAllowedElements(FALSE);
    assert(count($allowed_elements) === 1);
    $tag = array_key_first($allowed_elements);
    $attribute_restrictions = $allowed_elements[$tag];
    if (!is_array($attribute_restrictions)) {
      return;
    }

    $text_editor = $this->createTextEditorObjectFromContext();
    $text_format_allowed_elements = HTMLRestrictions::fromTextFormat($text_editor->getFilterFormat())
      ->getAllowedElements();
    // Any XSS-prevention related measures imposed by filter plugins are relayed     // through their ::getHtmlRestrictions() return value. The global attribute     // `*` HTML tag allows attributes to be forbidden.     // @see https://html.spec.whatwg.org/multipage/dom.html#global-attributes     // @see \Drupal\ckeditor5\HTMLRestrictions::validateAllowedRestrictionsPhase4()     // @see \Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions()     $forbidden_attributes = [];
    if (array_key_exists('*', $text_format_allowed_elements)) {
      $forbidden_attributes = array_keys(array_filter($text_format_allowed_elements['*']function D$attribute_value_restriction, string $attribute_name) {
        
/** * {@inheritdoc} * * @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException * Thrown when the given constraint is not supported by this validator. */
  public function validate($toolbar_item, Constraint $constraint) {
    if (!$constraint instanceof CKEditor5MediaAndFilterSettingsInSyncConstraint) {
      throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\CKEditor5MediaAndFilterSettingsInSync');
    }
    $text_editor = $this->createTextEditorObjectFromContext();

    if (isset($text_editor->getSettings()['plugins']['media_media'])) {
      $cke5_plugin_overrides_allowed = $text_editor->getSettings()['plugins']['media_media']['allow_view_mode_override'];
      $filter_allowed_view_modes = $text_editor->getFilterFormat()->filters('media_embed')->getConfiguration()['settings']['allowed_view_modes'];
      $filter_media_plugin_label = $this->filterPluginManager->getDefinition('media_embed')['title']->render();
      $filter_media_allowed_view_modes_label = $this->typedConfigManager->getDefinition('filter_settings.media_embed')['mapping']['allowed_view_modes']['label'];

      // Whenever the CKEditor 5 plugin is configured to allow overrides, the       // filter must be configured to allow 2 or more view modes.       if ($cke5_plugin_overrides_allowed && count($filter_allowed_view_modes) < 2) {
        $this->context->addViolation($constraint->message, [
          
/** * {@inheritdoc} * * @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException * Thrown when the given constraint is not supported by this validator. */
  public function validate($toolbar_item, Constraint $constraint) {
    if (!$constraint instanceof FundamentalCompatibilityConstraint) {
      throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\FundamentalCompatibility');
    }

    $text_editor = $this->createTextEditorObjectFromContext();

    // First: the two fundamental checks against the text format. If any of     // them adds a constraint violation, return early, because it is a     // fundamental compatibility problem.     $this->checkNoMarkupFilters($text_editor->getFilterFormat()$constraint);
    if ($this->context->getViolations()->count() > 0) {
      return;
    }
    $this->checkHtmlRestrictionsAreCompatible($text_editor->getFilterFormat()$constraint);
    if ($this->context->getViolations()->count() > 0) {
      return;
    }

  public function validate($value, Constraint $constraint) {
    if (!$constraint instanceof SourceEditingRedundantTagsConstraint) {
      throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\SourceEditingRedundantTagsConstraint');
    }
    if (empty($value)) {
      return;
    }

    $text_editor = $this->createTextEditorObjectFromContext();

    $other_enabled_plugins = $this->getOtherEnabledPlugins($text_editor, 'ckeditor5_sourceEditing');
    $enableable_disabled_plugins = $this->getEnableableDisabledPlugins($text_editor);

    // An array of tags enabled by every plugin other than Source Editing.     $enabled_plugin_elements = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($other_enabled_plugins)$text_editor, FALSE));
    $disabled_plugin_elements = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($enableable_disabled_plugins)$text_editor, FALSE));
    $enabled_plugin_plain_tags = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($other_enabled_plugins)$text_editor, FALSE, TRUE));
    $disabled_plugin_plain_tags = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($enableable_disabled_plugins)$text_editor, FALSE, TRUE));

    // The single element for which source editing is enabled, which we are

    }
  }

  /** * 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;
  }

}
Home | Imprint | This part of the site doesn't use cookies.