Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Provide an extensible way to change content edit/draft create views
  • Loading branch information
Maciej Kobus authored and webhdx committed Sep 22, 2017
1 parent 48c1ff4 commit e394a02
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 24 deletions.
23 changes: 12 additions & 11 deletions bundle/Controller/ContentEditController.php
Expand Up @@ -14,6 +14,8 @@
use eZ\Publish\API\Repository\LocationService;
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\ContentEditView;
use EzSystems\RepositoryForms\Data\Content\CreateContentDraftData;
use EzSystems\RepositoryForms\Data\Mapper\ContentCreateMapper;
use EzSystems\RepositoryForms\Data\Mapper\ContentUpdateMapper;
Expand Down Expand Up @@ -46,6 +48,8 @@ class ContentEditController extends Controller

/**
* @var string
*
* @deprecated Deprecated since 1.10 and will be removed in 2.0. See setPagelayout().
*/
private $pagelayout;

Expand All @@ -69,7 +73,7 @@ public function __construct(
* @param int $parentLocationId Location the content should be a child of
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
* @return \EzSystems\RepositoryForms\Content\View\ContentEditView|\Symfony\Component\HttpFoundation\Response
*/
public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request)
{
Expand All @@ -88,10 +92,9 @@ public function createWithoutDraftAction($contentTypeIdentifier, $language, $par
}
}

return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', [
return new ContentEditView(null, [
'form' => $form->createView(),
'languageCode' => $language,
'pagelayout' => $this->pagelayout,
]);
}

Expand All @@ -104,7 +107,7 @@ public function createWithoutDraftAction($contentTypeIdentifier, $language, $par
* @param string $toLanguage
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
* @return \EzSystems\RepositoryForms\Content\View\ContentCreateDraftView|\Symfony\Component\HttpFoundation\Response
*/
public function createContentDraftAction($contentId, $fromVersionNo = null, $fromLanguage = null, $toLanguage = null, Request $request)
{
Expand Down Expand Up @@ -135,10 +138,7 @@ public function createContentDraftAction($contentId, $fromVersionNo = null, $fro
}
}

return $this->render('@EzSystemsRepositoryForms/Content/content_create_draft.html.twig', [
'form' => $form->createView(),
'pagelayout' => $this->pagelayout,
]);
return new ContentCreateDraftView(null, ['form' => $form->createView()]);
}

/**
Expand All @@ -149,7 +149,7 @@ public function createContentDraftAction($contentId, $fromVersionNo = null, $fro
* @param \Symfony\Component\HttpFoundation\Request $request
* @param string $language Language code to create the version in (eng-GB, ger-DE, ...))
*
* @return \Symfony\Component\HttpFoundation\Response
* @return \EzSystems\RepositoryForms\Content\View\ContentEditView|\Symfony\Component\HttpFoundation\Response
* @throws \eZ\Publish\Core\Base\Exceptions\BadStateException If the version isn't editable, or if there is no editable version.
*/
public function editContentDraftAction($contentId, $versionNo = null, Request $request, $language = null)
Expand Down Expand Up @@ -183,16 +183,17 @@ public function editContentDraftAction($contentId, $versionNo = null, Request $r
}
}

return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', [
return new ContentEditView(null, [
'form' => $form->createView(),
'languageCode' => $language,
'pagelayout' => $this->pagelayout,
]);
}

/**
* @param string $pagelayout
* @return ContentEditController
*
* @deprecated Deprecated since 1.10 and will be removed in 2.0. Pagelayout is injected via ViewTemplatesListener.
*/
public function setPagelayout($pagelayout)
{
Expand Down
11 changes: 3 additions & 8 deletions bundle/Controller/UserRegisterController.php
Expand Up @@ -9,8 +9,8 @@
namespace EzSystems\RepositoryFormsBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;
use EzSystems\RepositoryForms\Data\Mapper\UserRegisterMapper;
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute;
use EzSystems\RepositoryForms\Data\Mapper\UserRegisterMapper;
use EzSystems\RepositoryForms\Form\ActionDispatcher\ActionDispatcherInterface;
use EzSystems\RepositoryForms\Form\Type\User\UserRegisterType;
use EzSystems\RepositoryForms\UserRegister\View\UserRegisterConfirmView;
Expand Down Expand Up @@ -43,9 +43,7 @@ public function __construct(
*
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Exception if the current user isn't allowed to register an account
* @return \EzSystems\RepositoryForms\UserRegister\View\UserRegisterFormView|\Symfony\Component\HttpFoundation\Response * @throws \Exception if the current user isn't allowed to register an account
*/
public function registerAction(Request $request)
{
Expand All @@ -70,10 +68,7 @@ public function registerAction(Request $request)
}
}

return new UserRegisterFormView(
null,
['form' => $form->createView()]
);
return new UserRegisterFormView(null, ['form' => $form->createView()]);
}

