TestContextAwareLayout.php

Same filename in other branches
  1. 10 core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Layout/TestContextAwareLayout.php
  2. 11.x core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Layout/TestContextAwareLayout.php

Namespace

Drupal\layout_builder_test\Plugin\Layout

File

core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Layout/TestContextAwareLayout.php

View source
<?php

namespace Drupal\layout_builder_test\Plugin\Layout;

use Drupal\Core\Layout\LayoutDefault;

/**
 * @Layout(
 *   id = "layout_builder_test_context_aware",
 *   label = @Translation("Layout Builder Test: Context Aware"),
 *   regions = {
 *     "main" = {
 *       "label" = @Translation("Main Region")
 *     }
 *   },
 *   context_definitions = {
 *     "user" = @ContextDefinition("entity:user")
 *   }
 * )
 */
class TestContextAwareLayout extends LayoutDefault {
    
    /**
     * {@inheritdoc}
     */
    public function build(array $regions) {
        $build = parent::build($regions);
        $build['main']['#attributes']['class'][] = 'user--' . $this->getContextValue('user')
            ->getAccountName();
        return $build;
    }

}

Classes

Title Deprecated Summary
TestContextAwareLayout Plugin annotation @Layout( id = "layout_builder_test_context_aware", label = @Translation("Layout Builder Test: Context Aware"), regions = { "main" = { "label" = @Translation("Main Region") } }, context_definitions = { …

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