Skip to content

Commit

Permalink
IBX-6592: Refactored solution to base Object State on Location instea…
Browse files Browse the repository at this point in the history
…d of ContentInfo
  • Loading branch information
barw4 committed Nov 8, 2023
1 parent e47a001 commit 7e135a6
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 61 deletions.
22 changes: 8 additions & 14 deletions src/bundle/Controller/ObjectStateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use eZ\Publish\API\Repository\ObjectStateService;
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
Expand Down Expand Up @@ -296,17 +296,10 @@ public function updateAction(Request $request, ObjectState $objectState): Respon
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function updateContentStateAction(
Request $request,
ContentInfo $contentInfo,
ObjectStateGroup $objectStateGroup,
Location $location
): Response {
Expand All @@ -320,18 +313,19 @@ public function updateContentStateAction(

$form = $this->formFactory->create(
ContentObjectStateUpdateType::class,
new ContentObjectStateUpdateData($contentInfo, $objectStateGroup, null, $location)
new ContentObjectStateUpdateData($objectStateGroup, null, $location)
);
$form->handleRequest($request);

$contentInfo = $location->getContentInfo();

if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (ContentObjectStateUpdateData $data) {
$contentInfo = $data->getContentInfo();
$location = $data->getLocation();
$objectStateGroup = $data->getObjectStateGroup();
$objectState = $data->getObjectState();
$location = $data->getLocation();
$this->objectStateService->setContentState(
$contentInfo,
$location->getContentInfo(),
$objectStateGroup,
$objectState,
$location
Expand All @@ -351,8 +345,8 @@ public function updateContentStateAction(
}

return $this->redirectToRoute('_ez_content_view', [
'contentId' => $contentInfo->id,
'locationId' => $contentInfo->mainLocationId,
'contentId' => $contentInfo->getId(),
'locationId' => $contentInfo->getMainLocationId(),
'_fragment' => 'ez-tab-location-view-details',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ ezplatform.object_state.state.bulk_delete:
_controller: 'EzSystems\EzPlatformAdminUiBundle\Controller\ObjectStateController::bulkDeleteAction'

ezplatform.object_state.contentstate.update:
path: /state/contentstate/update/{contentInfoId}/group/{objectStateGroupId}/{locationId}
path: /state/contentstate/update/{locationId}/group/{objectStateGroupId}
defaults:
_controller: 'EzSystems\EzPlatformAdminUiBundle\Controller\ObjectStateController::updateContentStateAction'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@
{{ form_start(form_state_update[object_state.objectStateGroup.id], {
'method': 'POST',
'action': path('ezplatform.object_state.contentstate.update', {
'contentInfoId': content_info.id,
'objectStateGroupId': object_state.objectStateGroup.id,
'locationId': location.id,
}),
'attr': {'class': 'form-inline ez-form-inline ez-form-inline--align-left'}
}) }}
{{ form_row(form_state_update[object_state.objectStateGroup.id].contentInfo) }}
{{ form_row(form_state_update[object_state.objectStateGroup.id].objectStateGroup) }}
{{ form_row(form_state_update[object_state.objectStateGroup.id].objectState, { 'attr': {'class': 'ez-form-autosubmit'} }) }}
{% do form_state_update[object_state.objectStateGroup.id].set.setRendered %}
Expand Down
16 changes: 0 additions & 16 deletions src/lib/Form/Data/ObjectState/ContentObjectStateUpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@

namespace EzSystems\EzPlatformAdminUi\Form\Data\ObjectState;

use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;

class ContentObjectStateUpdateData
{
/** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo|null */
private $contentInfo;

/** @var \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup|null */
private $objectStateGroup;

Expand All @@ -28,27 +24,15 @@ class ContentObjectStateUpdateData
private $location;

public function __construct(
ContentInfo $contentInfo = null,
ObjectStateGroup $objectStateGroup = null,
ObjectState $objectState = null,
Location $location = null
) {
$this->contentInfo = $contentInfo;
$this->objectStateGroup = $objectStateGroup;
$this->objectState = $objectState;
$this->location = $location;
}

public function getContentInfo(): ContentInfo
{
return $this->contentInfo;
}

public function setContentInfo(ContentInfo $contentInfo)
{
$this->contentInfo = $contentInfo;
}

public function getObjectStateGroup(): ObjectStateGroup
{
return $this->objectStateGroup;
Expand Down
25 changes: 7 additions & 18 deletions src/lib/Form/Type/ObjectState/ContentObjectStateUpdateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
use EzSystems\EzPlatformAdminUi\Form\Data\ObjectState\ContentObjectStateUpdateData;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\ContentInfoType;
use EzSystems\EzPlatformAdminUi\Form\Type\Content\LocationType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
Expand All @@ -29,23 +29,16 @@ class ContentObjectStateUpdateType extends AbstractType
/** @var \eZ\Publish\API\Repository\PermissionResolver */
private $permissionResolver;

/**
* @param \eZ\Publish\API\Repository\ObjectStateService $objectStateService
* @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver
*/
public function __construct(ObjectStateService $objectStateService, PermissionResolver $permissionResolver)
{
$this->objectStateService = $objectStateService;
$this->permissionResolver = $permissionResolver;
}

/**
* @inheritdoc
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('contentInfo', ContentInfoType::class, [
->add('location', LocationType::class, [
'label' => false,
])
->add('objectStateGroup', ObjectStateGroupType::class, [
Expand All @@ -59,21 +52,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
/** @var \EzSystems\EzPlatformAdminUi\Form\Data\ObjectState\ContentObjectStateUpdateData $contentObjectStateUpdateData */
$contentObjectStateUpdateData = $event->getData();
$objectStateGroup = $contentObjectStateUpdateData->getObjectStateGroup();
$contentInfo = $contentObjectStateUpdateData->getContentInfo();
$location = $contentObjectStateUpdateData->getLocation();
$form = $event->getForm();

$form->add('objectState', ObjectStateChoiceType::class, [
'label' => false,
'choice_loader' => new CallbackChoiceLoader(
function () use ($objectStateGroup, $contentInfo, $location) {
function () use ($objectStateGroup, $location) {
return array_filter(
$this->objectStateService->loadObjectStates($objectStateGroup),
function (ObjectState $objectState) use ($contentInfo, $location) {
function (ObjectState $objectState) use ($location) {
return $this->permissionResolver->canUser(
'state',
'assign',
$contentInfo,
$location->getContentInfo(),
[$location, $objectState],
);
}
Expand All @@ -83,10 +75,7 @@ function (ObjectState $objectState) use ($contentInfo, $location) {
});
}

/**
* @inheritdoc
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => ContentObjectStateUpdateData::class,
Expand Down
11 changes: 7 additions & 4 deletions src/lib/Tab/LocationView/DetailsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public function getTemplate(): string

/**
* @inheritdoc
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function getTemplateParameters(array $contextParameters = []): array
{
Expand All @@ -133,7 +135,7 @@ public function getTemplateParameters(array $contextParameters = []): array
]);

$this->supplySectionParameters($viewParameters, $contentInfo, $location);
$this->supplyObjectStateParameters($viewParameters, $contentInfo, $location);
$this->supplyObjectStateParameters($viewParameters, $location);
$this->supplyTranslations($viewParameters, $versionInfo);
$this->supplyFormLocationUpdate($viewParameters, $location);
$this->supplyCreator($viewParameters, $contentInfo);
Expand Down Expand Up @@ -185,13 +187,15 @@ private function supplyLastContributor(ArrayObject $parameters, VersionInfo $ver
}
}

/**
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
private function supplyObjectStateParameters(
ArrayObject &$parameters,
ContentInfo $contentInfo,
Location $location
): void {
$objectStatesDataset = $this->datasetFactory->objectStates();
$objectStatesDataset->load($contentInfo, $location);
$objectStatesDataset->load($location);

$canAssignObjectState = $this->canUserAssignObjectState();

Expand All @@ -205,7 +209,6 @@ private function supplyObjectStateParameters(
$objectStateUpdateForm = $this->formFactory->create(
ContentObjectStateUpdateType::class,
new ContentObjectStateUpdateData(
$contentInfo,
$objectStateGroup,
$objectState,
$location,
Expand Down
7 changes: 3 additions & 4 deletions src/lib/UI/Dataset/ObjectStatesDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace EzSystems\EzPlatformAdminUi\UI\Dataset;

use eZ\Publish\API\Repository\ObjectStateService;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
use EzSystems\EzPlatformAdminUi\UI\Value as UIValue;
Expand All @@ -32,16 +31,16 @@ public function __construct(ObjectStateService $objectStateService, ValueFactory
$this->valueFactory = $valueFactory;
}

public function load(ContentInfo $contentInfo, Location $location): self
public function load(Location $location): self
{
$data = array_map(
function (ObjectStateGroup $objectStateGroup) use ($contentInfo, $location) {
function (ObjectStateGroup $objectStateGroup) use ($location) {
$hasObjectStates = !empty($this->objectStateService->loadObjectStates($objectStateGroup));
if (!$hasObjectStates) {
return [];
}

return $this->valueFactory->createObjectState($contentInfo, $objectStateGroup, $location);
return $this->valueFactory->createObjectState($objectStateGroup, $location);
},
$this->objectStateService->loadObjectStateGroups()
);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/UI/Value/ValueFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\UserService;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\DraftList\Item\ContentDraftListItem;
use eZ\Publish\API\Repository\Values\Content\DraftList\Item\UnauthorizedContentDraftListItem;
use eZ\Publish\API\Repository\Values\Content\Language;
Expand Down Expand Up @@ -257,10 +256,10 @@ public function createLocation(Location $location): UIValue\Content\Location
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function createObjectState(
ContentInfo $contentInfo,
ObjectStateGroup $objectStateGroup,
Location $location
): UIValue\ObjectState\ObjectState {
$contentInfo = $location->getContentInfo();
$objectState = $this->objectStateService->getContentState($contentInfo, $objectStateGroup);

return new UIValue\ObjectState\ObjectState($objectState, [
Expand Down

0 comments on commit 7e135a6

Please sign in to comment.