kitpages/KitpagesDataGridBundle — pull request #38 by rjbijl (2014-11-14 09:56:00+00:00)
Title: Flatten arrays with one value when normalizing item

My usecase is the following:
I have a questionnaire which is translated using the PrezentDoctrineTranslatableBundle. My queryBuilder is the following:
``` php
$this->createQueryBuilder('q')
->select('q, qt')
->join('q.translations', 'qt')
->where('qt.locale = :locale')
->orderBy('qt.name')
->setParameter('locale', $locale);
```
The result, after 'getArrayResult()':
```php
array (size=2)
'id' => int 4
'translations' =>
array (size=1)
'en' =>
array (size=4)
'name' => string 'asdfa' (length=5)
'description' => string '' (length=0)
'id' => int 6
'locale' => string 'en' (length=2)
```
Note that the 'translations' array, is not numerical, but has the locale as its key. This is because the PrezentTranslatable uses an indexBy strategy on 'locale', on the relation between the translatable entity and its translations.

Because of this, the normalized item comes out like:
```php
array (size=2)
'q.id' => int 4
'qt.en' =>
array (size=4)
'name' => string 'asdfa' (length=5)
'description' => string '' (length=0)
'id' => int 6
'locale' => string 'en' (length=2)
```
instead of
```php
array (size=5)
'q.id' => int 4
'qt.name' => string 'asdfa' (length=5)
'qt.description' => string '' (length=0)
'qt.id' => int 6
'qt.locale' => string 'en' (length=2)
```
This causes the grid to not display a value for i.e. 'qt.name', and also makes it impossible to filter and sort on this field.

The reason for this is that the normalizeOneItem function, only flattens an array if its key is '0'. I thought about this, and I think the same can be done for all arrays with only one value, even if they have an alphanumerical key.
I'm just not sure if this has any side-effects. I haven't encountered any yet, but thats not saying anything, of course.