You are here

class DomainConfigUIManager in Domain Access 8

Domain Config UI manager.

Hierarchy

Expanded class hierarchy of DomainConfigUIManager

3 files declare their use of DomainConfigUIManager
Config.php in domain_config_ui/src/Config/Config.php
ConfigFactory.php in domain_config_ui/src/Config/ConfigFactory.php
SwitchForm.php in domain_config_ui/src/Form/SwitchForm.php
1 string reference to 'DomainConfigUIManager'
domain_config_ui.services.yml in domain_config_ui/domain_config_ui.services.yml
domain_config_ui/domain_config_ui.services.yml
1 service uses DomainConfigUIManager
domain_config_ui.manager in domain_config_ui/domain_config_ui.services.yml
Drupal\domain_config_ui\DomainConfigUIManager

File

domain_config_ui/src/DomainConfigUIManager.php, line 10

Namespace

Drupal\domain_config_ui
View source
class DomainConfigUIManager implements DomainConfigUIManagerInterface {

  /**
   * A RequestStack instance.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * The current request.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $currentRequest;

  /**
   * Constructs DomainConfigUIManager object.
   *
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(RequestStack $request_stack) {

    // We want the currentRequest, but it is not always available.
    // https://www.drupal.org/project/domain/issues/3004243#comment-13700917
    $this->requestStack = $request_stack;
  }

  /**
   * {@inheritdoc}
   */
  public function getSelectedConfigName($name, $omit_language = FALSE) {
    if ($domain_id = $this
      ->getSelectedDomainId()) {
      $prefix = "domain.config.{$domain_id}.";
      if (!$omit_language && ($langcode = $this
        ->getSelectedLanguageId())) {
        $prefix .= "{$langcode}.";
      }
      return $prefix . $name;
    }
    return $name;
  }

  /**
   * {@inheritdoc}
   */
  public function getSelectedDomainId() {
    if (!empty($this
      ->getRequest()) && ($domain = $this->currentRequest
      ->get('domain_config_ui_domain'))) {
      return $domain;
    }
    elseif (isset($_SESSION['domain_config_ui_domain'])) {
      return $_SESSION['domain_config_ui_domain'];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getSelectedLanguageId() {
    if (!empty($this
      ->getRequest()) && ($language = $this->currentRequest
      ->get('domain_config_ui_language'))) {
      return $language;
    }
    elseif (isset($_SESSION['domain_config_ui_language'])) {
      return $_SESSION['domain_config_ui_language'];
    }
  }

  /**
   * Ensures that the currentRequest is loaded.
   *
   * @return Symfony\Component\HttpFoundation\Request|null
   *   The current request object.
   */
  private function getRequest() {
    if (!isset($this->currentRequest)) {
      $this->currentRequest = $this->requestStack
        ->getCurrentRequest();
    }
    return $this->currentRequest;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DomainConfigUIManager::$currentRequest protected property The current request.
DomainConfigUIManager::$requestStack protected property A RequestStack instance.
DomainConfigUIManager::getRequest private function Ensures that the currentRequest is loaded.
DomainConfigUIManager::getSelectedConfigName public function Get selected config name. Overrides DomainConfigUIManagerInterface::getSelectedConfigName
DomainConfigUIManager::getSelectedDomainId public function Get the selected domain ID. Overrides DomainConfigUIManagerInterface::getSelectedDomainId
DomainConfigUIManager::getSelectedLanguageId public function Get the selected language ID. Overrides DomainConfigUIManagerInterface::getSelectedLanguageId
DomainConfigUIManager::__construct public function Constructs DomainConfigUIManager object.