Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. // this function allows for extra fields to be added to the file upload widget
  2. function playerfields_form_alter(&$form, $form_state, $form_id) {
  3. if ($form_id == "feature_node_form" || $form_id == "review_node_form" || $form_id == "story_node_form") {
  4. // each field can have multiple values, we need to add custom process function to every upload field
  5. foreach (element_children($form['field_music_player']) as $key) {
  6. if ($form['field_music_player'][$key]['#type'] == 'filefield_widget') {
  7. // we have to include original process functions along with the new custom process functions. otherwise field wont be build correctly
  8. $form['field_music_player'][$key]['#process'] = array('filefield_widget_process', 'artist_widget_process', 'track_widget_process', 'year_widget_process', 'download_widget_process');
  9. // same with validation function
  10. $form['field_music_player'][$key]['#element_validate'] = array('filefield_widget_validate', 'artist_widget_validate', 'track_widget_validate', 'year_widget_validate', 'download_widget_validate');
  11. }
  12. }
  13. // each field can have multiple values, we need to add custom process function to every upload field
  14. foreach (element_children($form['field_review_player']) as $key) {
  15. if ($form['field_review_player'][$key]['#type'] == 'filefield_widget') {
  16. // we have to include original process functions along with the new custom process functions. otherwise field wont be build correctly
  17. $form['field_review_player'][$key]['#process'] = array('filefield_widget_process', 'artist_widget_process', 'track_widget_process', 'year_widget_process', 'download_widget_process');
  18. // same with validation function
  19. $form['field_music_player'][$key]['#element_validate'] = array('filefield_widget_validate', 'artist_widget_validate', 'track_widget_validate', 'year_widget_validate', 'download_widget_validate');
  20. }
  21. }
  22. }
  23. }
  24.  
  25. //This function adds a downloadable selection field Name text entry field
  26. function download_widget_process($element, $edit, &$form_state, $form) {
  27. $file = $element['#value'];
  28.  
  29. $element['data']['download'] = array(
  30. '#options' => array(Yes,No),
  31. '#required' => TRUE,
  32. '#type' => 'select',
  33. '#title' => t('Downloadable'),
  34. '#value' => $file['fid'] ? $file['data']['download'] : ''
  35. );
  36.  
  37. return $element;
  38. }
  39.  
  40. function track_widget_validate($node, &$form) {
  41. $playerinfo = $form['values']['field_music_player'];
  42. foreach ($playerinfo as $int => $value) {
  43. if ($playerinfo[$int]['data']['track'] == NULL) {
  44. //if ($form['values']['field_music_player'][0]['data']['track'] == NULL) {
  45. form_set_error('', t('You must set a track name for each music file.'));
  46. }
  47. }
  48. //dpm($form);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement