/**
  * @Route("/admin/asset/location-type/save")
  * @Method("POST")
  */
 public function saveAction(Request $request)
 {
     $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN', null, 'Unable to access this page!');
     $em = $this->getDoctrine()->getManager();
     $response = new Response();
     $locationTypes = [];
     $locationTypes['types'] = $em->getRepository('AppBundle\\Entity\\Asset\\LocationType')->findAll();
     $form = $this->createForm(LocationTypesType::class, $locationTypes, ['allow_extra_fields' => true]);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $locationTypes = $form->getData();
         foreach ($locationTypes['types'] as $type) {
             $em->persist($type);
         }
         $em->flush();
         $this->addFlash('notice', 'common.success');
         $response = new RedirectResponse($this->generateUrl('app_admin_asset_locationtype_index', [], UrlGeneratorInterface::ABSOLUTE_URL));
         $response->prepare($request);
         return $response->send();
     } else {
         $errorMessages = [];
         $formData = $form->all();
         foreach ($formData as $name => $item) {
             if (!$item->isValid()) {
                 $errorMessages[] = $name . ' - ' . $item->getErrors(true);
             }
         }
         return $this->render('admin/asset/location_types.html.twig', array('location_types_form' => $form->createView(), 'base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..')));
     }
 }
Пример #2
0
 /**
  * Handles an access denied failure redirecting to home page
  *
  * @param Request               $request
  * @param AccessDeniedException $accessDeniedException
  *
  * @return Response may return null
  */
 public function handle(Request $request, AccessDeniedException $accessDeniedException)
 {
     $this->logger->error('User tried to access: ' . $request->getUri());
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['message' => $accessDeniedException->getMessage(), 'trace' => $accessDeniedException->getTraceAsString(), 'exception' => get_class($accessDeniedException)], Response::HTTP_SERVICE_UNAVAILABLE);
     } else {
         $url = $request->getBasePath() !== "" ? $request->getBasePath() : "/";
         $response = new RedirectResponse($url);
         $response->setStatusCode(Response::HTTP_FORBIDDEN);
         $response->prepare($request);
         return $response->send();
     }
 }
Пример #3
0
 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *   In case the host name in the request is not trusted.
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     $core_root = dirname(dirname(dirname(__DIR__)));
     require_once $core_root . '/includes/bootstrap.inc';
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $site_path = static::findSitePath($request);
     $kernel->setSitePath($site_path);
     Settings::initialize(dirname($core_root), $site_path, $class_loader);
     // Initialize our list of trusted HTTP Host headers to protect against
     // header attacks.
     $host_patterns = Settings::get('trusted_host_patterns', array());
     if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
         if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
             throw new BadRequestHttpException('The provided host name is not valid for this server.');
         }
     }
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     return $kernel;
 }
Пример #4
0
 /**
  * Creates a redirect response
  *
  * @param string  $url     URL to redirect to
  * @param integer $status  The status code (302 by default)
  * @param array   $headers An array of response headers (Location is always set to the given URL)
  * @return SymfonyRedirectResponse
  * @throws InvalidArgumentException
  */
 public function prepareRedirectResponse($url, $status = 302, array $headers = array())
 {
     $header_bag = $this->getHeaders();
     $header_bag->add($headers);
     $response = new SymfonyRedirectResponse($url, $status, $header_bag->all());
     $response->prepare($this->request);
     return $response;
 }
 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $kernel->initializeSettings($request);
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     return $kernel;
 }
Пример #6
0
 /**
  * Create a DrupalKernel object from a request.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  * @param $class_loader
  *   The class loader. Normally Composer's ClassLoader, as included by the
  *   front controller, but may also be decorated; e.g.,
  *   \Symfony\Component\ClassLoader\ApcClassLoader.
  * @param string $environment
  *   String indicating the environment, e.g. 'prod' or 'dev'.
  * @param bool $allow_dumping
  *   (optional) FALSE to stop the container from being written to or read
  *   from disk. Defaults to TRUE.
  *
  * @return static
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *   In case the host name in the request is not trusted.
  */
 public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE)
 {
     // Include our bootstrap file.
     $core_root = dirname(dirname(dirname(__DIR__)));
     require_once $core_root . '/includes/bootstrap.inc';
     $class_loader_class = get_class($class_loader);
     $kernel = new static($environment, $class_loader, $allow_dumping);
     // Ensure sane php environment variables..
     static::bootEnvironment();
     // Get our most basic settings setup.
     $site_path = static::findSitePath($request);
     $kernel->setSitePath($site_path);
     Settings::initialize(dirname($core_root), $site_path, $class_loader);
     // Initialize our list of trusted HTTP Host headers to protect against
     // header attacks.
     $host_patterns = Settings::get('trusted_host_patterns', array());
     if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
         if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
             throw new BadRequestHttpException('The provided host name is not valid for this server.');
         }
     }
     // Redirect the user to the installation script if Drupal has not been
     // installed yet (i.e., if no $databases array has been defined in the
     // settings.php file) and we are not already installing.
     if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
         $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
         $response->prepare($request)->send();
     }
     // If the class loader is still the same, possibly upgrade to the APC class
     // loader.
     if ($class_loader_class == get_class($class_loader) && Settings::get('class_loader_auto_detect', TRUE) && function_exists('apc_fetch')) {
         $prefix = Settings::getApcuPrefix('class_loader', $core_root);
         $apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $class_loader);
         $class_loader->unregister();
         $apc_loader->register();
         $class_loader = $apc_loader;
     }
     // Ensure that the class loader reference is up-to-date.
     $kernel->classLoader = $class_loader;
     return $kernel;
 }