setTemplate('index', 'site'); $this->setKey('index'); $this->withSeoSettings('index', 'site'); $this->setTitle(_t('@site', 'Home Page')); $this->useBlocksRotation(); $this->filterViewOptions = [ 'none' => ['title' => _t('@', 'No'), 'block' => function () { return null; }], 'listings' => ['title' => _t('@listings', 'Listings'), 'block' => function () { return FilterBlock::i(); }], ]; } public function blocks() { $this->addBlock('welcomeBlock', IndexWelcomeBlock::class, function (IndexWelcomeBlock $block) { $block->title = &$this->titleh1; }); $this->rotateBlock('welcomeBlock', false); $this->addBlock('categoriesBlock', CategoriesBlock::class); if (Listings::geoFilterEnabled()) { $this->addBlock('mapBlock', MapBlock::class); } $this->addBlock('premiumItemsBlock', PremiumItemsBlock::class); $this->addBlock('quickItemsBlock', QuickItemsBlock::class); $this->addBlock('latestItemsBlock', LatestItemsBlock::class); $this->addBlock('promoBlock', IndexPromoBlock::class); $this->banners(); } public function banners() { $list = [ 'site_index_1', 'site_index_2', 'site_index_3', 'site_index_4', 'site_index_5', ]; $i = 1; foreach ($list as $position) { $this->addBanner('banner_' . $position, $position, function (Banner $banner) use ($i) { $banner->setTitle(_t('@site', 'Banner [num]', ['num' => $i])); $banner->setTemplate('index/banner', 'site'); $banner->setKey('banner' . $i); }); $i++; } } public function data() { $data = parent::data(); $this->buildFilterView($this->filterView); return $data; } public function buildFilterView($view = null) { if (! array_key_exists($view, $this->filterViewOptions)) { $view = array_key_first($this->filterViewOptions); } $block = call_user_func($this->filterViewOptions[$view]['block']); if ($block) { $this->view->afterRender('filter', static function () use ($block) { return $block; }); } } /** * Register filter view * @param string $view id * @param string $title * @param Closure $block callable with returns: Block instance, string, null */ public function registerFilterView(string $view, string $title, Closure $block) { $this->filterViewOptions[$view] = [ 'title' => $title, 'block' => $block, ]; } public function seoSettings() { $this->seo ->titleH1(true, _t('@site', 'H1 Title')) ->seotext() ->social(); } public function seo() { $this->seo->canonicalUrl( Site::url('index', [], true) ); $this->seoApply(); } public function settingsForm($form) { $form->radio('filterView', _t('@site', 'Search Filter'), $this->filterView, function () { $options = []; foreach ($this->filterViewOptions as $view => $option) { $options[$view] = $option['title']; } return $options; })->hidden(sizeof($this->filterViewOptions) <= 1); } public function settings() { return [ 'filterView', ]; } }