mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Compare commits
2 Commits
ec93c994f8
...
71d60b0734
Author | SHA1 | Date | |
---|---|---|---|
|
71d60b0734 | ||
|
93e4379c3d |
@ -47,7 +47,7 @@ class GridFieldDetailFormItemRequestExtension extends Extension
|
||||
|
||||
$classes = $component->getClasses($grid);
|
||||
|
||||
if (!count($classes)) {
|
||||
if (!count($classes ?? [])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ class GridFieldAddNewInlineButton extends AbstractGridFieldComponent implements
|
||||
private function getRowTemplate(GridField $grid, GridFieldEditableColumns $editable)
|
||||
{
|
||||
$columns = ArrayList::create();
|
||||
$handled = array_keys($editable->getDisplayFields($grid));
|
||||
$handled = array_keys($editable->getDisplayFields($grid) ?? []);
|
||||
|
||||
if ($grid->getList()) {
|
||||
$record = Injector::inst()->create($grid->getModelClass());
|
||||
@ -129,7 +129,7 @@ class GridFieldAddNewInlineButton extends AbstractGridFieldComponent implements
|
||||
$fields = $editable->getFields($grid, $record);
|
||||
|
||||
foreach ($grid->getColumns() as $column) {
|
||||
if (in_array($column, $handled)) {
|
||||
if (in_array($column, $handled ?? [])) {
|
||||
$field = $fields->dataFieldByName($column);
|
||||
$field->setName(sprintf(
|
||||
'%s[%s][{%%=o.num%%}][%s]',
|
||||
@ -149,7 +149,7 @@ class GridFieldAddNewInlineButton extends AbstractGridFieldComponent implements
|
||||
$content = str_replace(
|
||||
sprintf('[%s][0]', GridFieldEditableColumns::POST_KEY),
|
||||
sprintf('[%s][{%%=o.num%%}]', self::POST_KEY),
|
||||
$content
|
||||
$content ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ class GridFieldAddNewInlineButton extends AbstractGridFieldComponent implements
|
||||
}
|
||||
|
||||
if ($list instanceof ManyManyList) {
|
||||
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
|
||||
$extra = array_intersect_key($form->getData() ?? [], (array) $list->getExtraFields());
|
||||
}
|
||||
|
||||
$item->write(false, false, false, true);
|
||||
|
@ -124,7 +124,7 @@ class GridFieldAddNewMultiClass extends AbstractGridFieldComponent implements
|
||||
$result = array();
|
||||
|
||||
if (is_null($this->classes)) {
|
||||
$classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()));
|
||||
$classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()) ?? []);
|
||||
sort($classes);
|
||||
} else {
|
||||
$classes = $this->classes;
|
||||
@ -135,7 +135,7 @@ class GridFieldAddNewMultiClass extends AbstractGridFieldComponent implements
|
||||
if (!is_string($class)) {
|
||||
$class = $title;
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
if (!class_exists($class ?? '')) {
|
||||
continue;
|
||||
}
|
||||
$is_abstract = (($reflection = new ReflectionClass($class)) && $reflection->isAbstract());
|
||||
@ -216,7 +216,7 @@ class GridFieldAddNewMultiClass extends AbstractGridFieldComponent implements
|
||||
throw new Exception('The add new multi class component requires the detail form component.');
|
||||
}
|
||||
|
||||
if (!$class || !array_key_exists($class, $classes)) {
|
||||
if (!$class || !array_key_exists($class, $classes ?? [])) {
|
||||
throw new HTTPResponse_Exception(400);
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ class GridFieldAddNewMultiClass extends AbstractGridFieldComponent implements
|
||||
{
|
||||
$classes = $this->getClasses($grid);
|
||||
|
||||
if (!count($classes)) {
|
||||
if (!count($classes ?? [])) {
|
||||
return array();
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ class GridFieldAddNewMultiClass extends AbstractGridFieldComponent implements
|
||||
*/
|
||||
protected function sanitiseClassName($class)
|
||||
{
|
||||
return str_replace('\\', '-', $class);
|
||||
return str_replace('\\', '-', $class ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,6 +304,6 @@ class GridFieldAddNewMultiClass extends AbstractGridFieldComponent implements
|
||||
*/
|
||||
protected function unsanitiseClassName($class)
|
||||
{
|
||||
return str_replace('-', '\\', $class);
|
||||
return str_replace('-', '\\', $class ?? '');
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,6 @@ class GridFieldAddNewMultiClassHandler extends GridFieldDetailForm_ItemRequest
|
||||
*/
|
||||
protected function sanitiseClassName($class)
|
||||
{
|
||||
return str_replace('\\', '-', $class);
|
||||
return str_replace('\\', '-', $class ?? '');
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ class GridFieldConfigurablePaginator extends GridFieldPaginator
|
||||
$this->pageSizes = $pageSizes;
|
||||
|
||||
// Reset items per page
|
||||
$this->setItemsPerPage(current($pageSizes));
|
||||
$this->setItemsPerPage(current($pageSizes ?? []));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -356,7 +356,7 @@ class GridFieldConfigurablePaginator extends GridFieldPaginator
|
||||
return array(
|
||||
'footer' => $forTemplate->renderWith(
|
||||
__CLASS__,
|
||||
array('Colspan' => count($gridField->getColumns()))
|
||||
array('Colspan' => count($gridField->getColumns() ?? []))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
if (!$this->displayFields) {
|
||||
// If setDisplayFields() not used, utilize $summary_fields
|
||||
// in a way similar to base class
|
||||
$colRelation = explode('.', $col);
|
||||
$colRelation = explode('.', $col ?? '');
|
||||
$value = $grid->getDataFieldValue($record, $colRelation[0]);
|
||||
$field = $fields->fieldByName($colRelation[0]);
|
||||
if (!$field || $field->isReadonly() || $field->isDisabled()) {
|
||||
@ -82,7 +82,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
|
||||
// Fall back to previous logic
|
||||
if (!$field) {
|
||||
$rel = (strpos($col, '.') === false); // field references a relation value
|
||||
$rel = (strpos($col ?? '', '.') === false); // field references a relation value
|
||||
$field = ($rel) ? clone $fields->fieldByName($col) : ReadonlyField::create($col);
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists($col, $this->fieldCasting)) {
|
||||
if (array_key_exists($col, $this->fieldCasting ?? [])) {
|
||||
$value = $grid->getCastedValue($value, $this->fieldCasting[$col]);
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
}
|
||||
|
||||
if ($list instanceof ManyManyList) {
|
||||
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
|
||||
$extra = array_intersect_key($form->getData() ?? [], (array) $list->getExtraFields());
|
||||
}
|
||||
|
||||
$item->write(false, false, false, true);
|
||||
@ -244,7 +244,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
if (!$field && $list instanceof ManyManyList) {
|
||||
$extra = $list->getExtraFields();
|
||||
|
||||
if ($extra && array_key_exists($col, $extra)) {
|
||||
if ($extra && array_key_exists($col, $extra ?? [])) {
|
||||
$field = Injector::inst()->create($extra[$col], $col)->scaffoldFormField();
|
||||
}
|
||||
}
|
||||
@ -259,7 +259,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
// revert to looking good in cases where the field isn't
|
||||
// available or is readonly
|
||||
//
|
||||
$colRelation = explode('.', $col);
|
||||
$colRelation = explode('.', $col ?? '');
|
||||
if ($class && $obj = DataObject::singleton($class)->dbObject($colRelation[0])) {
|
||||
$field = $obj->scaffoldFormField();
|
||||
} else {
|
||||
|
@ -19,7 +19,7 @@ class GridFieldExternalLink extends GridFieldDataColumns
|
||||
*/
|
||||
public function augmentColumns($gridField, &$columns)
|
||||
{
|
||||
if (!in_array('Actions', $columns)) {
|
||||
if (!in_array('Actions', $columns ?? [])) {
|
||||
$columns[] = 'Actions';
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
if ($list instanceof ManyManyList) {
|
||||
$extra = $list->getExtraFields();
|
||||
|
||||
if ($extra && array_key_exists($field, $extra)) {
|
||||
if ($extra && array_key_exists($field, $extra ?? [])) {
|
||||
return;
|
||||
}
|
||||
} elseif ($list instanceof ManyManyThroughList) {
|
||||
@ -239,7 +239,7 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
if ($list instanceof ManyManyList) {
|
||||
$extra = $list->getExtraFields();
|
||||
$table = $list->getJoinTable();
|
||||
if ($extra && array_key_exists($field, $extra)) {
|
||||
if ($extra && array_key_exists($field, $extra ?? [])) {
|
||||
return $table;
|
||||
}
|
||||
} elseif ($list instanceof ManyManyThroughList) {
|
||||
@ -277,8 +277,8 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
|
||||
public function augmentColumns($grid, &$cols)
|
||||
{
|
||||
if (!in_array('Reorder', $cols) && $grid->getState()->GridFieldOrderableRows->enabled) {
|
||||
array_splice($cols, $this->reorderColumnNumber, 0, 'Reorder');
|
||||
if (!in_array('Reorder', $cols ?? []) && $grid->getState()->GridFieldOrderableRows->enabled) {
|
||||
array_splice($cols, $this->reorderColumnNumber ?? 0, 0, 'Reorder');
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,7 +308,7 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
// if it exists, not directly from the record
|
||||
$throughListSorts = $this->getSortValuesFromManyManyThroughList($list, $this->getSortField());
|
||||
|
||||
if (array_key_exists($record->ID, $throughListSorts)) {
|
||||
if (array_key_exists($record->ID, $throughListSorts ?? [])) {
|
||||
$currentSortValue = $throughListSorts[$record->ID];
|
||||
}
|
||||
}
|
||||
@ -408,8 +408,8 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
|
||||
// Get records from the `GridFieldEditableColumns` column
|
||||
$gridFieldName = $grid->getName();
|
||||
if (strpos($gridFieldName, '.') !== false) {
|
||||
$gridFieldName = str_replace('.', '_', $gridFieldName);
|
||||
if (strpos($gridFieldName ?? '', '.') !== false) {
|
||||
$gridFieldName = str_replace('.', '_', $gridFieldName ?? '');
|
||||
}
|
||||
|
||||
$data = $request->postVar($gridFieldName);
|
||||
@ -549,7 +549,7 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$items = $list->filter('ID', $sortedIDs)->sort($sortterm);
|
||||
|
||||
// Ensure that each provided ID corresponded to an actual object.
|
||||
if (count($items) != count($sortedIDs)) {
|
||||
if (count($items ?? []) != count($sortedIDs ?? [])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -720,7 +720,7 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
protected function getSortTableClauseForIds(DataList $list, $ids)
|
||||
{
|
||||
if (is_array($ids)) {
|
||||
$value = 'IN (' . implode(', ', array_map('intval', $ids)) . ')';
|
||||
$value = 'IN (' . implode(', ', array_map('intval', $ids ?? [])) . ')';
|
||||
} else {
|
||||
$value = '= ' . (int) $ids;
|
||||
}
|
||||
@ -734,7 +734,7 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$foreignKey = $this->getManyManyInspectorForeignKey($introspector);
|
||||
$foreignID = (int) $list->getForeignID();
|
||||
|
||||
if ($extra && array_key_exists($this->getSortField(), $extra)) {
|
||||
if ($extra && array_key_exists($this->getSortField(), $extra ?? [])) {
|
||||
return sprintf(
|
||||
'"%s" %s AND "%s" = %d',
|
||||
$key,
|
||||
|
@ -69,7 +69,7 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
||||
$config = new GridFieldConfig_RelationEditor();
|
||||
$config->addComponent($orderable);
|
||||
|
||||
list($parentClass, $parentInstanceID) = explode('.', $fixtureID);
|
||||
list($parentClass, $parentInstanceID) = explode('.', $fixtureID ?? '');
|
||||
$parent = $this->objFromFixture($parentClass, $parentInstanceID);
|
||||
|
||||
$grid = new GridField(
|
||||
@ -83,7 +83,7 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
||||
$desiredOrder = [];
|
||||
|
||||
// Make order non-contiguous, and 1-based
|
||||
foreach (array_reverse($originalOrder) as $index => $id) {
|
||||
foreach (array_reverse($originalOrder ?? []) as $index => $id) {
|
||||
$desiredOrder[$index * 2 + 1] = $id;
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
||||
);
|
||||
|
||||
$originalOrder = $parent->Children()->column('ID');
|
||||
$desiredOrder = array_reverse($originalOrder);
|
||||
$desiredOrder = array_reverse($originalOrder ?? []);
|
||||
|
||||
$this->assertNotEquals($originalOrder, $desiredOrder);
|
||||
|
||||
@ -270,7 +270,7 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
||||
$desiredOrder = [];
|
||||
|
||||
// Make order non-contiguous, and 1-based
|
||||
foreach (array_reverse($originalOrder) as $index => $id) {
|
||||
foreach (array_reverse($originalOrder ?? []) as $index => $id) {
|
||||
$desiredOrder[$index * 2 + 1] = $id;
|
||||
}
|
||||
|
||||
|
@ -80,11 +80,11 @@ class OrderableRowsThroughVersionedTest extends SapphireTest
|
||||
$originalOrder = $parent->$relationName()->sort($sortName)->column('ID');
|
||||
// Ring (un)shift by one, e.g. 3,2,1 becomes 1,3,2.
|
||||
// then string key our new order starting at 1
|
||||
$desiredOrder = array_values($originalOrder);
|
||||
$desiredOrder = array_values($originalOrder ?? []);
|
||||
array_unshift($desiredOrder, array_pop($desiredOrder));
|
||||
$desiredOrder = array_combine(
|
||||
range('1', count($desiredOrder)),
|
||||
$desiredOrder
|
||||
range('1', count($desiredOrder ?? [])),
|
||||
$desiredOrder ?? []
|
||||
);
|
||||
$this->assertNotEquals($originalOrder, $desiredOrder);
|
||||
|
||||
|
@ -9,7 +9,7 @@ class StubA implements TestOnly
|
||||
public function i18n_singular_name()
|
||||
{
|
||||
$class = get_class($this);
|
||||
return substr($class, -1);
|
||||
return substr($class ?? '', -1);
|
||||
}
|
||||
|
||||
public function canCreate()
|
||||
|
Loading…
Reference in New Issue
Block a user