Search by

packagefactory / enumbasedcontentdimensionsource

Nezaniel

Package for implementing content dimension sources via PHP enums

Package info

codeberg.org/PackageFactory/enumbasedcontentdimensionsource

Issues

Type:neos-package

pkg:composer/packagefactory/enumbasedcontentdimensionsource

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

1.0.0 2026-09-29 08:48 UTC

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.