Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#3157 fix required tagit metadata fields validation #3158

Closed
wants to merge 2 commits into from

Conversation

bozana
Copy link
Collaborator

@bozana bozana commented Dec 4, 2017

s. #3157

@@ -67,6 +67,10 @@ function addChecks($submission) {
if ($context->getSetting($key . 'Required')) switch(1) {
case in_array($key, $this->getLocaleFieldNames()):
$this->_parentForm->addCheck(new FormValidatorLocale($this->_parentForm, $key, 'required', 'common.required', $submission->getLocale()));
break;
case in_array($key, $this->getTagitFieldNames()):
$this->_parentForm->addCheck(new FormValidatorCustom($this->_parentForm, $key, 'required', 'common.required', create_function('$key,$form,$name', '$data = $form->getData(\'keywords\'); return array_key_exists($name, $data);'), array($this->_parentForm, $submission->getLocale().'-'.$key)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening when we call $form->getData(\'keywords\')? It seems to me like the form can only have one tag it field's data stored at keywords. So if I have metadata for disciplines and keywords, how does it know to check for each one? I may be missing something here, but just trying to figure out what's happening here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tagit fields are called keywords, s. https://github.com/pkp/pkp-lib/blob/master/templates/form/keywordInput.tpl -- I do not why -- maybe there was a reason for that. Then they have an index <locale>-<key>. i.e. for the discipline and multilanguage the field would have the name keywords['en-US-disciplines'][] and for the keywords it would be keywords['en-US-keywords'][]. Thus the function gets all tagit fields with $form->getData(\'keywords\') and then it looks if the appropriate array key exists -- for example, for key = disciplines and submission locale = en-US , the function would look if that array key en-US-disciplines exists in $data. The appropriate array key is given as the last parameter $name = $submission->getLocale().'-'.$key to the function.
OK?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok! That makes sense. No wonder I was confused. :)

@NateWr
Copy link
Member

NateWr commented Jan 5, 2018

Replaced by #3241

@NateWr NateWr closed this Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants