Extending a module - edit form example

Here's how you can customise a module to add custom functionality around the edit form, by sub-classing the WebMatEdit class.

In your module, look for the file

/inc/item_edit.inc

If this file does not exist, for example in a new custom module, then you need to create it.

You need to create the class that extends WebMATEdit

class RegistrationsItemWebMATEdit extends WebMATEdit
{
}

There are a number of functions in WebMATEdit and it's parent classes such as WebMATItem that are provided as hooks for custom code.

Here is example code using these hook functions for a hypothetical registrations module.

<?php
/**
* Registrations edit class
* 
* @package Registrations
*/

class RegistrationsItemWebMATEdit extends WebMATEdit
{

private $debug = true;

/**
 * Override here to change the module toolbar links
 */
function editTableLinks(& $links, $id, $item) {
	global $USER;
	
	// if (!$this->db_functions->isClosed($id)) {
		// bcrm_unset($links, 'Delete');
	// }
	
	// $links['Registrations'] = array(
		// 'href' => 'confirm.php', //$this->getFileSetHref($this->edit_link), 
		// 'text' => 'Confirm registration', 
		// 'icon' => 'page_misc.png',
		// 'title' => 'Confirm'
		// );
	
}
	
/**
 * any processing required before adding to the form is created
 * this is an opportunity to alter the data definition
 */
function beforeForm(&$id, &$item, &$error_msg) {
	global $SERVICES;

	//$this->dd->changeAttributes(array('field_key' => 'id', 'label' => 'A new label'));
	
}



/**
 * do further processing after the submit has completed
 */
function doSubmitEnd($id) { 
	//here is the data array
	//print_r($this->item);
	
	//temp
	if (1) {
		//do stuff
	}		
}

/**
 * go somewhere else after completing
 */
function doRedirect($id) {
	print ("<h3>Landing page with will be here</h3>");
	//header('Location: my_page.php');
	exit();
}

}
?>
 
extending_a_module_-_edit_form_example.txt · Last modified: 2010/03/23 13:52 by 203.97.219.50
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki