You are here

class DomainController in Domain Access 8

Controller routines for AJAX callbacks for domain actions.

Hierarchy

Expanded class hierarchy of DomainController

File

domain/src/Controller/DomainController.php, line 13

Namespace

Drupal\domain\Controller
View source
class DomainController {
  use StringTranslationTrait;

  /**
   * Handles AJAX operations from the overview form.
   *
   * @param \Drupal\domain\DomainInterface $domain
   *   A domain record object.
   * @param string|null $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::messenger()
        ->addMessage($message);
    }
    else {
      \Drupal::messenger()
        ->addError($this
        ->t('The operation failed.'));
    }

    // Return to the invoking page.
    $url = Url::fromRoute('domain.admin', [], [
      'absolute' => TRUE,
    ]);
    return new RedirectResponse($url
      ->toString(), 302);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DomainController::ajaxOperation public function Handles AJAX operations from the overview form.
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.