[OJS 3] custom metadata fields

@asmecher, thanks, that was helpful—

For anyone else looking to add custom metadata (in the most minimal kind of way—this doesn’t tie in with the translation system, DC, etc.), here is what you need to modify:

In lib/pkp/classes/submission/PKPSubmissionMetadataFormImplementation.inc.php:

  • In the initData function, add 'myField' => $submission->getData('myField', null) to the formData var
  • In readInputData, add 'myField' to the userVars var
  • In getLocaleFieldNames, add 'myField' to the array (not sure if this is necessary)

In lib/pkp/classes/submission/SubmissionDAO.inc.php: in getLocaleFieldNames, add 'myField' to the array

In lib/pkp/templates/submission/submissionMetadataFormTitleFields.tpl: append something like the following to the end of the template (here is a case where you might want to do some extra work to integrate with translations):

{fbvFormSection title="MyField" for="myField" required=false}
    {fbvElement type="textarea" multilingual=true name="myField" id="myField" value=$myField rich="extended" readonly=$readOnly}
{/fbvFormSection}

In plugins/themes/bootstrap3/templates/frontend/objects/article_details.tpl (or similar): add the following where desired:

{if $article->getLocalizedData('myField') }
    <div class="article-summary" id="myField">
        <h2>My Field</h2>
        <div class="article-myField">
             {$article->getLocalizedData('myField')|strip_unsafe_html|nl2br}
        </div>
    </div>
{/if}
3 Likes