<?php
namespace Website\Widgets\Breadcrumbs; use Moto; use Website; class PageCollection extends Moto\System\PriorityCollection { protected $_priorityNames = [ 'MAIN_PAGE' => 10, 'HOME_PAGE' => 10, 'PARENT_PAGE' => 100, 'CURRENT_PAGE' => 1000, ]; protected $_filled = false; protected static $_previewData = [ [ 'name' => 'Home Page', 'isMainPage' => true, ], [ 'name' => 'Parent Page', 'isMainPage' => false, ], [ 'name' => 'Child Page', 'isMainPage' => false, ], ]; public static function create(array $params = []) { $collection = new static(); $collection->disableAutoSorting(); if (Moto\Util::getValue($params, 'previewData')) { $collection->_fillPreviewData(); } else { Moto\Hook::trigger(Moto\Hook::WIDGET_BREADCRUMBS__FULL_PAGE_COLLECTION_CREATED, $collection); } return $collection; } protected function _fillPreviewData() { static::$_previewData[0] = new Website\Widgets\Breadcrumbs\MainPage(); foreach (static::$_previewData as $index => $page) { $this->insert((object) $page); } $this->updateSorting(); $this->markAsFilled(); } public function isFilled() { return $this->_filled; } public function markAsFilled() { if ($this->isFilled()) { return $this; } $this->_filled = true; $this->enableAutoSorting(); Moto\Hook::trigger(Moto\Hook::WIDGET_BREADCRUMBS__FULL_PAGE_COLLECTION_FILLED, $this); $this->updateSorting(); return $this; } } 