LayoutBuilderUiCacheContext.php

Same filename in other branches
  1. 8.9.x core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php
  2. 10 core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php
  3. 11.x core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php

Namespace

Drupal\layout_builder\Cache

File

core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php

View source
<?php

namespace Drupal\layout_builder\Cache;

use Drupal\Core\Cache\Context\RouteNameCacheContext;

/**
 * Determines if an entity is being viewed in the Layout Builder UI.
 *
 * Cache context ID: 'route.name.is_layout_builder_ui'.
 *
 * @internal
 *   Tagged services are internal.
 */
class LayoutBuilderUiCacheContext extends RouteNameCacheContext {
    
    /**
     * {@inheritdoc}
     */
    public static function getLabel() {
        return t('Layout Builder user interface');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getContext() {
        $route_name = $this->routeMatch
            ->getRouteName();
        if ($route_name && str_starts_with($route_name, 'layout_builder.')) {
            return 'is_layout_builder_ui.0';
        }
        return 'is_layout_builder_ui.1';
    }

}

Classes

Title Deprecated Summary
LayoutBuilderUiCacheContext Determines if an entity is being viewed in the Layout Builder UI.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.