Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function render(GridViewInterface $grid, ColumnInterface $column, $sorting)
 {
     $definition = $grid->getDefinition();
     $name = $column->getName();
     if (!$definition->hasSort($name)) {
         return;
     }
     $sort = $sorting === SorterInterface::ASC ? $name : '-' . $name;
     $routeParameters = [];
     if (($request = $this->requestStack->getMasterRequest()) !== null) {
         $routeParameters = array_merge($request->attributes->get('_route_params', []), $request->query->all());
     }
     if (!isset($routeParameters['grid']['reset']) && isset($routeParameters['grid']['sorting']) && $routeParameters['grid']['sorting'] === $sort) {
         return;
     }
     if ($definition->hasOption('persistent') && $definition->getOption('persistent')) {
         $filters = $this->filterManager->get($definition);
         if (isset($filters['sorting']) && $filters['sorting'] === $sort) {
             return;
         }
     }
     $routeParameters['grid']['sorting'] = $sort;
     unset($routeParameters['grid']['reset']);
     return $this->urlGenerator->generate($definition->getOption('grid_route'), $routeParameters);
 }
 /**
  * @param FormEvent $event
  */
 public function onPostSubmit(FormEvent $event)
 {
     $form = $event->getForm();
     if ($form->isValid()) {
         unset($this->submittedData['page']);
         unset($this->submittedData['reset']);
         unset($this->submittedData['_xml_http_request']);
         $this->filterManager->set($form->getConfig()->getOption('grid'), $this->submittedData);
     }
 }
 public function testRenderWithPersistentSorted()
 {
     $column = $this->createColumnMock();
     $column->expects($this->once())->method('getName')->will($this->returnValue($name = 'name'));
     $view = $this->createGridViewMock();
     $view->expects($this->once())->method('getDefinition')->will($this->returnValue($grid = $this->createGridMock()));
     $grid->expects($this->once())->method('hasSort')->with($this->identicalTo($name))->will($this->returnValue(true));
     $this->requestStack->expects($this->once())->method('getMasterRequest')->will($this->returnValue($request = $this->createRequestMock()));
     $request->attributes->expects($this->once())->method('get')->with($this->identicalTo('_route_params'), $this->identicalTo([]))->will($this->returnValue($routeParams = ['route' => 'param']));
     $request->query->expects($this->once())->method('all')->will($this->returnValue($queryParams = ['query' => 'query']));
     $grid->expects($this->once())->method('hasOption')->with($this->identicalTo('persistent'))->will($this->returnValue(true));
     $grid->expects($this->once())->method('getOption')->with($this->identicalTo('persistent'))->will($this->returnValue(true));
     $this->filterManager->expects($this->once())->method('get')->with($this->identicalTo($grid))->will($this->returnValue(['sorting' => $name]));
     $this->assertNull($this->renderer->render($view, $column, SorterInterface::ASC));
 }