public function run(CantigaController $controller, $id, $customDataGenerator = null) { try { $repository = $this->info->getRepository(); $fetch = $this->fetch; $item = $fetch($repository, $id); $nameProperty = 'get' . ucfirst($this->info->getItemNameProperty()); $name = $item->{$nameProperty}(); $customData = null; if (is_callable($customDataGenerator)) { $customData = $customDataGenerator($item); } $vars = $this->getVars(); $vars['pageTitle'] = $this->info->getPageTitle(); $vars['pageSubtitle'] = $this->info->getPageSubtitle(); $vars['item'] = $item; $vars['name'] = $name; $vars['custom'] = $customData; $vars['indexPage'] = $this->info->getIndexPage(); $vars['infoPage'] = $this->info->getInfoPage(); $vars['insertPage'] = $this->info->getInsertPage(); $vars['editPage'] = $this->info->getEditPage(); $vars['removePage'] = $this->info->getRemovePage(); $controller->breadcrumbs()->link($name, $this->info->getInfoPage(), $this->slugify(['id' => $id])); return $controller->render($this->info->getTemplateLocation() . $this->info->getInfoTemplate(), $vars); } catch (ItemNotFoundException $exception) { return $this->onError($controller, $controller->trans($this->info->getItemNotFoundErrorMessage())); } catch (ModelException $exception) { return $this->onError($controller, $controller->trans($exception->getMessage())); } }
public function handleRequest(CantigaController $ctrl, Request $request) { $answer = $request->query->get('answer', null); if ($answer == 'yes') { $callback = $this->successCallback; $callback(); return $ctrl->redirect($ctrl->generateUrl($this->routeName, $this->routeArgs)); } elseif ($answer == 'no') { return $ctrl->redirect($ctrl->generateUrl($this->routeName, $this->routeArgs)); } else { $successArgs = $this->respondArgs; $cancelArgs = $this->respondArgs; $successArgs['answer'] = 'yes'; $cancelArgs['answer'] = 'no'; return $ctrl->render('CantigaCoreBundle:layout:question.html.twig', array('pageTitle' => $this->title, 'pageSubtitle' => $this->subtitle, 'questionTitle' => $ctrl->trans('Question', [], 'general'), 'question' => $this->question, 'successPath' => $ctrl->generateUrl($this->respondName, $successArgs), 'failurePath' => $ctrl->generateUrl($this->respondName, $cancelArgs), 'successBtn' => $ctrl->trans('Indeed', [], 'general'), 'failureBtn' => $ctrl->trans('Cancel', [], 'general'))); } }