22
22
23
23
class SectionForm extends PKPSectionForm
24
24
{
25
+ /** @var int $_serverId */
26
+ public $ _serverId ;
27
+
25
28
/**
26
29
* Constructor.
27
30
*
@@ -36,11 +39,22 @@ public function __construct($request, $sectionId = null)
36
39
$ sectionId
37
40
);
38
41
42
+ $ this ->_serverId = $ serverId = $ request ->getContext ()->getId ();
43
+
39
44
// Validation checks for this form
45
+ $ form = $ this ;
40
46
$ this ->addCheck (new \PKP \form \validation \FormValidatorLocale ($ this , 'title ' , 'required ' , 'manager.setup.form.section.nameRequired ' ));
41
47
$ this ->addCheck (new \PKP \form \validation \FormValidatorLocale ($ this , 'abbrev ' , 'required ' , 'manager.sections.form.abbrevRequired ' ));
42
- $ this ->addCheck (new \PKP \form \validation \FormValidator ($ this , 'path ' , 'required ' , 'manager.setup.form.section.pathRequired ' ));
43
- $ server = $ request ->getServer ();
48
+ $ this ->addCheck (new \PKP \form \validation \FormValidatorRegExp ($ this , 'urlPath ' , 'required ' , 'grid.section.urlPathAlphaNumeric ' , '/^[a-zA-Z0-9\/._-]+$/ ' ));
49
+ $ this ->addCheck (new \PKP \form \validation \FormValidatorCustom (
50
+ $ this ,
51
+ 'urlPath ' ,
52
+ 'required ' ,
53
+ 'grid.section.urlPathExists ' ,
54
+ function ($ urlPath ) use ($ form , $ serverId ) {
55
+ return !Repo::section ()->getByUrlPath ($ urlPath , $ serverId ) || ($ form ->getData ('oldPath ' ) != null && $ form ->getData ('oldPath ' ) == $ urlPath );
56
+ }
57
+ ));
44
58
}
45
59
46
60
/**
@@ -62,6 +76,8 @@ public function initData()
62
76
'abbrev ' => $ this ->section ->getAbbrev (null ), // Localized
63
77
'reviewFormId ' => $ this ->section ->getReviewFormId (),
64
78
'isInactive ' => $ this ->section ->getIsInactive (),
79
+ 'urlPath ' => $ this ->section ->getUrlPath (),
80
+ 'notBrowsable ' => $ this ->section ->getNotBrowsable (),
65
81
'metaIndexed ' => !$ this ->section ->getMetaIndexed (), // #2066: Inverted
66
82
'metaReviewed ' => !$ this ->section ->getMetaReviewed (), // #2066: Inverted
67
83
'abstractsNotRequired ' => $ this ->section ->getAbstractsNotRequired (),
@@ -71,7 +87,6 @@ public function initData()
71
87
'hideAuthor ' => $ this ->section ->getHideAuthor (),
72
88
'policy ' => $ this ->section ->getPolicy (null ), // Localized
73
89
'wordCount ' => $ this ->section ->getAbstractWordCount (),
74
- 'path ' => $ this ->section ->getPath (),
75
90
'description ' => $ this ->section ->getDescription (null )
76
91
]);
77
92
}
@@ -125,7 +140,12 @@ public function fetch($request, $template = null, $display = false)
125
140
public function readInputData ()
126
141
{
127
142
parent ::readInputData ();
128
- $ this ->readUserVars (['abbrev ' , 'path ' , 'description ' , 'policy ' , 'identifyType ' , 'isInactive ' , 'metaIndexed ' , 'abstractsNotRequired ' , 'editorRestriction ' , 'wordCount ' ]);
143
+ $ this ->readUserVars (['abbrev ' , 'urlPath ' , 'description ' , 'policy ' , 'identifyType ' , 'isInactive ' , 'notBrowsable ' , 'metaIndexed ' , 'abstractsNotRequired ' , 'editorRestriction ' , 'wordCount ' ]);
144
+ // For path duplicate checking; excuse the current path.
145
+ if ($ sectionId = $ this ->getSectionId ()) {
146
+ $ section = Repo::section ()->get ($ sectionId , $ this ->_serverId );
147
+ $ this ->setData ('oldPath ' , $ section ->getUrlPath ());
148
+ }
129
149
}
130
150
131
151
/**
@@ -157,9 +177,10 @@ public function execute(...$functionArgs)
157
177
// Populate/update the section object from the form
158
178
$ section ->setTitle ($ this ->getData ('title ' ), null ); // Localized
159
179
$ section ->setAbbrev ($ this ->getData ('abbrev ' ), null ); // Localized
160
- $ section ->setPath ($ this ->getData ('path ' ));
180
+ $ section ->setUrlPath ($ this ->getData ('urlPath ' ));
161
181
$ section ->setDescription ($ this ->getData ('description ' ), null ); // Localized
162
182
$ section ->setIsInactive ($ this ->getData ('isInactive ' ) ? 1 : 0 );
183
+ $ section ->setNotBrowsable ($ this ->getData ('notBrowsable ' ) ? 1 : 0 );
163
184
$ section ->setMetaIndexed ($ this ->getData ('metaIndexed ' ) ? 0 : 1 ); // #2066: Inverted
164
185
$ section ->setAbstractsNotRequired ($ this ->getData ('abstractsNotRequired ' ) ? 1 : 0 );
165
186
$ section ->setIdentifyType ($ this ->getData ('identifyType ' ), null ); // Localized
0 commit comments