I have been recently using attributes instead of declaring allowed_actions in the private var, and I must say this has been a great improvement. No more dev/build when adding an action. No need to look at two places anymore. Hopefully the team will make use of attributes in the future
That sounds pretty neat, do you have an example you can show us?
Sure ! it would look something like this
This is really basic, but it would be easy enough to also add any validation logic (like a permission check or any other method call)
Would be lovely to have that in the core. There are probably other places where attributes could be really helpful (i’m thinking ORM field definitions that would be much more robust for example)
That’s pretty cool!
For this to outright replace the
allowed_actions configuration property we’d need to make sure actions can be applied via extensions as well using attributes - but there are plenty of ways we could tackle that.
I wonder what other configuration we could replace with attributes like this… there’s bound to be a bunch of stuff like this we’ve shoved into config for convenience with extensions that isn’t really configurable per se.
yes, routing and orm are probably the two biggest areas where attributes make sense
also, attributes could be collected by composer (olvlvl/composer-attribute-collector - Packagist) to allow ClassInfo like logic if needed (find all classes with x attribute) at no runtime cost