Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this function allows for extra fields to be added to the file upload widget
- function playerfields_form_alter(&$form, $form_state, $form_id) {
- if ($form_id == "feature_node_form" || $form_id == "review_node_form" || $form_id == "story_node_form") {
- // each field can have multiple values, we need to add custom process function to every upload field
- foreach (element_children($form['field_music_player']) as $key) {
- if ($form['field_music_player'][$key]['#type'] == 'filefield_widget') {
- // we have to include original process functions along with the new custom process functions. otherwise field wont be build correctly
- $form['field_music_player'][$key]['#process'] = array('filefield_widget_process', 'artist_widget_process', 'track_widget_process', 'year_widget_process', 'download_widget_process');
- // same with validation function
- $form['field_music_player'][$key]['#element_validate'] = array('filefield_widget_validate', 'artist_widget_validate', 'track_widget_validate', 'year_widget_validate', 'download_widget_validate');
- }
- }
- // each field can have multiple values, we need to add custom process function to every upload field
- foreach (element_children($form['field_review_player']) as $key) {
- if ($form['field_review_player'][$key]['#type'] == 'filefield_widget') {
- // we have to include original process functions along with the new custom process functions. otherwise field wont be build correctly
- $form['field_review_player'][$key]['#process'] = array('filefield_widget_process', 'artist_widget_process', 'track_widget_process', 'year_widget_process', 'download_widget_process');
- // same with validation function
- $form['field_music_player'][$key]['#element_validate'] = array('filefield_widget_validate', 'artist_widget_validate', 'track_widget_validate', 'year_widget_validate', 'download_widget_validate');
- }
- }
- }
- }
- //This function adds a downloadable selection field Name text entry field
- function download_widget_process($element, $edit, &$form_state, $form) {
- $file = $element['#value'];
- $element['data']['download'] = array(
- '#options' => array(Yes,No),
- '#required' => TRUE,
- '#type' => 'select',
- '#title' => t('Downloadable'),
- '#value' => $file['fid'] ? $file['data']['download'] : ''
- );
- return $element;
- }
- function track_widget_validate($node, &$form) {
- $playerinfo = $form['values']['field_music_player'];
- foreach ($playerinfo as $int => $value) {
- if ($playerinfo[$int]['data']['track'] == NULL) {
- //if ($form['values']['field_music_player'][0]['data']['track'] == NULL) {
- form_set_error('', t('You must set a track name for each music file.'));
- }
- }
- //dpm($form);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement