Skip to content
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

Merged
merged 8 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 77 additions & 3 deletions src/bundle/Controller/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\Base\Exceptions\BadStateException;
use EzSystems\EzPlatformAdminUi\Exception\InvalidArgumentException as AdminInvalidArgumentException;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\ContentVisibilityUpdateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Location\ContentMainLocationUpdateData;
Expand All @@ -23,6 +24,7 @@
use EzSystems\EzPlatformAdminUi\Form\DataMapper\MainTranslationUpdateMapper;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Form\SubmitHandler;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\ContentVisibilityUpdateType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Translation\MainTranslationUpdateType;
use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface;
use EzSystems\EzPlatformAdminUi\Siteaccess\SiteaccessResolverInterface;
Expand Down Expand Up @@ -279,9 +281,9 @@ public function updateMainLocationAction(Request $request): Response

if (null !== $contentInfo) {
return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
'locationId' => $contentInfo->mainLocationId,
'_fragment' => 'ez-tab-location-view-locations',
]));
'locationId' => $contentInfo->mainLocationId,
'_fragment' => 'ez-tab-location-view-locations',
]));
}

return $this->redirectToRoute('ezplatform.dashboard');
Expand Down Expand Up @@ -381,4 +383,76 @@ public function updateMainTranslationAction(Request $request): Response

return $this->redirectToRoute('ezplatform.dashboard');
}

/**
* @param Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function updateVisibilityAction(Request $request): Response
{
$form = $this->createForm(ContentVisibilityUpdateType::class);
$form->handleRequest($request);
$result = null;

if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (ContentVisibilityUpdateData $data) {
$contentInfo = $data->getContentInfo();
$desiredVisibility = $data->getVisible();
$location = $data->getLocation();

if ($contentInfo->isHidden && $desiredVisibility === false) {
$this->notificationHandler->success(
$this->translator->trans(
/** @Desc("Content '%name%' was already hidden.") */
'content.hide.already_hidden',
['%name%' => $contentInfo->name],
'content'
)
);
}

if (!$contentInfo->isHidden && $desiredVisibility === true) {
$this->notificationHandler->success(
$this->translator->trans(
/** @Desc("Content '%name%' was already visible.") */
'content.reveal.already_visible',
['%name%' => $contentInfo->name],
'content'
)
);
}

if (!$contentInfo->isHidden && $desiredVisibility === false) {
$this->contentService->hideContent($contentInfo);

$this->notificationHandler->success(
$this->translator->trans(
/** @Desc("Content '%name%' has been hidden.") */
'content.hide.success',
['%name%' => $contentInfo->name],
'content'
)
);
}

if ($contentInfo->isHidden && $desiredVisibility === true) {
$this->contentService->revealContent($contentInfo);

$this->notificationHandler->success(
$this->translator->trans(
/** @Desc("Content '%name%' has been revealed.") */
'content.reveal.success',
['%name%' => $contentInfo->name],
'content'
)
);
}

return $location === null ? $this->redirectToRoute('ezplatform.dashboard') : $this->redirectToLocation($location);
});
}

return $result instanceof Response ? $result : $this->redirectToRoute('ezplatform.dashboard');
}
}
31 changes: 31 additions & 0 deletions src/bundle/Controller/ContentViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use eZ\Publish\API\Repository\UserService;
use eZ\Publish\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\ContentVisibilityUpdateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationCopyData;
Expand All @@ -31,13 +32,15 @@
use EzSystems\EzPlatformAdminUi\Form\Data\User\UserDeleteData;
use EzSystems\EzPlatformAdminUi\Form\Data\User\UserEditData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\ContentVisibilityUpdateType;
use EzSystems\EzPlatformAdminUi\Specification\Content\ContentHaveAssetRelation;
use EzSystems\EzPlatformAdminUi\Specification\Content\ContentHaveUniqueRelation;
use EzSystems\EzPlatformAdminUi\Specification\ContentIsUser;
use EzSystems\EzPlatformAdminUi\Specification\Location\HasChildren;
use EzSystems\EzPlatformAdminUi\Specification\Location\IsContainer;
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ContentViewParameterSupplier as SubitemsContentViewParameterSupplier;
use EzSystems\EzPlatformAdminUi\UI\Service\PathService;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;

