Difference between revisions of "API:EPrints/MetaField"

From EPrints Documentation
Jump to: navigation, search
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
<!-- Pod2Wiki=_preamble_  
 
<!-- Pod2Wiki=_preamble_  
 
This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
 
This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
  -->
+
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=perl_lib/EPrints/MetaField.pm|package_name=EPrints::MetaField}}[[Category:API|METAFIELD]][[Category:API:EPrints/MetaField|METAFIELD]]<div><!-- Edit below this comment -->
__NOTOC__
+
{{API}}{{Pod2Wiki}}{{API:Source|file=EPrints/MetaField.pm|package_name=EPrints::MetaField}}[[Category:API|MetaField]]<div><!-- Edit below this comment -->
+
  
  
<!-- Pod2Wiki=head_name --></div>
+
<!-- Pod2Wiki=_private_ --><!-- Pod2Wiki=head_name -->
 
==NAME==
 
==NAME==
'''EPrints::MetaField''' - A single metadata field.
+
EPrints::MetaField - A single metadata field.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=head_synopsis --></div>
+
<!-- Pod2Wiki= -->
 +
<!-- Pod2Wiki=head_synopsis -->
 
==SYNOPSIS==
 
==SYNOPSIS==
  my $field = $dataset-&gt;get_field( $fieldname );
+
<source lang="perl">my $field = $dataset->field( $fieldname );
 
+
$dataset = $field->dataset;
  # you must clone a field to modify any properties
+
$repo = $field->repository;
  $newfield = $field-&gt;clone;
+
$field->set_property( $property, $value );
  $newfield-&gt;set_property( $property, $value );
+
$value = $field->property( $property );
 
+
$name = $field->name;
  $name = $field-&gt;get_name;
+
$type = $field->type;
  $type = $field-&gt;get_type;
+
$xhtml = $field->render_name;
  $value = $field-&gt;get_property( $property );
+
$xhtml = $field->render_help;
  $boolean = $field-&gt;is_type( @typenames );
+
$xhtml = $field->render_value_label( $value );
  $results = $field-&gt;call_property( $property, @args );
+
$values = $field->all_values( %opts );
  # (results depend on what the property sub returns)
+
$sorted_list = $field->sort_values( $unsorted_list );</source>
 
+
 
  $xhtml = $field-&gt;render_name( $handle );
+
  $xhtml = $field-&gt;render_help( $handle );
+
  $xhtml = $field-&gt;render_value( $handle, $value, $show_all_langs, $dont_include_links, $object );
+
  $xhtml = $field-&gt;render_single_value( $handle, $value );
+
  $xhtml = $field-&gt;get_value_label( $handle, $value );
+
 
+
  $values = $field-&gt;get_values( $handle, $dataset, %opts );
+
 
+
  $sorted_list = $field-&gt;sort_values( $handle, $unsorted_list );
+
 
+
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
<h4><span style='display:none'>User Comments</span></h4>
+
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=head_description --></div>
+
<!-- Pod2Wiki= -->
 +
<!-- Pod2Wiki=head_description -->
 
==DESCRIPTION==
 
==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.
+
This 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".
 
"type" is the most important property, it is the type of the metadata field. For example: "text", "name" or "date".
Line 53: Line 39:
 
A full description of metadata types and properties is in the eprints documentation and will not be duplicated here.
 
A full description of metadata types and properties is in the eprints documentation and will not be duplicated here.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=head_methods --></div>
+
<!-- Pod2Wiki= -->
==METHODS==
+
<!-- Pod2Wiki=head_properties -->
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
==PROPERTIES==
<h4><span style='display:none'>User Comments</span></h4>
+
* replace_core =&gt; 0
 +
: Normally any attempt to define two fields with the same name will fail. However, you can replace a core system field by specifying the "replace_core" property. This should be used very carefully!
 +
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_set_property --></div>
+
<!-- Pod2Wiki= -->
===$field-&gt;set_property( $property, $value )===
+
<!-- Pod2Wiki=head_rendering -->
 +
===Rendering===
 +
* render_value =&gt; CODEREF
 +
<pre>  sub my_render_method
 +
  {
 +
    my( $repo, $field, $value, $all_langs, $no_link, $object ) = @_;
 +
 
 +
    return $repo->xml->create_text_node( $value );
 +
  }</pre>
  
Set the named property to the given value.
+
: Override the default rendering of values with a custom method. Renders $value (which may be a multiple) and returns an XHTML fragment.
  
This should not be called on metafields unless they've been cloned first.
+
<!-- Edit below this comment -->
  
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.
+
<!-- Pod2Wiki= -->
 +
