function _asset_widget_form in Asset 5
Same name and namespace in other branches
- 6 modules/asset_content.inc \_asset_widget_form()
- 6 inc/modules/asset_content.inc \_asset_widget_form()
2 calls to _asset_widget_form()
- asset_widget in modules/
asset_content.inc - Define the behavior of a widget.
- asset_widget_js in modules/
asset_content.inc
File
- modules/
asset_content.inc, line 323
Code
function _asset_widget_form(&$form_item, $field, $node_field, $delta = 0) {
module_invoke('i18n', 'language_rtl') ? $rtl = "right" : ($rtl = "left");
$field_name = $field['field_name'];
$item_count = $delta + 1;
$form_item = array(
'#tree' => TRUE,
);
// Set the title
$form_item['value'] = array(
'#type' => 'textfield',
'#title' => t($field['widget']['label']) . " " . $item_count,
'#attributes' => array(
'disabled' => 'disabled',
),
'#default_value' => $node_field['value'],
);
// Set the aid (hidden)
$form_item['aid'] = array(
'#type' => 'hidden',
'#default_value' => $node_field['aid'],
);
if (!empty($node_field['aid'])) {
$aid = $node_field['aid'];
// Set the preview
$is_image = array(
'jpg',
'jpeg',
'png',
'gif',
'tif',
'tiff',
'bmp',
);
$a = asset_load(array(
'aid' => $aid,
));
// Preview the image
if (in_array($a->extension, $is_image)) {
if (variable_get('asset_imagecache', 0)) {
$presets = _imagecache_get_presets();
$preset = $presets[variable_get('asset_imagecache', 0)];
$preview = theme('imagecache', $preset, str_replace("//", "/", $a->filepath));
}
else {
$asset = array(
'aid' => $aid,
'format' => 'image',
'formatter' => 'asset',
'width' => '120',
'height' => '80',
);
$preview = asset_render_macro($asset);
}
$form_item['preview'] = array(
'#prefix' => '<div id="preview_' . $field_name . '_' . $delta . '" style="float:' . $rtl . '">',
'#suffix' => '</div>',
'#value' => $preview,
);
}
else {
if (asset_preview($aid)) {
$form_item['preview'] = array(
'#prefix' => '<div id="preview_' . $field_name . '_' . $delta . '" style="float:' . $rtl . '">',
'#suffix' => '</div>',
'#value' => asset_preview($aid),
);
}
else {
// Display a placeholder for assets that don't have a preview: .mov, .doc, ...
$form_item['preview'] = array(
'#type' => 'markup',
'#value' => '<div id="preview_' . $field_name . '_' . $delta . '" style="float:' . $rtl . '"></div>',
);
}
}
}
else {
$form_item['preview'] = array(
'#type' => 'markup',
'#value' => '<div id="preview_' . $field_name . '_' . $delta . '" style="float:' . $rtl . '"></div>',
);
}
// Set the caption
$form_item['caption'] = array(
'#type' => 'textfield',
'#maxlength' => '256',
'#default_value' => $node_field['caption'],
'#description' => 'Enter the caption for this asset',
'#prefix' => '<div style="margin-' . $rtl . ':130px"><table style="width:400px;margin-top:-15px;border-collapse:inherit"><tr><td style="padding:0px;margin:0px;text-align:center;padding-top:16px;width:10px" valign="top">' . l('<img src="' . base_path() . drupal_get_path('module', 'asset') . '/lullacons/doc-option-add.png' . '" alt="' . t("Insert asset") . '" title="' . t("Insert asset") . '"/>', 'asset/wizard/textfield', array(
'class' => 'asset-textfield-link',
'id' => 'asset-link-' . $field_name . '-' . $delta . '-value',
'onclick' => "window.open(this.href, 'asset_textfield_link', 'width=614,height=400,scrollbars=yes,status=yes,resizable=yes,toolbar=no,menubar=no'); return false",
), 'textfield=' . $field_name . '[' . $delta . '][value]&aidfield=' . $field_name . '[' . $delta . '][aid]&delta=' . $delta, NULL, FALSE, TRUE) . '</td><td>',
'#suffix' => '</td></tr></table></div>',
);
// Set the copyright
$form_item['copyright'] = array(
'#type' => 'textfield',
'#maxlength' => '256',
'#default_value' => $node_field['copyright'],
'#description' => 'Enter the copyright for this asset',
'#prefix' => '<div style="margin-' . $rtl . ':130px"><table style="width:400px;margin-top:-30px;border-collapse:inherit"><tr><td style="padding:0px;margin:0px;text-align:center;padding-top:16px;width:10px" valign="top">' . l('<img src="' . base_path() . drupal_get_path('module', 'asset') . '/lullacons/doc-option-remove.png' . '" alt="' . t("Delete asset") . '" title="' . t("Delete asset") . '"/>', '', array(
'onclick' => "\n document.getElementById('edit-" . str_replace("_", "-", $field_name) . "-" . $delta . "-value').value='';\n document.getElementById('edit-" . str_replace("_", "-", $field_name) . "-" . $delta . "-aid').value='';\n document.getElementById('edit-" . str_replace("_", "-", $field_name) . "-" . $delta . "-caption').value='';\n document.getElementById('edit-" . str_replace("_", "-", $field_name) . "-" . $delta . "-copyright').value='';\n document.getElementById('preview_" . $field_name . "_" . $delta . "').innerHTML='';\n return false;",
), NULL, NULL, FALSE, TRUE) . '</td><td>',
'#suffix' => '</td></tr></table></div>',
);
if ($delta == 0 && isset($field['widget']['description']) && !empty($field['widget']['description'])) {
$form_item['description'] = array(
'#value' => '<div class="description">' . $field['widget']['description'] . '</div>',
);
}
$form_item['#prefix'] = '<div class="clear-block">';
$form_item['#suffix'] = '</div>';
}