Treat this method as a controller action.
Return view() or other content to display.

@param \Yajra\CMS\Entities\Widget $widget
@return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
19986
public function run($widget)
    {
        $navigation = app('navigation')->findOrFail($widget->param('navigation_id'));

        if (! $navigation->menus()->count()) {
            return ''; // return empty string if navigation does not have menu items
        }

        return view($widget->present()->template(), [
            'config' => $this->config,
            'widget' => $widget,
            'menu'   => 'menu_' . $navigation->type,
        ]);
    }
1151771
private function renderTemplate($viewType, array $templateParams = [], $widget = false)
    {
        $template = $widget && !empty($this->configuration['view'][$viewType]['template'])
            ? $this->configuration['view'][$viewType]['template']
            : sprintf('DarvinAdminBundle:Crud%s:%s.html.twig', $widget ? '/widget' : '', $viewType);

        return $this->renderView($template, $templateParams);
    }
529531
public function renderNewForm($form, $widget, $slot, View $view, $quantum = null, $entity = null)
    {
        //the template displayed is in the widget bundle
        $templateName = $this->container->get('victoire_widget.widget_helper')->getTemplateName('new', $widget);

        return $this->container->get('templating')->render(
            $templateName,
            [
                'widget'  => $widget,
                'form'    => $form->createView(),
                'slot'    => $slot,
                'entity'  => $entity,
                'view'    => $view,
                'quantum' => $quantum,
            ]
        );
    }
1197184
public function renderRequestForm($widget = true, FormInterface $form = null)
    {
        if (empty($form)) {
            $form = $this->passwordResetTokenFormFactory->createRequestForm();
        }

        $template = $widget
            ? 'DarvinUserBundle:PasswordResetToken/widget/request:form.html.twig'
            : 'DarvinUserBundle:PasswordResetToken:request.html.twig';

        return $this->templating->render($template, [
            'form' => $form->createView(),
        ]);
    }
467734
public function index(WidgetContractInterface $widget, $key = null)
    {
        $widget->query = request('term');
        $widget->key = $key;

        if (! is_null($key)) {
            return response()->json($widget->handler());
        }

        return response()->json([
            'results' => $widget->handler(),
        ]);
    }
919130
public function publish(Widget $widget)
    {
        $widget->published = ! $widget->published;
        $widget->save();

        return $this->notifySuccess(trans('cms::widget.update.publish', [
                'task' => $widget->published ? 'published' : 'unpublished',
            ])
        );
    }
311384
public function view(string $id)
    {
        $dashboard = $this->Dashboards->get($id, [
            'contain' => [
                'Roles',
                'Widgets'
            ]
        ]);

        $query = $this->Dashboards->getUserDashboards($this->Auth->user());
        /**
         * @var \Search\Model\Table\WidgetsTable $widgetsTable
         */
        $widgetsTable = TableRegistry::get('Search.Widgets');

        $userDashboards = $query->find('list')->toArray();
        if (!array_key_exists($dashboard->id, $userDashboards)) {
            throw new ForbiddenException();
        }

        $widgets = [];

        foreach ($dashboard->get('widgets') as $k => $item) {
            $opts = $widgetsTable->getWidgetOptions($item);

            $x = (int)$opts['x'];
            $y = (int)$opts['y'];

            if (isset($widgets[$y][$x])) {
                $widgets[$y][] = $item;
            } else {
                $widgets[$y][$x] = $item;
            }
        }

        ksort($widgets);

        foreach ($widgets as $k => $items) {
            if (count($items) < 2) {
                continue;
            }

            usort($widgets[$k], function ($a, $b) {
                $opts_a = json_decode($a->widget_options, true);
                $opts_b = json_decode($b->widget_options, true);

                $x_a = (int)$opts_a['x'];
                $x_b = (int)$opts_b['x'];

                if ($x_a == $x_b) {
                    return 0;
                }

                return ($x_a < $x_b) ? -1 : 1;
            });
        }

        $this->set('dashboardWidgets', $widgets);
        $this->set('columns', Configure::readOrFail('Search.dashboard.columns'));
        $this->set('user', $this->Auth->user());
        $this->set('dashboard', $dashboard);
        $this->set('_serialize', ['dashboard']);
    }
