Skip to content

Commit

Permalink
rex_list: refactor logic into new formatRowAttributes() method (#5826)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 29, 2023
1 parent 31929eb commit d4265f3
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions redaxo/src/core/lib/list.php
Expand Up @@ -1096,6 +1096,25 @@ public function formatValue($value, $format, $escape, $field = null)
return $value;
}

protected function formatRowAttributes(): string
{
$rowAttributesCallable = null;
if (is_callable($this->rowAttributes)) {
$rowAttributesCallable = $this->rowAttributes;
} elseif ($this->rowAttributes) {
$rowAttributes = rex_string::buildAttributes($this->rowAttributes);
$rowAttributesCallable = function (self $list) use ($rowAttributes) {
return $this->replaceVariables($rowAttributes);
};
}

if ($rowAttributesCallable) {
return ' ' . $rowAttributesCallable($this);
}

return '';
}

/**
* @return string
*/
Expand Down Expand Up @@ -1243,22 +1262,9 @@ public function get()
$maxRows = $nbRows;
}

$rowAttributesCallable = null;
if (is_callable($this->rowAttributes)) {
$rowAttributesCallable = $this->rowAttributes;
} elseif ($this->rowAttributes) {
$rowAttributes = rex_string::buildAttributes($this->rowAttributes);
$rowAttributesCallable = function () use ($rowAttributes) {
return $this->replaceVariables($rowAttributes);
};
}

$s .= ' <tbody>' . "\n";
for ($i = 0; $i < $maxRows; ++$i) {
$rowAttributes = '';
if ($rowAttributesCallable) {
$rowAttributes = ' ' . $rowAttributesCallable($this);
}
$rowAttributes = $this->formatRowAttributes();

$s .= ' <tr' . $rowAttributes . ">\n";
foreach ($columnNames as $columnName) {
Expand Down

0 comments on commit d4265f3

Please sign in to comment.