mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
8883413ba7
This new opt-in setting will let grid field detail forms redirect to the “Correct” URL of a GridField if it’s not found in the current list. This works by: * Looking for the item in the database * If it exists, check for a CMSEditLink() method that returns a value * If so, redirect to that This is useful if you have a number of grid fields that each show a partial list of records, and it’s possible for the user to make changes such the item no longer appears in the list, but does appear in another list. It’s an opt-in feature as I think all changes like this should be opt-in, based on previous experiences improving GridField and in turn breaking SecurityAdmin and slowing versioned-data-browsing down. ;-)
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Forms\Tests\GridField\GridFieldDetailFormTest;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
use SilverStripe\Dev\TestOnly;
|
|
use SilverStripe\Forms\FieldList;
|
|
use SilverStripe\Forms\Form;
|
|
use SilverStripe\Forms\GridField\GridField;
|
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
|
|
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
|
use SilverStripe\Forms\GridField\GridFieldEditButton;
|
|
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
|
|
use SilverStripe\Forms\GridField\GridFieldViewButton;
|
|
|
|
/**
|
|
* @skipUpgrade
|
|
*/
|
|
class TestController extends Controller implements TestOnly
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
if (Controller::has_curr()) {
|
|
$this->setRequest(Controller::curr()->getRequest());
|
|
}
|
|
}
|
|
|
|
public function Link($action = null)
|
|
{
|
|
return Controller::join_links('GridFieldDetailFormTest_Controller', $action, '/');
|
|
}
|
|
|
|
private static $allowed_actions = ['Form'];
|
|
|
|
protected $template = 'BlankPage';
|
|
|
|
public function Form()
|
|
{
|
|
$group = PeopleGroup::get()
|
|
->filter('Name', 'My Group')
|
|
->sort('Name')
|
|
->First();
|
|
|
|
$field = new GridField('testfield', 'testfield', $group->People());
|
|
$field->getConfig()->addComponent(new GridFieldToolbarHeader());
|
|
$field->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right'));
|
|
$field->getConfig()->addComponent(new GridFieldViewButton());
|
|
$field->getConfig()->addComponent(new GridFieldEditButton());
|
|
/** @skipUpgrade */
|
|
$gridFieldForm = new GridFieldDetailForm($this, 'Form');
|
|
$gridFieldForm->setRedirectMissingRecords(true);
|
|
$field->getConfig()->addComponent($gridFieldForm);
|
|
$field->getConfig()->addComponent(new GridFieldEditButton());
|
|
/** @skipUpgrade */
|
|
return new Form($this, 'Form', new FieldList($field), new FieldList());
|
|
}
|
|
}
|