mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Merge branch 'develop' into feature/cleanup
# Conflicts: # modules/backend/widgets/Form.php
This commit is contained in:
commit
743252c3ff
@ -8,6 +8,7 @@ use Event;
|
||||
use Redirect;
|
||||
use Backend;
|
||||
use Backend\Classes\ControllerBehavior;
|
||||
use October\Rain\Html\Helper as HtmlHelper;
|
||||
use October\Rain\Router\Helper as RouterHelper;
|
||||
use ApplicationException;
|
||||
use Exception;
|
||||
|
@ -783,9 +783,11 @@ class Form extends WidgetBase
|
||||
list($fieldName, $fieldContext) = $this->getFieldName($name);
|
||||
|
||||
$field = new FormField($fieldName, $label);
|
||||
|
||||
if ($fieldContext) {
|
||||
$field->context = $fieldContext;
|
||||
}
|
||||
|
||||
$field->arrayName = $this->arrayName;
|
||||
$field->idPrefix = $this->getId();
|
||||
|
||||
@ -793,25 +795,22 @@ class Form extends WidgetBase
|
||||
* Simple field type
|
||||
*/
|
||||
if (is_string($config)) {
|
||||
|
||||
if ($this->isFormWidget($config) !== false) {
|
||||
$field->displayAs('widget', ['widget' => $config]);
|
||||
}
|
||||
else {
|
||||
$field->displayAs($config);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Defined field type
|
||||
*/
|
||||
else {
|
||||
|
||||
$fieldType = $config['type'] ?? null;
|
||||
if (!is_string($fieldType) && $fieldType !== null) {
|
||||
throw new ApplicationException(Lang::get(
|
||||
'backend::lang.field.invalid_type',
|
||||
['type'=>gettype($fieldType)]
|
||||
['type' => gettype($fieldType)]
|
||||
));
|
||||
}
|
||||
|
||||
@ -824,7 +823,6 @@ class Form extends WidgetBase
|
||||
}
|
||||
|
||||
$field->displayAs($fieldType, $config);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -832,12 +830,37 @@ class Form extends WidgetBase
|
||||
*/
|
||||
$field->value = $this->getFieldValue($field);
|
||||
|
||||
/*
|
||||
* Apply the field name to the validation engine
|
||||
*/
|
||||
$attrName = implode('.', HtmlHelper::nameToArray($field->fieldName));
|
||||
|
||||
if ($this->model && method_exists($this->model, 'setValidationAttributeName')) {
|
||||
$this->model->setValidationAttributeName($attrName, $field->label);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check model if field is required
|
||||
*/
|
||||
if ($field->required === null && $this->model && method_exists($this->model, 'isAttributeRequired')) {
|
||||
$fieldName = implode('.', HtmlHelper::nameToArray($field->fieldName));
|
||||
$field->required = $this->model->isAttributeRequired($fieldName);
|
||||
// Check nested fields
|
||||
if ($this->isNested) {
|
||||
// Get the current attribute level
|
||||
$nameArray = HtmlHelper::nameToArray($this->arrayName);
|
||||
unset($nameArray[0]);
|
||||
|
||||
// Convert any numeric indexes to wildcards
|
||||
foreach ($nameArray as $i => $value) {
|
||||
if (preg_match('/^[0-9]*$/', $value)) {
|
||||
$nameArray[$i] = '*';
|
||||
}
|
||||
}
|
||||
|
||||
// Recombine names for full attribute name in rules array
|
||||
$attrName = implode('.', $nameArray) . ".{$attrName}";
|
||||
}
|
||||
|
||||
$field->required = $this->model->isAttributeRequired($attrName);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user