diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index 1f63e72ec8..f5125088d0 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -91,9 +91,9 @@ class FormField public $span = 'full'; /** - * @var string Specifies a size. Possible values: tiny, small, large, huge, giant. + * @var string|int Specifies a size. Possible values for textarea: tiny, small, large, huge, giant. */ - public $size = 'large'; + public $size; /** * @var string Specifies contextual visibility of this form field. @@ -211,7 +211,7 @@ public function span($value = 'full') } /** - * Sets a side of the field on a form. + * Sets the size of the field on a form. * @param string $value Specifies a size. Possible values: tiny, small, large, huge, giant */ public function size($value = 'large') @@ -259,6 +259,11 @@ public function options($value = null) */ public function displayAs($type, $config = []) { + if (in_array($type, ['textarea', 'widget'])) { + // defaults to 'large' + $this->size = 'large'; + } + $this->type = strtolower($type) ?: $this->type; $this->config = $this->evalConfig($config); @@ -281,18 +286,18 @@ protected function evalConfig($config) */ $applyConfigValues = [ 'commentHtml', - 'placeholder', + 'context', + 'cssClass', 'dependsOn', - 'required', - 'readOnly', 'disabled', - 'cssClass', - 'stretch', - 'context', 'hidden', - 'trigger', - 'preset', 'path', + 'placeholder', + 'preset', + 'readOnly', + 'required', + 'stretch', + 'trigger', ]; foreach ($applyConfigValues as $value) { @@ -729,4 +734,31 @@ protected function getFieldNameFromData($fieldName, $data, $default = null) return $result; } + + /** + * Implements the getter functionality. + * @param string $name + */ + public function __get($name) + { + if (array_key_exists($name, $this->config)) { + return array_get($this->config, $name); + } + if (property_exists($this, $name)) { + return $this->{$name}; + } + return null; + } + + /** + * Determine if an attribute exists on the object. + * @param string $name + */ + public function __isset($name) + { + if (array_key_exists($name, $this->config)) { + return true; + } + return property_exists($this, $name) && !is_null($this->{$name}); + } } diff --git a/modules/backend/widgets/form/partials/_field_url.php b/modules/backend/widgets/form/partials/_field_url.php index 2144ecbc62..43b68e7e3d 100644 --- a/modules/backend/widgets/form/partials/_field_url.php +++ b/modules/backend/widgets/form/partials/_field_url.php @@ -27,18 +27,15 @@ class="form-control" name="getName() ?>" id="getId() ?>" value="value) ?>" - placeholder="placeholder)) ?>" class="form-control" + autocomplete) && is_string($field->autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?> + maxlength) && is_numeric($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?> + minlength) && is_numeric($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?> + pattern) && is_string($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?> + placeholder) && is_string($field->placeholder) ? 'placeholder="' . e($field->placeholder) . '"' : '' ?> + size) && is_numeric($field->size) ? 'size="' . e($field->size) . '"' : '' ?> getAttributes() ?> - maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?> - minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?> - pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?> - size) ? 'size="' . e($field->size) . '"' : '' ?> - autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?> - required) && $field->required ? 'required' : '' ?> - readonly) && $field->readonly ? 'readonly' : '' ?> - disabled) && $field->disabled ? 'disabled' : '' ?> />