Exemplo n.º 1
0
 /**
  * Build a route for the given admin and action, with the provided params
  *
  * This method will first attempt to find a custom Route (like "YourCustomAdminBundle:Section:index")
  * and if it does not work
  *
  * @param \Leapt\AdminBundle\Admin\AdminInterface $admin
  * @param string $action
  * @param array $params
  * @param bool $defaultRoute
  * @return \Symfony\Component\Routing\Route
  */
 public function getRoute(AdminInterface $admin, $action, $params = array(), $defaultRoute = false)
 {
     $defaults = array();
     $pattern = '/' . $admin->getAlias();
     if (!$defaultRoute) {
         $pattern .= '/' . $action;
     }
     foreach ($params as $paramKey => $paramValue) {
         if (is_int($paramKey)) {
             $paramName = $paramValue;
         } else {
             $paramName = $paramKey;
             $defaults[$paramName] = $paramValue;
         }
         $pattern .= '/{' . $paramName . '}';
     }
     preg_match('/(?:[A-Z](?:[A-Za-z0-9])+\\\\)*(?:)[A-Z](?:[A-Za-z0-9])+Bundle/', get_class($admin), $matches);
     $bundle = implode('', explode('\\', $matches[0]));
     $section = StringUtil::camelize($admin->getAlias());
     $controller = $bundle . ':' . $section . ':' . $action;
     try {
         $controller = $this->parser->parse($controller);
     } catch (\InvalidArgumentException $e) {
         $controller = $this->parser->parse('LeaptAdminBundle:Content:' . $action);
     }
     $defaults = array_merge(array('_controller' => $controller, 'alias' => $admin->getAlias()), $defaults);
     return new Route($pattern, $defaults);
 }
Exemplo n.º 2
0
 /**
  * Handle standard delete (no modal)
  *
  * @param Request $request
  * @param ContentAdmin $admin
  * @param $entity
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function delete(Request $request, ContentAdmin $admin, $entity)
 {
     if ($entity === null) {
         return $this->renderError('error.content.notfound', 404);
     }
     if ($request->isMethod('post')) {
         try {
             $admin->deleteEntity($entity);
             $this->buildEntityFlash('success', 'content.delete.flash.success', $admin, $entity);
         } catch (\Exception $e) {
             $this->buildEntityFlash('error', 'content.delete.flash.error', $admin, $entity);
             $this->get('logger')->addError($e->getMessage());
         }
         return $this->redirect($this->getRoutingHelper()->generateUrl($admin, 'index'));
     }
     return $this->render('LeaptAdminBundle:' . StringUtil::camelize($admin->getAlias()) . ':modalDelete.html.twig', array('admin' => $admin, 'entity' => $entity));
 }
Exemplo n.º 3
0
 /**
  * @param $string
  * @return string
  */
 public function camelize($string)
 {
     return StringUtil::camelize($string);
 }