Skip to content

Commit

Permalink
Fix associative array cell content in Table widget (#19908)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
rhertogh and samdark committed Aug 9, 2023
1 parent 504a66d commit 84c15dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Yii Framework 2 Change Log
- Enh #19853: Added support for default value for `\yii\helpers\Console::select()` (rhertogh)
- Bug #19868: Added whitespace sanitation for tests, due to updates in ICU 72 (schmunk42)
- Enh #19884: Added support Enums in Query Builder (sk1t0n)
- Bug #19908: Fix associative array cell content rendering in Table widget (rhertogh)
- Bug #19906: Fixed multiline strings in the `\yii\console\widgets\Table` widget (rhertogh)


Expand Down
6 changes: 5 additions & 1 deletion framework/console/widgets/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ public function setRows(array $rows)
{
$this->rows = array_map(function($row) {
return array_map(function($value) {
return empty($value) && !is_numeric($value) ? ' ' : $value;
return empty($value) && !is_numeric($value)
? ' '
: (is_array($value)
? array_values($value)
: $value);
}, array_values($row));
}, $rows);
return $this;
Expand Down
5 changes: 3 additions & 2 deletions tests/framework/console/widgets/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public function testLists()
╔═══════════════╤═══════════════╤══════════════╗
║ test1 │ test2 │ test3 ║
╟───────────────┼───────────────┼──────────────╢
║ testcontent1 │ testcontent2 │ testcontent3 ║
║ • col1 │ testcontent2 │ testcontent3 ║
║ • col2 │ │ ║
╟───────────────┼───────────────┼──────────────╢
║ testcontent21 │ testcontent22 │ • col1 ║
║ │ │ • col2 ║
Expand All @@ -226,7 +227,7 @@ public function testLists()

$this->assertEqualsWithoutLE($expected, $table->setHeaders(['test1', 'test2', 'test3'])
->setRows([
['testcontent1', 'testcontent2', 'testcontent3'],
[['key1' => 'col1', 'key2' => 'col2'], 'testcontent2', 'testcontent3'],
['testcontent21', 'testcontent22', ['col1', 'col2']],
])->setScreenWidth(200)->run()
);
Expand Down

0 comments on commit 84c15dc

Please sign in to comment.