You are here

public function SystemTestController::permissionDependentContent in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php \Drupal\system_test\Controller\SystemTestController::permissionDependentContent()

Shows permission-dependent content.

Return value

array A render array.

1 string reference to 'SystemTestController::permissionDependentContent'
system_test.routing.yml in core/modules/system/tests/modules/system_test/system_test.routing.yml
core/modules/system/tests/modules/system_test/system_test.routing.yml

File

core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php, line 353

Class

SystemTestController
Controller routines for system_test routes.

Namespace

Drupal\system_test\Controller

Code

public function permissionDependentContent() {
  $build = [];

  // The content depends on the access result.
  $access = AccessResult::allowedIfHasPermission($this->currentUser, 'pet llamas');
  $this->renderer
    ->addCacheableDependency($build, $access);

  // Build the content.
  if ($access
    ->isAllowed()) {
    $build['allowed'] = [
      '#markup' => 'Permission to pet llamas: yes!',
    ];
  }
  else {
    $build['forbidden'] = [
      '#markup' => 'Permission to pet llamas: no!',
    ];
  }
  return $build;
}