class LayoutBuilderIsActiveCacheContext implements CalculatedCacheContextInterface (View source)

internal  Tagged services are internal.
 

Determines whether Layout Builder is active for a given entity type or not.

Cache context ID: 'layout_builder_is_active:%entity_type_id', e.g. 'layout_builder_is_active:node' (to vary by whether custom layout overrides are allowed for the Node entity specified by the route parameter).

Properties

protected RouteMatchInterface $routeMatch

The current route match.

Methods

__construct(RouteMatchInterface $route_match)

LayoutBuilderCacheContext constructor.

static string
getLabel()

Returns the label of the cache context.

string
getContext($entity_type_id = NULL)

Returns the string representation of the cache context.

getCacheableMetadata($entity_type_id = NULL)

Gets the cacheability metadata for the context based on the parameter value.

getDisplay(string $entity_type_id)

Returns the entity view display for a given entity type and view mode.

Details

__construct(RouteMatchInterface $route_match)

LayoutBuilderCacheContext constructor.

Parameters

RouteMatchInterface $route_match

The current route match.

static string getLabel()

Returns the label of the cache context.

Return Value

string

The label of the cache context.

string getContext($entity_type_id = NULL)

Returns the string representation of the cache context.

A cache context service's name is used as a token (placeholder) cache key, and is then replaced with the string returned by this method.

Parameters

$entity_type_id

Return Value

string

The string representation of the cache context. When $parameter is NULL, a value representing all possible parameters must be generated.

Exceptions

LogicException

CacheableMetadata getCacheableMetadata($entity_type_id = NULL)

Gets the cacheability metadata for the context based on the parameter value.

There are three valid cases for the returned CacheableMetadata object:

  • An empty object means this can be optimized away safely.
  • A max-age of 0 means that this context can never be optimized away. It will never bubble up and cache tags will not be used.
  • Any non-zero max-age and cache tags will bubble up into the cache item if this is optimized away to allow for invalidation if the context value changes.

Parameters

$entity_type_id

Return Value

CacheableMetadata

A cacheable metadata object.

Exceptions

LogicException

protected LayoutEntityDisplayInterface|null getDisplay(string $entity_type_id)

Returns the entity view display for a given entity type and view mode.

Parameters

string $entity_type_id

The entity type ID.

Return Value

LayoutEntityDisplayInterface|null

The entity view display, if it exists.