-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-30139: As an editor I want to hide and reveal a content item #865
Conversation
@pawbuj rebase is needed. |
You don't have to compile AlloyEditor. |
@dew326 done |
@lserwatka done |
$contentInfo = $contentData->getContentInfo(); | ||
$location = $contentData->getLocation(); | ||
|
||
if ($contentInfo->isHidden) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be handled inside data object?
$form = $this->createForm(ContentType::class); | ||
$form->handleRequest($request); | ||
|
||
if (!$form->isSubmitted() || !$form->isValid()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
submit handler for those?
$form->handleRequest($request); | ||
|
||
if (!$form->isSubmitted() || !$form->isValid()) { | ||
throw new BadRequestHttpException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we used to return information with errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we can not find place where similar notification are displayed do not take this into account
/** @var \EzSystems\EzPlatformAdminUi\Form\Data\Content\ContentData $contentData */ | ||
$contentData = $form->getData(); | ||
$contentInfo = $contentData->getContentInfo(); | ||
$location = $contentData->getLocation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in EzSystems\EzPlatformAdminUi\Form\Data\Content\ContentData
getLocation() can return null
and below we have redirectToLocation()
. Will not it be a problem?
/** | ||
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view | ||
*/ | ||
private function supplyContentReverseRelations(ContentView $view) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private function supplyContentReverseRelations(ContentView $view) | |
private function supplyContentReverseRelations(ContentView $view): void |
<svg class="ez-icon ez-alert--icon"> | ||
<use xlink:href="/bundles/ezplatformadminui/img/ez-icons.svg#hide"></use> | ||
</svg> | ||
{{ 'content.hidden.message'|trans()|desc('This content item is hidden and is not publicly available') }}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
</div>
at the end should be in the new line
</table> | ||
<table class="ez-table table"> | ||
<thead> | ||
<tr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, fix indentation
type="checkbox" | ||
name="updateVisibility" | ||
{% if not can_hide[location.id] %} disabled="disabled"{% endif %} | ||
value="{{ location.id }}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value="{{ location.id }}"> | |
value="{{ location.id }}" /> |
{{ location.main ? 'checked' }} | ||
{{ not location.canEdit ? 'disabled' }} | ||
name="updateMainLocation" | ||
value="{{ location.id }}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value="{{ location.id }}"> | |
value="{{ location.id }}" /> |
private $location; | ||
|
||
/** | ||
* ContentData constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think ContentType
and ContentData
is a good approach. First, ContentType
is very confusing name in our domain. ContentData
should not have getLocation()
method inside. We tend to have specific Type+Data class for every action. I'd go for ContentVisibilityUpdateType
and matching Data class.
$contentInfo = $view->getLocation()->getContentInfo(); | ||
$relations = $this->contentService->loadReverseRelations($contentInfo); | ||
|
||
$view->addParameters(['contentHasReverseRelations' => (bool)count($relations)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use underscore names in Twig. Also small nitpick: count(...) > 0
feels more logical and is easier to understand.
<div class="ez-modal-body__main"> | ||
<p> | ||
{{ 'content.hide.modal.message1'|trans()|desc('This item is being used by other content item(s). Please remove all instance(s) to avoid a 404 error.') }}<br/> | ||
{{ 'content.hide.modal.message2'|trans()|desc('If you wish to continue, please click on Confirm.') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use more meaningful translation keys.
src/bundle/Resources/views/content/modal_content_hide_confirmation.html.twig
Outdated
Show resolved
Hide resolved
</div> | ||
</div> | ||
</div> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing line feed at the end of this file
Tool version : PHP CS Fixer 2.7.1 Sandy Pool by Fabien Potencier and Dariusz Ruminski diff --git a/src/bundle/Controller/ContentController.php b/src/bundle/Controller/ContentController.php
index eea0e78..ac9fa7d 100644
--- a/src/bundle/Controller/ContentController.php
+++ b/src/bundle/Controller/ContentController.php
@@ -4,7 +4,6 @@
* @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\EzPlatformAdminUiBundle\Controller;
use eZ\Publish\API\Repository\ContentService;
@@ -34,7 +33,6 @@ use EzSystems\EzPlatformAdminUi\Specification\ContentType\ContentTypeIsUser;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\Translation\Exception\InvalidArgumentException;
use Symfony\Component\Translation\TranslatorInterface;
@@ -196,7 +194,7 @@ class ContentController extends Controller
$this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("New Version Draft for '%name%' created.") */
+ /** @Desc("New Version Draft for '%name%' created.") */
'content.create_draft.success',
['%name%' => $contentInfo->name],
'content'
@@ -259,7 +257,7 @@ class ContentController extends Controller
$this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Main location for '%name%' updated.") */
+ /** @Desc("Main location for '%name%' updated.") */
'content.main_location_update.success',
['%name%' => $contentInfo->name],
'content'
@@ -357,7 +355,7 @@ class ContentController extends Controller
$this->contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
$this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Main language for '%name%' updated.") */
+ /** @Desc("Main language for '%name%' updated.") */
'content.main_language_update.success',
['%name%' => $contentInfo->name],
'content'
@@ -398,14 +396,13 @@ class ContentController extends Controller
if ($form->isSubmitted()) {
$this->submitHandler->handle($form, function (ContentVisibilityUpdateData $data) {
-
$contentInfo = $data->getContentInfo();
$newValue = $data->getVisible();
if ($contentInfo->isHidden && $newValue === false) {
return $this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Content '%name%' was already hidden.") */
+ /** @Desc("Content '%name%' was already hidden.") */
'content.hide.already_hidden',
['%name%' => $contentInfo->name],
'content'
@@ -416,7 +413,7 @@ class ContentController extends Controller
if (!$contentInfo->isHidden && $newValue === true) {
return $this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Content '%name%' was already visible.") */
+ /** @Desc("Content '%name%' was already visible.") */
'content.reveal.already_visible',
['%name%' => $contentInfo->name],
'content'
@@ -426,9 +423,10 @@ class ContentController extends Controller
if ($newValue === false) {
$this->contentService->hideContent($contentInfo);
+
return $this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Content '%name%' has been hidden.") */
+ /** @Desc("Content '%name%' has been hidden.") */
'content.hide.success',
['%name%' => $contentInfo->name],
'content'
@@ -438,16 +436,16 @@ class ContentController extends Controller
if ($newValue === true) {
$this->contentService->revealContent($contentInfo);
+
return $this->noti(...)
NOTICE : Report truncated to 5Kb
|
Tool version : PHP CS Fixer 2.7.1 Sandy Pool by Fabien Potencier and Dariusz Ruminski diff --git a/src/bundle/Controller/ContentController.php b/src/bundle/Controller/ContentController.php
index eea0e78..ac9fa7d 100644
--- a/src/bundle/Controller/ContentController.php
+++ b/src/bundle/Controller/ContentController.php
@@ -4,7 +4,6 @@
* @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\EzPlatformAdminUiBundle\Controller;
use eZ\Publish\API\Repository\ContentService;
@@ -34,7 +33,6 @@ use EzSystems\EzPlatformAdminUi\Specification\ContentType\ContentTypeIsUser;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\Translation\Exception\InvalidArgumentException;
use Symfony\Component\Translation\TranslatorInterface;
@@ -196,7 +194,7 @@ class ContentController extends Controller
$this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("New Version Draft for '%name%' created.") */
+ /** @Desc("New Version Draft for '%name%' created.") */
'content.create_draft.success',
['%name%' => $contentInfo->name],
'content'
@@ -259,7 +257,7 @@ class ContentController extends Controller
$this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Main location for '%name%' updated.") */
+ /** @Desc("Main location for '%name%' updated.") */
'content.main_location_update.success',
['%name%' => $contentInfo->name],
'content'
@@ -357,7 +355,7 @@ class ContentController extends Controller
$this->contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
$this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Main language for '%name%' updated.") */
+ /** @Desc("Main language for '%name%' updated.") */
'content.main_language_update.success',
['%name%' => $contentInfo->name],
'content'
@@ -398,14 +396,13 @@ class ContentController extends Controller
if ($form->isSubmitted()) {
$this->submitHandler->handle($form, function (ContentVisibilityUpdateData $data) {
-
$contentInfo = $data->getContentInfo();
$newValue = $data->getVisible();
if ($contentInfo->isHidden && $newValue === false) {
return $this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Content '%name%' was already hidden.") */
+ /** @Desc("Content '%name%' was already hidden.") */
'content.hide.already_hidden',
['%name%' => $contentInfo->name],
'content'
@@ -416,7 +413,7 @@ class ContentController extends Controller
if (!$contentInfo->isHidden && $newValue === true) {
return $this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Content '%name%' was already visible.") */
+ /** @Desc("Content '%name%' was already visible.") */
'content.reveal.already_visible',
['%name%' => $contentInfo->name],
'content'
@@ -426,9 +423,10 @@ class ContentController extends Controller
if ($newValue === false) {
$this->contentService->hideContent($contentInfo);
+
return $this->notificationHandler->success(
$this->translator->trans(
- /** @Desc("Content '%name%' has been hidden.") */
+ /** @Desc("Content '%name%' has been hidden.") */
'content.hide.success',
['%name%' => $contentInfo->name],
'content'
@@ -438,16 +436,16 @@ class ContentController extends Controller
if ($newValue === true) {
$this->contentService->revealContent($contentInfo);
+
return $this->noti(...)
NOTICE : Report truncated to 5Kb
|
src/bundle/Controller/Controller.php
Outdated
/** | ||
* Redirects to the previous URL or to the dashboard if referer is different host. | ||
* | ||
* @param Request $request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Please use FQCN (also applicable in other places).
@@ -381,4 +383,72 @@ public function updateMainTranslationAction(Request $request): Response | |||
|
|||
return $this->redirectToRoute('ezplatform.dashboard'); | |||
} | |||
|
|||
/** | |||
* @param Request $request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Please use FQCN.
/** | ||
* @param Request $request | ||
* | ||
* @return Response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Please use FQCN.
src/bundle/Controller/Controller.php
Outdated
*/ | ||
public function redirectBack(Request $request): RedirectResponse | ||
{ | ||
$referer = $request->headers->get('referer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced with this method. You don't know what's inside referrer. Even though it won't redirect you to different domain it's still not predictable.
In your case you can simply redirect user back to Content View.
src/bundle/Controller/Controller.php
Outdated
/** | ||
* Redirects to the previous URL or to the dashboard if referer is different host | ||
* | ||
* @param Request $request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FQCN
}); | ||
} | ||
|
||
return $this->redirectBack($request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment. You can use https://github.com/ezsystems/ezplatform-admin-ui/blob/master/src/bundle/Controller/Location/TrashLocationWithAssetController.php#L67 as a reference.
Also it will disable possibility to override redirection by EventListeners
: https://github.com/ezsystems/ezplatform-admin-ui/blob/master/src/lib/Form/SubmitHandler.php#L77
$contentInfo = $data->getContentInfo(); | ||
$newValue = $data->getVisible(); | ||
|
||
if ($contentInfo->isHidden && $newValue === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could those two ifs be handled inside DataForm validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then, the behaviour will change, I do not want to show an error to the user if everything is ok.
…ystems#865) * EZP-30139: As an editor I want to hide and reveal a content item * cs fixes and refactoring * fixes js cs * cs fixes * more cs fixes * cs fixes * fix * fixes
Admin UI for hide/reveal content
Checklist:
$ composer fix-cs
)