UnblockReplicationForm.php in Workspace 8
File
src/Form/UnblockReplicationForm.php
View source
<?php
namespace Drupal\workspace\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class UnblockReplicationForm extends FormBase {
protected $state;
public function __construct(StateInterface $state) {
$this->state = $state;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('state'));
}
public function getFormId() {
return 'unblock_replication_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$last_replication_failed = $this->state
->get('workspace.last_replication_failed', FALSE);
$form['unblock'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Unblock replication'),
);
$form['unblock']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Unblock replication'),
'#disabled' => !$last_replication_failed,
];
$form['unblock']['description'] = [
'#type' => 'markup',
'#markup' => '<div class="description">' . $this
->t('Replications will be blocked after any kind of failure. This action will unblock replications so that they can run again (but make sure to resolve the underlying issue first).') . '</div>',
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->state
->set('workspace.last_replication_failed', FALSE);
$this
->messenger()
->addMessage($this
->t('Replications have been unblocked.'));
}
}