Skip to content

Commit d9d643f

Browse files
Merge pull request #34 from lepidus/stable-3_3_0
Feature/ added main contribution field to author form (OMP 3.3.0)
2 parents 13830d1 + 42d955e commit d9d643f

9 files changed

Lines changed: 137 additions & 4 deletions

File tree

ThothPlugin.inc.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
import('plugins.generic.thoth.classes.api.ThothEndpoint');
2222
import('plugins.generic.thoth.classes.components.forms.config.CatalogEntryFormConfig');
2323
import('plugins.generic.thoth.classes.components.forms.config.PublishFormConfig');
24-
import('plugins.generic.thoth.classes.templateFilters.ThothSectionTemplateFilter');
24+
import('plugins.generic.thoth.classes.formModifiers.AuthorFormModifier');
2525
import('plugins.generic.thoth.classes.listeners.PublicationEditListener');
2626
import('plugins.generic.thoth.classes.listeners.PublicationPublishListener');
2727
import('plugins.generic.thoth.classes.notification.ThothNotification');
2828
import('plugins.generic.thoth.classes.schema.ThothSchema');
29+
import('plugins.generic.thoth.classes.templateFilters.ThothSectionTemplateFilter');
2930

3031
class ThothPlugin extends GenericPlugin
3132
{
@@ -41,6 +42,7 @@ public function register($category, $path, $mainContextId = null)
4142

4243
$this->addToSchema();
4344
$this->addFormConfig();
45+
$this->addFormModifiers();
4446
$this->addEndpoints();
4547
$this->addListeners();
4648
}
@@ -130,8 +132,10 @@ public function addTemplateFilters($hookName, $args)
130132
public function addToSchema()
131133
{
132134
$thothSchema = new ThothSchema();
135+
HookRegistry::register('Schema::get::author', [$thothSchema, 'addToAuthorSchema']);
133136
HookRegistry::register('Schema::get::submission', [$thothSchema, 'addWorkIdToSchema']);
134137
HookRegistry::register('Schema::get::publication', [$thothSchema, 'addToPublicationSchema']);
138+
HookRegistry::register('authordao::getAdditionalFieldNames', [$thothSchema, 'addToAdditionalFieldNames']);
135139
HookRegistry::register('Submission::getBackendListProperties::properties', [$thothSchema, 'addToBackendProps']);
136140
}
137141

@@ -144,6 +148,14 @@ public function addFormConfig()
144148
HookRegistry::register('Form::config::before', [$catalogEntryFormConfig, 'addConfig']);
145149
}
146150

