Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
Adding multilang fields
(section)
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Adding a new field type (VirtualWithValue)== In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[API:EPrints/MetaField|MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field: <source lang="perl">package EPrints::MetaField::Virtualwithvalue; use strict; use warnings; use EPrints::MetaField; our @ISA = qw( EPrints::MetaField ); use strict; sub get_property_defaults { my ( $self ) = @_; my %defaults = $self->SUPER::get_property_defaults; $defaults{get_value} = $EPrints::MetaField::UNDEF; $defaults{set_value} = $EPrints::MetaField::UNDEF; return %defaults; } sub get_value { my( $self, $object ) = @_; if ( defined $self->get_property("get_value") ) { return $self->call_property( "get_value", $object); } return undef; # This is important. Using just a 'return;' or no return statement may break your repository e.g. when an EPrint revision file tried to be created. } sub set_value { my( $self, $object, $value ) = @_; if ( defined $self->get_property("set_value") ) { return $self->call_property( "set_value", $object, $value); } return undef; } </source> We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)