Completed
Pull Request — master (#307)
by Damian
01:45
created

ImageFormFactory::getFormFieldAttributesTab()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 46
rs 8.9411
cc 1
eloc 32
nc 1
nop 2
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(_t('AssetAdmin.ImageSpecs', 'Dimensions'),
47
                TextField::create(
48
                    'InsertWidth',
49
                    _t('AssetAdmin.ImageWidth', 'Width')
50
                )
51
                    ->setMaxLength(5)
52
                    ->addExtraClass('flexbox-area-grow'),
53
                TextField::create(
54
                    'InsertHeight',
55
                    _t('AssetAdmin.ImageHeight', 'Height')
56
                )
57
                    ->setMaxLength(5)
58
                    ->addExtraClass('flexbox-area-grow')
59
            )->addExtraClass('fill-width')
60
        );
61
62
        $tab->insertBefore(
63
            'Caption',
64
            TextField::create('AltText', _t('AssetAdmin.AltText', 'Alternative Text (alt)'))
65
                ->setDescription(_t('AssetAdmin.AltTextDescription', 'Shown to screen readers or if image can\'t be displayed'))
66
        );
67
        $tab->insertAfter(
68
            'AltText',
69
            TextField::create('TitleTooltip', _t('AssetAdmin.TitleTooltip', 'Title text (tooltip)'))
70
                ->setDescription(_t('AssetAdmin.TitleTooltipDescription', 'For additional information about the image'))
71
                ->setValue($record->Title)
72
        );
73
74
        return $tab;
75
    }
76
77
}
78