APYDataGridBundle
APYDataGridBundle copied to clipboard
Class column annotation and groups functionality.
In manual section Column Annotation for a class I see description of groups parameter:
Use this attribute to define more than one configuration for an Entity/Document.
If no groups is defined, the annotation is attributed for all groups.
$source = new Entity('MyProjectMyBundle:MyEntity', 'my_group');
But in code looks like some logic bug with If no groups is defined, the annotation is attributed for all groups. when non-default group using. When loading Column annotation for property without group specification, it puts all annotations under custom group. But Column annotations for class it puts under default group.
Example:
/**
* Test
* ...
* @Grid\Column(id="custom_column", sortable=false, filterable=false, title="Custom Column") #No Groups Spec!!!
* @GRID\Source(columns="<one set of columns with custom_column>") #No Groups Spec!!!
* @GRID\Source(columns=<another set of columns with custom_column>", groups="some_custom_group") #With Groups Spec!
* ...
*/
class Test
{
...
/**
* @GRID\Column(title="Some Property", type="number") #No Groups Spec!!!
*/
private $someProperty;
...
}
When I try to call
$source = new Entity('TestBundle:Test', 'some_custom_group');
...
$grid = $this->get('grid');
$grid->setSource($source);
$column = $grid->getColumn('custom_column');
it raises exception on last line:
Column with id "custom_column" doesn't exists.
Looking in code, I found in APY\DataGridBundle\Grid\Mapping\Driver\Annotation class that Column annotations for class puts custom_column column to default group only, not in specified in Entity constructor (but someProperty column was put to some_custom_group as requested). And you require to list all groups in Column annotations for class to resolve this issue.
BTW, the same is related to Source annotation too.
If this is correct, please update doc and add requirement to list all availabel groups in annotations (but this is not usefull).
If this is logic bug, I can provide PR to resolve it.
I think that we forget to implement group functionnality for the column annotation for class. We have to implement the same way.
You can provide a PR if you know how to do it. Thx
Can you try my last commit, this should be good now.
The column class annotation works good. But there is still problem with source annotation. Steps to reproduce:
Model
/**
* Test
*
* ...
* @GRID\Source(columns="id, <custom set of columns>", groups="custom_group")
* @GRID\Source(columns="id, <default set of columns>")
*/
class Test
{
...
}
Controller
public function indexAction()
{
$source = new Entity('TestBundle:Test', 'another_custom_group');
...
}
Expected behaviour: get list of columns, listed in default Source annotation What I get: list of all columns in entity.
How to fix
In file Grid/Mapping/Driver/Annotation.php after foreach block:
foreach ($this->reader->getClassAnnotations($reflection) as $class) {
$this->getMetadataFromClass($className, $class, $group);
}
add the following:
if(array_key_exists($className, $this->columns) && !array_key_exists($group, $this->columns[$className]) && array_key_exists('default', $this->columns[$className]))
{
$this->columns[$className][$group] = $this->columns[$className]['default'];
$this->filterable[$className][$group] = $this->filterable[$className]['default'];
$this->sortable[$className][$group] = $this->sortable[$className]['default'];
$this->groupBy[$className][$group] = $this->groupBy[$className]['default'];
}
Right.
So, can you add and commit changes above and decline my PR (as it was merged manually)?
I'll add tonight these changes.
thank you!
Sorry, but still cannot see fix for source annotation, discussed in comment
I think I've totally forgot to conitnue this request.
I see you forget about this fix again
Don't have time for the moment
@APY/collaborators I propose to throw an exception when a group name does not exist instead of display the default columns.
Agreed