interface BlockManagerInterface implements ContextAwarePluginManagerInterface, CategorizingPluginManagerInterface, FilteredPluginManagerInterface (View source)

Provides an interface for the discovery and instantiation of block plugins.

Methods

mixed
getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

array
getDefinitions()

Gets the definition of all plugins for this type.

bool
hasDefinition(string $plugin_id)

Indicates if a specific plugin definition exists.

object
createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

object|false
getInstance(array $options)

Gets a preconfigured instance of a plugin.

array
getDefinitionsForContexts(array $contexts = [])

Determines plugins whose constraints are satisfied by a set of contexts.

string[]
getCategories()

Gets the names of all categories.

array[]
getSortedDefinitions(array $definitions = NULL)

Gets sorted plugin definitions.

array[]
getGroupedDefinitions(array $definitions = NULL)

Gets sorted plugin definitions grouped by category.

getFilteredDefinitions(string $consumer, ContextInterface[]|null $contexts = NULL, array $extra = [])

Gets the plugin definitions for a given type and consumer and filters them.

Details

mixed getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

Parameters

string $plugin_id

A plugin id.

bool $exception_on_invalid

(optional) If TRUE, an invalid plugin ID will throw an exception.

Return Value

mixed

A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is FALSE.

Exceptions

PluginNotFoundException

array getDefinitions()

Gets the definition of all plugins for this type.

Return Value

array

An array of plugin definitions (empty array if no definitions were found). Keys are plugin IDs.

See also

FilteredPluginManagerInterface::getFilteredDefinitions

bool hasDefinition(string $plugin_id)

Indicates if a specific plugin definition exists.

Parameters

string $plugin_id

A plugin ID.

Return Value

bool

TRUE if the definition exists, FALSE otherwise.

object createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

Parameters

string $plugin_id

The ID of the plugin being instantiated.

array $configuration

An array of configuration relevant to the plugin instance.

Return Value

object

A fully configured plugin instance.

Exceptions

PluginException

object|false getInstance(array $options)

Gets a preconfigured instance of a plugin.

Parameters

array $options

An array of options that can be used to determine a suitable plugin to instantiate and how to configure it.

Return Value

object|false

A fully configured plugin instance. The interface of the plugin instance will depend on the plugin type. If no instance can be retrieved, FALSE will be returned.

array getDefinitionsForContexts(array $contexts = [])

Determines plugins whose constraints are satisfied by a set of contexts.

Use context definition objects after https://www.drupal.org/node/2281635.

Parameters

array $contexts

An array of contexts.

Return Value

array

An array of plugin definitions.

See also

FilteredPluginManagerInterface::getFilteredDefinitions

string[] getCategories()

Gets the names of all categories.

Return Value

string[]

An array of translated categories, sorted alphabetically.

array[] getSortedDefinitions(array $definitions = NULL)

Gets sorted plugin definitions.

Parameters

array $definitions

(optional) The plugin definitions to sort. If omitted, all plugin definitions are used.

Return Value

array[]

An array of plugin definitions, sorted by category and label.

array[] getGroupedDefinitions(array $definitions = NULL)

Gets sorted plugin definitions grouped by category.

In addition to grouping, both categories and its entries are sorted, whereas plugin definitions are sorted by label.

Parameters

array $definitions

(optional) The plugin definitions to group. If omitted, all plugin definitions are used.

Return Value

array[]

Keys are category names, and values are arrays of which the keys are plugin IDs and the values are plugin definitions.

PluginDefinitionInterface[]|array[] getFilteredDefinitions(string $consumer, ContextInterface[]|null $contexts = NULL, array $extra = [])

Gets the plugin definitions for a given type and consumer and filters them.

This allows modules and themes to alter plugin definitions at runtime, which is useful for tasks like hiding specific plugins from a particular user interface.

Parameters

string $consumer

A string identifying the consumer of these plugin definitions.

ContextInterface[]|null $contexts

(optional) Either an array of contexts to use for filtering, or NULL to not filter by contexts.

array $extra

(optional) An associative array containing additional information provided by the code requesting the filtered definitions.

Return Value

PluginDefinitionInterface[]|array[]

An array of plugin definitions that are filtered.

See also

hook_plugin_filter_TYPE_alter()
hook_plugin_filter_TYPE__CONSUMER_alter()