bug #17002 [Console][Table] fixed render row that contains multiple cells. (aitboudad)
This PR was merged into the 2.7 branch.
Discussion
----------
[Console][Table] fixed render row that contains multiple cells.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #16998
| License | MIT
| Doc PR | n/a
Commits
-------
3790ac7
[Console][Table] fixed render row with multiple cells.
This commit is contained in:
commit
dae4267216
@ -343,7 +343,6 @@ class Table
|
||||
|
||||
// Remove any new line breaks and replace it with a new line
|
||||
foreach ($rows[$rowKey] as $column => $cell) {
|
||||
$rows[$rowKey] = $this->fillCells($rows[$rowKey], $column);
|
||||
if (!strstr($cell, "\n")) {
|
||||
continue;
|
||||
}
|
||||
@ -363,7 +362,7 @@ class Table
|
||||
|
||||
$tableRows = array();
|
||||
foreach ($rows as $rowKey => $row) {
|
||||
$tableRows[] = $row;
|
||||
$tableRows[] = $this->fillCells($row);
|
||||
if (isset($unmergedRows[$rowKey])) {
|
||||
$tableRows = array_merge($tableRows, $unmergedRows[$rowKey]);
|
||||
}
|
||||
@ -429,21 +428,23 @@ class Table
|
||||
* fill cells for a row that contains colspan > 1.
|
||||
*
|
||||
* @param array $row
|
||||
* @param int $column
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function fillCells($row, $column)
|
||||
private function fillCells($row)
|
||||
{
|
||||
$cell = $row[$column];
|
||||
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
|
||||
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
|
||||
// insert empty value into rows at column position
|
||||
array_splice($row, $position, 0, '');
|
||||
$newRow = array();
|
||||
foreach ($row as $column => $cell) {
|
||||
$newRow[] = $cell;
|
||||
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
|
||||
foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
|
||||
// insert empty value at column position
|
||||
$newRow[] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $row;
|
||||
return $newRow ?: $row;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -459,6 +459,24 @@ TABLE
|
||||
| ISBN | Title | Author |
|
||||
+------+-------+--------+
|
||||
|
||||
TABLE
|
||||
),
|
||||
'Row with multiple cells' => array(
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
new TableCell('1', array('colspan' => 3)),
|
||||
new TableCell('2', array('colspan' => 2)),
|
||||
new TableCell('3', array('colspan' => 2)),
|
||||
new TableCell('4', array('colspan' => 2)),
|
||||
),
|
||||
),
|
||||
'default',
|
||||
<<<TABLE
|
||||
+--+--+--+--+--+--+--+--+--+
|
||||
| 1 | 2 | 3 | 4 |
|
||||
+--+--+--+--+--+--+--+--+--+
|
||||
|
||||
TABLE
|
||||
),
|
||||
);
|
||||
|
Reference in New Issue
Block a user