function tmgmt_entity_ui_translate_form in Translation Management Tool 7
Entity translation overview form.
1 string reference to 'tmgmt_entity_ui_translate_form'
- tmgmt_entity_ui_page_alter in sources/
entity/ ui/ tmgmt_entity_ui.module - Implements hook_page_alter().
File
- sources/
entity/ ui/ tmgmt_entity_ui.pages.inc, line 12 - Provides page and form callbacks for the Translation Management Tool Entity Source User Interface module.
Code
function tmgmt_entity_ui_translate_form($form, &$form_state, $build) {
// Store the entity in the form state so we can easily create the job in the
// submit handler.
$form_state['entity_type'] = $build['#entity_type'];
$form_state['entity'] = $build['#entity'];
$overview = $build['entity_translation_overview'];
list($id, $vid, $bundle) = entity_extract_ids($form_state['entity_type'], $form_state['entity']);
$form['top_actions']['#type'] = 'actions';
$form['top_actions']['#weight'] = -10;
tmgmt_ui_add_cart_form($form['top_actions'], $form_state, 'entity', $build['#entity_type'], $id);
// Inject our additional column into the header.
array_splice($overview['#header'], -1, 0, array(
t('Pending Translations'),
));
// Make this a tableselect form.
$form['languages'] = array(
'#type' => 'tableselect',
'#header' => $overview['#header'],
'#options' => array(),
);
$languages = language_list();
// Check if there is a job / job item that references this translation.
$entity_language = entity_language($form_state['entity_type'], $form_state['entity']);
$items = tmgmt_job_item_load_latest('entity', $form_state['entity_type'], $id, $entity_language);
foreach ($languages as $langcode => $language) {
if ($langcode == LANGUAGE_NONE) {
// Never show language neutral on the overview.
continue;
}
// Since the keys are numeric and in the same order we can shift one element
// after the other from the original non-form rows.
$option = array_shift($overview['#rows']);
if ($langcode == $entity_language) {
$additional = '<strong>' . t('Source') . '</strong>';
// This is the source object so we disable the checkbox for this row.
$form['languages'][$langcode] = array(
'#type' => 'checkbox',
'#disabled' => TRUE,
);
}
elseif (isset($items[$langcode])) {
$item = $items[$langcode];
$uri = $item
->uri();
$wrapper = entity_metadata_wrapper('tmgmt_job_item', $item);
$additional = l($wrapper->state
->label(), $uri['path'], array(
'query' => array(
'destination' => current_path(),
),
));
// Disable the checkbox for this row since there is already a translation
// in progress that has not yet been finished. This way we make sure that
// we don't stack multiple active translations for the same item on top
// of each other.
$form['languages'][$langcode] = array(
'#type' => 'checkbox',
'#disabled' => TRUE,
);
}
else {
// There is no translation job / job item for this target language.
$additional = t('None');
}
// Inject the additional column into the array.
// The generated form structure has changed, support both an additional
// 'data' key (that is not supported by tableselect) and the old version
// without.
if (isset($option['data'])) {
array_splice($option['data'], -1, 0, array(
$additional,
));
// Append the current option array to the form.
$form['languages']['#options'][$langcode] = $option['data'];
}
else {
array_splice($option, -1, 0, array(
$additional,
));
// Append the current option array to the form.
$form['languages']['#options'][$langcode] = $option;
}
}
$form['actions']['#type'] = 'actions';
$form['actions']['request'] = array(
'#type' => 'submit',
'#value' => t('Request translation'),
'#submit' => array(
'tmgmt_entity_ui_translate_form_submit',
),
'#validate' => array(
'tmgmt_entity_ui_translate_form_validate',
),
);
return $form;
}