You are here

trait GlobalSettingsTrait in Collapsiblock 4.x

Same name and namespace in other branches
  1. 3.x tests/src/Traits/GlobalSettingsTrait.php \Drupal\Tests\collapsiblock\Traits\GlobalSettingsTrait

Simplify working with global Collapsiblock settings.

Hierarchy

2 files declare their use of GlobalSettingsTrait
CollapsiblockFunctionalTestBase.php in tests/src/Functional/CollapsiblockFunctionalTestBase.php
CollapsiblockJavaScriptTestBase.php in tests/src/FunctionalJavascript/CollapsiblockJavaScriptTestBase.php

File

tests/src/Traits/GlobalSettingsTrait.php, line 8

Namespace

Drupal\Tests\collapsiblock\Traits
View source
trait GlobalSettingsTrait {

  /**
   * Configuration accessor for tests. Returns non-overridden configuration.
   *
   * @param string $name
   *   Configuration name.
   *
   * @return \Drupal\Core\Config\Config
   *   The configuration object with original configuration data.
   */
  protected abstract function config($name);

  /**
   * Get the global Collapsiblock configuration.
   *
   * @return \Drupal\Core\Config\Config
   *   The global Collapsiblock configuration object.
   */
  protected function getCollapsiblockGlobalConfig() {
    return $this
      ->config('collapsiblock.settings');
  }

  /**
   * Get a specific Collapsiblock global setting.
   *
   * @param string $key
   *   The setting to get the value for.
   *
   * @return mixed
   *   The given setting's current configuration.
   */
  protected function getCollapsiblockGlobalSetting($key = '') {
    return $this
      ->getCollapsiblockGlobalConfig()
      ->get($key);
  }

  /**
   * Set a specific Collapsiblock global setting.
   *
   * @param mixed $newValue
   *   The configuration to set.
   * @param string $key
   *   Which setting to set.
   */
  protected function setCollapsiblockGlobalSetting($newValue, $key = '') {
    $this
      ->getCollapsiblockGlobalConfig()
      ->set($key, $newValue)
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GlobalSettingsTrait::config abstract protected function Configuration accessor for tests. Returns non-overridden configuration.
GlobalSettingsTrait::getCollapsiblockGlobalConfig protected function Get the global Collapsiblock configuration.
GlobalSettingsTrait::getCollapsiblockGlobalSetting protected function Get a specific Collapsiblock global setting.
GlobalSettingsTrait::setCollapsiblockGlobalSetting protected function Set a specific Collapsiblock global setting.