From 8537d6ddb12754c85e7cba6c046b1d2993097720 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 28 Feb 2017 16:34:46 +1300 Subject: [PATCH] Simplify code to use dataFields() --- code/Controllers/CMSPageHistoryController.php | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/code/Controllers/CMSPageHistoryController.php b/code/Controllers/CMSPageHistoryController.php index abf5b296..7ac7c3f9 100644 --- a/code/Controllers/CMSPageHistoryController.php +++ b/code/Controllers/CMSPageHistoryController.php @@ -457,12 +457,12 @@ class CMSPageHistoryController extends CMSMain "ID" => $id, "Version" => $fromVersion, )); - + // Comparison views shouldn't be editable. // As the comparison output is HTML and not valid values for the various field types $readonlyFields = $this->transformReadonly($form->Fields()); $form->setFields($readonlyFields); - + return $form; } @@ -472,18 +472,21 @@ class CMSPageHistoryController extends CMSMain $crumbs[0]->Title = _t('CMSPagesController.MENUTITLE', 'Pages'); 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; }