Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xml2html-pkp-plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FNSO
FAIREST
xml2html-pkp-plugin
Commits
c1eb8fed
You need to sign in or sign up before continuing.
Commit
c1eb8fed
authored
1 year ago
by
Jerome Chauveau
Browse files
Options
Downloads
Patches
Plain Diff
form + settings save
parent
ae7c0fc2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
XML2HTMLPlugin.php
+25
-14
25 additions, 14 deletions
XML2HTMLPlugin.php
XML2HTMLSettingsForm.inc.php
+72
-39
72 additions, 39 deletions
XML2HTMLSettingsForm.inc.php
templates/settingsForm.tpl
+12
-1
12 additions, 1 deletion
templates/settingsForm.tpl
with
109 additions
and
54 deletions
XML2HTMLPlugin.php
+
25
−
14
View file @
c1eb8fed
...
@@ -144,29 +144,40 @@ class XML2HTMLPlugin extends GenericPlugin
...
@@ -144,29 +144,40 @@ class XML2HTMLPlugin extends GenericPlugin
}
}
public
function
manage
(
$args
,
$request
)
{
/**
* Load a form when the `settings` button is clicked and
* save the form when the user saves it.
*
* @param array $args
* @param Request $request
* @return JSONMessage
*/
public
function
manage
(
$args
,
$request
)
{
switch
(
$request
->
getUserVar
(
'verb'
))
{
switch
(
$request
->
getUserVar
(
'verb'
))
{
case
'settings'
:
case
'settings'
:
AppLocale
::
requireComponents
(
LOCALE_COMPONENT_APP_COMMON
,
LOCALE_COMPONENT_PKP_MANAGER
);
$this
->
import
(
'XML2HTMLSettingsForm'
);
$this
->
import
(
'XML2HTMLSettingsForm'
);
$form
=
new
XML2HTMLSettingsForm
(
$this
,
$request
->
getContext
()
->
getId
());
// Load the custom form
$form
=
new
XML2HTMLSettingsForm
(
$this
);
if
(
$request
->
getUserVar
(
'save'
))
{
// Fetch the form the first time it loads, before
// the user has tried to save it
if
(
!
$request
->
getUserVar
(
'save'
))
{
$form
->
initData
();
return
new
JSONMessage
(
true
,
$form
->
fetch
(
$request
));
}
// Validate and save the form data
$form
->
readInputData
();
$form
->
readInputData
();
if
(
$form
->
validate
())
{
if
(
$form
->
validate
())
{
$form
->
execute
();
$form
->
execute
();
$notificationManager
=
new
NotificationManager
();
$notificationManager
->
createTrivialNotification
(
$request
->
getUser
()
->
getId
());
return
new
JSONMessage
(
true
);
return
new
JSONMessage
(
true
);
}
}
}
else
{
$form
->
initData
();
}
return
new
JSONMessage
(
true
,
$form
->
fetch
(
$request
));
}
}
return
parent
::
manage
(
$args
,
$request
);
return
parent
::
manage
(
$args
,
$request
);
}
}
function
getPluginAssetsPath
(
$request
)
{
function
getPluginAssetsPath
(
$request
)
{
return
$request
->
getBaseUrl
()
.
'/'
.
$this
->
getPluginPath
()
.
'/resources/'
;
return
$request
->
getBaseUrl
()
.
'/'
.
$this
->
getPluginPath
()
.
'/resources/'
;
}
}
...
...
This diff is collapsed.
Click to expand it.
XML2HTMLSettingsForm.inc.php
+
72
−
39
View file @
c1eb8fed
<?php
<?php
import
(
'lib.pkp.classes.form.Form'
);
import
(
'lib.pkp.classes.form.Form'
);
import
(
'classes.notification.NotificationManager'
);
class
XML2HTMLSettingsForm
extends
Form
{
class
XML2HTMLSettingsForm
extends
Form
{
private
static
$FORMAT
_SETTING
=
"format"
;
private
static
$FORMAT
=
"format"
;
private
$_contextId
;
/*
private $_contextId;
*/
private
$
_
plugin
;
private
$plugin
;
/**
/**
* Constructor
*
* @param $plugin xml2html plugin
* @param $contextId int Context ID
*/
*/
function
__construct
(
$p
lugin
,
$
contextId
)
{
function
__construct
(
XML2HTMLP
lugin
$
plugin
)
{
$this
->
_contextId
=
$contextId
;
/*
$this->_contextId = $contextId;
*/
$this
->
_
plugin
=
$plugin
;
$this
->
plugin
=
$plugin
;
parent
::
__construct
(
$plugin
->
getTemplateResource
(
'settingsForm.tpl'
));
parent
::
__construct
(
$plugin
->
getTemplateResource
(
'settingsForm.tpl'
));
$this
->
addCheck
(
new
FormValidatorPost
(
$this
));
$this
->
addCheck
(
new
FormValidatorPost
(
$this
));
$this
->
addCheck
(
new
FormValidatorCSRF
(
$this
));
$this
->
addCheck
(
new
FormValidatorCSRF
(
$this
));
}
}
/**
/**
* Initialize form data.
* Load settings already saved in the database
*
* Settings are stored by context, so that each journal, press,
* or preprint server can have different settings.
*/
*/
function
initData
()
{
public
function
initData
()
$contextId
=
$this
->
_contextId
;
{
$plugin
=
$this
->
_plugin
;
$context
=
Application
::
get
()
$this
->
setData
(
'format'
,
$plugin
->
getSetting
(
$contextId
,
XML2HTMLSettingsForm
::
$FORMAT
));
->
getRequest
()
->
getContext
();
$this
->
setData
(
'format'
,
$this
->
plugin
->
getSetting
(
$context
->
getId
(),
'format'
)
);
parent
::
initData
();
}
}
/**
/**
*
Assign form data to user-submitted data.
*
Load data that was submitted with the form
*/
*/
function
readInputData
()
{
public
function
readInputData
()
$this
->
readUserVars
(
array
(
XML2HTMLSettingsForm
::
$FORMAT
));
{
$this
->
readUserVars
([
'format'
]);
//
// // if recent items is selected, check that we have a value
// if ($this->getData('displayItems') == 'recent') {
// $this->addCheck(new FormValidator($this, 'recentItems', 'required', 'plugins.generic.webfeed.settings.recentItemsRequired'));
// }
parent
::
readInputData
();
}
}
/**
/**
* Fetch the form.
* Fetch any additional data needed for your form.
* @copydoc Form::fetch()
*
* Data assigned to the form using $this->setData() during the
* initData() or readInputData() methods will be passed to the
* template.
*
* In the example below, the plugin name is passed to the
* template so that it can be used in the URL that the form is
* submitted to.
*/
*/
function
fetch
(
$request
,
$template
=
null
,
$display
=
false
)
{
public
function
fetch
(
$request
,
$template
=
null
,
$display
=
false
)
{
$templateMgr
=
TemplateManager
::
getManager
(
$request
);
$templateMgr
=
TemplateManager
::
getManager
(
$request
);
$templateMgr
->
assign
(
'pluginName'
,
$this
->
_plugin
->
getName
());
$templateMgr
->
assign
(
'pluginName'
,
$this
->
plugin
->
getName
());
return
parent
::
fetch
(
$request
);
return
parent
::
fetch
(
$request
,
$template
,
$display
);
}
}
/**
/**
* @copydoc Form::execute()
* Save the plugin settings and notify the user
* that the save was successful
*/
*/
function
execute
(...
$functionArgs
)
{
public
function
execute
(...
$functionArgs
)
$plugin
=
$this
->
_plugin
;
{
$contextId
=
$this
->
_contextId
;
$context
=
Application
::
get
()
->
getRequest
()
$plugin
->
updateSetting
(
$contextId
,
XML2HTMLSettingsForm
::
$FORMAT
,
$this
->
getData
(
XML2HTMLSettingsForm
::
$FORMAT
));
->
getContext
();
$this
->
plugin
->
updateSetting
(
parent
::
execute
(
...
$functionArgs
);
$context
->
getId
(),
'format'
,
$this
->
getData
(
'format'
)
);
$notificationMgr
=
new
NotificationManager
();
$notificationMgr
->
createTrivialNotification
(
Application
::
get
()
->
getRequest
()
->
getUser
()
->
getId
(),
NOTIFICATION_TYPE_SUCCESS
,
[
'contents'
=>
__
(
'common.changesSaved'
)]
);
return
parent
::
execute
();
}
}
}
}
This diff is collapsed.
Click to expand it.
templates/settingsForm.tpl
+
12
−
1
View file @
c1eb8fed
...
@@ -8,6 +8,17 @@
...
@@ -8,6 +8,17 @@
<form
class=
"pkp_form"
id=
"xml2htmlSettingsForm"
method=
"post"
action=
"
{
url
router
=
$smarty.const.ROUTE_COMPONENT
op
=
"manage"
category
=
"generic"
plugin
=
$pluginName
verb
=
"settings"
save
=
true
}
"
>
<form
class=
"pkp_form"
id=
"xml2htmlSettingsForm"
method=
"post"
action=
"
{
url
router
=
$smarty.const.ROUTE_COMPONENT
op
=
"manage"
category
=
"generic"
plugin
=
$pluginName
verb
=
"settings"
save
=
true
}
"
>
<div
id=
"xml2htmlSettings"
>
<div
id=
"xml2htmlSettings"
>
TEST
{
csrf
}
{
fbvFormSection
label
=
"plugins.generic.xml2html.format"
}
<select
name=
"format"
>
<option
value=
"JATS"
{
if
$format
==
'JATS'
}
selected
{/
if
}
>
JATS
</option>
<option
value=
"TEI"
{
if
$format
==
'TEI'
}
selected
{/
if
}
>
TEI
</option>
</select>
{/
fbvFormSection
}
{
fbvFormButtons
submitText
=
"common.save"
}
</div>
</div>
</form>
</form>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment