From fb96a2d7405913acf5556ca35328a4ddbd3e49bb Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 1 Nov 2019 13:27:46 -0700 Subject: [PATCH] (REF) AHQ::makeRoot() - Extract helper from FormDataModel --- ext/afform/core/Civi/Afform/AHQ.php | 14 ++++++++++++++ ext/afform/core/Civi/Afform/FormDataModel.php | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ext/afform/core/Civi/Afform/AHQ.php b/ext/afform/core/Civi/Afform/AHQ.php index 1a8f1edb61..e87512f5a5 100644 --- a/ext/afform/core/Civi/Afform/AHQ.php +++ b/ext/afform/core/Civi/Afform/AHQ.php @@ -10,6 +10,20 @@ namespace Civi\Afform; */ class AHQ { + /** + * Given a list of would-be child nodes, combine them under a common root. + * + * @param array $children + * @param string $tag + * @return array + */ + public static function makeRoot($children, $tag = 'placeholder') { + return [ + '#tag' => $tag, + '#children' => $children, + ]; + } + /** * Returns all tags with a certain tag name, e.g. 'af-entity' * diff --git a/ext/afform/core/Civi/Afform/FormDataModel.php b/ext/afform/core/Civi/Afform/FormDataModel.php index ec8cb7fdb2..ce45687cb1 100644 --- a/ext/afform/core/Civi/Afform/FormDataModel.php +++ b/ext/afform/core/Civi/Afform/FormDataModel.php @@ -26,10 +26,7 @@ class FormDataModel { * Parsed summary of the entities used in a given form. */ public static function create($layout) { - $root = [ - '#tag' => 'root', - '#children' => $layout, - ]; + $root = AHQ::makeRoot($layout); $entities = array_column(AHQ::getTags($root, 'af-entity'), NULL, 'name'); foreach (array_keys($entities) as $entity) { $entities[$entity]['fields'] = []; -- 2.25.1