class EntityContextDefinition extends ContextDefinition (View source)

Defines a class to provide entity context definitions.

Traits

Provides dependency injection friendly methods for serialization.

Wrapper methods for classes that needs typed data manager object.

Properties

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 TypedDataManagerInterface $typedDataManager

The typed data manager used for creating the data types.

from  TypedDataTrait
protected string $dataType

The data type of the data.

from  ContextDefinition
protected string $label

The human-readable label.

from  ContextDefinition
protected string|null $description

The human-readable description.

from  ContextDefinition
protected bool $isMultiple

Whether the data is multi-valued, i.e. a list of data items.

from  ContextDefinition
protected bool $isRequired

Determines whether a data value is required.

from  ContextDefinition
protected mixed $defaultValue

The default value.

from  ContextDefinition
protected array[] $constraints

An array of constraints.

from  ContextDefinition

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

$this
setTypedDataManager(TypedDataManagerInterface $typed_data_manager)

Sets the typed data manager.

getTypedDataManager()

Gets the typed data manager.

create(string $data_type = 'any')

Creates a new context definition.

__construct(string $data_type = 'any', string|null $label = NULL, bool $required = TRUE, bool $multiple = FALSE, string|null $description = NULL, mixed $default_value = NULL)

Constructs a new context definition object.

string
getDataType()

Gets the data type needed by the context.

$this
setDataType(string $data_type)

Sets the data type needed by the context.

string
getLabel()

Gets a human readable label.

$this
setLabel(string $label)

Sets the human readable label.

string|null
getDescription()

Gets a human readable description.

$this
setDescription(string|null $description)

Sets the human readable description.

bool
isMultiple()

Determines whether the data is multi-valued, i.e. a list of data items.

$this
setMultiple(bool $multiple = TRUE)

Sets whether the data is multi-valued.

bool
isRequired()

Determines whether the context is required.

$this
setRequired(bool $required = TRUE)

Sets whether the data is required.

mixed
getDefaultValue()

Gets the default value for this context definition.

$this
setDefaultValue(mixed $default_value)

Sets the default data value.

array
getConstraints()

Gets an array of validation constraints.

array
getConstraint(string $constraint_name)

Gets a validation constraint.

$this
setConstraints(array $constraints)

Sets the array of validation constraints.

$this
addConstraint(string $constraint_name, array|null $options = NULL)

Adds a validation constraint.

getDataDefinition()

Returns the data definition of the defined context.

bool
dataTypeMatches(ContextInterface $context)

Checks if this definition's data type matches that of the given context.

bool
isSatisfiedBy(ContextInterface $context)

Determines if this definition is satisfied by a context object.

getSampleValues()

Returns typed data objects representing this context definition.

Constraint[]
getConstraintObjects()

Extracts an array of constraints for a context definition object.

string
getEntityTypeId()

Returns the entity type ID of this context.

fromEntityTypeId(string $entity_type_id)

Creates a context definition from a given entity type ID.

fromEntityType(EntityTypeInterface $entity_type)

Creates a context definition from a given entity type.

fromEntity(EntityInterface $entity)

Creates a context definition from a given entity object.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

$this setTypedDataManager(TypedDataManagerInterface $typed_data_manager)

Sets the typed data manager.

Parameters

TypedDataManagerInterface $typed_data_manager

The typed data manager.

Return Value

$this

TypedDataManagerInterface getTypedDataManager()

Gets the typed data manager.

Return Value

TypedDataManagerInterface

The typed data manager.

static ContextDefinition create(string $data_type = 'any')

Creates a new context definition.

Parameters

string $data_type

The data type for which to create the context definition. Defaults to 'any'.

Return Value

ContextDefinition

The created context definition object.

__construct(string $data_type = 'any', string|null $label = NULL, bool $required = TRUE, bool $multiple = FALSE, string|null $description = NULL, mixed $default_value = NULL)

Constructs a new context definition object.

Parameters

string $data_type

The required data type.

string|null $label

The label of this context definition for the UI.

bool $required

Whether the context definition is required.

bool $multiple

Whether the context definition is multivalue.

string|null $description

The description of this context definition for the UI.

mixed $default_value

The default value of this definition.

string getDataType()

