Simplify code to use dataFields()

This commit is contained in:
Damian Mooyman 2017-02-28 16:34:46 +13:00
parent 2fafff084f
commit 8537d6ddb1
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A

View File

@ -473,17 +473,20 @@ class CMSPageHistoryController extends CMSMain
return $crumbs;
}
/**
* Replace all data fields with HTML readonly fields to display diff
*
* @param FieldList $fields
* @return FieldList
*/
public function transformReadonly(FieldList $fields)
{
foreach($fields as &$field) {
if ($field instanceof CompositeField) {
$subfields = $this->transformReadonly($field->FieldList());
$field->setChildren($subfields);
}
if ($field->hasData() && !$field instanceof HiddenField) {
$newField = $field->castedCopy(HTMLReadonlyField::class);
$fields->replaceField($field->getName(), $newField);
foreach ($fields->dataFields() as $field) {
if ($field instanceof HiddenField) {
continue;
}
$newField = $field->castedCopy(HTMLReadonlyField::class);
$fields->replaceField($field->getName(), $newField);
}
return $fields;
}