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.
return sprintf('<!--%s-->', $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'];
return $arr;
}
elseif ($node instanceof DOMText) {
- return $node->textContent;
+ return ['#text' => $node->textContent];
}
elseif ($node instanceof DOMComment) {
$arr = ['#comment' => $node->nodeValue];
return [
'html' => '<strong>New text!</strong>',
'shallow' => [
- ['#tag' => 'strong', '#children' => ['New text!']],
+ ['#tag' => 'strong', '#children' => [['#text' => 'New text!']]],
],
'deep' => [
- ['#tag' => 'strong', '#children' => ['New text!']],
+ ['#tag' => 'strong', '#children' => [['#text' => 'New text!']]],
],
];
[
'#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'}"],
],
],
[
'#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']],
],
],
return [
'html' => '<span>First</span> <span>Second</span>',
'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']]],
],
];
[
'#tag' => 'div',
'#children' => [
- 'One',
+ ['#text' => 'One'],
['#comment' => ' uno '],
- ' Two ',
+ ['#text' => ' Two '],
['#comment' => 'dos & so on '],
- ' Three',
+ ['#text' => ' Three'],
],
],
['#comment' => 'tres-a--b---c'],
[
'#tag' => 'div',
'#children' => [
- 'One',
+ ['#text' => 'One'],
['#comment' => ' uno '],
- ' Two ',
+ ['#text' => ' Two '],
['#comment' => 'dos & so on '],
- ' Three',
+ ['#text' => ' Three'],
],
],
['#comment' => 'tres-a--b---c'],
return [
'html' => 'hello world',
- 'shallow' => ['hello world'],
- 'deep' => ['hello world'],
+ 'shallow' => [['#text' => 'hello world']],
+ 'deep' => [['#text' => 'hello world']],
];