Bugzilla::Field - a particular piece of information about bugs and useful routines for form field manipulation
use Bugzilla; use Data::Dumper; # Display information about all fields. print Dumper(Bugzilla->get_fields()); # Display information about non-obsolete custom fields. print Dumper(Bugzilla->active_custom_fields); use Bugzilla::Field; # Display information about non-obsolete custom fields. # Bugzilla->get_fields() is a wrapper around Bugzilla::Field->match(), # so both methods take the same arguments. print Dumper(Bugzilla::Field->match({ obsolete => 0, custom => 1 })); # Create or update a custom field or field definition. my $field = Bugzilla::Field->create( {name => 'cf_silly', description => 'Silly', custom => 1}); # Instantiate a Field object for an existing field. my $field = new Bugzilla::Field({name => 'qacontact_accessible'}); if ($field->obsolete) { print $field->description . " is obsolete\n"; } # Validation Routines check_field($name, $value, \@legal_values, $no_warn); $fieldid = get_field_id($fieldname);
Field.pm defines field objects, which represent the particular pieces of information that Bugzilla stores about bugs.
This package also provides functions for dealing with CGI form fields.
Bugzilla::Field
is an implementation of Bugzilla::Object, and so provides all of the methods available in Bugzilla::Object, in addition to what is documented here.
name
the name of the field in the database; begins with "cf_" if field is a custom field, but test the value of the boolean "custom" property to determine if a given field is a custom field;
description
a short string describing the field; displayed to Bugzilla users in several places within Bugzilla's UI, f.e. as the form field label on the "show bug" page;
type
an integer specifying the kind of field this is; values correspond to the FIELD_TYPE_* constants in Constants.pm
custom
a boolean specifying whether or not the field is a custom field; if true, field name should start "cf_", but use this property to determine which fields are custom fields;
in_new_bugmail
a boolean specifying whether or not the field is displayed in bugmail for newly-created bugs;
sortkey
an integer specifying the sortkey of the field.
obsolete
a boolean specifying whether or not the field is obsolete;
enter_bug
A boolean specifying whether or not this field should appear on enter_bug.cgi
buglist
A boolean specifying whether or not this field is selectable as a display or order column in buglist.cgi
is_select
True if this is a FIELD_TYPE_SINGLE_SELECT
or FIELD_TYPE_MULTI_SELECT
field. It is only safe to call "legal_values" if this is true.
legal_values
Valid values for this field, as an array of Bugzilla::Field::Choice objects.
visibility_field
What field controls this field's visibility? Returns a Bugzilla::Field
object representing the field that controls this field's visibility.
Returns undef if there is no field that controls this field's visibility.
visibility_value
If we have a "visibility_field", then what value does that field have to be set to in order to show this field? Returns a Bugzilla::Field::Choice or undef if there is no visibility_field
set.
controls_visibility_of
An arrayref of Bugzilla::Field
objects, representing fields that this field controls the visibility of.
value_field
The Bugzilla::Field that controls the list of values for this field.
Returns undef if there is no field that controls this field's visibility.
controls_values_of
An arrayref of Bugzilla::Field
objects, representing fields that this field controls the values of.
These set the particular field that they are named after.
They take a single value--the new value for that field.
They will throw an error if you try to set the values to something invalid.
set_description
set_enter_bug
set_obsolete
set_sortkey
set_in_new_bugmail
set_buglist
set_visibility_field
set_visibility_value
set_value_field
remove_from_db
Attempts to remove the passed in field from the database. Deleting a field is only successful if the field is obsolete and there are no values specified (or EVER specified) for the field.
create
Just like "create" in Bugzilla::Object. Takes the following parameters:
name
Required - The name of the field.description
Required - The field label to display in the UI.mailhead
- boolean - Whether this field appears at the top of the bugmail for a newly-filed bug. Defaults to 0.custom
- boolean - True if this is a Custom Field. The field will be added to the bugs
table if it does not exist. Defaults to 0.sortkey
- integer - The sortkey of the field. Defaults to 0.enter_bug
- boolean - Whether this field is editable on the bug creation form. Defaults to 0.buglist
- boolean - Whether this field is selectable as a display or order column in bug lists. Defaults to 0.obsolete
- boolean - Whether this field is obsolete. Defaults to 0.
get_legal_field_values($field)
Description: returns all the legal values for a field that has a list of legal values, like rep_platform or resolution. The table where these values are stored must at least have the following columns: value, isactive, sortkey.
Params: $field
- Name of the table where valid values are.
Returns: a reference to a list of valid values.
populate_field_definitions()
Description: Populates the fielddefs table during an installation or upgrade.
Params: none
Returns: nothing
check_field($name, $value, \@legal_values, $no_warn)
Description: Makes sure the field $name is defined and its $value is non empty. If @legal_values is defined, this routine checks whether its value is one of the legal values associated with this field, else it checks against the default valid values for this field obtained by get_legal_field_values($name)
. If the test is successful, the function returns 1. If the test fails, an error is thrown (by default), unless $no_warn is true, in which case the function returns 0.
Params: $name - the field name $value - the field value @legal_values - (optional) list of legal values $no_warn - (optional) do not throw an error if true
Returns: 1 on success; 0 on failure if $no_warn is true (else an error is thrown).
get_field_id($fieldname)
Description: Returns the ID of the specified field name and throws an error if this field does not exist.
Params: $name - a field name
Returns: the corresponding field ID or an error if the field name does not exist.