# PluginCollection

class

Manages a list of CKEditor plugins, including loading, resolving dependencies and initialization.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L18)

<a id="type-parameters">

## Type parameters

### `TContext`

<a id="properties">

## Properties

<a id="member-_availablePlugins">

### `_availablePlugins: Map<string, PluginConstructor<TContext>>` _(private)_

A map of plugin constructors that can be retrieved by their names.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L28)

<a id="member-_context">

### `_context: TContext` _(private)_

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L21)

<a id="member-_contextPlugins">

### `_contextPlugins: Map<PluginConstructor<TContext> | PluginInterface, PluginConstructor<TContext> | PluginInterface>` _(private)_

Map of [context plugins](module_core_contextplugin-ContextPlugin.md) which can be retrieved by their constructors or instances.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L33)

<a id="member-_plugins">

### `_plugins: Map<string | PluginConstructor<TContext>, PluginInterface>` _(private)_

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L23)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( context, availablePlugins, contextPlugins )`

Creates an instance of the plugin collection class. Allows loading and initializing plugins and their dependencies. Allows providing a list of already loaded plugins. These plugins will not be destroyed along with this collection.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L46)

#### Type parameters

* `TContext`

#### Parameters

* `context: TContext`

* `availablePlugins: Iterable<PluginConstructor<TContext>>`

  Plugins (constructors) which the collection will be able to use when [`init`](#function-init) is used with the plugin names (strings, instead of constructors). Usually, the editor will pass its built-in plugins to the collection so they can later be used in `config.plugins` or `config.removePlugins` by names.

  Defaults to `[]`

* `contextPlugins: Iterable<PluginEntry<TContext>>`

  A list of already initialized plugins represented by a `[ PluginConstructor, pluginInstance ]` pair.

  Defaults to `[]`

<a id="function-Symbol.iterator">

### `Symbol.iterator() → IterableIterator<PluginEntry<TContext>>`

Iterable interface.

Returns `[ PluginConstructor, pluginInstance ]` pairs.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L80)

#### Returns

* `IterableIterator<PluginEntry<TContext>>`

<a id="function-delegate">

### `delegate( events ) → EmitterMixinDelegateChain` _(inherited)_

Delegates selected events to another [`Emitter`](module_utils_emittermixin-Emitter.md). For instance:

```typescript
emitterA.delegate( 'eventX' ).to( emitterB );
emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
```

then `eventX` is delegated (fired by) `emitterB` and `emitterC` along with `data`:

```typescript
emitterA.fire( 'eventX', data );
```

and `eventY` is delegated (fired by) `emitterC` along with `data`:

```typescript
emitterA.fire( 'eventY', data );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L539)

#### Parameters

* `events: Array<string>`

  Event names that will be delegated to another emitter.

#### Returns

* `EmitterMixinDelegateChain`

<a id="function-destroy">

### `destroy() → Promise<unknown>`

Destroys all loaded plugins.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L583)

#### Returns

* `Promise<unknown>`

<a id="function-fire">

### `fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]` _(inherited)_

Fires an event, executing all callbacks registered for it.

The first parameter passed to callbacks is an [`EventInfo`](module_utils_eventinfo-EventInfo.md) object, followed by the optional `args` provided in the `fire()` method call.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L512)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type describing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `eventOrInfo: GetNameOrEventInfo<TEvent>`

  The name of the event or `EventInfo` object if event is delegated.

* `args: TEvent[ 'args' ]`

  Additional arguments to be passed to the callbacks.

#### Returns

* `GetEventInfo<TEvent>[ 'return' ]`

  By default the method returns `undefined`. However, the return value can be changed by listeners through modification of the [`evt.return`](module_utils_eventinfo-EventInfo.md#member-return)'s property (the event info is the first param of every callback).

<a id="function-get">

### `get( key ) → PluginsMap[ TName ]`

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L89)

#### Type parameters

* `TName: extends string`

#### Parameters

* `key: TName`

#### Returns

* `PluginsMap[ TName ]`

<a id="function-get">

### `get( key ) → InstanceType<TConstructor>`

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L88)

#### Type parameters

* `TConstructor: extends PluginClassConstructor<TContext>`

#### Parameters

* `key: TConstructor`

#### Returns

* `InstanceType<TConstructor>`

<a id="function-has">

### `has( key ) → boolean`

Checks if a plugin is loaded.

