API Allow an array as a param to makeFieldReadOnly()

This commit is contained in:
Reece Alexander 2017-11-07 15:51:13 +13:00 committed by Damian Mooyman
parent 420041f2b6
commit 642cbdafc8

View File

@ -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) public function makeFieldReadonly($field)
{ {
$fieldName = ($field instanceof FormField) ? $field->getName() : $field; if (!is_array($field)) {
$srcField = $this->dataFieldByName($fieldName); $field = [$field];
if ($srcField) { }
$this->replaceField($fieldName, $srcField->performReadonlyTransformation());
} else { foreach ($field as $item) {
user_error("Trying to make field '$fieldName' readonly, but it does not exist in the list", E_USER_WARNING); $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);
}
} }
} }