CKEditor5PluginDefinition example

/** * {@inheritdoc} */
  public function setClass($class) {
    $this->definition['drupal']['class'] = $class;
  }

  /** * {@inheritdoc} */
  public function get(): CKEditor5PluginDefinition {
    return new CKEditor5PluginDefinition($this->definition);
  }

}
if (!$definition instanceof CKEditor5PluginDefinition) {
      throw new InvalidPluginDefinitionException($plugin_idsprintf('The "%s" CKEditor 5 plugin definition must extend %s', $plugin_id, CKEditor5PluginDefinition::class));
    }

    // A derived plugin will still have the ID of the derivative, rather than     // that of the derived plugin ID (`<base plugin ID>:<derivative ID>`).     // Generate an updated CKEditor5PluginDefinition.     // @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::encodePluginId()     // @todo Remove this in https://www.drupal.org/project/drupal/issues/2458769.     $is_derived = $definition->id() !== $plugin_id;
    if ($is_derived) {
      $definition = new CKEditor5PluginDefinition(['id' => $plugin_id] + $definition->toArray());
    }

    $expected_prefix = sprintf("%s_", $definition->getProvider());
    $id = $definition->id();
    if (!str_starts_with($id$expected_prefix)) {
      throw new InvalidPluginDefinitionException($idsprintf('The "%s" CKEditor 5 plugin definition must have a plugin ID that starts with "%s".', $id$expected_prefix));
    }

    try {
      $definition->validateCKEditor5Aspects($id$definition->toArray());
      $definition->validateDrupalAspects($id$definition->toArray());
    }

function hook_ckeditor5_plugin_info_alter(array &$plugin_definitions): void {
  assert($plugin_definitions['ckeditor5_link'] instanceof CKEditor5PluginDefinition);
  $link_plugin_definition = $plugin_definitions['ckeditor5_link']->toArray();
  $link_plugin_definition['ckeditor5']['config']['link']['decorators'][] = [
    'mode' => 'manual',
    'label' => t('Open in new window'),
    'attributes' => [
      'target' => '_blank',
    ],
  ];
  $plugin_definitions['ckeditor5_link'] = new CKEditor5PluginDefinition($link_plugin_definition);
}

/** * Modify the list of available CKEditor 4 to 5 Upgrade plugins. * * This hook may be used to modify plugin properties after they have been * specified by other modules. For example, to override a default upgrade path. * * @param array $plugin_definitions * An array of all the existing plugin definitions, passed by reference. * * @see \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginManager */
<<<YAML ckeditor5_derived_plugin_foo: ckeditor5: plugins: {} drupal: elements: false deriver: Drupal\ckeditor5_derived_plugin\Plugin\CKEditor5Plugin\SimpleDeriver YAML,
      NULL,
      $simple_deriver_additional_files,
      [
        'ckeditor5_derived_plugin_foo:bar' => new CKEditor5PluginDefinition([
          'provider' => 'ckeditor5_derived_plugin',
          'id' => 'ckeditor5_derived_plugin_foo:bar',
          'ckeditor5' => ['plugins' => []] + $ckeditor5_aspects_defaults,
          'drupal' => [
            'label' => 'Foo bar',
            'elements' => FALSE,
            'deriver' => 'Drupal\ckeditor5_derived_plugin\Plugin\CKEditor5Plugin\SimpleDeriver',
          ] + $drupal_aspects_defaults,
        ]),
        'ckeditor5_derived_plugin_foo:baz' => new CKEditor5PluginDefinition([
          'provider' => 'ckeditor5_derived_plugin',
          
Home | Imprint | This part of the site doesn't use cookies.