mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Changed base-class of GridFieldNestedForm, it doesn't share much with
GridFieldDetailForm anymore. Also changed how Breadcrumbs work.
This commit is contained in:
parent
654b7294fa
commit
c043220949
@ -8,12 +8,15 @@ use SilverStripe\Control\Controller;
|
|||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
use SilverStripe\Control\HTTPResponse_Exception;
|
use SilverStripe\Control\HTTPResponse_Exception;
|
||||||
|
use SilverStripe\Core\Extensible;
|
||||||
|
use SilverStripe\Forms\GridField\AbstractGridFieldComponent;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
|
||||||
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
|
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
|
||||||
use SilverStripe\Forms\GridField\GridField_DataManipulator;
|
use SilverStripe\Forms\GridField\GridField_DataManipulator;
|
||||||
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
|
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
|
||||||
use SilverStripe\Forms\GridField\GridField_SaveHandler;
|
use SilverStripe\Forms\GridField\GridField_SaveHandler;
|
||||||
|
use SilverStripe\Forms\GridField\GridField_URLHandler;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldStateAware;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DataObjectInterface;
|
use SilverStripe\ORM\DataObjectInterface;
|
||||||
@ -26,12 +29,14 @@ use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
|
|||||||
/**
|
/**
|
||||||
* Gridfield component for nesting GridFields
|
* Gridfield component for nesting GridFields
|
||||||
*/
|
*/
|
||||||
class GridFieldNestedForm extends GridFieldDetailForm implements
|
class GridFieldNestedForm extends AbstractGridFieldComponent implements
|
||||||
|
GridField_URLHandler,
|
||||||
GridField_ColumnProvider,
|
GridField_ColumnProvider,
|
||||||
GridField_SaveHandler,
|
GridField_SaveHandler,
|
||||||
GridField_HTMLProvider,
|
GridField_HTMLProvider,
|
||||||
GridField_DataManipulator
|
GridField_DataManipulator
|
||||||
{
|
{
|
||||||
|
use Extensible, GridFieldStateAware;
|
||||||
|
|
||||||
const POST_KEY = 'GridFieldNestedForm';
|
const POST_KEY = 'GridFieldNestedForm';
|
||||||
|
|
||||||
@ -39,6 +44,10 @@ class GridFieldNestedForm extends GridFieldDetailForm implements
|
|||||||
'handleNestedItem'
|
'handleNestedItem'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
protected $expandNested = false;
|
protected $expandNested = false;
|
||||||
protected $forceCloseNested = false;
|
protected $forceCloseNested = false;
|
||||||
protected $gridField = null;
|
protected $gridField = null;
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
namespace Symbiote\GridFieldExtensions;
|
namespace Symbiote\GridFieldExtensions;
|
||||||
|
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
||||||
use SilverStripe\Forms\GridField\GridFieldEditButton;
|
use SilverStripe\Forms\GridField\GridFieldEditButton;
|
||||||
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
|
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
|
||||||
@ -17,6 +19,7 @@ use SilverStripe\Forms\GridField\GridFieldSortableHeader;
|
|||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\HasManyList;
|
use SilverStripe\ORM\HasManyList;
|
||||||
use SilverStripe\ORM\Hierarchy\Hierarchy;
|
use SilverStripe\ORM\Hierarchy\Hierarchy;
|
||||||
|
use SilverStripe\View\ArrayData;
|
||||||
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
|
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
|
||||||
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
|
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
|
||||||
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
|
||||||
@ -32,6 +35,14 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
public function ItemEditForm()
|
public function ItemEditForm()
|
||||||
{
|
{
|
||||||
$config = new GridFieldConfig_RecordEditor();
|
$config = new GridFieldConfig_RecordEditor();
|
||||||
|
/** @var GridFieldDetailForm */
|
||||||
|
$detailForm = $config->getComponentByType(GridFieldDetailForm::class);
|
||||||
|
$detailForm->setItemEditFormCallback(function (Form $form, $itemRequest) {
|
||||||
|
$breadcrumbs = $itemRequest->Breadcrumbs(false);
|
||||||
|
if ($breadcrumbs && $breadcrumbs->exists()) {
|
||||||
|
$form->Backlink = $breadcrumbs->first()->Link;
|
||||||
|
}
|
||||||
|
});
|
||||||
$relationName = $this->component->getRelationName();
|
$relationName = $this->component->getRelationName();
|
||||||
$list = $this->record->$relationName();
|
$list = $this->record->$relationName();
|
||||||
if ($relationName == 'Children' && $this->record->hasExtension(Hierarchy::class)) {
|
if ($relationName == 'Children' && $this->record->hasExtension(Hierarchy::class)) {
|
||||||
@ -114,6 +125,29 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
/** @var ArrayList $items */
|
/** @var ArrayList $items */
|
||||||
$items = $this->popupController->Breadcrumbs($unlinked);
|
$items = $this->popupController->Breadcrumbs($unlinked);
|
||||||
|
|
||||||
|
if (!$items) {
|
||||||
|
$items = ArrayList::create();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->record && $this->record->ID) {
|
||||||
|
$title = ($this->record->Title) ? $this->record->Title : "#{$this->record->ID}";
|
||||||
|
$items->push(ArrayData::create([
|
||||||
|
'Title' => $title,
|
||||||
|
'Link' => parent::Link()
|
||||||
|
]));
|
||||||
|
} else {
|
||||||
|
$items->push(ArrayData::create([
|
||||||
|
'Title' => _t('SilverStripe\\Forms\\GridField\\GridField.NewRecord', 'New {type}', ['type' => $this->record->i18n_singular_name()]),
|
||||||
|
'Link' => false
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($items as $item) {
|
||||||
|
if ($item->Link) {
|
||||||
|
$item->Link = $this->gridField->addAllStateToUrl(Director::absoluteURL($item->Link));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->extend('updateBreadcrumbs', $items);
|
$this->extend('updateBreadcrumbs', $items);
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user