function videoftp_widget_process in Video 6.4
Same name and namespace in other branches
- 6.5 types/videoftp/videoftp_widget.inc \videoftp_widget_process()
Process an individual element.
1 string reference to 'videoftp_widget_process'
- videoftp_elements in types/
videoftp/ videoftp.module - Implementation of hook_elements().
File
- types/
videoftp/ videoftp_widget.inc, line 138 - videoftp widget hooks and callbacks.
Code
function videoftp_widget_process($element, $edit, &$form_state, $form) {
$item = $element['#value'];
$field_name = $element['#field_name'];
$delta = $element['#delta'];
$element['#theme'] = 'videoftp_widget_item';
$field = $form['#field_info'][$field_name];
if (isset($element['preview']) && $element['#value']['fid'] != 0) {
$element['preview']['#value'] = theme('videoftp_widget_preview', $element['#value']);
}
// Title is not necessary for each individual field.
if ($field['multiple'] > 0) {
unset($element['#title']);
}
// Set up the buttons first since we need to check if they were clicked.
$element['videoftp_attach'] = array(
'#type' => 'submit',
'#value' => t('Attach'),
'#submit' => array(
'node_form_submit_build_node',
),
'#ahah' => array(
// with JavaScript
'path' => 'videoftp/ahah/' . $element['#type_name'] . '/' . $element['#field_name'] . '/' . $element['#delta'],
'wrapper' => $element['#id'] . '-ahah-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
'#field_name' => $element['#field_name'],
'#delta' => $element['#delta'],
'#type_name' => $element['#type_name'],
'#weight' => 100,
'#post' => $element['#post'],
);
if (isset($element['#upload_validators'])) {
$element['videoftp_attach']['#upload_validators'] = $element['#upload_validators'];
}
$element['videoftp_remove'] = array(
// With default CCK edit forms, $element['#parents'] is array($element['#field_name'], $element['#delta']).
// However, if some module (for example, flexifield) places our widget deeper in the tree, we want to
// use that information in constructing the button name.
'#name' => implode('_', $element['#parents']) . '_videoftp_remove',
'#type' => 'submit',
'#value' => t('Remove'),
'#submit' => array(
'node_form_submit_build_node',
),
'#ahah' => array(
// with JavaScript
'path' => 'videoftp/ahah/' . $element['#type_name'] . '/' . $element['#field_name'] . '/' . $element['#delta'],
'wrapper' => $element['#id'] . '-ahah-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
'#field_name' => $element['#field_name'],
'#delta' => $element['#delta'],
'#weight' => 101,
'#post' => $element['#post'],
);
// Because the output of this field changes depending on the button clicked,
// we need to ask FAPI immediately if the remove button was clicked.
// It's not good that we call this private function, but
// $form_state['clicked_button'] is only available after this #process
// callback is finished.
if (_form_button_was_clicked($element['videoftp_remove'])) {
// Delete the file if it is currently unused. Note that field_file_delete()
// does a reference check in addition to our basic status check.
if (isset($edit['fid'])) {
$removed_file = field_file_load($edit['fid']);
if ($removed_file['status'] == 0) {
field_file_delete($removed_file);
}
}
$item = array(
'fid' => 0,
'list' => $field['list_default'],
'data' => array(
'description' => '',
'video_thumb' => '',
),
);
}
// Set access on the buttons and select.
$element['videoftp_attach']['#access'] = empty($item['fid']);
$element['videoftp_remove']['#access'] = !empty($item['fid']);
$options = videoftp_options($field);
if (empty($options)) {
$element['ftpselect'] = array(
'#type' => 'item',
'#value' => t('No suitable files found.'),
'#access' => empty($item['fid']),
);
// Hide the attach button.
$element['videoftp_attach']['#access'] = FALSE;
}
else {
array_unshift($options, t('Select Video'));
$element['ftpselect'] = array(
'#type' => 'select',
'#required' => isset($element['#required']) ? $element['#required'] : $field['required'],
'#options' => $options,
'#access' => empty($item['fid']),
'#theme' => 'videoftp_widget_file',
);
}
// Set the FID.
$element['fid'] = array(
'#type' => 'hidden',
'#value' => $item['fid'],
);
if ($item['fid'] != 0) {
$element['preview'] = array(
'#type' => 'markup',
'#value' => theme('video_widget_preview', $item),
);
}
// placeholder.. will be serialized into the data column. this is a place for widgets
// to put additional data.
$element['data'] = array(
'#tree' => TRUE,
'#access' => !empty($item['fid']),
);
// Create our thumbnails
if ($field['widget']['autothumbnail']) {
video_thumb_process($element);
}
if (!empty($field['description_field'])) {
$element['data']['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#value' => isset($item['data']['description']) ? $item['data']['description'] : '',
'#type' => variable_get('filefield_description_type', 'textfield'),
'#maxlength' => variable_get('filefield_description_length', 128),
);
}
if (!empty($field['list_field'])) {
$element['list'] = array(
'#type' => empty($item['fid']) ? 'hidden' : 'checkbox',
'#title' => t('List'),
'#value' => isset($item['list']) && !empty($item['fid']) ? $item['list'] : $field['list_default'],
'#attributes' => array(
'class' => 'filefield-list',
),
);
}
else {
$element['list'] = array(
'#type' => 'hidden',
'#value' => '1',
);
}
// Add our extra fields if in preview mode
if (!empty($item['fid'])) {
video_widget_element_settings($element);
}
// Set #element_validate in a way that it will not wipe out other
// validation functions already set by other modules.
if (empty($element['#element_validate'])) {
$element['#element_validate'] = array();
}
array_unshift($element['#element_validate'], 'videoftp_widget_validate');
// Make sure field info will be available to the validator which
// does not get the values in $form.
$form_state['#field_info'][$field['field_name']] = $field;
$element['#attributes']['id'] = $element['#id'] . '-ahah-wrapper';
$element['#prefix'] = '<div ' . drupal_attributes($element['#attributes']) . '>';
$element['#suffix'] = '</div>';
// Lets use the clicked_button #submit[0] value here instead and see how that works out for now...
if ($form_state['submitted'] == 1) {
video_widget_process($element, $form_state);
}
return $element;
}