Difference between revisions of "Document fields default.pl"

From EPrints Documentation
Jump to: navigation, search
(Improved formatting and explanation of example.)
(Added infor about Document get_defaults method.)
Line 20: 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.

Revision as of 00:40, 22 January 2022

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


Back to cfg.d

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";
};

N.B. There are also a number of defaults set by the EPrints::DataObj::Document::get_defaults method:

  1. pos is set to the next document position or to a bespoke position specified by $c->{ulimate_doc_pos} if it is defined.
  2. placement is set to the same value as pos as set above.