-
Notifications
You must be signed in to change notification settings - Fork 17
IBX-10370: Added Tab Tables possible extension point to use in another bundles #1706
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
Open
ViniTou
wants to merge
3
commits into
4.6
Choose a base branch
from
ibx-10370-headers-and-columns
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+187
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\AdminUi\Templating\Twig; | ||
|
||
use Ibexa\AdminUi\Tab\Event\CollectCustomTableColumnsEvent; | ||
use Ibexa\AdminUi\Tab\Event\CollectCustomTableHeadersEvent; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
final class TableExtension extends AbstractExtension | ||
{ | ||
private EventDispatcherInterface $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->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']), | ||
]; | ||
} | ||
|
||
/** | ||
* @param array<int, array<string, string|bool>> $existingHeaders | ||
* | ||
* @return array<int, array<string, string|bool>> | ||
*/ | ||
public function addCustomHeaders(string $tableIdentifier, array $existingHeaders): array | ||
{ | ||
$event = new CollectCustomTableHeadersEvent($tableIdentifier, $existingHeaders); | ||
$this->eventDispatcher->dispatch($event); | ||
|
||
return $event->getHeaders(); | ||
} | ||
|
||
/** | ||
* @param array<int, array<string, string|bool>> $existingColumns | ||
* @param mixed $row | ||
* | ||
* @return array<int, array<string, string|bool>> | ||
*/ | ||
public function addCustomColumns(string $tableIdentifier, array $existingColumns, $row): array | ||
{ | ||
$event = new CollectCustomTableColumnsEvent($tableIdentifier, $existingColumns, $row); | ||
$this->eventDispatcher->dispatch($event); | ||
|
||
return $event->getColumns(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\Tab\Event; | ||
|
||
class CollectCustomTableColumnsEvent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
private string $tableIdentifier; | ||
|
||
/** @var array<int, array<string, string|bool>> */ | ||
private array $columns; | ||
|
||
/** @var mixed */ | ||
private $row; | ||
|
||
/** | ||
* @param array<int, array<string, string|bool>> $columns | ||
* @param mixed $row | ||
*/ | ||
public function __construct(string $tableIdentifier, array $columns, $row) | ||
{ | ||
$this->tableIdentifier = $tableIdentifier; | ||
$this->columns = $columns; | ||
$this->row = $row; | ||
} | ||
|
||
public function getTableIdentifier(): string | ||
{ | ||
return $this->tableIdentifier; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getRow() | ||
{ | ||
return $this->row; | ||
} | ||
|
||
/** | ||
* @return array<int, array<string, string|bool>> | ||
*/ | ||
public function getColumns(): array | ||
{ | ||
return $this->columns; | ||
} | ||
|
||
/** | ||
* @param array<string, string|bool> $column | ||
*/ | ||
public function addColumn(array $column): void | ||
{ | ||
$this->columns[] = $column; | ||
} | ||
|
||
/** | ||
* @param array<string, string|bool> $column | ||
*/ | ||
public function addColumnAt(int $index, array $column): void | ||
{ | ||
array_splice($this->columns, $index, 0, [$column]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\Tab\Event; | ||
|
||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
class CollectCustomTableHeadersEvent extends Event | ||
{ | ||
private string $tableIdentifier; | ||
|
||
/** @var array<int, array<string, string|bool>> */ | ||
private array $headers; | ||
|
||
/** | ||
* @param array<int, array<string, string|bool>> $headers | ||
*/ | ||
public function __construct(string $tableIdentifier, array $headers) | ||
{ | ||
$this->tableIdentifier = $tableIdentifier; | ||
$this->headers = $headers; | ||
} | ||
|
||
public function getTableIdentifier(): string | ||
{ | ||
return $this->tableIdentifier; | ||
} | ||
|
||
/** | ||
* @return array<int, array<string, string|bool>> | ||
*/ | ||
public function getHeaders(): array | ||
{ | ||
return $this->headers; | ||
} | ||
|
||
/** | ||
* @param array<string, string|bool> $column | ||
*/ | ||
public function addHeader(array $column): void | ||
{ | ||
$this->headers[] = $column; | ||
} | ||
|
||
/** | ||
* @param array<string, string|bool> $header | ||
*/ | ||
public function addHeaderAt(int $index, array $header): void | ||
{ | ||
array_splice($this->headers, $index, 0, [$header]); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage is missing.