Skip to content

Commit 578226c

Browse files
ViniTouŁukasz Serwatka
authored andcommitted
EZP-29408: As an editor I want to delete a content item with an image asset field (#591)
* EZP-29408: As an editor I want to delete a content item with an image asset field * EZP-29408: As an editor I want to delete a content item with an image asset field * EZP-29408: Updated modals design * EZP-29408: changed when form options are build + CR fixes * fixup! EZP-29408: changed when form options are build + CR fixes * fixup! EZP-29408: changed when form options are build + CR fixes
1 parent 57eaab8 commit 578226c

21 files changed

+816
-18
lines changed

src/bundle/Controller/ContentViewController.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace EzSystems\EzPlatformAdminUiBundle\Controller;
1010

1111
use eZ\Publish\API\Repository\BookmarkService;
12+
use eZ\Publish\API\Repository\ContentService;
1213
use eZ\Publish\API\Repository\ContentTypeService;
1314
use eZ\Publish\API\Repository\LanguageService;
1415
use eZ\Publish\API\Repository\Values\Content\Location;
@@ -20,9 +21,12 @@
2021
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationCopySubtreeData;
2122
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationMoveData;
2223
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashData;
24+
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashWithAssetData;
2325
use EzSystems\EzPlatformAdminUi\Form\Data\User\UserDeleteData;
2426
use EzSystems\EzPlatformAdminUi\Form\Data\User\UserEditData;
2527
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
28+
use EzSystems\EzPlatformAdminUi\Specification\Content\ContentHaveAssetRelation;
29+
use EzSystems\EzPlatformAdminUi\Specification\Content\ContentHaveUniqueRelation;
2630
use EzSystems\EzPlatformAdminUi\Specification\ContentIsUser;
2731
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ContentViewParameterSupplier as SubitemsContentViewParameterSupplier;
2832
use EzSystems\EzPlatformAdminUi\UI\Service\PathService;
@@ -69,6 +73,9 @@ class ContentViewController extends Controller
6973
/** @var int */
7074
private $defaultCustomUrlPaginationLimit;
7175

76+
/** @var \eZ\Publish\API\Repository\ContentService */
77+
private $contentService;
78+
7279
/**
7380
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
7481
* @param \eZ\Publish\API\Repository\LanguageService $languageService
@@ -77,6 +84,7 @@ class ContentViewController extends Controller
7784
* @param \EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ContentViewParameterSupplier $subitemsContentViewParameterSupplier
7885
* @param \eZ\Publish\API\Repository\UserService $userService
7986
* @param \eZ\Publish\API\Repository\BookmarkService $bookmarkService
87+
* @param \eZ\Publish\API\Repository\ContentService $contentService
8088
* @param int $defaultDraftPaginationLimit
8189
* @param array $siteAccessLanguages
8290
* @param int $defaultRolePaginationLimit
@@ -92,6 +100,7 @@ public function __construct(
92100
SubitemsContentViewParameterSupplier $subitemsContentViewParameterSupplier,
93101
UserService $userService,
94102
BookmarkService $bookmarkService,
103+
ContentService $contentService,
95104
int $defaultDraftPaginationLimit,
96105
array $siteAccessLanguages,
97106
int $defaultRolePaginationLimit,
@@ -112,6 +121,7 @@ public function __construct(
112121
$this->defaultPolicyPaginationLimit = $defaultPolicyPaginationLimit;
113122
$this->defaultSystemUrlPaginationLimit = $defaultSystemUrlPaginationLimit;
114123
$this->defaultCustomUrlPaginationLimit = $defaultCustomUrlPaginationLimit;
124+
$this->contentService = $contentService;
115125
}
116126

117127
/**
@@ -230,7 +240,27 @@ private function supplyContentActionForms(ContentView $view): void
230240
'form_location_copy_subtree' => $locationCopySubtreeType->createView(),
231241
]);
232242

233-
if ((new ContentIsUser($this->userService))->isSatisfiedBy($content)) {
243+
$contentHaveAssetRelation = new ContentHaveAssetRelation($this->contentService);
244+
if ($contentHaveAssetRelation
245+
->and(new ContentHaveUniqueRelation($this->contentService))
246+
->isSatisfiedBy($content)
247+
) {
248+
$trashWithAssetType = $this->formFactory->trashLocationWithAsset(
249+
new LocationTrashWithAssetData($location)
250+
);
251+
252+
$view->addParameters([
253+
'form_location_trash_with_single_asset' => $trashWithAssetType->createView(),
254+
]);
255+
} elseif ($contentHaveAssetRelation->isSatisfiedBy($content)) {
256+
$locationTrashType = $this->formFactory->trashLocation(
257+
new LocationTrashData($location)
258+
);
259+
260+
$view->addParameters([
261+
'form_location_trash_with_asset' => $locationTrashType->createView(),
262+
]);
263+
} elseif ((new ContentIsUser($this->userService))->isSatisfiedBy($content)) {
234264
$userDeleteType = $this->formFactory->deleteUser(
235265
new UserDeleteData($content->contentInfo)
236266
);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace EzSystems\EzPlatformAdminUiBundle\Controller\Location;
10+
11+
use eZ\Publish\API\Repository\ContentService;
12+
use eZ\Publish\API\Repository\LocationService;
13+
use eZ\Publish\API\Repository\TrashService;
14+
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashWithAssetData;
15+
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
16+
use EzSystems\EzPlatformAdminUi\Form\SubmitHandler;
17+
use EzSystems\EzPlatformAdminUi\Form\Type\Location\LocationTrashWithAssetType;
18+
use EzSystems\EzPlatformAdminUiBundle\Controller\Controller;
19+
use Symfony\Component\HttpFoundation\Request;
20+
use Symfony\Component\HttpFoundation\Response;
21+
22+
class TrashLocationWithAssetController extends Controller
23+
{
24+
/** @var \EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory */
25+
private $formFactory;
26+
27+
/** @var \EzSystems\EzPlatformAdminUi\Form\SubmitHandler */
28+
private $submitHandler;
29+
30+
/** @var \eZ\Publish\API\Repository\LocationService */
31+
private $locationService;
32+
33+
/** @var \eZ\Publish\API\Repository\ContentService */
34+
private $contentService;
35+
36+
/** @var \eZ\Publish\API\Repository\TrashService */
37+
private $trashService;
38+
39+
/**
40+
* @param \EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory $formFactory
41+
* @param \EzSystems\EzPlatformAdminUi\Form\SubmitHandler $submitHandler
42+
* @param \eZ\Publish\API\Repository\LocationService $locationService
43+
* @param \eZ\Publish\API\Repository\ContentService $contentService
44+
* @param \eZ\Publish\API\Repository\TrashService $trashService
45+
*/
46+
public function __construct(
47+
FormFactory $formFactory,
48+
SubmitHandler $submitHandler,
49+
LocationService $locationService,
50+
ContentService $contentService,
51+
TrashService $trashService
52+
) {
53+
$this->formFactory = $formFactory;
54+
$this->submitHandler = $submitHandler;
55+
$this->trashService = $trashService;
56+
$this->locationService = $locationService;
57+
$this->contentService = $contentService;
58+
}
59+
60+
/**
61+
* @param \Symfony\Component\HttpFoundation\Request $request
62+
*
63+
* @return \Symfony\Component\HttpFoundation\Response
64+
*
65+
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
66+
*/
67+
public function trashAction(Request $request): Response
68+
{
69+
$form = $this->formFactory->trashLocationWithAsset(
70+
new LocationTrashWithAssetData()
71+
);
72+
$form->handleRequest($request);
73+
74+
if ($form->isSubmitted()) {
75+
$result = $this->submitHandler->handle($form, function (LocationTrashWithAssetData $data) {
76+
$location = $data->getLocation();
77+
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);
78+
if ($data->getTrashAssets() === LocationTrashWithAssetType::RADIO_SELECT_TRASH_WITH_ASSETS) {
79+
$content = $this->contentService->loadContentByContentInfo($location->contentInfo);
80+
$relations = $this->contentService->loadRelations($content->versionInfo);
81+
$imageLocation = $this->locationService->loadLocation($relations[0]->destinationContentInfo->mainLocationId);
82+
$this->trashService->trash($imageLocation);
83+
}
84+
85+
$this->trashService->trash($location);
86+
87+
return $this->redirectToLocation($parentLocation);
88+
});
89+
90+
if ($result instanceof Response) {
91+
return $result;
92+
}
93+
}
94+
95+
return $this->redirect($this->generateUrl('ezplatform.trash.list'));
96+
}
97+
}

