function globallink_field in GlobalLink Connect for Drupal 7.7
Same name and namespace in other branches
- 7.5 globallink_field_configuration.inc \globallink_field()
- 7.6 globallink_field_configuration.inc \globallink_field()
Renders form for globallink_field.
1 string reference to 'globallink_field'
- globallink_field_page in ./
globallink_field_configuration.inc - Returns form for globallink_field page.
File
- ./
globallink_field_configuration.inc, line 19 - Globallink_field_configuration.inc is a file that contains most functions needed on the Field Configuration UI.
Code
function globallink_field() {
module_load_include('inc', 'globallink', 'globallink');
module_load_include('inc', 'globallink', 'globallink_taxonomy/globallink_taxonomy');
$selected_value = '';
$entity_type = GLOBALLINK_ENTITY_TYPE_NODE;
if (!empty($_SESSION['globallink_selected_content_type'])) {
$selected_value = $_SESSION['globallink_selected_content_type'];
}
if (globallink_starts_with($selected_value, 'fpp:')) {
$entity_type = 'fieldable_panels_pane';
}
elseif (globallink_starts_with($selected_value, 'tax:')) {
$entity_type = 'taxonomy_term';
$arr_avail = globallink_get_all_translatable_taxonomy_types_and_names();
if (!array_key_exists($selected_value, $arr_avail)) {
$selected_value = '';
}
}
elseif (globallink_starts_with($selected_value, 'bean:')) {
$entity_type = 'bean';
}
elseif (globallink_starts_with($selected_value, 'file:')) {
$entity_type = 'file';
}
elseif (globallink_starts_with($selected_value, 'cp:')) {
$entity_type = 'commerce_product';
}
elseif (globallink_starts_with($selected_value, 'ce:')) {
$entity_type = 'custom_entity';
}
$form = array();
$n_arr = array(
'' => t('--Select Content Type--'),
);
$t_arr = globallink_get_translatable_node_types_and_names();
$node_types = $n_arr + $t_arr;
if (module_exists('globallink_fieldable_panels')) {
module_load_include('inc', 'globallink', 'globallink_fieldable_panels/globallink_fieldable_panels');
$t_arr = globallink_get_all_translatable_fpp_types_and_names();
if (!empty($t_arr)) {
$node_types += array(
'_fpp_' => t('--Select FPP Type--'),
);
$node_types += $t_arr;
}
}
if (module_exists('globallink_taxonomy')) {
module_load_include('inc', 'globallink', 'globallink_taxonomy/globallink_taxonomy');
$t_arr = globallink_get_all_translatable_taxonomy_types_and_names();
if (!empty($t_arr)) {
$node_types += array(
'_tax_' => t('--Select Vocabulary--'),
);
$node_types += $t_arr;
}
}
if (module_exists('globallink_beans')) {
module_load_include('inc', 'globallink', 'globallink_beans/globallink_beans');
$t_arr = globallink_get_all_translatable_bean_types_and_names();
if (!empty($t_arr)) {
$node_types += array(
'_bean_' => t('--Select Bean Type--'),
);
$node_types += $t_arr;
}
}
if (module_exists('globallink_file_entity')) {
module_load_include('inc', 'globallink', 'globallink_file_entity/globallink_file_entity');
$t_arr = globallink_get_all_translatable_file_types();
if (!empty($t_arr)) {
$node_types += array(
'_file_' => t('--Select File Type--'),
);
$node_types += $t_arr;
}
}
if (module_exists('globallink_commerce')) {
module_load_include('inc', 'globallink', 'globallink_commerce/globallink_commerce');
$t_arr = globallink_get_all_translatable_cp_types_and_names();
if (!empty($t_arr)) {
$node_types += array(
'_cp_' => '--Select Product Type--',
);
$node_types += $t_arr;
}
}
if (module_exists('eck')) {
module_load_include('inc', 'globallink', 'globallink_custom_entity/globallink_custom_entity');
$t_arr = globallink_get_all_translatable_customentity_types_and_names();
if (!empty($t_arr)) {
$node_types += array(
'_ce_' => t('--Select Bundles--'),
);
$node_types += $t_arr;
}
}
$form['#attributes']['class'][] = 'globallink-field';
$form['select_field'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'container-inline',
),
),
);
$form['select_field']['select_type'] = array(
'#type' => 'select',
'#title' => t('Content Type'),
'#options' => $node_types,
'#default_value' => $selected_value,
'#attributes' => array(
'class' => array(
'globallink-field-select-type',
),
),
'#field_suffix' => ' ',
);
$form['select_field']['select_entity_type'] = array(
'#type' => 'hidden',
'#value' => $entity_type,
);
$form['select_field']['go'] = array(
'#type' => 'submit',
'#value' => t('Go'),
'#attributes' => array(
'style' => 'display: none;',
),
);
if ($selected_value != '') {
$disabled = FALSE;
$f_arr = array(
'[all]' => t('All'),
);
switch ($entity_type) {
case GLOBALLINK_ENTITY_TYPE_NODE:
$p_arr = globallink_get_pending_fields($selected_value, $entity_type);
break;
case 'fieldable_panels_pane':
$fpp_type = str_replace('fpp:', '', $selected_value);
$p_arr = globallink_get_pending_fields($fpp_type, $entity_type);
break;
case 'taxonomy_term':
$tax_type = str_replace('tax:', '', $selected_value);
$p_arr = globallink_get_pending_fields($tax_type, $entity_type);
break;
case GLOBALLINK_ENTITY_TYPE_BEAN:
$bean_type = str_replace('bean:', '', $selected_value);
$p_arr = globallink_get_pending_fields($bean_type, $entity_type);
break;
case 'file':
$file_type = str_replace('file:', '', $selected_value);
$p_arr = globallink_get_pending_fields($file_type, $entity_type);
break;
case GLOBALLINK_ENTITY_TYPE_COM:
$file_type = str_replace('cp:', '', $selected_value);
$p_arr = globallink_get_pending_fields($file_type, $entity_type);
break;
case 'custom_entity':
$machine_name = str_replace('ce:', '', $selected_value);
$entity_type = globallink_get_entity_type_for_bundle($machine_name);
$bundle = $node_types[$selected_value];
$selected_value = $bundle;
$p_arr = globallink_get_pending_fields($bundle, $entity_type);
break;
}
$pending_fields = $f_arr + $p_arr;
if (count($pending_fields) == 1) {
$pending_fields = array(
'' => '--Select--',
);
$disabled = TRUE;
}
$form['select_field']['pending_fields'] = array(
'#type' => 'select',
'#title' => ' Fields: ',
'#options' => $pending_fields,
'#field_suffix' => ' ',
);
$form['select_field']['add_field'] = array(
'#type' => 'submit',
'#value' => t('Add'),
'#disabled' => $disabled,
);
$form['select_field']['br_markup'] = array(
'#type' => 'markup',
'#markup' => '<BR/><BR/>',
);
$header = array(
'field_label' => array(
'field' => 'field_label',
'data' => t('Field Label'),
),
'field_name' => array(
'field' => 'field_name',
'data' => t('Field Name'),
),
'field_type' => array(
'field' => 'field_type',
'data' => t('Field Type'),
),
'bundle' => array(
'field' => 'bundle',
'data' => t('Bundle'),
),
);
$ignore_field_types = array(
'list_boolean',
'taxonomy_term_reference',
'list_integer',
'list_text',
'list_float',
);
$query = db_select('globallink_field_config', 'tf')
->fields('tf')
->condition('content_type', $selected_value, '=')
->condition('field_type', $ignore_field_types, 'NOT IN')
->extend('TableSort')
->orderByHeader($header);
$results = $query
->execute();
$count = 0;
$rows = array();
$default_values = array();
$field_types = field_info_field_types();
$field_bundles = field_info_bundles();
foreach ($results as $item) {
if ($item->field_type == 'field_collection') {
continue;
}
if ($item->entity_type != 'node' || $item->entity_type == 'node' && entity_translation_node_supported_type($item->content_type)) {
if ($item->field_name != 'metatags' && strpos($item->field_name, '@summary') == FALSE) {
$query = db_select('field_config', 'tf')
->fields('tf', array(
'field_name',
))
->condition('field_name', $item->field_name, '=')
->condition(db_or()
->condition(db_and()
->condition('translatable', '1', '='))
->condition(db_and()
->condition('type', 'image', '=')));
$result_field = $query
->execute();
$row_count = $result_field
->rowCount();
if (!$row_count) {
continue 1;
}
}
}
$count++;
$bundle_info = $field_bundles[$item->entity_type];
$bundle_text = $item->bundle;
switch ($item->entity_type) {
case GLOBALLINK_ENTITY_TYPE_NODE:
if (isset($bundle_info[$item->content_type])) {
$bundle_text = $bundle_info[$item->content_type]['label'];
}
break;
case 'fieldable_panels_pane':
$exploded_bl = explode(':', $item->bundle);
$bundle = $exploded_bl[1];
if (!field_info_instance($item->entity_type, $item->field_name, $bundle)) {
continue 2;
}
if (isset($bundle_info[$bundle])) {
$bundle_text = $bundle_info[$bundle]['label'];
}
break;
case 'taxonomy_term':
$exploded_bl = explode(':', $item->bundle);
$bundle = $exploded_bl[1];
if (!field_info_instance($item->entity_type, $item->field_name, $bundle) && $item->field_name !== 'metatags') {
continue 2;
}
if (isset($bundle_info[$bundle])) {
$bundle_text = $bundle_info[$bundle]['label'];
}
break;
case 'bean':
$exploded_bl = explode(':', $item->bundle);
$bundle = $exploded_bl[1];
if (isset($bundle_info[$bundle])) {
$bundle_text = $bundle_info[$bundle]['label'];
}
break;
case 'file':
$exploded_bl = explode(':', $item->bundle);
$bundle = $exploded_bl[1];
if (isset($bundle_info[$bundle])) {
$bundle_text = $bundle_info[$bundle]['label'];
}
break;
case GLOBALLINK_ENTITY_TYPE_COM:
$exploded_bl = explode(':', $item->bundle);
$bundle = $exploded_bl[1];
if (isset($bundle_info[$bundle])) {
$bundle_text = $bundle_info[$bundle]['label'];
}
break;
}
$rows[$item->fid] = array(
'field_label' => $item->field_label,
'bundle' => $bundle_text,
'field_name' => $item->field_name,
'field_type' => isset($field_types[$item->field_type]) ? $field_types[$item->field_type]['label'] : $item->field_type,
);
if ($item->translatable == 1) {
$default_values[$item->fid] = 1;
}
else {
$default_values[$item->fid] = 0;
}
}
$form['field-heading'] = array(
'#type' => 'container',
);
$form['field-heading'][] = array(
'#markup' => '<em>' . t('Check all the fields that you wish to translate for this content type.') . '</em><br>',
);
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#empty' => t('No items available'),
'#default_value' => $default_values,
);
if (globallink_content_type_workbench_enabled($selected_value)) {
if ($states = workbench_moderation_state_labels()) {
$mod_key = '';
$current_value = variable_get('globallink_moderation_' . $selected_value, FALSE);
if ($current_value) {
$states_value = $states[$current_value];
unset($states[$current_value]);
$new_value = array(
$mod_key => t('Current: @state', array(
'@state' => $states_value,
)),
);
$states = array_merge($new_value, $states);
}
$form['state'] = array(
'#title' => t('Moderation state (after import)'),
'#type' => 'select',
'#options' => $states,
'#default_value' => $mod_key,
);
}
}
if ($count > 0) {
$form['submit_field_update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
}
}
return $form;
}