TypedDataManager
class TypedDataManager extends DefaultPluginManager implements TypedDataManagerInterface (View source)
Manages data type plugins.
Traits
Provides dependency injection friendly methods for serialization.
Provides methods to use a cache backend while respecting a 'use caches' flag.
Properties
| protected DiscoveryInterface | $discovery | The object that discovers plugins managed by this manager. |
from PluginManagerBase |
| protected FactoryInterface | $factory | The object that instantiates plugins managed by this manager. |
from PluginManagerBase |
| protected MapperInterface|null | $mapper | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. |
from PluginManagerBase |
| protected array | $definitions | Cached definitions array. |
from DiscoveryCachedTrait |
| protected CacheBackendInterface | $cacheBackend | Cache backend instance. |
from UseCacheBackendTrait |
| protected bool | $useCaches | Flag whether caches should be used or skipped. |
from UseCacheBackendTrait |
| protected string | $cacheKey | The cache key. |
from DefaultPluginManager |
| protected array | $cacheTags | An array of cache tags to use for the cached definitions. |
from DefaultPluginManager |
| protected string | $alterHook | Name of the alter hook if one should be invoked. |
from DefaultPluginManager |
| protected string|bool | $subdir | The subdirectory within a namespace to look for plugins, or FALSE if the plugins are in the top level of the namespace. |
from DefaultPluginManager |
| protected ModuleHandlerInterface | $moduleHandler | The module handler to invoke the alter hook. |
from DefaultPluginManager |
| protected array | $defaults | A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. |
from DefaultPluginManager |
| protected string | $pluginDefinitionAnnotationName | The name of the annotation that contains the plugin definition. |
from DefaultPluginManager |
| protected string|null | $pluginInterface | The interface each plugin should implement. |
from DefaultPluginManager |
| protected Traversable | $namespaces | An object that implements \Traversable which contains the root paths keyed by the corresponding namespace to look for plugin implementations. |
from DefaultPluginManager |
| protected string[] | $additionalAnnotationNamespaces | Additional namespaces the annotation discovery mechanism should scan for annotation definitions. |
from DefaultPluginManager |
| 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 ValidatorInterface | $validator | The validator used for validating typed data. |
|
| protected ConstraintManager | $constraintManager | The validation constraint manager to use for instantiating constraints. |
|
| protected array | $prototypes | An array of typed data property prototypes. |
|
| protected ClassResolverInterface | $classResolver | The class resolver. |
Methods
Gets a specific plugin definition.
Creates a pre-configured instance of a plugin.
Allows plugin managers to specify custom behavior if a plugin is not found.
Gets a preconfigured instance of a plugin.
Fetches from the cache backend, respecting the use caches flag.
Stores data in the persistent cache, respecting the use caches flag.
Constructs a new TypedDataManager.
Initialize the cache backend.
Clears static and persistent plugin definition caches.
Returns the cached plugin definitions of the decorated discovery class.
Sets a cache of plugin definitions for the decorated discovery class.
Performs extra processing on plugin definitions.
Extracts the provider from a plugin definition.
Invokes the hook to alter the definitions if the alter hook is set.
Determines if the provider of a definition exists.
The cache contexts associated with this object.
Creates a new typed data object instance.
Creates a new data definition object.
Creates a new list data definition for items of the given data type.
Get a typed data instance for a property of a given typed data object.
Sets the validator for validating typed data.
Gets the validator for validating typed data.
Sets the validation constraint manager.
Gets the validation constraint manager.
Gets default constraints for the given data definition.
Gets the canonical representation of a TypedData object.
Details
abstract
getDefinitions()
{@inheritdoc}
getDefinition($plugin_id, $exception_on_invalid = TRUE)
{@inheritdoc}
protected array|null
doGetDefinition(array $definitions, string $plugin_id, bool $exception_on_invalid)
Gets a specific plugin definition.
hasDefinition($plugin_id)
{@inheritdoc}
protected DiscoveryInterface
getDiscovery()
Gets the plugin discovery.
protected FactoryInterface
getFactory()
Gets the plugin factory.
object
createInstance($data_type, array $configuration = [])
Creates a pre-configured instance of a plugin.
protected object
handlePluginNotFound(string $plugin_id, array $configuration)
Allows plugin managers to specify custom behavior if a plugin is not found.
object|false
getInstance(array $options)
Gets a preconfigured instance of a plugin.
protected object|false
cacheGet(string $cid)
Fetches from the cache backend, respecting the use caches flag.
protected
cacheSet(string $cid, mixed $data, int $expire = Cache::PERMANENT, array $tags = [])
Stores data in the persistent cache, respecting the use caches flag.
__construct(Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ClassResolverInterface $class_resolver)
Constructs a new TypedDataManager.
setCacheBackend(CacheBackendInterface $cache_backend, string $cache_key, array $cache_tags = [])
Initialize the cache backend.
Plugin definitions are cached using the provided cache backend.
protected
alterInfo(string $alter_hook)
Sets the alter hook name.
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!
protected array|null
getCachedDefinitions()
Returns the cached plugin definitions of the decorated discovery class.
protected
setCachedDefinitions(array $definitions)
Sets a cache of plugin definitions for the decorated discovery class.
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.
processDefinition($definition, $plugin_id)
Performs extra processing on plugin definitions.
By default we add defaults for the type to the definition. If a type has additional processing logic they can do that by replacing or extending the method.
protected array
findDefinitions()
Finds plugin definitions.
protected string|null
extractProviderFromDefinition(mixed $plugin_definition)
Extracts the provider from a plugin definition.
protected
alterDefinitions($definitions)
Invokes the hook to alter the definitions if the alter hook is set.
protected bool
providerExists($provider)
Determines if the provider of a definition exists.
string[]
getCacheContexts()
The cache contexts associated with this object.
These identify a specific variation/representation of the object.
Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.
string[]
getCacheTags()
The cache tags associated with this object.
When this object is modified, these cache tags will be invalidated.
int
getCacheMaxAge()
The maximum age for which this object may be cached.
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
TypedDataInterface
create(DataDefinitionInterface $definition, mixed $value = NULL, string $name = NULL, mixed $parent = NULL)
Creates a new typed data object instance.
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':
ListDataDefinitionInterface
createListDataDefinition(string $item_type)
Creates a new list data definition for items of the given data type.
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.
setValidator(ValidatorInterface $validator)
Sets the validator for validating typed data.
ValidatorInterface
getValidator()
Gets the validator for validating typed data.
setValidationConstraintManager(ConstraintManager $constraintManager)
Sets the validation constraint manager.
The validation constraint manager is used to instantiate validation constraint plugins.
ConstraintManager
getValidationConstraintManager()
Gets the validation constraint manager.
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.
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).