You are here

magic_dev.module in Magic 7.2

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

Development settings for the magic module.

File

magic_dev/magic_dev.module
View source
<?php

/**
 * @file
 * Development settings for the magic module.
 */

/**
 * Implements hook_form_alter()-ish.
 *
 * Called from within magic.module's alter to ensure we always just add it in.
 */
function magic_dev_form_system_theme_settings(&$form, &$form_state, $theme) {

  // Development Magic Grouping
  $form['magic']['dev'] = array(
    '#type' => 'fieldset',
    '#title' => t('Development Enhancements'),
  );

  // Footer JavaScript Option
  $form['magic']['dev']['magic_rebuild_registry'] = array(
    '#type' => 'checkbox',
    '#title' => t('Rebuild Theme Registry on Reload'),
    '#description' => t('<a href="!link" target="_blank">Rebuild the theme registry</a> during project development.', array(
      '!link' => 'http://drupal.org/node/173880#theme-registry',
    )),
    '#default_value' => theme_get_setting('magic_rebuild_registry', $theme),
  );

  // Viewport Indicator Option
  $form['magic']['dev']['magic_viewport_indicator'] = array(
    '#type' => 'checkbox',
    '#title' => t('Viewport Width Indicator'),
    '#description' => t('Displays an indicator of the viewport. Tap/click to toggle between <em>em</em> and <em>px</em>. The CSS and JavaScript for this will bypass your CSS and JavaScript exclude options.'),
    '#default_value' => theme_get_setting('magic_viewport_indicator', $theme),
  );
  if (module_exists('modernizr')) {

    // Modernizr Debug Option
    $options = array(
      'attributes' => array(
        'target' => '_blank',
      ),
    );
    $form['magic']['dev']['magic_modernizr_debug'] = array(
      '#type' => 'checkbox',
      '#title' => t('Modernizr Indicator'),
      '#description' => t('Displays an indicator of !modernizr detected features. Tap/click to toggle display of all of the available features. Install the !module for full Modernizr support. The CSS and JavaScript for this will bypass your CSS and JavaScript exclude options.', array(
        '!modernizr' => l('Modernizr', 'http://modernizr.com/', $options),
        '!module' => l('Modernizr Drupal module', 'http://drupal.org/project/modernizr', $options),
      )),
      '#default_value' => theme_get_setting('magic_modernizr_debug', $theme),
    );
  }
  else {

    // We don't have modernizr :-(
    $form['magic']['dev']['magic_modernizr_debug'] = array(
      '#type' => 'hidden',
      '#value' => FALSE,
    );
  }
  return $form;
}

/**
 * Implements hook_preprocess_html().
 */
function magic_dev_preprocess_html(&$vars) {
  global $theme_key;

  // Theme Registry Rebuild
  if (theme_get_setting('magic_rebuild_registry', $theme_key) && !defined('MAINTENANCE_MODE')) {

    // Rebuild .info data.
    system_rebuild_theme_data();

    // Rebuild theme registry.
    drupal_theme_rebuild();
  }

  // RWD Debug Integration
  if (theme_get_setting('magic_viewport_indicator', $theme_key) || theme_get_setting('magic_modernizr_debug', $theme_key)) {
    drupal_add_css(drupal_get_path('module', 'magic_dev') . '/css/magic.debug.css');
    drupal_add_js(drupal_get_path('module', 'magic_dev') . '/js/magic.debug.js');

    // Adding a class to the body element.
    $vars['classes_array'][] = 'magic-indicator';
  }
}

/**
 * Implements hook_process_html().
 */
function magic_dev_process_html(&$vars) {
  global $theme_key;

  // RWD Debug Integration
  if (theme_get_setting('magic_viewport_indicator', $theme_key) || theme_get_setting('magic_modernizr_debug', $theme_key)) {
    $debug_output = '<div id="magic-development">';
    if (theme_get_setting('magic_viewport_indicator', $theme_key)) {
      $debug_output .= '<div id="magic-viewport-indicator"></div>';
    }
    if (theme_get_setting('magic_modernizr_debug', $theme_key)) {
      $debug_output .= '<div id="magic-modernizr-debug" class="open"></div>';
    }
    $debug_output .= '</div>';
    if (!empty($vars['page_bottom'])) {
      $vars['page_bottom'] .= $debug_output;
    }
    else {
      $vars['page_bottom'] = $debug_output;
    }
  }
}

/**
 * Implements hook_requirements().
 */
function magic_dev_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break during installation.
  $t = get_t();
  if ($phase == 'runtime') {
    $requirements['magic_dev'] = array(
      'title' => $t('Magic Development'),
      'value' => $t('Enabled'),
      'description' => $t('Magic development module should never be enabled on production sites. Please disable for production environments.'),
      'severity' => REQUIREMENT_WARNING,
    );
  }
  return $requirements;
}

Functions

Namesort descending Description
magic_dev_form_system_theme_settings Implements hook_form_alter()-ish.
magic_dev_preprocess_html Implements hook_preprocess_html().
magic_dev_process_html Implements hook_process_html().
magic_dev_requirements Implements hook_requirements().