diff --git a/docs/table.md b/docs/table.md index 49064c74b0..20720d8cde 100644 --- a/docs/table.md +++ b/docs/table.md @@ -564,7 +564,7 @@ Please note that if you are redefining {php:meth}`Table\Column::getHeaderCellHtm and you wish to preserve functionality of setting custom attributes and classes, you should generate your TD/TH tag through getTag method. -:::{php:method} getTag($tag, $position, $value) +:::{php:method} getTag($position, $attr, $value) Will apply cell-based attributes or classes then use {php:meth}`App::getTag` to generate HTML tag and encode it's content. ::: diff --git a/src/Table.php b/src/Table.php index e54549df8b..39bc46c4ac 100644 --- a/src/Table.php +++ b/src/Table.php @@ -613,7 +613,7 @@ public function getTotalsRowHtml(): string foreach ($this->columns as $name => $column) { // if no totals plan, then show dash, but keep column formatting if (!isset($this->totalsPlan[$name])) { - $output[] = $column->getTag('foot', '-'); + $output[] = $column->getTag('foot', [], '-'); continue; } @@ -627,7 +627,7 @@ public function getTotalsRowHtml(): string } // otherwise just show it, for example, "Totals:" cell - $output[] = $column->getTag('foot', $this->totalsPlan[$name]); + $output[] = $column->getTag('foot', [], $this->totalsPlan[$name]); } return implode('', $output); diff --git a/src/Table/Column.php b/src/Table/Column.php index b1e2aa778f..d40837c025 100644 --- a/src/Table/Column.php +++ b/src/Table/Column.php @@ -326,10 +326,10 @@ public function getTagAttributes(string $position, array $attr = []): array * added through addClass and setAttr. * * @param 'head'|'body'|'foot' $position - * @param string|array, 2?: string|array|null}|string>|null $value either HTML or array defining HTML structure, see App::getTag help - * @param array $attr extra attributes to apply on the tag + * @param array> $attr + * @param string|array, 2?: string|array|null}|string>|null $value */ - public function getTag(string $position, $value, array $attr = []): string + public function getTag(string $position, $attr, $value): string { $attr = $this->getTagAttributes($position, $attr); @@ -354,7 +354,7 @@ public function getHeaderCellHtml(Field $field = null, $value = null): string } if ($field === null) { - return $this->getTag('head', $this->caption ?? '', $this->table->sortable ? ['class' => ['disabled']] : []); + return $this->getTag('head', $this->table->sortable ? ['class' => ['disabled']] : [], $this->caption ?? ''); } // if $this->caption is empty, header caption will be overridden by linked field definition @@ -392,7 +392,7 @@ public function getHeaderCellHtml(Field $field = null, $value = null): string } } - return $this->getTag('head', [['div', ['class' => $class], $caption]], $attr); + return $this->getTag('head', $attr, [['div', ['class' => $class], $caption]]); } /** @@ -402,7 +402,7 @@ public function getHeaderCellHtml(Field $field = null, $value = null): string */ public function getTotalsCellHtml(Field $field, $value): string { - return $this->getTag('foot', $this->getApp()->uiPersistence->typecastSaveField($field, $value)); + return $this->getTag('foot', [], $this->getApp()->uiPersistence->typecastSaveField($field, $value)); } /** @@ -418,7 +418,7 @@ public function getTotalsCellHtml(Field $field, $value): string */ public function getDataCellHtml(Field $field = null, array $attr = []): string { - return $this->getTag('body', [$this->getDataCellTemplate($field)], $attr); + return $this->getTag('body', $attr, [$this->getDataCellTemplate($field)]); } /** diff --git a/src/Table/Column/ActionButtons.php b/src/Table/Column/ActionButtons.php index 1b66414628..53013fc88c 100644 --- a/src/Table/Column/ActionButtons.php +++ b/src/Table/Column/ActionButtons.php @@ -107,13 +107,13 @@ public function addModal($button, $defaults, \Closure $callback, $owner = null, } #[\Override] - public function getTag(string $position, $value, $attr = []): string + public function getTag(string $position, $attr, $value): string { if ($this->table->hasCollapsingCssActionColumn && $position === 'body') { $attr['class'][] = 'collapsing'; } - return parent::getTag($position, $value, $attr); + return parent::getTag($position, $attr, $value); } #[\Override] diff --git a/src/Table/Column/ActionMenu.php b/src/Table/Column/ActionMenu.php index ac4a9b85a1..099c866062 100644 --- a/src/Table/Column/ActionMenu.php +++ b/src/Table/Column/ActionMenu.php @@ -41,13 +41,13 @@ class ActionMenu extends Table\Column public $icon = 'dropdown'; #[\Override] - public function getTag(string $position, $value, $attr = []): string + public function getTag(string $position, $attr, $value): string { if ($this->table->hasCollapsingCssActionColumn && $position === 'body') { $attr['class'][] = 'collapsing'; } - return parent::getTag($position, $value, $attr); + return parent::getTag($position, $attr, $value); } /** diff --git a/src/Table/Column/ColorRating.php b/src/Table/Column/ColorRating.php index e4581069e7..5c3c75f49e 100644 --- a/src/Table/Column/ColorRating.php +++ b/src/Table/Column/ColorRating.php @@ -67,7 +67,7 @@ public function getDataCellHtml(Field $field = null, array $attr = []): string throw new Exception('ColorRating can be used only with model field'); } - return $this->getTag('body', '{$' . $field->shortName . '}', $attr); + return $this->getTag('body', $attr, '{$' . $field->shortName . '}'); } #[\Override] diff --git a/src/Table/Column/Money.php b/src/Table/Column/Money.php index c743093b2c..965a22cbca 100644 --- a/src/Table/Column/Money.php +++ b/src/Table/Column/Money.php @@ -38,7 +38,7 @@ public function getDataCellHtml(Field $field = null, array $attr = []): string throw new Exception('Money column requires a field'); } - return $this->getTag('body', '{$' . $field->shortName . '}', $attr); + return $this->getTag('body', $attr, '{$' . $field->shortName . '}'); } #[\Override]