function video_customfields_form_alter in Video 5
Same name and namespace in other branches
- 6 plugins/video_customfields/video_customfields.module \video_customfields_form_alter()
Implementation of hook_form_alter() We use this to add some custom fields to the video creation form. Fields will be displayed only if field title is set on settings page.
File
- plugins/
video_customfields/ video_customfields.module, line 118 - Enable addition of custom fileds on video nodes created by video module.
Code
function video_customfields_form_alter($form_id, &$form) {
if ($form_id == 'video_node_form' && isset($form['video']) && user_access('insert custom fields')) {
//get node object from form
$node = $form['#node'];
$title1 = variable_get('video_customfield1', '');
$title2 = variable_get('video_customfield2', '');
$title3 = variable_get('video_customfield3', '');
$title4 = variable_get('video_customfield4', '');
$title5 = variable_get('video_customfield5', '');
$title6 = variable_get('video_customfield6', '');
//Only display the custom fields group if atleast one field has a title.
if ($title1 . $title2 . $title3 . $title4 . $title5 . $title6 != '') {
$form['customfields'] = array(
'#type' => 'fieldset',
'#title' => variable_get('video_customfieldtitle', 'Custom Fields'),
'#collapsible' => TRUE,
'#collapsed' => variable_get('video_customgroupcollapsed', FALSE),
'#weight' => -17,
);
//If the custom field title is not blank, then display it.
if ($title1 != '') {
$form['customfields']['custom_field_1'] = array(
'#type' => 'textfield',
'#title' => $title1,
'#maxlength' => 250,
'#default_value' => $node->custom_field_1,
);
}
if ($title2 != '') {
$form['customfields']['custom_field_2'] = array(
'#type' => 'textfield',
'#title' => $title2,
'#maxlength' => 250,
'#default_value' => $node->custom_field_2,
);
}
if ($title3 != '') {
$form['customfields']['custom_field_3'] = array(
'#type' => 'textfield',
'#title' => $title3,
'#maxlength' => 250,
'#default_value' => $node->custom_field_3,
);
}
if ($title4 != '') {
$form['customfields']['custom_field_4'] = array(
'#type' => 'textfield',
'#title' => $title4,
'#maxlength' => 250,
'#default_value' => $node->custom_field_4,
);
}
if ($title5 != '') {
$form['customfields']['custom_field_5'] = array(
'#type' => 'textarea',
'#title' => $title5,
'#rows' => 4,
'#default_value' => $node->custom_field_5,
);
}
if ($title6 != '') {
$form['customfields']['custom_field_6'] = array(
'#type' => 'textarea',
'#title' => $title6,
'#rows' => 4,
'#default_value' => $node->custom_field_6,
);
}
}
}
}