public function registerConfirmAction()
Expand Down
66 changes: 66 additions & 0 deletions bundle/DependencyInjection/Configuration/Parser/ContentEdit.php
@@ -0,0 +1,66 @@
<?php
/**
* This file is part of the eZ RepositoryForms package.
*
* @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\RepositoryFormsBundle\DependencyInjection\Configuration\Parser;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

class ContentEdit extends AbstractParser
{
/**
* Adds semantic configuration definition.
*
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
{
$nodeBuilder
->arrayNode('content_edit')
->info('Content edit configuration')
->children()
->arrayNode('templates')
->info('Content edit templates.')
->children()
->scalarNode('edit')
->info('Template to use for content edit form rendering.')
->end()
->scalarNode('create_draft')
->info('Template to use for content draft creation rendering.')
->end()
->end()
->end()
->end()
->end();
}

public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
{
if (empty($scopeSettings['content_edit'])) {
return;
}

$settings = $scopeSettings['content_edit'];

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

if (!empty($settings['templates']['create_draft'])) {
$contextualizer->setContextualParameter(
'content_edit.templates.create_draft',
$currentScope,
$settings['templates']['create_draft']
);
}
}
}
2 changes: 2 additions & 0 deletions bundle/EzSystemsRepositoryFormsBundle.php
Expand Up @@ -14,6 +14,7 @@
use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\FieldTypeFormMapperDispatcherPass;
use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\FieldTypeFormMapperPass;
use EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler\LimitationFormMapperPass;
use EzSystems\RepositoryFormsBundle\DependencyInjection\Configuration\Parser\ContentEdit;
use EzSystems\RepositoryFormsBundle\DependencyInjection\Configuration\Parser\UserRegistration;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -30,6 +31,7 @@ public function build(ContainerBuilder $container)
$eZExtension = $container->getExtension('ezpublish');
$eZExtension->addPolicyProvider(new UserRegisterPolicyProvider());
$eZExtension->addConfigParser(new UserRegistration());
$eZExtension->addConfigParser(new ContentEdit());
$eZExtension->addDefaultSettings(__DIR__ . '/Resources/config', ['ezpublish_default_settings.yml']);
}
}
3 changes: 2 additions & 1 deletion bundle/Resources/config/ezpublish_default_settings.yml
Expand Up @@ -2,4 +2,5 @@ parameters:
ezsettings.default.user_registration.group_id: 11
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_draft: "EzSystemsRepositoryFormsBundle:Content:content_create_draft.html.twig"
13 changes: 10 additions & 3 deletions bundle/Resources/config/services.yml
Expand Up @@ -66,7 +66,8 @@ parameters:

ezrepoforms.user_register.registration_group_loader.configurable.class: EzSystems\RepositoryForms\UserRegister\ConfigurableRegistrationGroupLoader
ezrepoforms.user_register.registration_content_type_loader.configurable.class: EzSystems\RepositoryForms\UserRegister\ConfigurableRegistrationContentTypeLoader
ezrepoforms.user_register.view_templates_listener.class: EzSystems\RepositoryForms\EventListener\ViewTemplatesListener
ezrepoforms.view_templates_listener.class: EzSystems\RepositoryForms\EventListener\ViewTemplatesListener
ezrepoforms.user_register.view_templates_listener.class: '%ezrepoforms.view_templates_listener.class%' # Deprecated in 1.10, to be removed in 2.0

ezrepoforms.form_data_mapper.user_register.class: EzSystems\RepositoryForms\Data\Mapper\UserRegisterMapper

Expand Down Expand Up @@ -440,15 +441,21 @@ services:
calls:
- [setParam, ["language", "@=service('ezpublish.config.resolver').getParameter('languages', null, null)[0]"]]

ezrepoforms.user_register.view_templates_listener:
class: "%ezrepoforms.user_register.view_templates_listener.class%"
ezrepoforms.view_templates_listener:
class: "%ezrepoforms.view_templates_listener.class%"
tags:
- { name: kernel.event_subscriber }
calls:
- [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\ContentCreateDraftView', "$content_edit.templates.create_draft$"]]
- [setPagelayout, ["$pagelayout$"]]

ezrepoforms.user_register.view_templates_listener:
alias: ezrepoforms.view_templates_listener
deprecated: 'The "%service_id%" service is deprecated since 1.10 and will be removed in 2.0. Use "ezrepoforms.view_templates_listener" instead.'

ezrepoforms.translation.extractor.sorting:
class: EzSystems\RepositoryForms\Translation\SortingTranslationExtractor
tags:
Expand Down
3 changes: 2 additions & 1 deletion doc/bc/changes-1.10.md
Expand Up @@ -16,5 +16,6 @@ Changes affecting version compatibility with former or future versions.
How it might affect your code: Don't rely on `TranslationHelper` as the same functionality is now achieved by calling `getNames()` directly on the object.

## Deprecations

- The "ezrepoforms.user_register.view_templates_listener" service is deprecated since 1.10 and will be removed in 2.0. Use "ezrepoforms.view_templates_listener" instead

## Removed features
13 changes: 13 additions & 0 deletions lib/Content/View/ContentCreateDraftView.php
@@ -0,0 +1,13 @@
<?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;
use eZ\Publish\Core\MVC\Symfony\View\View;

class ContentCreateDraftView extends BaseView implements View
{
}
13 changes: 13 additions & 0 deletions lib/Content/View/ContentEditView.php
@@ -0,0 +1,13 @@
<?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;
use eZ\Publish\Core\MVC\Symfony\View\View;

class ContentEditView extends BaseView implements View
{
}

0 comments on commit e394a02

Please sign in to comment.