151+
public function addFormModifiers()
152+
{
153+
$authorFormModifier = new AuthorFormModifier($this);
154+
HookRegistry::register('authorform::Constructor', [$authorFormModifier, 'handleFormConstructor']);
155+
HookRegistry::register('authorform::display', [$authorFormModifier, 'handleFormDisplay']);
156+
HookRegistry::register('authorform::execute', [$authorFormModifier, 'handleFormExecute']);
157+
}
158+
147159
public function addEndpoints()
148160
{
149161
$thothEndpoint = new ThothEndpoint();

classes/factories/ThothContributionFactory.inc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function createFromAuthor($author, $primaryContactId = null)
3737

3838
private function isMainContribution($author, $primaryContactId = null)
3939
{
40+
if ($mainContribution = $author->getData('mainContribution')) {
41+
return $mainContribution;
42+
}
43+
4044
if ($author instanceof ChapterAuthor) {
4145
return (bool) $author->getPrimaryContact();
4246
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* @file plugins/generic/thoth/classes/formModifiers/AuthorFormModifier.inc.php
5+
*
6+
* Copyright (c) 2024-2025 Lepidus Tecnologia
7+
* Copyright (c) 2024-2025 Thoth
8+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
9+
*
10+
* @class AuthorFormModifier
11+
* @ingroup plugins_generic_thoth
12+
*
13+
* @brief Additional fields to the author form
14+
*/
15+
16+
class AuthorFormModifier
17+
{
18+
private $plugin;
19+
20+
public function __construct($plugin)
21+
{
22+
$this->plugin = $plugin;
23+
}
24+
25+
public function handleFormConstructor($hookName, $args)
26+
{
27+
$form = & $args[0];
28+
$form->setTemplate($this->plugin->getTemplateResource('form/authorForm.tpl'));
29+
30+
return false;
31+
}
32+
33+
public function handleFormDisplay($hookName, $args)
34+
{
35+
$request = PKPApplication::get()->getRequest();
36+
$templateMgr = TemplateManager::getManager($request);
37+
38+
$authorForm = & $args[0];
39+
$author = $authorForm->getAuthor();
40+
41+
if ($author) {
42+
$templateMgr->assign(['mainContribution' => $author->getData('mainContribution')]);
43+
}
44+
45+
return false;
46+
}
47+
48+
public function handleFormExecute($hookName, $args)
49+
{
50+
$form = & $args[0];
51+
$form->readUserVars(['mainContribution']);
52+
53+
$author = $form->getAuthor();
54+
$mainContribution = $form->getData('mainContribution');
55+
56+
$author->setData('mainContribution', $mainContribution);
57+
58+
return false;
59+
}
60+
}

classes/schema/ThothSchema.inc.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ class ThothSchema
1818
public function addWorkIdToSchema($hookName, $args)
1919
{
2020
$schema = & $args[0];
21+
2122
$schema->properties->{'thothWorkId'} = (object) [
2223
'type' => 'string',
2324
'apiSummary' => true,
2425
'validation' => ['nullable'],
2526
];
27+
2628
return false;
2729
}
2830

@@ -51,10 +53,33 @@ public function addToPublicationSchema($hookName, $args)
5153
return false;
5254
}
5355

56+
public function addToAuthorSchema($hookName, $args)
57+
{
58+
$schema = & $args[0];
59+
60+
$schema->properties->{'mainContribution'} = (object) [
61+
'type' => 'boolean',
62+
'apiSummary' => true,
63+
'validation' => ['nullable']
64+
];
65+
66+
return false;
67+
}
68+
5469
public function addToBackendProps($hookName, $args)
5570
{
5671
$props = & $args[0];
57-
5872
$props[] = 'thothWorkId';
73+
74+
return false;
75+
76+
}
77+
78+
public function addToAdditionalFieldNames($hookName, $params)
79+
{
80+
$fields = & $params[1];
81+
$fields[] = 'mainContribution';
82+
83+
return false;
5984
}
6085
}

locale/en_US/locale.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ msgstr "Page Count"
4040
msgid "plugins.generic.thoth.field.imageCount.label"
4141
msgstr "Image Count"
4242

43+
msgid "plugins.generic.thoth.field.mainContribution.label"
44+
msgstr "Identify this contributor as main contribution in Thoth."
45+
4346
msgid "plugins.generic.thoth.workType"
4447
msgstr "Work Type"
4548

locale/es_ES/locale.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ msgstr "Número de Páginas"
4040
msgid "plugins.generic.thoth.field.imageCount.label"
4141
msgstr "Número de Imágenes"
4242

43+
msgid "plugins.generic.thoth.field.mainContribution.label"
44+
msgstr "Identificar a este colaborador como colaboración principal en Thoth."
45+
4346
msgid "plugins.generic.thoth.workType"
4447
msgstr "Tipo de Trabajo"
4548

locale/pt_BR/locale.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ msgstr "Número de Páginas"
4040
msgid "plugins.generic.thoth.field.imageCount.label"
4141
msgstr "Número de Imagens"
4242

43+
msgid "plugins.generic.thoth.field.mainContribution.label"
44+
msgstr "Identificar este contribuidor como contribuição principal em Thoth."
45+
4346
msgid "plugins.generic.thoth.workType"
4447
msgstr "Tipo de Trabalho"
4548

templates/form/authorForm.tpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{**
2+
* templates/controllers/grid/users/author/form/authorForm.tpl
3+
*
4+
* Copyright (c) 2014-2021 Simon Fraser University
5+
* Copyright (c) 2003-2021 John Willinsky
6+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
7+
*
8+
* Submission Contributor grid form
9+
*
10+
*}
11+
12+
{if $submission->getData('workType') === $smarty.const.WORK_TYPE_EDITED_VOLUME}
13+
{capture assign="additionalCheckboxes"}
14+
{fbvElement type="checkbox" label="author.isVolumeEditor" id="isVolumeEditor" checked=$isVolumeEditor}
15+
{/capture}
16+
{/if}
17+
18+
{capture assign="additionalCheckboxes"}
19+
{$additionalCheckboxes}
20+
{fbvElement type="checkbox" label="plugins.generic.thoth.field.mainContribution.label" id="mainContribution" checked=$mainContribution}
21+
{/capture}
22+
23+
{include file="core:controllers/grid/users/author/form/authorForm.tpl" additionalCheckboxes=$additionalCheckboxes}

version.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<version>
44
<application>thoth</application>
55
<type>plugins.generic</type>
6-
<release>0.1.8.0</release>
7-
<date>2025-04-29</date>
6+
<release>0.1.9.0</release>
7+
<date>2025-05-01</date>
88
<lazy-load>1</lazy-load>
99
<class>ThothPlugin</class>
1010
</version>

0 commit comments

Comments
 (0)