Drupal8Config.php in Rocket.Chat 8
File
modules/rocket_chat_api/src/RocketChat/Drupal8Config.php
View source
<?php
namespace Drupal\rocket_chat_api\RocketChat;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Drupal8Config implements RocketChatConfigInterface, ContainerInjectionInterface {
protected $config;
protected $moduleHandler;
protected $state;
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $moduleHandler, StateInterface $state) {
$this->config = $config_factory
->get('rocket_chat.settings');
$this->moduleHandler = $moduleHandler;
$this->state = $state;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('state'));
}
public function getElement($elementName, $default = NULL) {
switch ($elementName) {
case 'rocket_chat_url':
$elementName = "server";
default:
$value = $this->config
->get($elementName);
if (empty($value)) {
$value = $default;
}
return $value;
case 'rocket_chat_uid':
case 'rocket_chat_uit':
return $this->state
->get($elementName, $default);
}
}
public function setElement($elementName, $newValue) {
$config = $this->config;
switch ($elementName) {
case 'rocket_chat_url':
$elementName = "url";
default:
$config
->clear($elementName)
->set($elementName, $newValue)
->save();
break;
case 'rocket_chat_uid':
case 'rocket_chat_uit':
$this->state
->delete($elementName);
if (!empty($newValue)) {
$this->state
->set($elementName, $newValue);
}
break;
}
}
public function isDebug() {
return $this->moduleHandler
->moduleExists('devel');
}
public function getJsonDecoder() {
return '\\Drupal\\Component\\Serialization\\Json::decode';
}
public function notify($message, $type) {
return drupal_set_message($message, $type);
}
}
Classes
Name |
Description |
Drupal8Config |
Class Drupal8Config connects the API with the drupal system. |