Skip to content

Commit

Permalink
IBX-8434: Added ProviderConfiguratorInterface to allow configuration …
Browse files Browse the repository at this point in the history
…post-processing
  • Loading branch information
Steveb-p committed Jul 3, 2024
1 parent b148e3d commit e8d52ae
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 131 deletions.
90 changes: 6 additions & 84 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,6 @@ parameters:
count: 1
path: src/lib/Configuration/Provider/CustomStyle.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\Provider\\\\CustomTag\\:\\:getConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/Provider/CustomTag.php

-
message: "#^Property Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\Provider\\\\CustomTag\\:\\:\\$customTagConfigurationMapper \\(Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\) does not accept Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTemplateConfigMapper\\.$#"
count: 1
path: src/lib/Configuration/Provider/CustomTag.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomStyle\\:\\:__construct\\(\\) has parameter \\$customStylesConfiguration with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -350,76 +340,6 @@ parameters:
count: 1
path: src/lib/Configuration/UI/Mapper/CustomStyle.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:__construct\\(\\) has parameter \\$customTagAttributeMappers with no value type specified in iterable type Traversable\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:__construct\\(\\) has parameter \\$customTagsConfiguration with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:mapConfig\\(\\) has parameter \\$enabledCustomTags with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:mapConfig\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:translateLabels\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:translateLabels\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Property Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:\\$customTagAttributeMappers \\(array\\<Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\\\AttributeMapper\\>\\) does not accept Traversable\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Property Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\:\\:\\$customTagsConfiguration type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\\\AttributeMapper\\:\\:mapConfig\\(\\) has parameter \\$customTagAttributeProperties with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag/AttributeMapper.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\\\AttributeMapper\\:\\:mapConfig\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag/AttributeMapper.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\\\ChoiceAttributeMapper\\:\\:mapConfig\\(\\) has parameter \\$customTagAttributeProperties with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag/ChoiceAttributeMapper.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\\\ChoiceAttributeMapper\\:\\:mapConfig\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag/ChoiceAttributeMapper.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\\\CommonAttributeMapper\\:\\:mapConfig\\(\\) has parameter \\$customTagAttributeProperties with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag/CommonAttributeMapper.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTag\\\\CommonAttributeMapper\\:\\:mapConfig\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Configuration/UI/Mapper/CustomTag/CommonAttributeMapper.php

-
message: "#^Method Ibexa\\\\FieldTypeRichText\\\\Configuration\\\\UI\\\\Mapper\\\\CustomTemplateConfigMapper\\:\\:mapConfig\\(\\) has parameter \\$enabledCustomTemplates with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1394,10 +1314,7 @@ parameters:
message: "#^Cannot access property \\$id on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php
-
message: "#^Cannot call method fetchOne\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php

-
message: "#^Cannot access property \\$value on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 1
Expand All @@ -1413,6 +1330,11 @@ parameters:
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php

-
message: "#^Cannot call method fetchOne\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\FieldTypeRichText\\\\Repository\\\\RichTextFieldTypeIntegrationTest\\:\\:__construct\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
24 changes: 24 additions & 0 deletions src/bundle/Resources/config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,42 @@ services:
arguments:
$customStyleConfigurationMapper: '@Ibexa\FieldTypeRichText\Configuration\UI\Mapper\CustomStyle'

ibexa.field_type_rich_text.configuration.provider.custom_style.configurable:
class: Ibexa\FieldTypeRichText\Configuration\Provider\ConfigurableProvider
decorates: Ibexa\FieldTypeRichText\Configuration\Provider\CustomStyle
arguments:
$configurators: !tagged_iterator ibexa.field_type.richtext.configuration.custom_style.configurator

Ibexa\FieldTypeRichText\Configuration\Provider\CustomTag:
arguments:
$customTagConfigurationMapper: '@Ibexa\FieldTypeRichText\Configuration\UI\Mapper\CustomTag'

ibexa.field_type_rich_text.configuration.provider.custom_tag.configurable:
class: Ibexa\FieldTypeRichText\Configuration\Provider\ConfigurableProvider
decorates: Ibexa\FieldTypeRichText\Configuration\Provider\CustomTag
arguments:
$configurators: !tagged_iterator ibexa.field_type.richtext.configuration.custom_tag.configurator

Ibexa\FieldTypeRichText\Configuration\Provider\AlloyEditor:
arguments:
$alloyEditorConfiguration: '%ibexa.field_type.richtext.alloy_editor%'

