class InstallerAccessPolicy

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Installer/InstallerAccessPolicy.php \Drupal\Core\Installer\InstallerAccessPolicy

Grants user 1 an all access pass during install.

@internal The policy is only to be used by the installer.

Hierarchy

Expanded class hierarchy of InstallerAccessPolicy

File

core/lib/Drupal/Core/Installer/InstallerAccessPolicy.php, line 16

Namespace

Drupal\Core\Installer
View source
final class InstallerAccessPolicy extends AccessPolicyBase {
    
    /**
     * {@inheritdoc}
     */
    public function calculatePermissions(AccountInterface $account, string $scope) : RefinableCalculatedPermissionsInterface {
        $calculated_permissions = parent::calculatePermissions($account, $scope);
        // Prevent the access policy from working when not in the installer.
        if ((int) $account->id() !== 1 || !InstallerKernel::installationAttempted()) {
            return $calculated_permissions;
        }
        return $calculated_permissions->addItem(new CalculatedPermissionsItem([], TRUE));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPersistentCacheContexts() : array {
        // Note that cache contexts in the installer are ignored because
        // \Drupal\Core\Installer\NormalInstallerServiceProvider::register() changes
        // everything to use a memory cache. If this was not the case, then this
        // should also return a cache context related to the return value of
        // \Drupal\Core\Installer\InstallerKernel::installationAttempted().
        return [
            'user.is_super_user',
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AccessPolicyBase::alterPermissions public function Alter the permissions after all policies have finished building them. Overrides AccessPolicyInterface::alterPermissions 2
AccessPolicyBase::applies public function Checks whether this access policy applies to a given scope. Overrides AccessPolicyInterface::applies 7
AccessPolicyInterface::SCOPE_DRUPAL constant Scope ID for general Drupal access.
InstallerAccessPolicy::calculatePermissions public function Calculates the permissions for an account within a given scope. Overrides AccessPolicyBase::calculatePermissions
InstallerAccessPolicy::getPersistentCacheContexts public function Gets the persistent cache contexts. Overrides AccessPolicyBase::getPersistentCacheContexts

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