Expand Down Expand Up @@ -91,6 +94,9 @@ class ContentViewController extends Controller
/** @var \eZ\Publish\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface */
private $userLanguagePreferenceProvider;

/** @var \Symfony\Component\Form\FormFactoryInterface */
private $sfFormFactory;
pawbuj marked this conversation as resolved.
Show resolved Hide resolved

/**
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
* @param \eZ\Publish\API\Repository\LanguageService $languageService
Expand All @@ -114,6 +120,7 @@ public function __construct(
LanguageService $languageService,
PathService $pathService,
FormFactory $formFactory,
FormFactoryInterface $sfFormFactory,
SubitemsContentViewParameterSupplier $subitemsContentViewParameterSupplier,
UserService $userService,
BookmarkService $bookmarkService,
Expand All @@ -131,6 +138,7 @@ public function __construct(
$this->languageService = $languageService;
$this->pathService = $pathService;
$this->formFactory = $formFactory;
$this->sfFormFactory = $sfFormFactory;
$this->subitemsContentViewParameterSupplier = $subitemsContentViewParameterSupplier;
$this->userService = $userService;
$this->bookmarkService = $bookmarkService;
Expand Down Expand Up @@ -178,6 +186,8 @@ public function locationViewAction(Request $request, ContentView $view): Content

$this->supplyIsLocationBookmarked($view);

$this->supplyContentReverseRelations($view);

return $view;
}

Expand Down Expand Up @@ -258,10 +268,20 @@ private function supplyContentActionForms(ContentView $view): void
new LocationCopySubtreeData($location)
);

$contentVisibilityUpdateForm = $this->sfFormFactory->create(
ContentVisibilityUpdateType::class,
new ContentVisibilityUpdateData(
$location->getContentInfo(),
$location,
$location->getContentInfo()->isHidden
)
);

$view->addParameters([
'form_location_copy' => $locationCopyType->createView(),
'form_location_move' => $locationMoveType->createView(),
'form_content_create' => $contentCreateType->createView(),
'form_content_visibility_update' => $contentVisibilityUpdateForm->createView(),
'form_subitems_content_edit' => $subitemsContentEdit->createView(),
'form_location_copy_subtree' => $locationCopySubtreeType->createView(),
]);
Expand Down Expand Up @@ -462,4 +482,15 @@ private function supplyIsLocationBookmarked(ContentView $view): void

$view->addParameters(['location_is_bookmarked' => $locationIsBookmarked]);
}

/**
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
*/
private function supplyContentReverseRelations(ContentView $view): void
{
$contentInfo = $view->getLocation()->getContentInfo();
$relations = $this->contentService->loadReverseRelations($contentInfo);

$view->addParameters(['content_has_reverse_relations' => count($relations) > 0]);
}
}
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ ezplatform.content.update_main_translation:
defaults:
_controller: 'EzPlatformAdminUiBundle:Content:updateMainTranslation'

ezplatform.content.update_visibility:
path: /content/update-visibility
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:Content:updateVisibility'

# LocationView / Versions tab

ezplatform.version.remove:
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Resources/encore/ez.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ module.exports = (Encore) => {
path.resolve('./vendor/ezsystems/ezplatform-admin-ui-assets/Resources/public/vendors/leaflet/dist/leaflet.js'),
path.resolve(__dirname, '../public/js/scripts/admin.location.load.map.js'),
path.resolve(__dirname, '../public/js/scripts/sidebar/btn/content.edit.js'),
path.resolve(__dirname, '../public/js/scripts/sidebar/btn/content.hide.js'),
path.resolve(__dirname, '../public/js/scripts/sidebar/btn/content.reveal.js'),
path.resolve(__dirname, '../public/js/scripts/admin.location.add.custom_url.js'),
path.resolve(__dirname, '../public/js/scripts/button.state.toggle.js'),
path.resolve(__dirname, '../public/js/scripts/admin.version.edit.conflict.js'),
Expand Down
7 changes: 7 additions & 0 deletions src/bundle/Resources/public/img/ez-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading