symfony2admingenerator/AdmingeneratorGeneratorBundle — pull request #266 by mikeyudin (2012-10-29 14:22:51+00:00)
Title: Conditional Object Actions

Allow generator.yml to supply a conditional function to object actions, along with an "inverse" option on whether the object's conditional result should be inverse. In the generator.yml, specify the condition like this:

```yaml
object_actions:
delete:
condition:
function: canDelete
inverse: false
```
In this case, the generator's model object must contain a "canDelete" method:

```php
class ProductEntity
{
public function canDelete()
{
return $this->countProductSales() == 0 ? true : false;
}
}
```

The link in the object_actions.php.twig template should then be wrapped with:

```twig
{% if action.conditionalFunction %}
{% if action.conditionalInverse %}
{{ echo_if (builder.ModelClass ~ "." ~ action.conditionalFunction ~ " == false") }}
{% else %}
{{ echo_if (builder.ModelClass ~ "." ~ action.conditionalFunction) }}
{% endif %}
{% endif %}

###---- LINK HERE ------###

{% if action.conditionalFunction %}
{{ echo_endif () }}
{% endif %}
```