ContextDefinition
class ContextDefinition implements ContextDefinitionInterface (View source)
Defines a class for 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. |
|
| protected string | $label | The human-readable label. |
|
| protected string|null | $description | The human-readable description. |
|
| protected bool | $isMultiple | Whether the data is multi-valued, i.e. a list of data items. |
|
| protected bool | $isRequired | Determines whether a data value is required. |
|
| protected mixed | $defaultValue | The default value. |
|
| protected array[] | $constraints | An array of constraints. |
Methods
Creates a new context definition.
Constructs a new context definition object.
Gets the data type needed by the context.
Sets the data type needed by the context.
Gets a human readable label.
Sets the human readable label.
Gets a human readable description.
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.
Determines whether the context is required.
Sets whether the data is required.
Gets the default value for this context definition.
Sets the default data value.
Gets an array of validation constraints.
Gets a validation constraint.
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.
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.