hasConditions example

try {
      $definition = $this->findDefinitionForToolbarItem($toolbar_item);
    }
    catch (\OutOfBoundsException $e) {
      // No plugin definition found for this toolbar item. It's the       // 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.
/** * {@inheritdoc} */
  public function getEnabledDefinitions(EditorInterface $editor): array {
    $definitions = $this->getDefinitions();
    ksort($definitions);

    $definitions_with_plugins_condition = [];

    foreach ($definitions as $plugin_id => $definition) {
      // Remove definition when plugin has conditions and they are not met.       if ($definition->hasConditions()) {
        $plugin = $this->getPlugin($plugin_id$editor);
        if ($this->isPluginDisabled($plugin$editor)) {
          unset($definitions[$plugin_id]);
        }
        else {
          // The `plugins` condition can only be evaluated at the end of           // gathering enabled definitions. ::isPluginDisabled() did not yet           // evaluate that condition.           if (array_key_exists('plugins', $definition->getConditions())) {
            $definitions_with_plugins_condition[$plugin_id] = $definition;
          }
        }

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

  /** * Whether this plugin has conditions. * * @return bool * * @see \Drupal\ckeditor5\Annotation\DrupalAspectsOfCKEditor5Plugin::$conditions */

  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)) {
                
$this->pluginManager->getDefinitions(),
      $this->pluginManager->getEnabledDefinitions($text_editor)
    );
    // Only consider plugins that can be explicitly enabled by the user: plugins     // that have a toolbar item and do not have conditions. Those are the only     // plugins that are truly available for the site builder to enable without     // other consequences.     // In the future, we may choose to expand this, but it will require complex     // infrastructure to generate messages that explain which of the conditions     // are already fulfilled and which are not.     $enableable_disabled_plugins = array_filter($disabled_pluginsfunction DCKEditor5PluginDefinition $definition) {
      return $definition->hasToolbarItems() && !$definition->hasConditions();
    });
    return $enableable_disabled_plugins;
  }

}
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:     // 1 - A conditionally enabled plugin that does not depend on a toolbar item     // to be active AND the plugins it depends on are enabled (if any) AND the     // filter it depends on is enabled (if any).     // 2 - A conditionally enabled plugin that does depend on a toolbar item,     // and that toolbar item is active.     if ($definition->hasConditions()) {
      $conditions = $definition->getConditions();
      if (!array_key_exists('toolbarItem', $conditions)) {
        $conclusion = TRUE;
        // The filter this plugin depends on must be enabled.         if (array_key_exists('filter', $conditions)) {
          $required_filter = $conditions['filter'];
          $format_filters = $editor->getFilterFormat()->filters();
          $conclusion = $conclusion && $format_filters->has($required_filter) && $format_filters->get($required_filter)->status;
        }
        // The CKEditor 5 plugins this plugin depends on must be enabled.         if (array_key_exists('plugins', $conditions)) {
          
Home | Imprint | This part of the site doesn't use cookies.