class DefaultSingleLazyPluginCollection extends LazyPluginCollection (View source)

Provides a default plugin collection for a plugin type.

A plugin collection usually stores multiple plugins, and is used to lazily instantiate them. When only one plugin is needed, it is still best practice to encapsulate all of the instantiation logic in a plugin collection. This class can be used directly, or subclassed to add further exception handling in self::initializePlugin().

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $pluginInstances

Stores all instantiated plugins.

from  LazyPluginCollection
protected array $instanceIds

Stores the IDs of all potential plugin instances.

from  LazyPluginCollection
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected PluginManagerInterface $manager

The manager used to instantiate the plugins.

protected array $configuration

An array of configuration to instantiate the plugin with.

protected string $instanceId

The instance ID used for this plugin collection.

Methods

initializePlugin(string $instance_id)

Initializes and stores a plugin.

array
getConfiguration()

Gets the current configuration of all plugins in this collection.

$this
setConfiguration(array $configuration)

Sets the configuration for all plugins in this collection.

clear()

Clears all instantiated plugins.

bool
has(string $instance_id)

Determines if a plugin instance exists.

get(string $instance_id)

Gets a plugin instance, initializing it if necessary.

set(string $instance_id, mixed $value)

Stores an initialized plugin.

remove(string $instance_id)

Removes an initialized plugin.

addInstanceId(string $id, array|null $configuration = NULL)

Adds an instance ID to the available instance IDs.

array
getInstanceIds()

Gets all instance IDs.

removeInstanceId(string $instance_id)

Removes an instance ID.

getIterator()

No description

count()

{@inheritdoc}

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(PluginManagerInterface $manager, string $instance_id, array $configuration)

Constructs a new DefaultSingleLazyPluginCollection object.

Details

protected initializePlugin(string $instance_id)

Initializes and stores a plugin.

Parameters

string $instance_id

The ID of the plugin instance to initialize.

array getConfiguration()

Gets the current configuration of all plugins in this collection.

Return Value

array

An array of up-to-date plugin configuration.

$this setConfiguration(array $configuration)

Sets the configuration for all plugins in this collection.

Parameters

array $configuration

An array of up-to-date plugin configuration.

Return Value

$this

clear()

Clears all instantiated plugins.

bool has(string $instance_id)

Determines if a plugin instance exists.

Parameters

string $instance_id

The ID of the plugin instance to check.

Return Value

bool

TRUE if the plugin instance exists, FALSE otherwise.

get(string $instance_id)

Gets a plugin instance, initializing it if necessary.

Parameters

string $instance_id

The ID of the plugin instance being retrieved.

set(string $instance_id, mixed $value)

Stores an initialized plugin.

Parameters

string $instance_id

The ID of the plugin instance being stored.

mixed $value

An instantiated plugin.

remove(string $instance_id)

Removes an initialized plugin.

The plugin can still be used; it will be reinitialized.

Parameters

string $instance_id

The ID of the plugin instance to remove.

addInstanceId(string $id, array|null $configuration = NULL)

Adds an instance ID to the available instance IDs.

Parameters

string $id

The ID of the plugin instance to add.

array|null $configuration

(optional) The configuration used by this instance. Defaults to NULL.

array getInstanceIds()

Gets all instance IDs.

Return Value

array

An array of all available instance IDs.

removeInstanceId(string $instance_id)

Removes an instance ID.

Parameters

string $instance_id

The ID of the plugin instance to remove.

getIterator()

No description

count()

{@inheritdoc}

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(PluginManagerInterface $manager, string $instance_id, array $configuration)

Constructs a new DefaultSingleLazyPluginCollection object.

Parameters

PluginManagerInterface $manager

The manager to be used for instantiating plugins.

string $instance_id

The ID of the plugin instance.

array $configuration

An array of configuration.