function Test::controllerWithCache

Same name in other branches
  1. 9 core/modules/system/tests/modules/test_page_test/src/Controller/Test.php \Drupal\test_page_test\Controller\Test::controllerWithCache()
  2. 8.9.x core/modules/system/tests/modules/test_page_test/src/Controller/Test.php \Drupal\test_page_test\Controller\Test::controllerWithCache()
  3. 11.x core/modules/system/tests/modules/test_page_test/src/Controller/Test.php \Drupal\test_page_test\Controller\Test::controllerWithCache()

Defines a controller with a cached render array.

Return value

array A render array

1 string reference to 'Test::controllerWithCache'
test_page_test.routing.yml in core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml
core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml

File

core/modules/system/tests/modules/test_page_test/src/Controller/Test.php, line 61

Class

Test
Defines a test controller for page titles.

Namespace

Drupal\test_page_test\Controller

Code

public function controllerWithCache() {
    $build = [];
    $build['#title'] = '<span>Cached title</span>';
    $build['#cache']['keys'] = [
        'test_controller',
        'with_title',
    ];
    return $build;
}

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