domain_microsite-1.0.0-alpha4/src/DomainMicrositeCacheContext.php

src/DomainMicrositeCacheContext.php
<?php

namespace Drupal\domain_microsite;

use Drupal\Core\Cache\Context\SiteCacheContext;
use Drupal\domain\DomainNegotiatorInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Replaces url.site cache context values with domain id.
 */
class DomainMicrositeCacheContext extends SiteCacheContext {

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * Domain negotiator.
   *
   * @var \Drupal\domain\DomainNegotiatorInterface
   */
  protected $domainNegotiator;

  /**
   * {@inheritdoc}
   */
  public function __construct(RequestStack $request_stack, DomainNegotiatorInterface $domain_negotiator) {
    $this->requestStack = $request_stack;
    $this->domainNegotiator = $domain_negotiator;
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    if ($domain = $this->domainNegotiator->getActiveDomain()) {
      return $domain->id();
    }
    else {
      return parent::getContext();
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc