PagersCacheContext.php 817 Bytes
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Cache\Context\PagersCacheContext.
6 7
 */

8
namespace Drupal\Core\Cache\Context;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

/**
 * Defines a cache context for "per page in a pager" caching.
 */
class PagersCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Pager');
  }

  /**
   * {@inheritdoc}
   *
   * @see pager_find_page()
   */
  public function getContext($pager_id = NULL) {
    // The value of the 'page' query argument contains the information that
    // controls *all* pagers.
    if ($pager_id === NULL) {
      return 'pager' . $this->requestStack->getCurrentRequest()->query->get('page', '');
    }

    return 'pager.' . $pager_id . '.' . pager_find_page($pager_id);
  }

}