Completed
Pull Request — master (#306)
by Damian
02:01
created

FileHistoryFormFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getForm() 0 6 1
A getFormFields() 0 16 1
A getFormActions() 0 8 1
1
<?php
2
3
namespace SilverStripe\AssetAdmin\Forms;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\FormFactory;
9
use SilverStripe\Forms\LiteralField;
10
use SilverStripe\Forms\ReadonlyField;
11
12
class FileHistoryFormFactory extends FileFormFactory
13
{
14
    public function getForm(Controller $controller, $name = FormFactory::DEFAULT_NAME, $context = [])
15
    {
16
        $form = parent::getForm($controller, $name, $context);
17
        $form->makeReadonly();
18
        return $form;
19
    }
20
21
    protected function getFormFields(Controller $controller, $name, $context = [])
22
    {
23
        $record = $context['Record'];
24
25
        $fields = new FieldList(
26
            LiteralField::create('Thumbnail', $this->getIconMarkup($record)),
27
            LiteralField::create('FileSpecs', $this->getSpecsMarkup($record)),
28
            ReadonlyField::create("Title", File::singleton()->fieldLabel('Title')),
29
            ReadonlyField::create('Name', File::singleton()->fieldLabel('Filename')),
30
            ReadonlyField::create("Path", _t('AssetTableField.PATH', 'Path'), $this->getPath($record))
31
        );
32
33
        $this->invokeWithExtensions('updateFormFields', $fields, $controller, $name, $context);
34
35
        return $fields;
36
    }
37
38
39
    protected function getFormActions(Controller $controller, $name, $context = [])
40
    {
41
        $actions = new FieldList();
42
        // Update
43
        $this->invokeWithExtensions('updateFormActions', $actions, $controller, $name, $context);
44
45
        return $actions;
46
    }
47
}
48