Source of file ColorAttributeValue.php
Size: 1,658 Bytes - Last Modified: 2021-12-23T10:02:45+00:00
/var/www/docs.ssmods.com/process/src/code/model/attributes/values/ColorAttributeValue.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | <?php /** * Created by PhpStorm. * User: Magnum * Date: 2018-02-03 * Time: 22:45 */ class ColorAttributeValue extends DataObject { private static $singular_name = "Color Attribute"; private static $plural_name = "Color Attribute"; private static $db = array( "Value" => "Varchar(200)", "URLSegment" => "Varchar(255)", "Sort" => "Int" ); private static $has_one = array( "ColorAttributeType" => "ColorAttributeType" ); private static $indexes = array( "URLSegment" => true, ); private static $field_labels = array( 'URLSegment' => 'URL' ); private static $default_sort = '"Sort" ASC'; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName("Sort"); return $fields; } /** * Generarte URLSegment for Object */ public function onBeforeWrite() { parent::onBeforeWrite(); if($this->Title && !$this->URLSegment) { $title = $this->Title; $filter = URLSegmentFilter::create(); $t = $filter->filter($title); // Fallback to generic page name if path is empty (= no valid, convertable characters) if (!$t || $t == '-' || $t == '-1') $t = "value-$this->ID"; // Hook for extensions $this->extend('updateURLSegment', $t, $title); $this->URLSegment = $t; $generate = new GeneratorURLSegment($this,$this->URLSegment); $generate->UniqueURLSegment(); $this->URLSegment = $generate->getURLSegment(); } } } |