Source of file CatalogPageExtension.php
Size: 2,814 Bytes - Last Modified: 2021-12-24T06:45:23+00:00
/var/www/docs.ssmods.com/process/src/code/Extensions/CatalogPageExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 | <?php /** * Class CatalogPageExtension */ class CatalogPageExtension extends DataExtension { /** * @config * @var array */ private static $parentClass; /** * @config * @var bool */ private static $can_duplicate = true; /** * Name of the sorting column. SiteTree has a col named "Sort", we use this as default * @config * @var string */ private static $sort_column = 'Sort'; /** * @config * @var bool */ private static $automatic_live_sort = true; /** * @inheritdoc * @param array $fields */ public function updateSummaryFields(&$fields) { $fields['isPublishedNice'] = 'Enabled'; } /** * Returns whether this page is published for the GridField * @return string */ public function isPublishedNice() { return $this->owner->isPublished() ? 'Yes' : 'No'; } /** * Adds functionality to CMS fields * * @param FieldList $fields * @throws Exception */ public function updateCMSFields(FieldList $fields) { $parentClass = $this->owner->stat('parentClass'); if ($pages = $this->getCatalogParents()) { if ($pages && $pages->exists()) { if ($pages->count() == 1) { $fields->addFieldToTab('Root.Main', HiddenField::create('ParentID', 'ParentID', $pages->first()->ID)); } else { $parentID = $this->owner->ParentID ? : $pages->first()->ID; $fields->addFieldToTab('Root.Main', DropdownField::create('ParentID', _t('CatalogManager.PARENTPAGE', 'Parent Page'), $pages->map('ID', 'Title'), $parentID)); } } else { throw new Exception('You must create a parent page of class ' . implode(',', $parentClass)); } } } /** * Gets the fieldname for the sort column. As we're on a subclass of SiteTree we assume 'Sort' as default. * Can be overwritten using $sort_column param on extended class. * Set $sort_column config to false to disable sorting in the gridfield * * @return string */ public function getSortFieldname() { return ($this->owner->config()->get('sort_column') === false) ? false : ($this->owner->config()->get('sort_column') ? : 'Sort'); } /** * Gets the parents of this page * * @return bool|DataList */ public function getCatalogParents() { $parentClass = $this->owner->stat('parentClass'); if (count($parentClass)) { $pages = SiteTree::get()->filter(array('ClassName' => array_values($parentClass))); return $pages; } return false; } } |