Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Currently mobwrite module by passes Drupal's validation to allow multiple users to save. This functionality is needed, but so is the rest of the validation.
// This "pre validation" function merely resents the timestamp of the node if its been saved by another user
159 // Referenced above in mobwrite_form_alter() via $form[]['#validate'][0] => mobwrite_pre_validation; and then mimics
160 // node_form_validate() at the end to put the validation back on track.
161 function mobwrite_pre_validation($node, $form) {
162 if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
163 $mobwrite_validate_timestamp = $node->changed;
164 $mobwrite_validate_update = db_update('node')
165 ->fields(array('changed' => $mobwrite_validate_timestamp))
166 ->execute();
167 }
168 // The rest of mobwrite_pre_validation() is a copy of node_from_validate:7
169 // $form_state['node'] contains the actual entity being edited, but we must
170 // not update it with form values that have not yet been validated, so we
171 // create a pseudo-entity to use during validation.
172 //$node = (object) $form_state['values'];
173 //node_validate($node, $form);
174
175 // Field validation. Requires access to $form_state, so this cannot be
176 // done in node_validate() as it currently exists.
177 // known bug: uncommenting breaks the page.
178 //entity_form_field_validate('node', $form, $form_state)
179 } // function mobwrite_node_validate()
Comments
Comment #1
tomdavidson CreditAttribution: tomdavidson commentedComment #2
tomdavidson CreditAttribution: tomdavidson commentedImplementing hook_validate with the same guts as my own function but with the expectation that the rest of Drupal's validation would be kept has no effect what so ever:
The above code (issue description the above code in this comment) functions, but it skips out on the rest of the validation process:
But reseting the callback seams to work:
How do I test and verify?
Comment #3
tomdavidson CreditAttribution: tomdavidson commentedRather than $form['#validate'][0] = 'mobwrite_validation'; in hook_form_alter() and then again $form['#validate'][0] = 'node_validation'; in mobwrite_validation() - sounds like even this might have not mattered.
Code uses array_unshift($form['#validate'], 'mobwrite_validation'); in hook_form_alter().
This provides the needed functionaliy - its it best practice? mobwrite_validation() might be expanding/changing next week with the submitt and auto save type functionality.
Comment #4
tomdavidson CreditAttribution: tomdavidson commentedoops, array_unshift($form['#validate'][], 'mobwrite_validation'); generates warning and does not work, "Warning: array_unshift(): The first argument should be an array in mobwrite_form_alter() (line 106 of /home/clients/websites/w_3f5b7z/public_html/3f5b7z/mw/sites/all/modules/mobwrite/mobwrite.module)."
reverting back to $form['#validate'][0] = 'mobwrite_validation' in form_alter() and $form['#validate'][0] = 'node_validation' in mbowrite_validation().
Comment #5
dmitrig01 CreditAttribution: dmitrig01 commentedA better approach, which wouldn't require any messing around with #validate, would be setting $form['changed']['#value'] to 0 in your _form_alter. This works because $form['changed'] has '#type' => 'value', which means it's like a hidden input, except it hasn't been rendered to the HTML - its gets passed
straight through to the submit as $form_state['values']['changed']. This value isn't depended upon anywhere except the validate - the changed value gets updated in node_save
Comment #6
tomdavidson CreditAttribution: tomdavidson commented$form['changed'] is also used for the timestamp in revisions. If we do some think like = 0, then it will mess up the revision right? And thinking about it, so does the existing mobwrite_validation():
poking around more.
Comment #7
tomdavidson CreditAttribution: tomdavidson commentedbtw: $form['changed'] == 0; Does not allow the prior editor to save after a later editor already has.
revision_timstamp, changed and changed from the node table are all = and shouldn't bite "if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed))" of node validate, but it does.
The task is to "unskip" Drupal's validation. I am reverting to what does work, but am renaming it to mobwrite_pre_validation() to avoid confusion with an implementation of hook_validate().
I agree there is prob to be a better way. But this issue I think is fixed and the solution does not appear grotesque. A more elegant solution will be sought when the remaining tasks are completed. Of course if dmitrig01 or lyricnz says issue is not resolved, ill come back to it right away.