Skip to content

autocompletion in twig for looped collections #1097

Open
@plandolt

Description

@plandolt

Given the extended ArrayCollection:

/**
 * @method Provider __iterator
 * @method Provider|null get($key)
 * @method Provider|null remove($key)
 * @method Provider current()
 * @method Provider|null next()
 * @method Provider|null first()
 * @method Provider|null last()
 * @method Provider[] toArray()
 * @method Provider[] getValues()
 * @method ProviderCollection filter(\Closure $p)
 * @method ProviderCollection slice($offset, $length = null)
 * @method ProviderCollection matching(Criteria $criteria)
 * @method ProviderCollection[] partition(\Closure $p)
 */
class ProviderCollection extends ArrayCollection
{
}

While in controller I get good autocompletion for my Provider Entity in a foreach:

foreach ($providers as $provider) {
    $provider->
}

But in twig i do not have autocompletion in a for loop:

{% for provider in providers %}
    <th>{{ provider. }}</th>
{% endfor %}

I can resolve that by hinting in twig with:
{# @var providers \AppBundle\Entity\Provider[] #}

I dont know if the sf plugin is the right place to get this addressed or if its a phpstorm thing. But wanted to note on that here. Please give it a look.

UPDATE:
The autocomplete also does not work in twig when type hinting with:
{# @var providers \AppBundle\Service\ProviderCollection #}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions