⧼vector-jumptocontent⧽

Document fields automatic.pl: Difference between revisions

From EPrints Documentation
No edit summary
Added actually file name in bold.
 
(2 intermediate revisions by one other user not shown)
Line 2: Line 2:
{{cfgd}}
{{cfgd}}


This file contains the set_document_fields_automatic function. You use this function to perform a set of actions which you want to happen automatically before the [[API:EPrints/DataObj/Document|Document]] as part of the [[API:EPrints/DataObj/Document|Document]] commit() step, in which the document is written to the database.
'''document_fields_automatic.pl''' contains the '''set_document_fields_automatic''' function. You use this function to perform a set of actions which you want to happen automatically before the [[API:EPrints/DataObj/Document|Document]] as part of the [[API:EPrints/DataObj/Document|Document]] commit() step, in which the document is written to the database.


* $data is a hash of the metadata which will make up the document object. Each field name is a key in the hash.
* $doc is the [[API:EPrints/DataObj/Document|Document]] object
* $session 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


==Example==
==Example==
<pre>
<pre>
$c->{set_document_defaults} = sub
$c->{set_document_automatic_fields} = sub
{
{
         my( $data, $session, $eprint ) = @_;
         my( $doc ) = @_;
 
         if($doc->value("description") eq ""){
         $data->{language} = $session->get_langid();
                $doc->value("description", "the default description"); #if the documents description is empty set it to a holding value
         $data->{security} = "public";
         }
};
};
</pre>
</pre>

Latest revision as of 12:14, 27 January 2022


Back to cfg.d

document_fields_automatic.pl contains the set_document_fields_automatic function. You use this function to perform a set of actions which you want to happen automatically before the Document as part of the Document commit() step, in which the document is written to the database.

Example

$c->{set_document_automatic_fields} = sub
{
        my( $doc ) = @_;
        if($doc->value("description") eq ""){
                 $doc->value("description", "the default description"); #if the documents description is empty set it to a holding value
        }
};