/** * 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 entity is given and it's not the object, retrieve it and set the entity for the widget if ($mode == Widget::MODE_BUSINESS_ENTITY && $view instanceof BusinessPage) { $widget->setEntity($view->getBusinessEntity()); } elseif ($view instanceof BusinessTemplate) { //We'll try to find a sample entity to mock the widget behavior /** @var EntityManager $entityManager */ $entityManager = $this->container->get('doctrine.orm.entity_manager'); if ($mock = $this->bepHelper->getEntitiesAllowedQueryBuilder($view, $entityManager)->setMaxResults(1)->getQuery()->getOneOrNullResult()) { $widget->setEntity($mock); } } //the templating service $templating = $this->container->get('templating'); //the content of the widget $parameters = $this->container->get('victoire_widget.widget_content_resolver')->getWidgetContent($widget); /* * In some cases, for example, WidgetRender in BusinessEntity mode with magic variables {{entity.id}} transformed * into the real business entity id, then if in the rendered action, we need to flush, it would persist the * modified widget which really uncomfortable ;) */ $this->container->get('doctrine.orm.entity_manager')->refresh($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); }
public function buildReference(View $businessPage, EntityManager $em) { $businessPageReference = null; $businessEntityMetadata = new ClassMetadata(get_class($businessPage->getBusinessEntity())); if ($businessEntityMetadata->name !== 'Victoire\\Bundle\\BlogBundle\\Entity\\Article') { $businessPageReference = parent::buildReference($businessPage, $em); } return $businessPageReference; }
/** * @param View $view * @param mixed $entity * * @return string */ public static function generateViewReferenceId(View $view, $entity = null) { $id = $view->getId(); if ($view instanceof BusinessPage) { $id = $view->getTemplate()->getId(); $entity = $view->getBusinessEntity(); } elseif (!$view instanceof WebViewInterface) { return $view->getId(); } $refId = sprintf('ref_%s', $id); if ($entity) { $refId .= '_' . $entity->getId(); } return $refId; }
/** * 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); }
/** * @param View $view * @param $entity * @return string */ public static function getViewReferenceId(View $view, $entity = null) { if ($view instanceof BusinessEntityPage) { $entity = $view->getBusinessEntity(); } $id = sprintf('ref_%s', $view->getId()); if ($entity) { $id .= '_' . $entity->getId(); } return $id; }