Controller/FormController.php
public function formEditItem(Request $request, string $formUuid, int $onVersion, string $itemUuid): Response
    {
        /** @var \Symfony\Component\Security\Core\User\UserInterface $user */
        $user = $this->getUser();

        /** @var Form $aggregate */
        $aggregate = $this->aggregateFactory->build($formUuid, Form::class, $onVersion, $user->getId());

        if (empty($aggregate->items)) {
            // Aggregate does not exist, or is empty.
            return $this->redirectToForm($formUuid);
        }

        // Get the item from the aggregate.
        $item = FormBaseHandler::getItem($aggregate, $itemUuid);

        // Get the form title.
        $title = $this->translator->trans('Edit %itemName% field', [
            '%itemName%' => $this->translator->trans($item['itemName'] ?? 'Form'),
        ]);

        if ($item && isset($item['data'], $item['itemName'])) {
            $form = $this->getItemForm($item['itemName'], $item, $aggregate->items);
            $form->handleRequest($request);

            if ($form->isSubmitted()) {
                // Get differences in data and check if data has changed.
                $data = $form->getData()['data'];
                // Remove data that hasn't changed.
                $data = $this->diff($item['data'], $data);
                if (empty($data)) {
                    $form->addError(new FormError($this->translator->trans('Data has not changed.')));
                }

                if ($form->isValid()) {
                    // Execute Command.
                    $success = false;
                    $this->commandBus->dispatch(new FormEditItemCommand($user->getId(), Uuid::uuid1()->toString(), $formUuid, $onVersion, [
                        'uuid' => $itemUuid,
                        'data' => $data,
                    ], function ($commandBus, $event) use (&$success) {
                        // Callback.
                        $success = true;
                    }));

                    if ($success) {
                        $this->addFlash(
                            'success',
                            $this->translator->trans('Field edited')
                        );

                        return $this->redirectToForm($formUuid);
                    }

                    return $this->errorResponse($formUuid);
                }
            }
        } else {
            return $this->errorResponse($formUuid);
        }

        return $this->render('@forms/Form/form.html.twig', [
            'title' => $title,
            'form' => $form->createView(),
        ]);
    }
public function formEditItem(Request $request, string $formUuid, int $onVersion, string $itemUuid): Response
    {
        /** @var \Symfony\Component\Security\Core\User\UserInterface $user */
        $user = $this->getUser();

        /** @var Form $aggregate */
        $aggregate = $this->aggregateFactory->build($formUuid, Form::class, $onVersion, $user->getId());

        if (empty($aggregate->items)) {
            // Aggregate does not exist, or is empty.
            return $this->redirectToForm($formUuid);
        }

        // Get the item from the aggregate.
        $item = FormBaseHandler::getItem($aggregate, $itemUuid);

        // Get the form title.
        $title = $this->translator->trans('Edit %itemName% field', [
            '%itemName%' => $this->translator->trans($item['itemName'] ?? 'Form'),
        ]);

        if ($item && isset($item['data'], $item['itemName'])) {
            $form = $this->getItemForm($item['itemName'], $item, $aggregate->items);
            $form->handleRequest($request);

            if ($form->isSubmitted()) {
                // Get differences in data and check if data has changed.
                $data = $form->getData()['data'];
                // Remove data that hasn't changed.
                $data = $this->diff($item['data'], $data);
                if (empty($data)) {
                    $form->addError(new FormError($this->translator->trans('Data has not changed.')));
                }

                if ($form->isValid()) {
                    // Execute Command.
                    $success = false;
                    $this->commandBus->dispatch(new FormEditItemCommand($user->getId(), Uuid::uuid1()->toString(), $formUuid, $onVersion, [
                        'uuid' => $itemUuid,
                        'data' => $data,
                    ], function ($commandBus, $event) use (&$success) {
                        // Callback.
                        $success = true;
                    }));

                    if ($success) {
                        $this->addFlash(
                            'success',
                            $this->translator->trans('Field edited')
                        );

                        return $this->redirectToForm($formUuid);
                    }

                    return $this->errorResponse($formUuid);
                }
            }
        } else {
            return $this->errorResponse($formUuid);
        }

        return $this->render('@forms/Form/form.html.twig', [
            'title' => $title,
            'form' => $form->createView(),
        ]);
    }
@Route("/edit-item/{formUuid}/{onVersion}/{itemUuid}", name="forms_edit_item")

@param Request $request
@param string  $formUuid
@param int     $onVersion
@param string  $itemUuid

@throws \Exception
@return Response