<!-- Pod2Wiki=head_read_only_properties -->
 +
===Read-only Properties===
 +
* provenance =&gt; "core" or "config"
 +
: Indiciates where the field was initialised from. "core" fields are defined in {{API:PodLink|file=DataObj|package_name=DataObj|section=|text=DataObj}} classes while "config" fields are defined in cfg.d files.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_clone --></div>
+
<!-- Pod2Wiki= -->
===$newfield = $field-&gt;clone===
+
<!-- Pod2Wiki=head_methods -->
 +
==METHODS==
 +
<!-- Pod2Wiki=head_set_property -->
 +
===set_property===
  
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.
+
<source lang="perl">$field->set_property( $property, $value )
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
</source>
<h4><span style='display:none'>User Comments</span></h4>
+
Set the named property to the given value.
<!-- Edit below this comment -->
+
  
 +
This should not be called on metafields unless they've been cloned first.
  
<!-- Pod2Wiki=item_get_dataset --></div>
+
This method will cause an abort error if the metafield is read only.
===$dataset = $field-&gt;get_dataset===
+
  
Return the dataset to which this field belongs, or undef.
+
In these cases a cloned version of the field should be used.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_render_name --></div>
+
<!-- Pod2Wiki= -->
===$xhtml = $field-&gt;render_name( $handle )===
+
<!-- Pod2Wiki=head_repository -->
 +
===repository===
  
Render the name of this field as an XHTML object.
+
<source lang="perl">$repository = $field->repository
 +
 
 +
</source>
 +
Return the [[API:EPrints/Repository|EPrints::Repository]] to which this field belongs.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_render_help --></div>
+
<!-- Pod2Wiki= -->
===$xhtml = $field-&gt;render_help( $handle )===
+
<!-- Pod2Wiki=head_dataset -->
 +
===dataset===
  
Return the help information for a user inputing some data for this field as an XHTML chunk.
+
<source lang="perl">$dataset = $field->dataset
 +
 
 +
</source>
 +
Return the [[API:EPrints/DataSet|EPrints::DataSet]] to which this field belongs, or undef.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_render_input_field --></div>
+
<!-- Pod2Wiki= -->
===$xhtml = $field-&gt;render_input_field( $handle, $value, [$dataset], [$staff], [$hidden_fields], $obj, [$prefix] )===
+
<!-- Pod2Wiki=head_render_name -->
 +
===render_name===
  
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.
+
<source lang="perl">$xhtml = $field->render_name
  
The actual function called may be overridden from the config options.
+
</source>
 +
Render the name of this field as an XHTML object.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_form_value --></div>
+
<!-- Pod2Wiki= -->
===$value = $field-&gt;form_value( $handle, $object, [$prefix] )===
+
<!-- Pod2Wiki=head_render_help -->
 +
===render_help===
  
Get a value for this field from the CGI parameters, assuming that the form contained the input fields for this metadata field.
+
<source lang="perl">$xhtml = $field->render_help
 +
 
 +
</source>
 +
Return the help information for a user inputing some data for this field as an XHTML chunk.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_get_name --></div>
+
<!-- Pod2Wiki= -->
===$name = $field-&gt;get_name===
+
<!-- Pod2Wiki=head_name -->
 +
===name===
 +
 
 +
<source lang="perl">$name = $field->name
  
 +
</source>
 
Return the name of this field.
 
Return the name of this field.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_get_type --></div>
+
<!-- Pod2Wiki= -->
===$type = $field-&gt;get_type===
+
<!-- Pod2Wiki=head_type -->
 +
===type===
  
 +
<source lang="perl">$type = $field->type
 +
 +
</source>
 
Return the type of this field.
 
Return the type of this field.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_get_property --></div>
+
<!-- Pod2Wiki= -->
===$value = $field-&gt;get_property( $property )===
+
<!-- Pod2Wiki=head_property -->
 +
===property===
  
 +
<source lang="perl">$value = $field->property( $property )
 +
 +
</source>
 
Return the value of the given 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.
+
Special note about "required" property: It only indicates if the field is always required. You must query the dataset to check if it is required for a specific type.
  
There's about 50 in total, with additional extras for some subtypes of MetaField! However the most useful ones are:
 
 
  if( $field-&gt;get_property( "multiple" ) ) { ... }
 
  if( $field-&gt;get_property( "required" ) ) { ... }
 
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_is_type --></div>
+
<!-- Pod2Wiki= -->
===$boolean = $field-&gt;is_type( @typenames )===
+
<!-- Pod2Wiki=head_sort_values -->
 +
===sort_values===
  
