Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function createNextId()
 {
     $domains = $this->loader->loadMultiple();
     $max = 0;
     foreach ($domains as $domain) {
         $domain_id = $domain->getDomainId();
         if ($domain_id > $max) {
             $max = $domain_id;
         }
     }
     return $max + 1;
 }
Exemplo n.º 2
0
 /**
  * Sets the domain context of the request.
  *
  * This method also determines the redirect status for the http request.
  *
  * Specifically, here we determine if a redirect is required. That happens
  * in one of two cases: an unauthorized request to an inactive domain is made;
  * a domain alias is set to redirect to its primary domain record.
  *
  * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The Event to process.
  */
 public function onKernelRequestDomain(GetResponseEvent $event)
 {
     $redirect = FALSE;
     // Negotiate the request and set domain context.
     if ($domain = $this->domainNegotiator->getActiveDomain(TRUE)) {
         $domain_url = $domain->getUrl();
         if ($domain_url) {
             $redirect_type = $domain->getRedirect();
             $path = trim($event->getRequest()->getPathInfo(), '/');
             // If domain negotiation asked for a redirect, issue it.
             if (!is_null($redirect_type)) {
                 $redirect = TRUE;
             } elseif ($apply = $this->accessCheck->checkPath($path)) {
                 $access = $this->accessCheck->access($this->account);
                 // If the access check fails, reroute to the default domain.
                 // Note that Allowed, Neutral, and Failed are the options here.
                 // We insist on Allowed.
                 if (!$access->isAllowed()) {
                     $default = $this->domainLoader->loadDefaultDomain();
                     $domain_url = $default->getUrl();
                     $redirect = TRUE;
                     $redirect_type = 302;
                 }
             }
         }
         if ($redirect) {
             // Pass a redirect if necessary.
             $response = new TrustedRedirectResponse($domain_url, $redirect_type);
             $event->setResponse($response);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function getAccessValues(EntityInterface $entity, $field_name = DOMAIN_ACCESS_FIELD)
 {
     // @TODO: static cache.
     $list = array();
     // @TODO In tests, $entity is returning NULL.
     if (is_null($entity)) {
         return $list;
     }
     // Get the values of an entity.
     $values = $entity->get($field_name);
     // Must be at least one item.
     if (!empty($values)) {
         foreach ($values as $item) {
             if ($target = $item->getValue()) {
                 if ($domain = $this->loader->load($target['target_id'])) {
                     $list[$domain->id()] = $domain->getDomainId();
                 }
             }
         }
     }
     return $list;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function setRequestDomain($httpHost, $reset = FALSE)
 {
     // @TODO: Investigate caching methods.
     $this->setHttpHost($httpHost);
     if ($domain = $this->domainLoader->loadByHostname($httpHost)) {
         // If the load worked, set an exact match flag for the hook.
         $domain->setMatchType(DOMAIN_MATCH_EXACT);
     } elseif ($domain = $this->domainLoader->loadDefaultDomain()) {
         $domain->setMatchType(DOMAIN_MATCH_NONE);
     } else {
         $values = array('hostname' => $httpHost);
         $domain = \Drupal::entityManager()->getStorage('domain')->create($values);
         $domain->setMatchType(DOMAIN_MATCH_NONE);
     }
     // Now check with modules (like Domain Alias) that register alternate
     // lookup systems with the main module.
     $this->moduleHandler->alter('domain_request', $domain);
     // We must have registered a valid id, else the request made no match.
     $id = $domain->id();
     if (!empty($id)) {
         $this->setActiveDomain($domain);
     }
 }