interface TypedConfigManagerInterface implements TypedDataManagerInterface (View source)

Defines an interface for managing config schema type 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.

clearCachedDefinitions()

Clears static and persistent plugin definition caches.

useCaches(bool $use_caches = FALSE)

Disable the use of caches.

create(DataDefinitionInterface $definition, mixed $value = NULL, string $name = NULL, mixed $parent = NULL)

Creates a new typed data object instance.

createDataDefinition(string $data_type)

Creates a new data definition object.

createListDataDefinition(string $item_type)

Creates a new list data definition for items of the given data type.

getPropertyInstance(TypedDataInterface $object, string $property_name, mixed $value = NULL)

Get a typed data instance for a property of a given typed data object.

ValidatorInterface
getValidator()

Gets the validator for validating typed data.

setValidator(ValidatorInterface $validator)

Sets the validator for validating typed data.

getValidationConstraintManager()

Gets the validation constraint manager.

setValidationConstraintManager(ConstraintManager $constraintManager)

Sets the validation constraint manager.

array
getDefaultConstraints(DataDefinitionInterface $definition)

Gets default constraints for the given data definition.

mixed
getCanonicalRepresentation(TypedDataInterface $data)

Gets the canonical representation of a TypedData object.

get(string $name)

Gets typed configuration data.

buildDataDefinition(array $definition, $value, string $name = NULL, object $parent = NULL)

Creates a new data definition object from a type definition array and actual configuration data. Since type definitions may contain variables to be replaced, we need the configuration value to create it.

bool
hasConfigSchema(string $name)

Checks if the configuration schema with the given config name exists.

createFromNameAndData(string $config_name, array $config_data)

Gets typed data for a given configuration name and its values.

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.

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.

clearCachedDefinitions()

Clears static and persistent plugin definition caches.

Don't resort to calling \Drupal::cache()->delete() and friends to make Drupal detect new or updated plugin definitions. Always use this method on the appropriate plugin type's plugin manager!

useCaches(bool $use_caches = FALSE)

Disable the use of caches.

Can be used to ensure that uncached plugin definitions are returned, without invalidating all cached information.

This will also remove all local/static caches.

Parameters

bool $use_caches

FALSE to not use any caches.

TypedDataInterface create(DataDefinitionInterface $definition, mixed $value = NULL, string $name = NULL, mixed $parent = NULL)

Creates a new typed data object instance.

Parameters

DataDefinitionInterface $definition

The data definition of the typed data object. For backwards-compatibility an array representation of the data definition may be passed also.

mixed $value

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

string $name

(optional) If a property or list item is to be created, the name of the property or the delta of the list item.

mixed $parent

(optional) If a property or list item is to be created, the parent typed data object implementing either the ListInterface or the ComplexDataInterface.

Return Value

TypedDataInterface

The instantiated typed data object.

See also

TypedDataManager::getPropertyInstance
BinaryData
BooleanData
Date
Duration
FloatData
IntegerData
StringData
Uri

DataDefinitionInterface createDataDefinition(string $data_type)

Creates a new data definition object.

While data definitions objects may be created directly if the definition class used by a data type is known, this method allows the creation of data definitions for any given data type.

For example, if a definition for a map is to be created, the following code could be used instead of calling this method with the argument 'map':

Parameters

string $data_type

The data type plugin ID, for which a data definition object should be created.

Return Value

DataDefinitionInterface

A data definition object for the given data type. The class of this object is provided by the definition_class in the plugin annotation.

See also

TypedDataManager::createListDataDefinition

ListDataDefinitionInterface createListDataDefinition(string $item_type)

Creates a new list data definition for items of the given data type.

Parameters

string $item_type

The item type, for which a list data definition should be created.

Return Value

ListDataDefinitionInterface

A list definition for items of the given data type.

See also

TypedDataManager::createDataDefinition

TypedDataInterface getPropertyInstance(TypedDataInterface $object, string $property_name, mixed $value = NULL)

Get a typed data instance for a property of a given typed data object.

This method will use prototyping for fast and efficient instantiation of many property objects with the same property path; for example, when multiple comments are used comment_body.0.value needs to be instantiated very often.

Prototyping is done by the root object's data type and the given property path, i.e. all property instances having the same property path and inheriting from the same data type are prototyped.

Parameters

TypedDataInterface $object

The parent typed data object, implementing the TypedDataInterface and either the ListInterface or the ComplexDataInterface.

string $property_name

The name of the property to instantiate, or the delta of a list item.

mixed $value

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

Return Value

TypedDataInterface

The new property instance.

Exceptions

InvalidArgumentException

See also

TypedDataManager::create

ValidatorInterface getValidator()

Gets the validator for validating typed data.

Return Value

ValidatorInterface

The validator object.

setValidator(ValidatorInterface $validator)

Sets the validator for validating typed data.

Parameters

ValidatorInterface $validator

The validator object to set.

ConstraintManager getValidationConstraintManager()

Gets the validation constraint manager.

Return Value

ConstraintManager

The constraint manager.

setValidationConstraintManager(ConstraintManager $constraintManager)

Sets the validation constraint manager.

The validation constraint manager is used to instantiate validation constraint plugins.

Parameters

ConstraintManager $constraintManager

The constraint manager to set.

array getDefaultConstraints(DataDefinitionInterface $definition)

Gets default constraints for the given data definition.

This generates default constraint definitions based on the data definition; for example, a NotNull constraint is generated if the data is defined as required. Besides that, any constraints defined for the data type (that is, below the 'constraint' key of the type's plugin definition) are taken into account.

Parameters

DataDefinitionInterface $definition

A data definition.

Return Value

array

An array of validation constraint definitions, keyed by constraint name. Each constraint definition can be used for instantiating \Symfony\Component\Validator\Constraint objects.

mixed getCanonicalRepresentation(TypedDataInterface $data)

Gets the canonical representation of a TypedData object.

The canonical representation is typically used when data is passed on to other code components. In many use cases, the TypedData object is mostly unified adapter wrapping a primary value (a string, an entity, etc.) which is the canonical representation that consuming code like constraint validators are really interested in. For some APIs, though, the domain object (for example, Field API's FieldItem and FieldItemList) directly implements TypedDataInterface, and the canonical representation is thus the data object itself.

When a TypedData object gets validated, for example, its canonical representation is passed on to constraint validators, which thus receive an Entity unwrapped, but a FieldItem as is.

Data types specify whether their data objects need unwrapping by using the 'unwrap_for_canonical_representation' property in the data definition (defaults to TRUE).

Parameters

TypedDataInterface $data

The data.

Return Value

mixed

The canonical representation of the passed data.

TraversableTypedDataInterface get(string $name)

Gets typed configuration data.

Parameters

string $name

Configuration object name.

Return Value

TraversableTypedDataInterface

Typed configuration element.

DataDefinitionInterface buildDataDefinition(array $definition, $value, string $name = NULL, object $parent = NULL)

Creates a new data definition object from a type definition array and actual configuration data. Since type definitions may contain variables to be replaced, we need the configuration value to create it.

Parameters

array $definition

The base type definition array, for which a data definition should be created.

$value

Optional value of the configuration element.

string $name

Optional name of the configuration element.

object $parent

Optional parent element.

Return Value

DataDefinitionInterface

A data definition for the given data type.

bool hasConfigSchema(string $name)

Checks if the configuration schema with the given config name exists.

Parameters

string $name

Configuration name.

Return Value

bool

TRUE if configuration schema exists, FALSE otherwise.

TraversableTypedDataInterface createFromNameAndData(string $config_name, array $config_data)

Gets typed data for a given configuration name and its values.

Parameters

string $config_name

The machine name of the configuration.

array $config_data

The data associated with the configuration. Note: This configuration doesn't yet have to be stored.

Return Value

TraversableTypedDataInterface

The typed configuration element.