class MetatagViewsCacheWrapper in Metatag 8
This class wraps a Views cache plugin.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\views\Plugin\views\PluginBase implements DependentPluginInterface, ContainerFactoryPluginInterface, TrustedCallbackInterface, ViewsPluginInterface
- class \Drupal\views\Plugin\views\cache\CachePluginBase
- class \Drupal\metatag_views\MetatagViewsCacheWrapper
 
 
 - class \Drupal\views\Plugin\views\cache\CachePluginBase
 
 - class \Drupal\views\Plugin\views\PluginBase implements DependentPluginInterface, ContainerFactoryPluginInterface, TrustedCallbackInterface, ViewsPluginInterface
 
 - class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
 
Expanded class hierarchy of MetatagViewsCacheWrapper
1 file declares its use of MetatagViewsCacheWrapper
- metatag_views.module in metatag_views/
metatag_views.module  - Contains hook implementations for the metatag_views module.
 
File
- metatag_views/
src/ MetatagViewsCacheWrapper.php, line 20  
Namespace
Drupal\metatag_viewsView source
class MetatagViewsCacheWrapper extends CachePluginBase {
  /**
   * The cache type we are interested in.
   */
  const RESULTS = 'results';
  /**
   * @var \Drupal\views\Plugin\views\cache\CachePluginBase
   */
  protected $plugin;
  /**
   * Whether cacheSet was called with $type 'result'.
   *
   * @var bool
   */
  protected $called = FALSE;
  /**
   * MetatagViewsCacheWrapper constructor.
   *
   * @param \Drupal\views\Plugin\views\cache\CachePluginBase $plugin
   *   The cache plugin being wrapped.
   */
  public function __construct(CachePluginBase $plugin) {
    $this->plugin = $plugin;
  }
  /**
   * {@inheritdoc}
   */
  public function cacheSet($type) {
    if ($type === self::RESULTS) {
      $this->called = TRUE;
    }
    else {
      $this->plugin
        ->cacheSet($type);
    }
  }
  /**
   * Actually run cacheSet for type results.
   *
   * It needs to be deferred past the render phase so the row tokens in
   * the style plugin are populated.
   */
  public function doDeferredCacheSet() {
    if (!$this->called) {
      return;
    }
    $plugin = $this->plugin;
    $view = $plugin->view;
    $data = [
      'result' => $plugin
        ->prepareViewResult($view->result),
      'total_rows' => isset($view->total_rows) ? $view->total_rows : 0,
      'current_page' => $view
        ->getCurrentPage(),
      'first_row_tokens' => MetatagDisplayExtender::getFirstRowTokensFromStylePlugin($view),
    ];
    $cache_set_max_age = $plugin
      ->cacheSetMaxAge(self::RESULTS);
    $expire = $cache_set_max_age === Cache::PERMANENT ? Cache::PERMANENT : (int) $view
      ->getRequest()->server
      ->get('REQUEST_TIME') + $cache_set_max_age;
    \Drupal::cache($plugin->resultsBin)
      ->set($plugin
      ->generateResultsKey(), $data, $expire, $plugin
      ->getCacheTags());
  }
  /**
   * {@inheritdoc}
   */
  public function cacheGet($type) {
    if ($type === self::RESULTS) {
      $cutoff = $this->plugin
        ->cacheExpire($type);
      // Values to set: $view->result, $view->total_rows, $view->execute_time,
      // $view->current_page and pass row tokens to metatag display extender.
      if ($cache = \Drupal::cache($this->plugin->resultsBin)
        ->get($this->plugin
        ->generateResultsKey())) {
        if (!$cutoff || $cache->created > $cutoff) {
          $view = $this->plugin->view;
          $view->result = $cache->data['result'];
          // Load entities for each result.
          $view->query
            ->loadEntities($view->result);
          $view->total_rows = $cache->data['total_rows'];
          $view
            ->setCurrentPage($cache->data['current_page'], TRUE);
          $view->execute_time = 0;
          $extenders = $view
            ->getDisplay()
            ->getExtenders();
          if (isset($extenders['metatag_display_extender'])) {
            $extenders['metatag_display_extender']
              ->setFirstRowTokens($cache->data['first_row_tokens']);
          }
          return TRUE;
        }
      }
      return FALSE;
    }
    return $this->plugin
      ->cacheGet($type);
  }
  /**
   * {@inheritdoc}
   */
  public function getResultsKey() {
    return $this->plugin
      ->getResultsKey();
  }
  /**
   * {@inheritdoc}
   */
  public function summaryTitle() {
    return $this->plugin
      ->summaryTitle();
  }
  /**
   * {@inheritdoc}
   */
  public function cacheFlush() {
    $this->plugin
      ->cacheFlush();
  }
  /**
   * {@inheritdoc}
   */
  public function postRender(&$output) {
    $this->plugin
      ->postRender($output);
  }
  /**
   * {@inheritdoc}
   */
  public function generateResultsKey() {
    return $this->plugin
      ->generateResultsKey();
  }
  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    return $this->plugin
      ->getCacheTags();
  }
  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return $this->plugin
      ->getCacheMaxAge();
  }
  /**
   * {@inheritdoc}
   */
  public function alterCacheMetadata(CacheableMetadata $cache_metadata) {
    $this->plugin
      ->alterCacheMetadata($cache_metadata);
  }
  /**
   * {@inheritdoc}
   */
  public function getRowCacheTags(ResultRow $row) {
    return $this->plugin
      ->getRowCacheTags($row);
  }
  /**
   * {@inheritdoc}
   */
  public function getRowCacheKeys(ResultRow $row) {
    return $this->plugin
      ->getRowCacheKeys($row);
  }
  /**
   * {@inheritdoc}
   */
  public function getRowId(ResultRow $row) {
    return $this->plugin
      ->getRowId($row);
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    CachePluginBase::create($container, $configuration, $plugin_id, $plugin_definition);
  }
  /**
   * {@inheritdoc}
   */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    $this->plugin
      ->init($view, $display, $options);
  }
  /**
   * {@inheritdoc}
   */
  public function filterByDefinedOptions(array &$storage) {
    $this->plugin
      ->filterByDefinedOptions($storage);
  }
  /**
   * {@inheritdoc}
   */
  public function unpackOptions(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE) {
    $this->plugin
      ->unpackOptions($storage, $options, $definition, $all, $check);
  }
  /**
   * {@inheritdoc}
   */
  public function destroy() {
    $this->plugin
      ->destroy();
  }
  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $this->plugin
      ->buildOptionsForm($form, $form_state);
  }
  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    CachePluginBase::trustedCallbacks();
  }
  /**
   * {@inheritdoc}
   */
  public function validateOptionsForm(&$form, FormStateInterface $form_state) {
    $this->plugin
      ->validateOptionsForm($form, $form_state);
  }
  /**
   * {@inheritdoc}
   */
  public function submitOptionsForm(&$form, FormStateInterface $form_state) {
    $this->plugin
      ->submitOptionsForm($form, $form_state);
  }
  /**
   * {@inheritdoc}
   */
  public function query() {
    $this->plugin
      ->query();
  }
  /**
   * {@inheritdoc}
   */
  public function themeFunctions() {
    return $this->plugin
      ->themeFunctions();
  }
  /**
   * {@inheritdoc}
   */
  public function validate() {
    return $this->plugin
      ->validate();
  }
  /**
   * {@inheritdoc}
   */
  public function pluginTitle() {
    return $this->plugin
      ->pluginTitle();
  }
  /**
   * {@inheritdoc}
   */
  public function usesOptions() {
    return $this->plugin
      ->usesOptions();
  }
  /**
   * {@inheritdoc}
   */
  public function globalTokenReplace($string = '', array $options = []) {
    return $this->plugin
      ->globalTokenReplace($string, $options);
  }
  /**
   * {@inheritdoc}
   */
  public function getAvailableGlobalTokens($prepared = FALSE, array $types = []) {
    return $this->plugin
      ->getAvailableGlobalTokens($prepared, $types);
  }
  /**
   * {@inheritdoc}
   */
  public function globalTokenForm(&$form, FormStateInterface $form_state) {
    $this->plugin
      ->globalTokenForm($form, $form_state);
  }
  /**
   * {@inheritdoc}
   */
  public static function preRenderAddFieldsetMarkup(array $form) {
    CachePluginBase::preRenderAddFieldsetMarkup($form);
  }
  /**
   * {@inheritdoc}
   */
  public static function preRenderFlattenData($form) {
    CachePluginBase::preRenderFlattenData($form);
  }
  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return $this->plugin
      ->calculateDependencies();
  }
  /**
   * {@inheritdoc}
   */
  public function getProvider() {
    return $this->plugin
      ->getProvider();
  }
  /**
   * {@inheritdoc}
   */
  public static function queryLanguageSubstitutions() {
    CachePluginBase::queryLanguageSubstitutions();
  }
  /**
   * {@inheritdoc}
   */
  public function getPluginId() {
    return $this->plugin
      ->getPluginId();
  }
  /**
   * {@inheritdoc}
   */
  public function getBaseId() {
    return $this->plugin
      ->getBaseId();
  }
  /**
   * {@inheritdoc}
   */
  public function getDerivativeId() {
    return $this->plugin
      ->getDerivativeId();
  }
  /**
   * {@inheritdoc}
   */
  public function getPluginDefinition() {
    return $this->plugin
      ->getPluginDefinition();
  }
  /**
   * {@inheritdoc}
   */
  public function isConfigurable() {
    return $this->plugin
      ->isConfigurable();
  }
  /**
   * {@inheritdoc}
   */
  public function setStringTranslation(TranslationInterface $translation) {
    return $this->plugin
      ->setStringTranslation($translation);
  }
  /**
   * {@inheritdoc}
   */
  public function __sleep() {
    return $this->plugin
      ->__sleep();
  }
  /**
   * {@inheritdoc}
   */
  public function __wakeup() {
    $this->plugin
      ->__wakeup();
  }
  /**
   * {@inheritdoc}
   */
  public function setMessenger(MessengerInterface $messenger) {
    $this->plugin
      ->setMessenger($messenger);
  }
  /**
   * {@inheritdoc}
   */
  public function messenger() {
    $this->plugin
      ->messenger();
  }
  public function __get($name) {
    return $this->plugin->{$name};
  }
  public function __set($name, $value) {
    $this->plugin->{$name} = $value;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            CachePluginBase:: | 
                  protected | property | Which cache bin to store query results in. | |
| 
            CachePluginBase:: | 
                  protected | property | Stores the cache ID used for the results cache. | |
| 
            CachePluginBase:: | 
                  public | property | Contains all data that should be written/read from cache. | |
| 
            CachePluginBase:: | 
                  protected | function | Determine the expiration time of the cache type, or NULL if no expire. | 2 | 
| 
            CachePluginBase:: | 
                  protected | function | Determine expiration time in the cache table of the cache type or CACHE_PERMANENT if item shouldn't be removed automatically from cache. | 1 | 
| 
            CachePluginBase:: | 
                  protected | function | Returns the default cache max age. | 2 | 
| 
            CachePluginBase:: | 
                  protected | function | Prepares the view result before putting it into cache. | |
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of entity type IDs keyed by the property name of their storages. | |
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of service IDs keyed by property name used for serialization. | |
| 
            MessengerTrait:: | 
                  protected | property | The messenger. | 29 | 
| 
            MetatagViewsCacheWrapper:: | 
                  protected | property | Whether cacheSet was called with $type 'result'. | |
| 
            MetatagViewsCacheWrapper:: | 
                  protected | property | ||
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Alters the cache metadata of a display upon saving a view. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Provide a form to edit options for this plugin. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Clear out cached data for a view. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Retrieve data from the cache. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Save data to the cache. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Calculates dependencies for the configured plugin. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public static | function | 
            Creates an instance of the plugin. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Clears a plugin. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | Actually run cacheSet for type results. | |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Filter out stored options depending on the defined options. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Calculates and sets a cache ID used for the result cache. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns an array of available token replacements. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Gets the base_plugin_id of the plugin instance. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Gets the max age for the current view. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Gets an array of cache tags for the current view. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Gets the derivative_id of the plugin instance. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Gets the definition of the plugin implementation. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Gets the plugin_id of the plugin instance. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns the plugin provider. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns the resultsKey property. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns the row cache keys. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns the row cache tags. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns a unique identifier for the specified row. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Adds elements for available core tokens to a form. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns a string with any core tokens replaced. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Initialize the plugin. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Determines if the plugin is configurable. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Gets the messenger. Overrides MessengerTrait:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Return the human readable name of the display. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Post process any rendered data. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public static | function | 
            Moves form elements into fieldsets for presentation purposes. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public static | function | 
            Flattens the structure of form elements. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Add anything to the query that we might need to. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public static | function | 
            Returns substitutions for Views queries for languages. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  constant | The cache type we are interested in. | ||
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Sets the messenger. Overrides MessengerTrait:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Sets the string translation service to use. Overrides StringTranslationTrait:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Handle any special handling on the validate form. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Return a string to display as the clickable title for the
access control. Overrides CachePluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Provide a full list of possible theme templates used by this style. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public static | function | 
            Lists the trusted callbacks provided by the implementing class. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Unpack options over our existing defaults, drilling down into arrays
so that defaults don't get totally blown away. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Returns the usesOptions property. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Validate that the plugin is correct and can be saved. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Validate the options form. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            MetatagViewsCacheWrapper constructor. Overrides PluginBase:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | ||
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | ||
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Overrides DependencySerializationTrait:: | 
                  |
| 
            MetatagViewsCacheWrapper:: | 
                  public | function | 
            Overrides DependencySerializationTrait:: | 
                  |
| 
            PluginBase:: | 
                  protected | property | Configuration information passed into the plugin. | 1 | 
| 
            PluginBase:: | 
                  public | property | Plugins's definition | |
| 
            PluginBase:: | 
                  public | property | The display object this plugin is for. | |
| 
            PluginBase:: | 
                  public | property | Options for this plugin will be held here. | |
| 
            PluginBase:: | 
                  protected | property | The plugin implementation definition. | 1 | 
| 
            PluginBase:: | 
                  protected | property | The plugin_id. | |
| 
            PluginBase:: | 
                  protected | property | Stores the render API renderer. | 3 | 
| 
            PluginBase:: | 
                  protected | property | Denotes whether the plugin has an additional options form. | 8 | 
| 
            PluginBase:: | 
                  public | property | The top object of a view. | 1 | 
| 
            PluginBase:: | 
                  protected | function | Information about options for all kinds of purposes will be held here. | 18 | 
| 
            PluginBase:: | 
                  constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
| 
            PluginBase:: | 
                  protected | function | Do the work to filter out stored options depending on the defined options. | |
| 
            PluginBase:: | 
                  protected | function | Returns the render API renderer. | 1 | 
| 
            PluginBase:: | 
                  constant | Include entity row languages when listing languages. | ||
| 
            PluginBase:: | 
                  constant | Include negotiated languages when listing languages. | ||
| 
            PluginBase:: | 
                  protected | function | Makes an array of languages, optionally including special languages. | |
| 
            PluginBase:: | 
                  protected | function | Fills up the options of the plugin with defaults. | |
| 
            PluginBase:: | 
                  protected | function | Replaces Views' tokens in a given string. The resulting string will be sanitized with Xss::filterAdmin. | 1 | 
| 
            PluginBase:: | 
                  constant | Query string to indicate the site default language. | ||
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. | |
| 
            TrustedCallbackInterface:: | 
                  constant | Untrusted callbacks throw exceptions. | ||
| 
            TrustedCallbackInterface:: | 
                  constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
| 
            TrustedCallbackInterface:: | 
                  constant | Untrusted callbacks trigger E_USER_WARNING errors. |