WebformThirdPartySettingsManager.php in Webform 8.5
File
src/WebformThirdPartySettingsManager.php
View source
<?php
namespace Drupal\webform;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class WebformThirdPartySettingsManager implements WebformThirdPartySettingsManagerInterface {
use StringTranslationTrait;
protected $configFactory;
protected $moduleHandler;
protected $pathValidator;
protected $addonsManager;
protected $config;
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, PathValidatorInterface $path_validator, WebformAddonsManagerInterface $addons_manager) {
$this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
$this->pathValidator = $path_validator;
$this->addonsManager = $addons_manager;
$this->config = $this->configFactory
->get('webform.settings');
$this
->loadIncludes();
}
public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
$this->moduleHandler
->alter($type, $data, $context1, $context2);
}
protected function loadIncludes() {
$modules = array_keys($this->moduleHandler
->getModuleList());
foreach ($modules as $module) {
$this->moduleHandler
->loadInclude($module, 'webform.inc');
$this->moduleHandler
->loadInclude($module, 'webform.inc', "webform/{$module}");
$this->moduleHandler
->loadInclude('webform', "inc", "third_party_settings/webform.{$module}");
}
}
public function setThirdPartySetting($module, $key, $value) {
$config = $this->configFactory
->getEditable('webform.settings');
$config
->set("third_party_settings.{$module}.{$key}", $value);
$config
->save();
return $this;
}
public function getThirdPartySetting($module, $key, $default = NULL) {
$value = $this->config
->get("third_party_settings.{$module}.{$key}");
return isset($value) ? $value : $default;
}
public function getThirdPartySettings($module) {
$this->config
->get("third_party_settings.{$module}") ?: [];
}
public function unsetThirdPartySetting($module, $key) {
$config = $this->configFactory
->getEditable('webform.settings');
$config
->clear("third_party_settings.{$module}.{$key}");
if (!$config
->get("third_party_settings.{$module}")) {
$config
->clear("third_party_settings.{$module}");
}
$config
->save();
return $this;
}
public function getThirdPartyProviders() {
$third_party_settings = $this->config
->get('third_party_settings') ?: [];
return array_keys($third_party_settings);
}
}