Source of file AdaptiveContent.php
Size: 2,044 Bytes - Last Modified: 2021-12-24T06:50:54+00:00
/var/www/docs.ssmods.com/process/src/code/Extensions/AdaptiveContent.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | <?php /** * Class AdaptiveContent */ class AdaptiveContent extends DataExtension { /** * @var array */ private static $db = array( 'Identifier' => 'Varchar(255)', 'SecondaryIdentifier' => 'Varchar(255)', 'TertiaryIdentifier' => 'Varchar(255)', 'Title' => 'Varchar(255)', 'SubTitle' => 'Varchar(255)', 'Teaser' => 'Text', 'ShortTeaser' => 'Text', 'Content' => 'HTMLText', 'SecondaryContent' => 'HTMLText' ); /** * @var array */ private static $has_one = array( 'LeadImage' => 'Image', 'SecondaryImage' => 'Image', 'LeadFile' => 'File' ); /** * @var array */ private static $many_many = array( 'Images' => 'Image', 'Files' => 'File' ); /** * Generates identifier from title, when identifier doesn't exist */ public function onBeforeWrite() { if ($this->owner->Identifier == '') { $this->owner->Identifier = $this->getGeneratedIdentifier(); } } /** * @param FieldList $fields */ public function updateCMSFields(FieldList $fields) { if ($this->owner->Identifier == '') { $fields->removeByName('Identifier'); } else { $fields->makeFieldReadonly('Identifier'); } $fields->removeByName('Images'); $fields->addFieldToTab( 'Root.Images', new UploadField('Images', 'Images', $this->owner->Images()) ); $fields->removeByName('Files'); $fields->addFieldToTab( 'Root.Files', new UploadField('Files', 'Files', $this->owner->Files()) ); } /** * @param bool $title * @return string */ public function getGeneratedIdentifier($title = false) { return URLSegmentFilter::create()->filter($title ? $title : $this->owner->Title); } } |