From 4c861807853418aac023bc985f813b9a4955bba2 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Tue, 9 Sep 2025 15:57:45 +0200 Subject: [PATCH 1/3] IBX-10370: Added TAB Tables possible extension point to use in another bundles --- .../config/services/ui_config/common.yaml | 2 + src/bundle/Templating/Twig/TableExtension.php | 49 ++++++++++++++++++ .../Event/CollectCustomTableColumnsEvent.php | 50 +++++++++++++++++++ .../Event/CollectCustomTableHeadersEvent.php | 44 ++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 src/bundle/Templating/Twig/TableExtension.php create mode 100644 src/lib/Tab/Event/CollectCustomTableColumnsEvent.php create mode 100644 src/lib/Tab/Event/CollectCustomTableHeadersEvent.php diff --git a/src/bundle/Resources/config/services/ui_config/common.yaml b/src/bundle/Resources/config/services/ui_config/common.yaml index 12885f3a6d..67e1f482b3 100644 --- a/src/bundle/Resources/config/services/ui_config/common.yaml +++ b/src/bundle/Resources/config/services/ui_config/common.yaml @@ -104,6 +104,8 @@ services: Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension: ~ + Ibexa\Bundle\AdminUi\Templating\Twig\TableExtension: ~ + Ibexa\AdminUi\UI\Config\Provider\UserContentTypes: tags: - { name: ibexa.admin_ui.config.provider, key: 'userContentTypes' } diff --git a/src/bundle/Templating/Twig/TableExtension.php b/src/bundle/Templating/Twig/TableExtension.php new file mode 100644 index 0000000000..566c7219ca --- /dev/null +++ b/src/bundle/Templating/Twig/TableExtension.php @@ -0,0 +1,49 @@ +eventDispatcher = $eventDispatcher; + } + + public function getFunctions(): array + { + return [ + new TwigFunction('ibexa_add_custom_table_headers', [$this, 'addCustomHeaders']), + new TwigFunction('ibexa_add_custom_table_columns', [$this, 'addCustomColumns']), + ]; + } + + public function addCustomHeaders(string $tableIdentifier, array $existingHeaders): array + { + $event = new CollectCustomTableHeadersEvent($tableIdentifier, $existingHeaders); + $this->eventDispatcher->dispatch($event); + + return $event->getHeaders(); + } + + public function addCustomColumns(string $tableIdentifier, array $existingColumns, $row): array + { + $event = new CollectCustomTableColumnsEvent($tableIdentifier, $existingColumns, $row); + $this->eventDispatcher->dispatch($event); + + return $event->getColumns(); + } +} diff --git a/src/lib/Tab/Event/CollectCustomTableColumnsEvent.php b/src/lib/Tab/Event/CollectCustomTableColumnsEvent.php new file mode 100644 index 0000000000..e135fae4b6 --- /dev/null +++ b/src/lib/Tab/Event/CollectCustomTableColumnsEvent.php @@ -0,0 +1,50 @@ +tableIdentifier = $tableIdentifier; + $this->columns = $columns; + $this->row = $row; + } + + public function getTableIdentifier(): string + { + return $this->tableIdentifier; + } + + public function getRow() + { + return $this->row; + } + + public function getColumns(): array + { + return $this->columns; + } + + public function addColumn(array $column): void + { + $this->columns[] = $column; + } + + public function addColumnAt(int $index, array $column): void + { + array_splice($this->columns, $index, 0, [$column]); + } +} diff --git a/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php b/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php new file mode 100644 index 0000000000..34d7fa72b4 --- /dev/null +++ b/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php @@ -0,0 +1,44 @@ +tableIdentifier = $tableIdentifier; + $this->headers = $headers; + } + + public function getTableIdentifier(): string + { + return $this->tableIdentifier; + } + + public function getHeaders(): array + { + return $this->headers; + } + + public function addHeader(array $column): void + { + $this->headers[] = $column; + } + + public function addHeaderAt(int $index, array $header): void + { + array_splice($this->headers, $index, 0, [$header]); + } +} From a0b492251a04e9e633974da8024d3d5f1dbf3d09 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Wed, 10 Sep 2025 08:49:52 +0200 Subject: [PATCH 2/3] Added missing phpdocs --- src/bundle/Templating/Twig/TableExtension.php | 12 ++++++++++++ .../Event/CollectCustomTableColumnsEvent.php | 18 ++++++++++++++++++ .../Event/CollectCustomTableHeadersEvent.php | 14 ++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/bundle/Templating/Twig/TableExtension.php b/src/bundle/Templating/Twig/TableExtension.php index 566c7219ca..7c0a5f9f92 100644 --- a/src/bundle/Templating/Twig/TableExtension.php +++ b/src/bundle/Templating/Twig/TableExtension.php @@ -31,6 +31,12 @@ public function getFunctions(): array ]; } + + /** + * @param array> $existingHeaders + * + * @return array> + */ public function addCustomHeaders(string $tableIdentifier, array $existingHeaders): array { $event = new CollectCustomTableHeadersEvent($tableIdentifier, $existingHeaders); @@ -39,6 +45,12 @@ public function addCustomHeaders(string $tableIdentifier, array $existingHeaders return $event->getHeaders(); } + /** + * @param array> $existingColumns + * @param mixed $row + * + * @return array> + */ public function addCustomColumns(string $tableIdentifier, array $existingColumns, $row): array { $event = new CollectCustomTableColumnsEvent($tableIdentifier, $existingColumns, $row); diff --git a/src/lib/Tab/Event/CollectCustomTableColumnsEvent.php b/src/lib/Tab/Event/CollectCustomTableColumnsEvent.php index e135fae4b6..f04d541c63 100644 --- a/src/lib/Tab/Event/CollectCustomTableColumnsEvent.php +++ b/src/lib/Tab/Event/CollectCustomTableColumnsEvent.php @@ -12,10 +12,16 @@ class CollectCustomTableColumnsEvent { private string $tableIdentifier; + /** @var array> */ private array $columns; + /** @var mixed */ private $row; + /** + * @param array> $columns + * @param mixed $row + */ public function __construct(string $tableIdentifier, array $columns, $row) { $this->tableIdentifier = $tableIdentifier; @@ -28,21 +34,33 @@ public function getTableIdentifier(): string return $this->tableIdentifier; } + /** + * @return mixed + */ public function getRow() { return $this->row; } + /** + * @return array> + */ public function getColumns(): array { return $this->columns; } + /** + * @param array $column + */ public function addColumn(array $column): void { $this->columns[] = $column; } + /** + * @param array $column + */ public function addColumnAt(int $index, array $column): void { array_splice($this->columns, $index, 0, [$column]); diff --git a/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php b/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php index 34d7fa72b4..ee25d12a8d 100644 --- a/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php +++ b/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php @@ -14,8 +14,13 @@ class CollectCustomTableHeadersEvent extends Event { private string $tableIdentifier; + + /** @var array> */ private array $headers; + /** + * @param array> $headers + */ public function __construct(string $tableIdentifier, array $headers) { $this->tableIdentifier = $tableIdentifier; @@ -27,16 +32,25 @@ public function getTableIdentifier(): string return $this->tableIdentifier; } + /** + * @return array> + */ public function getHeaders(): array { return $this->headers; } + /** + * @param array $column + */ public function addHeader(array $column): void { $this->headers[] = $column; } + /** + * @param array $header + */ public function addHeaderAt(int $index, array $header): void { array_splice($this->headers, $index, 0, [$header]); From c9812a769bcf483e64e8b32a8fc98a05193f9811 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Wed, 10 Sep 2025 08:59:34 +0200 Subject: [PATCH 3/3] fixed cs --- src/bundle/Templating/Twig/TableExtension.php | 1 - src/lib/Tab/Event/CollectCustomTableHeadersEvent.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/bundle/Templating/Twig/TableExtension.php b/src/bundle/Templating/Twig/TableExtension.php index 7c0a5f9f92..a63e662482 100644 --- a/src/bundle/Templating/Twig/TableExtension.php +++ b/src/bundle/Templating/Twig/TableExtension.php @@ -31,7 +31,6 @@ public function getFunctions(): array ]; } - /** * @param array> $existingHeaders * diff --git a/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php b/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php index ee25d12a8d..8adc1da350 100644 --- a/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php +++ b/src/lib/Tab/Event/CollectCustomTableHeadersEvent.php @@ -14,7 +14,6 @@ class CollectCustomTableHeadersEvent extends Event { private string $tableIdentifier; - /** @var array> */ private array $headers;