Jump to content

Need help - Failed to save template context field extra configuration values


bluellyr
 Share

Recommended Posts

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

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;
	}

}

2019-03-07_125341.png.adfd56ba9ebd5c6b4e2ebcc3b6a24c56.png

2019-03-07_125413.png.3f871c63f46aa9e2f72cbac669cdfc62.png

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...