Completed
Pull Request — master (#98)
by Nic
09:57
created

Variation::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 9.9666
1
<?php
2
3
namespace Dynamic\Foxy\Model;
4
5
use Bummzack\SortableFile\Forms\SortableUploadField;
6
use Dynamic\Products\Page\Product;
0 ignored issues
show
Bug introduced by
The type Dynamic\Products\Page\Product was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SilverStripe\Assets\File;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\ORM\DataObject;
10
11
/**
12
 * Class Variation
13
 * @package Dynamic\Foxy\Model
14
 */
15
class Variation extends DataObject
16
{
17
    /**
18
     * @var string
19
     */
20
    private static $table_name = 'Variation';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
21
22
    /**
23
     * @var string
24
     */
25
    private static $singular_name = 'Variation';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
26
27
    /**
28
     * @var string
29
     */
30
    private static $plural_name = 'Variations';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
31
32
    /**
33
     * @var string[]
34
     */
35
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
36
        'Title' => 'Varchar(255)',
37
        'Content' => 'HTMLText',
38
        'WeightModifier' => 'Decimal(9,3)',
39
        'CodeModifier' => 'Text',
40
        'PriceModifier' => 'Currency',
41
        'WeightModifierAction' => "Enum('Add,Subtract,Set', null)",
42
        'CodeModifierAction' => "Enum('Add,Subtract,Set', null)",
43
        'PriceModifierAction' => "Enum('Add,Subtract,Set', null)",
44
        'Available' => 'Boolean',
45
        'Type' => 'Int',
46
        'OptionModifierKey' => 'Varchar(255)',
47
        'SortOrder' => 'Int',
48
    ];
49
50
    /**
51
     * @var array
52
     */
53
    private static $many_many = [
0 ignored issues
show
introduced by
The private property $many_many is not used, and could be removed.
Loading history...
54
        'Images' => File::class,
55
    ];
56
57
    /**
58
     * @var \string[][]
59
     */
60
    private static $many_many_extraFields = [
0 ignored issues
show
introduced by
The private property $many_many_extraFields is not used, and could be removed.
Loading history...
61
        'Images' => [
62
            'SortOrder' => 'Int',
63
        ],
64
    ];
65
66
    /**
67
     * @var string[]
68
     */
69
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
70
        'Images',
71
    ];
72
73
    /**
74
     * The relation name was established before requests for videos.
75
     * The relation has subsequently been updated from Image::class to File::class
76
     * to allow for additional file types such as mp4
77
     *
78
     * @var array
79
     */
80
    private static $allowed_images_extensions = [
0 ignored issues
show
introduced by
The private property $allowed_images_extensions is not used, and could be removed.
Loading history...
81
        'gif',
82
        'jpeg',
83
        'jpg',
84
        'png',
85
        'bmp',
86
        'ico',
87
        'mp4',
88
    ];
89
90
91
    /**
92
     * @return FieldList
93
     */
94
    public function getCMSFields()
95
    {
96
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
97
            // Images tab
98
            $images = SortableUploadField::create('Images')
99
                ->setSortColumn('SortOrder')
100
                ->setIsMultiUpload(true)
101
                ->setAllowedExtensions($this->config()->get('allowed_images_extensions'))
102
                ->setFolderName('Uploads/Products/Images');
103
104
            $fields->addFieldsToTab('Root.Images', [
105
                $images,
106
            ]);
107
        });
108
109
        return parent::getCMSFields();
110
    }
111
}
112