/**
  * Add dynamic fields
  *
  * @param BuildBefore $event
  * @param string|null $alias
  * @param string|null $itemType
  * @param bool        $dynamicFirst flag if true - dynamic columns will be placed before static, false - after
  */
 public function doBuildBefore(BuildBefore $event, $alias = null, $itemType = null, $dynamicFirst = true)
 {
     $config = $event->getConfig();
     // get dynamic columns and merge them with static columns from configuration
     $additionalColumnSettings = $this->getDynamicFields($alias, $itemType);
     $filtersSorters = $this->getDynamicSortersAndFilters($additionalColumnSettings);
     $additionalColumnSettings = ['columns' => $additionalColumnSettings, 'sorters' => $filtersSorters['sorters'], 'filters' => $filtersSorters['filters']];
     $additionalColumnSettings = $this->datagridResolver->resolve($config->getName(), $additionalColumnSettings);
     foreach (['columns', 'sorters', 'filters'] as $itemName) {
         $path = '[' . $itemName . ']';
         // get already defined items
         $items = $config->offsetGetByPath($path, []);
         // merge additional items with existing
         if ($dynamicFirst) {
             $items = array_merge_recursive($additionalColumnSettings[$itemName], $items);
         } else {
             $items = array_merge_recursive($items, $additionalColumnSettings[$itemName]);
         }
         // set new item set with dynamic columns/sorters/filters
         $config->offsetSetByPath($path, $items);
     }
     // add/configure entity config properties
     $this->addEntityConfigProperties($config, $itemType);
     // add/configure entity config actions
     $actions = $config->offsetGetByPath(self::PATH_ACTIONS, []);
     $this->prepareRowActions($actions, $itemType);
     $config->offsetSetByPath(self::PATH_ACTIONS, $actions);
 }
 /**
  * Assert definition empty
  */
 public function testResolveEmpty()
 {
     $definition = [];
     $gridDefinition = $this->resolver->resolve('test', $definition);
     $this->assertEmpty($gridDefinition);
     $definition = ['filters' => ['entityName' => ['choices' => 'test-not-valid']]];
     $gridDefinition = $this->resolver->resolve('test', $definition);
     $this->assertEquals($definition, $gridDefinition);
 }
Exemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function getConfiguration($gridName)
 {
     if (!isset($this->rawConfiguration[$gridName])) {
         throw new RuntimeException(sprintf('A configuration for "%s" datagrid was not found.', $gridName));
     }
     if (!isset($this->processedConfiguration[$gridName])) {
         $config = $this->resolver->resolve($gridName, $this->rawConfiguration[$gridName]);
         $this->processedConfiguration[$gridName] = $config;
     }
     return DatagridConfiguration::createNamed($gridName, $this->processedConfiguration[$gridName]);
 }
Exemplo n.º 4
0
 /**
  * Assert definition escaped
  */
 public function testResolveEscaped()
 {
     $gridName = 'test';
     $gridDefinition = ['filters' => ['entityName' => ['choices_builder' => 'test\\@email.com']]];
     $gridDefinition = $this->resolver->resolve($gridName, $gridDefinition);
     $this->assertEquals('*****@*****.**', $gridDefinition['filters']['entityName']['choices_builder']);
 }