Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom annotation classes #4

Open
donquixote opened this issue Aug 4, 2017 · 9 comments
Open

Custom annotation classes #4

donquixote opened this issue Aug 4, 2017 · 9 comments

Comments

@donquixote
Copy link

donquixote commented Aug 4, 2017

I was looking at AnnotatedRouteControllerLoader::configureRoute().
Currently this supports a limited and hardcoded selection of annotation classes.

What about a new interface for generic route config annotations, like this:

interface RouteConfigurationAnnotationInterface {
  public function configureRoute(Route $route);
}

Then in AnnotatedRouteControllerLoader::configureRoute() we would add this:

            } elseif ($configuration instanceof RouteConfigurationAnnotationInterface) {
                $configuration->configureRoute($route);

As a (controversial) use case, currently I am thinking of this: #3
E.g. a @MenuLink(..) annotation, which would set an option in the route, which later can be read by a menu link plugin derivative.

Maybe there are less controversial use cases.
E.g. shortcuts for @Security: Instead of @Security(access=true), one could then write @AccessPublic.
Or instead of @Security(role="admin"), write @Role("admin")

Or maybe a @RouteTitle("Hello") or a generic @Option(_title = "Hello"), instead of @Route("/path/to/hello", options = {"title" = "Hello"})

Ok, I am not sure yet if my examples are really worthwhile, but I do think it would open some interesting possibilities.

Btw, I prefer longer identifiers like @RouteTitle over just @Title, this reduces the ambiguity on IDE autocomplete.

@donquixote
Copy link
Author

Let me know if you want a PR :)

@donquixote
Copy link
Author

donquixote commented Aug 4, 2017

See #5 @RouteTitleCallback

@donquixote
Copy link
Author

Another use case: @RouteIsAdmin instead of @Route(.., admin=true).

@slootjes
Copy link
Contributor

slootjes commented Aug 4, 2017

I'm excited about the new ideas you come with and I also like the idea of the interface but I think it should be prevented to end up with tons of different annotations that could conflict with each other. If using the PhpStorm with the Annotations plugin the options available are all being autocompleted too btw. I'll leave this open for now to discuss possible new annotations that can currently not be done.

@donquixote
Copy link
Author

donquixote commented Aug 4, 2017

it should be prevented to end up with tons of different annotations that could conflict with each other.

The idea, if that wasn't clear, is to allow others to write annotations for route settings outside of this module.

If using the PhpStorm with the Annotations plugin the options available are all being autocompleted too btw.

--Yes, this is what I am doing. It is great :)--
EDIT: Oh actually this specific feature I did not see yet, thanks!

@slootjes
Copy link
Contributor

slootjes commented Aug 4, 2017

The annotations also have to be loaded manually because I couldn't not find a way of doing this in Drupal. Maybe a few other annotations can be created but I think most of it is covered by this.

@donquixote
Copy link
Author

Yes, I noticed I needed to add some code to \Drupal\controller_annotations\Configuration\ConfigurationLoader::load().

This is called from RouteEventSubscriber and from ControllerEventSubscriber.
So other modules which provide route modifier annotations would need to do the same.
Annoying, but I don't see another way atm.

I am going to push a preview branch or PR soon-ish.

@donquixote
Copy link
Author

I notice that those extra annotations only work on methods, not on the class itself.
Do you know where the class annotations are processed?

donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
…edRouteControllerLoader::configureRoute().
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
The actual test cases have yet to be written.
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
donquixote added a commit to donquixote/drupal-controller-annotations that referenced this issue Aug 4, 2017
@donquixote
Copy link
Author

I am working with the new annotations, and I think they are fun.

I also created a custom module with more annotation classes @RouteMenuLink, @RouteTaskLink, @RouteDefaultTaskLink. It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants