Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
911 stars 137 forks source link

[Twig] global var autocomplete #558

Closed gharlan closed 5 months ago

gharlan commented 9 years ago

Should be implemented by #31 but it does not work for me (and for @marapper, see https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/31#issuecomment-109659709)

Haehnchen commented 7 years ago

Extensions are supported we just need:

twig:
    globals:
      service: @service
tklaas commented 6 years ago

autocomplete for variables that are defined under twig: globals: do work, but using a service does not suggest Methods on this service.

twig:
    globals:
        service: '@AppBundle\Service\MyService'

using this in my template it does work. {# @var service \AppBundle\Service\MyService #}

but If have to add this in every template, when I add it to my base template which is extended, it does not work within the child template.

Is there another way of doing this? Maybe with toolbox plugin like @Koc mentioned here: https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/468#issuecomment-230508799 https://github.com/Haehnchen/idea-php-toolbox

tklaas commented 6 years ago

@Haehnchen autocomplete for the global var is working now, but there is no autocomplete for methods on the service like {{service.user.name}}

having this Service class for example

class MyService 
{
    /**
     * @var AuthorizationCheckerInterface
     */
    private $authorizationChecker;
    /**
     * @var TokenStorageInterface
     */
    private $tokenStorage;

    public function __construct(AuthorizationCheckerInterface $authorizationChecker, TokenStorageInterface $tokenStorage)
    {
        $this->authorizationChecker = $authorizationChecker;
        $this->tokenStorage = $tokenStorage;
    }

    /**
     * @return bool
     */
    public function isLoggedIn()
    {
        return $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED');
    }

    /**
     * @return User|UserInterface
     */
    public function getUser()
    {
        return $this->tokenStorage->getToken()->getUser();
    }
}