/** * 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); }
/** * @param string $alias * @param \Leapt\AdminBundle\Admin\AdminInterface $admin */ public function registerAdmin($alias, AdminInterface $admin, array $options) { $admin->setAlias($alias); $resolver = new OptionsResolver(); $admin->configureOptions($resolver); $resolvedOptions = $resolver->resolve($options); $admin->setOptions($resolvedOptions); $this->admins[$alias] = $admin; }
/** * @param AdminInterface $admin * @param mixed $attributes * @param object $object * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ protected function secure(AdminInterface $admin, $attributes, $object = null) { if (!is_array($attributes)) { $attributes = array($attributes); } $suffixedAttributes = array_map(function ($attribute) use($admin) { return $attribute . '__' . strtoupper($admin->getAlias()); }, $attributes); if (!$this->getAuthorizationChecker()->isGranted($suffixedAttributes, $object)) { throw new AccessDeniedException(); } }
/** * @param \Leapt\AdminBundle\Admin\AdminInterface $admin * @param bool $plural * @return string */ public function getAdminLabel(AdminInterface $admin, $plural = false) { $number = $plural ? 10 : 1; $label = $admin->getOption('label'); return $this->translator->transChoice($label, $number, array(), $this->adminManager->getDefaultTranslationDomain()); }