-
Notifications
You must be signed in to change notification settings - Fork 8
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
CED-1124 NGSTACK-831 edit infocollection #89
Open
Gintron
wants to merge
89
commits into
3.x
Choose a base branch
from
CED-1124-edit-infocollection
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
89 commits
Select commit
Hold shift + click to select a range
82983ad
CED-1124 WIP
a325b2c
CED-1124 WIP
1078320
CED-1124 enable information collection editing
0feeea3
CED-1124 use form theme from bundle
9837590
CED-1124 add configuration for EnhancedSelectionFieldHandler and fix …
b571290
CED-1124 remove dump from form.html.twig
8ae1fc8
CED-1124 Add minimal styling for ic edit form and translations for ed…
vjeran 577d9e8
CED-1124 check edit permissions
3f85b70
CED-1124 add return type in createUpdateFormForLocation method
f9cf7a1
CED-1124 remove uneccessary comments
5ddfd75
CED-1124 set languages with config resolver
11c12af
CED-1124 add edit link on collection list
39638ea
CS Fixes
ludwig031 11079f5
CED-1124 add ibexa-forms-bundle package to composer.json
2dedd9f
CED-1124 refactor fromLegacyValue method
d44fc88
CED-1124 add fromLegacyValue method to interface
0b4f820
CED-1124 rename method fromLegacyValue to fromAttribute
2d33a49
CED-1124 use spritf when creating name for formbuilder
ac40a59
CED-1124 change the php version in composer.json
a5f8e50
CED-1124 fix code style and remove not necessary use statements in In…
0ff2402
CED-1124 require php 8.1 or greater
6fc74a5
CED-1124 InformationCollectionUpdateType.php code cleaning
1d67a7c
CED-1124 InformationCollectionUpdateMapper.php code cleaning
7faf13c
CED-1124 FormBuilder.php code cleaning
c34cdb5
CED-1124 code cleanup FormBuilder.php
251ce38
CED-1124 code cleanup AdminController.php
316673c
CED-1124 code cleanup field handlers
7182dd9
CED-1124 add findByCollectionIdAndFieldDefinitionId method to EzInfoC…
2f1bdff
CED-1024 rename variable in AdminController editAction
34ebdf2
CED-1024 add return value to CountryFieldHandler
4dc434f
CED-1124 typehint ValueObject instead of Value to make code more robust
d9710ed
CED-1124 use $this->createNotFoundException() in AdminController.php
36d5f6a
CED-1124 check if fielddefinition is null
2f9f33f
CED-1124 check if location is not null
58bc405
CED-1124 instead of type hinting ValueObject type hint Value Interface
e00a98d
CED-1124 rename method fromAttribute to getFieldValueFromAttribute
9d63353
CED-1124 use getFieldValueFromAttribute instead of fromAttribute
89702d5
CED-1124 typehint right InformationCollectionStruct
0c50e28
CED-1124 throw NotFoundException
1d3bd95
CED-1124 remove dependency on ibexa-forms-bundle
6f0f394
CED-1124 set right arguments
760b953
CED-1124 add form_fieldtype_handlers.yaml
1deef6b
CED-1124 add FieldTypeHandlerRegistryPass.php
852d03a
CED-1124 register FieldTypeHandlerRegistryPass.php
bdf85a9
CED-1124 adjustments to work with old FieldTypeHandler
d42fe13
CED-1124 clean up DataMapper.php
12dcfa7
CED-1124 clean up FieldTypeHandler.php
b540b6f
CED-1124 clean up Checkbox.php
691a39a
CED-1124 clean up Country.php
bba4273
CED-1124 clean up Selection.php
5a1554d
CED-1124 clean up FieldTypeHandlerInterface.php
65ef538
CED-1124 clean up field type handlers
932f303
CED-1124 remove User.php class
8aa2661
CED-1124 remove User from field type config
a0d2b5e
CED-1124 fix BinaryFile return type
83093de
CED-1124 sync parameter name with interface in mapDataToForms method
6580c58
CED-1124 sync parameter name with interface in mapFormsToData method
f574457
CED-1124 fix alias in Checkbox.php
75d831c
CED-1124 fix aliases and return types in field type handlers
fac3dfd
CED-1124 add docblock type hint to Country.php
e0905a8
CED-1124 match variable with interface Selection.php
df6111a
CED-1124 add docblock type hint to field type handler
6bec7a9
CED-1124 update code to PHP 8.1 standards
37edb6f
CED-1124 change name of variable in DataMapper.php
bc480a8
CED-1124 remove redundant inline type hint
90f8ad9
CED-1124 remove redundant inline type hint
54aa265
CED-1124 add return type to getCollectedValue method
cc986d9
CED-1124 add return type for value variable in setCollectedValue method
aec51eb
CED-1124 change alias in DateAndTime.php
a6d9a0e
CED-1124 fixed wrong variable name in DataMapper.php
1ab8f5d
CED-1124 remove UserType.php
7822313
CED-1124 remove UserUpdateType.php
bfce0ac
CED-1124 remove UserCreateType.php
6266154
CED-1124 add type hints to DataWrapper.php
4ccfd43
CED-1124 update docs in DataWrapper.php
706fed5
CED-1124 remove callable from parameter docs in FieldTypeHandlerRegis…
d2abeb6
CED-1124 type hint FieldTypeHandlerInterface in register method
38530c5
CED-1124 remove handling callable from get method in FieldTypeHandler…
49dc73c
CED-1124 move form types to Type folder
f52577d
CED-1124 adapt tag name for form_fieldtype_handlers.yaml
9f56103
CED-1124 adapt tag in FieldTypeHandlerRegistryPass.php
137ab03
CED-1124 add Birthday type
e46037b
CED-1124 remove FieldTypeHandlerInterface from Ibexa Forms bundle in …
9fb2e01
CED-1124 change class namespace in configuration
fc5f4d2
CED-1124 add enhanced selection handler
2c79357
CED-1124 standardize EnhancedSelection.php and Birthday.php with Fiel…
ffdd8eb
CED-1124 change input type and remove constraint in Birthday.php
8e9d616
CED-2116 Collection deletion bug fix
1f7fd08
Merge pull request #96 from netgen/CED-2116-collection-deletion-bug
emodric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Content; | ||
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute; | ||
use Ibexa\Bundle\Core\Controller; | ||
use Ibexa\Contracts\Core\Repository\ContentService; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Content; | ||
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; | ||
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute; | ||
use Netgen\Bundle\InformationCollectionBundle\Form\Builder\FormBuilder; | ||
use Netgen\InformationCollection\API\Persistence\Anonymizer\Anonymizer; | ||
use Netgen\InformationCollection\API\Service\InformationCollection; | ||
use Netgen\InformationCollection\API\Value\Collection; | ||
use Netgen\InformationCollection\API\Value\Filter\CollectionFields; | ||
use Netgen\InformationCollection\API\Value\Filter\CollectionId; | ||
use Netgen\InformationCollection\API\Value\Filter\Collections; | ||
use Netgen\InformationCollection\API\Value\Filter\ContentId; | ||
use Netgen\InformationCollection\API\Value\Filter\Contents; | ||
use Netgen\InformationCollection\API\Value\Filter\Query; | ||
use Netgen\InformationCollection\API\Value\Filter\SearchQuery; | ||
use Netgen\InformationCollection\Core\Factory\FieldDataFactory; | ||
use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListAdapter; | ||
use Netgen\InformationCollection\Core\Pagination\InformationCollectionCollectionListSearchAdapter; | ||
use Netgen\InformationCollection\Core\Pagination\InformationCollectionContentsAdapter; | ||
use Netgen\InformationCollection\Doctrine\Repository\EzInfoCollectionAttributeRepository; | ||
use Netgen\InformationCollection\Doctrine\Repository\EzInfoCollectionRepository; | ||
use Pagerfanta\Adapter\AdapterInterface; | ||
use Pagerfanta\Pagerfanta; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
use function array_merge; | ||
use function count; | ||
use function time; | ||
|
||
class AdminController extends Controller | ||
{ | ||
protected InformationCollection $service; | ||
|
@@ -36,25 +47,39 @@ class AdminController extends Controller | |
|
||
protected Anonymizer $anonymizer; | ||
|
||
protected FieldDataFactory $factory; | ||
protected EzInfoCollectionRepository $infoCollectionRepository; | ||
|
||
protected EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository; | ||
|
||
protected FormBuilder $builder; | ||
|
||
private TranslatorInterface $translator; | ||
|
||
public function __construct( | ||
InformationCollection $service, | ||
Anonymizer $anonymizer, | ||
ContentService $contentService, | ||
ConfigResolverInterface $configResolver, | ||
TranslatorInterface $translator | ||
) | ||
{ | ||
TranslatorInterface $translator, | ||
FieldDataFactory $factory, | ||
EzInfoCollectionRepository $infoCollectionRepository, | ||
EzInfoCollectionAttributeRepository $infoCollectionAttributeRepository, | ||
FormBuilder $builder | ||
) { | ||
$this->service = $service; | ||
$this->contentService = $contentService; | ||
$this->configResolver = $configResolver; | ||
$this->anonymizer = $anonymizer; | ||
$this->translator = $translator; | ||
$this->factory = $factory; | ||
$this->infoCollectionRepository = $infoCollectionRepository; | ||
$this->infoCollectionAttributeRepository = $infoCollectionAttributeRepository; | ||
$this->builder = $builder; | ||
} | ||
|
||
/** | ||
* Displays overview page | ||
* Displays overview page. | ||
*/ | ||
public function overviewAction(Request $request): Response | ||
{ | ||
|
@@ -63,27 +88,27 @@ public function overviewAction(Request $request): Response | |
$adapter = new InformationCollectionContentsAdapter($this->service, Query::countQuery()); | ||
$pager = $this->getPager($adapter, (int) $request->query->get('page')); | ||
|
||
return $this->render("@NetgenInformationCollection/admin/overview.html.twig", ['objects' => $pager]); | ||
return $this->render('@NetgenInformationCollection/admin/overview.html.twig', ['objects' => $pager]); | ||
} | ||
|
||
/** | ||
* Displays list of collection for selected Content | ||
* Displays list of collection for selected Content. | ||
*/ | ||
public function collectionListAction(Request $request, Content $content): Response | ||
{ | ||
$this->checkReadPermissions(); | ||
|
||
$adapter = new InformationCollectionCollectionListAdapter($this->service, ContentId::withContentId($content->id)); | ||
$pager = $this->getPager($adapter, (int)$request->query->get('page')); | ||
$pager = $this->getPager($adapter, (int) $request->query->get('page')); | ||
|
||
return $this->render("@NetgenInformationCollection/admin/collection_list.html.twig", [ | ||
return $this->render('@NetgenInformationCollection/admin/collection_list.html.twig', [ | ||
'objects' => $pager, | ||
'content' => $content, | ||
]); | ||
} | ||
|
||
/** | ||
* Handles collection search | ||
* Handles collection search. | ||
*/ | ||
public function searchAction(Request $request, Content $content): Response | ||
{ | ||
|
@@ -92,9 +117,10 @@ public function searchAction(Request $request, Content $content): Response | |
$query = SearchQuery::withContentAndSearchText($content->id, $request->query->get('searchText')); | ||
|
||
$adapter = new InformationCollectionCollectionListSearchAdapter($this->service, $query); | ||
$pager = $this->getPager($adapter, (int)$request->query->get('page')); | ||
$pager = $this->getPager($adapter, (int) $request->query->get('page')); | ||
|
||
return $this->render("@NetgenInformationCollection/admin/collection_list.html.twig", | ||
return $this->render( | ||
'@NetgenInformationCollection/admin/collection_list.html.twig', | ||
[ | ||
'objects' => $pager, | ||
'content' => $content, | ||
|
@@ -103,20 +129,20 @@ public function searchAction(Request $request, Content $content): Response | |
} | ||
|
||
/** | ||
* Displays individual collection details | ||
* Displays individual collection details. | ||
*/ | ||
public function viewAction(Collection $collection): Response | ||
{ | ||
$this->checkReadPermissions(); | ||
|
||
return $this->render("@NetgenInformationCollection/admin/view.html.twig", [ | ||
return $this->render('@NetgenInformationCollection/admin/view.html.twig', [ | ||
'collection' => $collection, | ||
'content' => $collection->getContent(), | ||
]); | ||
} | ||
|
||
/** | ||
* Handles actions performed on overview page | ||
* Handles actions performed on overview page. | ||
*/ | ||
public function handleContentsAction(Request $request): RedirectResponse | ||
{ | ||
|
@@ -132,7 +158,6 @@ public function handleContentsAction(Request $request): RedirectResponse | |
} | ||
|
||
if ($request->request->has('DeleteCollectionByContentAction')) { | ||
|
||
$this->checkDeletePermissions(); | ||
|
||
$query = new Contents($contents); | ||
|
@@ -150,7 +175,7 @@ public function handleContentsAction(Request $request): RedirectResponse | |
} | ||
|
||
/** | ||
* Handles actions performed on collection list page | ||
* Handles actions performed on collection list page. | ||
*/ | ||
public function handleCollectionListAction(Request $request): RedirectResponse | ||
{ | ||
|
@@ -167,7 +192,6 @@ public function handleCollectionListAction(Request $request): RedirectResponse | |
} | ||
|
||
if ($request->request->has('DeleteCollectionAction')) { | ||
|
||
$this->checkDeletePermissions(); | ||
|
||
$query = new Collections($contentId, $collections); | ||
|
@@ -180,7 +204,6 @@ public function handleCollectionListAction(Request $request): RedirectResponse | |
} | ||
|
||
if ($request->request->has('AnonymizeCollectionAction')) { | ||
|
||
$this->checkAnonymizePermissions(); | ||
|
||
foreach ($collections as $collection) { | ||
|
@@ -198,7 +221,7 @@ public function handleCollectionListAction(Request $request): RedirectResponse | |
} | ||
|
||
/** | ||
* Handles action on collection details page | ||
* Handles action on collection details page. | ||
*/ | ||
public function handleCollectionAction(Request $request): RedirectResponse | ||
{ | ||
|
@@ -219,7 +242,6 @@ public function handleCollectionAction(Request $request): RedirectResponse | |
} | ||
|
||
if ($request->request->has('DeleteFieldAction')) { | ||
|
||
$this->checkDeletePermissions(); | ||
|
||
$query = new CollectionFields($contentId, $collectionId, $fields); | ||
|
@@ -232,7 +254,6 @@ public function handleCollectionAction(Request $request): RedirectResponse | |
} | ||
|
||
if ($request->request->has('AnonymizeFieldAction')) { | ||
|
||
$this->checkAnonymizePermissions(); | ||
|
||
$this->anonymizer->anonymizeCollection($collectionId, $fields); | ||
|
@@ -243,25 +264,22 @@ public function handleCollectionAction(Request $request): RedirectResponse | |
} | ||
|
||
if ($request->request->has('DeleteCollectionAction')) { | ||
|
||
$this->checkDeletePermissions(); | ||
|
||
$query = new Collections($contentId, [$collectionId]); | ||
$this->service->deleteCollections($query); | ||
|
||
$this->addFlashMessage("success", "collection_removed"); | ||
$this->addFlashMessage('success', 'collection_removed'); | ||
|
||
return $this->redirectToRoute('netgen_information_collection.route.admin.collection_list', ['contentId' => $contentId]); | ||
|
||
} | ||
|
||
if ($request->request->has('AnonymizeCollectionAction')) { | ||
|
||
$this->checkAnonymizePermissions(); | ||
|
||
$this->anonymizer->anonymizeCollection($collectionId); | ||
|
||
$this->addFlashMessage("success", "collection_anonymized"); | ||
$this->addFlashMessage('success', 'collection_anonymized'); | ||
|
||
return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]); | ||
} | ||
|
@@ -271,10 +289,81 @@ public function handleCollectionAction(Request $request): RedirectResponse | |
return $this->redirectToRoute('netgen_information_collection.route.admin.view', ['collectionId' => $collectionId]); | ||
} | ||
|
||
public function editAction(Request $request, int $collectionId) | ||
{ | ||
$this->checkEditPermissions(); | ||
|
||
$collection = $this->service->getCollection(new CollectionId($collectionId)); | ||
|
||
$locationService = $this->getRepository()->getLocationService(); | ||
|
||
$location = $locationService->loadLocation($collection->getContent()->contentInfo->mainLocationId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main Location is directly available on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 251ce38 |
||
|
||
$form = $this->builder->createUpdateFormForLocation($location, $collection)->getForm(); | ||
|
||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$struct = $form->getData()->payload; | ||
pspanja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$contentType = $form->getData()->definition; | ||
pspanja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$ezInfo = $this->infoCollectionRepository->find($collectionId); | ||
pspanja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$ezInfo->setModified(time()); | ||
|
||
$this->infoCollectionRepository->save($ezInfo); | ||
|
||
foreach ($struct->getCollectedFields() as $fieldDefIdentifier => $value) { | ||
if ($value === null) { | ||
continue; | ||
} | ||
|
||
$fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier); | ||
pspanja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$legacyValue = $this->factory->getLegacyValue($value, $fieldDefinition); | ||
pspanja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$ezInfoAttributes = $this->infoCollectionAttributeRepository->findByCollectionIdAndFieldDefinitionIds( | ||
pspanja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$collectionId, | ||
[$fieldDefinition->id] | ||
); | ||
|
||
if (count($ezInfoAttributes) > 0) { | ||
$ezInfoAttribute = $ezInfoAttributes[0]; | ||
} else { | ||
$ezInfoAttribute = $this->infoCollectionAttributeRepository->getInstance(); | ||
$ezInfoAttribute->setContentObjectId($collection->getContent()->id); | ||
$ezInfoAttribute->setContentObjectAttributeId($collection->getContent()->getField($fieldDefinition->identifier)->id); | ||
$ezInfoAttribute->setContentClassAttributeId($fieldDefinition->id); | ||
$ezInfoAttribute->setInformationCollectionId($collection->getId()); | ||
} | ||
|
||
$ezInfoAttribute->setDataInt($legacyValue->getDataInt()); | ||
$ezInfoAttribute->setDataFloat($legacyValue->getDataFloat()); | ||
$ezInfoAttribute->setDataText($legacyValue->getDataText()); | ||
|
||
$this->infoCollectionAttributeRepository->save($ezInfoAttribute); | ||
} | ||
|
||
return $this->redirectToRoute( | ||
'netgen_information_collection.route.admin.view', | ||
[ | ||
'contentId' => $location->contentInfo->id, | ||
'collectionId' => $collection->getId(), | ||
] | ||
); | ||
} | ||
|
||
return $this->render('@NetgenInformationCollection/admin/edit.html.twig', [ | ||
'collection' => $collection, | ||
'content' => $location->getContent(), | ||
'form' => $form->createView(), | ||
]); | ||
} | ||
|
||
/** | ||
* Adds a flash message with specified parameters. | ||
*/ | ||
protected function addFlashMessage(string $messageType, string $message, int $count = 1, array $parameters = array()): void | ||
protected function addFlashMessage(string $messageType, string $message, int $count = 1, array $parameters = []): void | ||
{ | ||
$parameters = array_merge($parameters, ['count' => $count]); | ||
|
||
|
@@ -289,7 +378,7 @@ protected function addFlashMessage(string $messageType, string $message, int $co | |
} | ||
|
||
/** | ||
* Returns configured instance of Pagerfanta | ||
* Returns configured instance of Pagerfanta. | ||
*/ | ||
protected function getPager(AdapterInterface $adapter, int $currentPage): Pagerfanta | ||
{ | ||
|
@@ -320,4 +409,10 @@ protected function checkAnonymizePermissions(): void | |
$attribute = new Attribute('infocollector', 'anonymize'); | ||
$this->denyAccessUnlessGranted($attribute); | ||
} | ||
|
||
protected function checkEditPermissions(): void | ||
{ | ||
$attribute = new Attribute('infocollector', 'edit'); | ||
$this->denyAccessUnlessGranted($attribute); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Declare return type here.
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.
added in 251ce38