Exemple #1
0
 /**
  * Get the Inputfields that configure the given module or return null if not configurable
  * 
  * @param string|Module|int $moduleName
  * @param InputfieldWrapper|null $form Optionally specify the form you want Inputfields appended to.
  * @return InputfieldWrapper|null
  * 
  */
 public function ___getModuleConfigInputfields($moduleName, InputfieldWrapper $form = null)
 {
     $moduleName = $this->getModuleClass($moduleName);
     $configurable = $this->isConfigurableModule($moduleName);
     if (!$configurable) {
         return null;
     }
     if (is_null($form)) {
         $form = new InputfieldWrapper();
     }
     $data = $this->modules->getModuleConfigData($moduleName);
     // check for configurable module interface
     $configurableInterface = $this->isConfigurableModule($moduleName, "interface");
     if ($configurableInterface) {
         if (is_int($configurableInterface) && $configurableInterface > 1 && $configurableInterface < 20) {
             // non-static
             /** @var ConfigurableModule $module */
             $module = $this->getModule($moduleName);
             if ($configurableInterface === 2) {
                 // requires no arguments
                 $fields = $module->getModuleConfigInputfields();
             } else {
                 if ($configurableInterface === 3) {
                     // requires $data array
                     $fields = $module->getModuleConfigInputfields($data);
                 } else {
                     if ($configurableInterface === 4) {
                         // requires InputfieldWrapper
                         // we allow for option of no return statement in the method
                         $fields = new InputfieldWrapper();
                         $_fields = $module->getModuleConfigInputfields($fields);
                         if ($_fields instanceof InputfieldWrapper) {
                             $fields = $_fields;
                         }
                         unset($_fields);
                     } else {
                         if ($configurableInterface === 19) {
                             // non-static getModuleConfigArray method
                             $fields = new InputfieldWrapper();
                             $fields->importArray($module->getModuleConfigArray());
                             $fields->populateValues($module);
                         }
                     }
                 }
             }
         } else {
             if ($configurableInterface === 20) {
                 // static getModuleConfigArray method
                 $fields = new InputfieldWrapper();
                 $fields->importArray(call_user_func(array($moduleName, 'getModuleConfigArray')));
                 $fields->populateValues($data);
             } else {
                 if ($configurableInterface) {
                     // static getModuleConfigInputfields method
                     $fields = call_user_func(array($moduleName, 'getModuleConfigInputfields'), $data);
                 }
             }
         }
         if ($fields instanceof InputfieldWrapper) {
             foreach ($fields as $field) {
                 $form->append($field);
             }
         } else {
             if ($fields instanceof Inputfield) {
                 $form->append($fields);
             } else {
                 $this->error("{$moduleName}.getModuleConfigInputfields() did not return InputfieldWrapper");
             }
         }
     }
     // check for file-based config
     $file = $this->isConfigurableModule($moduleName, "file");
     if (!$file || !is_string($file) || !is_file($file)) {
         return $form;
     }
     $config = null;
     include_once $file;
     $configClass = $moduleName . "Config";
     $configModule = null;
     if (class_exists($configClass)) {
         // file contains a ModuleNameConfig class
         $configModule = new $configClass();
     } else {
         if (is_null($config)) {
             include $file;
         }
         // in case of previous include_once
         if (is_array($config)) {
             // file contains a $config array
             $configModule = new ModuleConfig();
             $configModule->add($config);
         }
     }
     if ($configModule && $configModule instanceof ModuleConfig) {
         $defaults = $configModule->getDefaults();
         $data = array_merge($defaults, $data);
         $configModule->setArray($data);
         $fields = $configModule->getInputfields();
         if ($fields instanceof InputfieldWrapper) {
             foreach ($fields as $field) {
                 $form->append($field);
             }
             foreach ($data as $key => $value) {
                 $f = $form->getChildByName($key);
                 if ($f) {
                     $f->attr('value', $value);
                 }
             }
         } else {
             $this->error("{$configModule}.getInputfields() did not return InputfieldWrapper");
         }
     }
     return $form;
 }