Skip to content

Commit

Permalink
Merge pull request #188 from webhdx/content_edit_action
Browse files Browse the repository at this point in the history
EZP-28556: Replace ContentDraftCreate with ContentEdit action handling optional draft creation
  • Loading branch information
Łukasz Serwatka authored Dec 15, 2017
2 parents 0916665 + 1208015 commit ea2e2df
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 30 deletions.
20 changes: 12 additions & 8 deletions src/bundle/Controller/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use eZ\Publish\API\Repository\Values\Content\Content;
use EzSystems\EzPlatformAdminUi\Exception\InvalidArgumentException as AdminInvalidArgumentException;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentDraftCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Location\ContentMainLocationUpdateData;
use EzSystems\EzPlatformAdminUi\Form\DataMapper\ContentMainLocationUpdateMapper;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
Expand Down Expand Up @@ -124,18 +124,22 @@ public function createAction(Request $request): Response
* @throws UnauthorizedException
* @throws InvalidOptionsException
*/
public function createDraftAction(Request $request): Response
public function editAction(Request $request): Response
{
$form = $this->formFactory->createContentDraft();
$form = $this->formFactory->contentEdit();
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$result = $this->submitHandler->handle($form, function (ContentDraftCreateData $data) {
$result = $this->submitHandler->handle($form, function (ContentEditData $data) {
$contentInfo = $data->getContentInfo();
$versionInfo = $data->getVersionInfo();
$language = $data->getLanguage();
$versionNo = $versionInfo->versionNo;

$contentDraft = $this->contentService->createContentDraft($contentInfo, $versionInfo);
if (!$versionInfo->isDraft()) {
$contentDraft = $this->contentService->createContentDraft($contentInfo, $versionInfo);
$versionNo = $contentDraft->getVersionInfo()->versionNo;
}

$this->notificationHandler->success(
$this->translator->trans(
Expand All @@ -148,7 +152,7 @@ public function createDraftAction(Request $request): Response

return $this->redirectToRoute('ez_content_draft_edit', [
'contentId' => $contentInfo->id,
'versionNo' => $contentDraft->getVersionInfo()->versionNo,
'versionNo' => $versionNo,
'language' => $language->languageCode,
]);
});
Expand All @@ -158,7 +162,7 @@ public function createDraftAction(Request $request): Response
}
}

/** @var ContentDraftCreateData $data */
/** @var ContentEditData $data */
$data = $form->getData();
$contentInfo = $data->getContentInfo();

Expand Down Expand Up @@ -216,7 +220,7 @@ public function updateMainLocationAction(Request $request): Response
}
}

/** @var ContentDraftCreateData $data */
/** @var ContentEditData $data */
$data = $form->getData();
$contentInfo = $data->getContentInfo();

Expand Down
8 changes: 4 additions & 4 deletions src/bundle/Controller/ContentViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentDraftCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationCopyData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationMoveData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashData;
Expand Down Expand Up @@ -101,8 +101,8 @@ private function supplyContentActionForms(ContentView $view): void
new LocationTrashData($location)
);

