EntityContextDefinition
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
Creates a new context definition.
Constructs a new context definition object.
Sets the data type needed by the context.
Sets the human readable description.
Determines whether the data is multi-valued, i.e. a list of data items.
Sets whether the data is multi-valued.
Sets the array of validation constraints.
Adds a validation constraint.
Returns the data definition of the defined context.
Checks if this definition's data type matches that of the given context.
Determines if this definition is satisfied by a context object.
Returns typed data objects representing this context definition.
Extracts an array of constraints for a context definition object.
Returns the entity type ID of this context.
Creates a context definition from a given entity type ID.
Creates a context definition from a given entity type.
Details
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
$this
setTypedDataManager(TypedDataManagerInterface $typed_data_manager)
Sets the typed data manager.
TypedDataManagerInterface
getTypedDataManager()
Gets the typed data manager.
static ContextDefinition
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.
If the context is multiple-valued, this represents the type of each value.
$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.
For required data a non-NULL value is mandatory.
$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.
NOTE: This will override any previously set constraints. In most cases ContextDefinitionInterface::addConstraint() should be used instead.
$this
addConstraint(string $constraint_name, array|null $options = NULL)
Adds a validation constraint.
DataDefinitionInterface
getDataDefinition()
Returns the data definition of the defined context.
protected 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.
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.
protected string
getEntityTypeId()
Returns the entity type ID of this context.
static EntityContextDefinition
fromEntityTypeId(string $entity_type_id)
Creates a context definition from a given entity type ID.
static EntityContextDefinition
fromEntityType(EntityTypeInterface $entity_type)
Creates a context definition from a given entity type.
static EntityContextDefinition
fromEntity(EntityInterface $entity)
Creates a context definition from a given entity object.