-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-8784: Created RichText configuration REST endpoint
- Loading branch information
Showing
13 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,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()); | ||
} | ||
} |
This file contains 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
This file contains 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,9 @@ | ||
services: | ||
_defaults: | ||
autoconfigure: true | ||
autowire: true | ||
public: false | ||
|
||
Ibexa\Bundle\FieldTypeRichText\Controller\RichTextConfigController: | ||
tags: | ||
- controller.service_arguments |
This file contains 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
This file contains 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,6 @@ | ||
ibexa.rest.richtext_config: | ||
path: /richtext-config | ||
controller: 'Ibexa\Bundle\FieldTypeRichText\Controller\RichTextConfigController::loadConfigAction' | ||
methods: [GET] | ||
options: | ||
expose: true |
28 changes: 28 additions & 0 deletions
28
src/lib/REST/Output/ValueObjectVisitor/RichTextConfigVisitor.php
This file contains 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,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'); | ||
} | ||
} |
This file contains 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,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; | ||
} | ||
} |
This file contains 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,80 @@ | ||
<?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\Tests\Integration\FieldTypeRichText\REST; | ||
|
||
use Ibexa\Contracts\Test\Rest\WebTestCase; | ||
|
||
final class RichTextConfigTest extends WebTestCase | ||
{ | ||
/** | ||
* @dataProvider provideForTestConfig | ||
*/ | ||
public function testConfig( | ||
string $type, | ||
string $acceptHeader, | ||
string $snapshot | ||
): void { | ||
$this->client->request('GET', '/api/ibexa/v2/richtext-config', [], [], [ | ||
'HTTP_ACCEPT' => $acceptHeader, | ||
]); | ||
|
||
$this->assertResponseIsSuccessful(); | ||
$response = $this->client->getResponse(); | ||
$content = $response->getContent(); | ||
self::assertIsString($content); | ||
|
||
if ($type === 'xml') { | ||
self::assertSame('application/vnd.ibexa.api.RichTextConfig+xml', $response->headers->get('Content-Type')); | ||
self::assertResponseMatchesXmlSnapshot($content, $snapshot); | ||
} elseif ($type === 'json') { | ||
self::assertSame('application/vnd.ibexa.api.RichTextConfig+json', $response->headers->get('Content-Type')); | ||
self::assertResponseMatchesJsonSnapshot($content, $snapshot); | ||
} else { | ||
throw new \LogicException(sprintf( | ||
'Unknown type: "%s". Expected one of: "%s"', | ||
$type, | ||
implode('", "', ['json', 'xml']), | ||
)); | ||
} | ||
} | ||
|
||
/** | ||
* @return iterable<array{ | ||
* 'xml'|'json', | ||
* non-empty-string, | ||
* non-empty-string, | ||
* }> | ||
*/ | ||
public static function provideForTestConfig(): iterable | ||
{ | ||
yield 'application/vnd.ibexa.api.RichTextConfig+json' => [ | ||
'json', | ||
'application/vnd.ibexa.api.RichTextConfig+json', | ||
__DIR__ . '/_output/RichTextConfig.json', | ||
]; | ||
|
||
yield 'application/json' => [ | ||
'json', | ||
'application/json', | ||
__DIR__ . '/_output/RichTextConfig.json', | ||
]; | ||
|
||
yield 'application/vnd.ibexa.api.RichTextConfig+xml' => [ | ||
'xml', | ||
'application/vnd.ibexa.api.RichTextConfig+xml', | ||
__DIR__ . '/_output/RichTextConfig.xml', | ||
]; | ||
|
||
yield 'application/xml' => [ | ||
'xml', | ||
'application/xml', | ||
__DIR__ . '/_output/RichTextConfig.xml', | ||
]; | ||
} | ||
} |
This file contains 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 @@ | ||
{ | ||
"RichTextConfig": { | ||
"_media-type": "application\/vnd.ibexa.api.RichTextConfig+json", | ||
"customStyles": [], | ||
"customTags": [], | ||
"alloyEditor": { | ||
"extraPlugins": [], | ||
"toolbars": [], | ||
"classes": [], | ||
"attributes": [], | ||
"nativeAttributes": { | ||
"table": [ | ||
"border" | ||
] | ||
} | ||
}, | ||
"CKEditor": { | ||
"toolbar": [] | ||
} | ||
} | ||
} |
This file contains 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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<RichTextConfig media-type="application/vnd.ibexa.api.RichTextConfig+xml"> | ||
<customStyles/> | ||
<customTags/> | ||
<alloyEditor> | ||
<value key="extraPlugins"/> | ||
<value key="toolbars"/> | ||
<value key="classes"/> | ||
<value key="attributes"/> | ||
<value key="nativeAttributes"> | ||
<value key="table"> | ||
<value>border</value> | ||
</value> | ||
</value> | ||
</alloyEditor> | ||
<CKEditor> | ||
<value key="toolbar"/> | ||
</CKEditor> | ||
</RichTextConfig> |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
ibexa.user.default_profile_image.initials: | ||
path: /user/default_profile_image/initials.svg | ||
|
||
ibexa.fieldtype_richtext.rest: | ||
resource: '@IbexaFieldTypeRichTextBundle/Resources/config/routing_rest.yaml' | ||
prefix: '%ibexa.rest.path_prefix%' |