Skip to content

Commit

Permalink
EZP-28265: Expose ContentCreateView to allow setting different theme …
Browse files Browse the repository at this point in the history
…for content creation (ezsystems#173)
  • Loading branch information
webhdx authored and Łukasz Serwatka committed Nov 20, 2017
1 parent 360a00d commit e1da558
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bundle/Controller/ContentEditController.php
Expand Up @@ -15,6 +15,7 @@
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
use eZ\Publish\Core\Base\Exceptions\BadStateException;
use EzSystems\RepositoryForms\Content\View\ContentCreateDraftView;
use EzSystems\RepositoryForms\Content\View\ContentCreateView;
use EzSystems\RepositoryForms\Content\View\ContentEditView;
use EzSystems\RepositoryForms\Data\Content\CreateContentDraftData;
use EzSystems\RepositoryForms\Data\Mapper\ContentCreateMapper;
Expand Down Expand Up @@ -73,10 +74,15 @@ public function __construct(
* @param int $parentLocationId Location the content should be a child of
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \EzSystems\RepositoryForms\Content\View\ContentEditView|\Symfony\Component\HttpFoundation\Response
* @return \EzSystems\RepositoryForms\Content\View\ContentCreateView|\Symfony\Component\HttpFoundation\Response
*
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request)
{
$parentLocation = $this->locationService->loadLocation($parentLocationId);
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
$data = (new ContentCreateMapper())->mapToFormData($contentType, [
'mainLanguageCode' => $language,
Expand All @@ -95,9 +101,11 @@ public function createWithoutDraftAction($contentTypeIdentifier, $language, $par
}
}

return new ContentEditView(null, [
return new ContentCreateView(null, [
'form' => $form->createView(),
'languageCode' => $language,
'contentType' => $contentType,
'parentLocation' => $parentLocation,
]);
}

Expand Down
11 changes: 11 additions & 0 deletions bundle/DependencyInjection/Configuration/Parser/ContentEdit.php
Expand Up @@ -30,6 +30,9 @@ public function addSemanticConfig(NodeBuilder $nodeBuilder)
->scalarNode('edit')
->info('Template to use for content edit form rendering.')
->end()
->scalarNode('create')
->info('Template to use for content create form rendering.')
->end()
->scalarNode('create_draft')
->info('Template to use for content draft creation rendering.')
->end()
Expand All @@ -55,6 +58,14 @@ public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerIn
);
}

if (!empty($settings['templates']['create'])) {
$contextualizer->setContextualParameter(
'content_edit.templates.create',
$currentScope,
$settings['templates']['create']
);
}

if (!empty($settings['templates']['create_draft'])) {
$contextualizer->setContextualParameter(
'content_edit.templates.create_draft',
Expand Down
1 change: 1 addition & 0 deletions bundle/Resources/config/ezpublish_default_settings.yml
Expand Up @@ -3,6 +3,7 @@ parameters:
ezsettings.default.user_registration.templates.form: "EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig"
ezsettings.default.user_registration.templates.confirmation: "EzSystemsRepositoryFormsBundle:User:register_confirmation.html.twig"
ezsettings.default.content_edit.templates.edit: "EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig"
ezsettings.default.content_edit.templates.create: "EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig"
ezsettings.default.content_edit.templates.create_draft: "EzSystemsRepositoryFormsBundle:Content:content_create_draft.html.twig"
ezsettings.default.limitation_value_templates:
- { template: 'EzSystemsRepositoryFormsBundle::limitation_values.html.twig', priority: 0 }
1 change: 1 addition & 0 deletions bundle/Resources/config/services.yml
Expand Up @@ -265,6 +265,7 @@ services:
- [setViewTemplate, ['EzSystems\RepositoryForms\UserRegister\View\UserRegisterFormView', "$user_registration.templates.form$"]]
- [setViewTemplate, ['EzSystems\RepositoryForms\UserRegister\View\UserRegisterConfirmView', "$user_registration.templates.confirmation$"]]
- [setViewTemplate, ['EzSystems\RepositoryForms\Content\View\ContentEditView', "$content_edit.templates.edit$"]]
- [setViewTemplate, ['EzSystems\RepositoryForms\Content\View\ContentCreateView', "$content_edit.templates.create$"]]
- [setViewTemplate, ['EzSystems\RepositoryForms\Content\View\ContentCreateDraftView', "$content_edit.templates.create_draft$"]]
- [setPagelayout, ["$pagelayout$"]]

Expand Down
12 changes: 12 additions & 0 deletions lib/Content/View/ContentCreateView.php
@@ -0,0 +1,12 @@
<?php
/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Content\View;

use eZ\Publish\Core\MVC\Symfony\View\BaseView;

class ContentCreateView extends BaseView
{
}

0 comments on commit e1da558

Please sign in to comment.