src/bundle/Resources/config/routing.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ ezplatform.location.copy_subtree:
418418
defaults:
419419
_controller: 'EzPlatformAdminUiBundle:Location:copySubtree'
420420

421+
ezplatform.location.trash_with_asset:
422+
path: /location/trash-with-asset
423+
methods: ['POST']
424+
defaults:
425+
_controller: 'EzPlatformAdminUiBundle:Location\TrashLocationWithAsset:trash'
426+
421427
# LocationView / Translation tab
422428

423429
ezplatform.translation.add:

src/bundle/Resources/config/services.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ services:
106106

107107
EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory: ~
108108

109-
110109
EzSystems\EzPlatformAdminUi\Notification\FlashBagNotificationHandler: ~
111110

112111
EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface: '@EzSystems\EzPlatformAdminUi\Notification\FlashBagNotificationHandler'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function (global, doc) {
2+
const toggleForms = [...doc.querySelectorAll('.ez-toggle-btn-state-radio')];
3+
4+
toggleForms.forEach((toggleForm) => {
5+
const radioInputs = [...toggleForm.querySelectorAll('input[type="radio"]')];
6+
const toggleButtonState = () => {
7+
const button = doc.querySelector(toggleForm.dataset.toggleButtonId);
8+
const oneIsSelected = radioInputs.some(el => el.checked);
9+
10+
if (oneIsSelected) {
11+
button['removeAttribute']('disabled', true);
12+
}
13+
};
14+
15+
radioInputs.forEach(radioInput => radioInput.addEventListener('change', toggleButtonState, false));
16+
});
17+
})(window, document);

