Jump to content
bluellyr

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

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...