ibexa.field_type_rich_text.configuration.provider.alloy_editor.configurable:
class: Ibexa\FieldTypeRichText\Configuration\Provider\ConfigurableProvider
decorates: Ibexa\FieldTypeRichText\Configuration\Provider\AlloyEditor
arguments:
$configurators: !tagged_iterator ibexa.field_type.richtext.configuration.alloy_editor.configurator

Ibexa\FieldTypeRichText\Configuration\Provider\CKEditor:
arguments:
$customStylesConfiguration: '%ibexa.field_type.richtext.custom_styles%'

ibexa.field_type_rich_text.configuration.provider.ck_editor.configurable:
class: Ibexa\FieldTypeRichText\Configuration\Provider\ConfigurableProvider
decorates: Ibexa\FieldTypeRichText\Configuration\Provider\CKEditor
arguments:
$configurators: !tagged_iterator ibexa.field_type.richtext.configuration.ck_editor.configurator

Ibexa\FieldTypeRichText\Configuration\AggregateProvider:
arguments:
$providers: !tagged ibexa.field_type.richtext.configuration.provider
2 changes: 1 addition & 1 deletion src/bundle/Resources/config/ui/mappers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
$customTagsConfiguration: '%ibexa.field_type.richtext.custom_tags%'
$translatorBag: '@translator'
$translationDomain: '%ibexa.field_type.richtext.custom_tags.translation_domain%'
$customTagAttributeMappers: !tagged ibexa.field_type.richtext.configuration.custom_tag.mapper
$customTagAttributeMappers: !tagged_iterator ibexa.field_type.richtext.configuration.custom_tag.mapper

# RichText Custom Styles UI config mapper
Ibexa\FieldTypeRichText\Configuration\UI\Mapper\CustomStyle:
Expand Down
19 changes: 19 additions & 0 deletions src/contracts/Configuration/ProviderConfiguratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\FieldTypeRichText\Configuration;

interface ProviderConfiguratorInterface
{
/**
* @param array<string, mixed> $configuration
*
* @return array<string, mixed>
*/
public function getConfiguration(array $configuration): array;
}
48 changes: 48 additions & 0 deletions src/lib/Configuration/Provider/ConfigurableProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\FieldTypeRichText\Configuration\Provider;

use Ibexa\Contracts\FieldTypeRichText\Configuration\Provider;

final class ConfigurableProvider implements Provider
{
private Provider $inner;

/** @var iterable<\Ibexa\Contracts\FieldTypeRichText\Configuration\ProviderConfiguratorInterface> */
private iterable $configurators;

/**
* @param iterable<\Ibexa\Contracts\FieldTypeRichText\Configuration\ProviderConfiguratorInterface> $configurators
*/
public function __construct(
Provider $inner,
iterable $configurators
) {
$this->inner = $inner;
$this->configurators = $configurators;
}

public function getName(): string
{
return $this->inner->getName();
}

/**
* @return array<string, mixed>
*/
public function getConfiguration(): array
{
$configuration = $this->inner->getConfiguration();
foreach ($this->configurators as $configurator) {
$configuration = $configurator->getConfiguration($configuration);
}

return $configuration;
}
}
24 changes: 19 additions & 5 deletions src/lib/Configuration/Provider/CustomTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@
* Custom Tags configuration provider.
*
* @internal For internal use by RichText package
*
* @phpstan-type TConfigOutput array{
* label: string,
* description: string,
* isInline: bool,
* icon?: string,
* attributes?: array<string, TConfigAttributeOutput>
* }
* @phpstan-type TConfigAttributeOutput array{
* type: string,
* required: bool,
* defaultValue: mixed,
* label: string,
* choices?: array<string>,
* choicesLabel?: array<string, string>,
* }
*/
final class CustomTag implements Provider
{
/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
private $configResolver;
private ConfigResolverInterface $configResolver;

/** @var \Ibexa\FieldTypeRichText\Configuration\UI\Mapper\CustomTag */
private $customTagConfigurationMapper;
private CustomTemplateConfigMapper $customTagConfigurationMapper;

public function __construct(
ConfigResolverInterface $configResolver,
Expand All @@ -39,7 +53,7 @@ public function getName(): string
}

/**
* @return array RichText Custom Tags config
* @phpstan-return array<TConfigOutput> RichText Custom Tags config
*/
public function getConfiguration(): array
{
Expand Down
Loading

0 comments on commit e8d52ae

Please sign in to comment.