mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Merge pull request #126 from SilbinaryWolf/upgrade-gridfieldeditablecolumns
Updated GridFieldEditableColumns to have nicer defaults, so you can just add it in and it'll "just work" with your 'summary_fields' data.
This commit is contained in:
commit
8ea87d851d
@ -29,12 +29,37 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
}
|
||||
|
||||
$fields = $this->getForm($grid, $record)->Fields();
|
||||
$value = $grid->getDataFieldValue($record, $col);
|
||||
$rel = (strpos($col,'.') === false); // field references a relation value
|
||||
$field = ($rel) ? clone $fields->fieldByName($col) : new ReadonlyField($col);
|
||||
|
||||
if(!$field) {
|
||||
throw new Exception("Could not find the field '$col'");
|
||||
if (!$this->displayFields)
|
||||
{
|
||||
// If setDisplayFields() not used, utilize $summary_fields
|
||||
// in a way similar to base class
|
||||
$colRelation = explode('.', $col);
|
||||
$value = $grid->getDataFieldValue($record, $colRelation[0]);
|
||||
$field = $fields->fieldByName($colRelation[0]);
|
||||
if (!$field || $field->isReadonly() || $field->isDisabled()) {
|
||||
return parent::getColumnContent($grid, $record, $col);
|
||||
}
|
||||
|
||||
// Ensure this field is available to edit on the record
|
||||
// (ie. Maybe its readonly due to certain circumstances, or removed and not editable)
|
||||
$cmsFields = $record->getCMSFields();
|
||||
$cmsField = $cmsFields->dataFieldByName($colRelation[0]);
|
||||
if (!$cmsField || $cmsField->isReadonly() || $cmsField->isDisabled())
|
||||
{
|
||||
return parent::getColumnContent($grid, $record, $col);
|
||||
}
|
||||
$field = clone $field;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = $grid->getDataFieldValue($record, $col);
|
||||
$rel = (strpos($col,'.') === false); // field references a relation value
|
||||
$field = ($rel) ? clone $fields->fieldByName($col) : new ReadonlyField($col);
|
||||
|
||||
if(!$field) {
|
||||
throw new Exception("Could not find the field '$col'");
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists($col, $this->fieldCasting)) {
|
||||
@ -163,7 +188,24 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
}
|
||||
|
||||
if(!$field) {
|
||||
if($class && $obj = singleton($class)->dbObject($col)) {
|
||||
if (!$this->displayFields)
|
||||
{
|
||||
// If setDisplayFields() not used, utilize $summary_fields
|
||||
// in a way similar to base class
|
||||
//
|
||||
// Allows use of 'MyBool.Nice' and 'MyHTML.NoHTML' so that
|
||||
// GridFields not using inline editing still look good or
|
||||
// revert to looking good in cases where the field isn't
|
||||
// available or is readonly
|
||||
//
|
||||
$colRelation = explode('.', $col);
|
||||
if($class && $obj = singleton($class)->dbObject($colRelation[0])) {
|
||||
$field = $obj->scaffoldFormField();
|
||||
} else {
|
||||
$field = new ReadonlyField($colRelation[0]);
|
||||
}
|
||||
}
|
||||
else if($class && $obj = singleton($class)->dbObject($col)) {
|
||||
$field = $obj->scaffoldFormField();
|
||||
} else {
|
||||
$field = new ReadonlyField($col);
|
||||
|
Loading…
Reference in New Issue
Block a user