/** * Return an InputfieldWrapper of Inputfields necessary to configure this module * * Values will be populated to the Inputfields automatically. However, you may also retrieve * any of the values from $this->[property]; as needed. * * Descending classes should call this method at the top of their getInputfields() method. * * Use this method only if defining Inputfield objects programatically. If definining via * an array then you should not implement this method. * * @return InputfieldWrapper * */ public function getInputfields() { foreach ($this->getDefaults() as $key => $value) { $this->set($key, $value); } $inputfields = new InputfieldWrapper(); if (count($this->inputfieldsArray)) { $inputfields->add($this->inputfieldsArray); } return $inputfields; }
public function getConfig(array $data) { // check that they have the required PW version if (version_compare(wire('config')->version, '2.2.13', '<')) { $this->error("Email Image requires ProcessWire 2.2.13 or newer. Please update."); } $modules = wire('modules'); $form = new InputfieldWrapper(); $field = $modules->get("InputfieldText"); $field->attr('name', 'pop3_hostname'); $field->attr('value', $data['pop3_hostname']); $field->label = __('POP3 hostname'); $field->columnWidth = 50; $field->required = true; $form->add($field); $field = $modules->get("InputfieldInteger"); $field->attr('name', 'pop3_port'); $field->attr('value', $data['pop3_port']); $field->label = __('POP3 port'); $field->columnWidth = 20; $field->required = true; $form->add($field); $field = $modules->get("InputfieldInteger"); $field->attr('name', 'wait_seconds'); $field->attr('value', $data['wait_seconds']); $field->label = __('Check every # seconds'); $field->columnWidth = 30; $field->required = true; $form->add($field); $field = $modules->get("InputfieldText"); $field->attr('name', 'pop3_user'); $field->attr('value', $data['pop3_user']); $field->label = __('POP3 user'); $field->columnWidth = 50; $field->required = true; $form->add($field); $field = $modules->get("InputfieldText"); $field->attr('name', 'pop3_password'); $field->attr('value', $data['pop3_password']); $field->attr('type', 'password'); $field->label = __('POP3 password'); $field->columnWidth = 50; $field->required = true; $form->add($field); $field = $modules->get("InputfieldTextarea"); $field->attr('name', 'valid_senders'); $field->attr('value', $data['valid_senders']); $field->label = __('Valid senders'); $field->description = __('Enter a list of email addresses (1 per line) to process emails from.'); $form->add($field); $fieldset = $modules->get('InputfieldFieldset'); $fieldset->label = __('Advanced'); $fieldset->attr('name', '_advanced'); $fieldset->collapsed = Inputfield::collapsedYes; $field = $modules->get('InputfieldCheckbox'); $field->attr('name', 'pop3_apop'); $field->attr('value', 1); $field->attr('checked', $data['pop3_apop'] ? 'checked' : ''); $field->columnWidth = 50; $field->label = __('Use APOP?'); $field->notes = __('In rare cases this may be required.'); $fieldset->add($field); $field = $modules->get('InputfieldCheckbox'); $field->attr('name', 'pop3_tls'); $field->attr('value', 1); $field->attr('checked', $data['pop3_tls'] ? 'checked' : ''); $field->columnWidth = 50; $field->label = __('Use TLS?'); $field->notes = __('GMail uses TLS and port 993.'); $fieldset->add($field); $field = $modules->get("InputfieldText"); $field->attr('name', 'pop3_body_txt_start'); $field->attr('value', $data['pop3_body_txt_start']); $field->label = __('Tag or word that starts email body text for image description'); $field->notes = __('Example: [text]'); $field->columnWidth = 50; $fieldset->add($field); $field = $modules->get("InputfieldText"); $field->attr('name', 'pop3_body_txt_end'); $field->attr('value', $data['pop3_body_txt_end']); $field->label = __('Tag or word that ends email body text for image description'); $field->notes = __('Example: [/text]'); $field->columnWidth = 50; $fieldset->add($field); $form->add($fieldset); $field = $modules->get('InputfieldCheckbox'); $field->attr('name', '_test_settings'); $field->label = __('Test settings now'); $field->attr('value', 1); $field->attr('checked', ''); $form->add($field); if (wire('session')->test_settings) { wire('session')->remove('test_settings'); $field->notes = $this->testSettings(); } else { if (wire('input')->post->_test_settings) { wire('session')->set('test_settings', 1); } } $file = wire('config')->paths->templates . 'email-images.php'; if (!is_file($file)) { $this->error("Please copy the file /site/modules/EmailImage/email-images.php to /site/templates/email-images.php"); } return $form; }
/** * Get any custom configuration fields for this Inputfield * * Intended to be extended or overriden * * @return FormfieldWrapper * */ public function ___getConfigInputfields() { $fields = new InputfieldWrapper(); $field = $this->modules->get("InputfieldRadios"); $field->attr('name', 'collapsed'); $field->label = "How should this field be displayed in the editor?"; $field->addOption(self::collapsedNo, "Always open"); $field->addOption(self::collapsedBlank, "Collapsed only when blank"); $field->addOption(self::collapsedYes, "Always collapsed, requiring a click to open"); $field->addOption(self::collapsedHidden, "Hidden, not shown in the editor"); $field->attr('value', (int) $this->collapsed); $fields->append($field); if ($this->config->advanced) { $field = $this->modules->get('InputfieldCheckbox'); $field->label = 'Required?'; $field->attr('name', 'required'); $field->attr('value', 1); $field->attr('checked', $this->required ? 'checked' : ''); $field->collapsed = self::collapsedBlank; $field->description = "If checked, a value will be required for this field."; $fields->append($field); } return $fields; }
* This init file is called before ProcessWire starts rendering the page or executing the process * * This is a place to attach hooks or modify render-specific settings before they are used. * */ $config->inputfieldColumnWidthSpacing = 0; // percent spacing between columns $markup = InputfieldWrapper::getMarkup(); $markup['item_label'] = "\n\t\t<label class='InputfieldHeader' for='{for}'>{out}</label>"; $markup['item_label_hidden'] = "\n\t\t<label class='InputfieldHeader InputfieldHeaderHidden'><span>{out}</span></label>"; $markup['item_content'] = "\n\t\t<div class='InputfieldContent'>\n{out}\n\t\t</div>"; InputfieldWrapper::setMarkup($markup); $classes = InputfieldWrapper::getClasses(); $classes['item'] = "Inputfield {class} Inputfield_{name}"; $classes['item_error'] = "InputfieldStateError"; InputfieldWrapper::setClasses($classes); wire()->addHookBefore('MarkupPagerNav::render', null, 'hookMarkupPagerNavRender'); /** * Change the default prev/next links for MarkupPagerNav * */ function hookMarkupPagerNavRender(HookEvent $event) { $options = $event->arguments(1); if (!isset($options['nextItemLabel'])) { $options['nextItemLabel'] = "<i class='fa fa-angle-right'></i>"; $options['previousItemLabel'] = "<i class='fa fa-angle-left'></i>"; $options['separatorItemLabel'] = "<span class='detail'>…</span>"; $event->arguments(1, $options); } }
/** * Get any configuration fields associated with the Inputfield * * @return InputfieldWrapper * */ public function ___getConfigInputfields() { $wrapper = new InputfieldWrapper(); $fieldgroupContext = $this->flags & Field::flagFieldgroupContext; if (!$fieldgroupContext) { $inputfields = new InputfieldWrapper(); $inputfields->head = $this->_('Field type details'); $inputfields->attr('title', $this->_('Details')); try { $fieldtypeInputfields = $this->type->getConfigInputfields($this); if ($fieldtypeInputfields) { foreach ($fieldtypeInputfields as $inputfield) { $inputfields->append($inputfield); } } } catch (Exception $e) { $this->error($e->getMessage()); } if (count($inputfields)) { $wrapper->append($inputfields); } } else { // we currently exclude fieldtype configuration changes when in fieldgroup context // not sure that we need to, but keeping it simple to start } $inputfields = new InputfieldWrapper(); $dummyPage = $this->fuel('pages')->get("/"); // only using this to satisfy param requirement if ($inputfield = $this->getInputfield($dummyPage)) { if (!$fieldgroupContext) { $inputfields->head = $this->_('Input field settings'); } $inputfields->attr('title', $this->_('Input')); $inputfieldInputfields = $inputfield->getConfigInputfields(); if ($inputfieldInputfields) { foreach ($inputfieldInputfields as $i) { // currently we only support collapsed and columnWidth for fieldgroup context // however we may support everything after starting with these limited options for awhile if ($fieldgroupContext && !in_array($i->name, array('visibility', 'collapsed', 'columnWidth', 'required', 'requiredIf', 'showIf'))) { continue; } $inputfields->append($i); } } } $wrapper->append($inputfields); return $wrapper; }
/** * Get inputfields for advanced settings of the Field and Fieldtype * * In most cases, you will want to override getConfigInputfields rather than this method * * @TODO should this be moved back into modules/Process/ProcessField.module? (that's where it is saved) * * @param Field $field * @return InputfieldWrapper * */ public function ___getConfigAdvancedInputfields(Field $field) { // advanced settings $inputfields = new InputfieldWrapper(); if ($this->getLoadQueryAutojoin($field, new DatabaseQuerySelect())) { $f = $this->modules->get('InputfieldCheckbox'); $f->label = 'Autojoin'; $f->attr('name', 'autojoin'); $f->attr('value', 1); $f->attr('checked', $field->flags & Field::flagAutojoin ? 'checked' : ''); $f->description = '' . "If checked, the data for this field will be loaded with every instance of the page, regardless of whether it's used at the time. " . "If unchecked, the data will be loaded on-demand, and only when the field is specifically accessed. " . "Enabling autojoin also allows the field to be used as a key for sorting pages."; $inputfields->append($f); } $f = $this->modules->get('InputfieldCheckbox'); $f->attr('name', 'global'); $f->label = 'Global'; $f->description = "If checked, ALL pages will be required to have this field. " . "It will be automatically added to any fieldgroups/templates that don't already have it. " . "This does not mean that a value is required in the field, only that the editable field will exist in all pages."; $f->attr('value', 1); if ($field->flags & Field::flagGlobal) { $f->attr('checked', 'checked'); } else { $f->collapsed = true; } $inputfields->append($f); if ($this->config->advanced) { $f = $this->modules->get('InputfieldCheckbox'); $f->attr('name', 'system'); $f->label = 'System'; $f->description = "If checked, this field is considered a system field and is not renameable or deleteable. " . "System fields may not be undone using ProcessWire's API."; $f->attr('value', 1); if ($field->flags & Field::flagSystem) { $f->attr('checked', 'checked'); } else { $f->collapsed = true; } $inputfields->append($f); $f = $this->modules->get('InputfieldCheckbox'); $f->attr('name', 'permanent'); $f->label = 'Permanent'; $f->description = "If checked, this field is considered a permanent field and it can't be removed from any of the " . "system templates/fieldgroups to which it is attached. This flag may not be undone using ProcessWire's API."; $f->attr('value', 1); if ($field->flags & Field::flagPermanent) { $f->attr('checked', 'checked'); } else { $f->collapsed = true; } $inputfields->append($f); } return $inputfields; }
/** * Set custom classes for render, see self::$classes at top for reference. * * @param array $classes * */ public static function setClasses(array $classes) { self::$classes = array_merge(self::$classes, $classes); }
/** * 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; }
/** * Get any custom configuration fields for this Inputfield * * Intended to be extended by each Inputfield as needed to add more config options. * * NOTE: Inputfields with a name that starts with an underscore, i.e. "_myname" are assumed to be for runtime * use and are NOT stored in the database. * * @return InputfieldWrapper * */ public function ___getConfigInputfields() { $conditionsText = $this->_('Conditions are expressed with a "field=value" selector containing fields and values to match. Multiple conditions should be separated by a comma.'); $conditionsNote = $this->_('Read more about [how to use this](http://processwire.com/api/selectors/inputfield-dependencies/).'); $fields = new InputfieldWrapper(); $fieldset = $this->modules->get('InputfieldFieldset'); $fieldset->label = $this->_('Visibility'); $fieldset->attr('name', 'visibility'); $fieldset->icon = 'eye'; $field = $this->modules->get("InputfieldSelect"); $field->attr('name', 'collapsed'); $field->label = $this->_('Presentation'); $field->description = $this->_("How should this field be displayed in the editor?"); $field->addOption(self::collapsedNo, $this->_('Always open (default)')); $field->addOption(self::collapsedNever, $this->_('Always open and cannot be collapsed')); $field->addOption(self::collapsedBlank, $this->_("Collapsed only when blank")); $field->addOption(self::collapsedPopulated, $this->_("Collapsed only when populated")); $field->addOption(self::collapsedYes, $this->_("Always collapsed, requiring a click to open")); $field->addOption(self::collapsedHidden, $this->_("Hidden, not shown in the editor")); $field->addOption(self::collapsedYesLocked, $this->_("Always collapsed and not editable (locked)")); $field->addOption(self::collapsedNoLocked, $this->_("Open when populated and not editable (locked)")); $field->attr('value', (int) $this->collapsed); $fieldset->append($field); $field = $this->modules->get("InputfieldText"); $field->label = $this->_('Show this field only if...'); $field->description = $this->_('Enter the conditions under which the field will be shown.') . ' ' . $conditionsText; $field->notes = $conditionsNote; $field->icon = 'question-circle'; $field->attr('name', 'showIf'); $field->attr('value', $this->getSetting('showIf')); $field->collapsed = Inputfield::collapsedBlank; $field->showIf = "collapsed!=" . self::collapsedHidden; $fieldset->append($field); $fieldset->collapsed = $this->collapsed == Inputfield::collapsedNo && !$this->getSetting('showIf') ? Inputfield::collapsedYes : Inputfield::collapsedNo; $fields->append($fieldset); $field = $this->modules->get('InputfieldInteger'); $value = (int) $this->getSetting('columnWidth'); if ($value < 10 || $value >= 100) { $value = 100; } $field->label = sprintf($this->_("Column Width (%d%%)"), $value); $field->icon = 'arrows-h'; $field->attr('id+name', 'columnWidth'); $field->attr('type', 'text'); $field->attr('maxlength', 4); $field->attr('size', 4); $field->attr('max', 100); $field->attr('value', $value . '%'); $field->description = $this->_("The percentage width of this field's container (10%-100%). If placed next to other fields with reduced widths, it will create floated columns."); // Description of colWidth option $field->notes = $this->_("Note that not all fields will work at reduced widths, so you should test the result after changing this."); // Notes for colWidth option if (!wire('input')->get('process_template')) { if ($value == 100) { $field->collapsed = Inputfield::collapsedYes; } } $fields->append($field); if (!$this instanceof InputfieldWrapper) { $field = $this->modules->get('InputfieldCheckbox'); $field->label = $this->_('Required?'); $field->icon = 'asterisk'; $field->attr('name', 'required'); $field->attr('value', 1); $field->attr('checked', $this->getSetting('required') ? 'checked' : ''); $field->description = $this->_("If checked, a value will be required for this field."); $field->collapsed = $this->getSetting('required') ? Inputfield::collapsedNo : Inputfield::collapsedYes; $fields->add($field); $field = $this->modules->get('InputfieldText'); $field->label = $this->_('Required only if...'); $field->icon = 'asterisk'; $field->description = $this->_('Enter the conditions under which a value will be required for this field.') . ' ' . $conditionsText; $field->notes = $conditionsNote; $field->attr('name', 'requiredIf'); $field->attr('value', $this->getSetting('requiredIf')); $field->collapsed = $field->attr('value') ? Inputfield::collapsedNo : Inputfield::collapsedYes; $field->showIf = "required>0"; $fields->add($field); } return $fields; }
/** * Custom processing for the options string in getConfigInputfields * * Detects and confirms option deletions. * * @param Inputfield $inputfield For the _options inputfield * @throws WireException * */ protected function process(Inputfield $inputfield) { $value = $this->wire('input')->post('_options'); if ($this->wire('process') != 'ProcessField' || !$this->wire('user')->isSuperuser()) { return; } $ns = "{$this}{$this->field}"; // namespace for session if (!is_null($value)) { // _options has been posted if ($this->manager->useLanguages() && $inputfield->useLanguages) { // multi-language $valuesPerLanguage = array(); $changed = false; foreach ($this->wire('languages') as $language) { $key = $language->isDefault() ? "_options" : "_options__{$language}"; $valuesPerLanguage[$language->id] = $this->wire('input')->post($key); $key = $language->isDefault() ? "value" : "value{$language}"; if ($inputfield->{$key} != $valuesPerLanguage[$language->id]) { $changed = true; } } if ($changed) { $this->manager->setOptionsStringLanguages($this->field, $valuesPerLanguage, false); } } else { // non multi-language if ($value != $inputfield->attr('value')) { $this->manager->setOptionsString($this->field, $value, false); } } $removedOptionIDs = $this->manager->getRemovedOptionIDs($this->field); // identified for removal if (count($removedOptionIDs)) { // stuff in session for next request $this->wire('session')->set($ns, 'removedOptionIDs', $removedOptionIDs); } $deleteOptionIDs = $this->wire('input')->post('_delete_options'); $deleteConfirm = (int) $this->wire('input')->post('_delete_confirm'); if ($deleteOptionIDs && $deleteConfirm) { // confirmed deleted if (!ctype_digit(str_replace(',', '', $deleteOptionIDs))) { throw new WireException("Invalid deleteOptionIDs"); } $deleteOptionIDs = explode(',', $deleteOptionIDs); foreach ($deleteOptionIDs as $key => $value) { $deleteOptionIDs[$key] = (int) $value; } $this->manager->deleteOptionsByID($this->field, $deleteOptionIDs); } } else { // options not posted, check if there are any pending session activities $removedOptionIDs = $this->wire('session')->get($ns, 'removedOptionIDs'); if (count($removedOptionIDs)) { $f = $this->wire('modules')->get('InputfieldHidden'); $f->attr('name', '_delete_options'); $f->attr('value', implode(',', $removedOptionIDs)); $this->inputfields->prepend($f); // setup for confirmation $f = $this->wire('modules')->get('InputfieldCheckbox'); $f->attr('name', '_delete_confirm'); $f->label = $this->_('Please confirm that you want to delete options'); $f->label2 = $this->_n('Delete this option', 'Delete these options', count($removedOptionIDs)); $this->warning($f->label); $removeOptions = $this->manager->getOptionsByID($this->field, $removedOptionIDs); $delimiter = $this->_('DELETE:') . ' '; $f->description .= $delimiter . $removeOptions->implode("\n{$delimiter}", 'title'); // collapse other inputfields since we prefer them to focus on this one only for now foreach ($this->inputfields as $i) { $i->collapsed = Inputfield::collapsedYes; } // add our confirmation field $this->inputfields->prepend($f); // was stuffed in session from previous request, unset it now since this is a one time thing $this->wire('session')->remove($ns, 'removedOptionIDs'); } } }
public function getConfig(array $data) { // check that they have the required PW version if (version_compare(wire('config')->version, '2.5.11', '<')) { $this->error(" requires ProcessWire 2.5.11 or newer. Please update."); } $modules = wire('modules'); if ($modules->isInstalled('InputfieldRangeSlider')) { $rangeSliderInfo = InputfieldRangeSlider::getModuleInfo(); } $hasSlider = $modules->isInstalled('InputfieldRangeSlider') && version_compare($rangeSliderInfo['version'], '1.0.4', '>='); $form = new InputfieldWrapper(); $fieldset = $modules->get('InputfieldFieldset'); $fieldset->label = 'Quality & Sharpening'; $fieldset->attr('name', '_quality_sharpening'); $fieldset->description = __('Here you can set sitewide options for Quality and Sharpening'); $fieldset->collapsed = Inputfield::collapsedNo; $field = $modules->get('InputfieldCheckbox'); $field->attr('name', 'manualSelectionDisabled'); $field->label = __('Globally disable the usage of DropDown-Selects for Quality & Sharpening!'); $field->attr('value', 1); $field->attr('checked', $data['manualSelectionDisabled'] ? 'checked' : ''); $field->columnWidth = 100; $fieldset->add($field); $field = $modules->get('InputfieldSelect'); $field->label = 'global setting for Sharpening'; $field->attr('name', 'optionSharpening'); if (is_numeric($data['optionSharpening']) && isset(self::$sharpeningValues[intval($data['optionSharpening'])])) { $value = $data['optionSharpening']; } elseif (is_string($data['optionSharpening']) && in_array($data['optionSharpening'], self::$sharpeningValues)) { $flippedA = array_flip(self::$sharpeningValues); $value = strval($flippedA[$data['optionSharpening']]); } else { $value = '1'; } $field->attr('value', intval($value)); $field->addOptions(self::$sharpeningValues); $field->description = __('sharpening: none | soft | medium | strong'); $field->columnWidth = 50; $field->showIf = "manualSelectionDisabled=1"; $fieldset->add($field); $field = $modules->get('InputfieldInteger'); $field->label = 'global setting for Quality'; $field->attr('name', 'optionQuality'); $field->attr('value', $data['optionQuality'] > 0 && $data['optionQuality'] <= 100 ? $data['optionQuality'] : 90); $field->description = __('quality: 1-100 where higher is better but bigger'); $field->columnWidth = 50; $field->showIf = "manualSelectionDisabled=1"; if ($hasSlider) { $field->collapsed = Inputfield::collapsedHidden; $fieldset->add($field); $fieldS = $modules->get('InputfieldRangeSlider'); // read value from optionQuality, not from optionQualitySlider $fieldS->label = 'quality'; $fieldS->attr('name', 'optionQualitySlider'); $fieldS->attr('value', array('min' => $data['optionQuality'] > 0 && $data['optionQuality'] <= 100 ? $data['optionQuality'] : 90)); $fieldS->isrange = false; $fieldS->minValue = 1; $fieldS->maxValue = 100; $fieldS->step = 1; $fieldS->width = 100; $fieldS->description = __('quality: 1-100 where higher is better but bigger'); $fieldS->columnWidth = 50; $fieldS->showIf = "manualSelectionDisabled=1"; $fieldset->add($fieldS); } else { $fieldset->add($field); } $form->add($fieldset); // $field = $modules->get("InputfieldMarkup"); // $field->attr('name', 'info1'); // $field->collapsed = Inputfield::collapsedNo; // $field->attr('value', // "THIS IS A TEMPORARY PLACEHOLDER FOR LATER CONTRIBUTIONS<br /><br />" // ); // $field->label = __('Info'); // $field->columnWidth = 100; // $form->add($field); // $field = $modules->get('InputfieldCheckbox'); // $field->attr('name', 'remove_all_variations'); // $field->label = __('Remove all Imagevariations to clear the images-cache sitewide!'); // $field->attr('value', 1); // $field->attr('checked', ''); // $field->columnWidth = 65; // $form->add($field); // // if(wire('session')->remove_all_variations) { // wire('session')->remove('remove_all_variations'); // $testmode = '1'==$data['do_only_test_run'] ? true : false; // $field->notes = $this->doTheDishes( !$testmode ); // } else if(wire('input')->post->remove_all_variations) { // wire('session')->set('remove_all_variations', 1); // } // // $field = $modules->get('InputfieldCheckbox'); // $field->attr('name', 'do_only_test_run'); // $field->label = __('Run only in test mode! Do not delete the variations.'); // $field->attr('value', 1); // $field->attr('checked', '1'); // $field->columnWidth = 35; // $form->add($field); return $form; }
/** * Populate any configuration inputfields to the given $inputfields wrapper for $process * * @param InputfieldWrapper $inputfields * @param Process $process * */ public function addConfigInputfields(InputfieldWrapper $inputfields) { $field = $this->wire('modules')->get('InputfieldCheckbox'); $field->attr('name', 'useBookmarks'); $field->label = $this->_('Allow use of bookmarks?'); $field->description = $this->_('Bookmarks enable you to create shortcuts to pages from this module, configurable by user role. Useful for large applications.'); $field->icon = 'bookmark-o'; if ($this->process->useBookmarks) { $field->attr('checked', 'checked'); } $inputfields->add($field); }
/** * Get any configuration fields associated with the Inputfield * * @return InputfieldWrapper * */ public function ___getConfigInputfields() { $wrapper = new InputfieldWrapper(); $inputfields = $this->modules->get("InputfieldFieldset"); $inputfields->description = "The following settings are requested by {$this->type->name}"; $inputfields->label = "Fieldtype Settings"; $fieldtypeInputfields = $this->type->getConfigInputfields($this); if ($fieldtypeInputfields) { foreach ($fieldtypeInputfields as $inputfield) { $inputfields->append($inputfield); } } if (count($inputfields)) { $wrapper->append($inputfields); } $inputfields = $this->modules->get("InputfieldFieldset"); $dummyPage = $this->fuel('pages')->get("/"); // only using this to satisfy param requirement if ($inputfield = $this->getInputfield($dummyPage)) { $inputfieldLabel = $inputfield->className(); $inputfields->description = "The following settings are requested by {$inputfieldLabel}, which accompanies {$this->type->name}"; $inputfields->label = "Inputfield Settings"; $inputfieldInputfields = $inputfield->getConfigInputfields(); if ($inputfieldInputfields) { foreach ($inputfieldInputfields as $i) { $inputfields->append($i); } } } $wrapper->append($inputfields); return $wrapper; }
/** * Get any configuration Inputfields common to all InputfieldWrappers * */ public function ___getConfigInputfields() { $fields = new InputfieldWrapper(); $field = $this->modules->get("InputfieldRadios"); $field->attr('name', 'collapsed'); $field->label = $this->_("How should this field be displayed?"); $field->addOption(Inputfield::collapsedNo, $this->_("Always open")); $field->addOption(Inputfield::collapsedYes, $this->_("Always collapsed, requiring a click to open")); $field->attr('value', (int) $this->collapsed); $fields->append($field); return $fields; }
/** * Get all of the Inputfields associated with the provided Page and populate them * * @param Page $page * @return Inputfield acting as a container for multiple Inputfields * */ public function getPageInputfields(Page $page) { $container = new InputfieldWrapper(); foreach ($this as $field) { $inputfield = $field->getInputfield($page); if (!$inputfield) { continue; } $inputfield->value = $page->get($field->name); $container->add($inputfield); } return $container; }
/** * Get any custom configuration fields for this Inputfield * * Intended to be extended or overriden * * @return FormfieldWrapper * */ public function ___getConfigInputfields() { $fields = new InputfieldWrapper(); $field = $this->modules->get("InputfieldSelect"); $field->attr('name', 'collapsed'); $field->label = $this->_("Visibility"); $field->description = $this->_("How should this field be displayed in the editor?"); $field->addOption(self::collapsedNo, $this->_('Always open (default)')); $field->addOption(self::collapsedBlank, $this->_("Collapsed only when blank")); $field->addOption(self::collapsedPopulated, $this->_("Collapsed only when populated")); $field->addOption(self::collapsedYes, $this->_("Always collapsed, requiring a click to open")); $field->addOption(self::collapsedHidden, $this->_("Hidden, not shown in the editor")); $field->attr('value', (int) $this->collapsed); if ($this->collapsed == Inputfield::collapsedNo) { $field->collapsed = Inputfield::collapsedYes; } $fields->append($field); if (!$this instanceof InputfieldWrapper) { $field = $this->modules->get('InputfieldInteger'); $value = (int) $this->getSetting('columnWidth'); if ($value < 10 || $value >= 100) { $value = 100; } $field->label = sprintf($this->_("Column Width (%d%%)"), $value); $field->attr('id+name', 'columnWidth'); $field->attr('maxlength', 4); $field->attr('size', 4); $field->attr('value', $value . '%'); $field->description = $this->_("The percentage width of this field's container (10%-100%). If placed next to other fields with reduced widths, it will create floated columns."); // Description of colWidth option $field->notes = $this->_("Note that not all fields will work at reduced widths, so you should test the result after changing this."); // Notes for colWidth option if (!wire('input')->get('process_template')) { if ($value == 100) { $field->collapsed = Inputfield::collapsedYes; } } $fields->append($field); } if ($this->config->advanced) { $field = $this->modules->get('InputfieldCheckbox'); $field->label = $this->_('Required?'); $field->attr('name', 'required'); $field->attr('value', 1); $field->attr('checked', $this->required ? 'checked' : ''); $field->collapsed = self::collapsedBlank; $field->description = $this->_("If checked, a value will be required for this field."); $fields->append($field); } return $fields; }
/** * 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 all of the Inputfields associated with the provided Page and populate them * * @param Page $page * @param string $contextStr Optional context string to append to all the Inputfield's names (helper for things like repeaters) * @return Inputfield acting as a container for multiple Inputfields * */ public function getPageInputfields(Page $page, $contextStr = '') { $container = new InputfieldWrapper(); foreach ($this as $field) { // get a clone in the context of this fieldgroup, if it has contextual settings if (isset($this->fieldContexts[$field->id])) { $field = $this->getField($field->id, true); } $inputfield = $field->getInputfield($page, $contextStr); if (!$inputfield) { continue; } $inputfield->value = $page->get($field->name); $container->add($inputfield); } return $container; }
/** * Render a value using an Inputfield's renderValue() method * * @param $value * @return string * */ protected function renderInputfieldValue($value) { $field = $this->getField(); $page = $this->getPage(); if (!$page->id || !$field) { return (string) $value; } /** @var Inputfield $inputfield */ $inputfield = $field->getInputfield($page); if (!$inputfield) { return (string) $value; } $inputfield->columnWidth = 100; $inputfield->attr('value', $value); if (method_exists($inputfield, 'setField')) { $inputfield->setField($field); } if (method_exists($inputfield, 'setPage')) { $inputfield->setPage($page); } $wrapper = new InputfieldWrapper(); $wrapper->quietMode = true; $wrapper->add($inputfield); $out = $wrapper->renderValue(); return $out; }
/** * Get any configuration fields associated with the Inputfield * * @return InputfieldWrapper * */ public function ___getConfigInputfields() { $wrapper = new InputfieldWrapper(); $inputfields = new InputfieldWrapper(); $inputfields->head = "Field type details"; $inputfields->attr('title', 'Details'); $fieldtypeInputfields = $this->type->getConfigInputfields($this); if ($fieldtypeInputfields) { foreach ($fieldtypeInputfields as $inputfield) { $inputfields->append($inputfield); } } if (count($inputfields)) { $wrapper->append($inputfields); } $inputfields = new InputfieldWrapper(); $dummyPage = $this->fuel('pages')->get("/"); // only using this to satisfy param requirement if ($inputfield = $this->getInputfield($dummyPage)) { $inputfieldLabel = $inputfield->className(); $inputfields->head = "Input field settings"; $inputfields->attr('title', 'Input'); $inputfieldInputfields = $inputfield->getConfigInputfields(); if ($inputfieldInputfields) { foreach ($inputfieldInputfields as $i) { $inputfields->append($i); } } } $wrapper->append($inputfields); return $wrapper; }