Merge in GridField changes from 3.0.1-rc2

This commit is contained in:
Hamish Friedlander 2012-07-27 14:47:12 +12:00
commit 27fad40198
2 changed files with 15 additions and 13 deletions

View File

@ -94,7 +94,7 @@ class GridFieldDataColumns implements GridField_ColumnProvider {
* Caution: Make sure to escape special php-characters like in a normal php-statement.
* Example: "myFieldName" => '<a href=\"custom-admin/$ID\">$ID</a>'.
* Alternatively, pass a anonymous function, which takes two parameters:
* The value returned by Convert::raw2xml and the original list item.
* The value and the original list item.
*
* @param array $formatting
*/
@ -126,18 +126,20 @@ class GridFieldDataColumns implements GridField_ColumnProvider {
// Allow callbacks
if(is_array($columnInfo) && isset($columnInfo['callback'])) {
$method = $columnInfo['callback'];
$value = Convert::raw2xml($method($record));
$value = $method($record);
// This supports simple FieldName syntax
} else {
$value = Convert::raw2xml($gridField->getDataFieldValue($record, $columnName));
$value = $gridField->getDataFieldValue($record, $columnName);
}
$value = $this->castValue($gridField, $columnName, $value);
$value = $this->formatValue($gridField, $record, $columnName, $value);
$value = $this->castValue($gridField, $columnName, $value);
$value = $this->escapeValue($gridField, $value);
return $value;
return (is_object($value) && $value instanceof Object && $value->hasMethod('forTemplate'))
? $value->forTemplate()
: Convert::raw2xml($value);
}
/**

View File

@ -2514,13 +2514,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @param $fieldPath string
* @return string
*/
public function relField($fieldPath) {
if(strpos($fieldPath, '.') !== false) {
$parts = explode('.', $fieldPath);
public function relField($fieldName) {
$component = $this;
if(strpos($fieldName, '.') !== false) {
$parts = explode('.', $fieldName);
$fieldName = array_pop($parts);
// Traverse dot syntax
$component = $this;
foreach($parts as $relation) {
if($component instanceof SS_List) {
if(method_exists($component,$relation)) $component = $component->$relation();
@ -2529,11 +2530,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$component = $component->$relation();
}
}
return $component->$fieldName;
} else {
return $this->$fieldPath;
}
if ($component->hasMethod($fieldName)) return $component->$fieldName();
return $component->$fieldName;
}
/**