function _support_ensure_upload_field in Support Ticketing System 7
Make sure support_ticket has a field available for node and comment file attachments.
2 calls to _support_ensure_upload_field()
- support_install in ./
support.install - Install support database schema.
- support_update_7001 in ./
support.install - Ensure an upload field is created for uploading to comments.
File
- ./
support.install, line 499 - Install, update and uninstall functions for the ._support module.
Code
function _support_ensure_upload_field() {
// Force the file module to be enabled.
module_enable(array(
'file',
));
// If you want to migrate from the comment_upload data in D6 but don't want
// to use this automatically created field, create a file field manually
// and set this variable to the field name.
$field_name = variable_get('support_mail_upload_field', 'support_ticket_upload');
$info = field_info_field($field_name);
if (!$info) {
// Field is missing, create it.
$field = array(
'field_name' => $field_name,
'type' => 'file',
'module' => 'file',
'locked' => FALSE,
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'translatable' => FALSE,
'settings' => array(
'display_field' => 1,
'display_default' => variable_get('upload_list_default', 1),
'uri_scheme' => file_default_scheme(),
'default_file' => 0,
),
);
field_create_field($field);
}
$upload_size = variable_get('upload_uploadsize_default', 1);
// Base instance.
$base_instance = array(
'field_name' => $field_name,
'entity_type' => NULL,
'bundle' => NULL,
'label' => 'File attachments',
'required' => 0,
'description' => '',
'widget' => array(
'weight' => '1',
'settings' => array(
'progress_indicator' => 'throbber',
),
'type' => 'file_generic',
),
'settings' => array(
'max_filesize' => $upload_size ? $upload_size . ' MB' : '',
'file_extensions' => variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'),
'file_directory' => 'support',
// @@@ I think this is a good idea personally but need a second opinion.
'description_field' => 1,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'file_table',
'settings' => array(),
'weight' => 0,
'module' => 'file',
),
),
);
if (!$info || !isset($info['bundles']['comment']) || !in_array('comment_node_support_ticket', $info['bundles']['comment'])) {
// Field isn't associated with support_ticket comments, attach it.
$instance = $base_instance;
$instance['entity_type'] = 'comment';
$instance['bundle'] = 'comment_node_support_ticket';
$instance['display']['full'] = $instance['display']['default'];
field_create_instance($instance);
}
if (!$info || !isset($info['bundles']['node']) || !in_array('support_ticket', $info['bundles']['node'])) {
// Additionally check if the 'upload' field is available -- we support falling back to that
// if the field is missing, so users with 6.x sites don't end up with 2 fields.
$info2 = field_info_field('upload');
if (!$info2 || !isset($info2['bundles']['node']) || !in_array('support_ticket', $info2['bundles']['node'])) {
// Field isn't associated with support_ticket nodes and there wasn't a legacy upload field, attach it.
$instance = $base_instance;
$instance['entity_type'] = 'node';
$instance['bundle'] = 'support_ticket';
$instance['display']['full'] = $instance['display']['default'];
$instance['display']['rss'] = $instance['display']['default'];
$instance['display']['teaser'] = $instance['display']['default'];
$instance['display']['teaser']['type'] = 'hidden';
field_create_instance($instance);
}
}
}