You are here

class ErrorLevelConfigOverride in Error Level Permission 8

Hierarchy

Expanded class hierarchy of ErrorLevelConfigOverride

1 string reference to 'ErrorLevelConfigOverride'
errorlevelpermission.services.yml in ./errorlevelpermission.services.yml
errorlevelpermission.services.yml
1 service uses ErrorLevelConfigOverride
errorlevelpermission.config_override in ./errorlevelpermission.services.yml
Drupal\errorlevelpermission\ErrorLevelConfigOverride

File

src/ErrorLevelConfigOverride.php, line 9

Namespace

Drupal\errorlevelpermission
View source
class ErrorLevelConfigOverride implements ConfigFactoryOverrideInterface {

  /**
   * {@inheritdoc}
   */
  public function loadOverrides($names) {
    $overrides = [];
    if (in_array('system.logging', $names)) {
      $overrides['system.logging']['error_level'] = $this
        ->errorLevel();
    }
    return $overrides;
  }

  /**
   * Get error level value depending on user permissions.
   *
   * @return string
   *   The error level.
   */
  protected function errorLevel() {
    $currentUser = \Drupal::currentUser();
    if ($currentUser
      ->hasPermission('errorlevelpermission display verbose')) {
      return ERROR_REPORTING_DISPLAY_VERBOSE;
    }
    elseif ($currentUser
      ->hasPermission('errorlevelpermission display all')) {
      return ERROR_REPORTING_DISPLAY_ALL;
    }
    elseif ($currentUser
      ->hasPermission('errorlevelpermission display some')) {
      return ERROR_REPORTING_DISPLAY_SOME;
    }
    else {
      return ERROR_REPORTING_HIDE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheSuffix() {
    return 'errorlevelpermission';
  }

  /**
   * {@inheritdoc}
   */
  public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($name) {
    $cacheableMetadata = new CacheableMetadata();
    $cacheableMetadata
      ->addCacheContexts([
      'user.permissions',
    ]);
    return $cacheableMetadata;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ErrorLevelConfigOverride::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
ErrorLevelConfigOverride::errorLevel protected function Get error level value depending on user permissions.
ErrorLevelConfigOverride::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
ErrorLevelConfigOverride::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
ErrorLevelConfigOverride::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides