public bool
setFields
(mixed &$elements, mixed $group = null, mixed $replace = true, mixed $fieldset = 'default')
Method to set some field XML elements to the form definition. If the replace flag is set then
the fields will be set whether they already exists or not. If it isn't set, then the fields
will not be replaced if they already exist.
Parameters
- array & $elements The array of XML element object representations of the form fields.
- string $group The optional dot-separated form group path on which to set the fields.
- bool $replace True to replace existing fields if they already exist.
- string $fieldset The name of the fieldset we are adding the field to.
Returns
Since
-
- \UnexpectedValueException
/**
* Method to set some field XML elements to the form definition. If the replace flag is set then
* the fields will be set whether they already exists or not. If it isn't set, then the fields
* will not be replaced if they already exist.
*
* @param array &$elements The array of XML element object representations of the form fields.
* @param string $group The optional dot-separated form group path on which to set the fields.
* @param boolean $replace True to replace existing fields if they already exist.
* @param string $fieldset The name of the fieldset we are adding the field to.
*
* @return boolean True on success.
*
* @since 1.7.0
* @throws \UnexpectedValueException
*/
public function setFields(&$elements, $group = null, $replace = true, $fieldset = 'default')
{
// Make sure there is a valid Form XML document.
if (!$this->xml instanceof \SimpleXMLElement) {
throw new \UnexpectedValueException(sprintf('%s::%s `xml` is not an instance of SimpleXMLElement', \get_class($this), __METHOD__));
}
// Make sure the elements to set are valid.
foreach ($elements as $element) {
if (!$element instanceof \SimpleXMLElement) {
throw new \UnexpectedValueException(sprintf('%s::%s `xml` is not an instance of SimpleXMLElement', \get_class($this), __METHOD__));
}
}
// Set the fields.
$return = true;
foreach ($elements as $element) {
if (!$this->setField($element, $group, $replace, $fieldset)) {
$return = false;
}
}
// Synchronize any paths found in the load.
$this->syncPaths();
return $return;
}