Index: moduleinfo.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/moduleinfo/moduleinfo.module,v retrieving revision 1.1.2.3 diff -u -p -r1.1.2.3 moduleinfo.module --- moduleinfo.module 27 May 2009 16:20:37 -0000 1.1.2.3 +++ moduleinfo.module 22 Jun 2009 17:58:27 -0000 @@ -1,5 +1,5 @@ $description){ - if ($files[$module]->status=="0")continue; - - $info = moduleinfo_get_info($module); - if (!$info)continue; - - $fieldset = array( - '#title' => t('ModuleInfo'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#value' => $info, - ); - $form["description"][$module]['#value'] .= theme('fieldset', $fieldset);; +/** + * Implementation of hook_form_alter(). + * This hook gets the module specific data (from moduleinfo_get_info) + * for each module and inserts it into the system_modules form + * which is displayed on the pages admin/build/modules and admin/build/modules/list + */ +function moduleinfo_form_alter($form, $form_state, $form_id) { + if ($form_id == 'system_modules') { + if ('admin/build/modules/info' == $_GET['q'] || variable_get('moduleinfo_shown', TRUE)) { + $files = module_rebuild_cache(); + foreach ($form['description'] as $module => $description) { + if ($files[$module]->status == '0') { + continue; } - } - else { - drupal_set_message(l(t("View info about your modules"),"admin/build/modules/info")); + $info = moduleinfo_get_info($module); + if (!$info) { + continue; + } + + $fieldset = array( + '#title' => t('ModuleInfo'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#value' => $info, + ); + $form['description'][$module]['#value'] .= theme('fieldset', $fieldset); } } + else { + drupal_set_message(l(t('View info about your modules'), 'admin/build/modules/info')); + } + } } -/**** -an implementation of hook_help -****/ -function moduleinfo_help($section='') { + +/** + * Implementation of hook_help(). + */ +function moduleinfo_help($section = '') { switch ($section) { - case "admin/help#moduleinfo": - return t("ModuleInfo informs the admin about changes a module makes to the interface."); + case 'admin/help#moduleinfo': + return t('ModuleInfo informs the admin about changes a module makes to the interface.'); } - return ''; - } -/*** possible new hook? -returns associative array: -$info["created"]["pages"] = path => array(name=> description=>) -$info["created"]["blocks"] = i => array(name=> description=>) -$info["created"]["content-types"] = name => description -$info["effected"]....[mirrors created] +/** possible new hook? + * returns associative array: + * $info["created"]["pages"] = path => array(name=> description=>) + * $info["created"]["blocks"] = i => array(name=> description=>) + * $info["created"]["content-types"] = name => description + * $info["effected"]....[mirrors created] function moduleinfo_moduleinfo(){ $info = array(); @@ -79,146 +81,169 @@ function moduleinfo_moduleinfo(){ $info['blocks']['created'][] = 'block description'; return $info; } -***/ + */ -/*** collects all the information we can find about a module from various hooks ***/ -function moduleinfo_get_info($module){ - $output = ''; - $help = moduleinfo_get_help($module); - if ($help){ - $output.= ''.t('Help').''; - $output.= ''; - } - $pages = moduleinfo_get_pages($module); - if (isset($pages["config"])){ - $output.= ''.t('Configuration').''; - $output.= ''; - } - if (isset($pages["other"])){ - $output.= ''.t('Pages').''; - $output.= ''; - } - $blocks = moduleinfo_get_blocks($module); - if ($blocks){ - $output.= ''.t('Blocks').''; - $output.= ''; - } - $cts = moduleinfo_get_content_types($module); - if ($cts){ - $output.= ''.t('Content Types').''; - $output.= ''; - } - return $output; -} - -/*** check for help ***/ -function moduleinfo_get_help($module){ - if (module_hook($module,"help")){ - $res = module_invoke($module,"help","admin/help#".$module,arg()); - if ($res) - return array("
  • ".t("You can find help for this module on the page ").l(moduleinfo_get_menu_name("admin/help/".$module).t(" help"),"admin/help/".$module)."
  • "); - } - return array(); -} - -/*** check for pages, both config and other ***/ -/** todo -- display w/ submenu structure **/ -function moduleinfo_get_pages($module,$cached=TRUE){ - $pages = array(); - if (module_hook($module,"menu")){ - $menus = module_invoke($module, "menu", $cached); - if ($menus){ - foreach ($menus as $path=>$menu){ - if ($menu["type"]!=MENU_CALLBACK){ /** menu_callbacks wont appear in menus **/ - $full = moduleinfo_get_breadcrumb($path); - $txt="
  • ".l(moduleinfo_get_menu_name($path),$path).''.t(" ($full)")."
  • \n"; - if (strpos($path,"admin/settings")!==FALSE) - $pages["config"][] = '
  • '.l(moduleinfo_get_menu_name($path),$path).'
  • '; - else - $pages["other"][] = $txt; - } - } - } +/** + * Collects all the information we can find about a module from various hooks. + */ +function moduleinfo_get_info($module) { + $output = ''; + $help = moduleinfo_get_help($module); + if ($help) { + $output .= ''. t('Help') .''; + $output .= ''; + } + $pages = moduleinfo_get_pages($module); + if (isset($pages['config'])) { + $output .= ''. t('Configuration') .''; + $output .= ''; + } + if (isset($pages['other'])) { + $output .= ''. t('Pages') .''; + $output .= ''; + } + $blocks = moduleinfo_get_blocks($module); + if ($blocks) { + $output .= ''. t('Blocks') .''; + $output .= ''; + } + $content_types = moduleinfo_get_content_types($module); + if ($content_types) { + $output .= ''. t('Content types') .''; + $output .= ''; + } + return $output; +} + +/** + * Check for help. + */ +function moduleinfo_get_help($module) { + if (module_hook($module, 'help')) { + $res = module_invoke($module, 'help', "admin/help#$module", arg()); + if ($res) { + return array('
  • '. t('You can find help for this module on the page @help-tile help.', array('@help-page' => "admin/help/$module", '@help-tile' => moduleinfo_get_menu_name("admin/help/$module"))) .'
  • '); } - return $pages; + } + return array(); } -/*** check for block ***/ -function moduleinfo_get_blocks($module){ - /*** check for blocks ***/ - $blocks = array(); - if (module_hook($module, "block")){ - $mblocks = module_invoke($module,"block","list"); - if ($mblocks){ - foreach($mblocks as $i=>$block){ - $blocks[] ="
  • ".l($block["info"],"admin/build/block/configure/".$module."/".$i)."
  • \n"; - } - } +/** + * Check for pages, both config and other. + * todo: display w/ submenu structure + */ +function moduleinfo_get_pages($module, $cached = TRUE) { + $pages = array(); + if (module_hook($module, 'menu')) { + $menus = module_invoke($module, 'menu', $cached); + if ($menus) { + foreach ($menus as $path => $menu) { + // menu_callbacks wont appear in menus. + if ($menu['type'] != MENU_CALLBACK) { + if (strpos($path, 'admin/settings') !== FALSE) { + $pages['config'][] = '
  • '. l(moduleinfo_get_menu_name($path), $path) .'
  • '; + } + else { + $pages['other'][] = '
  • '. l(moduleinfo_get_menu_name($path), $path) .' ('. moduleinfo_get_breadcrumb($path) .')
  • '; + } } - return $blocks; + } + } + } + return $pages; } -/*** check for custom content-types ***/ -function moduleinfo_get_content_types($module){ - $content_types = array(); - if (module_hook($module, "node_info")){ - $nodes = module_invoke($module,"node_info"); - if ($nodes){ - foreach ($nodes as $name=>$node){ - $content_types[] = "
  • ".l($node["name"],"admin/content/types/".$name).": ".$node["description"]."
  • \n"; - } - } - } - return $content_types; +/** + * Check for blocks. + */ +function moduleinfo_get_blocks($module) { + $blocks = array(); + if (module_hook($module, 'block')) { + $mblocks = module_invoke($module, 'block', 'list'); + if ($mblocks) { + foreach ($mblocks as $i => $block) { + $blocks[] = '
  • '. l($block['info'], "admin/build/block/configure/$module/$i") .'
  • '; + } + } + } + return $blocks; } -/*** grab a module name from the database ***/ -function moduleinfo_get_menu_name($path){ - $result = db_query("SELECT link_title FROM {menu_links} WHERE link_path = '%s'",array($path)); - $res = db_fetch_object($result)->link_title; - if (!$res){ - $res = array_slice(explode("/",$path),-1); - $res = ucwords($res[0]); - } - return $res; -} - -/*** generate a breadcrumb-style string from a menu path ***/ -function moduleinfo_get_breadcrumb($path){ - $parts = explode("/",$path); - $current = ""; - $breadcrumb = ""; - foreach($parts as $part){ - if ($breadcrumb!="")$breadcrumb.="»"; - if ($current!="")$current.="/"; - $current .= $part; - $breadcrumb .= moduleinfo_get_menu_name($current); +/** + * Check for custom content types. + */ +function moduleinfo_get_content_types($module) { + $content_types = array(); + if (module_hook($module, 'node_info')) { + $nodes = module_invoke($module, 'node_info'); + if ($nodes) { + foreach ($nodes as $name => $node) { + $content_types[] = '
  • '. l($node['name'], "admin/content/types/$name") .': '. $node['description'] .'
  • '; + } } - return $breadcrumb; + } + return $content_types; } -function moduleinfo_settings_form() { +/** + * Grab a module name from the database. + */ +function moduleinfo_get_menu_name($path) { + $result = db_query("SELECT link_title FROM {menu_links} WHERE link_path = '%s'", array($path)); + $res = db_fetch_object($result)->link_title; + if (!$res) { + $res = array_slice(explode('/', $path), -1); + $res = ucwords($res[0]); + } + return $res; +} + +/** + * Generate a breadcrumb-style string from a menu path. + */ +function moduleinfo_get_breadcrumb($path) { + $parts = explode('/', $path); + $current = ''; + $breadcrumb = ''; + foreach ($parts as $part) { + if ($breadcrumb != '') { + $breadcrumb .= "»"; + } + if ($current != '') { + $current .= '/'; + } + $current .= $part; + $breadcrumb .= moduleinfo_get_menu_name($current); + } + return $breadcrumb; +} +/** + * Settings form. + */ +function moduleinfo_settings_form() { $form['moduleinfo_shown'] = array( - '#title' => t('Shown by Default'), + '#title' => t('Shown by default'), '#type' => 'checkbox', - '#description' => t('Show info on the main modules page or only on the sub-page (admin/build/modules/info)'), + '#description' => t('Show info on the main modules page or only on the sub-page (admin/build/modules/info).'), '#default_value' => variable_get('moduleinfo_shown', TRUE), ); - $form[] = array( + $form['submit'] = array( '#type' => 'submit', - '#value' => t('Save Settings'), + '#value' => t('Save'), ); return $form; } +/** + * Submit handler for settings form. + */ function moduleinfo_settings_form_submit($form, &$form_state) { - foreach ($form_state['values'] AS $name => $value) { + foreach ($form_state['values'] as $name => $value) { if (!strcmp(drupal_substr($name, 0, drupal_strlen('moduleinfo_')), 'moduleinfo_')) { variable_set($name, $value); } } - drupal_set_message(t("The settings have been saved.")); + drupal_set_message(t('The settings have been saved.')); } -