diff --git a/data_ui/data_ui.admin.inc b/data_ui/data_ui.admin.inc index d1075249df34e9ee46e05b965ef448d3abd91b4c..ad89c11755d645aabc9b43303f7ade050969b905 100644 --- a/data_ui/data_ui.admin.inc +++ b/data_ui/data_ui.admin.inc @@ -18,7 +18,8 @@ function data_ui_view() { db_query('SELECT COUNT(*) FROM {' . db_escape_table($table->get('name')) . '}')->fetchField(), ); if (module_exists('views')) { - $row[] = l(t('View'), data_ui_get_default_path($table->get('name'))); + $path = data_ui_get_default_path($table->get('name')); + $row[] = $path ? l(t('View'), $path) : l(t('Edit schema'), 'admin/structure/data/edit/' . $table->get('name')); } $rows[] = $row; } @@ -57,9 +58,13 @@ function data_ui_manage() { $operations[] = l(t('Export'), 'admin/structure/data/export/' . $table->get('name')); } if (module_exists('views')) { - $operations[] = l(t('View records'), 'admin/content/data/view/' . $table->get('name')); - if (user_access('administer views')) { - $operations[] = l(t('Edit view'), 'admin/structure/views/view/' . $table->get('name') . '/edit'); + // The existence of a path serves as a test that a view is provided. + $path = data_ui_get_default_path($table->get('name')); + if ($path) { + $operations[] = l(t('View records'), 'admin/content/data/view/' . $table->get('name')); + if (user_access('administer views')) { + $operations[] = l(t('Edit view'), 'admin/structure/views/view/' . $table->get('name') . '/edit'); + } } } diff --git a/data_ui/data_ui.module b/data_ui/data_ui.module index 6eeb4b66406e7f88436ecac04275dedbc8f20ad2..c48ab4d497bd64650f09a3202d5fe7509d501297 100644 --- a/data_ui/data_ui.module +++ b/data_ui/data_ui.module @@ -8,9 +8,14 @@ * Implements hook_help(). */ function data_ui_help($path, $arg) { + $no_primary_key_text = '

' . + t("Some tables may not have a 'view' link; this happens when a table doesn't have a primary key or is not joined to another table with a primary key. You can add a primary key field or a join from the table's 'Edit schema' page.") . + '

'; + switch ($path) { case 'admin/content/data': $output = '

' . t('View content in data tables. If you would like to edit these tables, visit the !data_manage_page.', array('!data_manage_page' => l(t('Data table management page'), 'admin/structure/data'))) . '

'; + $output .= $no_primary_key_text; return $output; case 'admin/structure/data/adopt': $output = '

' . t('Manage database tables that aren\'t claimed by other modules. Adopting tables listed here will add them to Data\'s list of tables.') . '

'; @@ -18,6 +23,7 @@ function data_ui_help($path, $arg) { case 'admin/structure/data': if (module_exists('views')) { $output = '

' . t('Manage data tables. If you would like to view the content of these tables, visit the !data_view_page.', array('!data_view_page' => l(t('Data table content page'), 'admin/content/data'))) . '

'; + $output .= $no_primary_key_text; } else { $output = '

' . t('Manage data tables.') . '

'; @@ -247,7 +253,13 @@ function data_ui_permission() { */ function data_ui_get_default_path($name) { if ($table = data_get_table($name)) { - // Check, whether there is a data mananged table to the left. + // Check whether this can be a Views base table. + $table_schema = $table->get('table_schema'); + if (isset($table_schema['primary key'])) { + return 'admin/content/data/view/' . $name; + } + + // Check whether there is a data mananged table to the left. // @todo: go all the way to the left. $path = ''; $meta = $table->get('meta'); @@ -256,8 +268,8 @@ function data_ui_get_default_path($name) { if ($left_table = data_get_table($left_table_name)) { $path .= $left_table_name . '/'; } + return 'admin/content/data/view/' . $path . $name; } - return 'admin/content/data/view/' . $path . $name; } return ''; } diff --git a/data_ui/data_ui.views_default.inc b/data_ui/data_ui.views_default.inc index 4e95f3c15364503c1ba227d80e2109c8223dc4b0..5bc334935dd7d7a8702f67b90ab7fec24e037192 100644 --- a/data_ui/data_ui.views_default.inc +++ b/data_ui/data_ui.views_default.inc @@ -49,7 +49,7 @@ function data_ui_views_default_views() { $meta_fields = $meta['fields']; foreach ($schema['fields'] as $field_name => $field) { $fields[$field_name] = array( - 'label' => isset($meta_fields[$field_name]['label']) ? $meta_fields[$field_name]['label'] : $field_name, + 'label' => $meta_fields[$field_name]['label'] ? $meta_fields[$field_name]['label'] : $field_name, 'id' => $field_name, 'table' => $table->get('name'), 'field' => $field_name,