From 856fce1b8c66f7c51c7414c0b73bdfe7f1afbc28 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 19 Oct 2018 21:17:06 +0200 Subject: [PATCH 1/2] DOCS Clarify usage of EditableColumns in a pre-scaffolded GridFieldConfig, before edit button --- docs/en/index.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/en/index.md b/docs/en/index.md index 7ccfe8cc..42d5f9cc 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -57,6 +57,14 @@ $grid->getConfig()->getComponentByType('GridFieldEditableColumns')->setDisplayFi Editing data contained in `many_many_extraFields` is supported - just treat it as you would any other field. +**Please note:** If you are using a GridFieldConfig that is scaffolded by GridField by default, +and adding GridFieldEditableColumns into it, you will probably want to add it before the edit and/or +delete buttons: + +```php +$gridFieldConfig->addComponent($editableColumns, GridFieldEditButton::class); +``` + Multi Class Adding ------------------ From 39a7e3fd74b0d07726a90a77f680b56b237f483d Mon Sep 17 00:00:00 2001 From: micmania1 Date: Thu, 21 Mar 2019 11:10:04 +1300 Subject: [PATCH 2/2] NEW added the ability to autopublish items that are already live --- docs/en/index.md | 13 +++++++++++ src/GridFieldOrderableRows.php | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/docs/en/index.md b/docs/en/index.md index 42d5f9cc..7f6412c2 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -114,6 +114,19 @@ class Item extends DataObject { } ``` +### Versioning +By default `GridFieldOrderableRows` will handle versioning but won't automatically publish any records. The user will need to go into each record and publish them manually which could get cumbersome for large lists. + +You can configure the list to automatically publish a record if the record is the latest version and is already published. This won't publish any records which have draft changes. + +```php +$orderable = new GridFieldOrderableRows() + ->setRepublishLiveRecords(true); +``` + +There are caveats with both approaches so consideration should be made for which approach best suits the requirements. + + **Please NOTE:** There is a limitation when using `GridFieldOrderableRows` on unsaved data objects; namely, that it doesn't work as without data being saved, the list of related objects has no context. Please check `$this->ID` before adding the `GridFieldOrderableRows` component to the grid field config (or even, before adding the gridfield at all). Configurable Paginator diff --git a/src/GridFieldOrderableRows.php b/src/GridFieldOrderableRows.php index d8c5e0ce..23890dd9 100755 --- a/src/GridFieldOrderableRows.php +++ b/src/GridFieldOrderableRows.php @@ -89,8 +89,18 @@ class GridFieldOrderableRows extends RequestHandler implements */ protected $reorderColumnNumber = 0; + /** + * If the items in the list are versioned and this is set to true, then + * we will check to see if the version we're sorting is the latest published + * version and if so then we will re-publish the item. + * + * @var boolean + */ + protected $republishLiveRecords = false; + /** * @param string $sortField + * @param boolean $republishLiveRecords */ public function __construct($sortField = 'Sort') { @@ -138,6 +148,28 @@ public function setImmediateUpdate($bool) return $this; } + /** + * @see $republishLiveRecords + * + * @return boolean + */ + public function getRepublishLiveRecords() + { + return $this->republishLiveRecords; + } + + /** + * @see $republishLiveRecords + * + * @param boolean $bool + * @return GridFieldOrderableRows $this + */ + public function setRepublishLiveRecords($bool) + { + $this->republishLiveRecords = $bool; + return $this; + } + /** * @return string|array */ @@ -656,7 +688,15 @@ protected function reorderItems($list, array $values, array $sortedIDs) $record = $currentSortList[$targetRecordID]; if ($record->$sortField != $newSortValue) { $record->$sortField = $newSortValue; + + // We need to do this before writing otherwith isLiveVersion() will always be false + $shouldRepublish = $this->getRepublishLiveRecords() && $record->isLiveVersion(); + + // Write our staged record and publish if required $record->write(); + if ($shouldRepublish) { + $record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE, true); + } } } }