function entity_translation_views_data_alter in Entity Translation 7
Implements hook_views_data_alter().
Add entity translation information to the various entity tables.
File
- views/
entity_translation.views.inc, line 205 - Provide views data and handlers for entity_translation.
Code
function entity_translation_views_data_alter(&$data) {
foreach (entity_get_info() as $type => $info) {
if ($info['fieldable'] && isset($data[$info['base table']])) {
$table =& $data[$info['base table']];
$table['entity_translations'] = array(
'title' => t('Entity translation: translations'),
'help' => t('Translation information.'),
'relationship' => array(
'label' => t('Translations'),
'base' => 'entity_translation',
'base field' => 'entity_id',
'relationship field' => $info['entity keys']['id'],
'handler' => 'entity_translation_handler_relationship',
// We add our information here in the definition, so we can copy it
// later.
'left_table' => $info['base table'],
'left_field' => $info['entity keys']['id'],
'entity type' => $type,
),
);
}
}
// Expose all translatable fields, using a handler based off Views' default
// field handler, that allows users to select the language to display the
// field in.
foreach (field_info_fields() as $field) {
if ($field['translatable'] && $field['storage']['type'] == 'field_sql_storage') {
// Set defaults and just change the handler, title, group, and help.
$defaults = field_views_field_default_views_data($field);
foreach ($defaults as $table_name => $table_data) {
if (isset($data[$table_name][$field['field_name']]) && isset($table_data[$field['field_name']])) {
$field_title = $table_data[$field['field_name']]['title'];
$table_data[$field['field_name']]['title'] = t('!title: translated', array(
'!title' => $field_title,
));
$table_data[$field['field_name']]['group'] = t('Entity translation');
$table_data[$field['field_name']]['help'] .= ' ' . t('Show the field !title translated into a specified language', array(
'!title' => $field_title,
));
$table_data[$field['field_name']]['field']['handler'] = 'entity_translation_handler_field_field';
$data[$table_name][$field['field_name'] . '_et'] = $table_data[$field['field_name']];
}
}
}
}
}