interface FieldTypePluginManagerInterface implements PluginManagerInterface, CategorizingPluginManagerInterface (View source)

Defines an interface for the field type plugin manager.

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.

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.

createFieldItemList(FieldableEntityInterface $entity, string $field_name, mixed $values = NULL)

Creates a new field item list.

createFieldItem(FieldItemListInterface $items, int $index, array|null $values = NULL)

Creates a new field item as part of a field item list.

array
getDefaultFieldSettings(string $type)

Returns the default field-level settings for a field type.

array
getDefaultStorageSettings(string $type)

Returns the default storage-level settings for a field type.

array
getUiDefinitions()

Gets the definition of all field types that can be added via UI.

array
getPreconfiguredOptions(string $field_type)

Returns preconfigured field options for a field type.

string
getPluginClass(string $type)

Returns the PHP class that implements the field type plugin.

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.

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.

FieldItemListInterface createFieldItemList(FieldableEntityInterface $entity, string $field_name, mixed $values = NULL)

Creates a new field item list.

The provided entity is assigned as the parent of the created item list. However, it is the responsibility of the caller (usually the parent entity itself) to make the parent aware of the field as a new child.

Parameters

FieldableEntityInterface $entity

The entity this field item list will be part of.

string $field_name

The name of the field.

mixed $values

(optional) The data value. If set, it has to match one of the supported data type format as documented for the data type classes.

Return Value

FieldItemListInterface

The instantiated object.

FieldItemInterface createFieldItem(FieldItemListInterface $items, int $index, array|null $values = NULL)

Creates a new field item as part of a field item list.

The provided item list is assigned as the parent of the created item. It However, it is the responsibility of the caller (usually the parent list itself) to have the parent aware of the item as a new child.

Parameters

FieldItemListInterface $items

The field item list, for which to create a new item.

int $index

The list index at which the item is created.

array|null $values

(optional) The values to assign to the field item properties.

Return Value

FieldItemInterface

The instantiated object.

array getDefaultFieldSettings(string $type)

Returns the default field-level settings for a field type.

Parameters

string $type

A field type name.

Return Value

array

The field's default settings, as provided by the plugin definition, or an empty array if type or settings are undefined.

array getDefaultStorageSettings(string $type)

Returns the default storage-level settings for a field type.

Parameters

string $type

A field type name.

Return Value

array

The type's default settings, as provided by the plugin definition, or an empty array if type or settings are undefined.

array getUiDefinitions()

Gets the definition of all field types that can be added via UI.

Return Value

array

An array of field type definitions.

array getPreconfiguredOptions(string $field_type)

Returns preconfigured field options for a field type.

This is a wrapper around \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions() allowing modules to alter the result of this method by implementing hook_field_ui_preconfigured_options_alter().

Parameters

string $field_type

The field type plugin ID.

Return Value

array

A multi-dimensional array as returned from \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions().

See also

PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions
hook_field_ui_preconfigured_options_alter()

string getPluginClass(string $type)

Returns the PHP class that implements the field type plugin.

Parameters

string $type

A field type name.

Return Value

string

Field type plugin class name.

Exceptions

PluginNotFoundException