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

Include the correct type into the property of the ContentBehavior #3894

Closed
Anubarak opened this issue Feb 23, 2019 · 2 comments
Closed

Include the correct type into the property of the ContentBehavior #3894

Anubarak opened this issue Feb 23, 2019 · 2 comments
Labels
enhancement improvements to existing features site development 👩‍💻 features related to website/API development

Comments

@Anubarak
Copy link
Contributor

Anubarak commented Feb 23, 2019

Description

First of all: The way you handle the ContentBehavior is absolutely awesome and I appreciate your idea really much.
I'm not sure if you have ever thought about including a more specific type into the PHPDoc when you create this class? I know this is far away from being a first world problem but including a property like

public static $phpDocType = 'mixed';

into craft\base\Field that can overwritten by any class that extends it. For example the BaseRelationField could have

public static $phpDocType = 'craft\elements\db\ElementQuery';

would be really awesome.

You could then fetch the type of the field together with the handle in your query and check if the specific class exists to grab the static attribute

$docType = class_exists($fieldType)? $fieldType::$phpDocType : 'mixed';
//------
//------
/**
 * @var {$docType} Value for field with the handle “{$handle}”.
 */
public \${$handle};

If you think that might make Craft better but don't have the time for it I'm happy to create a pull request.

This way: when we type $element->user-> PHPStorm (or others) won't complain about missmatches and suggest the functions of ElementQuery

@brandonkelly
Copy link
Member

Yeah good idea. Feel free to PR it. Just keep in mind that the same field handle could be used by more than one field in different contexts (e.g. body could be a global field and a sub-field of a Matrix block type.) So you’d need to combine all the different property types together with |s.

@brandonkelly
Copy link
Member

Added for 3.2 per your PR!

@brandonkelly brandonkelly added this to the 3.2 milestone Apr 9, 2019
@brandonkelly brandonkelly added site development 👩‍💻 features related to website/API development enhancement improvements to existing features labels Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements to existing features site development 👩‍💻 features related to website/API development
Projects
None yet
Development

No branches or pull requests

2 participants