/**
  * Returns a template name either from extended models config.gridlist_template of set or from the extended models ClassName. In either case the current
  * GridList view mode (grid, list or search) is appended.
  *
  * @return string
  */
 protected function template()
 {
     $mode = GridList::service()->mode();
     if (!($template = $this()->config()->get('gridlist_template'))) {
         $template = "GridList/" . $this()->ClassName;
     }
     return "{$template}" . '_' . $mode;
 }
 public function constrainGridListItems(&$items)
 {
     $service = GridList::service();
     $currentFilterID = $service->Filters()->currentFilterID();
     // filter to current filter if set
     if ($currentFilterID) {
         $out = new \ArrayList();
         foreach ($items as $item) {
             if ($item->GridListFilters()->find('ID', $currentFilterID)) {
                 $out->push($item);
             }
         }
         $items = $out;
     }
 }
 /**
  * @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;
     }
 }