class ContextDefinition extends Plugin (View source)

Defines a context definition annotation object.

Some plugins require various data contexts in order to function. This class supports that need by allowing the contexts to be easily defined within an annotation and return a ContextDefinitionInterface implementing class.

Properties

protected ContextDefinitionInterface $definition

The ContextDefinitionInterface object.

Methods

__construct($values)

Constructs a new context definition object.

array
parse(array $values)

Parses an annotation into its definition.

from  Plugin
get()

Returns the value of an annotation.

string
getProvider()

Gets the name of the provider of the annotated class.

from  Plugin
setProvider(string $provider)

Sets the name of the provider of the annotated class.

from  Plugin
string
getId()

Gets the unique ID for this annotated class.

from  Plugin
string
getClass()

Gets the class of the annotated class.

from  Plugin
setClass(string $class)

Sets the class of the annotated class.

from  Plugin
string
getDefinitionClass(array $values)

Determines the context definition class to use.

Details

__construct($values)

Constructs a new context definition object.

Parameters

$values

Exceptions

Exception

protected array parse(array $values)

Parses an annotation into its definition.

Parameters

array $values

The annotation array.

Return Value

array

The parsed annotation as a definition.

get()

Returns the value of an annotation.

string getProvider()

Gets the name of the provider of the annotated class.

Return Value

string

setProvider(string $provider)

Sets the name of the provider of the annotated class.

Parameters

string $provider

The provider of the annotated class.

string getId()

Gets the unique ID for this annotated class.

Return Value

string

string getClass()

Gets the class of the annotated class.

Return Value

string

setClass(string $class)

Sets the class of the annotated class.

Parameters

string $class

The class of the annotated class.

protected string getDefinitionClass(array $values)

Determines the context definition class to use.

If the annotation specifies a specific context definition class, we use that. Otherwise, we use \Drupal\Core\Plugin\Context\EntityContextDefinition if the data type starts with 'entity:', since it contains specialized logic specific to entities. Otherwise, we fall back to the generic \Drupal\Core\Plugin\Context\ContextDefinition class.

Parameters

array $values

The annotation values.

Return Value

string

The fully-qualified name of the context definition class.