From 35775ad2ce9bcdf09417a7a376d429361a21f3fd Mon Sep 17 00:00:00 2001 From: UndefinedOffset Date: Tue, 8 Jan 2019 12:21:33 -0400 Subject: [PATCH] More adjustments to how ManyManyThroughLists are handled Fixed issue causing the alert to be empty when an error occurs on the server --- javascript/GridFieldSortableRows.js | 2 +- src/Forms/GridFieldSortableRows.php | 34 +++++++++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/javascript/GridFieldSortableRows.js b/javascript/GridFieldSortableRows.js index 87c936c..32f55d7 100644 --- a/javascript/GridFieldSortableRows.js +++ b/javascript/GridFieldSortableRows.js @@ -107,7 +107,7 @@ dataType: 'html', success: callback, error: function (e) { - alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION')); + alert(ss.i18n._t('Admin.ERRORINTRANSACTION', 'An error occured while fetching data from the server\n Please try again later.')); } }, ajaxOpts)); } diff --git a/src/Forms/GridFieldSortableRows.php b/src/Forms/GridFieldSortableRows.php index 1d9c7ab..ceeed84 100644 --- a/src/Forms/GridFieldSortableRows.php +++ b/src/Forms/GridFieldSortableRows.php @@ -126,7 +126,7 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP 'Checked' => ($state->sortableToggle == true ? ' checked = "checked"' : ''), 'List' => $dataList); - $forTemplate = new arrayData($data); + $forTemplate = new ArrayData($data); Requirements::css('undefinedoffset/sortablegridfield:css/GridFieldSortableRows.css'); Requirements::javascript('undefinedoffset/sortablegridfield:javascript/GridFieldSortableRows.js'); @@ -230,15 +230,10 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP return $query; }); - $many_many = ($list instanceof ManyManyList); + $many_many = ($list instanceof ManyManyList || $list instanceof ManyManyThroughList); if (!$many_many) { - if($list instanceof ManyManyThroughList) { - $fieldType = $list->getExtraFields(); - $fieldType = $fieldType[$this->sortColumn]; - } else { - $sng = singleton($gridField->getModelClass()); - $fieldType = $sng->config()->db[$this->sortColumn]; - } + $sng = singleton($gridField->getModelClass()); + $fieldType = $sng->config()->db[$this->sortColumn]; if (!$fieldType || !($fieldType == 'Int' || $fieldType == 'SilverStripe\\ORM\\FieldType\\DBInt' || is_subclass_of($fieldType, 'SilverStripe\\ORM\\FieldType\\DBInt'))) { if (is_array($fieldType)) { @@ -264,8 +259,13 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP $parentField=$componentDetails['parentField']; $componentField=$componentDetails['childField']; $table=$componentDetails['join']; + + //For ManyManyThroughLists get the right join table + if ($list instanceof ManyManyThroughList && class_exists($table)) { + $table=$schema->tableName($table); + } - $extraFields = $schema->manyManyExtraFieldsForComponent(get_class($owner), (!empty($this->custom_relation_name) ? $this->custom_relation_name : $gridField->getName())); + $extraFields = $list->getExtraFields(); if (!$extraFields || !array_key_exists($this->sortColumn, $extraFields) || !($extraFields[$this->sortColumn] == 'Int' || $extraFields[$this->sortColumn] == 'SilverStripe\\ORM\\FieldType\\DBInt' || is_subclass_of('SilverStripe\\ORM\\FieldType\\DBInt', $extraFields[$this->sortColumn]))) { user_error('Sort column ' . $this->sortColumn . ' must be an SilverStripe\\ORM\\FieldType\\DBInt, column is of type ' . $extraFields[$this->sortColumn], E_USER_ERROR); @@ -470,7 +470,7 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP $className = $gridField->getModelClass(); $owner = $gridField->Form->getRecord(); $items = clone $gridField->getList(); - $many_many = ($items instanceof ManyManyList); + $many_many = ($items instanceof ManyManyList || $items instanceof ManyManyThroughList); $sortColumn = $this->sortColumn; $pageOffset = 0; @@ -489,6 +489,11 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP $parentField=$componentDetails['parentField']; $componentField=$componentDetails['childField']; $table=$componentDetails['join']; + + //For ManyManyThroughLists get the right join table + if ($items instanceof ManyManyThroughList && class_exists($table)) { + $table=$schema->tableName($table); + } } else { //Find table containing the sort column $table = false; @@ -612,7 +617,7 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP /** @var DataList $items */ $items = clone $gridField->getList(); - $many_many = ($items instanceof ManyManyList); + $many_many = ($items instanceof ManyManyList || $items instanceof ManyManyThroughList); $sortColumn = $this->sortColumn; $targetItem = $items->byID(intval($data['ItemID'])); @@ -633,6 +638,11 @@ class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionP $parentField=$componentDetails['parentField']; $componentField=$componentDetails['childField']; $table=$componentDetails['join']; + + //For ManyManyThroughLists get the right join table + if ($items instanceof ManyManyThroughList && class_exists($table)) { + $table=$schema->tableName($table); + } } if ($data['Target'] == 'previouspage') {