interface VariantInterface implements PluginInspectionInterface, ConfigurableInterface, DependentPluginInterface, PluginFormInterface, RefinableCacheableDependencyInterface (View source)

Provides an interface for DisplayVariant plugins.

Methods

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

array
getConfiguration()

Gets this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

array
defaultConfiguration()

Gets default configuration for this plugin.

array
calculateDependencies()

Calculates dependencies for the configured plugin.

array
buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

string[]
getCacheContexts()

The cache contexts associated with this object.

string[]
getCacheTags()

The cache tags associated with this object.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

$this
addCacheContexts(array $cache_contexts)

Adds cache contexts.

$this
addCacheTags(array $cache_tags)

Adds cache tags.

$this
mergeCacheMaxAge(int $max_age)

Merges the maximum age (in seconds) with the existing maximum age.

$this
addCacheableDependency(CacheableDependencyInterface|object $other_object)

Adds a dependency on an object: merges its cacheability metadata.

string
label()

Returns the user-facing display variant label.

string
adminLabel()

Returns the admin-facing display variant label.

string
id()

Returns the unique ID for the display variant.

int
getWeight()

Returns the weight of the display variant.

setWeight(int $weight)

Sets the weight of the display variant.

bool
access(AccountInterface $account = NULL)

Determines if this display variant is accessible.

array
build()

Builds and returns the renderable array for the display variant.

Details

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

array getConfiguration()

Gets this plugin's configuration.

Return Value

array

An array of this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

Parameters

array $configuration

An associative array containing the plugin's configuration.

array defaultConfiguration()

Gets default configuration for this plugin.

Return Value

array

An associative array with the default configuration.

array calculateDependencies()

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code array( 'config' => array('user.role.anonymous', 'user.role.authenticated'), 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), 'module' => array('node', 'user'), 'theme' => array('seven'), ); @endcode

See also

ConfigDependencyManager
EntityInterface::getConfigDependencyName

array buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and

array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form

An associative array containing the initial structure of the plugin form.

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return Value

array

The form structure.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

See also

CacheContextsManager::convertTokensToKeys

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

$this addCacheContexts(array $cache_contexts)

Adds cache contexts.

Parameters

array $cache_contexts

The cache contexts to be added.

Return Value

$this

$this addCacheTags(array $cache_tags)

Adds cache tags.

Parameters

array $cache_tags

The cache tags to be added.

Return Value

$this

$this mergeCacheMaxAge(int $max_age)

Merges the maximum age (in seconds) with the existing maximum age.

The max age will be set to the given value if it is lower than the existing value.

Parameters

int $max_age

The max age to associate.

Return Value

$this

Exceptions

InvalidArgumentException

$this addCacheableDependency(CacheableDependencyInterface|object $other_object)

Adds a dependency on an object: merges its cacheability metadata.

Parameters

CacheableDependencyInterface|object $other_object

The dependency. If the object implements CacheableDependencyInterface, then its cacheability metadata will be used. Otherwise, the passed in object must be assumed to be uncacheable, so max-age 0 is set.

Return Value

$this

See also

CacheableMetadata::createFromObject

string label()

Returns the user-facing display variant label.

Return Value

string

The display variant label.

string adminLabel()

Returns the admin-facing display variant label.

This is for the type of display variant, not the configured variant itself.

Return Value

string

The display variant administrative label.

string id()

Returns the unique ID for the display variant.

Return Value

string

The display variant ID.

int getWeight()

Returns the weight of the display variant.

Return Value

int

The display variant weight.

setWeight(int $weight)

Sets the weight of the display variant.

Parameters

int $weight

The weight to set.

bool access(AccountInterface $account = NULL)

Determines if this display variant is accessible.

Parameters

AccountInterface $account

(optional) The user for which to check access, or NULL to check access for the current user. Defaults to NULL.

Return Value

bool

TRUE if this display variant is accessible, FALSE otherwise.

array build()

Builds and returns the renderable array for the display variant.

The variant can contain cacheability metadata for the configuration that was passed in setConfiguration(). In the build() method, this should be added to the render array that is returned.

Return Value

array

A render array for the display variant.