/**
  * 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);
 }
Beispiel #2
0
 /**
  * @param $fileEntity
  * @param array $fileConfig
  * @return string
  */
 private function generateFileName($fileEntity, array $fileConfig)
 {
     $path = $fileConfig['path'];
     if (null !== $fileConfig['pathCallback']) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $path = $accessor->getValue($fileEntity, $fileConfig['pathCallback']);
     }
     $path .= '/';
     $ext = '.' . $fileConfig['property']->getValue($fileEntity)->guessExtension();
     if ($fileConfig['nameCallback'] !== null) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $filename = $accessor->getValue($fileEntity, $fileConfig['nameCallback']);
         $filename = StringUtil::slugify($filename);
         /*
          * Here we add a uniqid at the end of the filename to avoid any cache issue
          */
         $filename .= '-' . uniqid();
     } else {
         $filename = uniqid();
     }
     return $path . $filename . $ext;
 }
 /**
  * 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));
 }
Beispiel #4
0
 /**
  * @param $string
  * @return string
  */
 public function camelize($string)
 {
     return StringUtil::camelize($string);
 }