-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Grid] [DataObject] List available system columns (#439)
* Move Collector for assets to asset Namespace * Get system colums for data objects. * add translation. * Apply php-cs-fixer changes --------- Co-authored-by: martineiber <martineiber@users.noreply.github.com>
- Loading branch information
1 parent
675fecc
commit 6a1ceb9
Showing
15 changed files
with
466 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
95 changes: 95 additions & 0 deletions
95
src/DataObject/Controller/Grid/GetAvailableColumnsController.php
This file contains 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,95 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Controller\Grid; | ||
|
||
use OpenApi\Attributes\Get; | ||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Property; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; | ||
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; | ||
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\ColumnConfigurationServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class GetAvailableColumnsController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly ColumnConfigurationServiceInterface $columnConfigurationService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws NotFoundException|SearchException | ||
*/ | ||
#[Route( | ||
'/data-object/grid/available-columns/{className}', | ||
name: 'pimcore_studio_api_get_data_objects_grid_available_columns', | ||
methods: ['GET'] | ||
)] | ||
#[IsGranted(UserPermissions::DATA_OBJECTS->value)] | ||
#[Get( | ||
path: self::API_PATH . '/data-object/grid/available-columns/{className}', | ||
operationId: 'data_object_get_available_grid_columns', | ||
description: 'data_object_get_available_grid_columns_description', | ||
summary: 'data_object_get_available_grid_columns_summary', | ||
tags: [Tags::DataObjectsGrid->value] | ||
)] | ||
#[SuccessResponse( | ||
description: 'data_object_get_available_grid_columns_success_response', | ||
content: new JsonContent( | ||
properties: [ | ||
new Property( | ||
property: 'columns', | ||
type: 'array', | ||
items: new Items(ref: ColumnConfiguration::class), | ||
)], | ||
) | ||
)] | ||
#[StringParameter( | ||
name: 'className', | ||
example: 'MyClass', | ||
description: 'Itentifies the class name for which the columns should be retrieved.', | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND, | ||
])] | ||
public function getDataObjectAvailableGridColumns(string $className): JsonResponse | ||
{ | ||
$columns = $this->columnConfigurationService->getAvailableDataObjectColumnConfiguration(); | ||
|
||
return $this->jsonResponse([ | ||
'columns' => $columns, | ||
]); | ||
} | ||
} |
This file contains 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 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
85 changes: 85 additions & 0 deletions
85
src/Grid/Column/Collector/DataObject/SystemFieldCollector.php
This file contains 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,85 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Collector\DataObject; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnCollectorInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnConfiguration; | ||
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\SystemColumnServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; | ||
use function array_key_exists; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SystemFieldCollector implements ColumnCollectorInterface | ||
{ | ||
public function __construct( | ||
private SystemColumnServiceInterface $systemColumnService, | ||
) { | ||
} | ||
|
||
public function getCollectorName(): string | ||
{ | ||
return 'system'; | ||
} | ||
|
||
/** | ||
* @param ColumnDefinitionInterface[] $availableColumnDefinitions | ||
* | ||
* @return ColumnConfiguration[] | ||
*/ | ||
public function getColumnConfigurations(array $availableColumnDefinitions): array | ||
{ | ||
$systemColumns = $this->systemColumnService->getSystemColumnsForDataObjects(); | ||
$columns = []; | ||
foreach ($systemColumns as $columnKey => $type) { | ||
$type = $this->concatType($type); | ||
if (!array_key_exists($type, $availableColumnDefinitions)) { | ||
continue; | ||
} | ||
|
||
$column = new ColumnConfiguration( | ||
key: $columnKey, | ||
group: $this->getCollectorName(), | ||
sortable: $availableColumnDefinitions[$type]->isSortable(), | ||
editable: false, | ||
localizable: false, | ||
locale: null, | ||
type: $availableColumnDefinitions[$type]->getType(), | ||
frontendType: $availableColumnDefinitions[$type]->getFrontendType(), | ||
config: [] | ||
); | ||
|
||
$columns[] = $column; | ||
} | ||
|
||
return $columns; | ||
} | ||
|
||
public function supportedElementTypes(): array | ||
{ | ||
return [ | ||
ElementTypes::TYPE_DATA_OBJECT, | ||
]; | ||
} | ||
|
||
private function concatType(string $type): string | ||
{ | ||
return $this->getCollectorName() . '.' . $type; | ||
} | ||
} |
This file contains 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 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 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 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 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 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,40 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\PathParameter; | ||
use OpenApi\Attributes\Schema; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] | ||
final class StringParameter extends PathParameter | ||
{ | ||
public function __construct( | ||
string $name, | ||
string $example, | ||
string $description, | ||
bool $required = true, | ||
) { | ||
parent::__construct( | ||
name: $name, | ||
description: $description, | ||
in: 'path', | ||
required: $required, | ||
schema: new Schema(type: 'string', example: $example), | ||
); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.