|
2 | 2 |
|
3 | 3 | namespace Drupal\session_example\Form;
|
4 | 4 |
|
| 5 | +use Drupal\Core\Cache\CacheTagsInvalidatorInterface; |
5 | 6 | use Drupal\Core\Form\FormBase;
|
6 | 7 | use Drupal\Core\Form\FormStateInterface;
|
7 | 8 | use Drupal\Core\Link;
|
8 | 9 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
9 |
| -use Drupal\Core\Cache\CacheTagsInvalidatorInterface; |
10 | 10 | use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
11 | 11 |
|
12 | 12 | /**
|
@@ -37,17 +37,19 @@ class SessionExampleForm extends FormBase {
|
37 | 37 | *
|
38 | 38 | * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
|
39 | 39 | */
|
40 |
| - protected $cache_tag_invalidator; |
| 40 | + protected $cacheTagInvalidator; |
41 | 41 |
|
42 | 42 | /**
|
43 | 43 | * Constructs a new SessionExampleForm object.
|
44 | 44 | *
|
45 |
| - * @param \Symfony\Component\HttpFoundation\Session\SessionInterface |
| 45 | + * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session |
46 | 46 | * The session object.
|
| 47 | + * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $invalidator |
| 48 | + * The cache tag invalidator service. |
47 | 49 | */
|
48 | 50 | public function __construct(SessionInterface $session, CacheTagsInvalidatorInterface $invalidator) {
|
49 | 51 | $this->session = $session;
|
50 |
| - $this->cache_tag_invalidator = $invalidator; |
| 52 | + $this->cacheTagInvalidator = $invalidator; |
51 | 53 | }
|
52 | 54 |
|
53 | 55 | /**
|
@@ -155,7 +157,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
|
155 | 157 | // Tell the user what happened here, and that they can look at another page
|
156 | 158 | // to see the result.
|
157 | 159 | $this->messenger()->addMessage($this->t('The session has been saved successfully. @link', [
|
158 |
| - '@link' => Link::createFromRoute('Check here.', 'session_example.view')->toString() |
| 160 | + '@link' => Link::createFromRoute('Check here.', 'session_example.view')->toString(), |
159 | 161 | ]));
|
160 | 162 | // Since we might have changed the session information, we will invalidate
|
161 | 163 | // the cache tag for this session.
|
@@ -188,7 +190,7 @@ public function submitClearSession(array &$form, FormStateInterface $form_state)
|
188 | 190 | * updates their information in the submit handlers.
|
189 | 191 | */
|
190 | 192 | protected function invalidateCacheTag() {
|
191 |
| - $this->cache_tag_invalidator->invalidateTags(['session_example:' . $this->session->getId()]); |
| 193 | + $this->cacheTagInvalidator->invalidateTags(['session_example:' . $this->session->getId()]); |
192 | 194 | }
|
193 | 195 |
|
194 | 196 | }
|
0 commit comments