Skip to content
Snippets Groups Projects
Commit aa6c8f13 authored by Taras Kravchuk's avatar Taras Kravchuk Committed by Artem Sylchuk
Browse files

Issue #3337189 by _tarik_, artem_sylchuk: Inject keyValue storage properly in the AjaxController

parent f738a230
No related branches found
No related tags found
1 merge request!49Issue #3337189: Inject keyValue storage properly in the AjaxController
...@@ -7,6 +7,7 @@ use Drupal\Core\Ajax\AjaxResponse; ...@@ -7,6 +7,7 @@ use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\Core\Render\RendererInterface; use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Site\Settings; use Drupal\Core\Site\Settings;
...@@ -80,6 +81,13 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface { ...@@ -80,6 +81,13 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
*/ */
protected $privateMessageService; protected $privateMessageService;
/**
* The key/value storage collection.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
*/
protected $keyValueStore;
/** /**
* Constructs a AjaxController object. * Constructs a AjaxController object.
* *
...@@ -102,7 +110,8 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface { ...@@ -102,7 +110,8 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
EntityTypeManagerInterface $entityTypeManager, EntityTypeManagerInterface $entityTypeManager,
ConfigFactoryInterface $configFactory, ConfigFactoryInterface $configFactory,
AccountProxyInterface $currentUser, AccountProxyInterface $currentUser,
PrivateMessageServiceInterface $privateMessageService PrivateMessageServiceInterface $privateMessageService,
KeyValueStoreInterface $keyValueStore
) { ) {
$this->renderer = $renderer; $this->renderer = $renderer;
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
...@@ -111,6 +120,7 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface { ...@@ -111,6 +120,7 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
$this->configFactory = $configFactory; $this->configFactory = $configFactory;
$this->currentUser = $currentUser; $this->currentUser = $currentUser;
$this->privateMessageService = $privateMessageService; $this->privateMessageService = $privateMessageService;
$this->keyValueStore = $keyValueStore;
} }
/** /**
...@@ -123,7 +133,8 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface { ...@@ -123,7 +133,8 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
$container->get('entity_type.manager'), $container->get('entity_type.manager'),
$container->get('config.factory'), $container->get('config.factory'),
$container->get('current_user'), $container->get('current_user'),
$container->get('private_message.service') $container->get('private_message.service'),
$container->get('keyvalue')->get('entity_autocomplete')
); );
} }
...@@ -184,7 +195,7 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface { ...@@ -184,7 +195,7 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
// Selection settings are passed in as a hashed key of a serialized array // Selection settings are passed in as a hashed key of a serialized array
// stored in the key/value store. // stored in the key/value store.
$selection_settings = \Drupal::keyValue('entity_autocomplete')->get($selection_settings_key, FALSE); $selection_settings = $this->keyValueStore->get($selection_settings_key, FALSE);
if ($selection_settings !== FALSE) { if ($selection_settings !== FALSE) {
$selection_settings_hash = Crypt::hmacBase64(serialize($selection_settings) . $target_type . $selection_handler, Settings::getHashSalt()); $selection_settings_hash = Crypt::hmacBase64(serialize($selection_settings) . $target_type . $selection_handler, Settings::getHashSalt());
if (!hash_equals($selection_settings_hash, $selection_settings_key)) { if (!hash_equals($selection_settings_hash, $selection_settings_key)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment