<<

Bugzilla::Field

NAME

Bugzilla::Field - a particular piece of information about bugs and useful routines for form field manipulation

SYNOPSIS

  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->get_fields({ obsolete => 1, custom => 1 }));

  # Display a list of the names of non-obsolete custom fields.
  print Bugzilla->custom_field_names;

  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 => 1, 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);

DESCRIPTION

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.

Instance Properties

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

legal_values

A reference to an array with valid active values for this field.

Instance Mutators

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

Class Methods

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.

obsolete - boolean - Whether this field is obsolete. Defaults to 0.

match
Description

Returns a list of fields that match the specified criteria.

You should be using "get_fields" in Bugzilla and "get_custom_field_names" in Bugzilla instead of this function.

Params

Takes named parameters in a hashref:

name - The name of the field.
custom - Boolean. True to only return custom fields. False to only return non-custom fields.
obsolete - Boolean. True to only return obsolete fields. False to not return obsolete fields.
type - The type of the field. A FIELD_TYPE constant from Bugzilla::Constants.
enter_bug - Boolean. True to only return fields that appear on enter_bug.cgi. False to only return fields that don't appear on enter_bug.cgi.
Returns

A reference to an array of Bugzilla::Field objects.

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

Data Validation

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.

<<