You are here

class WebformThirdPartySettingsManager in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformThirdPartySettingsManager.php \Drupal\webform\WebformThirdPartySettingsManager

Webform third party settings manager.

Hierarchy

Expanded class hierarchy of WebformThirdPartySettingsManager

1 string reference to 'WebformThirdPartySettingsManager'
webform.services.yml in ./webform.services.yml
webform.services.yml
1 service uses WebformThirdPartySettingsManager
webform.third_party_settings_manager in ./webform.services.yml
Drupal\webform\WebformThirdPartySettingsManager

File

src/WebformThirdPartySettingsManager.php, line 13

Namespace

Drupal\webform
View source
class WebformThirdPartySettingsManager implements WebformThirdPartySettingsManagerInterface {
  use StringTranslationTrait;

  /**
   * The configuration object factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The path validator.
   *
   * @var \Drupal\Core\Path\PathValidatorInterface
   */
  protected $pathValidator;

  /**
   * The webform add-ons manager.
   *
   * @var \Drupal\webform\WebformAddonsManagerInterface
   */
  protected $addonsManager;

  /**
   * The Webform module's default configuration settings.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * Constructs a WebformThirdPartySettingsManager.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration object factory.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler class to use for loading includes.
   * @param \Drupal\Core\Path\PathValidatorInterface $path_validator
   *   The path validator.
   * @param \Drupal\webform\WebformAddonsManagerInterface $addons_manager
   *   The webform add-ons manager.
   */
  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();
  }

  /**
   * {@inheritdoc}
   */
  public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
    $this->moduleHandler
      ->alter($type, $data, $context1, $context2);
  }

  /**
   * Load all third party settings includes.
   *
   * @see {module}/{module}.webform.inc
   * @see {module}/webform/{module}.webform.inc
   * @see webform/webform.{module}.inc
   */
  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}");
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setThirdPartySetting($module, $key, $value) {
    $config = $this->configFactory
      ->getEditable('webform.settings');
    $config
      ->set("third_party_settings.{$module}.{$key}", $value);
    $config
      ->save();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getThirdPartySetting($module, $key, $default = NULL) {
    $value = $this->config
      ->get("third_party_settings.{$module}.{$key}");
    return isset($value) ? $value : $default;
  }

  /**
   * {@inheritdoc}
   */
  public function getThirdPartySettings($module) {
    $this->config
      ->get("third_party_settings.{$module}") ?: [];
  }

  /**
   * {@inheritdoc}
   */
  public function unsetThirdPartySetting($module, $key) {
    $config = $this->configFactory
      ->getEditable('webform.settings');
    $config
      ->clear("third_party_settings.{$module}.{$key}");

    // If the third party is no longer storing any information, completely
    // remove the array holding the settings for this module.
    if (!$config
      ->get("third_party_settings.{$module}")) {
      $config
        ->clear("third_party_settings.{$module}");
    }
    $config
      ->save();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getThirdPartyProviders() {
    $third_party_settings = $this->config
      ->get('third_party_settings') ?: [];
    return array_keys($third_party_settings);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WebformThirdPartySettingsManager::$addonsManager protected property The webform add-ons manager.
WebformThirdPartySettingsManager::$config protected property The Webform module's default configuration settings.
WebformThirdPartySettingsManager::$configFactory protected property The configuration object factory.
WebformThirdPartySettingsManager::$moduleHandler protected property The module handler service.
WebformThirdPartySettingsManager::$pathValidator protected property The path validator.
WebformThirdPartySettingsManager::alter public function Wrapper for \Drupal\Core\Extension\ModuleHandlerInterface::alter. Overrides WebformThirdPartySettingsManagerInterface::alter
WebformThirdPartySettingsManager::getThirdPartyProviders public function Gets the list of third parties that store information. Overrides ThirdPartySettingsInterface::getThirdPartyProviders
WebformThirdPartySettingsManager::getThirdPartySetting public function Gets the value of a third-party setting. Overrides ThirdPartySettingsInterface::getThirdPartySetting
WebformThirdPartySettingsManager::getThirdPartySettings public function Gets all third-party settings of a given module. Overrides ThirdPartySettingsInterface::getThirdPartySettings
WebformThirdPartySettingsManager::loadIncludes protected function Load all third party settings includes.
WebformThirdPartySettingsManager::setThirdPartySetting public function Sets the value of a third-party setting. Overrides ThirdPartySettingsInterface::setThirdPartySetting
WebformThirdPartySettingsManager::unsetThirdPartySetting public function Unsets a third-party setting. Overrides ThirdPartySettingsInterface::unsetThirdPartySetting
WebformThirdPartySettingsManager::__construct public function Constructs a WebformThirdPartySettingsManager.