Create a widget.

@param string $mode
@param string $type
@param string $slotId
@param View   $view
@param string $entity
@param string $type

@throws \Exception

@return Template
427142
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;
    }
212508
public function create($type)
    {
        $twigEngine = $this->getTwigEngine();
        if (!$twigEngine) {
            throw new \Exception('Twig Engine not found.  Please see https://github.com/mmucklo/DtcGridBundle/README.md for instructions.');
        }
        switch ($type) {
            case 'datatables':
                $renderer = new DataTablesRenderer($this->twigEngine, $this->router);
                break;
            case 'jq_grid':
                $renderer = new JQGridRenderer($this->twigEngine, $this->router);
                break;
            case 'table':
                $renderer = new TableGridRenderer($this->twigEngine, $this->router);
                break;
            default:
                throw new \Exception("No renderer for type '$type''");
        }

        if (method_exists($renderer, 'setThemeCss')) {
            $renderer->setThemeCss($this->themeCss);
        }

        if (method_exists($renderer, 'setThemeJs')) {
            $renderer->setThemeJs($this->themeJs);
        }

        if (method_exists($renderer, 'setJQuery')) {
            $renderer->setJQuery($this->jQuery);
        }

        if (method_exists($renderer, 'setPurl')) {
            $renderer->setPurl($this->purl);
        }

        if (method_exists($renderer, 'setPageDivStyle')) {
            $renderer->setPageDivStyle($this->pageDivStyle);
        }

        if (method_exists($renderer, 'setJqGridCss')) {
            $renderer->setJqGridCss($this->jqGridCss);
        }

        if (method_exists($renderer, 'setJqGridJs')) {
            $renderer->setJqGridJs($this->jqGridJs);
        }

        if (method_exists($renderer, 'setDataTablesCss')) {
            $renderer->setDataTablesCss($this->dataTablesCss);
        }

        if (method_exists($renderer, 'setDataTablesJs')) {
            $renderer->setDataTablesJs($this->dataTablesJs);
        }

        if (method_exists($renderer, 'setDatatablesClass') && $this->dataTablesClass) {
            $renderer->setDatatablesClass($this->dataTablesClass);
        }

        return $renderer;
    }
1046500
public static function create($template = null, $action = null, $method = 'POST', $encType = null) {

		return new static($template, $action, $method, $encType);

	}
92985
private function checkParam(string $type, int $mode) {
        WebAclRule::checkRoleType($type);
        WebAclRule::checkMode($mode);
        if ($this->res->getAclUrl() === '') {
            throw new NotFound();
        }
    }
810974
public function createPair($domain, $type, $protocol)
    {
        $ret = @socket_create_pair($domain, $type, $protocol, $pair);
        if ($ret === false) {
            throw Exception::createFromGlobalSocketOperation('Unable to create pair of sockets');
        }
        return array(new Socket($pair[0]), new Socket($pair[1]));
    }
62132
public function createBlockAction(Request $request, $type)
    {
        $entity = new Block();
        $entity->setType($type);
        $form = $this->createBlockCreateForm($entity);
        $form->handleRequest($request);

        $availableLangs = $this->container->getParameter('flowcode_page.available_languages');

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $page = $entity->getPage();
            foreach ($availableLangs as $key => $value) {
                $entityLang = new Block();
                $entityLang->setName($entity->getName());
                $entityLang->setLang($key);
                $entityLang->setContent($entity->getContent());
                $entityLang->setPage($entity->getPage());
                $entityLang->setType($type);
                $em->persist($entityLang);
            }


            $em->flush();

            return $this->redirect($this->generateUrl('admin_page_show', array('id' => $page->getId())));
        }

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
510826
public function createAndSubmitForm($type, $data = null, callable $validCallback = null)
    {
        $form = $this->createForm($type, $data);

        if ($this->isPost()) {
            $form->handleRequest($this->getRequest());

            if ($form->isValid()) {
                if ($validCallback) {
                    $response = $validCallback($form->getData(), $form);

                    if($response instanceof Response)

                        return $response;
                }
            }
        }

        return $form->createView();
    }
1019039
public function widget($module, $controller = 'index', $action = 'index', array $params = [])
    {
        return \Mmi\Mvc\ActionHelper::getInstance()->action((new \Mmi\Http\Request($params))
                ->setModuleName($module)
                ->setControllerName($controller)
                ->setActionName($action));
    }
