mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
FIX: checkbox uncheck
This commit is contained in:
parent
0e152eef6e
commit
146231c127
@ -2,20 +2,13 @@
|
||||
|
||||
namespace A2nt\CMSNiceties\Forms\GridField;
|
||||
|
||||
/**
|
||||
* Milkyway Multimedia
|
||||
* SaveAllButton.php
|
||||
*
|
||||
* @package milkyway-multimedia/ss-gridfield-utils
|
||||
* @author Mellisa Hankins <mell@milkywaymultimedia.com.au>
|
||||
*/
|
||||
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
|
||||
use SilverStripe\Forms\GridField\GridField_ActionProvider;
|
||||
use SilverStripe\Forms\GridField\GridField_FormAction;
|
||||
use SilverStripe\Forms\GridField\GridField_SaveHandler;
|
||||
use SilverStripe\Control\Controller;
|
||||
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
|
||||
|
||||
class SaveAllButton implements GridField_HTMLProvider, GridField_ActionProvider
|
||||
{
|
||||
@ -100,45 +93,74 @@ class SaveAllButton implements GridField_HTMLProvider, GridField_ActionProvider
|
||||
|
||||
protected function saveAllRecords(GridField $grid, $arguments, $data)
|
||||
{
|
||||
if (isset($data[$grid->Name])) {
|
||||
$currValue = $grid->Value();
|
||||
$grid->setValue($data[$grid->Name]);
|
||||
$model = singleton($grid->List->dataClass());
|
||||
if (!isset($data[$grid->Name])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($grid->getConfig()->getComponents() as $component) {
|
||||
if ($component instanceof GridField_SaveHandler) {
|
||||
$component->handleSave($grid, $model);
|
||||
}
|
||||
$currValue = $grid->Value();
|
||||
$grid->setValue($data[$grid->Name]);
|
||||
$model = singleton($grid->List->dataClass());
|
||||
$cfg = $grid->getConfig();
|
||||
|
||||
foreach ($cfg->getComponents() as $component) {
|
||||
if ($component instanceof GridField_SaveHandler) {
|
||||
$component->handleSave($grid, $model);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->publish) {
|
||||
// Only use the viewable list items, since bulk publishing can take a toll on the system
|
||||
$list = ($paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator')) ? $paginator->getManipulatedData($grid, $grid->List) : $grid->List;
|
||||
// Only use the viewable list items, since bulk publishing can take a toll on the system
|
||||
$paginator = $cfg->getComponentByType('GridFieldPaginator');
|
||||
$list = $paginator
|
||||
? $paginator->getManipulatedData($grid, $grid->List)
|
||||
: $grid->List;
|
||||
|
||||
$list->each(
|
||||
function ($item) {
|
||||
if ($item->hasExtension('Versioned')) {
|
||||
$item->writeToStage('Stage');
|
||||
$item->publish('Stage', 'Live');
|
||||
// add missing checkbox fields
|
||||
$cols = $cfg->getComponentByType(GridFieldEditableColumns::class);
|
||||
if ($cols) {
|
||||
$fields = $cols->getFields($grid, $model);
|
||||
$colsData = $data[$grid->Name]['GridFieldEditableColumns'];
|
||||
|
||||
if (isset($colsData)) {
|
||||
$list->each(function ($item) use ($colsData, $grid, $fields) {
|
||||
/* @var $item \SilverStripe\ORM\DataObject */
|
||||
if (!isset($colsData[$item->ID])) {
|
||||
foreach ($fields as $field) {
|
||||
/* @var $field \SilverStripe\Forms\FormField */
|
||||
$fieldName = $field->getName();
|
||||
$item->setField($fieldName, '');
|
||||
}
|
||||
|
||||
$item->write();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if ($model->exists()) {
|
||||
$model->delete();
|
||||
$model->destroy();
|
||||
}
|
||||
|
||||
$grid->setValue($currValue);
|
||||
|
||||
if (Controller::curr() && $response = Controller::curr()->Response) {
|
||||
if (!$this->completeMessage) {
|
||||
$this->completeMessage = _t('GridField.DONE', 'Done.');
|
||||
if ($this->publish) {
|
||||
$list->each(function ($item) {
|
||||
if ($item->hasExtension('Versioned')) {
|
||||
$item->writeToStage('Stage');
|
||||
$item->publish('Stage', 'Live');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$response->addHeader('X-Status', rawurlencode($this->completeMessage));
|
||||
if ($model->exists()) {
|
||||
$model->delete();
|
||||
$model->destroy();
|
||||
}
|
||||
|
||||
$grid->setValue($currValue);
|
||||
|
||||
$curr = Controller::curr();
|
||||
$response = $curr->Response;
|
||||
|
||||
if ($curr && $response) {
|
||||
if (!$this->completeMessage) {
|
||||
$this->completeMessage = _t('GridField.DONE', 'Done.');
|
||||
}
|
||||
|
||||
$response->addHeader('X-Status', rawurlencode($this->completeMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user