Gets the data type needed by the context.

If the context is multiple-valued, this represents the type of each value.

Return Value

string

The data type.

$this setDataType(string $data_type)

Sets the data type needed by the context.

Parameters

string $data_type

The data type to set.

Return Value

$this

string getLabel()

Gets a human readable label.

Return Value

string

The label.

$this setLabel(string $label)

Sets the human readable label.

Parameters

string $label

The label to set.

Return Value

$this

string|null getDescription()

Gets a human readable description.

Return Value

string|null

The description, or NULL if no description is available.

$this setDescription(string|null $description)

Sets the human readable description.

Parameters

string|null $description

The description to set.

Return Value

$this

bool isMultiple()

Determines whether the data is multi-valued, i.e. a list of data items.

Return Value

bool

Whether the data is multi-valued; i.e. a list of data items.

$this setMultiple(bool $multiple = TRUE)

Sets whether the data is multi-valued.

Parameters

bool $multiple

(optional) Whether the data is multi-valued. Defaults to TRUE.

Return Value

$this

bool isRequired()

Determines whether the context is required.

For required data a non-NULL value is mandatory.

Return Value

bool

Whether a data value is required.

$this setRequired(bool $required = TRUE)

Sets whether the data is required.

Parameters

bool $required

(optional) Whether the data is multi-valued. Defaults to TRUE.

Return Value

$this

mixed getDefaultValue()

Gets the default value for this context definition.

Return Value

mixed

The default value or NULL if no default value is set.

$this setDefaultValue(mixed $default_value)

Sets the default data value.

Parameters

mixed $default_value

The default value to be set or NULL to remove any default value.

Return Value

$this

array getConstraints()

Gets an array of validation constraints.

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.

array getConstraint(string $constraint_name)

Gets a validation constraint.

Parameters

string $constraint_name

The name of the constraint, i.e. its plugin id.

Return Value

array

A validation constraint definition which can be used for instantiating a \Symfony\Component\Validator\Constraint object.

$this setConstraints(array $constraints)

Sets the array of validation constraints.

NOTE: This will override any previously set constraints. In most cases ContextDefinitionInterface::addConstraint() should be used instead.

Parameters

array $constraints

The array of constraints.

Return Value

$this

$this addConstraint(string $constraint_name, array|null $options = NULL)

Adds a validation constraint.

Parameters

string $constraint_name

The name of the constraint to add, i.e. its plugin id.

array|null $options

The constraint options as required by the constraint plugin, or NULL.

Return Value

$this

DataDefinitionInterface getDataDefinition()

Returns the data definition of the defined context.

Return Value

DataDefinitionInterface

The data definition object.

protected bool dataTypeMatches(ContextInterface $context)

Checks if this definition's data type matches that of the given context.

Parameters

ContextInterface $context

The context to test against.

Return Value

bool

TRUE if the data types match, otherwise FALSE.

bool isSatisfiedBy(ContextInterface $context)

Determines if this definition is satisfied by a context object.

Parameters

ContextInterface $context

The context object.

Return Value

bool

TRUE if this definition is satisfiable by the context object, FALSE otherwise.

protected getSampleValues()

Returns typed data objects representing this context definition.

This should return as many objects as needed to reflect the variations of the constraints it supports.

protected Constraint[] getConstraintObjects()

Extracts an array of constraints for a context definition object.

Return Value

Constraint[]

A list of applied constraints for the context definition.

protected string getEntityTypeId()

Returns the entity type ID of this context.

Return Value

string

The entity type ID.

static EntityContextDefinition fromEntityTypeId(string $entity_type_id)

Creates a context definition from a given entity type ID.

Parameters

string $entity_type_id

The entity type ID from which to derive a context definition.

Return Value

EntityContextDefinition

static EntityContextDefinition fromEntityType(EntityTypeInterface $entity_type)

Creates a context definition from a given entity type.

Parameters

EntityTypeInterface $entity_type

The entity type from which to derive a context definition.

Return Value

EntityContextDefinition

static EntityContextDefinition fromEntity(EntityInterface $entity)

Creates a context definition from a given entity object.

Parameters

EntityInterface $entity

The entity from which to derive a context definition.

Return Value

EntityContextDefinition