Skip to content

Commit a667d4d

Browse files
committed
Add main contributor property to author schema
Issue: documentacao-e-tarefas/desenvolvimento_e_infra#994 Signed-off-by: Thiago Brasil <thiago@lepidus.com.br>
1 parent 3d87e1b commit a667d4d

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

ThothPlugin.inc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ public function addTemplateFilters($hookName, $args)
132132
public function addToSchema()
133133
{
134134
$thothSchema = new ThothSchema();
135+
HookRegistry::register('Schema::get::author', [$thothSchema, 'addToAuthorSchema']);
135136
HookRegistry::register('Schema::get::submission', [$thothSchema, 'addWorkIdToSchema']);
136137
HookRegistry::register('Schema::get::publication', [$thothSchema, 'addToPublicationSchema']);
138+
HookRegistry::register('authordao::getAdditionalFieldNames', [$thothSchema, 'addToAdditionalFieldNames']);
137139
HookRegistry::register('Submission::getBackendListProperties::properties', [$thothSchema, 'addToBackendProps']);
138140
}
139141

@@ -150,6 +152,8 @@ public function addFormModifiers()
150152
{
151153
$authorFormModifier = new AuthorFormModifier($this);
152154
HookRegistry::register('authorform::Constructor', [$authorFormModifier, 'handleFormConstructor']);
155+
HookRegistry::register('authorform::display', [$authorFormModifier, 'handleFormDisplay']);
156+
HookRegistry::register('authorform::execute', [$authorFormModifier, 'handleFormExecute']);
153157
}
154158

155159
public function addEndpoints()

classes/formModifiers/AuthorFormModifier.inc.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,35 @@ public function __construct($plugin)
2525
public function handleFormConstructor($hookName, $args)
2626
{
2727
$form = & $args[0];
28-
2928
$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(['mainContributor' => $author->getData('mainContributor')]);
43+
}
44+
45+
return false;
46+
}
47+
48+
public function handleFormExecute($hookName, $args)
49+
{
50+
$form = & $args[0];
51+
$form->readUserVars(['mainContributor']);
52+
$author = $form->getAuthor();
53+
$mainContributor = $form->getData('mainContributor');
54+
55+
$author->setData('mainContributor', $mainContributor);
56+
57+
return false;
3058
}
3159
}

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->{'mainContributor'} = (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[] = 'mainContributor';
82+
83+
return false;
5984
}
6085
}

0 commit comments

Comments
 (0)