41711
public function postAction(Request $request, User $loggedUser, $type)
    {
        $this->checkPortfolioToolAccess($loggedUser);

        $widgetManager = $this->getWidgetsManager();

        try {
            $newWidget = $widgetManager->getNewDataWidget($type, $loggedUser);
            $data = $widgetManager->handle($newWidget, $type, $request->request->all(), $this->get('kernel')->getEnvironment());
            $statusCode = Response::HTTP_CREATED;
        } catch (\Exception $exception) {
            $data = [];
            $statusCode = Response::HTTP_INTERNAL_SERVER_ERROR;
        }

        $response = new JsonResponse();
        $response
            ->setData($data)
            ->setStatusCode($statusCode);

        return $response;
    }
40143
public function render($type = 'html', $template = null)
    {
        if (!$this->isTableInit()) {
            $this->initializable();
        }

        if ($type == 'html') {
            return $this->getRender()->renderTableAsHtml();
        } elseif ($type == 'dataTableAjaxInit') {
            return $this->getRender()->renderDataTableAjaxInit();
        } elseif ($type == 'dataTableJson') {
            return $this->getRender()->renderDataTableJson();
        } elseif ($type == 'custom') {
            return $this->getRender()->renderCustom($template);
        } elseif ($type == 'newDataTableJson') {
            return $this->getRender()->renderNewDataTableJson();
        } else {
            throw new Exception\InvalidArgumentException(sprintf('Invalid type %s', $type));
        }

    }
636249
protected function createSocket($type, $mode, $dsn = null, $options = array())
    {
        $context = $this->getContext();
        $socket = new Socket($context, $type);

        $options = $this->options + $options;
        foreach ($options as $key => $value) {
            $socket->setSockOpt($key, $value);
        }

        $this->connect($socket, $mode, $dsn);

        return $socket;
    }
158187
public function createAction()
	{
		$this->isPostRequest();

		$type = $this->getRequestParameter('type');

		$page = null;

		switch ($type) {
			case Entity::APPLICATION_DISCR:
				$page = new ApplicationPage(
						$this->getRequestParameter('application_id')
				);
				break;
			case Entity::PAGE_DISCR:
				$page = new Page();
				break;
			default:
				throw new \InvalidArgumentException(sprintf('Unknown page type [%s]', $type));
		}

		$localeId = $this->getCurrentLocale()->getId();

		$localization = Localization::factory($page, $localeId);
		/* @var $localization PageLocalization */

		if (! $localization instanceof PageLocalization) {
			throw new \UnexpectedValueException(sprintf(
					'Expecting created localization to be instance of PageLocalization, [%s] received.',
					get_class($localization)
			));
		}

		$templateId = $this->getRequestParameter('template');
		
		$template = $this->getEntityManager()
				->find(Template::CN(), $templateId);
		/* @var $template Template */

		if ($template === null) {
			throw new CmsException(null, 'Template not specified or found.');
		}

		$templateLocalization = $template->getLocalization($localeId);

		if ($templateLocalization === null) {
			throw new \InvalidArgumentException(
					"Specified template has no localization for [{$localeId}] locale."
			);
		}

		$localization->setTemplate($template);

		// copy values from template
		$localization->setIncludedInSearch($templateLocalization->isIncludedInSearch());
		$localization->setVisibleInMenu($templateLocalization->isVisibleInMenu());
		$localization->setVisibleInSitemap($templateLocalization->isVisibleInSitemap());

		$title = trim($this->getRequestParameter('title', ''));

		if (empty($title)) {
			throw new CmsException(null, 'Page title cannot be empty.');
		}
		
		$localization->setTitle($title);

		$parentLocalization = $pathPart
				= null;

		$parentLocalizationId = $this->getRequestParameter('parent_id');
		
		if (! empty($parentLocalizationId)) {

			$parentLocalization = $this->getEntityManager()
					->find(Localization::CN(), $parentLocalizationId);

			if ($parentLocalization === null) {
				throw new CmsException(null, sprintf(
						'Specified parent page [%s] not found.',
						$parentLocalizationId
				));
			}

			$pathPart = trim($this->getRequestParameter('path'));

			// path part cannot be empty for non-root pages.
			if (empty($pathPart)) {
				throw new CmsException(null, 'Page path can not be empty.');
			}
		}

		if ($parentLocalization && $pathPart) {
			$localization->setPathPart($pathPart);
		} else {
			$rootPath = $localization->getPathEntity();
			$rootPath->setPath('');
			$localization->setPathPart('');
		}

		$entityManager = $this->getEntityManager();

		$entityManager->transactional(function (EntityManager $entityManager) use ($page, $localization, $parentLocalization) {

			$this->lockNestedSet($page);

			$entityManager->persist($page);
			$entityManager->persist($localization);

			if ($parentLocalization) {
				$page->moveAsLastChildOf($parentLocalization->getMaster());
			}

			$this->unlockNestedSet($page);
		});

		return new SupraJsonResponse($this->loadNodeMainData($localization));
	}
