Browse Source

[UPDATE] introduce method to add multiple options from array

experimental
Georgi Hristov 2 years ago
parent
commit
dff529d3cd
1 changed files with 26 additions and 0 deletions
  1. +26
    -0
      modules/Utils/LeightboxPrompt/LeightboxPrompt_0.php

+ 26
- 0
modules/Utils/LeightboxPrompt/LeightboxPrompt_0.php View File

@@ -37,6 +37,32 @@ class Utils_LeightboxPrompt extends Module {
//this way works because no init is called
if (isset($form) && $form->exportValue('submited') && !$form->validate()) Utils_LeightboxPromptCommon::open($this->group, $this->get_params([]));
}
public function add_options($options) {
foreach ($options as $option => $desc) {
$desc['label'] = $desc['label']?? $option;
$desc['active'] = $desc['active']?? true;
$desc['active'] = is_array($desc['active'])? $desc['active']: [$desc['active']];
if (!(bool) array_product($desc['active'])) continue;
$form = null;
if ($desc['elements']?? []) {
$form = $this->init_module(Libs_QuickForm::module_name());
$elements = array_filter($desc['elements'], function($element) {
return $element['active']?? true;
});
$form->add_array($elements);
$form->setDefaults($desc['defaults']?? []);
}
$this->add_option($option, $desc['label'], $desc['icon']?? null, $form, $desc['tip']?? null);
}
}
public function set_selected_option($option) {


Loading…
Cancel
Save