public static function getOptionsForm($pluginName, $form, $options)
{
foreach ($options as $option) {
if (empty($option['type'])) {
$option['type'] = 'text';
}
if (in_array($option['type'], array('select', 'text', 'textarea', 'richText', 'color', 'range', 'checkbox', 'password'))) {
$option['type'] = ucfirst($option['type']);
}
$className = $option['type'];
if (class_exists($className)) {
$newField = new $className($option);
} else {
$className = 'Ip\\Form\\Field\\' . $option['type'];
if (class_exists($className)) {
$newField = new $className($option);
}
}
if (!isset($newField)) {
//field type is not recognised
continue;
}
$default = isset($option['default']) ? $option['default'] : null;
if (!empty($option['name'])) {
$newField->setName($option['name']);
$optionKey = "{$pluginName}.{$option['name']}";
if ($newField instanceof \Ip\Form\FieldLang) {
$value = array();
foreach (ipContent()->getLanguages() as $language) {
$value[$language->getCode()] = ipGetOptionLang($optionKey, $language->getCode(), $default);
}
$newField->setValue($value);
} else {
$newField->setValue(ipGetOption($optionKey, $default));
}
}
$newField->setLabel(empty($option['label']) ? '' : $option['label']);
if (!empty($option['note'])) {
$newField->setNote($option['note']);
}
if (!empty($option['validators'])) {
$newField->addValidator($option['validators']);
}
$form->addfield($newField);
}
}