Document fields default.pl: Difference between revisions
Appearance
No edit summary |
Added actually file name in bold. |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
{{cfgd}} | {{cfgd}} | ||
'''document_fields_default.pl''' contains the '''set_document_defaults''' function. This 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 | ||
| Line 18: | Line 20: | ||
}; | }; | ||
</pre> | </pre> | ||
N.B. There are also a number of defaults set by the [[API:EPrints/DataObj/Document#get_defaults|EPrints::DataObj::Document::get_defaults]] method: | |||
# '''pos''' is set to the next document position or to a bespoke position specified by <tt>$c->{ulimate_doc_pos}</tt> if it is defined. | |||
# '''placement''' is set to the same value as ''pos'' as set above. | |||
Latest revision as of 12:15, 27 January 2022
EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects
document_fields_default.pl contains the set_document_defaults function. This 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[edit]
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";
};
N.B. There are also a number of defaults set by the EPrints::DataObj::Document::get_defaults method:
- pos is set to the next document position or to a bespoke position specified by $c->{ulimate_doc_pos} if it is defined.
- placement is set to the same value as pos as set above.