Skip to content

Commit

Permalink
Added EmbeddedItemEditFormExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Sep 5, 2023
1 parent f23997b commit 22eb3dd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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
52 changes: 52 additions & 0 deletions src/bundle/Templating/Twig/EmbeddedItemEditFormExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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'),
]
)->createView();
}
}

0 comments on commit 22eb3dd

Please sign in to comment.