Example #1
0
 /**
  * {@inheritDoc}
  */
 public function getDatagridByRequestParams($name, array $additionalParameters = [])
 {
     $gridScope = $this->nameStrategy->parseGridScope($name);
     if (!$gridScope) {
         // In case if grid has scope in config we should use it to get grid parameters properly
         $configuration = $this->getConfigurationForGrid($name);
         $scope = $configuration->offsetGetOr('scope');
         if ($scope) {
             $name = $this->nameStrategy->buildGridFullName($name, $scope);
         }
     }
     $uniqueName = $this->getDatagridUniqueName($name);
     $parameters = $this->parametersFactory->createParameters($uniqueName);
     /**
      * In case of custom relation - $gridScope will be present.
      * So we need to check for additional parameters (pager, sorter, etc.) by gridName (without scope).
      * E.g. 'uniqueName' can be like 'entity-relation-grid:OroAcme_Bundle_AcmeBundle_Entity_AcmeEntit-relOneToMany'
      *  so parameters by 'uniqueName' will contain 'class_name', 'field_name', 'id'
      *  and parameters by 'gridName' (entity-relation-grid) will contain '_pager', '_sort_by', etc.
      * In such cases we'll merge them together, otherwise pagination and sorters will not work.
      */
     if ($gridScope) {
         $gridName = $this->nameStrategy->parseGridName($name);
         $additional = $this->parametersFactory->createParameters($gridName)->all();
         if ($additional) {
             $additionalParameters = array_merge($additionalParameters, $additional);
         }
     }
     $parameters->add($additionalParameters);
     return $this->getDatagrid($name, $parameters);
 }
 public function testCreateParametersFromNotArrayRequestParams()
 {
     $gridName = 'test_grid';
     $this->request->expects($this->at(0))->method('get')->with($gridName, [], false)->will($this->returnValue('foo'));
     $this->request->expects($this->at(1))->method('get')->with(RequestParameterBagFactory::DEFAULT_ROOT_PARAM, [], false)->will($this->returnValue(null));
     $parameters = $this->factory->createParameters($gridName);
     $this->assertInstanceOf(self::PARAMETERS_CLASS, $parameters);
     $this->assertEquals(array(), $parameters->all());
 }
 public function testOnWidgetRender()
 {
     $gridParams = ['i' => 1, 'p' => 25, 's' => []];
     $event = new ProductGridWidgetRenderEvent(['grid' => ['removed' => 'params']]);
     $this->requestParameterBagFactory->expects($this->once())->method('createParameters')->willReturn(new ParameterBag($gridParams));
     $this->listener->onWidgetRender($event);
     $eventParams = $event->getWidgetRouteParameters();
     $this->assertArrayHasKey('grid', $eventParams);
     $this->assertSame($gridParams, $eventParams['grid']);
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function getDatagridByRequestParams($name, array $additionalParameters = [])
 {
     $gridScope = $this->nameStrategy->parseGridScope($name);
     if (!$gridScope) {
         // In case if grid has scope in config we should use it to get grid parameters properly
         $configuration = $this->getConfigurationForGrid($name);
         $scope = $configuration->offsetGetOr('scope');
         if ($scope) {
             $name = $this->nameStrategy->buildGridFullName($name, $scope);
         }
     }
     $parameters = $this->parametersFactory->createParameters($name);
     $parameters->add($additionalParameters);
     return $this->getDatagrid($name, $parameters);
 }
 /**
  * @param ProductGridWidgetRenderEvent $event
  */
 public function onWidgetRender(ProductGridWidgetRenderEvent $event)
 {
     $params = $event->getWidgetRouteParameters();
     $gridParameters = $this->requestParameterBagFactory->createParameters();
     $event->setWidgetRouteParameters(array_merge($params, [RequestParameterBagFactory::DEFAULT_ROOT_PARAM => $gridParameters->all()]));
 }