Return true if the type of this field is one of @typenames.
+
<source lang="perl">$out_list = $field->sort_values( $in_list, $langid )
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
</source>
<h4><span style='display:none'>User Comments</span></h4>
+
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.
<!-- Edit below this comment -->
+
  
 
<!-- Pod2Wiki=item_render_value --></div>
 
===$xhtml = $field-&gt;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.
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_sort_values --></div>
+
<!-- Pod2Wiki= -->
===$out_list = $field-&gt;sort_values( $handle, $in_list )===
+
<!-- Pod2Wiki=head_all_values -->
 
+
===all_values===
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.
+
 
+
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
<h4><span style='display:none'>User Comments</span></h4>
+
<!-- Edit below this comment -->
+
 
+
  
<!-- Pod2Wiki=item_call_property --></div>
+
<source lang="perl">$values = $field->all_values( %opts )
===$value2 = $field-&gt;call_property( $property, @args )===
+
  
Call the method described by $property. Pass it the arguments and return the result.
+
</source>
 +
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.
  
The property may contain either a code reference, or the scalar name of a method.
+
Results are sorted according to the ordervalues of the current session.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_render_single_value --></div>
+
<!-- Pod2Wiki= -->
===$xhtml_dom = $field-&gt;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.
+
 
+
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
<h4><span style='display:none'>User Comments</span></h4>
+
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_get_values --></div>
+
<!-- Pod2Wiki= -->
===$values = $field-&gt;get_values( $handle, $dataset, %opts )===
+
<!-- Pod2Wiki=head_copyright -->
 +
==COPYRIGHT==
 +
Copyright 2000-2011 University of Southampton.
  
Return a reference to an array of all the values of this field.  
+
This file is part of EPrints http://www.eprints.org/.
  
For fields like "subject" or "set" it returns all the variations.  
+
EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  
For fields like "text" return all the distinct values from the database.
+
EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  
Results are sorted according to the ordervalues of the $handle.
+
You should have received a copy of the GNU Lesser General Public License along with EPrints.  If not, see http://www.gnu.org/licenses/.
  
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_get_value_label --></div>
+
<!-- Pod2Wiki= -->
===$xhtml = $field-&gt;get_value_label( $handle, $value )===
+
<!-- Pod2Wiki=_postamble_ -->
 
+
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.
+
 
+
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
<h4><span style='display:none'>User Comments</span></h4>
+
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
 
 
<!-- Pod2Wiki=_postamble_ --><!-- Edit below this comment -->
 

Latest revision as of 09:44, 11 May 2012

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.3, 3.2) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::MetaField - A single metadata field.


SYNOPSIS

my $field = $dataset->field( $fieldname );
$dataset = $field->dataset;
$repo = $field->repository;
$field->set_property( $property, $value );
$value = $field->property( $property );
$name = $field->name;
$type = $field->type;
$xhtml = $field->render_name;
$xhtml = $field->render_help;
$xhtml = $field->render_value_label( $value );
$values = $field->all_values( %opts );
$sorted_list = $field->sort_values( $unsorted_list );


DESCRIPTION

This 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.


PROPERTIES

  • replace_core => 0
Normally any attempt to define two fields with the same name will fail. However, you can replace a core system field by specifying the "replace_core" property. This should be used very carefully!


Rendering

  • render_value => CODEREF
  sub my_render_method
  {
    my( $repo, $field, $value, $all_langs, $no_link, $object ) = @_;
  
    return $repo->xml->create_text_node( $value );
  }
Override the default rendering of values with a custom method. Renders $value (which may be a multiple) and returns an XHTML fragment.


Read-only Properties

  • provenance => "core" or "config"
Indiciates where the field was initialised from. "core" fields are defined in DataObj classes while "config" fields are defined in cfg.d files.


METHODS

set_property

$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.


repository

$repository = $field->repository

Return the EPrints::Repository to which this field belongs.


dataset

$dataset = $field->dataset

Return the EPrints::DataSet to which this field belongs, or undef.


render_name

$xhtml = $field->render_name

Render the name of this field as an XHTML object.


render_help

$xhtml = $field->render_help

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


name

$name = $field->name

Return the name of this field.


type

$type = $field->type

Return the type of this field.


property

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

Return the value of the given property.

Special note about "required" property: It only indicates if the field is always required. You must query the dataset to check if it is required for a specific type.


sort_values

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

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.


all_values

$values = $field->all_values( %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 current session.



COPYRIGHT

Copyright 2000-2011 University of Southampton.

This file is part of EPrints http://www.eprints.org/.

EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with EPrints. If not, see http://www.gnu.org/licenses/.