src/bundle/Resources/public/scss/_buttons.scss

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,27 @@
109109
}
110110
}
111111

112+
.ez-modal--trash-with-asset {
113+
.modal-footer {
114+
.btn-secondary {
115+
background-color: $ez-color-base-medium;
116+
border-color: $ez-color-base-medium;
117+
118+
&:hover {
119+
background-color: $ez-color-base-medium-hover;
120+
border-color: $ez-color-base-medium-hover;
121+
}
122+
}
123+
}
124+
}
125+
112126
.ez-content-view,
113127
.ez-trash-list-view {
114128
.ez-modal--send-to-trash {
115129
.modal-footer {
116130
.form-check-inline {
117131
margin-right: 0;
118132

119-
.btn {
120-
font-size: 1rem;
121-
padding-bottom: .5rem;
122-
}
123-
124133
.btn-danger {
125134
margin-right: 0;
126135
}

src/bundle/Resources/public/scss/_forms.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,9 @@ form:not(.form-inline) {
112112
color: $ez-color-danger;
113113
}
114114
}
115+
116+
.ez-trash-with-asset-checkbox-list {
117+
.form-check-input {
118+
position: absolute;
119+
}
120+
}

src/bundle/Resources/public/scss/_modals.scss

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,50 @@
149149
}
150150
}
151151
}
152+
153+
.ez-modal--trash-with-asset {
154+
.modal-dialog {
155+
max-width: calculateRem(800px);
156+
}
157+
158+
.modal-header {
159+
background: $ez-color-base-pale;
160+
border-bottom: none;
161+
162+
.modal-title {
163+
font-size: calculateRem(24px);
164+
}
165+
166+
.close {
167+
margin-top: calculateRem(-9px);
168+
}
169+
}
170+
171+
.modal-body {
172+
padding: calculateRem(32px);
173+
background-color: $ez-ground-base-medium;
174+
border-radius: 0 0 calculateRem(4px) calculateRem(4px);
175+
176+
.ez-modal-body__main {
177+
margin-bottom: calculateRem(24px);
178+
179+
.ez-modal-body__main-content {
180+
margin-bottom: 0;
181+
}
182+
}
183+
184+
.ez-table-header,
185+
.ez-table__draft-conflict {
186+
margin-bottom: 0;
187+
}
188+
189+
.form-check {
190+
margin-bottom: 0;
191+
margin-left: calculateRem(50px);
192+
}
193+
}
194+
195+
.modal-footer {
196+
justify-content: center;
197+
}
198+
}

