Source of file ImageExtension.php
Size: 1,312 Bytes - Last Modified: 2021-12-23T10:58:12+00:00
/var/www/docs.ssmods.com/process/src/code/ImageExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | <?php /** * Class ImageExtension * * @property Image $owner */ class ImageExtension extends DataExtension { private static $db = [ 'AltText' => 'Varchar(255)', ]; private static $has_one = [ 'OwningPage' => 'Page' ]; public function updateCMSFields(FieldList $fields) { Requirements::customCSS( <<<CSS form.small .field input.text, form.small .field textarea, form.small .field select, form.small .field .TreeDropdownField, .field.small input.text, .field.small textarea, .field.small select, .field.small .TreeDropdownField { width: 100%; } CSS ); $fields->dataFieldByName('Title')->setTitle(_t('Linkable.TITLE', 'Title Attribute')) ->setDescription('Describe the image to humans'); /** @var TextField $altText */ $fields->addFieldToTab('Root.Main', $altText = TextField::create('AltText', _t('Linkable.SEOTEXT', 'Alt Attribute')), 'Name'); $altText->setDescription('Describe the image to google'); $fields->removeByName('OwningPageID'); } public function getDownloadAttribute() { /** @var File $component */ if ($this->owner->Type === 'File' && $component = $this->owner->getComponent($this->owner->Type)) { if ($component->exists()) { return ' download="' . $component->Name . '" '; } } return null; } } |