Mercurial > hg > MPIWG-drupal-modules
view sites/all/modules/custom/solrext/solrext.module @ 0:015d06b10d37 default tip
initial
author | dwinter |
---|---|
date | Wed, 31 Jul 2013 13:49:13 +0200 |
parents | |
children |
line wrap: on
line source
<?php /** * @file * Helps site builders and module developers investigate a site. */ /** * Implements hook_form_alter() to show each form's identifier. */ function solrext_form_alter(&$form, &$form_state, $form_id) { $form['solrext_display_form_id'] = array( '#type' => 'item', '#title' => t('Form ID'), '#markup' => $form_id, '#theme_wrappers' => array('container__solrext__form'), '#attributes' => array('class' => array('solrext')), '#weight' => -100, ); //debug($form, $form_id, TRUE); } /** * Implements hook_help(). */ function solrext_help($path, $arg) { switch ($path) { case 'admin/structure/block': return t('This site has stuff!'); case 'admin/appearance':{ return _solrext_help_admin_appearance(); }} } /** * Help text for the admin/appearance page. */ function _solrext_help_admin_appearance() { $output = ''; $data = solrext_stats_enabled_themes(); $output .= format_plural( $data['num_hidden'], 'There is one hidden theme.', 'There are @count hidden themes.' ); return theme('solrext_help', array('text' => $output)); } /** * Implements hook_menu(). */ function solrext_menu() { $items['admin/reports/solrtext'] = array( 'title' => 'X-ray technical site overview', 'description' => 'See the internal structure of this site.', 'page callback' => 'solrtext_overview_page', 'access callback' => TRUE, 'access arguments' => array('access site reports'), ); $items['admin/reports/solrtext/overview'] = array( 'title' => 'Overview', 'description' => "Technical overview of the site's internals.", 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/reports/solrtext/overview2'] = array( 'title' => 'Overview2', 'description' => "Technical overview of the site's internals.", 'type' => MENU_LOCAL_TASK, 'weight' => -1, 'page callback' => 'solrext_permission_names_page', 'access arguments' => array('access site reports'), ); return $items; } function solrtext_overview_page(){ return "XX"; } /** * Display the X-ray permission names page. */ function solrext_permission_names_page_OLD() { $names = solrext_permission_names(); //debug($names); return theme('solrext_permission_names', array('names' => $names)); } /** * Collect permission names. */ function solrext_permission_names() { $names = array(); $permissions = module_invoke_all('permission'); // Extract just the permission title from each permission array. foreach ($permissions as $machine_name => $permission) { $names[$machine_name] = $permission['title']; } // Put permission names in alphabetical order by title. asort($names); return $names; } /** * Returns HTML of permission machine and display names in a table. * * @param $variables * An associative array containing: * - names: Array of human-readable names keyed by machine names. * * @ingroup themeable */ function theme_solrext_permission_names($variables) { $names = $variables['names']; $output = ''; $header = array(t('Permission title'), t('Permission machine name')); $rows = array(); foreach ($names as $machine_name => $title) { $rows[] = array($title, $machine_name); } $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'solrext-permission-names'))); return $output; /** * Fetch information about themes. */ function solrext_stats_enabled_themes() { $themes = list_themes(); $num_themes = count($themes); // Initialize variables for the data you will collect. $num_hidden = 0; // Number of hidden themes. $num_enabled = 0; $summaries = array(); // Iterate through each theme, gathering data that you care about. foreach ($themes as $themename => $theme) { // Do not gather statistics for hidden themes, but keep a count of them. if (isset($theme->info['hidden']) && $theme->info['hidden']) { $num_hidden++; } else { // This is a visible theme. if ($theme->status) { $num_enabled++; // This is an enabled theme, provide more stats. $summaries[$theme->info['name']] = array( 'regions' => count($theme->info['regions']), 'overlay_regions' => count($theme->info['overlay_regions']), 'regions_hidden' => count($theme->info['regions_hidden']), 'features' => count($theme->info['features']), 'kindsofstylesheets' => count($theme->info['stylesheets']), 'allstylesheets' => isset($theme->info['stylesheets']['all']) ? count($theme->info['stylesheets']['all']) : 0, ); } } } return compact('num_themes', 'num_hidden', 'num_enabled', 'summaries'); } } /** * Implements hook_theme(). */ function solrext_theme() { return array( 'solrext_permission_names' => array( 'render element' => 'names', ), 'solrext_show_page_callback' => array( 'variables' => array( 'page_callback' => NULL, 'include_file' => NULL, 'page_arguments' => NULL, ), ), ); } /** * Display permission machine and display names in a table. * * @return * An array as expected by drupal_render(). */ function solrext_permission_names_page() { $build = array(); // Gather data, an array of human-readable names keyed by machine names. $names = solrext_permission_names(); // Format the data as a table. $header = array(t('Permission title'), t('Permission machine name')); $rows = array(); foreach ($names as $machine_name => $title) { $rows[] = array($title, $machine_name); } $build['names_table'] = array( '#theme' => 'table__solrext__permission_names', '#header' => $header, '#rows' => $rows, '#attributes' => array('id' => 'solrext-permission-names') ); return $build; } /** * Provide the page callback function (and other router item information). */ function solrext_show_page_callback() { debug("XX"); // Do not hand in the path; menu_get_item() finds dynamic paths on its own // but fails if handed help's $path variable which is node/% for node/1. $router_item = menu_get_item(); // menu_get_item() can return null when called via drush command line. if ($router_item) { return theme('solrext_show_page_callback', $router_item); } } /** * Theme the page callback and optionally other elements of a router item. */ function theme_solrext_show_page_callback($variables) { extract($variables, EXTR_SKIP); $output = ''; $output .= '<p class="solrext-help solrext-page-callback">'; $output .= t('This page is brought to you by '); if ($page_arguments) { foreach ($page_arguments as $key => $value) { $page_arguments[$key] = drupal_placeholder($value); } $output .= format_plural(count($page_arguments), 'the argument !arg handed to ', 'the arguments !arg handed to ', array('!arg' => solrext_oxford_comma_list($page_arguments)) ); } $output .= t('the function %func', array('%func' => $page_callback . '()')); if ($include_file) { $output .= t(' and the included file %file', array('%file' => $include_file)); } $output .= '.</p>'; return $output; }