class SwitchToLiveForm

Same name and namespace in other branches
  1. 11.x core/modules/workspaces/src/Form/SwitchToLiveForm.php \Drupal\workspaces\Form\SwitchToLiveForm

Provides a form that switches to the live version of the site.

Hierarchy

Expanded class hierarchy of SwitchToLiveForm

1 string reference to 'SwitchToLiveForm'
workspaces.routing.yml in core/modules/workspaces/workspaces.routing.yml
core/modules/workspaces/workspaces.routing.yml

File

core/modules/workspaces/src/Form/SwitchToLiveForm.php, line 15

Namespace

Drupal\workspaces\Form
View source
class SwitchToLiveForm extends ConfirmFormBase implements WorkspaceFormInterface, ContainerInjectionInterface {
  
  /**
   * The workspace manager.
   *
   * @var \Drupal\workspaces\WorkspaceManagerInterface
   */
  protected $workspaceManager;
  
  /**
   * Constructs a new SwitchToLiveForm.
   *
   * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
   *   The workspace manager.
   */
  public function __construct(WorkspaceManagerInterface $workspace_manager) {
    $this->workspaceManager = $workspace_manager;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container->get('workspaces.manager'));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'switch_to_live_form';
  }
  
  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this->t('Would you like to switch to the live version of the site?');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this->t('Switch to the live version of the site.');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('<current>');
  }
  
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->workspaceManager
      ->switchToLive();
    $this->messenger()
      ->addMessage($this->t('You are now viewing the live version of the site.'));
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.