mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Don't lazy load tab that are not in a TabSet.
This commit is contained in:
parent
5276b6cbb1
commit
d2a51471e9
@ -2,7 +2,10 @@
|
||||
|
||||
namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\Forms\FormField;
|
||||
use SilverStripe\Forms\TabSet;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\Limitable;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
|
||||
/**
|
||||
@ -19,9 +22,17 @@ class GridFieldLazyLoader implements GridField_DataManipulator, GridField_HTMLPr
|
||||
*/
|
||||
public function getManipulatedData(GridField $gridField, SS_List $dataList)
|
||||
{
|
||||
return $this->isLazy($gridField) ?
|
||||
ArrayList::create([]) :
|
||||
$dataList;
|
||||
// If we are lazy loading, empty the list
|
||||
if ($this->isLazy($gridField)) {
|
||||
if ($dataList instanceof Limitable) {
|
||||
// If our original list can be limited, set the limit to 0.
|
||||
$dataList = $dataList->limit(0);
|
||||
} else {
|
||||
// If not, create an empty list instead.
|
||||
$dataList = ArrayList::create([]);
|
||||
}
|
||||
}
|
||||
return $dataList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,12 +47,32 @@ class GridFieldLazyLoader implements GridField_DataManipulator, GridField_HTMLPr
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if the current request should include results
|
||||
* Detect if the current request should include results.
|
||||
* @param GridField $gridField
|
||||
* @return bool
|
||||
*/
|
||||
private function isLazy(GridField $gridField)
|
||||
{
|
||||
return $gridField->getRequest()->getHeader('X-Pjax') !== 'CurrentField';
|
||||
return
|
||||
$gridField->getRequest()->getHeader('X-Pjax') !== 'CurrentField' &&
|
||||
$this->isInTabSet($gridField);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively check if $field is inside a TabSet.
|
||||
* @param FormField $field
|
||||
* @return bool
|
||||
*/
|
||||
private function isInTabSet(FormField $field)
|
||||
{
|
||||
$list = $field->getContainerFieldList();
|
||||
if ($list && $containerField = $list->getContainerField()) {
|
||||
// Classes that extends TabSet might not have the expected JS to lazy load.
|
||||
return get_class($containerField) === TabSet::class
|
||||
?: $this->isInTabSet($containerField);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user