/** * Simple trivial test to check admin registration * */ public function testRegisterAdmin() { $adminManager = new AdminManager(); $admin = $this->getMock('Leapt\\AdminBundle\\Admin\\AdminInterface'); $adminManager->registerAdmin('foo', $admin); $this->assertInstanceOf('Leapt\\AdminBundle\\Admin\\AdminInterface', $adminManager->getAdmin('foo')); }
/** * @param \Symfony\Component\Form\FormView $view * @param \Symfony\Component\Form\FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['allow_add'] = $options['allow_add']; if ($options['allow_add']) { $view->vars['add_url'] = $this->routingHelper->generateUrl($this->adminManager->getAdmin($options['admin']), 'modalCreate'); $view->vars['add_label'] = $options['add_label']; } }
/** * Loads a resource. * * @param mixed $resource The resource * @param string $type The resource type */ public function load($resource, $type = null) { $routes = new RouteCollection(); foreach ($this->adminManager->getAdmins() as $alias => $admin) { $admin->addRoutes($routes); } return $routes; }
/** * @param \Symfony\Component\HttpFoundation\Request $request * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @return bool|void */ public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); $alias = $request->attributes->get('alias'); if (!$request->attributes->has('alias')) { throw new NotFoundHttpException('Cannot find admin without alias'); } try { $admin = $this->adminManager->getAdmin($alias); $request->attributes->set($param, $admin); $this->registry->addActivePath($admin->getDefaultPath()); } catch (\InvalidArgumentException $e) { throw new NotFoundHttpException(sprintf('Cannot find admin with alias "%s"', $alias)); } }
/** * Get logs corresponding to the provided criteria * * @param $entity * @param string|array $action * @return array */ public function getLogsForEntity($entity, $action = null) { if (null !== $action && !is_array($action)) { $action = array($action); } $admin = $this->admin->getAdminForEntity($entity); $qb = $this->em->createQueryBuilder()->select('l')->from($this->entityClassName, 'l')->where('l.admin = :admin')->andWhere('l.entityId = :entity_id')->setParameter('admin', $admin->getAlias())->setParameter('entity_id', $entity->getId()); if (null !== $action) { $qb->andWhere($qb->expr()->in('l.action', ':action'))->setParameter('action', $action); } return $qb->getQuery()->getResult(); }
/** * @return string */ public function getDefaultTranslationDomain() { return $this->adminManager->getDefaultTranslationDomain(); }