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. |