Which allows you to get on with your actual work instead, of writing awesome code. Plus it allows PhpStorm to dynamically understand your code, rather than you having to teach it. But I figure this new approach is the simplest to change existing code to, as it's only a very small and less obtrusive change. I've seen more and more of that sprinkled around contrib & core code. */ doxygen comments around your code to help inform PhpStorm of what a service is. Which might be discouraged, but I doubt will ever be entirely eliminated, especially in custom code which might often be a bit more 'quick & dirty', by necessity. Of course, this only really matters when you're forced to get the service via the \Drupal class, rather than dependency injection, such as in static/procedural code. Doxygen etc) in terms of generating final documentation files. This is super handy - especially for methods with a ton of parameters! PhpStorm creates stubs of PHPDoc blocks when you type the / opening tag and press Enter. Here's how it actually looks for me, demonstrating the inline parameter hint, and with PhpStorm's ' Quick documentation' tooltip opened (press F1 to get this). This is barely any more code, but suddenly I can click into the definition of the ->something() method, and get all the IDE functionality I normally expect. Instead, if I change my code to the following, PhpStorm suddenly understands what the service is, so it can help me code more easily! \Drupal::getContainer() Or perhaps because the Symfony plugin just isn't aware of this Drupalism. I discovered this is probably because the doxygen for the return type of \Drupal::service() is simply ' mixed'. That meant PhpStorm couldn't give me hints about what parameters the ' ->something()' method should take, or even auto-complete what methods are available on the service. But I'd noticed that PhpStorm often didn't recognise the method used after my code referred to a service like this: \Drupal::service('my_service') First, ensure you have enabled the Drupal Symfony Bridge and Symfony Support plugins they're brilliant for auto-complete suggestions, and navigating around services, controllers, annotations and twig templates! I find it so helpful to be able to cmd+click (or ctrl+click) on a service name, whether in a YAML definition, or PHP code, and jump straight to the service class. Here's a super simple tip to help you work with services for Drupal in PhpStorm ( our favourite IDE).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |