diff --git a/docs/src/reference/types/column/link.md b/docs/src/reference/types/column/link.md index 6462e2ea..e514f6dc 100644 --- a/docs/src/reference/types/column/link.md +++ b/docs/src/reference/types/column/link.md @@ -15,15 +15,26 @@ The [`LinkColumnType`](https://github.com/Kreyu/data-table-bundle/blob/main/src/ Sets the value that will be used as a [href attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href). +The callback will always receive three arguments: + +- first represents a data of the column +- second represents a data of the row +- third is always an instance of the column + +Let's assume, that we're displaying a list of products, and each product has one category: + ```php use App\Entity\Category; +use App\Entity\Product; +use Kreyu\Bundle\DataTableBundle\Column\ColumnInterface; use Kreyu\Bundle\DataTableBundle\Column\Type\LinkColumnType; $builder ->addColumn('category', LinkColumnType::class, [ - 'href' => function (Category $category): string { - return $this->urlGenerator->generate('category_show', [ - 'id' => $category->getId(), + 'href' => function (Category $category, Product $product, ColumnInterface $column): string { + return $this->urlGenerator->generate('product_category_show', [ + 'product' => $product->getId(), + 'category' => $category->getId(), ]); }, ]) diff --git a/src/Column/Type/LinkColumnType.php b/src/Column/Type/LinkColumnType.php index d5c6a98a..2ed60c3b 100755 --- a/src/Column/Type/LinkColumnType.php +++ b/src/Column/Type/LinkColumnType.php @@ -13,11 +13,11 @@ final class LinkColumnType extends AbstractColumnType public function buildValueView(ColumnValueView $view, ColumnInterface $column, array $options): void { if (is_callable($href = $options['href'])) { - $href = $href($view->vars['data']); + $href = $href($view->vars['data'], $view->parent->data, $column); } if (is_callable($target = $options['target'])) { - $target = $target($view->vars['data']); + $target = $target($view->vars['data'], $view->parent->data, $column); } $view->vars = array_replace($view->vars, [