<?php
 namespace Website\Widgets\Blog; use Moto; use Website; use Illuminate; class TagListWidget extends Website\Widgets\Blog\AbstractPostsWidget { protected $_name = 'blog.tag_list'; protected static $_defaultProperties = array( 'listType' => 'all', 'customList' => array(), 'hideEmpty' => false, 'title' => [ 'content' => '', 'textStyle' => 'moto-text_system_8', ], 'visible_on' => 'mobile-v', 'preset' => 'default', 'spacing' => array( 'top' => 'auto', 'right' => 'auto', 'bottom' => 'auto', 'left' => 'auto', ), ); protected $_tags; public function getTemplatePath($preset = null) { return '@websiteWidgets/blog/templates/tag_list.twig.html'; } public function getCssClasses() { $classes = 'moto-preset-' . $this->getPropertyValue('preset'); $classes .= ' ' . $this->getSpacing('classes'); $classes .= ' ' . $this->getVisibleOn('classes'); return $classes; } public function getTags() { if ($this->_tags) { return $this->_tags; } $query = Moto\Database\ContentTaxonomyBlogTag::query(); if ($this->getPropertyValue('hideEmpty')) { $query->whereHas('publishedTargets'); } $customList = null; if ($this->getPropertyValue('listType') === 'custom') { $customList = []; foreach ((array) $this->getPropertyValue('customList') as $item) { $id = $item; if (is_array($item)) { $id = Moto\Util::getValue($item, 'id'); } $customList[] = (int) $id; } $query->whereIn('id', $customList); $collection = $query->get(); $items = new Illuminate\Database\Eloquent\Collection(); foreach ($customList as $id) { $item = $collection->find($id); if ($item) { $items->add($item); } } } else { $query->orderBy('name'); $items = $query->get(); } $this->_tags = $items; return $this->_tags; } } 