bluellyr Posted March 5, 2019 Share Posted March 5, 2019 Hi, I have made a module that adds new configuration fields to all field types. One of the issues that I am struggling with is , the new configuration fields works fine when editing the field itself but on the template context the field value is not saved when changed. When saving the new value when editing the the field on the template context the wire('input')->post is empty and I do not know how to get the new value to save it on the field "value" attribute or what might be wrong with the code. In attach is the file of the module "ExtraFieldConfigurations.module". Many thanks ExtraFieldConfigurations.module Link to comment Share on other sites More sharing options...
Robin S Posted March 6, 2019 Share Posted March 6, 2019 I'm not sure what's going wrong in your module, but maybe it helps you to look at this proof of concept module which adds a config field named "Animal" to every field and allows setting the field in template context. ExtraFieldConfig.module <?php namespace ProcessWire; /** * * ExtraFieldConfig * * @author Robin Sallis * * ProcessWire 3.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class ExtraFieldConfig extends WireData implements Module { /** * Module information */ public static function getModuleInfo() { return array( 'title' => 'Extra Field Config', 'summary' => 'Test module for adding and extra config field to Fieldtype config.', 'version' => '0.1.0', 'author' => 'Robin Sallis', 'autoload' => true, 'requires' => 'ProcessWire>=3.0.0', ); } /** * Ready */ public function ready() { $this->addHookAfter('Fieldtype::getConfigInputfields', $this, 'addConfigField'); $this->addHookAfter('Fieldtype::getConfigAllowContext', $this, 'allowContext'); } /** * Add config field * * @param HookEvent $event */ protected function addConfigField(HookEvent $event) { $field = $event->arguments(0); $wrapper = $event->return; /* @var InputfieldText $f */ $f = $this->wire('modules')->InputfieldText; $f_name = 'animal'; $f->name = $f_name; $f->label = $this->_('Animal'); $f->value = $field->$f_name; $wrapper->add($f); } /** * Allow setting config field in template context * * @param HookEvent $event */ protected function allowContext(HookEvent $event) { $allowed = $event->return; $allowed[] = 'animal'; $event->return = $allowed; } } 2 Link to comment Share on other sites More sharing options...
bluellyr Posted March 15, 2019 Author Share Posted March 15, 2019 Many thanks for you reply, I am going to check my code using your example. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now