```typescript
// Check if the 'Clipboard' plugin was loaded.
if ( editor.plugins.has( 'ClipboardPipeline' ) ) {
	// Now use the clipboard plugin instance:
	const clipboard = editor.plugins.get( 'ClipboardPipeline' );

	// ...
}
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L154)

#### Parameters

* `key: string | PluginConstructor<TContext>`

  The plugin constructor or [name](module_core_plugin-PluginStaticMembers.md#member-pluginName).

#### Returns

* `boolean`

<a id="function-init">

### `init( plugins, pluginsToRemove, pluginsSubstitutions ) → Promise<LoadedPlugins>`

Initializes a set of plugins and adds them to the collection.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L174)

#### Parameters

* `plugins: readonly Array<string | PluginConstructor<TContext>>`

  An array of [plugin constructors](module_core_plugin-PluginInterface.md) or [plugin names](module_core_plugin-PluginStaticMembers.md#member-pluginName).

* `pluginsToRemove: readonly Array<string | PluginConstructor<TContext>>`

  Names of the plugins or plugin constructors that should not be loaded (despite being specified in the `plugins` array).

  Defaults to `[]`

* `pluginsSubstitutions: readonly Array<PluginConstructor<TContext>>`

  An array of [plugin constructors](module_core_plugin-PluginInterface.md) that will be used to replace plugins of the same names that were passed in `plugins` or that are in their dependency tree. A useful option for replacing built-in plugins while creating tests (for mocking their APIs). Plugins that will be replaced must follow these rules:

  * The new plugin must be a class.
  * The new plugin must be named.
  * Both plugins must not depend on other plugins.

  Defaults to `[]`

#### Returns

* `Promise<LoadedPlugins>`

  A promise which gets resolved once all plugins are loaded and available in the collection.

<a id="function-listenTo:BASE_EMITTER">

### `listenTo( emitter, event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed when an event is fired in a specific (emitter) object.

Events can be grouped in namespaces using `:`. When namespaced event is fired, it additionally fires all callbacks for that namespace.

```typescript
// myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
myEmitter.on( 'myGroup', genericCallback );
myEmitter.on( 'myGroup:myEvent', specificCallback );

// genericCallback is fired.
myEmitter.fire( 'myGroup' );
// both genericCallback and specificCallback are fired.
myEmitter.fire( 'myGroup:myEvent' );
// genericCallback is fired even though there are no callbacks for "foo".
myEmitter.fire( 'myGroup:foo' );
```

An event callback can [stop the event](module_utils_eventinfo-EventInfo.md#member-stop) and set the [return value](module_utils_eventinfo-EventInfo.md#member-return) of the [`fire`](#function-fire) method.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L475)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type describing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `emitter: Emitter`

  The object that fires the event.

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-off">

### `off( event, callback ) → void` _(inherited)_

Stops executing the callback on the given event. Shorthand for [`this.stopListening( this, event, callback )`](#function-stopListening:BASE_STOP).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L444)

#### Parameters

* `event: string`

  The name of the event.

* `callback: Function`

  The function to stop being called.

#### Returns

* `void`

<a id="function-on">

### `on( event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed when an event is fired.

Shorthand for [`this.listenTo( this, event, callback, options )`](#function-listenTo:BASE_EMITTER) (it makes the emitter listen on itself).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L416)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type descibing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-once">

### `once( event, callback, options? ) → void` _(inherited)_

Registers a callback function to be executed on the next time the event is fired only. This is similar to calling [`on`](#function-on) followed by [`off`](#function-off) in the callback.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L431)

#### Type parameters

* `TEvent: extends BaseEvent`

  The type descibing the event. See [`BaseEvent`](module_utils_emittermixin-BaseEvent.md).

#### Parameters

* `event: TEvent[ 'name' ]`

  The name of the event.

* `callback: GetCallback<TEvent>`

  The function to be called on event.

* `options?: GetCallbackOptions<TEvent>`

  Additional options.

#### Returns

* `void`

<a id="function-stopDelegating">

### `stopDelegating( event?, emitter? ) → void` _(inherited)_

Stops delegating events. It can be used at different levels:

* To stop delegating all events.
* To stop delegating a specific event to all emitters.
* To stop delegating a specific event to a specific emitter.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L552)

#### Parameters

* `event?: string`

  The name of the event to stop delegating. If omitted, stops it all delegations.

* `emitter?: Emitter`

  (requires `event`) The object to stop delegating a particular event to. If omitted, stops delegation of `event` to all emitters.

#### Returns

* `void`

<a id="function-stopListening:BASE_STOP">

### `stopListening( emitter?, event?, callback? ) → void` _(inherited)_

Stops listening for events. It can be used at different levels:

* To stop listening to a specific callback.
* To stop listening to a specific event.
* To stop listening to all events fired by a specific object.
* To stop listening to all events fired by all objects.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/emittermixin.ts#L497)

#### Parameters

* `emitter?: Emitter`

  The object to stop listening to. If omitted, stops it for all objects.

* `event?: string`

  (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it for all events from `emitter`.

* `callback?: Function`

  (Requires the `event`) The function to be removed from the call list for the given `event`.

#### Returns

* `void`

<a id="function-_add">

### `_add( PluginConstructor, plugin ) → void` _(private)_

Adds the plugin to the collection. Exposed mainly for testing purposes.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugincollection.ts#L601)

#### Parameters

* `PluginConstructor: PluginConstructor<TContext>`

  The plugin constructor.

* `plugin: PluginInterface`

  The instance of the plugin.

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
