Complex classes like GridFieldDetailForm_ItemRequest 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 GridFieldDetailForm_ItemRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 243 | class GridFieldDetailForm_ItemRequest extends RequestHandler { |
||
| 244 | |||
| 245 | private static $allowed_actions = array( |
||
| 246 | 'edit', |
||
| 247 | 'view', |
||
| 248 | 'ItemEditForm' |
||
| 249 | ); |
||
| 250 | |||
| 251 | /** |
||
| 252 | * |
||
| 253 | * @var GridField |
||
| 254 | */ |
||
| 255 | protected $gridField; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * |
||
| 259 | * @var GridFieldDetailForm |
||
| 260 | */ |
||
| 261 | protected $component; |
||
| 262 | |||
| 263 | /** |
||
| 264 | * |
||
| 265 | * @var DataObject |
||
| 266 | */ |
||
| 267 | protected $record; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * This represents the current parent RequestHandler (which does not necessarily need to be a Controller). |
||
| 271 | * It allows us to traverse the RequestHandler chain upwards to reach the Controller stack. |
||
| 272 | * |
||
| 273 | * @var RequestHandler |
||
| 274 | */ |
||
| 275 | protected $popupController; |
||
| 276 | |||
| 277 | /** |
||
| 278 | * |
||
| 279 | * @var string |
||
| 280 | */ |
||
| 281 | protected $popupFormName; |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @var String |
||
| 285 | */ |
||
| 286 | protected $template = null; |
||
| 287 | |||
| 288 | private static $url_handlers = array( |
||
| 289 | '$Action!' => '$Action', |
||
| 290 | '' => 'edit', |
||
| 291 | ); |
||
| 292 | |||
| 293 | /** |
||
| 294 | * |
||
| 295 | * @param GridFIeld $gridField |
||
| 296 | * @param GridFieldDetailForm $component |
||
| 297 | * @param DataObject $record |
||
| 298 | * @param RequestHandler $requestHandler |
||
| 299 | * @param string $popupFormName |
||
| 300 | */ |
||
| 301 | public function __construct($gridField, $component, $record, $requestHandler, $popupFormName) { |
||
| 309 | |||
| 310 | public function Link($action = null) { |
||
| 314 | |||
| 315 | public function view($request) { |
||
| 316 | if(!$this->record->canView()) { |
||
| 317 | $this->httpError(403); |
||
| 318 | } |
||
| 319 | |||
| 320 | $controller = $this->getToplevelController(); |
||
| 321 | |||
| 322 | $form = $this->ItemEditForm(); |
||
| 323 | $form->makeReadonly(); |
||
| 324 | |||
| 325 | $data = new ArrayData(array( |
||
| 326 | 'Backlink' => $controller->Link(), |
||
| 327 | 'ItemEditForm' => $form |
||
| 328 | )); |
||
| 329 | $return = $data->renderWith($this->getTemplates()); |
||
| 330 | |||
| 331 | if($request->isAjax()) { |
||
| 332 | return $return; |
||
| 333 | } else { |
||
| 334 | return $controller->customise(array('Content' => $return)); |
||
| 335 | } |
||
| 336 | } |
||
| 337 | |||
| 338 | public function edit($request) { |
||
| 339 | $controller = $this->getToplevelController(); |
||
| 340 | $form = $this->ItemEditForm(); |
||
| 341 | |||
| 342 | $return = $this->customise(array( |
||
| 343 | 'Backlink' => $controller->hasMethod('Backlink') ? $controller->Backlink() : $controller->Link(), |
||
| 344 | 'ItemEditForm' => $form, |
||
| 345 | ))->renderWith($this->getTemplates()); |
||
| 346 | |||
| 347 | if($request->isAjax()) { |
||
| 348 | return $return; |
||
| 349 | } else { |
||
| 350 | // If not requested by ajax, we need to render it within the controller context+template |
||
| 351 | return $controller->customise(array( |
||
| 352 | // TODO CMS coupling |
||
| 353 | 'Content' => $return, |
||
| 354 | )); |
||
| 355 | } |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Builds an item edit form. The arguments to getCMSFields() are the popupController and |
||
| 360 | * popupFormName, however this is an experimental API and may change. |
||
| 361 | * |
||
| 362 | * @todo In the future, we will probably need to come up with a tigher object representing a partially |
||
| 363 | * complete controller with gaps for extra functionality. This, for example, would be a better way |
||
| 364 | * of letting Security/login put its log-in form inside a UI specified elsewhere. |
||
| 365 | * |
||
| 366 | * @return Form |
||
| 367 | */ |
||
| 368 | public function ItemEditForm() { |
||
| 369 | $list = $this->gridField->getList(); |
||
| 370 | |||
| 371 | if (empty($this->record)) { |
||
| 372 | $controller = $this->getToplevelController(); |
||
| 373 | $url = $controller->getRequest()->getURL(); |
||
| 374 | $noActionURL = $controller->removeAction($url); |
||
| 375 | $controller->getResponse()->removeHeader('Location'); //clear the existing redirect |
||
| 376 | return $controller->redirect($noActionURL, 302); |
||
| 377 | } |
||
| 378 | |||
| 379 | $canView = $this->record->canView(); |
||
| 380 | $canEdit = $this->record->canEdit(); |
||
| 381 | $canDelete = $this->record->canDelete(); |
||
| 382 | $canCreate = $this->record->canCreate(); |
||
| 383 | |||
| 384 | if(!$canView) { |
||
| 385 | $controller = $this->getToplevelController(); |
||
| 386 | // TODO More friendly error |
||
| 387 | return $controller->httpError(403); |
||
| 388 | } |
||
| 389 | |||
| 390 | // Build actions |
||
| 391 | $actions = $this->getFormActions(); |
||
| 392 | |||
| 393 | // If we are creating a new record in a has-many list, then |
||
| 394 | // pre-populate the record's foreign key. |
||
| 395 | if($list instanceof HasManyList && !$this->record->isInDB()) { |
||
| 396 | $key = $list->getForeignKey(); |
||
| 397 | $id = $list->getForeignID(); |
||
| 398 | $this->record->$key = $id; |
||
| 399 | } |
||
| 400 | |||
| 401 | $fields = $this->component->getFields(); |
||
| 402 | if(!$fields) $fields = $this->record->getCMSFields(); |
||
| 403 | |||
| 404 | // If we are creating a new record in a has-many list, then |
||
| 405 | // Disable the form field as it has no effect. |
||
| 406 | if($list instanceof HasManyList) { |
||
| 407 | $key = $list->getForeignKey(); |
||
| 408 | |||
| 409 | if($field = $fields->dataFieldByName($key)) { |
||
| 410 | $fields->makeFieldReadonly($field); |
||
| 411 | } |
||
| 412 | } |
||
| 413 | |||
| 414 | // Caution: API violation. Form expects a Controller, but we are giving it a RequestHandler instead. |
||
| 415 | // Thanks to this however, we are able to nest GridFields, and also access the initial Controller by |
||
| 416 | // dereferencing GridFieldDetailForm_ItemRequest->getController() multiple times. See getToplevelController |
||
| 417 | // below. |
||
| 418 | $form = new Form( |
||
| 419 | $this, |
||
| 420 | 'ItemEditForm', |
||
| 421 | $fields, |
||
| 422 | $actions, |
||
| 423 | $this->component->getValidator() |
||
| 424 | ); |
||
| 425 | |||
| 426 | $form->loadDataFrom($this->record, $this->record->ID == 0 ? Form::MERGE_IGNORE_FALSEISH : Form::MERGE_DEFAULT); |
||
| 427 | |||
| 428 | if($this->record->ID && !$canEdit) { |
||
| 429 | // Restrict editing of existing records |
||
| 430 | $form->makeReadonly(); |
||
| 431 | // Hack to re-enable delete button if user can delete |
||
| 432 | if ($canDelete) { |
||
| 433 | $form->Actions()->fieldByName('action_doDelete')->setReadonly(false); |
||
| 434 | } |
||
| 435 | } elseif(!$this->record->ID && !$canCreate) { |
||
| 436 | // Restrict creation of new records |
||
| 437 | $form->makeReadonly(); |
||
| 438 | } |
||
| 439 | |||
| 440 | // Load many_many extraData for record. |
||
| 441 | // Fields with the correct 'ManyMany' namespace need to be added manually through getCMSFields(). |
||
| 442 | if($list instanceof ManyManyList) { |
||
| 443 | $extraData = $list->getExtraData('', $this->record->ID); |
||
| 444 | $form->loadDataFrom(array('ManyMany' => $extraData)); |
||
| 445 | } |
||
| 446 | |||
| 447 | // TODO Coupling with CMS |
||
| 448 | $toplevelController = $this->getToplevelController(); |
||
| 449 | if($toplevelController && $toplevelController instanceof LeftAndMain) { |
||
| 450 | // Always show with base template (full width, no other panels), |
||
| 451 | // regardless of overloaded CMS controller templates. |
||
| 452 | // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller |
||
| 453 | $form->setTemplate([ |
||
| 454 | 'type' => 'Includes', |
||
| 455 | 'SilverStripe\\Admin\\LeftAndMain_EditForm', |
||
| 456 | ]); |
||
| 457 | $form->addExtraClass('cms-content cms-edit-form center'); |
||
| 458 | $form->setAttribute('data-pjax-fragment', 'CurrentForm Content'); |
||
| 459 | if($form->Fields()->hasTabset()) { |
||
| 460 | $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); |
||
| 461 | $form->addExtraClass('cms-tabset'); |
||
| 462 | } |
||
| 463 | |||
| 464 | $form->Backlink = $this->getBackLink(); |
||
| 465 | } |
||
| 466 | |||
| 467 | $cb = $this->component->getItemEditFormCallback(); |
||
| 468 | if($cb) $cb($form, $this); |
||
| 469 | $this->extend("updateItemEditForm", $form); |
||
| 470 | return $form; |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Build the set of form field actions for this DataObject |
||
| 475 | * |
||
| 476 | * @return FieldList |
||
| 477 | */ |
||
| 478 | protected function getFormActions() { |
||
| 479 | $canEdit = $this->record->canEdit(); |
||
| 480 | $canDelete = $this->record->canDelete(); |
||
| 481 | $actions = new FieldList(); |
||
| 482 | if($this->record->ID !== 0) { |
||
| 483 | if($canEdit) { |
||
| 484 | $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save')) |
||
| 485 | ->setUseButtonTag(true) |
||
| 486 | ->addExtraClass('ss-ui-action-constructive') |
||
| 487 | ->setAttribute('data-icon', 'accept')); |
||
| 488 | } |
||
| 489 | |||
| 490 | if($canDelete) { |
||
| 491 | $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete')) |
||
| 492 | ->setUseButtonTag(true) |
||
| 493 | ->addExtraClass('ss-ui-action-destructive action-delete')); |
||
| 494 | } |
||
| 495 | |||
| 496 | } else { // adding new record |
||
| 497 | //Change the Save label to 'Create' |
||
| 498 | $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create')) |
||
| 499 | ->setUseButtonTag(true) |
||
| 500 | ->addExtraClass('ss-ui-action-constructive') |
||
| 501 | ->setAttribute('data-icon', 'add')); |
||
| 502 | |||
| 503 | // Add a Cancel link which is a button-like link and link back to one level up. |
||
| 504 | $crumbs = $this->Breadcrumbs(); |
||
| 505 | if($crumbs && $crumbs->count() >= 2){ |
||
| 506 | $oneLevelUp = $crumbs->offsetGet($crumbs->count() - 2); |
||
| 507 | $text = sprintf( |
||
| 508 | "<a class=\"%s\" href=\"%s\">%s</a>", |
||
| 509 | "crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all", // CSS classes |
||
| 510 | $oneLevelUp->Link, // url |
||
| 511 | _t('GridFieldDetailForm.CancelBtn', 'Cancel') // label |
||
| 512 | ); |
||
| 513 | $actions->push(new LiteralField('cancelbutton', $text)); |
||
| 514 | } |
||
| 515 | } |
||
| 516 | $this->extend('updateFormActions', $actions); |
||
| 517 | return $actions; |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Traverse the nested RequestHandlers until we reach something that's not GridFieldDetailForm_ItemRequest. |
||
| 522 | * This allows us to access the Controller responsible for invoking the top-level GridField. |
||
| 523 | * This should be equivalent to getting the controller off the top of the controller stack via Controller::curr(), |
||
| 524 | * but allows us to avoid accessing the global state. |
||
| 525 | * |
||
| 526 | * GridFieldDetailForm_ItemRequests are RequestHandlers, and as such they are not part of the controller stack. |
||
| 527 | * |
||
| 528 | * @return Controller |
||
| 529 | */ |
||
| 530 | protected function getToplevelController() { |
||
| 531 | $c = $this->popupController; |
||
| 532 | while($c && $c instanceof GridFieldDetailForm_ItemRequest) { |
||
| 533 | $c = $c->getController(); |
||
| 534 | } |
||
| 535 | return $c; |
||
| 536 | } |
||
| 537 | |||
| 538 | protected function getBackLink(){ |
||
| 539 | // TODO Coupling with CMS |
||
| 540 | $backlink = ''; |
||
| 541 | $toplevelController = $this->getToplevelController(); |
||
| 542 | if($toplevelController && $toplevelController instanceof LeftAndMain) { |
||
| 543 | if($toplevelController->hasMethod('Backlink')) { |
||
| 544 | $backlink = $toplevelController->Backlink(); |
||
| 545 | } elseif($this->popupController->hasMethod('Breadcrumbs')) { |
||
| 546 | $parents = $this->popupController->Breadcrumbs(false)->items; |
||
| 547 | $backlink = array_pop($parents)->Link; |
||
| 548 | } |
||
| 549 | } |
||
| 550 | if(!$backlink) $backlink = $toplevelController->Link(); |
||
| 551 | |||
| 552 | return $backlink; |
||
| 553 | } |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Get the list of extra data from the $record as saved into it by |
||
| 557 | * {@see Form::saveInto()} |
||
| 558 | * |
||
| 559 | * Handles detection of falsey values explicitly saved into the |
||
| 560 | * DataObject by formfields |
||
| 561 | * |
||
| 562 | * @param DataObject $record |
||
| 563 | * @param SS_List $list |
||
| 564 | * @return array List of data to write to the relation |
||
| 565 | */ |
||
| 566 | protected function getExtraSavedData($record, $list) { |
||
| 567 | // Skip extra data if not ManyManyList |
||
| 568 | if(!($list instanceof ManyManyList)) { |
||
| 569 | return null; |
||
| 570 | } |
||
| 571 | |||
| 572 | $data = array(); |
||
| 573 | foreach($list->getExtraFields() as $field => $dbSpec) { |
||
| 574 | $savedField = "ManyMany[{$field}]"; |
||
| 575 | if($record->hasField($savedField)) { |
||
| 576 | $data[$field] = $record->getField($savedField); |
||
| 577 | } |
||
| 578 | } |
||
| 579 | return $data; |
||
| 580 | } |
||
| 581 | |||
| 582 | public function doSave($data, $form) { |
||
| 583 | $isNewRecord = $this->record->ID == 0; |
||
| 584 | |||
| 585 | // Check permission |
||
| 586 | if (!$this->record->canEdit()) { |
||
| 587 | return $this->httpError(403); |
||
| 588 | } |
||
| 589 | |||
| 590 | // Save from form data |
||
| 591 | try { |
||
| 592 | $this->saveFormIntoRecord($data, $form); |
||
| 593 | } catch (ValidationException $e) { |
||
| 594 | return $this->generateValidationResponse($form, $e); |
||
| 595 | } |
||
| 596 | |||
| 597 | $link = '<a href="' . $this->Link('edit') . '">"' |
||
| 598 | . htmlspecialchars($this->record->Title, ENT_QUOTES) |
||
| 599 | . '"</a>'; |
||
| 600 | $message = _t( |
||
| 601 | 'GridFieldDetailForm.Saved', |
||
| 602 | 'Saved {name} {link}', |
||
| 603 | array( |
||
| 604 | 'name' => $this->record->i18n_singular_name(), |
||
| 605 | 'link' => $link |
||
| 606 | ) |
||
| 607 | ); |
||
| 608 | |||
| 609 | $form->sessionMessage($message, 'good', false); |
||
| 610 | |||
| 611 | // Redirect after save |
||
| 612 | return $this->redirectAfterSave($isNewRecord); |
||
| 613 | } |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Response object for this request after a successful save |
||
| 617 | * |
||
| 618 | * @param bool $isNewRecord True if this record was just created |
||
| 619 | * @return SS_HTTPResponse|DBHTMLText |
||
| 620 | */ |
||
| 621 | protected function redirectAfterSave($isNewRecord) { |
||
| 622 | $controller = $this->getToplevelController(); |
||
| 623 | if($isNewRecord) { |
||
| 624 | return $controller->redirect($this->Link()); |
||
| 625 | } elseif($this->gridField->getList()->byID($this->record->ID)) { |
||
| 626 | // Return new view, as we can't do a "virtual redirect" via the CMS Ajax |
||
| 627 | // to the same URL (it assumes that its content is already current, and doesn't reload) |
||
| 628 | return $this->edit($controller->getRequest()); |
||
| 629 | } else { |
||
| 630 | // Changes to the record properties might've excluded the record from |
||
| 631 | // a filtered list, so return back to the main view if it can't be found |
||
| 632 | $url = $controller->getRequest()->getURL(); |
||
| 633 | $noActionURL = $controller->removeAction($url); |
||
| 634 | $controller->getRequest()->addHeader('X-Pjax', 'Content'); |
||
| 635 | return $controller->redirect($noActionURL, 302); |
||
| 636 | } |
||
| 637 | } |
||
| 638 | |||
| 639 | public function httpError($errorCode, $errorMessage = null) { |
||
| 640 | $controller = $this->getToplevelController(); |
||
| 641 | return $controller->httpError($errorCode, $errorMessage); |
||
| 642 | } |
||
| 643 | |||
| 644 | /** |
||
| 645 | * Loads the given form data into the underlying dataobject and relation |
||
| 646 | * |
||
| 647 | * @param array $data |
||
| 648 | * @param Form $form |
||
| 649 | * @throws ValidationException On error |
||
| 650 | * @return DataObject Saved record |
||
| 651 | */ |
||
| 652 | protected function saveFormIntoRecord($data, $form) { |
||
| 653 | $list = $this->gridField->getList(); |
||
| 654 | |||
| 655 | // Check object matches the correct classname |
||
| 656 | if (isset($data['ClassName']) && $data['ClassName'] != $this->record->ClassName) { |
||
| 657 | $newClassName = $data['ClassName']; |
||
| 658 | // The records originally saved attribute was overwritten by $form->saveInto($record) before. |
||
| 659 | // This is necessary for newClassInstance() to work as expected, and trigger change detection |
||
| 660 | // on the ClassName attribute |
||
| 661 | $this->record->setClassName($this->record->ClassName); |
||
| 662 | // Replace $record with a new instance |
||
| 663 | $this->record = $this->record->newClassInstance($newClassName); |
||
| 664 | } |
||
| 665 | |||
| 666 | // Save form and any extra saved data into this dataobject |
||
| 667 | $form->saveInto($this->record); |
||
| 668 | $this->record->write(); |
||
| 669 | $extraData = $this->getExtraSavedData($this->record, $list); |
||
| 670 | $list->add($this->record, $extraData); |
||
| 671 | |||
| 672 | return $this->record; |
||
| 673 | } |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Generate a response object for a form validation error |
||
| 677 | * |
||
| 678 | * @param Form $form The source form |
||
| 679 | * @param ValidationException $e The validation error message |
||
| 680 | * @return SS_HTTPResponse |
||
| 681 | * @throws SS_HTTPResponse_Exception |
||
| 682 | */ |
||
| 683 | protected function generateValidationResponse($form, $e) { |
||
| 684 | $controller = $this->getToplevelController(); |
||
| 685 | |||
| 686 | $form->sessionMessage($e->getResult()->message(), 'bad', false); |
||
| 687 | $responseNegotiator = new PjaxResponseNegotiator(array( |
||
| 688 | 'CurrentForm' => function() use(&$form) { |
||
| 689 | return $form->forTemplate(); |
||
| 690 | }, |
||
| 691 | 'default' => function() use(&$controller) { |
||
| 692 | return $controller->redirectBack(); |
||
| 693 | } |
||
| 694 | )); |
||
| 695 | if($controller->getRequest()->isAjax()){ |
||
| 696 | $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm'); |
||
| 697 | } |
||
| 698 | return $responseNegotiator->respond($controller->getRequest()); |
||
| 699 | } |
||
| 700 | |||
| 701 | |||
| 702 | public function doDelete($data, $form) { |
||
| 703 | $title = $this->record->Title; |
||
| 704 | $backLink = $this->getBacklink(); |
||
| 705 | try { |
||
| 706 | if (!$this->record->canDelete()) { |
||
| 707 | throw new ValidationException( |
||
| 708 | _t('GridFieldDetailForm.DeletePermissionsFailure',"No delete permissions"),0); |
||
| 709 | } |
||
| 710 | |||
| 711 | $this->record->delete(); |
||
| 712 | } catch(ValidationException $e) { |
||
| 713 | $form->sessionMessage($e->getResult()->message(), 'bad', false); |
||
| 714 | return $this->getToplevelController()->redirectBack(); |
||
| 715 | } |
||
| 716 | |||
| 717 | $message = sprintf( |
||
| 718 | _t('GridFieldDetailForm.Deleted', 'Deleted %s %s'), |
||
| 719 | $this->record->i18n_singular_name(), |
||
| 720 | htmlspecialchars($title, ENT_QUOTES) |
||
| 721 | ); |
||
| 722 | |||
| 723 | $toplevelController = $this->getToplevelController(); |
||
| 724 | if($toplevelController && $toplevelController instanceof LeftAndMain) { |
||
| 725 | $backForm = $toplevelController->getEditForm(); |
||
| 726 | $backForm->sessionMessage($message, 'good', false); |
||
| 727 | } else { |
||
| 728 | $form->sessionMessage($message, 'good', false); |
||
| 729 | } |
||
| 730 | |||
| 731 | //when an item is deleted, redirect to the parent controller |
||
| 732 | $controller = $this->getToplevelController(); |
||
| 733 | $controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh |
||
| 734 | |||
| 735 | return $controller->redirect($backLink, 302); //redirect back to admin section |
||
| 736 | } |
||
| 737 | |||
| 738 | /** |
||
| 739 | * @param string $template |
||
| 740 | * @return $this |
||
| 741 | */ |
||
| 742 | public function setTemplate($template) { |
||
| 746 | |||
| 747 | /** |
||
| 748 | * @return String |
||
| 749 | */ |
||
| 750 | public function getTemplate() { |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Get list of templates to use |
||
| 756 | * |
||
| 757 | * @return array |
||
| 758 | */ |
||
| 759 | public function getTemplates() |
||
| 760 | { |
||
| 761 | $templates = SSViewer::get_templates_by_class($this, '', __CLASS__); |
||
| 762 | // Prefer any custom template |
||
| 763 | if($this->getTemplate()) { |
||
| 764 | array_unshift($templates, $this->getTemplate()); |
||
| 765 | } |
||
| 766 | return $templates; |
||
| 768 | |||
| 769 | /** |
||
| 770 | * @return Controller |
||
| 771 | */ |
||
| 772 | public function getController() { |
||
| 775 | |||
| 776 | /** |
||
| 777 | * @return GridField |
||
| 778 | */ |
||
| 779 | public function getGridField() { |
||
| 782 | |||
| 783 | /** |
||
| 784 | * @return DataObject |
||
| 785 | */ |
||
| 786 | public function getRecord() { |
||
| 789 | |||
| 790 | /** |
||
| 791 | * CMS-specific functionality: Passes through navigation breadcrumbs |
||
| 792 | * to the template, and includes the currently edited record (if any). |
||
| 793 | * see {@link LeftAndMain->Breadcrumbs()} for details. |
||
| 794 | * |
||
| 795 | * @param boolean $unlinked |
||
| 796 | * @return ArrayData |
||
| 797 | */ |
||
| 798 | public function Breadcrumbs($unlinked = false) { |
||
| 817 | } |
||
| 818 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: