Skip to content

Commit 9a8b89d

Browse files
Merge pull request #33 from lepidus/main
Feature/added Thoth fields (OMP 3.4.0)
2 parents eb92df3 + 0724925 commit 9a8b89d

9 files changed

Lines changed: 120 additions & 3 deletions

File tree

ThothPlugin.inc.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PKP\linkAction\request\AjaxModal;
2323

2424
import('plugins.generic.thoth.classes.api.ThothEndpoint');
25+
import('plugins.generic.thoth.classes.components.forms.config.CatalogEntryFormConfig');
2526
import('plugins.generic.thoth.classes.components.forms.config.PublishFormConfig');
2627
import('plugins.generic.thoth.classes.templateFilters.ThothSectionTemplateFilter');
2728
import('plugins.generic.thoth.classes.listeners.PublicationEditListener');
@@ -122,8 +123,9 @@ public function manage($args, $request)
122123
public function addToSchema()
123124
{
124125
$thothSchema = new ThothSchema();
125-
HookRegistry::register('Schema::get::submission', [$thothSchema, 'addWorkIdToSchema']);
126126
HookRegistry::register('Schema::get::eventLog', [$thothSchema, 'addReasonToSchema']);
127+
HookRegistry::register('Schema::get::submission', [$thothSchema, 'addWorkIdToSchema']);
128+
HookRegistry::register('Schema::get::publication', [$thothSchema, 'addToPublicationSchema']);
127129
HookRegistry::register('Submission::getSubmissionsListProps', [$thothSchema, 'addToSubmissionsListProps']);
128130
}
129131

@@ -156,6 +158,9 @@ public function addFormConfig()
156158
{
157159
$publishFormConfig = new PublishFormConfig();
158160
HookRegistry::register('Form::config::before', [$publishFormConfig, 'addConfig']);
161+
162+
$catalogEntryFormConfig = new CatalogEntryFormConfig();
163+
HookRegistry::register('Form::config::before', [$catalogEntryFormConfig, 'addConfig']);
159164
}
160165

161166
public function addListeners()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* @file plugins/generic/thoth/classes/components/forms/config/CatalogEntryFormConfig.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 CatalogEntryFormConfig
11+
* @ingroup plugins_generic_thoth
12+
*
13+
* @brief Thoth config for catalog entry form
14+
*/
15+
16+
use APP\facades\Repo;
17+
18+
class CatalogEntryFormConfig
19+
{
20+
public function addConfig($hookName, $form)
21+
{
22+
if ($form->id !== 'catalogEntry' || !empty($form->errors)) {
23+
return;
24+
}
25+
26+
$actionParts = explode('/', $form->action);
27+
$publicationId = end($actionParts);
28+
$publication = Repo::publication()->get($publicationId);
29+
30+
$form->addField(new \PKP\components\forms\FieldText('place', [
31+
'label' => __('plugins.generic.thoth.field.place.label'),
32+
'value' => $publication->getData('place'),
33+
]))
34+
->addField(new \PKP\components\forms\FieldText('pageCount', [
35+
'label' => __('plugins.generic.thoth.field.pageCount.label'),
36+
'value' => $publication->getData('pageCount'),
37+
]))
38+
->addField(new \PKP\components\forms\FieldText('imageCount', [
39+
'label' => __('plugins.generic.thoth.field.imageCount.label'),
40+
'value' => $publication->getData('imageCount'),
41+
]));
42+
43+
return false;
44+
}
45+
}

classes/factories/ThothBookFactory.inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function createFromPublication($publication)
4242
'edition' => $publication->getData('version'),
4343
'doi' => $this->getDoi($publication),
4444
'publicationDate' => $publication->getData('datePublished'),
45+
'place' => $publication->getData('place'),
46+
'pageCount' => $publication->getData('pageCount'),
47+
'imageCount' => $publication->getData('imageCount'),
4548
'license' => $publication->getData('licenseUrl')
4649
?? $submission->_getContextLicenseFieldValue(
4750
null,

classes/schema/ThothSchema.inc.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@ public function addReasonToSchema($hookName, $args)
3838
return false;
3939
}
4040

41+
public function addToPublicationSchema($hookName, $args)
42+
{
43+
$schema = & $args[0];
44+
45+
$schema->properties->{'place'} = (object) [
46+
'type' => 'string',
47+
'apiSummary' => true,
48+
'validation' => ['nullable'],
49+
];
50+
51+
$schema->properties->{'pageCount'} = (object) [
52+
'type' => 'integer',
53+
'apiSummary' => true,
54+
'validation' => ['nullable'],
55+
];
56+
57+
$schema->properties->{'imageCount'} = (object) [
58+
'type' => 'integer',
59+
'apiSummary' => true,
60+
'validation' => ['nullable'],
61+
];
62+
63+
return false;
64+
}
65+
4166
public function addToSubmissionsListProps($hookName, $args)
4267
{
4368
$props = & $args[0];

locale/en/locale.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ msgstr "Your site administrator must set a secret in the config file ('api_key_s
3131
msgid "plugins.generic.thoth.credentialsMissing"
3232
msgstr "Thoth credentials not configured."
3333

34+
msgid "plugins.generic.thoth.field.place.label"
35+
msgstr "Place of Publication"
36+
37+
msgid "plugins.generic.thoth.field.pageCount.label"
38+
msgstr "Page Count"
39+
40+
msgid "plugins.generic.thoth.field.imageCount.label"
41+
msgstr "Image Count"
42+
3443
msgid "plugins.generic.thoth.workType"
3544
msgstr "Work Type"
3645

locale/es/locale.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ msgstr "El administrador de su sitio debe establecer un secreto en el archivo de
3131
msgid "plugins.generic.thoth.credentialsMissing"
3232
msgstr "Credenciales de Thoth no configuradas."
3333

34+
msgid "plugins.generic.thoth.field.place.label"
35+
msgstr "Lugar de Publicación"
36+
37+
msgid "plugins.generic.thoth.field.pageCount.label"
38+
msgstr "Número de Páginas"
39+
40+
msgid "plugins.generic.thoth.field.imageCount.label"
41+
msgstr "Número de Imágenes"
42+
3443
msgid "plugins.generic.thoth.workType"
3544
msgstr "Tipo de Trabajo"
3645

locale/pt_BR/locale.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ msgstr "O administrador do seu site deve definir um segredo no arquivo de config
3131
msgid "plugins.generic.thoth.credentialsMissing"
3232
msgstr "Credenciais do Thoth não configuradas."
3333

34+
msgid "plugins.generic.thoth.field.place.label"
35+
msgstr "Local de Publicação"
36+
37+
msgid "plugins.generic.thoth.field.pageCount.label"
38+
msgstr "Número de Páginas"
39+
40+
msgid "plugins.generic.thoth.field.imageCount.label"
41+
msgstr "Número de Imagens"
42+
3443
msgid "plugins.generic.thoth.workType"
3544
msgstr "Tipo de Trabalho"
3645

tests/classes/factories/ThothBookFactoryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ private function setUpMockEnvironment()
137137
->shouldReceive('getLocalizedCoverImageUrl')
138138
->withAnyArgs()
139139
->andReturn('https://omp.publicknowledgeproject.org/templates/images/book-default.png')
140+
->shouldReceive('getData')
141+
->with('place')
142+
->andReturn('Salvador, BR')
143+
->shouldReceive('getData')
144+
->with('pageCount')
145+
->andReturn(64)
146+
->shouldReceive('getData')
147+
->with('imageCount')
148+
->andReturn(32)
140149
->getMock();
141150

142151
$this->mocks = [];
@@ -159,6 +168,9 @@ public function testCreateThothBookFromPublication()
159168
'subtitle' => 'My book subtitle',
160169
'edition' => 1,
161170
'publicationDate' => '2020-01-01',
171+
'place' => 'Salvador, BR',
172+
'pageCount' => 64,
173+
'imageCount' => 32,
162174
'doi' => 'https://doi.org/10.12345/0101010101',
163175
'license' => 'https://creativecommons.org/licenses/by-nc/4.0/',
164176
'copyrightHolder' => 'Public Knowledge Press',

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.2.5.2</release>
7-
<date>2025-04-28</date>
6+
<release>0.2.6.0</release>
7+
<date>2025-04-29</date>
88
<lazy-load>1</lazy-load>
99
<class>ThothPlugin</class>
1010
</version>

0 commit comments

Comments
 (0)