/**
* 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.6
*/
public function __set($name, $value)
{
switch ($name) {
case 'formsource':
$this->formsource = (string) $value;
// Add root path if we have a path to XML file
if (strrpos($this->formsource, '.xml') === \strlen($this->formsource) - 4) {
$this->formsource = Path::clean(JPATH_ROOT . '/' . $this->formsource);
}
break;
case 'min':
$this->min = (int) $value;
break;
case 'max':
if ($value) {
$this->max = max(1, (int) $value);
}
break;
case 'groupByFieldset':
if ($value !== null) {
$value = (string) $value;
$this->groupByFieldset = !($value === 'false' || $value === 'off' || $value === '0');
}
break;
case 'layout':
$this->layout = (string) $value;
// Make sure the layout is not empty.
if (!$this->layout) {
// Set default value depend from "multiple" mode
$this->layout = !$this->multiple ? 'joomla.form.field.subform.default' : 'joomla.form.field.subform.repeatable';
}
break;
case 'buttons':
if (!$this->multiple) {
$this->buttons = array();
break;
}
if ($value && !\is_array($value)) {
$value = explode(',', (string) $value);
$value = array_fill_keys(array_filter($value), true);
}
if ($value) {
$value = array_merge(array('add' => false, 'remove' => false, 'move' => false), $value);
$this->buttons = $value;
}
break;
case 'value':
// We allow a json encoded string or an array
if (is_string($value)) {
$value = json_decode($value, true);
}
$this->value = $value !== null ? (array) $value : null;
break;
default:
parent::__set($name, $value);
}
}