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->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->fields() is a wrapper around Bugzilla::Field->get_all(), # with arguments which filter the fields before returning them. print Dumper(Bugzilla->fields({ 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) { say $field->description . " is obsolete"; } # 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;
long_desc
A string providing detailed info about the field;
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.
is_abnormal
Most fields that have a SELECT
"type" have a certain schema for the table that stores their values, the table has the same name as the field, and the field's legal values can be edited via editvalues.cgi.
However, some fields do not follow that pattern. Those fields are considered "abnormal".
This method returns 1
if the field is "abnormal", 0
otherwise.
is_timetracking
True if this is a time-tracking field that should only be shown to users in the timetrackinggroup
.
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_values
If we have a "visibility_field", then what values 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.
is_visible_on_bug
is_relationship
Applies only to fields of type FIELD_TYPE_BUG_ID. Checks to see if a reverse relationship description has been set. This is the canonical condition to enable reverse link display, dependency tree display, and similar functionality.
reverse_desc
Applies only to fields of type FIELD_TYPE_BUG_ID. Describes the reverse relationship of this field. For example, if a BUG_ID field is called "Is a duplicate of", the reverse description would be "Duplicates of this bug".
is_mandatory
a boolean specifying whether or not the field is mandatory;
is_numeric
A boolean specifying whether or not this field logically contains numeric (integer, decimal, or boolean) values. By "logically contains" we mean that the user inputs numbers into the value of the field in the UI. This is mostly used by Bugzilla::Search.
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_long_desc
set_enter_bug
set_obsolete
set_sortkey
set_in_new_bugmail
set_buglist
set_reverse_desc
set_visibility_field
set_visibility_values
set_value_field
set_is_mandatory
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.long_desc
- A longer description of the field.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.
is_mandatory
- boolean - Whether this field is mandatory. 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.