Changed base-class of GridFieldNestedForm, it doesn't share much with

GridFieldDetailForm anymore.
Also changed how Breadcrumbs work.
This commit is contained in:
Niklas Forsdahl 2024-04-18 10:56:35 +03:00
parent 654b7294fa
commit c043220949
2 changed files with 46 additions and 3 deletions

View File

@ -8,12 +8,15 @@ use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Extensible;
use SilverStripe\Forms\GridField\AbstractGridFieldComponent;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
use SilverStripe\Forms\GridField\GridField_DataManipulator;
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
use SilverStripe\Forms\GridField\GridField_SaveHandler;
use SilverStripe\Forms\GridField\GridField_URLHandler;
use SilverStripe\Forms\GridField\GridFieldStateAware;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
@ -26,12 +29,14 @@ use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
/**
* Gridfield component for nesting GridFields
*/
class GridFieldNestedForm extends GridFieldDetailForm implements
class GridFieldNestedForm extends AbstractGridFieldComponent implements
GridField_URLHandler,
GridField_ColumnProvider,
GridField_SaveHandler,
GridField_HTMLProvider,
GridField_DataManipulator
{
use Extensible, GridFieldStateAware;
const POST_KEY = 'GridFieldNestedForm';
@ -39,6 +44,10 @@ class GridFieldNestedForm extends GridFieldDetailForm implements
'handleNestedItem'
];
/**
* @var string
*/
protected $name;
protected $expandNested = false;
protected $forceCloseNested = false;
protected $gridField = null;

View File

@ -3,12 +3,14 @@
namespace Symbiote\GridFieldExtensions;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use SilverStripe\Forms\GridField\GridFieldEditButton;
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
@ -17,6 +19,7 @@ use SilverStripe\Forms\GridField\GridFieldSortableHeader;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\HasManyList;
use SilverStripe\ORM\Hierarchy\Hierarchy;
use SilverStripe\View\ArrayData;
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
@ -32,6 +35,14 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
public function ItemEditForm()
{
$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();
$list = $this->record->$relationName();
if ($relationName == 'Children' && $this->record->hasExtension(Hierarchy::class)) {
@ -113,7 +124,30 @@ class GridFieldNestedFormItemRequest extends GridFieldDetailForm_ItemRequest
/** @var ArrayList $items */
$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);
return $items;
}