You are here

data_ui.module in Data 6

Same filename and directory in other branches
  1. 7 data_ui/data_ui.module

Hooks and API functions for Data UI module.

File

data_ui/data_ui.module
View source
<?php

/**
 * @file
 * Hooks and API functions for Data UI module.
 */

/**
 * Implementation of hook_help().
 */
function data_ui_help($path, $arg) {
  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/build/data'),
      )) . '</p><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>';
      return $output;
    case 'admin/build/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>';
      return $output;
    case 'admin/build/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>';
      }
      else {
        $output = '<p>' . t('Manage data tables.') . '</p>';
      }
      return $output;
  }
}

/**
 * Implementation of hook_menu()
 */
function data_ui_menu() {
  $items = array();
  if (module_exists('views')) {
    $items['admin/content/data'] = array(
      'title' => 'Data tables',
      'description' => 'View data tables.',
      'page callback' => 'data_ui_view',
      'file' => 'data_ui.admin.inc',
      'access arguments' => array(
        'administer data tables',
      ),
    );
  }
  $items['admin/build/data'] = array(
    'title' => 'Data tables',
    'description' => 'Create, modify and delete data tables.',
    'page callback' => 'data_ui_manage',
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
  );
  $items['admin/build/data/overview'] = array(
    'title' => 'Overview',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/build/data/compare'] = array(
    'title' => 'Compare schemas',
    'description' => 'Administer data tables.',
    'page callback' => 'data_ui_compare',
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/build/data/compare/%data_ui_table'] = array(
    'title' => 'Adjust schema',
    'description' => 'Administer data tables.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_adjust_form',
      4,
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/build/data/adopt'] = array(
    'title' => 'Adopt tables',
    'description' => 'Adopt data tables that aren\'t claimed by any module.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_adopt_form',
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  );
  $items['admin/build/data/create'] = array(
    'title' => 'Create a table',
    'description' => 'Create a data table.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_create_form',
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/build/data/drop/%data_ui_table'] = array(
    'title' => 'Drop table',
    'description' => 'Drop a data table.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_drop_form',
      4,
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/build/data/edit/%data_ui_table'] = array(
    'title' => 'Data table',
    'description' => 'Administer data tables.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_edit_form',
      4,
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/build/data/edit/%data_ui_table/edit'] = array(
    'title' => 'Edit schema',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/build/data/edit/%data_ui_table/title'] = array(
    'title' => 'Edit title',
    'description' => 'Edit the title of the table.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_edit_title_form',
      4,
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => -9,
  );
  if (module_exists('views')) {
    $items['admin/build/data/edit/%data_ui_table/views'] = array(
      'title' => 'Configure views',
      'description' => 'Administer data tables.',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'data_ui_views_form',
        4,
      ),
      'file' => 'data_ui.admin.inc',
      'access arguments' => array(
        'administer data tables',
      ),
      'type' => MENU_LOCAL_TASK,
    );
  }
  if (module_exists('devel')) {
    $items['admin/build/data/edit/%data_ui_table/view-schema'] = array(
      'title' => 'Devel load',
      'description' => 'Administer data tables.',
      'page callback' => 'data_ui_view_schema',
      'page arguments' => array(
        4,
      ),
      'file' => 'data_ui.admin.inc',
      'access arguments' => array(
        'administer data tables',
      ),
      'type' => MENU_LOCAL_TASK,
      'weight' => 10,
    );
  }
  $items['admin/build/data/edit/%data_ui_table/join'] = array(
    'title' => 'Join tables',
    'description' => 'Administer data tables.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_join_form',
      4,
      6,
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/build/data/revert/%data_ui_table'] = array(
    'title' => 'Revert data table',
    'description' => 'Administer data tables.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_revert_form',
      4,
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/build/data/export/%data_ui_table'] = array(
    'title' => 'Data table',
    'description' => 'Export data table.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'data_ui_export_form',
      4,
    ),
    'file' => 'data_ui.admin.inc',
    'access arguments' => array(
      'administer data tables',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Menu loader callback.
 */
function data_ui_table_load($table_name) {
  return data_get_table($table_name);
}

/**
 * Title callback.
 */
function data_ui_title($title) {
  return t('Edit table @table', array(
    '@table' => $table
      ->get('title'),
  ));
}

/**
 * Implementation of hook_views_api().
 */
function data_ui_views_api() {
  return array(
    'api' => '2.0',
  );
}

/**
 * Implementation of hook_theme()
 */
function data_ui_theme() {
  return array(
    'data_ui_edit_form' => array(
      'arguments' => array(
        'form' => array(),
      ),
    ),
    'data_ui_views_form' => array(
      'arguments' => array(
        'form' => array(),
      ),
    ),
    'data_ui_create_form' => array(
      'arguments' => array(
        'form' => array(),
      ),
    ),
    'data_ui_schema_compare_table' => array(
      'arguments' => array(
        'comparison' => array(),
      ),
    ),
  );
}

/**
 * Implementation of hook_perm().
 */
function data_ui_perm() {
  return array(
    'administer data tables',
  );
}

/**
 * Creates the default path for a data table.
 */
function data_ui_get_default_path($name) {
  if ($table = data_get_table($name)) {

    // 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');
    if (isset($meta['join']) && is_array($meta['join']) && !empty($meta['join'])) {
      $left_table_name = key($meta['join']);
      if ($left_table = data_get_table($left_table_name)) {
        $path .= $left_table_name . '/';
      }
      return 'admin/content/data/view/' . $path . $name;
    }
  }
  return '';
}

Functions

Namesort descending Description
data_ui_get_default_path Creates the default path for a data table.
data_ui_help Implementation of hook_help().
data_ui_menu Implementation of hook_menu()
data_ui_perm Implementation of hook_perm().
data_ui_table_load Menu loader callback.
data_ui_theme Implementation of hook_theme()
data_ui_title Title callback.
data_ui_views_api Implementation of hook_views_api().