1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\AssetAdmin\Forms; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Assets\File; |
6
|
|
|
use SilverStripe\Core\Config\Configurable; |
7
|
|
|
use SilverStripe\Forms\DropdownField; |
8
|
|
|
use SilverStripe\Forms\FieldGroup; |
9
|
|
|
use SilverStripe\Forms\Tab; |
10
|
|
|
use SilverStripe\Forms\TextField; |
11
|
|
|
|
12
|
|
|
class ImageFormFactory extends FileFormFactory |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
protected function getSpecsMarkup($record) |
16
|
|
|
{ |
17
|
|
|
if (!$record || !$record->exists()) { |
18
|
|
|
return null; |
19
|
|
|
} |
20
|
|
|
// Add dimensions to specs |
21
|
|
|
$dimensions = $record->getDimensions() ? $record->getDimensions() . 'px,' : ''; |
22
|
|
|
return sprintf( |
23
|
|
|
'<div class="editor__specs">%s %s %s</div>', |
24
|
|
|
$dimensions, |
25
|
|
|
$record->getSize(), |
26
|
|
|
$this->getStatusFlagMarkup($record) |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function getFormFieldAttributesTab($record, $context = []) |
31
|
|
|
{ |
32
|
|
|
/** @var Tab $tab */ |
33
|
|
|
$tab = parent::getFormFieldAttributesTab($record); |
34
|
|
|
|
35
|
|
|
$alignments = array( |
36
|
|
|
'leftAlone' => _t('AssetAdmin.AlignmentLeftAlone', 'On the left, on its own.'), |
37
|
|
|
'center' => _t('AssetAdmin.AlignmentCenter', 'Centered, on its own.'), |
38
|
|
|
'left' => _t('AssetAdmin.AlignmentLeft', 'On the left, with text wrapping around.'), |
39
|
|
|
'right' => _t('AssetAdmin.AlignmentRight', 'On the right, with text wrapping around.'), |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$tab->push( |
43
|
|
|
DropdownField::create('Alignment', _t('AssetAdmin.Alignment', 'Alignment'), $alignments) |
44
|
|
|
); |
45
|
|
|
$tab->push( |
46
|
|
|
FieldGroup::create( |
47
|
|
|
_t('AssetAdmin.ImageSpecs', 'Dimensions'), |
48
|
|
|
TextField::create( |
49
|
|
|
'InsertWidth', |
50
|
|
|
_t('AssetAdmin.ImageWidth', 'Width') |
51
|
|
|
) |
52
|
|
|
->setMaxLength(5) |
53
|
|
|
->addExtraClass('flexbox-area-grow'), |
54
|
|
|
TextField::create( |
55
|
|
|
'InsertHeight', |
56
|
|
|
_t('AssetAdmin.ImageHeight', 'Height') |
57
|
|
|
) |
58
|
|
|
->setMaxLength(5) |
59
|
|
|
->addExtraClass('flexbox-area-grow') |
60
|
|
|
)->addExtraClass('fill-width') |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$tab->insertBefore( |
64
|
|
|
'Caption', |
65
|
|
|
TextField::create('AltText', _t('AssetAdmin.AltText', 'Alternative text (alt)')) |
66
|
|
|
->setDescription(_t( |
67
|
|
|
'AssetAdmin.AltTextDescription', |
68
|
|
|
'Shown to screen readers or if image can\'t be displayed' |
69
|
|
|
)) |
70
|
|
|
); |
71
|
|
|
$tab->insertAfter( |
72
|
|
|
'AltText', |
73
|
|
|
TextField::create('TitleTooltip', _t('AssetAdmin.TitleTooltip', 'Title text (tooltip)')) |
74
|
|
|
->setDescription(_t('AssetAdmin.TitleTooltipDescription', 'For additional information about the image')) |
75
|
|
|
->setValue($record->Title) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
return $tab; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|