We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
12 | class PageCrudController extends CrudController |
||
13 | { |
||
14 | use PageTemplates; |
||
15 | use TraitReflections; |
||
16 | |||
17 | public function setup($template_name = false) |
||
18 | { |
||
19 | parent::__construct(); |
||
20 | |||
21 | $modelClass = config('backpack.pagemanager.page_model_class', 'Backpack\PageManager\app\Models\Page'); |
||
22 | |||
23 | $this->checkForTemplatesAndUniquePagesNotDistinct(); |
||
24 | |||
25 | /* |
||
26 | |-------------------------------------------------------------------------- |
||
27 | | BASIC CRUD INFORMATION |
||
28 | |-------------------------------------------------------------------------- |
||
29 | */ |
||
30 | $this->crud->setModel($modelClass); |
||
31 | $this->crud->setRoute(config('backpack.base.route_prefix').'/page'); |
||
32 | $this->crud->setEntityNameStrings(trans('backpack::pagemanager.page'), trans('backpack::pagemanager.pages')); |
||
33 | |||
34 | $template_names = $this->getTemplateNames(); |
||
35 | $this->crud->addClause('whereIn', 'template', $template_names); |
||
36 | |||
37 | |||
38 | /* |
||
39 | |-------------------------------------------------------------------------- |
||
40 | | COLUMNS |
||
41 | |-------------------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | $this->crud->addColumn([ |
||
45 | 'name' => 'name', |
||
46 | 'label' => trans('backpack::pagemanager.name'), |
||
47 | ]); |
||
48 | $this->crud->addColumn([ |
||
49 | 'name' => 'template', |
||
50 | 'label' => trans('backpack::pagemanager.template'), |
||
51 | 'type' => 'model_function', |
||
52 | 'function_name' => 'getTemplateName', |
||
53 | ]); |
||
54 | $this->crud->addColumn([ |
||
55 | 'name' => 'slug', |
||
56 | 'label' => trans('backpack::pagemanager.slug'), |
||
57 | ]); |
||
58 | |||
59 | /* |
||
60 | |-------------------------------------------------------------------------- |
||
61 | | FIELDS |
||
62 | |-------------------------------------------------------------------------- |
||
63 | */ |
||
64 | |||
65 | // In PageManager, |
||
66 | // - default fields, that all templates are using, are set using $this->addDefaultPageFields(); |
||
67 | // - template-specific fields are set per-template, in the PageTemplates trait; |
||
68 | |||
69 | /* |
||
70 | |-------------------------------------------------------------------------- |
||
71 | | BUTTONS |
||
72 | |-------------------------------------------------------------------------- |
||
73 | */ |
||
74 | $this->crud->addButtonFromModelFunction('line', 'open', 'getOpenButton', 'beginning'); |
||
75 | } |
||
76 | |||
77 | // ----------------------------------------------- |
||
78 | // Overwrites of CrudController |
||
79 | // ----------------------------------------------- |
||
80 | |||
81 | // Overwrites the CrudController create() method to add template usage. |
||
82 | public function create($template = false) |
||
83 | { |
||
84 | $this->addDefaultPageFields($template); |
||
85 | $this->useTemplate($template); |
||
86 | |||
87 | return parent::create(); |
||
88 | } |
||
89 | |||
90 | // Overwrites the CrudController store() method to add template usage. |
||
91 | public function store(StoreRequest $request) |
||
92 | { |
||
93 | $this->addDefaultPageFields(\Request::input('template')); |
||
94 | $this->useTemplate(\Request::input('template')); |
||
95 | |||
96 | return parent::storeCrud(); |
||
97 | } |
||
98 | |||
99 | // Overwrites the CrudController edit() method to add template usage. |
||
100 | public function edit($id, $template = false) |
||
101 | { |
||
102 | // if the template in the GET parameter is missing, figure it out from the db |
||
103 | if ($template == false) { |
||
104 | $model = $this->crud->model; |
||
105 | $this->data['entry'] = $model::findOrFail($id); |
||
106 | $template = $this->data['entry']->template; |
||
107 | } |
||
108 | |||
109 | $this->addDefaultPageFields($template); |
||
110 | $this->useTemplate($template); |
||
111 | |||
112 | return parent::edit($id); |
||
113 | } |
||
114 | |||
115 | // Overwrites the CrudController update() method to add template usage. |
||
116 | public function update(UpdateRequest $request) |
||
117 | { |
||
118 | $this->addDefaultPageFields(\Request::input('template')); |
||
119 | $this->useTemplate(\Request::input('template')); |
||
120 | |||
121 | return parent::updateCrud(); |
||
122 | } |
||
123 | |||
124 | // ----------------------------------------------- |
||
125 | // Methods that are particular to the PageManager. |
||
126 | // ----------------------------------------------- |
||
127 | |||
128 | /** |
||
129 | * Populate the create/update forms with basic fields, that all pages need. |
||
130 | * |
||
131 | * @param string $template The name of the template that should be used in the current form. |
||
132 | */ |
||
133 | public function addDefaultPageFields($template = false) |
||
134 | { |
||
135 | $this->crud->addField([ |
||
136 | 'name' => 'template', |
||
137 | 'label' => trans('backpack::pagemanager.template'), |
||
138 | 'type' => 'select_page_template', |
||
139 | 'options' => $this->getTemplatesArray(), |
||
140 | 'value' => $template, |
||
141 | 'allows_null' => false, |
||
142 | 'wrapperAttributes' => [ |
||
143 | 'class' => 'form-group col-md-6', |
||
144 | ], |
||
145 | ]); |
||
146 | $this->crud->addField([ |
||
147 | 'name' => 'name', |
||
148 | 'label' => trans('backpack::pagemanager.page_name'), |
||
149 | 'type' => 'text', |
||
150 | 'wrapperAttributes' => [ |
||
151 | 'class' => 'form-group col-md-6', |
||
152 | ], |
||
153 | // 'disabled' => 'disabled' |
||
154 | ]); |
||
155 | $this->crud->addField([ |
||
156 | 'name' => 'title', |
||
157 | 'label' => trans('backpack::pagemanager.page_title'), |
||
158 | 'type' => 'text', |
||
159 | // 'disabled' => 'disabled' |
||
160 | ]); |
||
161 | $this->crud->addField([ |
||
162 | 'name' => 'slug', |
||
163 | 'label' => trans('backpack::pagemanager.page_slug'), |
||
164 | 'type' => 'text', |
||
165 | 'hint' => trans('backpack::pagemanager.page_slug_hint'), |
||
166 | // 'disabled' => 'disabled' |
||
167 | ]); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Add the fields defined for a specific template. |
||
172 | * |
||
173 | * @param string $template_name The name of the template that should be used in the current form. |
||
174 | */ |
||
175 | public function useTemplate($template_name = false) |
||
176 | { |
||
177 | $templates = $this->getTemplates(); |
||
178 | |||
179 | // set the default template |
||
180 | if ($template_name == false) { |
||
181 | $template_name = $templates[0]->name; |
||
182 | } |
||
183 | |||
184 | // actually use the template |
||
185 | if ($template_name) { |
||
186 | $this->{$template_name}(); |
||
187 | } |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Get all defined template as an array. |
||
192 | * |
||
193 | * Used to populate the template dropdown in the create/update forms. |
||
194 | */ |
||
195 | public function getTemplatesArray() |
||
205 | } |
||
206 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.