diff --git a/docs/en/02_Developer_Guides/15_Customising_the_Admin_Interface/How_Tos/Customise_CMS_Menu.md b/docs/en/02_Developer_Guides/15_Customising_the_Admin_Interface/How_Tos/Customise_CMS_Menu.md index 886e03bd47a..3810ee36ed2 100644 --- a/docs/en/02_Developer_Guides/15_Customising_the_Admin_Interface/How_Tos/Customise_CMS_Menu.md +++ b/docs/en/02_Developer_Guides/15_Customising_the_Admin_Interface/How_Tos/Customise_CMS_Menu.md @@ -126,7 +126,7 @@ SilverStripe\Admin\LeftAndMain: ## Customising the CMS form actions -The `Previous`, `Next` and `Add` actions on the edit form are visible by default but can be hidden by adding the following `.yml` config: +The `Previous`, `Next` and `Add` actions on the edit form are visible by default but can be hidden globally by adding the following `.yml` config: ```yml FormActions: @@ -135,6 +135,16 @@ FormActions: showAdd: false ``` +You can also configure this for a specific `GridField` instance when using the `GridFieldConfig_RecordEditor` constructor: + +```php +$grid = new GridField( + "pages", + "All Pages", + SiteTree::get(), + GridFieldConfig_RecordEditor::create(null, false, false, false)); +``` + ## Related * [How to extend the CMS interface](extend_cms_interface) diff --git a/src/Forms/GridField/GridFieldConfig_RecordEditor.php b/src/Forms/GridField/GridFieldConfig_RecordEditor.php index 5a831e106d5..789a4f95a0d 100644 --- a/src/Forms/GridField/GridFieldConfig_RecordEditor.php +++ b/src/Forms/GridField/GridFieldConfig_RecordEditor.php @@ -10,8 +10,11 @@ class GridFieldConfig_RecordEditor extends GridFieldConfig /** * * @param int $itemsPerPage - How many items per page should show up + * @param bool $showPrevious Whether the `Previous` button should display or not, leave as null to use default + * @param bool $showNext Whether the `Next` button should display or not, leave as null to use default + * @param bool $showAdd Whether the `Add` button should display or not, leave as null to use default */ - public function __construct($itemsPerPage = null) + public function __construct($itemsPerPage = null, $showPrevious = null, $showNext = null, $showAdd = null) { parent::__construct(); @@ -26,7 +29,7 @@ public function __construct($itemsPerPage = null) $this->addComponent(new GridField_ActionMenu()); $this->addComponent(new GridFieldPageCount('toolbar-header-right')); $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage)); - $this->addComponent(new GridFieldDetailForm()); + $this->addComponent(new GridFieldDetailForm(null, $showPrevious, $showNext, $showAdd)); $sort->setThrowExceptionOnBadDataType(false); $filter->setThrowExceptionOnBadDataType(false); diff --git a/src/Forms/GridField/GridFieldDetailForm.php b/src/Forms/GridField/GridFieldDetailForm.php index 89a5a5f8784..d8e05697fcd 100644 --- a/src/Forms/GridField/GridFieldDetailForm.php +++ b/src/Forms/GridField/GridFieldDetailForm.php @@ -43,6 +43,24 @@ class GridFieldDetailForm implements GridField_URLHandler */ protected $name; + /** + * + * @var bool + */ + protected $showPrevious; + + /** + * + * @var bool + */ + protected $showNext; + + /** + * + * @var bool + */ + protected $showAdd; + /** * @var Validator The form validator used for both add and edit fields. */ @@ -79,10 +97,16 @@ public function getURLHandlers($gridField) * controller who wants to display the getCMSFields * * @param string $name The name of the edit form to place into the pop-up form + * @param bool $showPrevious Whether the `Previous` button should display or not, leave as null to use default + * @param bool $showNext Whether the `Next` button should display or not, leave as null to use default + * @param bool $showAdd Whether the `Add` button should display or not, leave as null to use default */ - public function __construct($name = 'DetailForm') + public function __construct($name = null, $showPrevious = null, $showNext = null, $showAdd = null) { - $this->name = $name; + $this->name = $name ?: 'DetailForm'; + $this->showPrevious = $showPrevious; + $this->showNext = $showNext; + $this->showAdd = $showAdd; } /** @@ -183,6 +207,30 @@ public function getName() return $this->name; } + /** + * @return bool + */ + public function getShowPrevious() + { + return $this->showPrevious; + } + + /** + * @return bool + */ + public function getShowNext() + { + return $this->showNext; + } + + /** + * @return bool + */ + public function getShowAdd() + { + return $this->showAdd; + } + /** * @param Validator $validator * @return $this diff --git a/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php b/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php index a95748f014d..5fb7775eba2 100644 --- a/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php +++ b/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php @@ -308,10 +308,13 @@ protected function getFormActions() $previousAndNextGroup->addExtraClass('rounded'); $previousAndNextGroup->setFieldHolderTemplate(get_class($previousAndNextGroup) . '_holder_buttongroup'); + + $component = $this->gridField->getConfig()->getComponentByType(GridFieldDetailForm::class); $formActionsConfig = $this->config()->get("formActions"); - $showPrevious = $formActionsConfig["showPrevious"]; - $showNext = $formActionsConfig["showNext"]; - $showAdd = $formActionsConfig["showAdd"]; + + $showPrevious = is_bool($component->getShowPrevious()) ? $component->getShowPrevious() : $formActionsConfig["showPrevious"]; + $showNext = is_bool($component->getShowNext()) ? $component->getShowNext() : $formActionsConfig["showNext"]; + $showAdd = is_bool($component->getShowAdd()) ? $component->getShowAdd() : $formActionsConfig["showAdd"]; if ($showPrevious) { $previousAndNextGroup->push(FormAction::create('doPrevious') @@ -515,7 +518,6 @@ public function getEditLink($id) $this->gridField->Link(), "item", $id, - // todo: use http header instead '?gridState=' . urlencode($this->gridField->getState(false)->Value()) ); }