Skip to content

Commit cb2c006

Browse files
committed
Added EmbeddedItemEditFormExtension
1 parent 90212cb commit cb2c006

File tree

7 files changed

+205
-0
lines changed

7 files changed

+205
-0
lines changed

src/bundle/Resources/config/services/components.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ services:
3939
public: false
4040

4141
Ibexa\Contracts\AdminUi\Component\Renderer\RendererInterface: '@Ibexa\AdminUi\Component\Renderer\DefaultRenderer'
42+
43+
ibexa.adminui.layout.content.after:
44+
parent: Ibexa\AdminUi\Component\TwigComponent
45+
arguments:
46+
$template: '@@ibexadesign/ui/layout_content_after.html.twig'
47+
tags:
48+
- { name: ibexa.admin_ui.component, group: 'layout-content-after' }

src/bundle/Resources/config/services/ui_config/common.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ services:
9696

9797
Ibexa\Bundle\AdminUi\Templating\Twig\ContentTypeIconExtension: ~
9898

99+
Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension: ~
100+
99101
Ibexa\AdminUi\UI\Config\Provider\UserContentTypes:
100102
tags:
101103
- { name: ibexa.admin_ui.config.provider, key: 'userContentTypes' }

src/bundle/Resources/views/themes/admin/ui/layout.html.twig

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@
221221
{% endblock %}
222222
{% endif %}
223223

224+
{{ ibexa_render_component_group('layout-content-after') }}
225+
224226
{{ encore_entry_script_tags('ibexa-admin-ui-layout-js', null, 'ibexa') }}
225227
{{ encore_entry_script_tags('ibexa-admin-ui-udw-tabs-js', null, 'ibexa') }}
226228
{{ encore_entry_script_tags('ibexa-admin-ui-udw-extras-js', null, 'ibexa') }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="ibexa-embedded-item-edit-container">
2+
{% set form = ibexa_render_embedded_item_edit_form() %}
3+
4+
{{ form_start(form) }}
5+
{{ form_widget(form.content_info, { 'attr': {
6+
'hidden': 'hidden',
7+
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--content-info'
8+
} }) }}
9+
{{ form_widget(form.version_info, { 'attr': {
10+
'hidden': 'hidden',
11+
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--version-info'
12+
} }) }}
13+
{{ form_widget(form.language, { 'attr': {
14+
'hidden': 'hidden',
15+
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--language'
16+
} }) }}
17+
{{ form_widget(form.location, { 'attr': {
18+
'hidden': 'hidden',
19+
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--location'
20+
} }) }}
21+
{{ form_end(form) }}
22+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Bundle\AdminUi\Templating\Twig;
10+
11+
use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData;
12+
use Ibexa\AdminUi\Form\Factory\FormFactory;
13+
use Symfony\Component\Form\FormView;
14+
use Symfony\Component\Routing\RouterInterface;
15+
use Twig\Extension\AbstractExtension;
16+
use Twig\TwigFunction;
17+
18+
final class EmbeddedItemEditFormExtension extends AbstractExtension
19+
{
20+
private FormFactory $formFactory;
21+
22+
private RouterInterface $router;
23+
24+
public function __construct(
25+
FormFactory $formFactory,
26+
RouterInterface $router
27+
) {
28+
$this->formFactory = $formFactory;
29+
$this->router = $router;
30+
}
31+
32+
public function getFunctions(): array
33+
{
34+
return [
35+
new TwigFunction(
36+
'ibexa_render_embedded_item_edit_form',
37+
[$this, 'renderEmbeddedItemEditForm']
38+
),
39+
];
40+
}
41+
42+
public function renderEmbeddedItemEditForm(): FormView
43+
{
44+
return $this->formFactory->contentEdit(
45+
new ContentEditData(),
46+
'embedded_item_edit',
47+
[
48+
'action' => $this->router->generate('ibexa.content.edit'),
49+
'attr' => [
50+
'class' => 'ibexa-embedded-item-edit',
51+
],
52+
]
53+
)->createView();
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Bundle\AdminUi\Templating\Twig;
10+
11+
use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData;
12+
use Ibexa\AdminUi\Form\Factory\FormFactory;
13+
use Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension;
14+
use Symfony\Component\Form\FormInterface;
15+
use Symfony\Component\Form\FormView;
16+
use Symfony\Component\Routing\RouterInterface;
17+
use Twig\Test\IntegrationTestCase;
18+
19+
/**
20+
* @covers \Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension
21+
*/
22+
final class EmbeddedItemEditFormExtensionTest extends IntegrationTestCase
23+
{
24+
private const FORM_ACTION = '/admin/content/edit';
25+
26+
protected function getExtensions(): array
27+
{
28+
return [
29+
new EmbeddedItemEditFormExtension(
30+
$this->createFormFactory(),
31+
$this->createRouter()
32+
),
33+
];
34+
}
35+
36+
/**
37+
* @dataProvider getLegacyTests
38+
* @group legacy
39+
*
40+
* @param string $file
41+
* @param string $message
42+
* @param string $condition
43+
* @param array<string> $templates
44+
* @param string $exception
45+
* @param array<mixed> $outputs
46+
* @param string $deprecation
47+
*/
48+
public function testLegacyIntegration(
49+
$file,
50+
$message,
51+
$condition,
52+
$templates,
53+
$exception,
54+
$outputs,
55+
$deprecation = ''
56+
): void {
57+
// disable Twig legacy integration test to avoid producing risky warning
58+
self::markTestSkipped('This package does not contain Twig legacy integration test cases');
59+
}
60+
61+
protected function getFixturesDir(): string
62+
{
63+
return __DIR__ . '/_fixtures/render_embedded_item_edit_form/';
64+
}
65+
66+
private function createEditForm(): FormInterface
67+
{
68+
$editForm = $this->createMock(FormInterface::class);
69+
$editForm
70+
->method('createView')
71+
->willReturn(
72+
$this->createMock(FormView::class)
73+
);
74+
75+
return $editForm;
76+
}
77+
78+
private function createFormFactory(): FormFactory
79+
{
80+
$formFactory = $this->createMock(FormFactory::class);
81+
$formFactory
82+
->method('contentEdit')
83+
->with(
84+
new ContentEditData(),
85+
'embedded_item_edit',
86+
[
87+
'action' => self::FORM_ACTION,
88+
'attr' => [
89+
'class' => 'ibexa-embedded-item-edit',
90+
],
91+
]
92+
)
93+
->willReturn($this->createEditForm());
94+
95+
return $formFactory;
96+
}
97+
98+
private function createRouter(): RouterInterface
99+
{
100+
$router = $this->createMock(RouterInterface::class);
101+
$router
102+
->method('generate')
103+
->with('ibexa.content.edit')
104+
->willReturn(self::FORM_ACTION);
105+
106+
return $router;
107+
}
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
"ibexa_render_embedded_item_edit_form" function
3+
--TEMPLATE--
4+
{% set form = ibexa_render_embedded_item_edit_form() %}
5+
{% if form is defined %} YES {% else %} NO {% endif %}
6+
--DATA--
7+
return [];
8+
--EXPECT--
9+
YES

0 commit comments

Comments
 (0)