headless_cms-1.0.3/modules/headless_cms_preview/src/TempStore/PreviewTempStoreFactory.php

modules/headless_cms_preview/src/TempStore/PreviewTempStoreFactory.php
<?php

declare(strict_types=1);

namespace Drupal\headless_cms_preview\TempStore;

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\PrivateTempStore;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\headless_cms_preview\Session\AccountProxyWrapper;

/**
 * Custom PrivateTempStore factory for previews.
 */
class PreviewTempStoreFactory extends PrivateTempStoreFactory {

  /**
   * {@inheritdoc}
   *
   * Allows setting the user account for the current user explicitly.
   */
  public function get($collection, ?AccountInterface $account = NULL) {
    $user = $account ? new AccountProxyWrapper($account) : $this->currentUser;

    // Store the data for this collection in the database.
    $storage = $this->storageFactory->get("tempstore.private.$collection");
    return new PrivateTempStore($storage, $this->lockBackend, $user, $this->requestStack, $this->expire);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc