Merge branch 'develop' into feature/cleanup

# Conflicts:
#	modules/backend/widgets/Form.php
This commit is contained in:
Nathan van der Werf 2018-08-29 19:18:01 +02:00
commit 743252c3ff
No known key found for this signature in database
GPG Key ID: 8D25D930BC0B1439
2 changed files with 31 additions and 7 deletions

View File

@ -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;

View File

@ -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);
}
/*