Skip to content

Commit

Permalink
EZP-30918: Added information to relations about restricted access (#327)
Browse files Browse the repository at this point in the history
* EZP-30918: Added information to relations about restricted access.

* fixup! EZP-30918: Added information to relations about restricted access.
  • Loading branch information
mikadamczyk authored and lserwatka committed Nov 22, 2019
1 parent 52578bf commit 87df225
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lib/Form/Type/FieldType/RelationFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\FieldType\Relation\Value;
use EzSystems\RepositoryForms\FieldType\DataTransformer\RelationValueTransformer;
Expand Down Expand Up @@ -69,13 +70,23 @@ public function finishView(FormView $view, FormInterface $form, array $options)
if (!$data instanceof Value || null === $data->destinationContentId) {
return;
}
$contentId = $data->destinationContentId;
$contentInfo = null;
$contentType = null;
$unauthorized = false;

$contentInfo = $this->contentService->loadContentInfo($data->destinationContentId);
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
try {
$contentInfo = $this->contentService->loadContentInfo($contentId);
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
} catch (UnauthorizedException $e) {
$unauthorized = true;
}

$view->vars['relations'][$data->destinationContentId] = [
'contentInfo' => $contentInfo,
'contentType' => $contentType,
'unauthorized' => $unauthorized,
'contentId' => $contentId,
];
}

Expand Down
15 changes: 13 additions & 2 deletions lib/Form/Type/FieldType/RelationListFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\FieldType\RelationList\Value;
use EzSystems\RepositoryForms\FieldType\DataTransformer\RelationListValueTransformer;
Expand Down Expand Up @@ -71,12 +72,22 @@ public function finishView(FormView $view, FormInterface $form, array $options)
}

foreach ($data->destinationContentIds as $contentId) {
$contentInfo = $this->contentService->loadContentInfo($contentId);
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
$contentInfo = null;
$contentType = null;
$unauthorized = false;

try {
$contentInfo = $this->contentService->loadContentInfo($contentId);
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
} catch (UnauthorizedException $e) {
$unauthorized = true;
}

$view->vars['relations'][$contentId] = [
'contentInfo' => $contentInfo,
'contentType' => $contentType,
'unauthorized' => $unauthorized,
'contentId' => $contentId,
];
}
}
Expand Down

0 comments on commit 87df225

Please sign in to comment.