mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API Allow an array as a param to makeFieldReadOnly()
This commit is contained in:
parent
420041f2b6
commit
642cbdafc8
@ -671,18 +671,24 @@ class FieldList extends ArrayList
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the named field into a readonly feld.
|
||||
* Transform the named field into a readonly field.
|
||||
*
|
||||
* @param string|FormField
|
||||
* @param string|array|FormField $field
|
||||
*/
|
||||
public function makeFieldReadonly($field)
|
||||
{
|
||||
$fieldName = ($field instanceof FormField) ? $field->getName() : $field;
|
||||
$srcField = $this->dataFieldByName($fieldName);
|
||||
if ($srcField) {
|
||||
$this->replaceField($fieldName, $srcField->performReadonlyTransformation());
|
||||
} else {
|
||||
user_error("Trying to make field '$fieldName' readonly, but it does not exist in the list", E_USER_WARNING);
|
||||
if (!is_array($field)) {
|
||||
$field = [$field];
|
||||
}
|
||||
|
||||
foreach ($field as $item) {
|
||||
$fieldName = ($item instanceof FormField) ? $item->getName() : $item;
|
||||
$srcField = $this->dataFieldByName($fieldName);
|
||||
if ($srcField) {
|
||||
$this->replaceField($fieldName, $srcField->performReadonlyTransformation());
|
||||
} else {
|
||||
user_error("Trying to make field '$fieldName' readonly, but it does not exist in the list", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user