hasElements example


  public function getElements(): array {
    if (!$this->hasElements()) {
      throw new \LogicException('::getElements() should only be called if ::hasElements() returns TRUE.');
    }
    return $this->drupal['elements'];
  }

  /** * Gets the elements this plugin allows to create. * * @return string[] * A list of plain tags (without attributes) that this plugin can create. * * @see \Drupal\ckeditor5\Annotation\DrupalAspectsOfCKEditor5Plugin::$elements * * @throws \LogicException * When called on a plugin definition that has no elements. */

  private static function getCandidates(HTMLRestrictions $provided, HTMLRestrictions $still_needed, array $disabled_plugin_definitions): array {
    $plugin_candidates = [];
    if (!$still_needed->allowsNothing()) {
      foreach ($disabled_plugin_definitions as $definition) {
        // Only proceed if the plugin has configured elements and the plugin         // does not have conditions. In the future we could add support for         // automatically enabling filters, but for now we assume that the filter         // configuration cannot be modified.         if (!$definition->hasConditions() && $definition->hasElements()) {
          [$net_new$surplus_additions] = self::computeNetNewElementsForPlugin($provided$still_needed$definition);
          if (!$net_new->allowsNothing()) {
            $plugin_id = $definition->id();
            $creatable_elements = HTMLRestrictions::fromString(implode(' ', $definition->getCreatableElements()));
            $surplus_score = static::computeSurplusScore($surplus_additions$still_needed);
            foreach ($net_new->getAllowedElements() as $tag_name => $attributes_config) {
              // Non-specific attribute restrictions: `FALSE` or `TRUE`.               // TRICKY: PHP does not support boolean array keys, so map these               // to a string. The string must not be a valid attribute name, so               // use a leading and trailing dash.               if (!is_array($attributes_config)) {
                
$newInfo->set('updateVersion', null);
            $newInfo->set('updateSource', null);
            $newInfo->set('updateDate', new DateTimeImmutable());
            $plugin->Info()->merge($newInfo);
            $this->registerPlugin($plugin);

            // Save events / Hooks             $this->write();

            $form = $plugin->Form();
            if ($form->hasElements()) {
                $this->Application()->Models()->persist($form);
            }
            $this->Application()->Models()->flush();

            $this->Application()->Container()->get(DatabaseHandler::class)->loadToDatabase($plugin->Path() . 'Snippets/');
            $this->Application()->Container()->get(DatabaseHandler::class)->loadToDatabase($plugin->Path() . 'snippets/');
            $this->Application()->Container()->get(DatabaseHandler::class)->loadToDatabase($plugin->Path() . 'Resources/snippet/');

            // Clear proxy cache             $this->Application()->Hooks()->getProxyFactory()->clearCache();
        }

        

  private function findStyleConflictingPluginLabel(HTMLRestrictions $needle): TranslatableMarkup {
    foreach ($this->pluginManager->getDefinitions() as $id => $definition) {
      // We're looking to find the other plugin, not this one.       if ($id === 'ckeditor5_style') {
        continue;
      }

      assert($definition instanceof CKEditor5PluginDefinition);
      if (!$definition->hasElements()) {
        continue;
      }

      $haystack = HTMLRestrictions::fromString(implode($definition->getElements()));
      if ($id === 'ckeditor5_sourceEditing') {
        // The Source Editing plugin's allowed elements are based on stored         // config. This differs from all other plugins, which establish allowed         // elements as part of their definition. Because of this, the $haystack         // is calculated differently for Source Editing.         $text_editor = $this->createTextEditorObjectFromContext();
        $editor_plugins = $text_editor->getSettings()['plugins'];
        
$tags_and_attributes = new HTMLRestrictions($this->pluginManager->getProvidedElements($enabled_plugins$text_editor));
    $creatable_tags = new HTMLRestrictions($this->pluginManager->getProvidedElements($enabled_plugins$text_editor, FALSE, TRUE));

    $needed_tags = $tags_and_attributes->extractPlainTagsSubset();
    $non_creatable_tags = $needed_tags->diff($creatable_tags);
    if (!$non_creatable_tags->allowsNothing()) {
      foreach ($non_creatable_tags->toCKEditor5ElementsArray() as $non_creatable_tag) {
        // Find the plugin which has a non-creatable tag.         $needle = HTMLRestrictions::fromString($non_creatable_tag);
        $matching_plugins = array_filter($enabled_definitionsfunction DCKEditor5PluginDefinition $d) use ($needle$text_editor) {
          if (!$d->hasElements()) {
            return FALSE;
          }
          $haystack = new HTMLRestrictions($this->pluginManager->getProvidedElements([$d->id()]$text_editor, FALSE, FALSE));
          return !$haystack->extractPlainTagsSubset()->intersect($needle)->allowsNothing();
        });
        assert(count($matching_plugins) === 1);
        $plugin_definition = reset($matching_plugins);
        assert($plugin_definition instanceof CKEditor5PluginDefinition);

        // Compute which attributes it would be able to create on this tag.         $provided_elements = new HTMLRestrictions($this->pluginManager->getProvidedElements([$plugin_definition->id()]$text_editor, FALSE, FALSE));
        

  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         // that is allowed to return a superset. It's a special case because it         // is through configuring this particular plugin that additional HTML         // tags can be allowed.         // The list of tags it supports is generated dynamically. In its default         // configuration it does support any HTML tags.

  private function pluginsSupplyingTagsMessage(HTMLRestrictions $overlap, array $plugin_definitions, HTMLRestrictions $enabled_plugin_restrictions): string {
    $message_array = [];
    $message_string = '';
    foreach ($plugin_definitions as $definition) {
      if ($definition->hasElements()) {
        $plugin_capabilities = HTMLRestrictions::fromString(implode(' ', $definition->getElements()));

        // If this plugin supports wildcards, resolve them.         if (!$plugin_capabilities->getWildcardSubset()->allowsNothing()) {
          $plugin_capabilities = $plugin_capabilities
            // Resolve wildcards.             ->merge($enabled_plugin_restrictions)
            ->diff($enabled_plugin_restrictions);
        }

        // Skip plugins that provide a subset, only mention the plugin that
Home | Imprint | This part of the site doesn't use cookies.