API:EPrints/MetaField

From EPrints Documentation
Revision as of 13:08, 20 August 2009 by Cjg (talk | contribs)
Jump to: navigation, search


EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::MetaField - A single metadata field.

User Comments


SYNOPSIS

 my $field = $dataset->get_field( $fieldname );
 
 # you must clone a field to modify any properties
 $newfield = $field->clone;
 $newfield->set_property( $property, $value );
 
 $name = $field->get_name;
 $type = $field->get_type;
 $value = $field->get_property( $property );
 $boolean = $field->is_type( @typenames );
 $results = $field->call_property( $property, @args ); 
 # (results depend on what the property sub returns)
 
 $xhtml = $field->render_name( $handle );
 $xhtml = $field->render_help( $handle );
 $xhtml = $field->render_value( $handle, $value, $show_all_langs, $dont_include_links, $object );
 $xhtml = $field->render_single_value( $handle, $value );
 $xhtml = $field->get_value_label( $handle, $value );
 
 $values = $field->get_values( $handle, $dataset, %opts );
 
 $sorted_list = $field->sort_values( $handle, $unsorted_list );
 

User Comments


DESCRIPTION

Theis object represents a single metadata field, not the value of that field. A field belongs (usually) to a dataset and has a large number of properties. Optional and required properties vary between types.

"type" is the most important property, it is the type of the metadata field. For example: "text", "name" or "date".

A full description of metadata types and properties is in the eprints documentation and will not be duplicated here.

User Comments


METHODS

User Comments


$field->set_property( $property, $value )

Set the named property to the given value.

This should not be called on metafields unless they've been cloned first.

This method will cause an abort error if the metafield is read only.

In these cases a cloned version of the field should be used.

User Comments


$newfield = $field->clone

Clone the field, so the clone can be edited without affecting the original. Does not deep copy properties which are references - these should be set to new values, rather than the contents altered. Eg. don't push to a cloned options list, replace it.

User Comments


$dataset = $field->get_dataset

Return the dataset to which this field belongs, or undef.

User Comments


$xhtml = $field->render_name( $handle )

Render the name of this field as an XHTML object.

User Comments


$xhtml = $field->render_help( $handle )

Return the help information for a user inputing some data for this field as an XHTML chunk.

User Comments


$xhtml = $field->render_input_field( $handle, $value, [$dataset], [$staff], [$hidden_fields], $obj, [$prefix] )

Return the XHTML of the fields for an form which will allow a user to input metadata to this field. $value is the default value for this field.

The actual function called may be overridden from the config options.

User Comments


$value = $field->form_value( $handle, $object, [$prefix] )

Get a value for this field from the CGI parameters, assuming that the form contained the input fields for this metadata field.

User Comments


$name = $field->get_name

Return the name of this field.

User Comments


$type = $field->get_type

Return the type of this field.

User Comments


$value = $field->get_property( $property )

Return the value of the given property.

Special note about "required" property, the workflow may in some situations return a field which is 'required' which isn't if you get it via $dataset.

There's about 50 in total, with additional extras for some subtypes of MetaField! However the most useful ones are:

 if( $field->get_property( "multiple" ) ) { ... }
 if( $field->get_property( "required" ) ) { ... }
 

User Comments


$boolean = $field->is_type( @typenames )

Return true if the type of this field is one of @typenames.

User Comments


$xhtml = $field->render_value( $handle, $value, [$alllangs], [$nolink], $object )

Render the given value of this given string as XHTML DOM. If $alllangs is true and this is a multilang field then render all language versions, not just the current language (for editorial checking). If $nolink is true then don't make this field a link, for example subject fields might otherwise link to the subject view page.

If render_value or render_single_value properties are set then these control the rendering instead.

User Comments


$out_list = $field->sort_values( $handle, $in_list )

Sorts the in_list into order, based on the "order values" of the values in the in_list. Assumes that the values are not a list of multiple values. [ [], [], [] ], but rather a list of single values.

User Comments


$value2 = $field->call_property( $property, @args )

Call the method described by $property. Pass it the arguments and return the result.

The property may contain either a code reference, or the scalar name of a method.

User Comments


$xhtml_dom = $field->render_single_value( $handle, $value )

Returns the XHTML representation of the value. If the field is multiple then $value should be a single item from the values, not the list.

User Comments


$values = $field->get_values( $handle, $dataset, %opts )

Return a reference to an array of all the values of this field.

For fields like "subject" or "set" it returns all the variations.

For fields like "text" return all the distinct values from the database.

Results are sorted according to the ordervalues of the $handle.

User Comments


$xhtml = $field->get_value_label( $handle, $value )

Return an XHTML DOM object describing the given value. Normally this is just the value, but in the case of something like a "set" field this returns the name of the option in the current language.

User Comments