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
423278
public function run($widget)
    {
        $category  = Category::query()->findOrNew($widget->param('category_id'));
        $limit     = (int) $widget->param('limit') ?: 5;
        $direction = 'desc';
        if ($category->exists) {
            $articles = $category->articles()->isNotPage()->published()->orderBy('hits', $direction)->take($limit)->get();
        } else {
            $articles = Article::query()->isNotPage()->published()->orderBy('hits', $direction)->take($limit)->get();
        }

        return view($widget->present()->template(), [
            'config'   => $this->config,
            'widget'   => $widget,
            'category' => $category,
            'articles' => $articles,
        ]);
    }
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;
    }
1065678
private function generateWidget(Widget $widget)
    {
        $environment   = $this->getEnvironment();
        $inputProvider = $environment->getInputProvider();

        if (('select' !== $inputProvider->getParameter('act'))
            && ('edit' !== $inputProvider->getParameter('mode'))
        ) {
            echo $widget->generate();

            return;
        }

        $model = $environment->getDataProvider()->getEmptyModel();
        $model->setProperty($widget->name, $widget->value);

        echo (new ContaoWidgetManager($environment, $model))->getWidget($inputProvider->getValue('name'))->generate();
    }
1103310
protected function addWidget(SharpWidget $widget)
    {
        $this->widgets[] = $widget;
        $this->dashboardBuilt = false;

        return $this;
    }
168038
public function getView()
    {
        $controller = $this->getActionController();
        if (null === $controller) {
            $controller = $this->getFrontController();
        }

        return $controller->view;
    }
29576
private function getWidgetPath($widget, $moduleName = '', $isModule = false)
    {
        $modulePath = 'Views';
        if ($isModule) {
            $modulePath = $this->moduleDir.DS.$moduleName.DS.'Views';
        }

        return $this->paths['app.path'].DS.$modulePath.DS.$widget.'.view.php';
    }
27601
public function getViewWidgetViewHelper()
    {
        $config = $this->serviceLocator
                       ->get( 'Config' );

        return View\Helper\ViewWidget::factory(
            $this->serviceLocator,
            empty( $config['view_widgets'] ) ? array() : $config['view_widgets']
        );
    }
792649
public function getView()
    {
        if (view()->exists(static::$view)) {
            return static::$view;
        }

        if (view()->exists('admin.widgets.'.static::safeTitle().'.widget')) {
            return 'admin.widgets.'.static::safeTitle().'.widget';
        }

        if (view()->exists('admin.widgets.'.static::safeTitle())) {
            return 'admin.widgets.'.static::safeTitle();
        }

        if (view()->exists('admin.'.static::safeTitle())) {
            return 'admin.'.static::safeTitle();
        }

        if (view()->exists('flare::'.self::$view)) {
            return 'flare::'.self::$view;
        }
    }
1238156
public function render(renderable $widget) {
        $classname = get_class($widget);
        // Strip namespaces.
        $classname = preg_replace('/^.*\\\/', '', $classname);
        // Keep a copy at this point, we may need to look for a deprecated method.
        $deprecatedmethod = 'render_'.$classname;
        // Remove _renderable suffixes
        $classname = preg_replace('/_renderable$/', '', $classname);

        $rendermethod = 'render_'.$classname;
        if (method_exists($this, $rendermethod)) {
            return $this->$rendermethod($widget);
        }
        if ($rendermethod !== $deprecatedmethod && method_exists($this, $deprecatedmethod)) {
            // This is exactly where we don't want to be.
            // If you have arrived here you have a renderable component within your plugin that has the name
            // blah_renderable, and you have a render method render_blah_renderable on your plugin.
            // In 2.8 we revamped output, as part of this change we changed slightly how renderables got rendered
            // and the _renderable suffix now gets removed when looking for a render method.
            // You need to change your renderers render_blah_renderable to render_blah.
            // Until you do this it will not be possible for a theme to override the renderer to override your method.
            // Please do it ASAP.
            static $debugged = array();
            if (!isset($debugged[$deprecatedmethod])) {
                debugging(sprintf('Deprecated call. Please rename your renderables render method from %s to %s.',
                    $deprecatedmethod, $rendermethod), DEBUG_DEVELOPER);
                $debugged[$deprecatedmethod] = true;
            }
            return $this->$deprecatedmethod($widget);
        }
        // pass to core renderer if method not found here
        return $this->output->render($widget);
    }
1115011
public function parameters($id, $widget)
    {
        $widget    = Widget::withoutGlobalScope('menu_assignment')->findOrNew($widget);
        $extension = $this->repository->findOrFail($id);
        $formView  = $extension->param('form');

        if (view()->exists($formView)) {
            return view($formView, compact('widget'));
        }

        return view('widgets.partials.none');
    }
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;
    }
74635
public function getWidgetData(AbstractWidget $widget)
    {
        $widgetViews = array(
            'views' => array('view' => $this->getView($widget, $widget->getWidgetType())),
        );

        return $widget->getCommonData() + $widgetViews + $widget->getData();
    }
189379
public function cmsWidgetUnlinkAction($widgetId, $view)
    {
        $viewReference = $this->viewReferenceRepository->getOneReferenceByParameters(
            ['viewId' => $view->getId()]
        );
        if (!$viewReference && $view->getId() != '') {
            $viewReference = new ViewReference($view->getId());
        } elseif ($view instanceof VirtualBusinessPage) {
            $viewReference = new ViewReference($view->getTemplate()->getId());
        }

        $view->setReference($viewReference);

        return $this->widgetRenderer->renderUnlinkActionByWidgetId($widgetId, $view);
    }
853156
public function render(renderable $widget) {

        $namespacedclassname = get_class($widget);
        $plainclassname = preg_replace('/^.*\\\/', '', $namespacedclassname);
        $rendermethod = 'render_'.$plainclassname;

        if (method_exists($this, $rendermethod)) {
            // Explicit rendering method exists, fall back to the default behaviour.
            return parent::render($widget);
        }

        $interfaces = class_implements($namespacedclassname);

        if (isset($interfaces['templatable'])) {
            // Default implementation of template-based rendering.
            $data = $widget->export_for_template($this);
            return parent::render_from_template('tool_policy/'.$plainclassname, $data);

        } else {
            return parent::render($widget);
        }
    }
1342691
public function renderForm(Form $form, Widget $widget, $entity = null)
    {
        //the template displayed is in the widget bundle
        $templateName = $this->container->get('victoire_widget.widget_helper')->getTemplateName('edit', $widget);

        return $this->container->get('templating')->render(
            $templateName,
            [
                'widget' => $widget,
                'slot'   => $widget->getWidgetMap()->getSlot(),
                'view'   => $this->container->get('victoire_core.current_view')->getCurrentView(),
                'form'   => $form->createView(),
                'id'     => $widget->getId(),
                'entity' => $entity,
            ]
        );
    }
591065
public function hasWidget($widget)
    {
        if ($widget instanceof Model) {
            $widget = $widget->id;
        }

        return $this->widgets()->where('widget_id', $widget)->exists();
    }
32159
public function addWidget($widget)
    {
        $this->widgets->add($widget); 
        $this->layoutWidget($widget);
        return $this;
    }