06e0794a86fb2122fe270591c687b74ae7d6cdef
[yaffs-website] / web / modules / contrib / ctools / src / Form / ContextDelete.php
1 <?php
2
3 namespace Drupal\ctools\Form;
4
5
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Form\ConfirmFormBase;
8 use Drupal\user\SharedTempStoreFactory;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Provides a form for deleting an contexts and relationships.
13  */
14 abstract class ContextDelete extends ConfirmFormBase {
15
16   /**
17    * @var \Drupal\user\SharedTempStoreFactory
18    */
19   protected $tempstore;
20
21   /**
22    * @var string
23    */
24   protected $tempstore_id;
25
26   /**
27    * @var string
28    */
29   protected $machine_name;
30
31   /**
32    * The static context's machine name.
33    *
34    * @var array
35    */
36   protected $context_id;
37
38   public static function create(ContainerInterface $container) {
39     return new static($container->get('user.shared_tempstore'));
40   }
41
42   public function __construct(SharedTempStoreFactory $tempstore) {
43     $this->tempstore = $tempstore;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getFormId() {
50     return 'ctools_context_delete_form';
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function getConfirmText() {
57     return $this->t('Delete');
58   }
59
60   /**
61    * {@inheritdoc}
62    */
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);
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function submitForm(array &$form, FormStateInterface $form_state) {
74     $form_state->setRedirectUrl($this->getCancelUrl());
75   }
76
77   protected function getTempstore() {
78     return $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
79   }
80
81   protected function setTempstore($cached_values) {
82     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
83   }
84
85 }