Extending WebTemplate Classes

By extending a WebTemplate class and registering that class to a node type you may customise the operations which are peformed on nodes.

For example, you may extend the contact class and override the setAttributes function to ensure that the first name attribute begins with a capital letter.

class CustomContact extends WTContact
{
  // override the setAttributes function of the contact class
  public function setAttributes($attributes) {
    // check to see if "First Name" is being set
    if(array_key_exists("First Name", $attributes)) {
      // make sure the first letter is capitalised
      $attributes["First Name"] = ucwords($attributes["First Name"]);
    }
    // call the parent's function
    return parent::setAttributes($attributes);
  }
}

// register the class to the node type
$GLOBALS["WT"]->registerNodeTypeClass("Contact", "CustomContact");