3 namespace Drupal\ctools\Form;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Form\ConfirmFormBase;
8 use Drupal\user\SharedTempStoreFactory;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Provides a form for deleting an contexts and relationships.
14 abstract class ContextDelete extends ConfirmFormBase {
17 * @var \Drupal\user\SharedTempStoreFactory
24 protected $tempstore_id;
29 protected $machine_name;
32 * The static context's machine name.
36 protected $context_id;
38 public static function create(ContainerInterface $container) {
39 return new static($container->get('user.shared_tempstore'));
42 public function __construct(SharedTempStoreFactory $tempstore) {
43 $this->tempstore = $tempstore;
49 public function getFormId() {
50 return 'ctools_context_delete_form';
56 public function getConfirmText() {
57 return $this->t('Delete');
63 public function buildForm(array $form, FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $context_id = NULL) {
64 $this->tempstore_id = $tempstore_id;
65 $this->machine_name = $machine_name;
66 $this->context_id = $context_id;
67 return parent::buildForm($form, $form_state);
73 public function submitForm(array &$form, FormStateInterface $form_state) {
74 $form_state->setRedirectUrl($this->getCancelUrl());
77 protected function getTempstore() {
78 return $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
81 protected function setTempstore($cached_values) {
82 $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);