/** * Get any configuration fields associated with the Inputfield * * @return InputfieldWrapper * */ public function ___getConfigInputfields() { $wrapper = new InputfieldWrapper(); $fieldgroupContext = $this->flags & Field::flagFieldgroupContext; if ($fieldgroupContext) { $allowContext = $this->type->getConfigAllowContext($this); if (!is_array($allowContext)) { $allowContext = array(); } } else { $allowContext = array(); } if (!$fieldgroupContext || count($allowContext)) { $inputfields = new InputfieldWrapper(); if (!$fieldgroupContext) { $inputfields->head = $this->_('Field type details'); } $inputfields->attr('title', $this->_('Details')); try { $fieldtypeInputfields = $this->type->getConfigInputfields($this); if (!$fieldtypeInputfields) { $fieldtypeInputfields = new InputfieldWrapper(); } $configArray = $this->type->getConfigArray($this); if (count($configArray)) { $w = new InputfieldWrapper(); $w->importArray($configArray); $w->populateValues($this); $fieldtypeInputfields->import($w); } foreach ($fieldtypeInputfields as $inputfield) { if ($fieldgroupContext && !in_array($inputfield->name, $allowContext)) { continue; } $inputfields->append($inputfield); } } catch (Exception $e) { $this->trackException($e, false, true); } if (count($inputfields)) { $wrapper->append($inputfields); } } $inputfields = new InputfieldWrapper(); $dummyPage = $this->wire('pages')->get("/"); // only using this to satisfy param requirement if ($inputfield = $this->getInputfield($dummyPage)) { if ($fieldgroupContext) { $allowContext = array('visibility', 'collapsed', 'columnWidth', 'required', 'requiredIf', 'showIf'); $allowContext = array_merge($allowContext, $inputfield->getConfigAllowContext($this)); } else { $allowContext = array(); $inputfields->head = $this->_('Input field settings'); } $inputfields->attr('title', $this->_('Input')); $inputfieldInputfields = $inputfield->getConfigInputfields(); if (!$inputfieldInputfields) { $inputfieldInputfields = new InputfieldWrapper(); } $configArray = $inputfield->getConfigArray(); if (count($configArray)) { $w = new InputfieldWrapper(); $w->importArray($configArray); $w->populateValues($this); $inputfieldInputfields->import($w); } foreach ($inputfieldInputfields as $i) { if ($fieldgroupContext && !in_array($i->name, $allowContext)) { continue; } $inputfields->append($i); } } $wrapper->append($inputfields); return $wrapper; }
/** * 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; }