CalculatedPermissionsTrait.php

Same filename and directory in other branches
  1. 11.x core/lib/Drupal/Core/Session/CalculatedPermissionsTrait.php

Namespace

Drupal\Core\Session

File

core/lib/Drupal/Core/Session/CalculatedPermissionsTrait.php

View source
<?php

namespace Drupal\Core\Session;


/**
 * Trait for \Drupal\Core\Session\CalculatedPermissionsInterface.
 */
trait CalculatedPermissionsTrait {
  
  /**
   * A list of calculated permission items, keyed by scope and identifier.
   *
   * @var array
   */
  protected array $items = [];
  
  /**
   * {@inheritdoc}
   */
  public function getItem(string $scope = AccessPolicyInterface::SCOPE_DRUPAL, string|int $identifier = AccessPolicyInterface::SCOPE_DRUPAL) : CalculatedPermissionsItemInterface|false {
    return $this->items[$scope][$identifier] ?? FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getItems() : array {
    $item_sets = [];
    foreach ($this->items as $scope_items) {
      $item_sets[] = array_values($scope_items);
    }
    return array_merge(...$item_sets);
  }
  
  /**
   * {@inheritdoc}
   */
  public function getScopes() : array {
    return array_keys($this->items);
  }
  
  /**
   * {@inheritdoc}
   */
  public function getItemsByScope(string $scope = AccessPolicyInterface::SCOPE_DRUPAL) : array {
    return isset($this->items[$scope]) ? array_values($this->items[$scope]) : [];
  }

}

Traits

Title Deprecated Summary
CalculatedPermissionsTrait Trait for \Drupal\Core\Session\CalculatedPermissionsInterface.

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