Issues (54)

src/Page/RecipeLanding.php (9 issues)

1
<?php
2
3
namespace Dynamic\RecipeBook\Page;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\GridField\GridField;
7
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
8
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
9
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
10
use SilverStripe\Forms\NumericField;
11
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
12
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
13
14
class RecipeLanding extends \Page
15
{
16
    /**
17
     * @var array
18
     */
19
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
20
        'PerPage' => 'Int',
21
    ];
22
23
    /**
24
     * @var array
25
     */
26
    private static $many_many = [
0 ignored issues
show
The private property $many_many is not used, and could be removed.
Loading history...
27
        'FeaturedCategories' => RecipeCategoryPage::class,
28
    ];
29
30
    /**
31
     * @var array
32
     */
33
    private static $many_many_extraFields = [
0 ignored issues
show
The private property $many_many_extraFields is not used, and could be removed.
Loading history...
34
        'FeaturedCategories' => [
35
            'SortOrder' => 'Int',
36
        ],
37
    ];
38
39
    /**
40
     * @var array
41
     */
42
    private static $defaults = [
0 ignored issues
show
The private property $defaults is not used, and could be removed.
Loading history...
43
        'PerPage' => 9,
44
    ];
45
46
    /**
47
     * @var string
48
     */
49
    private static $singular_name = 'Recipe Landing Page';
0 ignored issues
show
The private property $singular_name is not used, and could be removed.
Loading history...
50
51
    /**
52
     * @var string
53
     */
54
    private static $plural_name = 'Recipe Landing Pages';
0 ignored issues
show
The private property $plural_name is not used, and could be removed.
Loading history...
55
56
    /**
57
     * @var array
58
     */
59
    private static $allowed_children = [
0 ignored issues
show
The private property $allowed_children is not used, and could be removed.
Loading history...
60
        RecipeCategoryPage::class,
61
    ];
62
63
    /**
64
     * @var string
65
     */
66
    private static $table_name = 'RecipeLanding';
0 ignored issues
show
The private property $table_name is not used, and could be removed.
Loading history...
67
68
    /**
69
     * @return \SilverStripe\Forms\FieldList
70
     */
71
    public function getCMSFields()
72
    {
73
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
74
            if ($this->ID) {
75
                $config = GridFieldConfig_RelationEditor::create()
76
                    ->addComponent(new GridFieldOrderableRows('SortOrder'))
77
                    ->removeComponentsByType(GridFieldAddExistingAutocompleter::class)
78
                    ->removeComponentsByType(GridFieldAddNewButton::class)
79
                    ->addComponent(new GridFieldAddExistingSearchButton());
80
                $cats = $this->FeaturedCategories()->sort('SortOrder');
0 ignored issues
show
The method FeaturedCategories() does not exist on Dynamic\RecipeBook\Page\RecipeLanding. 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

80
                $cats = $this->/** @scrutinizer ignore-call */ FeaturedCategories()->sort('SortOrder');
Loading history...
81
                $catsField = GridField::create(
82
                    'FeaturedCategories',
83
                    'Featured Categories',
84
                    $cats,
85
                    $config
86
                );
87
88
                $fields->addFieldsToTab('Root.Featured', array(
89
                    $catsField,
90
                ));
91
            }
92
93
            $fields->addFieldsToTab('Root.Browse', [
94
                NumericField::create('PerPage', 'Categories per page'),
95
            ]);
96
        });
97
98
        return parent::getCMSFields();
99
    }
100
101
    /**
102
     * @return mixed
103
     */
104
    public function getFeaturedList()
105
    {
106
        return $this->FeaturedCategories()->sort('SortOrder');
107
    }
108
}
109