public function createWidget($mode, $type, $slotId, View $view, $entity, $position, $widgetReference, $quantum)
    {
        //services
        $formErrorHelper = $this->formErrorHelper;
        $request = $this->getRequest();

        if ($view instanceof VirtualBusinessPage) {
            $this->virtualToBpTransformer->transform($view);
        }
        //create a new widget
        $widget = $this->widgetHelper->newWidgetInstance($type, $view, $slotId, $mode);

        $form = $this->widgetFormBuilder->callBuildFormSwitchParameters($widget, $view, $entity, $position, $widgetReference, $slotId, $quantum);

        $noValidate = $request->query->get('novalidate', false);

        $form->handleRequest($request);
        if ($noValidate === false && $form->isValid()) {
            if (!$view->getId()) {
                //create a view for the business entity instance if we are currently on a virtual one
                $this->entityManager->persist($view);
            }

            //get the widget from the form
            $widget = $form->getData();

            //update fields of the widget
            $widget->setBusinessEntityId($entity);

            //persist the widget
            $this->entityManager->persist($widget);
            $this->entityManager->flush();

            $this->widgetMapManager->insert($widget, $view, $slotId, $position, $widgetReference);

            $this->entityManager->persist($view);
            $this->entityManager->flush();

            $widget->setCurrentView($view);

            $event = new WidgetFlushedEvent($widget);
            $this->eventDispatcher->dispatch(VictoireCmsEvents::WIDGET_POST_FLUSH, $event);
            $this->eventDispatcher->dispatch(VictoireCmsEvents::WIDGET_POST_FLUSH.'_'.strtoupper($type), $event);

            $this->widgetMapBuilder->build($view);

            //get the html for the widget
            $htmlWidget = $this->widgetRenderer->renderContainer($widget, $view);

            $response = [
                'success'  => true,
                'widgetId' => $widget->getId(),
                'html'     => $htmlWidget,
            ];
        } else {
            //get the errors as a string
            $response = [
                'success' => false,
                'message' => $noValidate === false ? $formErrorHelper->getRecursiveReadableErrors($form) : null,
                'html'    => $this->widgetFormBuilder->renderNewForm($form, $widget, $slotId, $view, $quantum, $entity),
            ];
        }

        return $response;
    }