168038
public function getView()
    {
        $controller = $this->getActionController();
        if (null === $controller) {
            $controller = $this->getFrontController();
        }

        return $controller->view;
    }
38089
public function form(Classes\SCore\Base\Widget $Widget, array $args = []): Classes\SCore\WidgetForm
    {
        return $this->App->Di->get(Classes\SCore\WidgetForm::class, compact('Widget', 'args'));
    }
68726
public function editWidget(Widget $widget, View $currentView, $quantum = null, $businessEntityId = null, $widgetMode = Widget::MODE_STATIC)
    {
        /** @var BusinessEntity[] $classes */
        $classes = $this->cacheReader->getBusinessClassesForWidget($widget);
        $request = $this->getRequest();

        //the id of the edited widget
        //a new widget might be created in the case of a legacy
        $initialWidgetId = $widget->getId();

        //the type of method used
        $requestMethod = $request->getMethod();

        //if the form is posted
        if ($requestMethod === 'POST') {
            //the widget view
            $widgetView = $widget->getWidgetMap()->getView();
            if ($currentView instanceof VirtualBusinessPage) {
                $this->virtualToBpTransformer->transform($currentView);
            }

            //we only copy the widget if the view of the widget is not the current view
            if ($widgetView !== $currentView) {
                $widget = $this->overwriteWidget($currentView, $widget);
            }
            if ($businessEntityId !== null) {
                $form = $this->widgetFormBuilder->buildForm($widget, $currentView, $businessEntityId, $classes[$businessEntityId]->getClass(), $widgetMode, null, null, null, $quantum);
            } else {
                $form = $this->widgetFormBuilder->buildForm($widget, $currentView, null, null, $widgetMode, null, null, null, $quantum);
            }

            $noValidate = $request->query->get('novalidate', false);
            $form->handleRequest($request);
            if ($noValidate === false && $form->isValid()) {
                $widget->setBusinessEntityId($businessEntityId);

                //force cache invalidation
                $widget->setUpdatedAt(new \DateTime());
                $this->entityManager->persist($widget);

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

                $response = [
                    'view'        => $currentView,
                    'success'     => true,
                    'html'        => $this->widgetRenderer->render($widget, $currentView),
                    'widgetId'    => $initialWidgetId,
                    'slot'        => $widget->getWidgetMap()->getSlot(),
                    'viewCssHash' => $currentView->getCssHash(),
                ];
            } else {
                $formErrorHelper = $this->formErrorHelper;
                //Return a message for developer in console and form view in order to refresh view and show form errors
                $response = [
                    'success'  => false,
                    'widgetId' => $initialWidgetId,
                    'slot'     => $widget->getWidgetMap()->getSlot(),
                    'message'  => $noValidate === false ? $formErrorHelper->getRecursiveReadableErrors($form) : null,
                    'html'     => $this->widgetFormBuilder->renderForm($form, $widget, $businessEntityId),
                ];
            }
        } else {
            $widgets = $widget->getWidgetMap()->getWidgets();
            $forms = $this->widgetFormBuilder->renderNewQuantumForms($widget->getSlot(), $currentView, $widgets, $widget, $classes);

            $response = [
                'success' => true,
                'html'    => $this->templating->render(
                    'VictoireCoreBundle:Widget:Form/edit.html.twig',
                    [
                        'view'            => $currentView,
                        'slot'            => $widget->getWidgetMap()->getSlot(),
                        'position'        => $widget->getWidgetMap()->getPosition(),
                        'parentWidgetMap' => $widget->getWidgetMap()->getParent() ? $widget->getWidgetMap()->getParent()->getId() : null,
                        'classes'         => $classes,
                        'forms'           => $forms,
                        'widgets'         => $widgets,
                        'widget'          => $widget,
                    ]
                ),
            ];
        }

        return $response;
    }
1257406
protected function getContent()
    {
        $widget = (object) $this->widget->execute();
        $widget->cache_key = $this->widget->cacheKeys();

        return trim(preg_replace('/(\s|\r|\n)+</', '<',
            view($this->widget->template(), compact('widget'))->render()
        ));

        // Debug function if App has error:
        // `Cannot end a section without first starting one.`
        return view($this->widget->template(), compact('widget'));
    }
