/** * 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; }
/** * 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; }
/** * 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 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) { $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 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; }
/** * 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 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 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; }