/**
  * @param \DataList|\ArrayList $items
  * @param                      $filters
  * @param array                $parameters
  */
 public function sequenceGridListItems(&$items, $filters, &$parameters = [])
 {
     $limit = isset($parameters['PageLength']) ? $parameters['PageLength'] : null;
     // filter items for each filter to current page length
     if ($limit) {
         $start = GridList::service()->Filters()->start() ?: 0;
         $out = new \ArrayList();
         $currentFilter = GridList::service()->constraint(Constraints::FilterVar);
         if ($currentFilter && $currentFilter != 'all') {
             if ($filter = GridListFilter::get()->filter(['ModelTag' => $currentFilter])->first()) {
                 $out->merge($items->limit($limit, $start));
             }
         } else {
             foreach ($filters as $filter) {
                 $filtered = new \ArrayList();
                 foreach ($items as $item) {
                     if ($item instanceof Block) {
                         // only push blocks first page
                         if ($start == 0) {
                             $filtered->push($item);
                         }
                     } else {
                         if ($currentFilter == 'all') {
                             $filtered->push($item);
                         } else {
                             if ($item->GridListFilters()->find('ID', $filter->ID)) {
                                 $filtered->push($item);
                             }
                         }
                     }
                 }
                 // merge limited filtered items back in
                 $out->merge($filtered->limit($limit, $start));
             }
         }
         $items = $out;
     }
 }
 /**
  * limits the number of displayed items
  *
  * @param DataList $galleryList
  * @return DataList|SS_Limitable
  */
 protected function LimitGalleryItems(DataList $galleryList)
 {
     $limit = Config::inst()->get('HeaderGalleryExtension', 'limit_header_images');
     return $limit ? $galleryList->limit($limit) : $galleryList;
 }
 /**
  * limits the products to a maximum number (for speed's sake)
  * @return DataList (this->allProducts adjusted!)
  */
 protected function limitCurrentFinalProducts()
 {
     $this->rawCount = $this->allProducts->count();
     $max = EcommerceConfig::get("ProductGroup", "maximum_number_of_products_to_list");
     if ($this->rawCount > $max) {
         $this->allProducts = $this->allProducts->limit($max);
         $this->totalCount = $max;
     } else {
         $this->totalCount = $this->rawCount;
     }
     return $this->allProducts;
 }