interface ContextDefinitionInterface implements ContextDefinitionInterface (View source)

Interface to define definition objects in ContextInterface via TypedData.

Methods

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.

string
getDataType()

Gets the data type needed by the context.

$this
setDataType(string $data_type)

Sets the data type needed by the context.

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.

$this
setConstraints(array $constraints)

Sets the array of validation constraints.

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

Adds a validation constraint.

array
getConstraint(string $constraint_name)

Gets a validation constraint.

getDataDefinition()

Returns the data definition of the defined context.

bool
isSatisfiedBy(ContextInterface $context)

Determines if this definition is satisfied by a context object.

Details

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

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

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.

$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

See also

\Drupal\Component\Plugin\Context\self::addConstraint()

$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

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.

DataDefinitionInterface getDataDefinition()

Returns the data definition of the defined context.

Return Value

DataDefinitionInterface

The data definition object.

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.