3 namespace Drupal\security_review\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\security_review\Checklist;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides implementation for the Run form.
13 class RunForm extends FormBase {
16 * The security_review.checklist service.
18 * @var \Drupal\security_review\Checklist
23 * Constructs a RunForm.
25 * @param \Drupal\security_review\Checklist $checklist
26 * The security_review.checklist service.
28 public function __construct(Checklist $checklist) {
29 $this->checklist = $checklist;
35 public static function create(ContainerInterface $container) {
37 $container->get('security_review.checklist')
44 public function getFormId() {
45 return 'security-review-run';
51 public function buildForm(array $form, FormStateInterface $form_state) {
52 if (!$this->currentUser()->hasPermission('run security checks')) {
58 '#title' => $this->t('Run'),
59 '#description' => $this->t('Click the button below to run the security checklist and review the results.') . '<br />',
63 $form['run_form']['submit'] = [
65 '#value' => $this->t('Run checklist'),
68 // Return the finished form.
75 public function submitForm(array &$form, FormStateInterface $form_state) {
78 'finished' => '_security_review_batch_run_finished',
79 'title' => $this->t('Performing Security Review'),
80 'init_message' => $this->t('Security Review is starting.'),
81 'progress_message' => $this->t('Progress @current out of @total.'),
82 'error_message' => $this->t('An error occurred. Rerun the process or consult the logs.'),
85 foreach ($this->checklist->getEnabledChecks() as $check) {
86 $batch['operations'][] = [
87 '_security_review_batch_run_op',