Skip to content

Commit

Permalink
IBX-1260: As a Developer, I want to extend Content Type Create/Update…
Browse files Browse the repository at this point in the history
… views
  • Loading branch information
adamwojs committed Oct 14, 2021
1 parent b3368e2 commit cffe8bd
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/bundle/Controller/ContentTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
use EzSystems\EzPlatformAdminUi\Tab\ContentType\TranslationsTab;
use EzSystems\EzPlatformContentForms\Form\ActionDispatcher\ActionDispatcherInterface;
use Ibexa\AdminUi\UI\Module\FieldTypeToolbar\FieldTypeToolbarFactory;
use Ibexa\AdminUi\View\ContentTypeCreateView;
use Ibexa\AdminUi\View\ContentTypeEditView;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\Form\FormInterface;
Expand Down Expand Up @@ -170,13 +172,13 @@ public function listAction(ContentTypeGroup $group, string $routeName, int $page
/**
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $group
*
* @return \Symfony\Component\HttpFoundation\Response
* @return \Symfony\Component\HttpFoundation\Response|\Ibexa\AdminUi\View\ContentTypeCreateView
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException
*/
public function addAction(ContentTypeGroup $group): Response
public function addAction(ContentTypeGroup $group)
{
$this->denyAccessUnlessGranted(new Attribute('class', 'create'));
$languages = $this->configResolver->getParameter('languages');
Expand All @@ -203,12 +205,15 @@ public function addAction(ContentTypeGroup $group): Response
$language = $this->languageService->loadLanguage($mainLanguageCode);
$form = $this->createUpdateForm($group, $contentTypeDraft, $language);

return $this->render('@ezdesign/content_type/create.html.twig', [
'content_type_group' => $group,
'content_type' => $contentTypeDraft,
'form' => $form->createView(),
$view = new ContentTypeCreateView('@ezdesign/content_type/create.html.twig');
$view->setContentTypeGroup($group);
$view->setContentTypeDraft($contentTypeDraft);
$view->setForm($form);
$view->setParameters([
'field_type_toolbar' => $this->fieldTypeToolbarFactory->create(),
]);

return $view;
}

/**
Expand Down Expand Up @@ -460,7 +465,7 @@ public function copyAction(Request $request, ContentTypeGroup $group, ContentTyp
* @param \eZ\Publish\API\Repository\Values\Content\Language|null $language
* @param \eZ\Publish\API\Repository\Values\Content\Language|null $baseLanguage
*
* @return \Symfony\Component\HttpFoundation\Response
* @return \Symfony\Component\HttpFoundation\Response|\Ibexa\AdminUi\View\ContentTypeEditView
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
Expand All @@ -470,7 +475,7 @@ public function updateAction(
ContentTypeDraft $contentTypeDraft,
Language $language = null,
Language $baseLanguage = null
): Response {
) {
if (!$language) {
$language = $this->getDefaultLanguage($contentTypeDraft);
}
Expand Down Expand Up @@ -525,13 +530,16 @@ public function updateAction(
}
}

return $this->render('@ezdesign/content_type/edit.html.twig', [
'content_type_group' => $group,
'content_type' => $contentTypeDraft,
'form' => $form->createView(),
'language_code' => $baseLanguage ? $baseLanguage->languageCode : $language->languageCode,
$view = new ContentTypeEditView('@ezdesign/content_type/edit.html.twig');
$view->setContentTypeGroup($group);
$view->setContentTypeDraft($contentTypeDraft);
$view->setForm($form);
$view->setLanguage($baseLanguage ?? $language);
$view->addParameters([
'field_type_toolbar' => $this->fieldTypeToolbarFactory->create(),
]);

return $view;
}

public function addFieldDefinitionFormAction(
Expand Down
68 changes: 68 additions & 0 deletions src/lib/View/ContentTypeCreateView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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\AdminUi\View;

use eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft;
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup;
use eZ\Publish\Core\MVC\Symfony\View\BaseView;
use Symfony\Component\Form\FormInterface;

final class ContentTypeCreateView extends BaseView
{
/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup */
private $contentTypeGroup;

/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft */
private $contentTypeDraft;

/** @var \Symfony\Component\Form\FormInterface */
private $form;

public function getContentTypeGroup(): ContentTypeGroup
{
return $this->contentTypeGroup;
}

public function setContentTypeGroup(ContentTypeGroup $contentTypeGroup): void
{
$this->contentTypeGroup = $contentTypeGroup;
}

public function getContentTypeDraft(): ContentTypeDraft
{
return $this->contentTypeDraft;
}

public function setContentTypeDraft(ContentTypeDraft $contentTypeDraft): void
{
$this->contentTypeDraft = $contentTypeDraft;
}

public function getForm(): FormInterface
{
return $this->form;
}

public function setForm(FormInterface $form): void
{
$this->form = $form;
}

/**
* @return array<string,mixed>
*/
protected function getInternalParameters(): array
{
return [
'content_type_group' => $this->contentTypeGroup,
'content_type' => $this->contentTypeDraft,
'form' => $this->form ? $this->form->createView() : null,
];
}
}
83 changes: 83 additions & 0 deletions src/lib/View/ContentTypeEditView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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\AdminUi\View;

use eZ\Publish\API\Repository\Values\Content\Language;
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft;
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup;
use eZ\Publish\Core\MVC\Symfony\View\BaseView;
use Symfony\Component\Form\FormInterface;

final class ContentTypeEditView extends BaseView
{
/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup */
private $contentTypeGroup;

/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft */
private $contentTypeDraft;

/** @var \eZ\Publish\API\Repository\Values\Content\Language */
private $language;

/** @var \Symfony\Component\Form\FormInterface */
private $form;

public function getContentTypeGroup(): ContentTypeGroup
{
return $this->contentTypeGroup;
}

public function setContentTypeGroup(ContentTypeGroup $contentTypeGroup): void
{
$this->contentTypeGroup = $contentTypeGroup;
}

public function getContentTypeDraft(): ContentTypeDraft
{
return $this->contentTypeDraft;
}

public function setContentTypeDraft(ContentTypeDraft $contentTypeDraft): void
{
$this->contentTypeDraft = $contentTypeDraft;
}

public function getLanguage(): ?Language
{
return $this->language;
}

public function setLanguage(?Language $language): void
{
$this->language = $language;
}

public function getForm(): FormInterface
{
return $this->form;
}

public function setForm(FormInterface $form): void
{
$this->form = $form;
}

/**
* @return array<string,mixed>
*/
protected function getInternalParameters(): array
{
return [
'content_type_group' => $this->contentTypeGroup,
'content_type' => $this->contentTypeDraft,
'form' => $this->form ? $this->form->createView() : null,
'language_code' => $this->language->languageCode,
];
}
}

0 comments on commit cffe8bd

Please sign in to comment.