Total Complexity | 114 |
Total Lines | 794 |
Duplicated Lines | 0 % |
Changes | 27 | ||
Bugs | 7 | Features | 2 |
Complex classes like ActionsGridFieldItemRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ActionsGridFieldItemRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class ActionsGridFieldItemRequest extends DataExtension |
||
41 | { |
||
42 | use Configurable; |
||
43 | use Extensible; |
||
44 | |||
45 | /** |
||
46 | * @config |
||
47 | * @var boolean |
||
48 | */ |
||
49 | private static $enable_save_prev_next = true; |
||
50 | |||
51 | /** |
||
52 | * @config |
||
53 | * @var boolean |
||
54 | */ |
||
55 | private static $enable_save_close = true; |
||
56 | |||
57 | /** |
||
58 | * @config |
||
59 | * @var boolean |
||
60 | */ |
||
61 | private static $enable_delete_right = true; |
||
62 | |||
63 | /** |
||
64 | * @config |
||
65 | * @var boolean |
||
66 | */ |
||
67 | private static $enable_utils_prev_next = false; |
||
68 | |||
69 | /** |
||
70 | * @var array Allowed controller actions |
||
71 | */ |
||
72 | private static $allowed_actions = [ |
||
73 | 'doSaveAndClose', |
||
74 | 'doSaveAndNext', |
||
75 | 'doSaveAndPrev', |
||
76 | 'doCustomAction', // For CustomAction |
||
77 | 'doCustomLink', // For CustomLink |
||
78 | ]; |
||
79 | |||
80 | /** |
||
81 | * @return array |
||
82 | */ |
||
83 | protected function getAvailableActions($actions) |
||
84 | { |
||
85 | $list = []; |
||
86 | foreach ($actions as $action) { |
||
87 | if (is_a($action, CompositeField::class)) { |
||
88 | $list = array_merge($list, $this->getAvailableActions($action->FieldList())); |
||
89 | } else { |
||
90 | $list[] = $action->getName(); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | return $list; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Updates the detail form to include new form actions and buttons |
||
99 | * |
||
100 | * This is called by GridFieldDetailForm_ItemRequest |
||
101 | * |
||
102 | * @param Form $form The ItemEditForm object |
||
103 | */ |
||
104 | public function updateItemEditForm($form) |
||
105 | { |
||
106 | $itemRequest = $this->owner; |
||
107 | |||
108 | /** @var DataObject $record */ |
||
109 | $record = $itemRequest->record; |
||
110 | if (!$record) { |
||
111 | $record = $form->getRecord(); |
||
112 | } |
||
113 | if (!$record) { |
||
114 | return; |
||
115 | } |
||
116 | |||
117 | // We get the actions as defined on our record |
||
118 | /** @var FieldList $CMSActions */ |
||
119 | $CMSActions = $record->getCMSActions(); |
||
120 | |||
121 | // address Silverstripe bug when SiteTree buttons are broken |
||
122 | // @link https://github.com/silverstripe/silverstripe-cms/issues/2702 |
||
123 | $CMSActions->setForm($form); |
||
124 | |||
125 | // We can the actions from the GridFieldDetailForm_ItemRequest |
||
126 | // It sets the Save and Delete buttons + Right Group |
||
127 | $actions = $form->Actions(); |
||
128 | |||
129 | // The default button group that contains the Save or Create action |
||
130 | // @link https://docs.silverstripe.org/en/4/developer_guides/customising_the_admin_interface/how_tos/extend_cms_interface/#extending-the-cms-actions |
||
131 | $MajorActions = $actions->fieldByName('MajorActions'); |
||
132 | |||
133 | // If it doesn't exist, push to default group |
||
134 | if (!$MajorActions) { |
||
135 | $MajorActions = $actions; |
||
136 | } |
||
137 | |||
138 | // Push our actions that are otherwise ignored by SilverStripe |
||
139 | foreach ($CMSActions as $action) { |
||
140 | // Avoid duplicated actions (eg: when added by SilverStripe\Versioned\VersionedGridFieldItemRequest) |
||
141 | if ($actions->fieldByName($action->getName())) { |
||
142 | continue; |
||
143 | } |
||
144 | $actions->push($action); |
||
145 | } |
||
146 | |||
147 | // We create a Drop-Up menu afterwards because it may already exist in the $CMSActions |
||
148 | // and we don't want to duplicate it |
||
149 | $this->processDropUpMenu($actions); |
||
150 | |||
151 | // Add extension hook |
||
152 | $this->extend('onBeforeUpdateCMSActions', $actions, $record); |
||
153 | $record->extend('onBeforeUpdateCMSActions', $actions); |
||
154 | |||
155 | $ActionMenus = $actions->fieldByName('ActionMenus'); |
||
156 | // Re-insert ActionMenus to make sure they always follow the buttons |
||
157 | if ($ActionMenus) { |
||
158 | $actions->remove($ActionMenus); |
||
159 | $actions->push($ActionMenus); |
||
160 | } |
||
161 | |||
162 | // We have a 4.4 setup, before that there was no RightGroup |
||
163 | $RightGroup = $actions->fieldByName('RightGroup'); |
||
164 | |||
165 | // Insert again to make sure our actions are properly placed after apply changes |
||
166 | if ($RightGroup) { |
||
167 | $actions->remove($RightGroup); |
||
168 | $actions->push($RightGroup); |
||
169 | } |
||
170 | |||
171 | $opts = [ |
||
172 | 'save_close' => self::config()->enable_save_close, |
||
173 | 'save_prev_next' => self::config()->enable_save_prev_next, |
||
174 | 'delete_right' => self::config()->enable_delete_right, |
||
175 | ]; |
||
176 | if ($record->hasMethod('getCMSActionsOptions')) { |
||
177 | $opts = array_merge($opts, $record->getCMSActionsOptions()); |
||
178 | } |
||
179 | |||
180 | if ($opts['save_close']) { |
||
181 | $this->addSaveAndClose($actions, $record); |
||
182 | } |
||
183 | |||
184 | if ($opts['save_prev_next']) { |
||
185 | $this->addSaveNextAndPrevious($actions, $record); |
||
186 | } |
||
187 | |||
188 | if ($opts['delete_right']) { |
||
189 | $this->moveCancelAndDelete($actions, $record); |
||
190 | } |
||
191 | |||
192 | // Add extension hook |
||
193 | $this->extend('onAfterUpdateCMSActions', $actions, $record); |
||
194 | $record->extend('onAfterUpdateCMSActions', $actions); |
||
195 | } |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Collect all Drop-Up actions into a menu. |
||
200 | * @param FieldList $actions |
||
201 | * @return void |
||
202 | */ |
||
203 | protected function processDropUpMenu($actions) |
||
204 | { |
||
205 | // The Drop-up container may already exist |
||
206 | $dropUpContainer = $actions->fieldByName('ActionMenus.MoreOptions'); |
||
207 | foreach ($actions as $action) { |
||
208 | if ($action->hasMethod('getDropUp') && $action->getDropUp()) { |
||
209 | if (!$dropUpContainer) { |
||
210 | $dropUpContainer = $this->createDropUpContainer($actions); |
||
211 | } |
||
212 | $action->getContainerFieldList()->removeByName($action->getName()); |
||
213 | $dropUpContainer->push($action); |
||
214 | } |
||
215 | } |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * Prepares a Drop-Up menu |
||
220 | * @param FieldList $actions |
||
221 | * @return Tab |
||
222 | */ |
||
223 | protected function createDropUpContainer($actions) |
||
224 | { |
||
225 | $rootTabSet = new TabSet('ActionMenus'); |
||
226 | $dropUpContainer = new Tab( |
||
227 | 'MoreOptions', |
||
228 | _t(__CLASS__ . '.MoreOptions', 'More options', 'Expands a view for more buttons') |
||
229 | ); |
||
230 | $dropUpContainer->addExtraClass('popover-actions-simulate'); |
||
231 | $rootTabSet->push($dropUpContainer); |
||
232 | $rootTabSet->addExtraClass('ss-ui-action-tabset action-menus noborder'); |
||
233 | |||
234 | $actions->insertBefore('RightGroup', $rootTabSet); |
||
235 | |||
236 | return $dropUpContainer; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Check if a record can be edited/created/exists |
||
241 | * @param DataObject $record |
||
242 | * @return bool |
||
243 | */ |
||
244 | protected function checkCan($record) |
||
245 | { |
||
246 | if (!$record->canEdit() || (!$record->ID && !$record->canCreate())) { |
||
247 | return false; |
||
248 | } |
||
249 | |||
250 | return true; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @param FieldList $actions |
||
255 | * @param DataObject $record |
||
256 | * @return void |
||
257 | */ |
||
258 | public function moveCancelAndDelete(FieldList $actions, DataObject $record) |
||
292 | } |
||
293 | } |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * @param DataObject $record |
||
298 | * @return int |
||
299 | */ |
||
300 | public function getCustomPreviousRecordID(DataObject $record) |
||
301 | { |
||
302 | if ($record->hasMethod('PrevRecord')) { |
||
303 | return $record->PrevRecord()->ID ?? 0; |
||
304 | } |
||
305 | |||
306 | return $this->owner->getPreviousRecordID(); |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * @param DataObject $record |
||
311 | * @return int |
||
312 | */ |
||
313 | public function getCustomNextRecordID(DataObject $record) |
||
314 | { |
||
315 | if ($record->hasMethod('NextRecord')) { |
||
316 | return $record->NextRecord()->ID ?? 0; |
||
317 | } |
||
318 | |||
319 | return $this->owner->getNextRecordID(); |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * @param FieldList $actions |
||
324 | * @param DataObject $record |
||
325 | * @return void |
||
326 | */ |
||
327 | public function addSaveNextAndPrevious(FieldList $actions, DataObject $record) |
||
328 | { |
||
329 | if (!$record->canEdit() || !$record->ID) { |
||
330 | return; |
||
331 | } |
||
332 | |||
333 | $MajorActions = $actions->fieldByName('MajorActions'); |
||
334 | |||
335 | // If it doesn't exist, push to default group |
||
336 | if (!$MajorActions) { |
||
337 | $MajorActions = $actions; |
||
338 | } |
||
339 | |||
340 | // TODO: check why with paginator, after the first page, getPreviousRecordID/getNextRecordID tend to not work properly |
||
341 | $getPreviousRecordID = $this->getCustomPreviousRecordID($record); |
||
342 | $getNextRecordID = $this->getCustomNextRecordID($record); |
||
343 | |||
344 | // Coupling for HasPrevNextUtils |
||
345 | if (Controller::has_curr()) { |
||
346 | /** @var HTTPRequest $request */ |
||
347 | $request = Controller::curr()->getRequest(); |
||
348 | $routeParams = $request->routeParams(); |
||
349 | $routeParams['PreviousRecordID'] = $getPreviousRecordID; |
||
350 | $routeParams['NextRecordID'] = $getNextRecordID; |
||
351 | $request->setRouteParams($routeParams); |
||
352 | } |
||
353 | |||
354 | if ($getPreviousRecordID) { |
||
355 | $doSaveAndPrev = new FormAction('doSaveAndPrev', _t('ActionsGridFieldItemRequest.SAVEANDPREVIOUS', 'Save and Previous')); |
||
356 | $doSaveAndPrev->addExtraClass($this->getBtnClassForRecord($record)); |
||
357 | $doSaveAndPrev->addExtraClass('font-icon-angle-double-left btn-mobile-collapse'); |
||
358 | $doSaveAndPrev->setUseButtonTag(true); |
||
359 | $MajorActions->push($doSaveAndPrev); |
||
360 | } |
||
361 | if ($getNextRecordID) { |
||
362 | $doSaveAndNext = new FormAction('doSaveAndNext', _t('ActionsGridFieldItemRequest.SAVEANDNEXT', 'Save and Next')); |
||
363 | $doSaveAndNext->addExtraClass($this->getBtnClassForRecord($record)); |
||
364 | $doSaveAndNext->addExtraClass('font-icon-angle-double-right btn-mobile-collapse'); |
||
365 | $doSaveAndNext->setUseButtonTag(true); |
||
366 | $MajorActions->push($doSaveAndNext); |
||
367 | } |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @param FieldList $actions |
||
372 | * @param DataObject $record |
||
373 | * @return void |
||
374 | */ |
||
375 | public function addSaveAndClose(FieldList $actions, DataObject $record) |
||
376 | { |
||
377 | if (!$this->checkCan($record)) { |
||
378 | return; |
||
379 | } |
||
380 | |||
381 | $MajorActions = $actions->fieldByName('MajorActions'); |
||
382 | |||
383 | // If it doesn't exist, push to default group |
||
384 | if (!$MajorActions) { |
||
385 | $MajorActions = $actions; |
||
386 | } |
||
387 | |||
388 | if ($record->ID) { |
||
389 | $label = _t('ActionsGridFieldItemRequest.SAVEANDCLOSE', 'Save and Close'); |
||
390 | } else { |
||
391 | $label = _t('ActionsGridFieldItemRequest.CREATEANDCLOSE', 'Create and Close'); |
||
392 | } |
||
393 | $saveAndClose = new FormAction('doSaveAndClose', $label); |
||
394 | $saveAndClose->addExtraClass($this->getBtnClassForRecord($record)); |
||
395 | $saveAndClose->setAttribute('data-text-alternate', $label); |
||
396 | if ($record->ID) { |
||
397 | $saveAndClose->setAttribute('data-btn-alternate-add', 'btn-primary'); |
||
398 | $saveAndClose->setAttribute('data-btn-alternate-remove', 'btn-outline-primary'); |
||
399 | } |
||
400 | $saveAndClose->addExtraClass('font-icon-level-up btn-mobile-collapse'); |
||
401 | $saveAndClose->setUseButtonTag(true); |
||
402 | $MajorActions->push($saveAndClose); |
||
403 | } |
||
404 | |||
405 | /** |
||
406 | * New and existing records have different classes |
||
407 | * |
||
408 | * @param DataObject $record |
||
409 | * @return string |
||
410 | */ |
||
411 | protected function getBtnClassForRecord(DataObject $record) |
||
412 | { |
||
413 | if ($record->ID) { |
||
414 | return 'btn-outline-primary'; |
||
415 | } |
||
416 | |||
417 | return 'btn-primary'; |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @param $action |
||
422 | * @param $definedActions |
||
423 | * @return mixed|CompositeField|null |
||
424 | */ |
||
425 | protected static function findAction($action, $definedActions) |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Forward a given action to a DataObject |
||
453 | * |
||
454 | * Action must be declared in getCMSActions to be called |
||
455 | * |
||
456 | * @param string $action |
||
457 | * @param array $data |
||
458 | * @param Form $form |
||
459 | * @return HTTPResponse|DBHTMLText|string |
||
460 | * @throws HTTPResponse_Exception |
||
461 | */ |
||
462 | protected function forwardActionToRecord($action, $data = [], $form = null) |
||
463 | { |
||
464 | $controller = $this->getToplevelController(); |
||
465 | |||
466 | // We have an item request or a controller that can provide a record |
||
467 | $record = null; |
||
468 | if ($this->owner->hasMethod('ItemEditForm')) { |
||
469 | // It's a request handler. Don't check for a specific class as it may be subclassed |
||
470 | $record = $this->owner->record; |
||
471 | } elseif ($controller->hasMethod('save_siteconfig')) { |
||
472 | // Check for any type of siteconfig controller |
||
473 | $record = SiteConfig::current_site_config(); |
||
474 | } elseif (!empty($data['ClassName']) && !empty($data['ID'])) { |
||
475 | $record = DataObject::get_by_id($data['ClassName'], $data['ID']); |
||
476 | } elseif ($controller->hasMethod("getRecord")) { |
||
477 | $record = $controller->getRecord(); |
||
478 | } |
||
479 | |||
480 | if (!$record) { |
||
481 | throw new Exception("No record to handle the action $action on " . get_class($controller)); |
||
482 | } |
||
483 | $definedActions = $record->getCMSActions(); |
||
484 | // Check if the action is indeed available |
||
485 | $clickedAction = null; |
||
486 | if (!empty($definedActions)) { |
||
487 | $clickedAction = self::findAction($action, $definedActions); |
||
488 | } |
||
489 | if (!$clickedAction) { |
||
490 | $class = get_class($record); |
||
491 | $availableActions = implode(',', $this->getAvailableActions($definedActions)); |
||
492 | if (!$availableActions) { |
||
493 | $availableActions = "(no available actions, please check getCMSActions)"; |
||
494 | } |
||
495 | |||
496 | return $this->owner->httpError(403, sprintf( |
||
497 | 'Action not available on %s. It must be one of : %s', |
||
498 | $class, |
||
499 | $availableActions |
||
500 | )); |
||
501 | } |
||
502 | $message = null; |
||
503 | $error = false; |
||
504 | |||
505 | // Check record BEFORE the action |
||
506 | // It can be deleted by the action, and it will return to the list |
||
507 | $isNewRecord = $record->ID === 0; |
||
508 | |||
509 | try { |
||
510 | $result = $record->$action($data, $form, $controller); |
||
511 | |||
512 | // We have a response |
||
513 | if ($result instanceof HTTPResponse) { |
||
514 | return $result; |
||
515 | } |
||
516 | |||
517 | if ($result === false) { |
||
518 | // Result returned an error (false) |
||
519 | $error = true; |
||
520 | $message = _t( |
||
521 | 'ActionsGridFieldItemRequest.FAILED', |
||
522 | 'Action {action} failed on {name}', |
||
523 | ['action' => $clickedAction->getTitle(), 'name' => $record->i18n_singular_name()] |
||
524 | ); |
||
525 | } elseif (is_string($result)) { |
||
526 | // Result is a message |
||
527 | $message = $result; |
||
528 | } |
||
529 | } catch (Exception $ex) { |
||
530 | $error = true; |
||
531 | $message = $ex->getMessage(); |
||
532 | } |
||
533 | |||
534 | // Build default message |
||
535 | if (!$message) { |
||
536 | $message = _t( |
||
537 | 'ActionsGridFieldItemRequest.DONE', |
||
538 | 'Action {action} was done on {name}', |
||
539 | ['action' => $clickedAction->getTitle(), 'name' => $record->i18n_singular_name()] |
||
540 | ); |
||
541 | } |
||
542 | $status = 'good'; |
||
543 | if ($error) { |
||
544 | $status = 'bad'; |
||
545 | } |
||
546 | |||
547 | // Progressive actions return array with json data |
||
548 | if (method_exists($clickedAction, 'getProgressive') && $clickedAction->getProgressive()) { |
||
549 | $response = $controller->getResponse(); |
||
550 | $response->addHeader('Content-Type', 'application/json'); |
||
551 | if ($result) { |
||
552 | $response->setBody(json_encode($result)); |
||
553 | } |
||
554 | |||
555 | return $response; |
||
556 | } |
||
557 | |||
558 | // We don't have a form, simply return the result |
||
559 | if (!$form) { |
||
560 | if ($error) { |
||
561 | return $this->owner->httpError(403, $message); |
||
562 | } |
||
563 | |||
564 | return $message; |
||
565 | } |
||
566 | |||
567 | if (Director::is_ajax()) { |
||
568 | $controller->getResponse()->addHeader('X-Status', rawurlencode($message)); |
||
569 | if (method_exists($clickedAction, 'getShouldRefresh') && $clickedAction->getShouldRefresh()) { |
||
570 | $controller->getResponse()->addHeader('X-Reload', "true"); |
||
571 | } |
||
572 | // 4xx status makes a red box |
||
573 | if ($error) { |
||
574 | $controller->getResponse()->setStatusCode(400); |
||
575 | } |
||
576 | } else { |
||
577 | // If the controller support sessionMessage, use it instead of form |
||
578 | if ($controller->hasMethod('sessionMessage')) { |
||
579 | $controller->sessionMessage($message, $status, ValidationResult::CAST_HTML); |
||
580 | } else { |
||
581 | $form->sessionMessage($message, $status, ValidationResult::CAST_HTML); |
||
582 | } |
||
583 | } |
||
584 | |||
585 | // Custom redirect |
||
586 | if (method_exists($clickedAction, 'getRedirectURL') && $clickedAction->getRedirectURL()) { |
||
587 | $controller->getResponse()->addHeader('X-Reload', "true"); // we probably need a full ui refresh |
||
588 | return $controller->redirect($clickedAction->getRedirectURL()); |
||
589 | } |
||
590 | |||
591 | // Redirect after action |
||
592 | return $this->redirectAfterAction($isNewRecord, $record); |
||
593 | } |
||
594 | |||
595 | /** |
||
596 | * Handles custom links |
||
597 | * |
||
598 | * Use CustomLink with default behaviour to trigger this |
||
599 | * |
||
600 | * See: |
||
601 | * DefaultLink::getModelLink |
||
602 | * GridFieldCustomLink::getLink |
||
603 | * |
||
604 | * @param HTTPRequest $request |
||
605 | * @return HTTPResponse|DBHTMLText|string |
||
606 | * @throws Exception |
||
607 | */ |
||
608 | public function doCustomLink(HTTPRequest $request) |
||
612 | } |
||
613 | |||
614 | /** |
||
615 | * Handles custom actions |
||
616 | * |
||
617 | * Use CustomAction class to trigger this |
||
618 | * |
||
619 | * Nested actions are submitted like this |
||
620 | * [action_doCustomAction] => Array |
||
621 | * ( |
||
622 | * [doTestAction] => 1 |
||
623 | * ) |
||
624 | * |
||
625 | * @param array $data The form data |
||
626 | * @param Form $form The form object |
||
627 | * @return HTTPResponse|DBHTMLText|string |
||
628 | * @throws Exception |
||
629 | */ |
||
630 | public function doCustomAction($data, $form) |
||
635 | } |
||
636 | |||
637 | /** |
||
638 | * Saves the form and goes back to list view |
||
639 | * |
||
640 | * @param array $data The form data |
||
641 | * @param Form $form The form object |
||
642 | */ |
||
643 | public function doSaveAndClose($data, $form) |
||
644 | { |
||
645 | $this->owner->doSave($data, $form); |
||
646 | // Redirect after save |
||
647 | $controller = $this->getToplevelController(); |
||
648 | |||
649 | $link = $this->getBackLink(); |
||
650 | |||
651 | $link = $this->addGridState($link, $data); |
||
652 | |||
653 | $controller->getResponse()->addHeader("X-Pjax", "Content"); |
||
654 | // Prevent Already directed to errors |
||
655 | $controller->getResponse()->addHeader("Location", $link); |
||
656 | |||
657 | return $controller->redirect($link); |
||
658 | } |
||
659 | |||
660 | /** |
||
661 | * Saves the form and goes back to the next item |
||
662 | * |
||
663 | * @param array $data The form data |
||
664 | * @param Form $form The form object |
||
665 | */ |
||
666 | public function doSaveAndNext($data, $form) |
||
667 | { |
||
668 | $record = $this->owner->record; |
||
669 | $this->owner->doSave($data, $form); |
||
670 | // Redirect after save |
||
671 | $controller = $this->getToplevelController(); |
||
672 | $controller->getResponse()->addHeader("X-Pjax", "Content"); |
||
673 | |||
674 | $getNextRecordID = $this->getCustomNextRecordID($record); |
||
675 | $class = get_class($record); |
||
676 | $next = $class::get()->byID($getNextRecordID); |
||
677 | |||
678 | $link = $this->owner->getEditLink($getNextRecordID); |
||
679 | |||
680 | $link = $this->addGridState($link, $data); |
||
681 | |||
682 | // Link to a specific tab if set, see cms-actions.js |
||
683 | if ($next && !empty($data['_activetab'])) { |
||
684 | $link .= sprintf('#%s', $data['_activetab']); |
||
685 | } |
||
686 | |||
687 | return $controller->redirect($link); |
||
688 | } |
||
689 | |||
690 | /** |
||
691 | * Saves the form and goes to the previous item |
||
692 | * |
||
693 | * @param array $data The form data |
||
694 | * @param Form $form The form object |
||
695 | */ |
||
696 | public function doSaveAndPrev($data, $form) |
||
697 | { |
||
698 | $record = $this->owner->record; |
||
699 | $this->owner->doSave($data, $form); |
||
700 | // Redirect after save |
||
701 | $controller = $this->getToplevelController(); |
||
702 | $controller->getResponse()->addHeader("X-Pjax", "Content"); |
||
703 | |||
704 | $getPreviousRecordID = $this->getCustomPreviousRecordID($record); |
||
705 | $class = get_class($record); |
||
706 | $prev = $class::get()->byID($getPreviousRecordID); |
||
707 | |||
708 | $link = $this->owner->getEditLink($getPreviousRecordID); |
||
709 | |||
710 | // Link to a specific tab if set, see cms-actions.js |
||
711 | if ($prev && !empty($data['_activetab'])) { |
||
712 | $link .= sprintf('#%s', $data['_activetab']); |
||
713 | } |
||
714 | |||
715 | return $controller->redirect($link); |
||
716 | } |
||
717 | |||
718 | protected function addGridState($url, $data) |
||
728 | } |
||
729 | |||
730 | /** |
||
731 | * Gets the top level controller. |
||
732 | * |
||
733 | * @return Controller |
||
734 | * @todo This had to be directly copied from {@link GridFieldDetailForm_ItemRequest} |
||
735 | * because it is a protected method and not visible to a decorator! |
||
736 | */ |
||
737 | protected function getToplevelController() |
||
738 | { |
||
739 | if ($this->isLeftAndMain($this->owner)) { |
||
740 | return $this->owner; |
||
741 | } |
||
742 | if (!$this->owner->hasMethod("getController")) { |
||
743 | return Controller::curr(); |
||
744 | } |
||
745 | $controller = $this->owner->getController(); |
||
746 | while ($controller instanceof GridFieldDetailForm_ItemRequest) { |
||
747 | $controller = $controller->getController(); |
||
748 | } |
||
749 | |||
750 | return $controller; |
||
751 | } |
||
752 | |||
753 | protected function isLeftAndMain($controller) |
||
756 | } |
||
757 | |||
758 | /** |
||
759 | * Gets the back link |
||
760 | * |
||
761 | * @return string |
||
762 | * @todo This had to be directly copied from {@link GridFieldDetailForm_ItemRequest} |
||
763 | * because it is a protected method and not visible to a decorator! |
||
764 | */ |
||
765 | public function getBackLink() |
||
781 | } |
||
782 | |||
783 | /** |
||
784 | * Response object for this request after a successful save |
||
785 | * |
||
786 | * @param bool $isNewRecord True if this record was just created |
||
787 | * @param DataObject $record |
||
788 | * @return HTTPResponse|DBHTMLText|string |
||
789 | * @todo This had to be directly copied from {@link GridFieldDetailForm_ItemRequest} |
||
790 | * because it is a protected method and not visible to a decorator! |
||
791 | */ |
||
792 | protected function redirectAfterAction($isNewRecord, $record = null) |
||
836 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths