/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 3.2
*/
public function __set($name, $value)
{
switch ($name) {
case 'class':
// Removes spaces from left & right and extra spaces from middle
$value = preg_replace('/\\s+/', ' ', trim((string) $value));
case 'description':
case 'hint':
case 'value':
case 'labelclass':
case 'layout':
case 'onchange':
case 'onclick':
case 'validate':
case 'pattern':
case 'validationtext':
case 'group':
case 'showon':
case 'parentclass':
case 'default':
case 'autocomplete':
$this->{$name} = (string) $value;
break;
case 'id':
$this->id = $this->getId((string) $value, $this->fieldname);
break;
case 'fieldname':
$this->fieldname = $this->getFieldName((string) $value);
break;
case 'name':
$this->fieldname = $this->getFieldName((string) $value);
$this->name = $this->getName($this->fieldname);
break;
case 'multiple':
// Allow for field classes to force the multiple values option.
$value = (string) $value;
$value = $value === '' && isset($this->forceMultiple) ? (string) $this->forceMultiple : $value;
case 'required':
case 'disabled':
case 'readonly':
case 'autofocus':
case 'hidden':
$value = (string) $value;
$this->{$name} = $value === 'true' || $value === $name || $value === '1';
break;
case 'spellcheck':
case 'translateLabel':
case 'translateDescription':
case 'translateHint':
$value = (string) $value;
$this->{$name} = !($value === 'false' || $value === 'off' || $value === '0');
break;
case 'translate_label':
$value = (string) $value;
$this->translateLabel = $this->translateLabel && !($value === 'false' || $value === 'off' || $value === '0');
break;
case 'translate_description':
$value = (string) $value;
$this->translateDescription = $this->translateDescription && !($value === 'false' || $value === 'off' || $value === '0');
break;
case 'size':
$this->{$name} = (int) $value;
break;
default:
// Detect data attribute(s)
if (strpos($name, 'data-') === 0) {
$this->dataAttributes[$name] = $value;
} else {
if (property_exists(__CLASS__, $name)) {
Log::add("Cannot access protected / private property {$name} of " . __CLASS__);
} else {
$this->{$name} = $value;
}
}
}
}