Source of file StylingHeight.php
Size: 2,008 Bytes - Last Modified: 2021-12-24T06:47:59+00:00
/var/www/docs.ssmods.com/process/src/src/StylingHeight.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | <?php namespace Fractas\ElementalStylings; use Fractas\ElementalStylings\Forms\StylingOptionsetField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\ORM\DataExtension; use SilverStripe\View\ArrayData; class StylingHeight extends DataExtension { private static $db = [ 'Height' => 'Varchar(255)', ]; /** * @var string */ private static $singular_name = 'Height'; /** * @var string */ private static $plural_name = 'Heights'; /** * @config * * @var array */ private static $height = []; public function getStylingHeightNice($key) { return (!empty($this->owner->config()->get('height')[$key])) ? $this->owner->config()->get('height')[$key] : $key; } public function getStylingHeightData() { return ArrayData::create([ 'Label' => self::$singular_name, 'Value' => $this->getStylingHeightNice($this->owner->Height), ]); } /** * @return string */ public function getHeightVariant() { $height = $this->owner->Height; $heights = $this->owner->config()->get('height'); if (isset($heights[$height])) { $height = strtolower($height); } else { $height = ''; } return 'height-'.$height; } public function updateCMSFields(FieldList $fields) { $height = $this->owner->config()->get('height'); if ($height && count($height) > 1) { $fields->addFieldsToTab('Root.Styling', StylingOptionsetField::create('Height', _t(__CLASS__.'.HEIGHT', 'Height Size'), $height)); } else { $fields->removeByName('Height'); } return $fields; } public function populateDefaults() { $height = $this->owner->config()->get('height'); $height = reset($height); $this->owner->Height = $height; parent::populateDefaults(); } } |