-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
205 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
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
22 changes: 22 additions & 0 deletions
22
src/bundle/Resources/views/themes/admin/ui/layout_content_after.html.twig
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,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
55
src/bundle/Templating/Twig/EmbeddedItemEditFormExtension.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,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
108
tests/bundle/Templating/Twig/EmbeddedItemEditFormExtensionTest.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,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; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...g/Twig/_fixtures/render_embedded_item_edit_form/ibexa_render_embedded_item_edit_form.test
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 @@ | ||
--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 |