Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions Classes/Configuration/IconConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,11 @@ class IconConfiguration extends AbstractBaseConfiguration
public function getIcon(): Icon
{
if (!($this->icon instanceof Icon)) {
$identifier = '';
$source = '';

extract($this->configuration);

if (static::isCustomConfiguration($this->configuration)) {
if (static::isExistingIdentifier($identifier)) {
throw new InvalidConfigurationException(
'Invalid configuration of icon. Identifier ' . $identifier . ' exists already.'
);
}
} else {
if (static::isFileReference($source)) {
$identifier = IconRegistrationUtility::convertFilenameToIdentifier($source);
}
$identifier = $this?->configuration['identifier'] ?? '';
$source = $this?->configuration['source'] ?? '';

if (static::isFileReference($source)) {
$identifier = IconRegistrationUtility::convertFilenameToIdentifier($source);
}

if (empty(trim($identifier))) {
Expand All @@ -59,12 +49,20 @@ public function getIcon(): Icon

public static function validate(array $configuration): ValidationResult
{
$validationResult = new ValidationResult();
$validationResult = GeneralUtility::makeInstance(ValidationResult::class);

if (!(self::hasValidIdentifier($configuration) || self::hasValidSource($configuration))) {
$validationResult->addError('Either identifier or source has to be set.');
}

if (self::isCustomConfiguration($configuration) && self::isExistingIdentifier($configuration['identifier'])) {
$validationResult->addError('Identifier "' . $configuration['identifier'] . '" exists already. Either change the identifier or omit the "source" key to use the existing icon.');
}

if (self::hasValidIdentifier($configuration) && !self::isExistingIdentifier($configuration['identifier'])) {
$validationResult->addError('Identifier "' . $configuration['identifier'] . '" does not exist. Either change the identifier or use the "source" key to register a new icon with this identifier.');
}

return $validationResult;
}

Expand Down Expand Up @@ -109,7 +107,7 @@ public static function isExistingIdentifier(string $identifier): bool
*/
public static function hasValidIdentifier(array $configuration): bool
{
return array_key_exists('identifier', $configuration);
return array_key_exists('identifier', $configuration) && empty($configuration['identifier']) === false;
}

/**
Expand All @@ -120,6 +118,6 @@ public static function hasValidIdentifier(array $configuration): bool
*/
public static function hasValidSource(array $configuration): bool
{
return array_key_exists('source', $configuration);
return array_key_exists('source', $configuration) && empty($configuration['source']) === false;
}
}