Skip to content

Commit

Permalink
Added EmbeddedItemEditFormExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Sep 18, 2023
1 parent f23997b commit 3dd7c95
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/services/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ services:
public: false

Ibexa\Contracts\AdminUi\Component\Renderer\RendererInterface: '@Ibexa\AdminUi\Component\Renderer\DefaultRenderer'

ibexa.adminui.layout.content.after:
parent: Ibexa\AdminUi\Component\TwigComponent
arguments:
$template: '@@ibexadesign/ui/layout_content_after.html.twig'
tags:
- { name: ibexa.admin_ui.component, group: 'layout-content-after' }
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services/ui_config/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ services:

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

Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension: ~

Ibexa\AdminUi\UI\Config\Provider\UserContentTypes:
tags:
- { name: ibexa.admin_ui.config.provider, key: 'userContentTypes' }
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Resources/views/themes/admin/ui/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@
{% endblock %}
{% endif %}

{{ ibexa_render_component_group('layout-content-after') }}

{{ encore_entry_script_tags('ibexa-admin-ui-layout-js', null, 'ibexa') }}
{{ encore_entry_script_tags('ibexa-admin-ui-udw-tabs-js', null, 'ibexa') }}
{{ encore_entry_script_tags('ibexa-admin-ui-udw-extras-js', null, 'ibexa') }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="ibexa-embedded-item-edit-container">
{% set form = ibexa_render_embedded_item_edit_form() %}

{{ form_start(form) }}
{{ form_widget(form.content_info, { 'attr': {
'hidden': 'hidden',
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--content-info'
} }) }}
{{ form_widget(form.version_info, { 'attr': {
'hidden': 'hidden',
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--version-info'
} }) }}
{{ form_widget(form.language, { 'attr': {
'hidden': 'hidden',
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--language'
} }) }}
{{ form_widget(form.location, { 'attr': {
'hidden': 'hidden',
'class': 'ibexa-embedded-item-edit__form-field ibexa-embedded-item-edit__form-field--location'
} }) }}
{{ form_end(form) }}
</div>
55 changes: 55 additions & 0 deletions src/bundle/Templating/Twig/EmbeddedItemEditFormExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\AdminUi\Templating\Twig;

use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData;
use Ibexa\AdminUi\Form\Factory\FormFactory;
use Symfony\Component\Form\FormView;
use Symfony\Component\Routing\RouterInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class EmbeddedItemEditFormExtension extends AbstractExtension
{
private FormFactory $formFactory;

private RouterInterface $router;

public function __construct(
FormFactory $formFactory,
RouterInterface $router
) {
$this->formFactory = $formFactory;
$this->router = $router;
}

public function getFunctions(): array
{
return [
new TwigFunction(
'ibexa_render_embedded_item_edit_form',
[$this, 'renderEmbeddedItemEditForm']
),
];
}

public function renderEmbeddedItemEditForm(): FormView
{
return $this->formFactory->contentEdit(
new ContentEditData(),
'embedded_item_edit',
[
'action' => $this->router->generate('ibexa.content.edit'),
'attr' => [
'class' => 'ibexa-embedded-item-edit',
],
]
)->createView();
}
}
108 changes: 108 additions & 0 deletions tests/bundle/Templating/Twig/EmbeddedItemEditFormExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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\Bundle\AdminUi\Templating\Twig;

use Ibexa\AdminUi\Form\Data\Content\Draft\ContentEditData;
use Ibexa\AdminUi\Form\Factory\FormFactory;
use Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Routing\RouterInterface;
use Twig\Test\IntegrationTestCase;

/**
* @covers \Ibexa\Bundle\AdminUi\Templating\Twig\EmbeddedItemEditFormExtension
*/
final class EmbeddedItemEditFormExtensionTest extends IntegrationTestCase
{
private const FORM_ACTION = '/admin/content/edit';

protected function getExtensions(): array
{
return [
new EmbeddedItemEditFormExtension(
$this->createFormFactory(),
$this->createRouter()
),
];
}

/**
* @dataProvider getLegacyTests
* @group legacy
*
* @param string $file
* @param string $message
* @param string $condition
* @param array<string> $templates
* @param string $exception
* @param array<mixed> $outputs
* @param string $deprecation
*/
public function testLegacyIntegration(
$file,
$message,
$condition,
$templates,
$exception,
$outputs,
$deprecation = ''
): void {
// disable Twig legacy integration test to avoid producing risky warning
self::markTestSkipped('This package does not contain Twig legacy integration test cases');
}

protected function getFixturesDir(): string
{
return __DIR__ . '/_fixtures/render_embedded_item_edit_form/';
}

private function createEditForm(): FormInterface
{
$editForm = $this->createMock(FormInterface::class);
$editForm
->method('createView')
->willReturn(
$this->createMock(FormView::class)
);

return $editForm;
}

private function createFormFactory(): FormFactory
{
$formFactory = $this->createMock(FormFactory::class);
$formFactory
->method('contentEdit')
->with(
new ContentEditData(),
'embedded_item_edit',
[
'action' => self::FORM_ACTION,
'attr' => [
'class' => 'ibexa-embedded-item-edit',
],
]
)
->willReturn($this->createEditForm());

return $formFactory;
}

private function createRouter(): RouterInterface
{
$router = $this->createMock(RouterInterface::class);
$router
->method('generate')
->with('ibexa.content.edit')
->willReturn(self::FORM_ACTION);

return $router;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
"ibexa_render_embedded_item_edit_form" function
--TEMPLATE--
{% set form = ibexa_render_embedded_item_edit_form() %}
{% if form is defined %} YES {% else %} NO {% endif %}
--DATA--
return [];
--EXPECT--
YES

0 comments on commit 3dd7c95

Please sign in to comment.