- Patch #544360 by David_Rothstein, seutje: some dashboard clean-ups and fixes.
							parent
							
								
									d0280b78ab
								
							
						
					
					
						commit
						cae0e20365
					
				| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
<?php
 | 
			
		||||
// $Id$
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file
 | 
			
		||||
 * Hooks provided by the Dashboard module.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @addtogroup hooks
 | 
			
		||||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Adds regions to the dashboard.
 | 
			
		||||
 *
 | 
			
		||||
 * @return
 | 
			
		||||
 *   An array whose keys are the names of the dashboard regions and whose
 | 
			
		||||
 *   values are the titles that will be displayed in the blocks administration
 | 
			
		||||
 *   interface. The keys are also used as theme wrapper functions.
 | 
			
		||||
 */
 | 
			
		||||
function hook_dashboard_regions() {
 | 
			
		||||
  // Define a new dashboard region. Your module can also then define
 | 
			
		||||
  // theme_mymodule_dashboard_region() as a theme wrapper function to control
 | 
			
		||||
  // the region's appearance.
 | 
			
		||||
  return array('mymodule_dashboard_region' => "My module's dashboard region");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Alter dashboard regions provided by modules.
 | 
			
		||||
 *
 | 
			
		||||
 * @param $regions
 | 
			
		||||
 *   An array containing all dashboard regions, in the format provided by
 | 
			
		||||
 *   hook_dashboard_regions().
 | 
			
		||||
 */
 | 
			
		||||
function hook_dashboard_regions_alter($regions) {
 | 
			
		||||
  // Remove the sidebar region defined by the core dashboard module.
 | 
			
		||||
  unset($regions['dashboard_sidebar']);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @} End of "addtogroup hooks".
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -20,14 +20,15 @@ Drupal.behaviors.dashboard = {
 | 
			
		|||
  addPlaceholders: function() {
 | 
			
		||||
    $('#dashboard .dashboard-region .region').each(function () {
 | 
			
		||||
      var empty_text = "";
 | 
			
		||||
      // If the region is empty
 | 
			
		||||
      if ($('.block', this).length == 0) {
 | 
			
		||||
        // We need a placeholder.
 | 
			
		||||
        // Check if we are in customize mode and grab the correct empty text
 | 
			
		||||
        if ($('#dashboard').hasClass('customize_mode')) {
 | 
			
		||||
          empty_text = Drupal.settings.dashboard.emptyRegionTextActive;
 | 
			
		||||
        } else {
 | 
			
		||||
          empty_text = Drupal.settings.dashboard.emptyRegionTextInactive;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // We need a placeholder.
 | 
			
		||||
        if ($('.placeholder', this).length == 0) {
 | 
			
		||||
          $(this).append('<div class="placeholder"></div>');
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +46,9 @@ Drupal.behaviors.dashboard = {
 | 
			
		|||
  enterCustomizeMode: function () {
 | 
			
		||||
    $('#dashboard').addClass('customize_mode');
 | 
			
		||||
    Drupal.behaviors.dashboard.addPlaceholders();
 | 
			
		||||
    // Hide the customize link
 | 
			
		||||
    $('#dashboard .customize .action-links').hide();
 | 
			
		||||
    // Load up the disabled blocks
 | 
			
		||||
    $('div.customize .canvas').load(Drupal.settings.dashboard.drawer, Drupal.behaviors.dashboard.setupDrawer);
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -161,10 +164,9 @@ Drupal.behaviors.dashboard = {
 | 
			
		|||
    $('#dashboard div.region').each(function () {
 | 
			
		||||
      var region = $(this).parent().attr('id').replace(/-/g, '_');
 | 
			
		||||
      var blocks = $(this).sortable('toArray');
 | 
			
		||||
      var i;
 | 
			
		||||
      for (i = 0; i < blocks.length; i++) {
 | 
			
		||||
        order.push(region + '[]=' + blocks[i]);
 | 
			
		||||
      }
 | 
			
		||||
      $.each(blocks, function() {
 | 
			
		||||
        order.push(region + '[]=' + this);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
    order = order.join('&');
 | 
			
		||||
    return order;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,11 +57,11 @@ function dashboard_block_info_alter(&$blocks) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Implement hook_page_alter().
 | 
			
		||||
 * Implement hook_page_build().
 | 
			
		||||
 *
 | 
			
		||||
 * Display dashboard blocks in the main content region.
 | 
			
		||||
 */
 | 
			
		||||
function dashboard_page_alter(&$page) {
 | 
			
		||||
function dashboard_page_build(&$page) {
 | 
			
		||||
  global $theme_key;
 | 
			
		||||
 | 
			
		||||
  if (dashboard_is_visible()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -154,6 +154,9 @@ function dashboard_theme() {
 | 
			
		|||
    'dashboard' => array(
 | 
			
		||||
      'arguments' => array('element' => NULL),
 | 
			
		||||
    ),
 | 
			
		||||
    'dashboard_admin' => array(
 | 
			
		||||
      'arguments' => array('element' => NULL),
 | 
			
		||||
    ),
 | 
			
		||||
    'dashboard_region' => array(
 | 
			
		||||
      'arguments' => array('element' => NULL),
 | 
			
		||||
    ),
 | 
			
		||||
| 
						 | 
				
			
			@ -173,11 +176,7 @@ function dashboard_theme() {
 | 
			
		|||
 *   Whether to launch in customization mode right away. TRUE or FALSE.
 | 
			
		||||
 */
 | 
			
		||||
function dashboard_admin($launch_customize = FALSE) {
 | 
			
		||||
  $output = '';
 | 
			
		||||
  if (user_access('administer blocks')) {
 | 
			
		||||
    $output .= '<div class="customize-dashboard js-hide">' . t('To customize the dashboard page, move blocks to the dashboard regions on !block-admin, or enable JavaScript on this page to use the drag-and-drop interface.', array('!block-admin' => l('the block administration page', 'admin/structure/block'))) . '</div>';
 | 
			
		||||
    drupal_add_js(drupal_get_path('module', 'dashboard') . '/dashboard.js');
 | 
			
		||||
    $settings = array(
 | 
			
		||||
  $js_settings = array(
 | 
			
		||||
    'dashboard' => array(
 | 
			
		||||
      'drawer' => url('admin/dashboard/drawer'),
 | 
			
		||||
      'blockContent' => url('admin/dashboard/block-content'),
 | 
			
		||||
| 
						 | 
				
			
			@ -190,12 +189,19 @@ function dashboard_admin($launch_customize = FALSE) {
 | 
			
		|||
      'emptyRegionTextActive' => _dashboard_get_default_string('dashboard_empty_region_text_active'),
 | 
			
		||||
    ),
 | 
			
		||||
  );
 | 
			
		||||
    drupal_add_js($settings, array('type' => 'setting'));
 | 
			
		||||
    drupal_add_library('system', 'ui.sortable');
 | 
			
		||||
  }
 | 
			
		||||
  // We do not return any main page content, because the content of the page
 | 
			
		||||
  // will be populated via the dashboard regions in dashboard_page_alter().
 | 
			
		||||
  return $output;
 | 
			
		||||
  $build = array(
 | 
			
		||||
    '#theme' => 'dashboard_admin',
 | 
			
		||||
    '#message' => t('To customize the dashboard page, move blocks to the dashboard regions on !block-admin, or enable JavaScript on this page to use the drag-and-drop interface.', array('!block-admin' => l('the block administration page', 'admin/structure/block'))),
 | 
			
		||||
    '#access' => user_access('administer blocks'),
 | 
			
		||||
    '#attached' => array(
 | 
			
		||||
      'js' => array(
 | 
			
		||||
        drupal_get_path('module', 'dashboard') . '/dashboard.js',
 | 
			
		||||
        array('data' => $js_settings, 'type' => 'setting'),
 | 
			
		||||
      ),
 | 
			
		||||
      'library' => array(array('system', 'ui.sortable')),
 | 
			
		||||
    ),
 | 
			
		||||
  );
 | 
			
		||||
  return $build;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -210,11 +216,9 @@ function dashboard_is_visible() {
 | 
			
		|||
 * Return an array of dashboard region descriptions, keyed by region name.
 | 
			
		||||
 */
 | 
			
		||||
function dashboard_region_descriptions() {
 | 
			
		||||
  $default_regions = array(
 | 
			
		||||
    'dashboard_main' =>  'Dashboard main',
 | 
			
		||||
    'dashboard_sidebar' => 'Dashboard sidebar',
 | 
			
		||||
  );
 | 
			
		||||
  return variable_get('dashboard_region_descriptions', $default_regions);
 | 
			
		||||
  $regions = module_invoke_all('dashboard_regions');
 | 
			
		||||
  drupal_alter('dashboard_regions', $regions);
 | 
			
		||||
  return $regions;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -224,6 +228,16 @@ function dashboard_regions() {
 | 
			
		|||
  return array_keys(dashboard_region_descriptions());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Implement hook_dashboard_regions().
 | 
			
		||||
 */
 | 
			
		||||
function dashboard_dashboard_regions() {
 | 
			
		||||
  return array(
 | 
			
		||||
    'dashboard_main' =>  'Dashboard main',
 | 
			
		||||
    'dashboard_sidebar' => 'Dashboard sidebar',
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * AJAX callback to show disabled blocks in the dashboard customization mode.
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			@ -338,6 +352,25 @@ function theme_dashboard($variables) {
 | 
			
		|||
  return '<div id="dashboard">' . $element['#children'] . '</div>';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Theme the page containing the dashboard.
 | 
			
		||||
 *
 | 
			
		||||
 * @param $variables
 | 
			
		||||
 *   An associative array containing:
 | 
			
		||||
 *   - elements: An associative array containing the properties of the element.
 | 
			
		||||
 *     Properties used: #message
 | 
			
		||||
 * @return
 | 
			
		||||
 *   A themed HTML string representing the non-customizable part of the
 | 
			
		||||
 *   dashboard page.
 | 
			
		||||
 *
 | 
			
		||||
 * @ingroup themeable
 | 
			
		||||
 */
 | 
			
		||||
function theme_dashboard_admin($variables) {
 | 
			
		||||
  // We only return a simple help message, since the actual content of the page
 | 
			
		||||
  // will be populated via the dashboard regions in dashboard_page_build().
 | 
			
		||||
  return '<div class="customize-dashboard js-hide">' . $variables['element']['#message'] . '</div>';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Theme a generic dashboard region.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -352,11 +385,11 @@ function theme_dashboard($variables) {
 | 
			
		|||
function theme_dashboard_region($variables) {
 | 
			
		||||
  extract($variables);
 | 
			
		||||
  $output = '<div id="' . $element['#dashboard_region'] . '" class="dashboard-region">';
 | 
			
		||||
  $output .= '<div class="region clearfix">';
 | 
			
		||||
  $output .= $element['#children'];
 | 
			
		||||
  if (!$element['#children']) {
 | 
			
		||||
    $output .= "<div class='region'></div>";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Closing div.region
 | 
			
		||||
  $output .= '</div>';
 | 
			
		||||
  // Closing div.dashboard-region
 | 
			
		||||
  $output .= '</div>';
 | 
			
		||||
  return $output;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue