summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoachim Noreiko2011-12-07 13:25:10 (GMT)
committer Joachim Noreiko2011-12-07 13:25:10 (GMT)
commit2095eb450a44f0566ff0a6499d1d232362928b28 (patch)
treea88b87f24ea243e78d2271ade31c7e362e2e2f82
parent31538328885560172434fbf9bba463fd77bb0a99 (diff)
- #616590 by becw, joachim: Fixed links to non-existent views for tables without primary keys.
-rw-r--r--data_ui/data_ui.admin.inc13
-rw-r--r--data_ui/data_ui.module16
-rw-r--r--data_ui/data_ui.views_default.inc2
3 files changed, 24 insertions, 7 deletions
diff --git a/data_ui/data_ui.admin.inc b/data_ui/data_ui.admin.inc
index d107524..ad89c11 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 6eeb4b6..c48ab4d 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 = '<p>' .
+ 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.") .
+ '</p>';
+
switch ($path) {
case 'admin/content/data':
$output = '<p>' . 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'))) . '</p>';
+ $output .= $no_primary_key_text;
return $output;
case 'admin/structure/data/adopt':
$output = '<p>' . t('Manage database tables that aren\'t claimed by other modules. Adopting tables listed here will add them to Data\'s list of tables.') . '</p>';
@@ -18,6 +23,7 @@ function data_ui_help($path, $arg) {
case 'admin/structure/data':
if (module_exists('views')) {
$output = '<p>' . 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'))) . '</p>';
+ $output .= $no_primary_key_text;
}
else {
$output = '<p>' . t('Manage data tables.') . '</p>';
@@ -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 4e95f3c..5bc3349 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,