Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
$drupal_user = User::create();
$drupal_user->setUsername($username);
In example above we will have $drupal_user
variable of \Drupal\Core\Entity\EntityInterface
type and will not have an autosuggestion feature which is provided by a lot of editors/IDEs.
Proposition is to add PHPDoc annotations to entity definitions with overridden return type.
Example:
/**
* @method static User load($id)
* @method static User create(array $values = [])
* @method static User[] loadMultiple(array $ids = NULL)
* @method User createDuplicate()
*/
Comment | File | Size | Author |
---|---|---|---|
#2 | user-override_phpdoc-2794733-2.patch | 579 bytes | BR0kEN |
Comments
Comment #2
BR0kENComment #5
dpiThis issue seems is with better IDE intelligence.
In recent versions of PHPStorm, returning
static
in an interface will correctly hint to the called class.Related: https://youtrack.jetbrains.com/issue/WI-19953, https://youtrack.jetbrains.com/issue/WI-23435
Comment #6
dpiAdding related