Skip to content

Unify Table\Column::getTag() params order #2155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::
Expand Down
4 changes: 2 additions & 2 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, array{0: string, 1?: array<0|string, string|bool>, 2?: string|array|null}|string>|null $value either HTML or array defining HTML structure, see App::getTag help
* @param array<string, string|bool|array> $attr extra attributes to apply on the tag
* @param array<string, string|bool|array<string>> $attr
* @param string|array<int, array{0: string, 1?: array<0|string, string|bool>, 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);

Expand All @@ -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
Expand Down Expand Up @@ -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]]);
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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)]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Table/Column/ActionButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/Table/Column/ActionMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Table/Column/ColorRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/Table/Column/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down