Skip to content
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

IBX-8150: Added option to enable attributes types #167

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
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
53 changes: 50 additions & 3 deletions src/bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use Ibexa\Bundle\Core\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

class Configuration extends SiteAccessConfiguration
{
Expand All @@ -28,17 +30,63 @@ public function getConfigTreeBuilder()
$rootNode = $treeBuilder->getRootNode();

$sections = $rootNode->children();
$this
->addEnabledAttributeTypesSection($sections);
$this
->addCustomTagsSection($sections);
$this
->addCustomStylesSection($sections);
$this
->addAlloyEditorSection($sections)
->addAlloyEditorSection($sections);

$this
->validateAttributeTypes($rootNode)
->end();

return $treeBuilder;
}

private function addEnabledAttributeTypesSection(NodeBuilder $richTextNode): NodeBuilder
{
return $richTextNode
->arrayNode('enabled_attribute_types')
->defaultValue(self::CUSTOM_TAG_ATTRIBUTE_TYPES)
->scalarPrototype()
->end()
->end()
;
}

private function validateAttributeTypes(NodeDefinition $rootNode): NodeDefinition
{
return $rootNode
->validate()
->ifTrue(static function (array $v): bool {
if (!isset($v['enabled_attribute_types']) || !isset($v['custom_tags'])) {
return false;
}
$enabledTypes = $v['enabled_attribute_types'];
foreach ($v['custom_tags'] as $tagIdentifier => $tag) {
foreach ($tag['attributes'] as $attribute) {
if (!in_array($attribute['type'], $enabledTypes, true)) {
throw new InvalidConfigurationException(
sprintf(
'The value "%s" is not allowed for path "ibexa_fieldtype_richtext.custom_tags.%s.attributes.campaign.type". Allowed values: %s',
$attribute['type'],
$tagIdentifier,
implode(', ', array_map(static fn ($type): string => "\"$type\"", $enabledTypes))
)
);
}
}
}

return false;
})
->then(static fn (array $v): array => $v)
->end();
}

/**
* Define RichText Custom Tags Semantic Configuration.
*
Expand Down Expand Up @@ -102,9 +150,8 @@ static function ($v) {
->thenInvalid('List of choices is supported by choices type only.')
->end()
->children()
->enumNode('type')
->scalarNode('type')
->isRequired()
->values(static::CUSTOM_TAG_ATTRIBUTE_TYPES)
->end()
->booleanNode('required')
->defaultFalse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function providerForTestProcessingConfiguration(): array
[
'custom_tags' => [],
'custom_styles' => [],
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
],
],
'Alloy editor configs from multiple sources' => [
Expand Down Expand Up @@ -111,6 +112,7 @@ public function providerForTestProcessingConfiguration(): array
],
'custom_tags' => [],
'custom_styles' => [],
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ custom_tags:
default_value: 360
is_inline: false
custom_styles: []
enabled_attribute_types:
- 'number'
- 'string'
- 'boolean'
- 'choice'
- 'link'
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ custom_tags:
default_value: 'abc'
is_inline: false
custom_styles: []
enabled_attribute_types:
- 'number'
- 'string'
- 'boolean'
- 'choice'
- 'link'
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ custom_tags:
default_value: ~
is_inline: false
custom_styles: []
enabled_attribute_types:
- 'number'
- 'string'
- 'boolean'
- 'choice'
- 'link'
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ custom_tags:
choices: ['choice-1', 'choice-2']
is_inline: false
custom_styles: []
enabled_attribute_types:
- 'number'
- 'string'
- 'boolean'
- 'choice'
- 'link'
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ custom_tags:
default_value: ~
is_inline: false
custom_styles: []
enabled_attribute_types:
- 'number'
- 'string'
- 'boolean'
- 'choice'
- 'link'
Loading