Source of file Section.php
Size: 1,835 Bytes - Last Modified: 2021-12-23T10:11:59+00:00
/var/www/docs.ssmods.com/process/src/code/Blocks/Section.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?php class Section extends DataObject { private static $db = array( 'Title' => 'Varchar', 'SortOrder' => 'Int', 'ShowTitle' => 'Boolean' ); private static $default_sort = 'SortOrder ASC'; private static $has_one = array( 'Page' => 'Page' ); public function getCMSFields() { $fields = parent::getCMSFields(); $fieldList = FieldList::create( TextField::create('Title'), CheckboxField::create("ShowTitle", "Show Title") ); $fields->removeFieldFromTab('Root.Main', 'SortOrder'); $fields->removeFieldFromTab('Root.Main', 'PageID'); $fields->addFieldsToTab("Root.Main", $fieldList); return $fields; } public static function get_section_type() { return trim(preg_replace('/([A-Z])/', ' $1', str_ireplace('Section', '', get_called_class()))); } public function populateDefaults() { $this->Title = $this->ClassName;// . " " . $this->RunningTotal(); parent::populateDefaults(); } function forTemplate() { $template = str_replace(" ", "", $this->get_section_type()); return $this->renderWith('Blocks/' . $template); } function RunningTotal() { $count = DB::query("SELECT COUNT(*) FROM Section")->value(); return $count + 1; } public function PageTitle (){ return $this->Page()->Title; } public function removeEmptyTabs(FieldList $fields) { foreach ($fields as $field) { if ($field instanceof TabSet) { $this->removeEmptyTabs($field->Tabs(), $fields); } if ($field instanceof Tab && $field->Fields()->count() == 0) { $fields->remove($field); } } return $fields; } } |