1116384
protected function createView($action, $type)
    {
        $view = (new \Stack\View)->byName($type, 'Model_' . ucfirst($action));
        $view['controller'] = $type;
        $view['controllerAction'] = $action;
        return $view;
    }
354369
protected function loadTemplate(string $mode)
    {
        if ($mode == 'create') { // create mode
            $tplPath = sprintf(MODULE_VIEWS, $this->module . '/' . $this->division);
            $tplName = $tplPath . 'edit.php';
            $this->template->load($tplName);
        }
    }
360447
public static function create(string $type): \Menu\Type\TypeInterface
    {
        if (empty($type)) {
            throw new InvalidArgumentException('Type must be a non-empty string.');
        }

        $className = __NAMESPACE__ . '\\Types\\' . Inflector::camelize($type);
        if (!class_exists($className)) {
            throw new RuntimeException('Class [' . $className . '] does not exist.');
        }

        $interface = __NAMESPACE__ . '\\' . static::INTERFACE_CLASS;
        if (!in_array($interface, class_implements($className))) {
            throw new RuntimeException('Class [' . $className . '] must implement [' . $interface . '] interface.');
        }

        return new $className();
    }
649522
public function insert(Widget $widget, View $view, $slotId, $position, $widgetReference)
    {
        $quantum = $this->em->getRepository('VictoireWidgetMapBundle:WidgetMap')->findOneBy([
            'view'     => $view,
            'slot'     => $slotId,
            'position' => $position,
            'parent'   => $widgetReference,
            'action'   => [
                WidgetMap::ACTION_CREATE,
                WidgetMap::ACTION_OVERWRITE,
            ],
        ]);

        if ($quantum) {
            $widget->setWidgetMap($quantum);
            $view->addWidgetMap($quantum);
        } else {
            $parent = null;
            if ($widgetReference) {
                $parent = $this->em->getRepository('VictoireWidgetMapBundle:WidgetMap')->find($widgetReference);
            }
            //create the new widget map
            $widgetMapEntry = new WidgetMap();
            $widgetMapEntry->setAction(WidgetMap::ACTION_CREATE);
            $widgetMapEntry->setSlot($slotId);
            $widgetMapEntry->setPosition($position);
            $widgetMapEntry->setParent($parent);
            $widget->setWidgetMap($widgetMapEntry);

            $view->addWidgetMap($widgetMapEntry);
        }
    }
151729
public function editWidgetStyle(Request $request, Widget $widget, View $view, $viewReference = null, $activeQuantum = null)
    {
        if ($request->getMethod() === 'POST') {
            $form = $this->widgetFormBuilder->buildWidgetStyleForm($widget, $viewReference, $activeQuantum);
            $form->handleRequest($request);

            if ($request->query->get('novalidate', false) === false && $form->isValid()) {
                if ($form->has('deleteBackground') && $form->get('deleteBackground')->getData()) {
                    // @todo: dynamic responsive key
                    foreach (['', 'XS', 'SM', 'MD', 'LG'] as $key) {
                        $widget->{'deleteBackground'.$key}();
                    }
                }
                $this->entityManager->flush();
                $params = [
                    'view'        => $view,
                    'success'     => true,
                    'html'        => $this->widgetRenderer->render($widget, $view),
                    'widgetId'    => $widget->getId(),
                    'viewCssHash' => $view->getCssHash(),
                ];
            } else {
                $template = ($request->query->get('novalidate', false) !== false) ? 'VictoireCoreBundle:Widget/Form/stylize:form.html.twig' : 'VictoireCoreBundle:Widget/Form:stylize.html.twig';
                $params = [
                    'success' => !$form->isSubmitted(),
                    'html'    => $this->templating->render(
                        $template,
                        [
                            'view'                     => $view,
                            'form'                     => $form->createView(),
                            'widget'                   => $widget,
                            'victoire_twig_responsive' => $this->twigResponsive,
                        ]
                    ),
                ];
            }
        } else {
            $widgets = $widget->getWidgetMap()->getWidgets();
            $forms = $this->widgetFormBuilder->renderQuantumStyleForms($viewReference, $widgets, $widget);
            $params = [
                'html' => $this->templating->render(
                    'VictoireCoreBundle:Widget/Form:stylize.html.twig',
                    [
                        'view'                     => $view,
                        'forms'                    => $forms,
                        'widget'                   => $widget,
                        'widgets'                  => $widgets,
                        'victoire_twig_responsive' => $this->twigResponsive,
                    ]
                ),
            ];
        }

        return new JsonResponse($params);
    }