Bugzilla:Extension Notes: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
==Checking Syntax==
It's not immediately obvious how to check the syntax of your extension's modules. Running checksetup.pl might do some of it, but the errors aren't necessarily massively informative.
perl -Mlib=lib -MBugzilla -e 'BEGIN { Bugzilla->extensions; } use Bugzilla::Extension::ExtensionName::Class;'
(run from BUGZILLA_HOME) will do the trick.
==Adding New Fields To Bugs==
==Adding New Fields To Bugs==



Revision as of 11:43, 9 December 2010

Checking Syntax

It's not immediately obvious how to check the syntax of your extension's modules. Running checksetup.pl might do some of it, but the errors aren't necessarily massively informative.

perl -Mlib=lib -MBugzilla -e 'BEGIN { Bugzilla->extensions; } use Bugzilla::Extension::ExtensionName::Class;' 

(run from BUGZILLA_HOME) will do the trick.

Adding New Fields To Bugs

To add new fields to a bug, you need to do the following:

  • Add an install_update_db hook to add the fields by calling Bugzilla::Field->create (only if the field doesn't already exist). Here's what it might look like for a single field:
my $field = new Bugzilla::Field({ name => $name });
return if $field;

$field = Bugzilla::Field->create({
    name        => $name,
    description => $description,
    type        => $type,        # From list in Constants.pm
    enter_bug   => 0,
    buglist     => 0,
    custom      => 1,
});
  • Push the name of the field onto the relevant arrays in the bug_columns and bug_fields hooks.
  • If you want direct accessors, or other functions on the object, you need to add a BEGIN block to your Extension.pm:
BEGIN { 
   *Bugzilla::Bug::is_foopy = \&_bug_is_foopy; 
}

...

sub _bug_is_foopy {
    return $_[0]->{'is_foopy'};
}
  • You don't have to change Bugzilla/DB/Schema.pm.

Adding New Fields To Other Things

If you are adding the new fields to an object other than a bug, you need to go a bit lower-level.

  • In install_update_db, use bz_add_column instead
  • Push on the columns in object_columns and object_update_columns instead of bug_columns.
  • Add validators for the values in object_validators

The process for adding accessor functions is the same.

Adding Configuration Panels

As well as using the config_add_panels hook, you will need a template to define the UI strings for the panel. See the templates in template/en/default/admin/params for examples, and put your own template in template/en/default/admin/params in your extension's directory.