/** * Provides the domain alias submission form. * * @param \Drupal\domain\DomainInterface $domain * An domain record entity. * * @return array * Returns the domain alias submission form. */ public function addAlias(DomainInterface $domain) { // The entire purpose of this controller is to add the values from // the parent domain entity. $values['domain_id'] = $domain->id(); // @TODO: ensure that this value is present in all cases. $alias = \Drupal::entityTypeManager()->getStorage('domain_alias')->create($values); return $this->entityFormBuilder()->getForm($alias); }
/** * Creates an alias for testing. * * @param Drupal\domain\Entity\Domain $domain * A domain entity. * @param string $pattern * An optional alias pattern. * @param int $redirect * An optional redirect (301 or 302). * * @return Drupal\domain_alias\Entity\DomainAlias * A domain alias entity. */ public function domainAliasCreateTestAlias(DomainInterface $domain, $pattern = NULL, $redirect = 0) { if (empty($pattern)) { $pattern = '*.' . $domain->getHostname(); } $values = array('domain_id' => $domain->id(), 'pattern' => $pattern, 'redirect' => $redirect); // Replicate the logic for creating machine_name patterns. $values['id'] = str_replace(array('*', '.'), '_', $values['pattern']); $alias = \Drupal::entityManager()->getStorage('domain_alias')->create($values); $alias->save(); return $alias; }
/** * Handles AJAX operations from the overview form. * * @param \Drupal\domain\DomainInterface * A domain record object. * @param $op * The operation being performed, either 'default' to make the domain record * the default, 'enable' to enable the domain record, or 'disable' to * disable the domain record. * * Note: The delete action is handled by the entity form system. * * @return \Symfony\Component\HttpFoundation\RedirectResponse * A redirect response to redirect back to the domain record list. * Supported by the UrlGeneratorTrait. * * @see \Drupal\domain\DomainListBuilder */ public function ajaxOperation(DomainInterface $domain, $op = NULL) { $success = FALSE; switch ($op) { case 'default': $domain->saveDefault(); $message = $this->t('Domain record set as default'); if ($domain->isDefault()) { $success = TRUE; } break; case 'enable': $domain->enable(); $message = $this->t('Domain record has been enabled.'); if ($domain->status()) { $success = TRUE; } break; case 'disable': $domain->disable(); $message = $this->t('Domain record has been disabled.'); if (!$domain->status()) { $success = TRUE; } break; } // Set a message. if ($success) { drupal_set_message($message); } else { drupal_set_message($this->t('The operation failed.')); } // Return to the invoking page. return $this->redirect('domain.admin'); }
/** * {@inheritdoc} */ public function execute(DomainInterface $domain = NULL) { $domain->disable(); }
/** * {@inheritdoc} */ public function execute(DomainInterface $domain = NULL) { $domain->saveDefault(); }
/** * {@inheritdoc} */ public function getActiveId() { return $this->domain->id(); }
/** * Login a user on a specific domain. * * @param Drupal\domain\DomainInterface $domain * The domain to log the user into. * @param Drupal\Core\Session\AccountInterface $account * The user account to login. */ public function domainLogin(DomainInterface $domain, AccountInterface $account) { if ($this->loggedInUser) { $this->drupalLogout(); } // For this to work, we must reset the password to a known value. $pass = '******'; $user = \Drupal::entityManager()->getStorage('user')->load($account->id()); $user->setPassword($pass)->save(); $url = $domain->getPath() . '/user/login'; $edit = ['name' => $account->getUsername(), 'pass' => $pass]; $this->drupalPostForm($url, $edit, t('Log in')); // @see WebTestBase::drupalUserIsLoggedIn() if (isset($this->sessionId)) { $account->session_id = $this->sessionId; } $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', array('%name' => $account->getUsername())), 'User login'); if ($pass) { $this->loggedInUser = $account; $this->container->get('current_user')->setAccount($account); } }
/** * @inheritdoc */ public function checkResponse(DomainInterface $domain) { $url = $domain->getPath() . drupal_get_path('module', 'domain') . '/tests/200.png'; try { // GuzzleHttp no longer allows for bogus URL calls. $request = $this->httpClient->get($url); } catch (RequestException $e) { watchdog_exception('domain', $e); // File a general server failure. $domain->setResponse(500); return; } // Expected result (i.e. no exception thrown.) $domain->setResponse($request->getStatusCode()); }
/** * Get configuration name for this hostname. * * It will be the same name with a prefix depending on domain and language: * domain.config.DOMAIN_ID.LANGCODE * * @param string $name * The name of the config object. * @param \Drupal\domain\DomainInterface $domain * The domain object. * * @return array * The domain-language, and domain-specific config names. */ protected function getDomainConfigName($name, DomainInterface $domain) { return ['langcode' => 'domain.config.' . $domain->id() . '.' . $this->language->getId() . '.' . $name, 'domain' => 'domain.config.' . $domain->id() . '.' . $name]; }