packagefactory / enumbasedcontentdimensionsource
Package for implementing content dimension sources via PHP enums
Package info
codeberg.org/PackageFactory/enumbasedcontentdimensionsource
Type:neos-package
pkg:composer/packagefactory/enumbasedcontentdimensionsource
Requires
- php: ^8.4
- neos/contentrepository-core: ^9.0
- neos/contentrepositoryregistry: ^9.0
Requires (Dev)
- mikey179/vfsstream: ^1.6.11
- neos/contentgraph-doctrinedbaladapter: ^9.0
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-30 05:44:03 UTC
README
Usage
Instead of completely configuring content dimensions via YAML, with this package you can also implement an enum-backed interface. This can then be used for type-safe access to the content repository's dimensions, e.g. for API endpoints and makes your dimension setup properly testable.
Implementation
You can implement an enum per content dimension; it has to be string-backed and implement PackageFactory\EnumBasedContentDimensionSource\Domain\ContentDimensionMetadataProvider.
See the test fixtures or the following example:
<?php
declare(strict_types=1);
namespace Acme\Site\Domain;
use Neos\ContentRepository\Core\Dimension\ContentDimensionConstraints;
use Neos\ContentRepository\Core\Dimension\ContentDimensionConstraintSet;
use Neos\ContentRepository\Core\Dimension\ContentDimensionId;
use PackageFactory\EnumBasedContentDimensionSource\Domain\ContentDimensionMetadataProvider;
enum Language: string implements ContentDimensionMetadataProvider
{
case LANGUAGE_EN = 'en';
case LANGUAGE_DE = 'de';
case LANGUAGE_LTZ = 'ltz';
public static function getContentDimensionId(): ContentDimensionId
{
return new ContentDimensionId('language');
}
/**
* @return array<string,mixed>
*/
public static function getDimensionConfiguration(string $environmentDiscriminator): array
{
return [
'icon' => 'language',
'label' => 'Language'
];
}
/**
* @return array<string,mixed>
*/
public function getDimensionValueConfiguration(string $environmentDiscriminator): array
{
return [
'label' => 'i18n',
];
}
/**
* @return array<int,self>
*/
public function getSpecializations(): array
{
return match ($this) {
self::LANGUAGE_EN => [],
self::LANGUAGE_DE => [self::LANGUAGE_LTZ],
};
}
public function getConstraints(): ContentDimensionConstraintSet
{
return match ($this) {
default => new ContentDimensionConstraintSet([]),
};
}
}
Configuration
Use the ContentRepositoryRegistry configuration to enable the enum-based content dimension source, either directly:
Neos:
ContentRepositoryRegistry:
contentRepositories:
my-cr:
contentDimensionSource:
factoryObjectName: PackageFactory\EnumBasedContentDimensionSource\Infrastructure\EnumBasedContentDimensionSourceFactory
options:
contentDimensions:
- Acme\Site\Domain\Language
environmentDiscriminator: 'default'
or as usual via preset.
Environment Discriminator
To achieve feature parity with the configuration based content dimension source, which can be adjusted via environment configuration,
you can configure an environment discriminator string that can then be further evaluated in ::getDimensionConfiguration and ::getDimensionValueConfiguration
Migration
To migrate from configuration-based content dimensions, just create your enum(s) exactly reflecting the previous config and replace the content dimension source as described above. No migrations are necessary otherwise.