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
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Site\Settings;
@@ -80,6 +81,13 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
   */
  protected $privateMessageService;

  /**
   * The key/value storage collection.
   *
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
   */
  protected $keyValueStore;

  /**
   * Constructs a AjaxController object.
   *
@@ -102,7 +110,8 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
    EntityTypeManagerInterface $entityTypeManager,
    ConfigFactoryInterface $configFactory,
    AccountProxyInterface $currentUser,
    PrivateMessageServiceInterface $privateMessageService
    PrivateMessageServiceInterface $privateMessageService,
    KeyValueStoreInterface $keyValueStore
  ) {
    $this->renderer = $renderer;
    $this->requestStack = $requestStack;
@@ -111,6 +120,7 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
    $this->configFactory = $configFactory;
    $this->currentUser = $currentUser;
    $this->privateMessageService = $privateMessageService;
    $this->keyValueStore = $keyValueStore;
  }

  /**
@@ -123,7 +133,8 @@ class AjaxController extends ControllerBase implements AjaxControllerInterface {
      $container->get('entity_type.manager'),
      $container->get('config.factory'),
      $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 {

    // Selection settings are passed in as a hashed key of a serialized array
    // 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) {
      $selection_settings_hash = Crypt::hmacBase64(serialize($selection_settings) . $target_type . $selection_handler, Settings::getHashSalt());
      if (!hash_equals($selection_settings_hash, $selection_settings_key)) {