1+ <?php
2+
3+ /**
4+ * Class ImageExtension
5+ *
6+ * @property Image $owner
7+ */
8+ class ImageExtension extends DataExtension {
9+
10+ private static $ db = [
11+ 'AltText ' => 'Varchar(255) ' ,
12+ ];
13+
14+ private static $ has_one = [
15+ 'OwningPage ' => 'Page '
16+ ];
17+
18+ public function updateCMSFields (FieldList $ fields ) {
19+
20+ Requirements::customCSS (
21+ <<<CSS
22+ form.small .field input.text,
23+ form.small .field textarea,
24+ form.small .field select,
25+ form.small .field .TreeDropdownField,
26+ .field.small input.text,
27+ .field.small textarea,
28+ .field.small select,
29+ .field.small .TreeDropdownField {
30+ width: 100%;
31+ }
32+ CSS
33+ );
34+
35+ $ fields ->dataFieldByName ('Title ' )->setTitle (_t ('Linkable.TITLE ' , 'Title Attribute ' ))
36+ ->setDescription ('Describe the image to humans ' );
37+
38+ /** @var TextField $altText */
39+ $ fields ->addFieldToTab ('Root.Main ' , $ altText = TextField::create ('AltText ' , _t ('Linkable.SEOTEXT ' , 'Alt Attribute ' )), 'Name ' );
40+ $ altText ->setDescription ('Describe the image to google ' );
41+
42+ $ fields ->removeByName ('OwningPageID ' );
43+ }
44+
45+ public function getDownloadAttribute () {
46+ /** @var File $component */
47+ if ($ this ->owner ->Type === 'File ' && $ component = $ this ->owner ->getComponent ($ this ->owner ->Type )) {
48+ if ($ component ->exists ()) {
49+ return ' download=" ' . $ component ->Name . '" ' ;
50+ }
51+
52+ }
53+
54+ return null ;
55+ }
56+
57+ }
0 commit comments