src/bundle/Resources/translations/forms.en.xliff

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,21 @@
146146
<target state="new">Move</target>
147147
<note>key: location_move.move</note>
148148
</trans-unit>
149+
<trans-unit id="4b7b2b4de853db0d1fb1851e07f3ccc51e5713fc" resname="location_trash_form.default_trash">
150+
<source>Delete only %content_name% (%content_type%)</source>
151+
<target state="new">Delete only %content_name% (%content_type%)</target>
152+
<note>key: location_trash_form.default_trash</note>
153+
</trans-unit>
149154
<trans-unit id="796f8196b2bc086fe788e6689a6189c79b8e047e" resname="location_trash_form.trash">
150155
<source>Send to Trash</source>
151156
<target state="new">Send to Trash</target>
152157
<note>key: location_trash_form.trash</note>
153158
</trans-unit>
159+
<trans-unit id="2598fe0050f38f3c02014a404ed14aee248e27d1" resname="location_trash_form.trash_with_asset">
160+
<source>Delete %content_name% (%content_type%) and its related image assets</source>
161+
<target state="new">Delete %content_name% (%content_type%) and its related image assets</target>
162+
<note>key: location_trash_form.trash_with_asset</note>
163+
</trans-unit>
154164
<trans-unit id="f86cd366867d370b0706e250355f605e2b783229" resname="policies_delete_form.delete">
155165
<source>Delete policies</source>
156166
<target state="new">Delete policies</target>

src/bundle/Resources/translations/messages.en.xliff

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,31 @@
249249
<target state="new">Are you sure you want to send this content item to trash?</target>
250250
<note>key: trash.modal.message</note>
251251
</trans-unit>
252+
<trans-unit id="bd97a738137e75de44544db1104bab3a46222791" resname="trash_asset.modal.message_body">
253+
<source>If you wish to delete this(/these) asset(s) too, first make sure they are not used by other content. You can check these content going to the asset(s) and looking at their content relations in the Relation tab.</source>
254+
<target state="new">If you wish to delete this(/these) asset(s) too, first make sure they are not used by other content. You can check these content going to the asset(s) and looking at their content relations in the Relation tab.</target>
255+
<note>key: trash_asset.modal.message_body</note>
256+
</trans-unit>
257+
<trans-unit id="17c7abad79d72d771a25b064e0de38b72fc6c926" resname="trash_asset.modal.message_header">
258+
<source>You are about to delete a content that has one or several asset(s) field(s) used by other content items. These assets will remain available in system.</source>
259+
<target state="new">You are about to delete a content that has one or several asset(s) field(s) used by other content items. These assets will remain available in system.</target>
260+
<note>key: trash_asset.modal.message_header</note>
261+
</trans-unit>
262+
<trans-unit id="0d57f9b91203aa4d9920e63d793b8e62c0bb242c" resname="trash_asset_single.modal.header">
263+
<source>Deleting content</source>
264+
<target state="new">Deleting content</target>
265+
<note>key: trash_asset_single.modal.header</note>
266+
</trans-unit>
267+
<trans-unit id="e81a14f38ebe272cb11ef90e2948a8c6602307ca" resname="trash_asset_single.modal.message">
268+
<source>You have the option to delete %content_name% (%content_type%) only or to also delete the assets it is using. Make your choice:</source>
269+
<target state="new">You have the option to delete %content_name% (%content_type%) only or to also delete the assets it is using. Make your choice:</target>
270+
<note>key: trash_asset_single.modal.message</note>
271+
</trans-unit>
272+
<trans-unit id="ff537a1e092270edf7497dc13ce051cdb458958b" resname="trash_asset_single.modal.message_main">
273+
<source>You are about to delete a content with one or several asset(s) field(s).</source>
274+
<target state="new">You are about to delete a content with one or several asset(s) field(s).</target>
275+
<note>key: trash_asset_single.modal.message_main</note>
276+
</trans-unit>
252277
</body>
253278
</file>
254279
</xliff>

src/bundle/Resources/views/content/locationview.html.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@
9494
{% if form_user_delete is defined %}
9595
{% include '@ezdesign/content/modal_user_delete.html.twig' with {'form': form_user_delete} only %}
9696
{% endif %}
97+
{% if form_location_trash_with_asset is defined %}
98+
{% include '@ezdesign/content/modal_location_trash_with_asset.html.twig' with {
99+
'form': form_location_trash_with_asset
100+
} only %}
101+
{% endif %}
102+
{% if form_location_trash_with_single_asset is defined %}
103+
{% include '@ezdesign/content/modal_location_trash_with_single_asset.html.twig' with {
104+
'form': form_location_trash_with_single_asset,
105+
'content_name': content.name,
106+
'content_type': contentType.name
107+
} only %}
108+
{% endif %}
97109
{{ form(form_location_copy, {'action': path('ezplatform.location.copy')}) }}
98110
{{ form(form_location_move, {'action': path('ezplatform.location.move')}) }}
99111
{{ form(form_location_copy_subtree, {'action': path('ezplatform.location.copy_subtree')}) }}

0 commit comments

Comments
 (0)