Completed
Pull Request — master (#30)
by Jason
17:47 queued 02:47
created

ProductDoc::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 26
rs 8.8571
1
<?php
2
3
namespace Dynamic\ProductCatalog\docs;
4
5
use SilverStripe\AssetAdmin\Forms\UploadField;
6
use SilverStripe\Assets\File;
7
use SilverStripe\Assets\Image;
8
use SilverStripe\Forms\TextField;
9
use SilverStripe\ORM\DataObject;
10
11
class ProductDoc extends DataObject
12
{
13
    /**
14
     * @var array
15
     */
16
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
17
        'Name' => 'Varchar(255)',
18
        'Title' => 'Varchar(255)',
19
        'Content' => 'HTMLText',
20
        'FileLink' => 'Varchar(255)',
21
    );
22
23
    /**
24
     * @var array
25
     */
26
    private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
27
        'Image' => Image::class,
28
        'Download' => File::class,
29
    );
30
31
    /**
32
     * @var string
33
     */
34
    private static $table_name = 'ProductDoc';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
35
36
    /**
37
     * @var array
38
     */
39
    private static $summary_fields = array(
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
40
        'Name' => 'Name',
41
        'Title' => 'Title',
42
    );
43
44
    /**
45
     * @var array
46
     */
47
    private static $searchable_fields = array(
0 ignored issues
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
48
        'Name',
49
        'Title',
50
    );
51
52
    /**
53
     * @var string
54
     */
55
    private static $default_sort = 'Title';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
56
57
    /**
58
     * @return \SilverStripe\Forms\FieldList
59
     */
60
    public function getCMSFields()
61
    {
62
        $fields = parent::getCMSFields();
63
64
        $file = UploadField::create('Download')
0 ignored issues
show
Bug introduced by
'Download' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
        $file = UploadField::create(/** @scrutinizer ignore-type */ 'Download')
Loading history...
65
            //->setFolderName('Uploads/FileDownloads')
66
            //->setConfig('allowedMaxFileNumber', 1)
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
            //->setAllowedFileCategories('doc')
68
            //->setAllowedMaxFileNumber(1)
69
        ;
70
71
        $fields->addFieldsToTab('Root.Download', array(
72
            $file,
73
            TextField::create('FileLink')
74
                ->setDescription('URL of external file. will display on page if no Download is specified above.')
75
                ->setAttribute('placeholder', 'http://'),
76
        ));
77
78
        $fields->insertBefore(
79
            UploadField::create('Image')
80
                //->setFolderName('Uploads/ProductDocs/Images')
81
                ->setDescription('Preview image of file'),
82
            'Content'
0 ignored issues
show
Bug introduced by
'Content' of type string is incompatible with the type SilverStripe\Forms\FormField expected by parameter $item of SilverStripe\Forms\FieldList::insertBefore(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
            /** @scrutinizer ignore-type */ 'Content'
Loading history...
83
        );
84
85
        return $fields;
86
    }
87
88
    /**
89
     * if SetClass dropdown is set, create a new instance of the new class.
90
     */
91
    public function onAfterWrite()
92
    {
93
        parent::onAfterWrite();
94
        if (isset($_REQUEST['SetClass'])) {
95
            $object = $this->newClassInstance($_REQUEST['SetClass']);
96
            $object->write();
97
        }
98
    }
99
}
100