Config Repository
The config repository is responsible for storing and loading widget configuration. Every
custom widget type needs one repository class that implements ConfigRepositoryInterface.
Interface
namespace Pimcore\Bundle\StudioDashboardsBundle\Repository\Widget;
interface ConfigRepositoryInterface
{
public function getSupportedWidgetType(): string;
/** @return string[] */
public function getRequiredPermissions(): array;
/** @return string[] */
public function getVisualizationOptions(): array;
public function getDataConfigurationKey(): ?string;
public function getDataConfigurationOptions(): array;
public function createConfiguration(array $widgetData): string;
public function updateConfiguration(array $widgetData): void;
public function getConfiguration(string $widgetId): array;
public function listConfigurations(): array;
public function deleteConfiguration(string $widgetId): void;
}
| Method | Purpose |
|---|---|
getSupportedWidgetType() | Returns the unique string identifier of the widget type (e.g. top_assets) |
getRequiredPermissions() | User permissions checked before the widget data is served |
getVisualizationOptions() | List of allowed visualization modes (e.g. table, bar_chart) |
getDataConfigurationKey() | Config key shown in the edit form drop-down (or null if unused) |
getDataConfigurationOptions() | Selectable options for the data configuration drop-down |
createConfiguration() | Persists a new widget config and returns the generated ID |
updateConfiguration() | Overwrites an existing widget config |
getConfiguration() | Returns one widget config by ID |
listConfigurations() | Returns all configs for this type |
deleteConfiguration() | Removes a widget config |
Extending AbstractConfigRepository
AbstractConfigRepository handles the boilerplate CRUD logic against Pimcore's
LocationAwareConfigRepository. Extend it and implement only the abstract methods:
namespace App\Widget\Repository;
use Pimcore\Bundle\StudioDashboardsBundle\Repository\Widget\AbstractConfigRepository;
use Pimcore\Bundle\StudioDashboardsBundle\Service\Loader\Widget\TaggedIteratorRepository;
use Pimcore\Bundle\StudioDashboardsBundle\Util\Constant\VisualizationOptions;
use Pimcore\Config\LocationAwareConfigRepository;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
#[AutoconfigureTag(TaggedIteratorRepository::REPOSITORY_TAG)]
final class TopAssetsConfigRepository extends AbstractConfigRepository
{
private ?LocationAwareConfigRepository $repository = null;
public function __construct(
private readonly array $widgetConfigurations,
private readonly array $storageConfig,
// ... other dependencies
) {
parent::__construct(/* NormalizerInterface */);
}
public function getSupportedWidgetType(): string
{
return 'top_assets';
}
public function getVisualizationOptions(): array
{
return [
VisualizationOptions::TABLE->value,
VisualizationOptions::BAR_CHART->value,
];
}
public function createConfiguration(array $widgetData): string
{
$config = $this->validateData($widgetData);
$this->saveConfigData($config);
return $config->getId();
}
protected function getWidgetNode(): string
{
return 'top_assets_widgets';
}
protected function getRepository(): LocationAwareConfigRepository
{
if ($this->repository === null) {
$this->repository = new LocationAwareConfigRepository(
$this->widgetConfigurations,
'pimcore_studio_dashboards_top_assets_widgets',
$this->storageConfig
);
}
return $this->repository;
}
protected function validateData(array $widgetData): SaveWidgetConfig
{
// Validate and return a SaveWidgetConfig (or custom subclass)
}
}
The #[AutoconfigureTag(TaggedIteratorRepository::REPOSITORY_TAG)] attribute registers the
class with the tagged-iterator loader - no manual service definition is needed.
Service Configuration
Wire the constructor arguments for the storage location in your bundle's services.yaml:
App\Widget\Repository\TopAssetsConfigRepository:
arguments:
$widgetConfigurations: '%pimcore_studio_dashboards.top_assets_widgets%'
$storageConfig: '%pimcore_studio_dashboards.config_location.top_assets_widgets%'
The %pimcore_studio_dashboards.top_assets_widgets% and
%pimcore_studio_dashboards.config_location.top_assets_widgets% parameters are populated by
the bundle's Configuration class once the widget node is registered there. See
Registering the Widget Type for how to add the config node.