forked from ezsystems/repository-forms
/
ContentEditController.php
150 lines (135 loc) · 5.48 KB
/
ContentEditController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?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\Controller;
use eZ\Bundle\EzPublishCoreBundle\Controller;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
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\Form\ActionDispatcher\ActionDispatcherInterface;
use EzSystems\RepositoryForms\Form\Type\Content\ContentDraftCreateType;
use Symfony\Component\HttpFoundation\Request;
class ContentEditController extends Controller
{
/** @var ContentTypeService */
private $contentTypeService;
/** @var ContentService */
private $contentService;
/** @var ActionDispatcherInterface */
private $contentActionDispatcher;
public function __construct(
ContentTypeService $contentTypeService,
ContentService $contentService,
ActionDispatcherInterface $contentActionDispatcher
) {
$this->contentTypeService = $contentTypeService;
$this->contentService = $contentService;
$this->contentActionDispatcher = $contentActionDispatcher;
}
/**
* Displays and processes a content creation form. Showing the form does not create a draft in the repository.
*
* @param \EzSystems\RepositoryForms\Content\View\ContentCreateView $view
*
* @return \EzSystems\RepositoryForms\Content\View\ContentCreateView|\Symfony\Component\HttpFoundation\Response
*/
public function createWithoutDraftAction(ContentCreateView $view)
{
return $view;
}
/**
* Displays a draft creation form that creates a content draft from an existing content.
*
* @param mixed $contentId
* @param int $fromVersionNo
* @param string $fromLanguage
* @param string $toLanguage
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \EzSystems\RepositoryForms\Content\View\ContentCreateDraftView|\Symfony\Component\HttpFoundation\Response
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
*/
public function createContentDraftAction(
$contentId,
$fromVersionNo = null,
$fromLanguage = null,
$toLanguage = null,
Request $request
) {
$createContentDraft = new CreateContentDraftData();
$contentInfo = null;
$contentType = null;
if ($contentId !== null) {
$createContentDraft->contentId = $contentId;
$contentInfo = $this->contentService->loadContentInfo($contentId);
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
$createContentDraft->fromVersionNo = $fromVersionNo ?: $contentInfo->currentVersionNo;
$createContentDraft->fromLanguage = $fromLanguage ?: $contentInfo->mainLanguageCode;
}
$form = $this->createForm(
ContentDraftCreateType::class,
$createContentDraft,
[
'action' => $this->generateUrl('ez_content_draft_create'),
]
);
$form->handleRequest($request);
if ($form->isValid() && null !== $form->getClickedButton()) {
$this->contentActionDispatcher->dispatchFormAction($form, $createContentDraft, $form->getClickedButton()->getName());
if ($response = $this->contentActionDispatcher->getResponse()) {
return $response;
}
}
return new ContentCreateDraftView(null, [
'form' => $form->createView(),
'contentInfo' => $contentInfo,
'contentType' => $contentType,
]);
}
/**
* @param \EzSystems\RepositoryForms\Content\View\ContentEditView $view
*
* @return \EzSystems\RepositoryForms\Content\View\ContentEditView|\Symfony\Component\HttpFoundation\Response
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
*/
public function editVersionDraftAction(ContentEditView $view)
{
return $view;
}
/**
* Shows a content draft editing form.
*
* @deprecated In 2.1 and will be removed in 3.0. Please use `editVersionDraftAction()` instead.
*
* @param int $contentId ContentType id to create
* @param int $versionNo Version number the version should be created from. Defaults to the currently published one.
* @param string $language Language code to create the version in (eng-GB, ger-DE, ...))
* @param int|null $locationId
*
* @return \EzSystems\RepositoryForms\Content\View\ContentEditView|\Symfony\Component\HttpFoundation\Response
*/
public function editContentDraftAction(
$contentId,
$versionNo = null,
$language = null,
$locationId = null
) {
return $this->forward('ez_content_edit:editVersionDraftAction', [
'contentId' => $contentId,
'versionNo' => $versionNo,
'languageCode' => $language,
'locationId' => $locationId,
]);
}
}