-
-
Notifications
You must be signed in to change notification settings - Fork 6
!!! FEATURE: Extensible meta data properties #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from 22 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
edc21d6
!!! FEATURE: Extensible meta data properties
bwaidelich 93294c7
Add `MetaDataManager::getMetaDataPropertyValues()`
bwaidelich c1debab
Respect asset source id
bwaidelich 8fb2e4e
Split `MetaDataConfiguration` into `MetaDataPropertyDefinitions` and …
bwaidelich e7bd6e2
Apply suggestion from @bwaidelich
bwaidelich 6f06c16
FIX: MetaDataDimensionSpacePointSet parsing
c4ll-m3-j4ck 8d4df59
WIP: TASK: Add translations
c4ll-m3-j4ck e902ffb
FEATURE: Add AssetMetaData eel-helper
c4ll-m3-j4ck 8d03077
FEATURE: Add migration for existing metadata from Asset
c4ll-m3-j4ck d81f183
FIX: Support assetSources in eel-helper, dsp hashing calculation
c4ll-m3-j4ck c4e076a
FIX: Adapt MigrationCommandController to new Reference interface
c4ll-m3-j4ck 46c2194
FEATURE: Convenience initializer for MetaDataAssetReference
c4ll-m3-j4ck 86a1684
FEATURE: Implement content-repository DSP adapter
c4ll-m3-j4ck adf9ad7
FEATURE: Implement i18n handling for properties from yaml
c4ll-m3-j4ck a7520f3
TASK: Replace dsp hash retrieval with generalized map
c4ll-m3-j4ck 40967cb
WIP: Cleanup dimensions fetching from cr
c4ll-m3-j4ck e3cabbd
TASK: Rename and move createAllPresetCombinations
dlubitz f9fca9a
TASK: Add VO equals method for comparison
dlubitz 0d37e45
TASK: Allow to fetch values without fallback and to fetch values from…
dlubitz b3df3e1
TASK: Allow unsetting values without DSP
dlubitz 6df8fca
BUGFIX: Fix migration command
dlubitz f3719cb
TASK: Allow PHP 8.5
Sebobo 4831e14
Fix doc comments of `MetaDataDimensionSpacePoint`
bwaidelich ac9d36c
Update README to reflect current version
bwaidelich 7d4c8f1
BUGFIX: Enumerate dimension space points by preset value
bwaidelich 4acb3bc
BUGFIX: Allow metadata properties without `ui` configuration
bwaidelich 516c0c3
!!! FEATURE: Respect `globalScope` of metadata properties
bwaidelich 85ac242
TASK: Cover enumeration of dimension space points by preset value
bwaidelich ec3cdf2
!!! FEATURE: Allow assets to be found by a metadata filter
bwaidelich 543992c
FEATURE: Add `getMetaDataProperty()` to the Eel helper
bwaidelich af564ce
FEATURE: Coerce metadata values to the configured property type
bwaidelich bbeee7a
TASK: Rework the test suite along the seams of the package
bwaidelich 79704fe
TASK: Move two paragraphs back out of the "Property types" section
bwaidelich fed6ec5
FIX: Add getOwnValue method to MetaDataPropertyValue for fusion access
c4ll-m3-j4ck 802aa88
Merge pull request #15 from c4ll-m3-j4ck/feature/global-scope-metadat…
bwaidelich 5ac2b4b
FEATURE: Skip metadata properties that are configured to `null`
bwaidelich ea8eba9
Merge branch 'feature/global-scope-metadata-properties' of https://gi…
bwaidelich 59da8b9
FEATURE: Allow nullable ui configuration
c4ll-m3-j4ck e1c7540
Merge pull request #16 from c4ll-m3-j4ck/feature/global-scope-metadat…
bwaidelich 190a95b
TASK: Add github action to run tests
Sebobo 3026e13
TASK: Bump phpstan to max level and adjust code
Sebobo 8f7421e
TASK: Split settings
Sebobo cc63a39
TASK: Allow translation shorthand strings for metadata property labels
Sebobo 4835685
TASK: Narrow phpstan version to prevent errors in CI
Sebobo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,110 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\MetaData\Command; | ||
|
|
||
| use InvalidArgumentException; | ||
| use JsonException; | ||
| use Neos\Flow\Cli\CommandController; | ||
| use Neos\MetaData\Domain\Dto\MetaDataAssetReference; | ||
| use Neos\MetaData\Domain\Dto\MetaDataDimensionSpacePoint; | ||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyName; | ||
| use Neos\MetaData\MetaDataManager; | ||
|
|
||
| final class AssetMetaDataCommandController extends CommandController | ||
| { | ||
|
|
||
| public function __construct( | ||
| private readonly MetaDataManager $metaDataManager, | ||
| ) | ||
| { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * Sets a metadata property for an asset to a specific value | ||
| * | ||
| * @param string $assetId ID of the asset to set the metadata property for | ||
| * @param string $property name of the metadata property to set | ||
| * @param string $value value of the metadata property | ||
| * @param string|null $assetSource optional asset source - default = "neos" | ||
| * @param string|null $dimensionSpacePoint optional dimension space point as JSON (e.g. `'{"language": "de"}') - default = the configured defaultDimensionSpacePoint | ||
| */ | ||
| public function setCommand(string $assetId, string $property, string $value, string|null $assetSource = null, string|null $dimensionSpacePoint = null): void | ||
| { | ||
| $dimensionSpacePointDecoded = $dimensionSpacePoint !== null ? self::parseDimensionSpacePoint($dimensionSpacePoint) : null; | ||
| $assetReference = MetaDataAssetReference::create($assetSource ?? 'neos', $assetId); | ||
| $this->metaDataManager->setMetaDataPropertyValue( | ||
| $assetReference, | ||
| MetaDataPropertyName::fromString($property), | ||
| $value, | ||
| $dimensionSpacePointDecoded, | ||
| ); | ||
| $message = sprintf('Metadata property "%s" of asset "%s" was set to "%s"', $property, $value, $assetId); | ||
| if ($dimensionSpacePointDecoded !== null) { | ||
| $message .= sprintf(' for dimension space point "%s"', $dimensionSpacePointDecoded->hash); | ||
| } | ||
| $this->outputLine("<success>$message</success>"); | ||
| } | ||
|
|
||
| /** | ||
| * Removes a metadata property for an asset | ||
| * | ||
| * @param string $assetId ID of the asset to unset the metadata property for | ||
| * @param string $property name of the metadata property to unset | ||
| * @param string|null $assetSource optional asset source - default = "neos" | ||
| * @param string|null $dimensionSpacePoint optional dimension space point as JSON (e.g. `'{"language": "de"}') - default = the configured defaultDimensionSpacePoint | ||
| */ | ||
| public function unsetCommand(string $assetId, string $property, string|null $assetSource = null, string|null $dimensionSpacePoint = null): void | ||
| { | ||
| $dimensionSpacePointDecoded = $dimensionSpacePoint !== null ? self::parseDimensionSpacePoint($dimensionSpacePoint) : null; | ||
| $assetReference = MetaDataAssetReference::create($assetSource ?? 'neos', $assetId); | ||
| $this->metaDataManager->unsetMetaDataPropertyValue( | ||
| $assetReference, | ||
| MetaDataPropertyName::fromString($property), | ||
| $dimensionSpacePointDecoded, | ||
| ); | ||
| $message = sprintf('Metadata property "%s" of asset "%s" was unset', $property, $assetId); | ||
| if ($dimensionSpacePointDecoded !== null) { | ||
| $message .= sprintf(' for dimension space point "%s"', $dimensionSpacePointDecoded->hash); | ||
| } | ||
| $this->outputLine("<success>$message</success>"); | ||
| } | ||
|
|
||
| /** | ||
| * Lists all metadata properties for an asset | ||
| * | ||
| * @param string $assetId ID of the asset to unset the metadata property for | ||
| * @param string|null $assetSource optional asset source - default = "neos" | ||
| * @param string|null $dimensionSpacePoint optional dimension space point as JSON (e.g. `'{"language": "de"}') - default = the configured defaultDimensionSpacePoint | ||
| */ | ||
| public function listCommand(string $assetId, string|null $assetSource = null, string|null $dimensionSpacePoint = null): void | ||
| { | ||
| $dimensionSpacePointDecoded = $dimensionSpacePoint !== null ? self::parseDimensionSpacePoint($dimensionSpacePoint) : null; | ||
| $assetReference = MetaDataAssetReference::create($assetSource ?? 'neos', $assetId); | ||
| $metaDataPropertyValues = $this->metaDataManager->getMetaDataPropertyValues( | ||
| $assetReference, | ||
| $dimensionSpacePointDecoded, | ||
| ); | ||
| $message = sprintf('Metadata properties of asset "%s"', $assetId); | ||
| if ($dimensionSpacePointDecoded !== null) { | ||
| $message .= sprintf(' for dimension space point "%s"', $dimensionSpacePointDecoded->hash); | ||
| } | ||
| $message .= ':'; | ||
| $this->outputLine($message); | ||
| foreach ($metaDataPropertyValues as $propertyName => $propertyValue) { | ||
| $this->outputLine(' <b>%s:</b> %s', [$propertyName, $propertyValue ?? '-']); | ||
| } | ||
| } | ||
|
|
||
| private static function parseDimensionSpacePoint(string $dimensionSpacePoint): MetaDataDimensionSpacePoint | ||
| { | ||
| try { | ||
| return MetaDataDimensionSpacePoint::fromCoordinates(json_decode($dimensionSpacePoint, true, 512, JSON_THROW_ON_ERROR)); | ||
| } catch (JsonException $e) { | ||
| throw new InvalidArgumentException('Failed to parse dimension space point: ' . $e->getMessage(), 1776274597, $e); | ||
| } | ||
| } | ||
|
|
||
| } |
48 changes: 48 additions & 0 deletions
48
Classes/Command/AssetMetaDataMigrationCommandController.php
This file contains hidden or 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,48 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\MetaData\Command; | ||
|
|
||
| use Neos\Flow\Cli\CommandController; | ||
| use Neos\Media\Domain\Model\Asset; | ||
| use Neos\Media\Domain\Repository\AssetRepository; | ||
| use Neos\MetaData\Domain\Dto\MetaDataAssetReference; | ||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyName; | ||
| use Neos\MetaData\MetaDataManager; | ||
|
|
||
| final class AssetMetaDataMigrationCommandController extends CommandController | ||
| { | ||
| public function __construct( | ||
| private readonly MetaDataManager $metaDataManager, | ||
| private readonly AssetRepository $assetRepository, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| public function migrateExistingAssetPropertiesCommand(): void | ||
| { | ||
| foreach ($this->assetRepository->findAll() as $asset) { | ||
| /** @var Asset $asset */ | ||
| $title = $asset->getTitle(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the title being ignored here? |
||
| $caption = $asset->getCaption(); | ||
| $copyrightNotice = $asset->getCopyrightNotice(); | ||
| $metaDataAssetReference = MetaDataAssetReference::create($asset->assetSourceIdentifier, $asset->getIdentifier()); | ||
|
|
||
| if (!empty($caption)) { | ||
| $this->metaDataManager->setMetaDataPropertyValue( | ||
| $metaDataAssetReference, | ||
| MetaDataPropertyName::fromString('caption'), | ||
| $asset->getCaption(), | ||
| ); | ||
| } | ||
| if (!empty($copyrightNotice)) { | ||
| $this->metaDataManager->setMetaDataPropertyValue( | ||
| $metaDataAssetReference, | ||
| MetaDataPropertyName::fromString('copyright'), | ||
| $asset->getCopyrightNotice(), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,14 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\MetaData\Configuration; | ||
|
|
||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyDefinitions; | ||
|
|
||
| /** | ||
| * Provider for global property configuration (usually from settings (YAML)) | ||
| */ | ||
| interface MetaDataConfigurationProvider | ||
| { | ||
| public function getPropertyConfiguration(): MetaDataPropertyDefinitions; | ||
| } |
59 changes: 59 additions & 0 deletions
59
Classes/Configuration/MetaDataConfigurationProviderYamlAdapter.php
This file contains hidden or 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,59 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\MetaData\Configuration; | ||
|
|
||
| use Neos\Flow\I18n\Translator; | ||
| use Neos\MetaData\Domain\Dto\MetaDataEditorDefinition; | ||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyDefinition; | ||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyDefinitions; | ||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyName; | ||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyType; | ||
| use Neos\MetaData\Domain\Dto\MetaDataPropertyUiDefinition; | ||
|
|
||
| class MetaDataConfigurationProviderYamlAdapter implements MetaDataConfigurationProvider | ||
| { | ||
| public function __construct( | ||
| private readonly array $propertyConfiguration, | ||
| private readonly Translator $translator, | ||
| ) | ||
| { | ||
| } | ||
|
|
||
| public function getPropertyConfiguration(): MetaDataPropertyDefinitions | ||
| { | ||
| $propertyDefinitions = []; | ||
| foreach ($this->propertyConfiguration as $propertyName => $propertyDefinition) { | ||
| $propertyDefinitions[] = new MetaDataPropertyDefinition( | ||
| MetaDataPropertyName::fromString($propertyName), | ||
| match ($propertyDefinition['type'] ?? null) { | ||
| 'integer' => MetaDataPropertyType::integer, | ||
| 'boolean' => MetaDataPropertyType::boolean, | ||
| default => MetaDataPropertyType::string, | ||
| }, | ||
| $propertyDefinition['globalScope'] ?? false, | ||
| new MetaDataPropertyUiDefinition( | ||
| $this->translatePropertyName($propertyName, $propertyDefinition['ui']['label']), | ||
| MetaDataEditorDefinition::create( | ||
| editorType: $propertyDefinition['ui']['inspector']['editor'] ?? null, | ||
| options: $propertyDefinition['ui']['inspector']['editorOptions'] ?? [], | ||
| ) | ||
| ) | ||
| ); | ||
| } | ||
| return MetaDataPropertyDefinitions::create(...$propertyDefinitions); | ||
| } | ||
|
|
||
| // ----------------------- | ||
|
|
||
| private function translatePropertyName(string $propertyName, ?string $label): string | ||
| { | ||
| if ($label === 'i18n') { | ||
| $translationShortHandString = sprintf('properties.%s', $propertyName); | ||
| return $this->translator->translateById($translationShortHandString, [], null, null, 'Main', 'Neos.MetaData') ?? $propertyName; | ||
| } elseif ($label !== null) { | ||
| return $label; | ||
| } | ||
| return $propertyName; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
Classes/Configuration/MetaDataConfigurationProviderYamlAdapterFactory.php
This file contains hidden or 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,21 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\MetaData\Configuration; | ||
|
|
||
| use Neos\Flow\I18n\Translator; | ||
|
|
||
| class MetaDataConfigurationProviderYamlAdapterFactory | ||
| { | ||
| public function __construct( | ||
| private readonly array $propertyConfiguration, | ||
| private readonly Translator $translator, | ||
| ) | ||
| { | ||
| } | ||
|
|
||
| public function create(): MetaDataConfigurationProvider | ||
| { | ||
| return new MetaDataConfigurationProviderYamlAdapter($this->propertyConfiguration, $this->translator); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
Classes/DimensionSpacePointProvider/DimensionSpacePointProvider.php
This file contains hidden or 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,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\MetaData\DimensionSpacePointProvider; | ||
|
|
||
| use Neos\MetaData\Domain\Dto\MetaDataDimensionSpacePoint; | ||
| use Neos\MetaData\Domain\Dto\MetaDataDimensionSpacePoints; | ||
|
|
||
| /** | ||
| * Provider for global dimension configuration (usually from the Neos Content Repository) | ||
| */ | ||
| interface DimensionSpacePointProvider | ||
| { | ||
| public function getDimensionSpacePoints(): MetaDataDimensionSpacePoints; | ||
|
|
||
| public function getDefaultDimensionSpacePoint(): MetaDataDimensionSpacePoint; | ||
|
|
||
| public function getDimensionSpacePointChain(MetaDataDimensionSpacePoint $dimensionSpacePoint): MetaDataDimensionSpacePoints; | ||
|
|
||
| public function isDimensionSpacePointValid(MetaDataDimensionSpacePoint $dimensionSpacePoint): bool; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check what happens with assets from other asset sources