$contentDraftCreateType = $this->formFactory->createContentDraft(
new ContentDraftCreateData($content->contentInfo, $versionInfo)
$contentEditType = $this->formFactory->contentEdit(
new ContentEditData($content->contentInfo, $versionInfo)
);

$contentCreateType = $this->formFactory->createContent(
Expand All @@ -113,7 +113,7 @@ private function supplyContentActionForms(ContentView $view): void
'form_location_copy' => $locationCopyType->createView(),
'form_location_move' => $locationMoveType->createView(),
'form_location_trash' => $locationTrashType->createView(),
'form_content_draft_create' => $contentDraftCreateType->createView(),
'form_content_edit' => $contentEditType->createView(),
'form_content_create' => $contentCreateType->createView(),
]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ ezplatform.content.update_main_location:
# Content Edit
#

ezplatform.content_draft.create:
path: /content/draft/create # @todo change to /content/draft/create once route is removed from repository-forms
ezplatform.content.edit:
path: /content/edit
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:Content:createDraft'
_controller: 'EzPlatformAdminUiBundle:Content:edit'

ezplatform.content.create:
path: /content/create
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% form_theme form_location_copy '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}
{% form_theme form_location_move '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}
{% form_theme form_location_trash '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}
{% form_theme form_content_draft_create '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}
{% form_theme form_content_edit '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}
{% form_theme form_content_create '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' '@EzPlatformAdminUi/form_fields.html.twig' %}

{% block bodyClass %}ez-content-view{% endblock %}
Expand Down Expand Up @@ -61,7 +61,7 @@

<div class="ez-extra-actions-container">
{% include '@EzPlatformAdminUi/content/widgets/content_create.html.twig' with {'form': form_content_create} only %}
{% include '@EzPlatformAdminUi/content/widgets/content_edit.html.twig' with {'form': form_content_draft_create} only %}
{% include '@EzPlatformAdminUi/content/widgets/content_edit.html.twig' with {'form': form_content_edit} only %}
</div>

{% include '@EzPlatformAdminUi/content/modal_location_trash.html.twig' with {'form': form_location_trash} only %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="ez-extra-actions ez-extra-actions--edit ez-extra-actions--hidden bg-secondary" data-actions="edit">
<div class="ez-extra-actions__header">{{ 'content.edit.select_language'|trans|desc('Select language') }}</div>
<div class="ez-extra-actions__content">
{{ form_start(form, { 'action': path('ezplatform.content_draft.create') }) }}
{{ form_start(form, { 'action': path('ezplatform.content.edit') }) }}
{{ form_widget(form.content_info, { 'attr': {
'hidden': 'hidden',
'class': 'ez-extra-actions__form-field'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @todo Add validation. $language have to be validated that $versionInfo indeed has this language
*/
class ContentDraftCreateData
class ContentEditData
{
/** @var ContentInfo|null */
protected $contentInfo;
Expand Down
16 changes: 8 additions & 8 deletions src/lib/Form/Factory/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace EzSystems\EzPlatformAdminUi\Form\Factory;

use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentDraftCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Location\ContentMainLocationUpdateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Location\ContentLocationAddData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Location\ContentLocationRemoveData;
Expand Down Expand Up @@ -51,7 +51,7 @@
use EzSystems\EzPlatformAdminUi\Form\Data\Trash\TrashItemRestoreData;
use EzSystems\EzPlatformAdminUi\Form\Data\Version\VersionRemoveData;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Draft\ContentCreateType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Draft\ContentDraftCreateType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Draft\ContentEditType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Location\ContentLocationAddType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Location\ContentLocationRemoveType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Location\ContentMainLocationUpdateType;
Expand Down Expand Up @@ -117,26 +117,26 @@ public function __construct(FormFactoryInterface $formFactory, UrlGeneratorInter
}

/**
* @param ContentDraftCreateData|null $data
* @param ContentEditData|null $data
* @param string|null $name
*
* @return FormInterface
*
* @throws InvalidOptionsException
*/
public function createContentDraft(
?ContentDraftCreateData $data = null,
public function contentEdit(
?ContentEditData $data = null,
?string $name = null
): FormInterface {
$name = $name ?: StringUtil::fqcnToBlockPrefix(ContentDraftCreateType::class);
$data = $data ?? new ContentDraftCreateData();
$name = $name ?: StringUtil::fqcnToBlockPrefix(ContentEditType::class);
$data = $data ?? new ContentEditData();
$options = null !== $data->getVersionInfo()
? ['language_codes' => $data->getVersionInfo()->languageCodes]
: [];

return $this->formFactory->createNamed(
$name,
ContentDraftCreateType::class,
ContentEditType::class,
$data,
$options
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace EzSystems\EzPlatformAdminUi\Form\Type\Content\Draft;

use eZ\Publish\API\Repository\LanguageService;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentDraftCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\ContentInfoType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\VersionInfoType;
use EzSystems\EzPlatformAdminUi\Form\Type\Language\LanguageChoiceType;
Expand All @@ -19,7 +19,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ContentDraftCreateType extends AbstractType
class ContentEditType extends AbstractType
{
/** @var LanguageService */
protected $languageService;
Expand Down Expand Up @@ -65,7 +65,7 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'data_class' => ContentDraftCreateData::class,
'data_class' => ContentEditData::class,
'translation_domain' => 'forms',
'language_codes' => false,
])
Expand Down

0 comments on commit ea2e2df

Please sign in to comment.