/** * Get content for the widget * * @param Widget $widget * * @return Ambigous <string, unknown, \Victoire\Bundle\CoreBundle\Widget\Managers\mixed, mixed> * @throws \Exception */ public function getWidgetContent(Widget $widget) { //the mode of display of the widget $mode = $widget->getMode(); //the widget must have a mode if ($mode === null) { throw new \Exception('The widget [' . $widget->getId() . '] has no mode.'); } $resolver = $this->widgetContentResolverChain->getResolverForWidget($widget); switch ($mode) { case Widget::MODE_STATIC: $parameters = $resolver->getWidgetStaticContent($widget); break; case Widget::MODE_ENTITY: //get the content of the widget with its entity $parameters = $resolver->getWidgetEntityContent($widget); break; case Widget::MODE_BUSINESS_ENTITY: //get the content of the widget with its entity $parameters = $resolver->getWidgetBusinessEntityContent($widget); break; case Widget::MODE_QUERY: $parameters = $resolver->getWidgetQueryContent($widget); break; default: throw new \Exception('The mode [' . $mode . '] is not supported by the widget manager. Widget ID:[' . $widget->getId() . ']'); } return $parameters; }
/** * render the Widget * @param Widget $widget * @param View $view * * @return widget show */ public function render(Widget $widget, View $view) { //the mode of display of the widget $mode = $widget->getMode(); //if entty is given and it's not the object, retrive it and set the entity for the widget if ($mode == Widget::MODE_BUSINESS_ENTITY && $view instanceof BusinessEntityPage) { $widget->setEntity($view->getBusinessEntity()); } //the templating service $templating = $this->container->get('victoire_templating'); //the content of the widget $parameters = $this->container->get('victoire_widget.widget_content_resolver')->getWidgetContent($widget); //the template displayed is in the widget bundle (with the potential theme) $showView = 'show' . ucfirst($widget->getTheme()); $templateName = $this->container->get('victoire_widget.widget_helper')->getTemplateName($showView, $widget); return $templating->render($templateName, $parameters); }