Closed DarthLegiON closed 7 years ago
@kartik-v, hello. Why not to accept my PR? Is there any errors in it? I forgot to remove "TODO" comment, I'm sorry, my fault :)
Why is this needed?
The class extends from yii\widgets\ActiveForm
and should automatically get PHP documentation and autocomplete from there.
@kartik-v, no, it doesn't happen. Here is PHPDoc in original ActiveForm.php:
/**
* Generates a form field.
* A form field is associated with a model and an attribute. It contains a label, an input and an error message
* and use them to interact with end users to collect their inputs for the attribute.
* @param Model $model the data model.
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
* about attribute expression.
* @param array $options the additional configurations for the field object. These are properties of [[ActiveField]]
* or a subclass, depending on the value of [[fieldClass]].
* @return ActiveField the created ActiveField object.
* @see fieldConfig
*/
public function field($model, $attribute, $options = [])
{
$config = $this->fieldConfig;
if ($config instanceof \Closure) {
$config = call_user_func($config, $model, $attribute);
}
if (!isset($config['class'])) {
$config['class'] = $this->fieldClass;
}
return Yii::createObject(ArrayHelper::merge($config, $options, [
'model' => $model,
'attribute' => $attribute,
'form' => $this,
]));
}
@return ActiveField
tells IDE that return value is ActiveField in same namespace, i.e. yii\widgets\ActiveField. But return object is generated dynamicly and in your code it is kartik\form\ActiveField. In this way, IDE doesn't know that result of $form->field(/*...*/)
is instance of your class. When I added code from PR into ActiveForm, my IDE (PHPStorm) correctly recognized concrete class.
I hope you add this PR to next release, it is simple, but can be useful)
This can be done in a different way... will update.
Scope
This pull request includes a
Changes
The following changes were made (this change is also documented in the change log):