Back to Form class

Method setFieldAttribute

public bool
setFieldAttribute
(mixed $name, mixed $attribute, mixed $value, mixed $group = null)
Method to set an attribute value for a field XML element.
Parameters
  • string $name The name of the form field for which to set the attribute value.
  • string $attribute The name of the attribute for which to set a value.
  • mixed $value The value to set for the attribute.
  • string $group The optional dot-separated form group path on which to find the field.
Returns
  • bool True on success.
Since
  • 1.7.0
-
  • \UnexpectedValueException
Class: Form
Project: Joomla

Method setFieldAttribute - Source code

/**
 * Method to set an attribute value for a field XML element.
 *
 * @param   string  $name       The name of the form field for which to set the attribute value.
 * @param   string  $attribute  The name of the attribute for which to set a value.
 * @param   mixed   $value      The value to set for the attribute.
 * @param   string  $group      The optional dot-separated form group path on which to find the field.
 *
 * @return  boolean  True on success.
 *
 * @since   1.7.0
 * @throws  \UnexpectedValueException
 */
public function setFieldAttribute($name, $attribute, $value, $group = null)
{
    // 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__));
    }
    // Find the form field element from the definition.
    $element = $this->findField($name, $group);
    // If the element doesn't exist return false.
    if (!$element instanceof \SimpleXMLElement) {
        return false;
    } else {
        $element[$attribute] = $value;
        // Synchronize any paths found in the load.
        $this->syncPaths();
        return true;
    }
}