Completed
Push — master ( 86c16b...d765f6 )
by Robbie
7s
created

CarouselItem::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 27
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 42
rs 8.8571
1
<?php
2
3
namespace CWP\AgencyExtensions\Model;
4
5
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
6
use SilverStripe\Versioned\Versioned;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\Assets\Image;
9
use SilverStripe\CMS\Model\SiteTree;
10
use SilverStripe\Forms\TextField;
11
use SilverStripe\AssetAdmin\Forms\UploadField;
0 ignored issues
show
Bug introduced by
The type SilverStripe\AssetAdmin\Forms\UploadField 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...
12
use SilverStripe\Forms\TreeDropdownField;
13
use SilverStripe\Forms\LabelField;
14
use SilverStripe\Forms\CheckboxField;
15
use SilverStripe\Forms\CompositeField;
16
use SilverStripe\Forms\FieldList;
17
use SilverStripe\ORM\DataObject;
18
use SilverStripe\Forms\FileHandleField;
19
20
class CarouselItem extends DataObject
21
{
22
    private static $table_name = 'CarouselItem';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
23
24
    private static $extensions = [
0 ignored issues
show
introduced by
The private property $extensions is not used, and could be removed.
Loading history...
25
        Versioned::class
26
    ];
27
28
    private static $versioned_gridfield_extensions = true;
0 ignored issues
show
introduced by
The private property $versioned_gridfield_extensions is not used, and could be removed.
Loading history...
29
30
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
31
        'Title' => 'Varchar(255)',
32
        'Content' => 'HTMLText',
33
        'SortOrder' => 'Int',
34
        'PrimaryCallToActionLabel' => 'Varchar(255)',
35
        'SecondaryCallToActionLabel' => 'Varchar(255)'
36
    ];
37
38
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
39
        'Parent' => 'HomePage',
40
        'Image' => Image::class,
41
        'PrimaryCallToAction' => SiteTree::class,
42
        'SecondaryCallToAction' => SiteTree::class
43
    ];
44
45
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
46
        'Image'
47
    ];
48
49
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
50
        'Image.CMSThumbnail' => 'Image',
51
        'Title' => 'Title',
52
        'Content.FirstSentence' => 'Text',
53
        'PrimaryCallToAction.Title' => 'Primary CTA',
54
        'SecondaryCallToAction.Title' => 'Secondary CTA'
55
    ];
56
57
    private static $searchable_fields = [
0 ignored issues
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
58
        'Title',
59
        'Content'
60
    ];
61
62
    public function getCMSFields()
63
    {
64
        $fields = new FieldList(
65
            // Set title
66
            TextField::create('Title', 'Title', null, 255),
0 ignored issues
show
Bug introduced by
'Title' 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

66
            TextField::create(/** @scrutinizer ignore-type */ 'Title', 'Title', null, 255),
Loading history...
Bug introduced by
255 of type integer 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

66
            TextField::create('Title', 'Title', null, /** @scrutinizer ignore-type */ 255),
Loading history...
67
            // Content
68
            HtmlEditorField::create('Content')
69
                ->setRows(5)
70
                ->setDescription(
71
                    _t(
72
                        __CLASS__ . '.CONTENT_HELPTIP',
73
                        'Recommended: Use less than 50 words. For carousel slides, use a similar amount of content ' .
74
                        'as other items to ensure carousel height does not vary.'
75
                    )
76
                ),
77
            // Image
78
            Injector::inst()->create(FileHandleField::class, 'Image', 'Image')
79
                ->setAllowedFileCategories('image')
80
                ->setDescription(
81
                    _t(
82
                        __CLASS__ . '.IMAGE_HELPTIP',
83
                        'Recommended: Use high resolution images greater than 1600x900px.'
84
                    )
85
                ),
86
            // Call to actions
87
            TextField::create('PrimaryCallToActionLabel'),
88
            TreeDropdownField::create(
89
                'PrimaryCallToActionID',
90
                _t(__CLASS__ . '.PRIMARYCALLTOACTION', 'Primary Call To Action Link'),
91
                SiteTree::class
92
            ),
93
            TextField::create('SecondaryCallToActionLabel'),
94
            TreeDropdownField::create(
95
                'SecondaryCallToActionID',
96
                _t(__CLASS__ . '.SECONDARYCALLTOACTION', 'Secondary Call To Action Link'),
97
                SiteTree::class
98
            )
99
        );
100
101
        $this->extend('updateCMSFields', $fields);
102
103
        return $fields;
104
    }
105
106
    public function canCreate($member = null, $context = array())
107
    {
108
        return $this->Parent()->canCreate($member);
0 ignored issues
show
Bug introduced by
The method Parent() does not exist on CWP\AgencyExtensions\Model\CarouselItem. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

108
        return $this->/** @scrutinizer ignore-call */ Parent()->canCreate($member);
Loading history...
109
    }
110
111
    public function canEdit($member = null)
112
    {
113
        return $this->Parent()->canEdit($member);
114
    }
115
116
    public function canDelete($member = null)
117
    {
118
        return $this->Parent()->canDelete($member);
119
    }
120
121
    public function canView($member = null)
122
    {
123
        return $this->Parent()->canView($member);
124
    }
125
}
126