easychart-8.x-3.5/src/Form/ResetOptionsConfirmForm.php
src/Form/ResetOptionsConfirmForm.php
<?php
namespace Drupal\easychart\Form;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Config reset options.
*/
class ResetOptionsConfirmForm extends ConfirmFormBase {
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* Constructor.
*
* @param \Drupal\Core\File\FileSystemInterface $fileSystem
* File system service.
*/
public function __construct(FileSystemInterface $fileSystem) {
$this->fileSystem = $fileSystem;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('file_system')
);
}
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'easychart_reset_options_confirm_form';
}
/**
* {@inheritdoc}
*/
public function getQuestion(): TranslatableMarkup {
return $this->t('Are you sure you want to reset the options to their default values ?');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl(): Url {
return new Url('easychart.options');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->fileSystem->delete('public://easychart-options.json');
$this->messenger()->addMessage($this->t('The options have been reset to their default values.'));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
