From a0f8a062ac1c7e6704efdda4a19867cc97030352 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 30 Oct 2019 16:53:19 -0400 Subject: [PATCH] ArrayHtml - Change text node format from string to array Everything in the arrayHtml is associative exept text nodes were just strings. That made it difficult to loop through the whole thing in javascript, so this updates the format to be consistent with everything else. --- ext/afform/core/CRM/Afform/ArrayHtml.php | 6 +++++- .../tests/phpunit/api/v4/formatExamples/apple.php | 4 ++-- .../tests/phpunit/api/v4/formatExamples/banana.php | 4 ++-- .../tests/phpunit/api/v4/formatExamples/cherry.php | 12 ++++++------ .../tests/phpunit/api/v4/formatExamples/comments.php | 12 ++++++------ .../tests/phpunit/api/v4/formatExamples/string.php | 4 ++-- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ext/afform/core/CRM/Afform/ArrayHtml.php b/ext/afform/core/CRM/Afform/ArrayHtml.php index 6f51179262..99fd3221b7 100644 --- a/ext/afform/core/CRM/Afform/ArrayHtml.php +++ b/ext/afform/core/CRM/Afform/ArrayHtml.php @@ -86,6 +86,10 @@ class CRM_Afform_ArrayHtml { return sprintf('', $array['#comment']); } + if (isset($array['#text'])) { + return $array['#text']; + } + $tag = empty($array['#tag']) ? self::DEFAULT_TAG : $array['#tag']; unset($array['#tag']); $children = empty($array['#children']) ? [] : $array['#children']; @@ -183,7 +187,7 @@ class CRM_Afform_ArrayHtml { return $arr; } elseif ($node instanceof DOMText) { - return $node->textContent; + return ['#text' => $node->textContent]; } elseif ($node instanceof DOMComment) { $arr = ['#comment' => $node->nodeValue]; diff --git a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php index dc37c5024b..28d8ba4be2 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php +++ b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/apple.php @@ -3,9 +3,9 @@ return [ 'html' => 'New text!', 'shallow' => [ - ['#tag' => 'strong', '#children' => ['New text!']], + ['#tag' => 'strong', '#children' => [['#text' => 'New text!']]], ], 'deep' => [ - ['#tag' => 'strong', '#children' => ['New text!']], + ['#tag' => 'strong', '#children' => [['#text' => 'New text!']]], ], ]; diff --git a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php index bf33a0a21f..7e0a134caa 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php +++ b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/banana.php @@ -6,7 +6,7 @@ return [ [ '#tag' => 'div', '#children' => [ - ['#tag' => 'strong', '#children' => ['New text!']], + ['#tag' => 'strong', '#children' => [['#text' => 'New text!']]], ['#tag' => 'af-field', 'name' => 'do_not_sms', 'defn' => "{label: 'Do not do any of the emailing'}"], ], ], @@ -15,7 +15,7 @@ return [ [ '#tag' => 'div', '#children' => [ - ['#tag' => 'strong', '#children' => ['New text!']], + ['#tag' => 'strong', '#children' => [['#text' => 'New text!']]], ['#tag' => 'af-field', 'name' => 'do_not_sms', 'defn' => ['label' => 'Do not do any of the emailing']], ], ], diff --git a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/cherry.php b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/cherry.php index 879329bce3..f47efed0e4 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/cherry.php +++ b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/cherry.php @@ -3,13 +3,13 @@ return [ 'html' => 'First Second', 'shallow' => [ - ['#tag' => 'span', '#children' => ['First']], - ' ', - ['#tag' => 'span', '#children' => ['Second']], + ['#tag' => 'span', '#children' => [['#text' => 'First']]], + ['#text' => ' '], + ['#tag' => 'span', '#children' => [['#text' => 'Second']]], ], 'deep' => [ - ['#tag' => 'span', '#children' => ['First']], - ' ', - ['#tag' => 'span', '#children' => ['Second']], + ['#tag' => 'span', '#children' => [['#text' => 'First']]], + ['#text' => ' '], + ['#tag' => 'span', '#children' => [['#text' => 'Second']]], ], ]; diff --git a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/comments.php b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/comments.php index 248cffddb3..c311e930e6 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/comments.php +++ b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/comments.php @@ -6,11 +6,11 @@ return [ [ '#tag' => 'div', '#children' => [ - 'One', + ['#text' => 'One'], ['#comment' => ' uno '], - ' Two ', + ['#text' => ' Two '], ['#comment' => 'dos & so on '], - ' Three', + ['#text' => ' Three'], ], ], ['#comment' => 'tres-a--b---c'], @@ -19,11 +19,11 @@ return [ [ '#tag' => 'div', '#children' => [ - 'One', + ['#text' => 'One'], ['#comment' => ' uno '], - ' Two ', + ['#text' => ' Two '], ['#comment' => 'dos & so on '], - ' Three', + ['#text' => ' Three'], ], ], ['#comment' => 'tres-a--b---c'], diff --git a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/string.php b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/string.php index 18ccc7f487..221e1a36f0 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/formatExamples/string.php +++ b/ext/afform/mock/tests/phpunit/api/v4/formatExamples/string.php @@ -2,6 +2,6 @@ return [ 'html' => 'hello world', - 'shallow' => ['hello world'], - 'deep' => ['hello world'], + 'shallow' => [['#text' => 'hello world']], + 'deep' => [['#text' => 'hello world']], ]; -- 2.25.1