diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f0be78..b8a532d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * feat(builder): allow to add block between children * feat(builder): improve UI to add new block * feat(settings): allow to edit a setting in plain page +* feat(crud/index): allow to define row attributes ## [v1.26.0] - 2025-03-17 ### Added diff --git a/src/core/Crud/CrudConfiguration.php b/src/core/Crud/CrudConfiguration.php index c8d8935..c083d9d 100644 --- a/src/core/Crud/CrudConfiguration.php +++ b/src/core/Crud/CrudConfiguration.php @@ -2,6 +2,8 @@ namespace App\Core\Crud; +use App\Core\Entity\EntityInterface; + /** * class CrudConfiguration. * @@ -28,6 +30,7 @@ class CrudConfiguration protected string $sortableCollectionProperty = 'sortOrder'; protected ?string $defaultLocale = null; protected array $showActions = []; + protected array $listRowAttributes = []; protected static $self; @@ -247,6 +250,26 @@ class CrudConfiguration return $this->viewDatas[$context][$name] ?? $defaultValue; } + public function setListRowAttributes(string $context, array $attributes): self + { + $this->listRowAttributes[$context] = $attributes; + + return $this; + } + + public function getListRowAttributes(string $context, EntityInterface $entity): array + { + $attributes = $this->listRowAttributes[$context] ?? []; + + foreach ($attributes as $key => $attribute) { + if (is_callable($attribute)) { + $attributes[$key] = $attribute($entity); + } + } + + return $attributes; + } + // -- public function setField(string $context, string $label, string $field, array $options): self diff --git a/src/core/Resources/views/admin/crud/index.html.twig b/src/core/Resources/views/admin/crud/index.html.twig index 596fdaf..fa5dcda 100644 --- a/src/core/Resources/views/admin/crud/index.html.twig +++ b/src/core/Resources/views/admin/crud/index.html.twig @@ -193,7 +193,10 @@ {%- endif -%} {%- endset -%} -