Skip to content

Commit 4a51b19

Browse files
mjauvinLukeTowers
andauthored
Fixed support for config properties on URL fields (#1439)
Co-authored-by: Luke Towers <git@luketowers.ca>
1 parent ced8f5d commit 4a51b19

3 files changed

Lines changed: 50 additions & 21 deletions

File tree

modules/backend/classes/FormField.php

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ class FormField
9191
public $span = 'full';
9292

9393
/**
94-
* @var string Specifies a size. Possible values: tiny, small, large, huge, giant.
94+
* @var string|int Specifies a size. Possible values for textarea: tiny, small, large, huge, giant.
9595
*/
96-
public $size = 'large';
96+
public $size;
9797

9898
/**
9999
* @var string Specifies contextual visibility of this form field.
@@ -211,7 +211,7 @@ public function span($value = 'full')
211211
}
212212

213213
/**
214-
* Sets a side of the field on a form.
214+
* Sets the size of the field on a form.
215215
* @param string $value Specifies a size. Possible values: tiny, small, large, huge, giant
216216
*/
217217
public function size($value = 'large')
@@ -259,6 +259,11 @@ public function options($value = null)
259259
*/
260260
public function displayAs($type, $config = [])
261261
{
262+
if (in_array($type, ['textarea', 'widget'])) {
263+
// defaults to 'large'
264+
$this->size = 'large';
265+
}
266+
262267
$this->type = strtolower($type) ?: $this->type;
263268
$this->config = $this->evalConfig($config);
264269

@@ -281,18 +286,18 @@ protected function evalConfig($config)
281286
*/
282287
$applyConfigValues = [
283288
'commentHtml',
284-
'placeholder',
289+
'context',
290+
'cssClass',
285291
'dependsOn',
286-
'required',
287-
'readOnly',
288292
'disabled',
289-
'cssClass',
290-
'stretch',
291-
'context',
292293
'hidden',
293-
'trigger',
294-
'preset',
295294
'path',
295+
'placeholder',
296+
'preset',
297+
'readOnly',
298+
'required',
299+
'stretch',
300+
'trigger',
296301
];
297302

298303
foreach ($applyConfigValues as $value) {
@@ -729,4 +734,31 @@ protected function getFieldNameFromData($fieldName, $data, $default = null)
729734

730735
return $result;
731736
}
737+
738+
/**
739+
* Implements the getter functionality.
740+
* @param string $name
741+
*/
742+
public function __get($name)
743+
{
744+
if (is_array($this->config) && array_key_exists($name, $this->config)) {
745+
return array_get($this->config, $name);
746+
}
747+
if (property_exists($this, $name)) {
748+
return $this->{$name};
749+
}
750+
return null;
751+
}
752+
753+
/**
754+
* Determine if an attribute exists on the object.
755+
* @param string $name
756+
*/
757+
public function __isset($name)
758+
{
759+
if (is_array($this->config) && array_key_exists($name, $this->config)) {
760+
return true;
761+
}
762+
return property_exists($this, $name) && !is_null($this->{$name});
763+
}
732764
}

modules/backend/widgets/form/partials/_field_tel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class="form-control"
3232
<?= isset($field->maxlength) && is_numeric($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?>
3333
<?= isset($field->minlength) && is_numeric($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?>
3434
<?= isset($field->pattern) && is_string($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?>
35-
<?= isset($field->placeholder) && is_string($field->placeholder) ? 'placeholder="' . e($field->placeholder) . '"' : '' ?>
35+
<?= isset($field->placeholder) && is_string($field->placeholder) ? 'placeholder="' . e(trans($field->placeholder)) . '"' : '' ?>
3636
<?= isset($field->size) && is_numeric($field->size) ? 'size="' . e($field->size) . '"' : '' ?>
3737
<?= $field->getAttributes() ?>
3838
<?= $listId ? 'list="' . e($listId) . '"' : '' ?>

modules/backend/widgets/form/partials/_field_url.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@ class="form-control"
2727
name="<?= $field->getName() ?>"
2828
id="<?= $field->getId() ?>"
2929
value="<?= e($field->value) ?>"
30-
placeholder="<?= e(trans($field->placeholder)) ?>"
3130
class="form-control"
31+
<?= isset($field->autocomplete) && is_string($field->autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?>
32+
<?= isset($field->maxlength) && is_numeric($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?>
33+
<?= isset($field->minlength) && is_numeric($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?>
34+
<?= isset($field->pattern) && is_string($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?>
35+
<?= isset($field->placeholder) && is_string($field->placeholder) ? 'placeholder="' . e(trans($field->placeholder)) . '"' : '' ?>
36+
<?= isset($field->size) && is_numeric($field->size) ? 'size="' . e($field->size) . '"' : '' ?>
3237
<?= $field->getAttributes() ?>
33-
<?= isset($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?>
34-
<?= isset($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?>
35-
<?= isset($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?>
36-
<?= isset($field->size) ? 'size="' . e($field->size) . '"' : '' ?>
3738
<?= $listId ? 'list="' . e($listId) . '"' : '' ?>
38-
<?= isset($field->autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?>
39-
<?= isset($field->required) && $field->required ? 'required' : '' ?>
40-
<?= isset($field->readonly) && $field->readonly ? 'readonly' : '' ?>
41-
<?= isset($field->disabled) && $field->disabled ? 'disabled' : '' ?>
4239
/>
4340
<?php if ($hasOptions): ?>
4441
<datalist id="<?= e($listId) ?>">

0 commit comments

Comments
 (0)