View source
<?php
namespace Drupal\rename_admin_paths;
use Drupal\Core\Config\Config as CoreConfig;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
class Config {
const CONFIG_KEY = 'rename_admin_paths.settings';
private $configFactory;
private $configEditable;
private $configImmutable;
public function __construct(ConfigFactoryInterface $configFactory) {
$this->configFactory = $configFactory;
}
private function getEditableConfig() : CoreConfig {
if (empty($this->configEditable)) {
$this->configEditable = $this->configFactory
->getEditable(self::CONFIG_KEY);
}
return $this->configEditable;
}
private function getImmutableConfig() : ImmutableConfig {
if (empty($this->configImmutable)) {
$this->configImmutable = $this->configFactory
->get(self::CONFIG_KEY);
}
return $this->configImmutable;
}
public function isPathEnabled(string $path) : bool {
return !empty($this
->getImmutableConfig()
->get(sprintf('%s_path', $path)));
}
public function getPathValue(string $path) : string {
return $this
->getImmutableConfig()
->get(sprintf('%s_path_value', $path));
}
public function setPathEnabled(string $path, string $enabled) : void {
$this
->getEditableConfig()
->set(sprintf('%s_path', $path), $enabled);
}
public function setPathValue(string $path, string $value) : void {
$this
->getEditableConfig()
->set(sprintf('%s_path_value', $path), $value);
}
public function save() : void {
$this
->getEditableConfig()
->save();
}
}