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,13 +671,18 @@ 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)) {
$field = [$field];
}
foreach ($field as $item) {
$fieldName = ($item instanceof FormField) ? $item->getName() : $item;
$srcField = $this->dataFieldByName($fieldName); $srcField = $this->dataFieldByName($fieldName);
if ($srcField) { if ($srcField) {
$this->replaceField($fieldName, $srcField->performReadonlyTransformation()); $this->replaceField($fieldName, $srcField->performReadonlyTransformation());
@ -685,6 +690,7 @@ class FieldList extends ArrayList
user_error("Trying to make field '$fieldName' readonly, but it does not exist in the list", E_USER_WARNING); user_error("Trying to make field '$fieldName' readonly, but it does not exist in the list", E_USER_WARNING);
} }
} }
}
/** /**
* Change the order of fields in this FieldList by specifying an ordered list of field names. * Change the order of fields in this FieldList by specifying an ordered list of field names.