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

[5.x]: Elements won't autocomplete customfields after first field in PHPStorm #15336

Closed
myleshyson opened this issue Jul 12, 2024 · 3 comments
Closed
Labels

Comments

@myleshyson
Copy link
Contributor

myleshyson commented Jul 12, 2024

What happened?

Description

Not sure if this is a bug per se, but would be nice to address. Been noticing that custom fields won't autocomplete after the first call even though they have a "static" return type in the CustomFieldBehavior.

I noticed this commit switched the method return types back from \$this to static.

When testing locally if I use self instead of static i'm able to chain just fine.

I'm using PHPStorm 2024.1.4

Steps to reproduce

  1. Open up a craft installation in php storm.
  2. Type the following:
$entry = new Entry();
$entry->someField('value')->anotherField('value');

Expected behavior

anotherField should show up in the method completion window.

Actual behavior

after typing someField, nothing else shows up in the completion window.

Craft CMS version

5.2.4.1

PHP version

8.2

@myleshyson myleshyson added the bug label Jul 12, 2024
@brandonkelly
Copy link
Member

I’m able to reproduce this. Even $this isn’t working quite right though – PhpStorm thinks the CustomFieldBehavior instance will be returned in that case, rather than the element.

Reported to JetBrains: https://youtrack.jetbrains.com/issue/WI-78254/static-and-this-return-types-not-working-properly-in-mixins

brandonkelly added a commit that referenced this issue Jul 16, 2024
Fixes #15336

[ci skip]
@brandonkelly
Copy link
Member

On second look, $this is working for me now, so it must have been a fluke that it wasn’t. Switched to that for the next Craft 4 and 5 releases.

@brandonkelly
Copy link
Member

Craft 4.10.6 and 5.2.7 are out now with that change. Thanks for pointing it out!

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

No branches or pull requests

2 participants