Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix invoice create and search (#2990)
  • Loading branch information
kevinpapst committed Dec 4, 2021
1 parent 4e42911 commit 1da26e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Controller/AbstractController.php
Expand Up @@ -218,6 +218,8 @@ protected function handleSearch(FormInterface $form, Request $request): bool
}
}

$request->query->remove('_token');

if ($request->query->has('resetSearchFilter')) {
$data->resetFilter();
$this->removeLastSearch($data);
Expand Down
13 changes: 10 additions & 3 deletions src/Controller/InvoiceController.php
Expand Up @@ -66,7 +66,7 @@ public function __construct(ServiceInvoice $service, InvoiceTemplateRepository $
* @Route(path="/", name="invoice", methods={"GET", "POST"})
* @Security("is_granted('view_invoice')")
*/
public function indexAction(Request $request, SystemConfiguration $configuration): Response
public function indexAction(Request $request, SystemConfiguration $configuration, CsrfTokenManagerInterface $csrfTokenManager): Response
{
if (!$this->templateRepository->hasTemplate()) {
if ($this->isGranted('manage_invoice_template')) {
Expand Down Expand Up @@ -100,6 +100,8 @@ public function indexAction(Request $request, SystemConfiguration $configuration
return $this->redirectToRoute('invoice');
}

$csrfTokenManager->refreshToken('invoice.create');

try {
return $this->renderInvoice($query, $request);
} catch (Exception $ex) {
Expand Down Expand Up @@ -148,6 +150,7 @@ public function previewAction(Customer $customer, Request $request, SystemConfig

if ($form->isValid()) {
try {
$query->setCustomers([$customer]);
$model = $this->service->createModel($query);

return $this->service->renderInvoiceWithModel($model, $this->dispatcher);
Expand All @@ -167,7 +170,7 @@ public function previewAction(Customer $customer, Request $request, SystemConfig
* @Security("is_granted('access', customer)")
* @Security("is_granted('create_invoice')")
*/
public function createInvoiceAction(Customer $customer, InvoiceTemplate $template, Request $request, SystemConfiguration $configuration): Response
public function createInvoiceAction(Customer $customer, InvoiceTemplate $template, Request $request, SystemConfiguration $configuration, CsrfTokenManagerInterface $csrfTokenManager): Response
{
if (!$this->templateRepository->hasTemplate()) {
return $this->redirectToRoute('invoice');
Expand All @@ -185,9 +188,13 @@ public function createInvoiceAction(Customer $customer, InvoiceTemplate $templat
return $this->redirectToRoute('invoice');
}

$csrfTokenManager->refreshToken('invoice.create');

$query = $this->getDefaultQuery();
$form = $this->getToolbarForm($query, $configuration->find('invoice.simple_form'));
$form->submit($request->query->all(), false);
if ($this->handleSearch($form, $request)) {
return $this->redirectToRoute('invoice');
}

if ($form->isValid()) {
$query->setTemplate($template);
Expand Down
6 changes: 5 additions & 1 deletion src/Form/Extension/SelectWithApiDataExtension.php
Expand Up @@ -75,8 +75,12 @@ public function buildView(FormView $view, FormInterface $form, array $options)
} while (($parent = $parent->getParent()) !== null);

$formPrefix = implode('_', array_reverse($formPrefixes));
$formField = $apiData['select'];

$formField = $formPrefix . '_' . $apiData['select'];
// forms with prefix (like toolbar & search) would result in a wrong field name "_foo" instead of "foo"
if ($formPrefix !== '') {
$formField = $formPrefix . '_' . $apiData['select'];
}

$view->vars['attr'] = array_merge($view->vars['attr'], [
'data-form-prefix' => $formPrefix,
Expand Down

0 comments on commit 1da26e0

Please sign in to comment.