Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX #309 Support ManyManyThroughList in EditableColumns #311

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/GridFieldEditableColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\ManyManyThroughList;

/**
* Allows inline editing of grid field records without having to load a separate
Expand Down Expand Up @@ -81,7 +82,14 @@ public function getColumnContent($grid, $record, $col)
}
$field = clone $field;
} else {
$value = $grid->getDataFieldValue($record, $col);
$value = $grid->getDataFieldValue($record, $col);
if (is_null($value)) {
// Try to find the value into the join record
$join = $record->getJoin();
if ($join) {
$value = $grid->getDataFieldValue($join, $col);
}
}
$rel = (strpos($col, '.') === false); // field references a relation value
$field = ($rel) ? clone $fields->fieldByName($col) : new ReadonlyField($col);

Expand Down Expand Up @@ -150,7 +158,7 @@ public function handleSave(GridField $grid, DataObjectInterface $record)
}
}

if ($list instanceof ManyManyList) {
if ($list instanceof ManyManyList || $list instanceof ManyManyThroughList) {
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
}

Expand Down Expand Up @@ -235,7 +243,7 @@ public function getFields(GridField $grid, DataObjectInterface $record)
}
}

if (!$field && $list instanceof ManyManyList) {
if (!$field && ($list instanceof ManyManyList || $list instanceof ManyManyThroughList)) {
$extra = $list->getExtraFields();

if ($extra && array_key_exists($col, $extra)) {
Expand Down