SwitchToLiveForm.php in Drupal 8
File
core/modules/workspaces/src/Form/SwitchToLiveForm.php
View source
<?php
namespace Drupal\workspaces\Form;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\workspaces\WorkspaceManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SwitchToLiveForm extends ConfirmFormBase implements WorkspaceFormInterface, ContainerInjectionInterface {
protected $workspaceManager;
public function __construct(WorkspaceManagerInterface $workspace_manager) {
$this->workspaceManager = $workspace_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('workspaces.manager'));
}
public function getFormId() {
return 'switch_to_live_form';
}
public function getQuestion() {
return $this
->t('Would you like to switch to the live version of the site?');
}
public function getDescription() {
return $this
->t('Switch to the live version of the site.');
}
public function getCancelUrl() {
return new Url('<current>');
}
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.'));
}
}