Difference between revisions of "Document fields default.pl"
(Improved formatting and explanation of example.) |
|||
Line 2: | Line 2: | ||
{{cfgd}} | {{cfgd}} | ||
− | The set_document_defaults function sets the default values for a Document. This usually happens when a Document is created but before it is given to the user to edit. | + | The '''set_document_defaults''' function sets the default values for a Document. This usually happens when a Document is created but before it is given to the user to edit. |
− | * $data is a hash of the metadata which will make up the document object. Each field name is a key in the hash. | + | * '''<tt>$data</tt>''' is a hash reference of the metadata which will make up the document object. Each field name is a key in the hash. |
− | * $session is a [[API:EPrints/Repository|Repository]] object (in 3.2 or later) | + | * '''<tt>$session</tt>''' is a [[API:EPrints/Repository|Repository]] object (in 3.2 or later). |
− | * $eprint is the [[API:EPrints/DataObj/EPrint|EPrint]] object to which the document belongs | + | * '''<tt>$eprint</tt>''' is the [[API:EPrints/DataObj/EPrint|EPrint]] object to which the document belongs. |
==Example== | ==Example== | ||
+ | In this example, the default for ''language'' is set to the ID string of for the Repository object's language, which comes from the '''<tt>$c->{defaultlanguage}</tt>''' configuration setting in [[languages.pl]] and the default for ''security'' is set to ''public''. | ||
+ | |||
<pre> | <pre> | ||
$c->{set_document_defaults} = sub | $c->{set_document_defaults} = sub |
Revision as of 17:20, 21 January 2022
EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects
The set_document_defaults function sets the default values for a Document. This usually happens when a Document is created but before it is given to the user to edit.
- $data is a hash reference of the metadata which will make up the document object. Each field name is a key in the hash.
- $session is a Repository object (in 3.2 or later).
- $eprint is the EPrint object to which the document belongs.
Example
In this example, the default for language is set to the ID string of for the Repository object's language, which comes from the $c->{defaultlanguage} configuration setting in languages.pl and the default for security is set to public.
$c->{set_document_defaults} = sub { my( $data, $session, $eprint ) = @_; $data->{language} = $session->get_langid(); $data->{security} = "public"; };