class Configs in Bamboo Twig 8
Provides a 'Configs' Twig Extensions.
Hierarchy
- class \Drupal\bamboo_twig_config\TwigExtension\Configs extends \Drupal\bamboo_twig_config\TwigExtension\Twig_Extension
Expanded class hierarchy of Configs
1 string reference to 'Configs'
- bamboo_twig_config.services.yml in bamboo_twig_config/
bamboo_twig_config.services.yml - bamboo_twig_config/bamboo_twig_config.services.yml
1 service uses Configs
File
- bamboo_twig_config/
src/ TwigExtension/ Configs.php, line 12
Namespace
Drupal\bamboo_twig_config\TwigExtensionView source
class Configs extends \Twig_Extension {
/**
* Config API for storing variables that travel between instances.
*
* @var Drupal\Core\Config\ConfigFactory
*/
private $config;
/**
* State API for storing variables that shouldn't travel between instances.
*
* @var Drupal\Core\State\StateInterface
*/
private $state;
/**
* TwigExtension constructor.
*/
public function __construct(ConfigFactory $config, StateInterface $state) {
$this->config = $config;
$this->state = $state;
}
/**
* List of all Twig functions.
*/
public function getFunctions() {
return [
new \Twig_SimpleFunction('get_config', [
$this,
'getConfig',
]),
new \Twig_SimpleFunction('get_state', [
$this,
'getState',
]),
];
}
/**
* Unique identifier for this Twig extension.
*/
public function getName() {
return 'bamboo_twig.twig.configs';
}
/**
* Load given Config API configuration.
*
* @param string $key
* The key of the data to retrieve.
* @param string $name
* The name of config to retrieve.
*
* @return mixed|null
* Returns the stored value for a given key, or NULL if no value exists.
*/
public function getConfig($key, $name) {
return $this->config
->get($key)
->get($name);
}
/**
* Load given State API configuration.
*
* @param string $key
* The key of the data to retrieve.
*
* @return mixed|null
* Returns the stored value for a given key, or NULL if no value exists.
*/
public function getState($key) {
return $this->state
->get($key);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Configs:: |
private | property | Config API for storing variables that travel between instances. | |
Configs:: |
private | property | State API for storing variables that shouldn't travel between instances. | |
Configs:: |
public | function | Load given Config API configuration. | |
Configs:: |
public | function | List of all Twig functions. | |
Configs:: |
public | function | Unique identifier for this Twig extension. | |
Configs:: |
public | function | Load given State API configuration. | |
Configs:: |
public | function | TwigExtension constructor. |