978637
protected function ___attainWidgetInstance($widget)
    {
        /** @var $widgetManager WidgetManager */
        $widgetManager = $this->sm->get('yimaWidgetator.WidgetManager');

        $options = [];
        if (is_array($widget)) {
            $wArg    = $widget;
            $widget  = $wArg['widget'];
            $options = (isset($wArg['params'])) ? $wArg['params'] : $options;
        }

        $instance = $widgetManager->get($widget, $options);

        return $instance;
    }
1028717
public function overwriteWidget(View $view, Widget $widget)
    {
        $widgetCopy = $this->cloneEntity($widget);
        $originalWidgetMap = $widget->getWidgetMap();
        $this->widgetMapManager->overwrite($view, $originalWidgetMap, $widgetCopy);

        return $widgetCopy;
    }
724563
public function getExtraCssClass(Widget $widget)
    {
        $cssClass = 'v-widget--'.strtolower($this->container->get('victoire_widget.widget_helper')->getWidgetName($widget));

        return $cssClass;
    }
1328655
private function generateHtml($widget, ...$args)
    {
        // Everything inside this function is executed only when the cache is not available.
        $expensivePhpCode = function () use ($widget, $args) {
            $this->makeDataForView($widget, $args);

            // render the template with the resulting data.
            return $this->renderTemplate($widget);
        };

        // We first try to get the output from the cache before trying to run the expensive $expensivePhpCode...
        if ($this->_policies->widgetShouldUseCache()) {
            return app(Cache::class)->cacheResult($args, $expensivePhpCode, $widget);
        }

        return $expensivePhpCode();
    }
121581
public function newAction(Request $request, $widget = false)
    {
        $this->checkIfUserHasPermission(Permission::CREATE_DELETE);

        list($parentEntity, $association) = $this->getParentEntityDefinition($request);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        $isXmlHttpRequest = $request->isXmlHttpRequest();

        if ($isXmlHttpRequest) {
            $widget = true;
        }

        $entityClass = $this->entityClass;
        $entity = new $entityClass();

        if ($this->meta->hasParent()) {
            $this->getPropertyAccessor()->setValue($entity, $association, $parentEntity);
        }
        if ($this->getTranslationJoiner()->isTranslatable($entityClass)) {
            $this->getTranslationsInitializer()->initializeTranslations($entity, $this->getParameter('darvin_admin.locales'));
        }

        $this->getNewActionFilterFormHandler()->handleForm($entity, $request);

        $form = $this->getAdminFormFactory()->createEntityForm(
            $this->meta,
            $entity,
            'new',
            $this->getAdminRouter()->generate($entity, $entityClass, AdminRouter::TYPE_NEW),
            $widget ? [AdminFormFactory::SUBMIT_INDEX] : $this->getEntityFormSubmitButtons()
        )->handleRequest($request);

        if (!$form->isSubmitted()) {
            return new Response($this->renderNewTemplate($widget, $form, $parentEntity));
        }

        $success = $form->isValid();

        if ($success) {
            $em = $this->getEntityManager();
            $em->persist($entity);
            $em->flush();

            $this->getEventDispatcher()->dispatch(CrudEvents::CREATED, new CreatedEvent($this->getUser(), $entity));

            $html = '';
            $message = $this->meta->getBaseTranslationPrefix().'action.new.success';
        } else {
            $html = $this->renderNewTemplate($widget, $form, $parentEntity);
            $message = FlashNotifierInterface::MESSAGE_FORM_ERROR;
        }
        if ($isXmlHttpRequest) {
            return new AjaxResponse($html, $success, $message, [], $success ? '' : null);
        }

        $this->getFlashNotifier()->done($success, $message);

        return $success
            ? $this->successRedirect($form, $entity)
            : new Response($this->renderNewTemplate($widget, $form, $parentEntity));
    }
591065
public function hasWidget($widget)
    {
        if ($widget instanceof Model) {
            $widget = $widget->id;
        }

        return $this->widgets()->where('widget_id', $widget)->exists();
    }