mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Move this logic to no longer depend on AR model
This commit is contained in:
parent
a324f01678
commit
c6bfd5d01c
@ -557,4 +557,26 @@ class FormField
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the final model and attribute name of a nested attribute.
|
||||
* Eg: list($model, $attribute) = $this->resolveAttribute('person[phone]');
|
||||
* @param string $attribute.
|
||||
* @return array
|
||||
*/
|
||||
public function resolveModelAttribute($model, $attribute = null)
|
||||
{
|
||||
if ($attribute === null) {
|
||||
$attribute = $this->valueFrom ?: $this->fieldName;
|
||||
}
|
||||
|
||||
$parts = is_array($attribute) ? $attribute : HtmlHelper::nameToArray($attribute);
|
||||
$last = array_pop($parts);
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$model = $model->{$part};
|
||||
}
|
||||
|
||||
return [$model, $last];
|
||||
}
|
||||
}
|
||||
|
@ -125,8 +125,7 @@ abstract class FormWidgetBase extends WidgetBase
|
||||
*/
|
||||
public function resolveModelAttribute($attribute)
|
||||
{
|
||||
$parts = HtmlHelper::nameToArray($attribute);
|
||||
return $this->model->resolveAttribute($parts);
|
||||
return $this->formField->resolveModelAttribute($this->model, $attribute);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -913,8 +913,7 @@ class Form extends WidgetBase
|
||||
* Refer to the model method or any of its behaviors
|
||||
*/
|
||||
if (!is_array($fieldOptions) && !$fieldOptions) {
|
||||
$htmlArray = HtmlHelper::nameToArray($field->fieldName);
|
||||
list($model, $attribute) = $this->model->resolveAttribute($htmlArray);
|
||||
list($model, $attribute) = $field->resolveModelAttribute($this->model, $field->fieldName);
|
||||
|
||||
$methodName = 'get'.studly_case($attribute).'Options';
|
||||
if (
|
||||
|
Loading…
x
Reference in New Issue
Block a user