The Pet module is Peter's Exogenic Tackon. Tackon because the module is tacked on to Drupal. Exogenic because it does not fit the Drupal coding style and uses classes instead of functions.
In earlier releases of Drupal, I used Pet with the menu module and the menu on-the-fly module to create a hierarchical menu structure. Menu on-the-fly provided an easy way to assign page nodes to menu items. Pet lets you specify the node for the home page.
I then added taxonomy for one of the other Drupal modules and decided to make taxonomy work for the menu structure. The home page node was moved out to a separate module named Vocabulary Node. The Taxonomy Menu module replaced menu on-the-fly.
Pet provided colours for areas within the menu structure and could be used to provide any other attribute for the same area. Pet could also provide separate CSS overrides for each area.
The current pet provides logging and other functions for the other Pet modules. The other modules are listed at the bottom of this page.
Install
- Download pet.zip or pet.tar.gz. If your browser does not give you the option to save the files then try clicking the right mouse button.
- Expand pet.zip into your modules directory as a subdirectory named pet.
- Some components create database tables. Some components create variables using Drupal's variable system. All the variables and tables have pet_ as a prefix.
- Visit Administration » Modules and switch on Pet.
You are now ready to add pet extensions for additional functionality.
pet.module
pet()
pet() provides objects for other modules. The following line shows the definition of the function.$object = pet($module_name = 'pet', $class_name = '', $file_name = '')
Here is an example for module abc.$abc = pet('abc', 'abc', 'abc.class.php')
A module can tell Drupal to autoload the class file by adding the class file name to a files[] line in the module's .info file. For module abc, the files[] line will look like the following line.files[] = abc.class.php
The following line is pet() for cases where the class is autoloaded by Drupal.$abc = pet('abc')
pet() caches the object for the life of the page request to ensure every call for a specific module will return the same object during the same page request.
pet_module_name()
pet_module_name() provides the internal name, or in Drupalese machine name
, of the module for code needing to build identifiers dynamically.
pet_display_name()
pet_display_name() provides a displayable human readable version of the module name for use in Web pages. pet_display_name() also accepts another name and returns that name in a displayable form. pet_display_name('example-module_name') returns Example module name. Try your text in the following form.
$other_name = '';
$display_name = '';
if(isset($_POST['other_name']) and $_POST['other_name'] != '' and function_exists('pet_display_name'))
{
$other_name = htmlentities($_POST['other_name']);
$display_name = pet_display_name($other_name);
}
?>
pet_log_object()
pet_log_object() returns an object created from class pet_log. pet_log_object() accepts a module display name for use by pet_log in messages. The name becomes the watchdog() type field and is added to the front of other messages. pet_log_object('Example module') returns an object that would create watchdog messages starting with watchdog('Example module', .
pet_log()
pet_log() logs messages using the log() method of the pet_log class. The following line shows the pet_log() parameters and their defaults.
pet_log($message, $variables = array(), $severity = WATCHDOG_NOTICE)
If you are the site administrator, the log includes a version of the message sent through the drupal_set_message() function to give you immediate feedback during testing. The following form attempts to emulate what you would see.
$message = '';
$module_name = '';
if(isset($_POST['module_name']))
{
$module_name = htmlentities($_POST['module_name']);
}
$variable = '';
if(isset($_POST['variable']))
{
$variable = htmlentities($_POST['variable']);
}
if(isset($_POST['message']) and $_POST['message'] != '' and function_exists('pet_log'))
{
$message = htmlentities($_POST['message']);
class pet_log_2 extends pet_log
{
function set_message($message, $variables = array(), $severity = WATCHDOG_NOTICE)
{
parent::set_message($message, $variables, $severity);
}
}
$watchdog_message = $message;
$pet_log_object = new pet_log_2('Test');
$pet_log_object->set_message($message, array('@v' => $variable));
}
?>
if(isset($_POST['message']) and $_POST['message'] != '' and function_exists('pet_log'))
{
?>
you can see the Drupal message at the top of this page. The following lines show the message as it appears in the watchdog Recent log messages report.
| Type | Date | Message |
|---|---|---|
}
?>
pet_log_error()
pet_log_error() is a shortcut for pet_log('message', array(), WATCHDOG_ERROR). If a Drupal message is set, it will display as an error.
pet_log_warning()
pet_log_warning() is a shortcut for pet_log('message', array(), WATCHDOG_WARNING). If a Drupal message is set, it will display as a warning.
pet_class_name()
pet_class_name() returns a CSS class name from your identifier string.pet_class_name('.gmKl G gh=[) returns gmkl-g-gh.
pet_node_load_from_title()
pet_node_load_from_title() loads the node with the supplied title. pet_node_load_from_title('Test') loads the node with the title of Test.
Pet modules









- Facebook Like
- Google Plus One
- Log in or register to post comments