/** * Generates the parameters form required for configuring a prebuilt form. * Fieldsets are given classes which define that they are collapsible and normally initially * collapsed, though the css for handling this must be defined elsewhere. For Drupal usage this * css is normally handled by default in the template. * @param array $options Options array with the following possibilities:<ul> * <li><b>form</b> * Name of the form file without the .php extension, e.g. mnhnl_dynamic_1.</li> * <li><b>currentSettings</b> * Associative array of default values to load into the form controls.</li> * <li><b>expandFirst</b> * Optional. If set to true, then the first fieldset on the form is initially expanded.</li> * <li><b>siteSpecific</b> * Optional. Defaults to false. If true then only parameters marked as specific to a site * are loaded. Used to provide a reduced version of the params form after migrating a * form between sites (e.g. when installing a Drupal feature).</li> * </ul> */ public static function prebuilt_form_params_form($options) { require_once 'data_entry_helper.php'; // temporarily disable caching because performance is not as important as reflecting // the latest available parameters, surveys etc. in the drop downs $oldnocache = self::$nocache; if (!isset($options['siteSpecific'])) { $options['siteSpecific'] = false; } self::$nocache = true; $formparams = self::get_form_parameters($options['form']); $fieldsets = array(); $r = ''; foreach ($formparams as $control) { // skip hidden controls or non-site specific controls when displaying the reduced site specific // version of the form if (isset($control['visible']) && !$control['visible'] || $options['siteSpecific'] && !(isset($control['siteSpecific']) && $control['siteSpecific'])) { continue; } $fieldset = isset($control['group']) ? $control['group'] : 'Other IForm Parameters'; // apply default options to the control $ctrlOptions = array_merge(array('id' => $control['fieldname'], 'sep' => '<br/>', 'class' => '', 'blankText' => '<' . lang::get('please select') . '>', 'extraParams' => array(), 'readAuth' => $options['readAuth']), $control); $type = self::map_type($control); // current form settings will overwrite the default if (isset($options['currentSettings']) && isset($options['currentSettings'][$control['fieldname']])) { $ctrlOptions['default'] = $options['currentSettings'][$control['fieldname']]; } $ctrlOptions['extraParams'] = array_merge($ctrlOptions['extraParams'], $options['readAuth']); // standardise the control width unless specified already in the control options if (strpos($ctrlOptions['class'], 'control-width') == false && $type != 'checkbox') { $ctrlOptions['class'] .= ' control-width-6'; } if (!isset($fieldsets[$fieldset])) { $fieldsets[$fieldset] = ''; } // form controls can specify the report helper class if (substr($type, 0, 15) == 'report_helper::') { $type = substr($type, 15); require_once 'report_helper.php'; $fieldsets[$fieldset] .= report_helper::$type($ctrlOptions); } else { $fieldsets[$fieldset] .= data_entry_helper::$type($ctrlOptions); } } $class = isset($options['expandFirst']) && $options['expandFirst'] ? 'collapsible' : 'collapsible collapsed'; foreach ($fieldsets as $fieldset => $content) { $r .= "<fieldset class=\"{$class}\"><legend>{$fieldset}</legend>\n"; $r .= $fieldsets[$fieldset]; $r .= "\n</fieldset>\n"; // any subsequent fieldset should be collapsed if (isset($options['expandFirst']) && $options['expandFirst']) { $class .= ' collapsed'; } } self::$nocache = $oldnocache; return $r; }
/** * Generates the parameters form required for configuring a prebuilt form. * Fieldsets are given classes which define that they are collapsible and normally initially * collapsed, though the css for handling this must be defined elsewhere. For Drupal usage this * css is normally handled by default in the template. * @param array $options Options array with the following possibilities:<ul> * <li><b>form</b> * Name of the form file without the .php extension, e.g. mnhnl_dynamic_1.</li> * <li><b>currentSettings</b> * Associative array of default values to load into the form controls.</li> * <li><b>expandFirst</b> * Optional. If set to true, then the first fieldset on the form is initially expanded.</li> * <li><b>siteSpecific</b> * Optional. Defaults to false. If true then only parameters marked as specific to a site * are loaded. Used to provide a reduced version of the params form after migrating a * form between sites (e.g. when installing a Drupal feature).</li> * <li><b>generator</b> * Optional. A string which, if it contains 'Drupal 7' is used to output * html specific to that CMS. </li> * </ul> */ public static function prebuilt_form_params_form($options) { if (function_exists('hostsite_add_library')) { hostsite_add_library('collapse'); } require_once 'data_entry_helper.php'; // temporarily disable caching because performance is not as important as reflecting // the latest available parameters, surveys etc. in the drop downs $oldnocache = self::$nocache; if (!isset($options['siteSpecific'])) { $options['siteSpecific'] = false; } self::$nocache = true; $formparams = self::get_form_parameters($options['form']); $fieldsets = array(); $r = ''; foreach ($formparams as $control) { // skip hidden controls or non-site specific controls when displaying the reduced site specific // version of the form if (isset($control['visible']) && !$control['visible'] || $options['siteSpecific'] && !(isset($control['siteSpecific']) && $control['siteSpecific'])) { continue; } $fieldset = isset($control['group']) ? $control['group'] : 'Other IForm Parameters'; // apply default options to the control $ctrlOptions = array_merge(array('id' => $control['fieldname'], 'sep' => '<br/>', 'class' => '', 'blankText' => '<' . lang::get('please select') . '>', 'extraParams' => array(), 'readAuth' => $options['readAuth']), $control); $type = self::map_type($control); // current form settings will overwrite the default if (isset($options['currentSettings']) && isset($options['currentSettings'][$control['fieldname']])) { $ctrlOptions['default'] = $options['currentSettings'][$control['fieldname']]; } $ctrlOptions['extraParams'] = array_merge($ctrlOptions['extraParams'], $options['readAuth']); // standardise the control width unless specified already in the control options if (strpos($ctrlOptions['class'], 'control-width') == false && $type != 'checkbox' && $type != 'report_helper::report_picker') { $ctrlOptions['class'] .= ' control-width-6'; } if (!isset($fieldsets[$fieldset])) { $fieldsets[$fieldset] = ''; } // form controls can specify the report helper class if (substr($type, 0, 15) == 'report_helper::') { $type = substr($type, 15); require_once 'report_helper.php'; $fieldsets[$fieldset] .= report_helper::$type($ctrlOptions); } else { $fieldsets[$fieldset] .= data_entry_helper::$type($ctrlOptions); } } $class = isset($options['expandFirst']) && $options['expandFirst'] ? 'collapsible' : 'collapsible collapsed'; foreach ($fieldsets as $fieldset => $content) { $r .= "<fieldset class=\"{$class}\">\n"; // In Drupal 7 the fieldset output includes an extra span // When called from within Drupal, DRUPAL_CORE_COMPATIBILITY can determine // version. When called by Ajax version has to be sent in $options. if (defined('DRUPAL_CORE_COMPATIBILITY') && DRUPAL_CORE_COMPATIBILITY === '7.x' || isset($options['generator']) && stristr($options['generator'], 'Drupal 7')) { $legendContent = "<span class=\"fieldset-legend\">{$fieldset}</span>"; } else { $legendContent = $fieldset; } $r .= "<legend>{$legendContent}</legend>\n"; $r .= "<div class=\"fieldset-wrapper\">\n"; $r .= $fieldsets[$fieldset]; $r .= "</div>\n"; $r .= "\n</fieldset>\n"; // any subsequent fieldset should be collapsed $class = 'collapsible collapsed'; } self::$nocache = $oldnocache; return $r; }