Skip to main content
Version: Next

Config Hydrator

The config hydrator converts raw configuration arrays (loaded from YAML storage) into typed WidgetConfig DTOs that the API layer serializes and returns to the frontend.

Interface

namespace Pimcore\Bundle\StudioDashboardsBundle\Hydrator\Widget;

use Pimcore\Bundle\StudioDashboardsBundle\Schema\Widget\WidgetConfig;

interface ConfigHydratorInterface
{
public function getSupportedWidgetType(): string;

public function hydrate(array $widgetData): WidgetConfig;
}
MethodPurpose
getSupportedWidgetType()Must return the same type identifier as the matching repository
hydrate()Returns a WidgetConfig subclass built from the raw config array

WidgetConfig and Subclasses

WidgetConfig is the base class. Its constructor accepts: id, name, widgetType, icon (optional ElementIcon), and visualization (optional string). Fields specific to a widget type - such as color, isWriteable, and data-display options - live on type-specific subclasses.

Create a dedicated subclass for your custom widget type:

namespace App\Widget\Schema;

use Pimcore\Bundle\StudioBackendBundle\Response\ElementIcon;
use Pimcore\Bundle\StudioDashboardsBundle\Schema\Widget\WidgetConfig;

final class TopAssetsWidgetConfig extends WidgetConfig
{
public function __construct(
string $id,
string $name,
?ElementIcon $icon,
private readonly string $color,
private readonly bool $isWriteable = true,
?string $visualization = null,
private readonly int $limit = 10,
) {
parent::__construct($id, $name, 'top_assets', $icon, $visualization);
}

public function getColor(): string { return $this->color; }

public function isWriteable(): bool { return $this->isWriteable; }

public function getLimit(): int { return $this->limit; }
}

Example Hydrator

namespace App\Widget\Hydrator;

use App\Widget\Schema\TopAssetsWidgetConfig;
use Pimcore\Bundle\StudioBackendBundle\Icon\Service\IconServiceInterface;
use Pimcore\Bundle\StudioDashboardsBundle\Hydrator\Widget\ConfigHydratorInterface;
use Pimcore\Bundle\StudioDashboardsBundle\Schema\Widget\WidgetConfig;
use Pimcore\Bundle\StudioDashboardsBundle\Service\Loader\Widget\TaggedIteratorHydrator;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag(TaggedIteratorHydrator::HYDRATOR_TAG)]
final class TopAssetsConfigHydrator implements ConfigHydratorInterface
{
public function __construct(
private readonly IconServiceInterface $iconService,
) {
}

public function getSupportedWidgetType(): string
{
return 'top_assets';
}

public function hydrate(array $widgetData): WidgetConfig
{
$icon = empty($widgetData['icon'])
? null
: $this->iconService->getIconForValue($widgetData['icon']);

return new TopAssetsWidgetConfig(
id: $widgetData['id'],
name: $widgetData['name'],
icon: $icon,
color: $widgetData['color'],
isWriteable: $widgetData['isWriteable'],
visualization: $widgetData['visualization'] ?? null,
limit: $widgetData['limit'] ?? 10,
);
}
}

The #[AutoconfigureTag(TaggedIteratorHydrator::HYDRATOR_TAG)] attribute registers the class automatically - no additional service definition is required beyond normal autowiring.