Skip to content

Commit 84c15dc

Browse files
rhertoghsamdark
andauthored
Fix associative array cell content in Table widget (#19908)
* Fixed rendering of assosative arrays in `\yii\console\widgets\Table` * Updated readme for #19908 (fix associative array cell content rendering in Table widget) --------- Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
1 parent 504a66d commit 84c15dc

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Yii Framework 2 Change Log
1313
- Enh #19853: Added support for default value for `\yii\helpers\Console::select()` (rhertogh)
1414
- Bug #19868: Added whitespace sanitation for tests, due to updates in ICU 72 (schmunk42)
1515
- Enh #19884: Added support Enums in Query Builder (sk1t0n)
16+
- Bug #19908: Fix associative array cell content rendering in Table widget (rhertogh)
1617
- Bug #19906: Fixed multiline strings in the `\yii\console\widgets\Table` widget (rhertogh)
1718

1819

framework/console/widgets/Table.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ public function setRows(array $rows)
136136
{
137137
$this->rows = array_map(function($row) {
138138
return array_map(function($value) {
139-
return empty($value) && !is_numeric($value) ? ' ' : $value;
139+
return empty($value) && !is_numeric($value)
140+
? ' '
141+
: (is_array($value)
142+
? array_values($value)
143+
: $value);
140144
}, array_values($row));
141145
}, $rows);
142146
return $this;

tests/framework/console/widgets/TableTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ public function testLists()
216216
╔═══════════════╤═══════════════╤══════════════╗
217217
║ test1 │ test2 │ test3 ║
218218
╟───────────────┼───────────────┼──────────────╢
219-
║ testcontent1 │ testcontent2 │ testcontent3 ║
219+
║ • col1 │ testcontent2 │ testcontent3 ║
220+
║ • col2 │ │ ║
220221
╟───────────────┼───────────────┼──────────────╢
221222
║ testcontent21 │ testcontent22 │ • col1 ║
222223
║ │ │ • col2 ║
@@ -226,7 +227,7 @@ public function testLists()
226227

227228
$this->assertEqualsWithoutLE($expected, $table->setHeaders(['test1', 'test2', 'test3'])
228229
->setRows([
229-
['testcontent1', 'testcontent2', 'testcontent3'],
230+
[['key1' => 'col1', 'key2' => 'col2'], 'testcontent2', 'testcontent3'],
230231
['testcontent21', 'testcontent22', ['col1', 'col2']],
231232
])->setScreenWidth(200)->run()
232233
);

0 commit comments

Comments
 (0)