|
30 | 30 | use PKP\linkAction\LinkAction;
|
31 | 31 | use PKP\linkAction\request\RemoteActionConfirmationModal;
|
32 | 32 | use PKP\plugins\Hook;
|
| 33 | +use PKP\validation\ValidatorFactory; |
33 | 34 |
|
34 | 35 | class IssueForm extends Form
|
35 | 36 | {
|
@@ -60,6 +61,7 @@ public function __construct($issue = null)
|
60 | 61 | return !$showTitle || implode('', $form->getData('title')) != '' ? true : false;
|
61 | 62 | }));
|
62 | 63 | $this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'urlPath', 'optional', 'validator.alpha_dash_period', '/^[a-zA-Z0-9]+([\\.\\-_][a-zA-Z0-9]+)*$/'));
|
| 64 | + |
63 | 65 | $this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
|
64 | 66 | $this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
|
65 | 67 | $this->issue = $issue;
|
@@ -143,6 +145,27 @@ public function validate($callHooks = true)
|
143 | 145 | }
|
144 | 146 | }
|
145 | 147 |
|
| 148 | + // Note! The following datePublished validation is not triggered |
| 149 | + // when JQuery DatePicker is enabled in the datePublished field. |
| 150 | + // The datePicker will convert any invalid date into a valid yyyy-mm-dd |
| 151 | + // date before the form data is submitted. |
| 152 | + |
| 153 | + if ($this->getData('datePublished')) { |
| 154 | + $validator = ValidatorFactory::make( |
| 155 | + ['value' => $this->getData('datePublished')], |
| 156 | + ['value' => ['required', 'date_format:Y-m-d']] |
| 157 | + ); |
| 158 | + |
| 159 | + if (!$validator->passes()) { |
| 160 | + $this->addError('datePublished', __('editor.issues.datePublished.invalid')); |
| 161 | + $this->addErrorField('datePublished'); |
| 162 | + } |
| 163 | + } elseif ($this->issue?->getPublished()) { |
| 164 | + // A published issue must have a published date |
| 165 | + $this->addError('datePublished', __('editor.issues.datePublished.requiredWhenPublished')); |
| 166 | + $this->addErrorField('datePublished'); |
| 167 | + } |
| 168 | + |
146 | 169 | return parent::validate($callHooks);
|
147 | 170 | }
|
148 | 171 |
|
@@ -243,9 +266,10 @@ public function execute(...$functionArgs)
|
243 | 266 | $issue->setVolume(empty($volume) ? null : $volume);
|
244 | 267 | $issue->setNumber(empty($number) ? null : $number);
|
245 | 268 | $issue->setYear(empty($year) ? null : $year);
|
246 |
| - if (!$isNewIssue) { |
247 |
| - $issue->setDatePublished($this->getData('datePublished')); |
248 |
| - } |
| 269 | + |
| 270 | + // If issue is not published, allow empty datePublished |
| 271 | + $issue->setDatePublished(!$this->getData('datePublished') && !$issue->getPublished() ? null : $this->getData('datePublished')); |
| 272 | + |
249 | 273 | $issue->setDescription($this->getData('description'), null); // Localized
|
250 | 274 | $issue->setShowVolume((int) $this->getData('showVolume'));
|
251 | 275 | $issue->setShowNumber((int) $this->getData('showNumber'));
|
|
0 commit comments