From ddec2ab03b4cf0500bf92d09ded8de7afa7006c4 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 25 Oct 2019 17:40:08 -0700 Subject: [PATCH] Civi/Afform/Utils - Small cleanups --- ext/afform/core/Civi/Afform/Utils.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ext/afform/core/Civi/Afform/Utils.php b/ext/afform/core/Civi/Afform/Utils.php index f8f4cc1505..45054f631a 100644 --- a/ext/afform/core/Civi/Afform/Utils.php +++ b/ext/afform/core/Civi/Afform/Utils.php @@ -8,7 +8,10 @@ class Utils { * Gets entity metadata and all fields from the form * * @param array $layout + * The root element of the layout, in shallow/deep format. * @return array + * A list of entities, keyed by named. + * Ex: $entities['spouse']['type'] = 'Contact'; */ public static function getEntities($layout) { $entities = array_column(self::getTags($layout, 'af-entity'), NULL, 'name'); @@ -19,16 +22,16 @@ class Utils { /** * Returns all tags with a certain tag name, e.g. 'af-entity' * - * @param array $collection + * @param array $element * @param string $tagName * @return array */ - public static function getTags($collection, $tagName) { + public static function getTags($element, $tagName) { $results = []; - if ($collection['#tag'] == $tagName) { - $results[] = self::getProps($collection); + if ($element['#tag'] == $tagName) { + $results[] = self::getProps($element); } - foreach ($collection['#children'] ?? [] as $child) { + foreach ($element['#children'] ?? [] as $child) { $results = array_merge($results, self::getTags($child, $tagName)); } return $results; @@ -36,7 +39,11 @@ class Utils { /** * @param array $layout + * The root element of the layout, in shallow/deep format. * @param array $entities + * A list of entities, keyed by named. + * This will be updated to include 'fields'. + * Ex: $entities['spouse']['type'] = 'Contact'; */ protected static function getFields($layout, &$entities) { foreach ($layout['#children'] as $child) { @@ -53,11 +60,11 @@ class Utils { * Returns all the real properties of a collection, * filtering out any array keys that start with a hashtag * - * @param array $collection + * @param array $element * @return array */ - public static function getProps($collection) { - return array_filter($collection, function($key) { + public static function getProps($element) { + return array_filter($element, function($key) { return substr($key, 0, 1) !== '#'; }, ARRAY_FILTER_USE_KEY); } -- 2.25.1