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-8784: Created RichText configuration REST endpoint #181

Open
wants to merge 3 commits into
base: 4.6
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"ibexa/search": "~4.6.x-dev",
"ibexa/solr": "~4.6.x-dev",
"ibexa/test-core": "~4.6.x-dev",
"ibexa/test-rest": "~4.6.x-dev",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-symfony": "^1.2",
"phpstan/phpstan-phpunit": "^1.3",
Expand Down
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ parameters:
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:load\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:load\\(\\) has parameter \\$configs with no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:prepend\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -150,11 +140,6 @@ parameters:
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Parameter \\#1 \\$configuration of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\Extension\\:\\:processConfiguration\\(\\) expects Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface, Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface\\|null given\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Parameter \\#1 \\$filename of static method Symfony\\\\Component\\\\Yaml\\\\Yaml\\:\\:parseFile\\(\\) expects string, string\\|false given\\.$#"
count: 2
Expand Down
28 changes: 28 additions & 0 deletions src/bundle/Controller/RichTextConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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\Bundle\FieldTypeRichText\Controller;

use Ibexa\Contracts\FieldTypeRichText\Configuration\ProviderService;
use Ibexa\FieldTypeRichText\REST\Value\RichTextConfig;
use Ibexa\Rest\Server\Controller;

final class RichTextConfigController extends Controller
{
private ProviderService $providerService;

public function __construct(ProviderService $providerService)
{
$this->providerService = $providerService;
}

public function loadConfigAction(): RichTextConfig
{
return new RichTextConfig($this->providerService->getConfiguration());
}
}
21 changes: 15 additions & 6 deletions src/bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,27 @@ class Configuration extends SiteAccessConfiguration
{
public const CUSTOM_TAG_ATTRIBUTE_TYPES = ['number', 'string', 'boolean', 'choice', 'link'];

/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(IbexaFieldTypeRichTextExtension::EXTENSION_NAME);

$rootNode = $treeBuilder->getRootNode();

$sections = $rootNode->children();

$rootNode
->children()
->booleanNode('expose_config_as_global')
->defaultTrue()
->setDeprecated(
'ibexa/fieldtype-richtext',
'4.6',
'expose_config_as_global configuration is deprecated and will be removed in 5.0. '
. 'Acquire RichText configuration via REST API instead.'
)
->end()
->end();

$this
->addEnabledAttributeTypesSection($sections);
$this
Expand Down
23 changes: 11 additions & 12 deletions src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
use Symfony\Component\Yaml\Yaml;

/**
* Ibexa RichText Field Type Bundle extension.
*/
class IbexaFieldTypeRichTextExtension extends Extension implements PrependExtensionInterface
class IbexaFieldTypeRichTextExtension extends ConfigurableExtension implements PrependExtensionInterface
{
public const EXTENSION_NAME = 'ibexa_fieldtype_richtext';

Expand All @@ -45,15 +45,15 @@ public function getAlias()
}

/**
* Load Ibexa RichText Field Type Bundle configuration.
*
* @param array $configs
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*
* @throws \Exception
* @param array<string, mixed> $mergedConfig
*/
public function load(array $configs, ContainerBuilder $container)
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void
{
$container->setParameter(
'ibexa.field_type.richtext.expose_config_as_global',
$mergedConfig['expose_config_as_global'],
);

$settingsLoader = new Loader\YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config/settings')
Expand Down Expand Up @@ -82,10 +82,9 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('configuration.yaml');
$loader->load('api.yaml');
$loader->load('command.yaml');
$loader->load('controller.yaml');

$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$this->registerRichTextConfiguration($config, $container);
$this->registerRichTextConfiguration($mergedConfig, $container);

(new IbexaEncoreConfigurationDumper($container))->dumpCustomConfiguration(
self::WEBPACK_CONFIG_NAMES
Expand Down
9 changes: 9 additions & 0 deletions src/bundle/Resources/config/controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
_defaults:
autoconfigure: true
autowire: true
public: false

Ibexa\Bundle\FieldTypeRichText\Controller\RichTextConfigController:
tags:
- controller.service_arguments
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ services:
- '@Ibexa\FieldTypeRichText\RichText\Converter\Html5Edit'
tags:
- { name: ibexa.rest.field_type.processor, alias: ezrichtext }

Ibexa\FieldTypeRichText\REST\Output\ValueObjectVisitor\RichTextConfigVisitor:
parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor
tags:
- { name: ibexa.rest.output.value_object.visitor, type: Ibexa\FieldTypeRichText\REST\Value\RichTextConfig }
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/routing_rest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ibexa.rest.richtext_config:
path: /richtext-config
controller: 'Ibexa\Bundle\FieldTypeRichText\Controller\RichTextConfigController::loadConfigAction'
methods: [GET]
options:
expose: true
4 changes: 3 additions & 1 deletion src/bundle/Resources/config/templating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ services:

Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\YoutubeIdExtractorExtension: ~

Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\RichTextConfigurationExtension: ~
Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\RichTextConfigurationExtension:
arguments:
$exposeGlobals: '%ibexa.field_type.richtext.expose_config_as_global%'
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@ final class RichTextConfigurationExtension extends AbstractExtension implements
/** @var \Ibexa\Contracts\FieldTypeRichText\Configuration\ProviderService */
private $configurationProvider;

public function __construct(ProviderService $configurationProvider)
private bool $exposeGlobals;

public function __construct(ProviderService $configurationProvider, bool $exposeGlobals = false)
{
$this->configurationProvider = $configurationProvider;
$this->exposeGlobals = $exposeGlobals;
}

public function getGlobals(): array
{
if (!$this->exposeGlobals) {
return [];
}

trigger_deprecation(
'ibexa/fieldtype-richtext',
'4.6',
'Richtext configuration as global Twig variable is deprecated and will be removed in 5.0. '
. 'Set bundle\'s configuration "ibexa_fieldtype_richtext.expose_config_as_global to false '
. 'and acquire RichText configuration via REST API instead.',
);

$config = $this->configurationProvider->getConfiguration();

return [
Expand Down
28 changes: 28 additions & 0 deletions src/lib/REST/Output/ValueObjectVisitor/RichTextConfigVisitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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\REST\Output\ValueObjectVisitor;

use Ibexa\Contracts\Rest\Output\Generator;
use Ibexa\Contracts\Rest\Output\ValueObjectVisitor;
use Ibexa\Contracts\Rest\Output\Visitor;

final class RichTextConfigVisitor extends ValueObjectVisitor
{
public function visit(Visitor $visitor, Generator $generator, $data): void
{
$generator->startObjectElement('RichTextConfig');
$visitor->setHeader('Content-Type', $generator->getMediaType('RichTextConfig'));

foreach ($data->getConfig() as $namespace => $config) {
$generator->generateFieldTypeHash($namespace, $config);
}

$generator->endObjectElement('RichTextConfig');
}
}
33 changes: 33 additions & 0 deletions src/lib/REST/Value/RichTextConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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\REST\Value;

use Ibexa\Rest\Value;

final class RichTextConfig extends Value
{
/** @var array<string, mixed> */
private array $config;

/**
* @param array<string, mixed> $config
*/
public function __construct(array $config)
{
$this->config = $config;
}

/**
* @return array<string, mixed>
*/
public function getConfig(): array
{
return $this->config;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function providerForTestProcessingConfiguration(): array
'custom_tags' => [],
'custom_styles' => [],
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
'expose_config_as_global' => true,
],
],
'Alloy editor configs from multiple sources' => [
Expand Down Expand Up @@ -113,6 +114,7 @@ public function providerForTestProcessingConfiguration(): array
'custom_tags' => [],
'custom_styles' => [],
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
'expose_config_as_global' => true,
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: true
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: true
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: true
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: true
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: true
Loading
Loading