You are here

dxpr_theme_helper.module in DXPR Theme Helper 7

Same filename and directory in other branches
  1. 1.0.x dxpr_theme_helper.module

File

dxpr_theme_helper.module
View source
<?php

/**
 * @file
 * Code for the DXPR Theme Configuration feature.
 */
include_once 'dxpr_theme_helper.features.inc';

/**
 * Implements hook_preprocess_page().
 *
 * Inject code to create the white "Theme Settings" button in the admin toolbar
 */
function dxpr_theme_helper_preprocess_page(&$vars) {
  global $user;
  if ($user->uid == 1 || user_access('access administration pages')) {
    $theme_path = drupal_get_path('theme', 'dxpr_theme');
    drupal_add_js(array(
      'dxpr_theme' => array(
        'dxpr_themePath' => $theme_path,
      ),
    ), 'setting');
    drupal_add_js(array(
      'dxpr_themeDefaultTheme' => variable_get('theme_default'),
    ), 'setting');
    drupal_add_js($theme_path . '/js/minified/' . 'dxpr-theme' . '.admin.min.js', 'file');
    drupal_add_css($theme_path . '/css/' . 'dxpr-theme' . '.admin.css');
  }
}

/**
 * Implements hook_admin_paths().
 *
 * If we don't set admin_path to FALSE our hook_custom_theme code doesn't work
 * @see dxpr_theme_helper_custom_theme()
 */
function dxpr_theme_helper_admin_paths() {
  $paths = array();
  $paths['admin/appearance/settings/*'] = FALSE;
  return $paths;
}

/**
 * Implements hook_custom_theme().
 *
 * Enable DXPR Theme for preview in DXPR Theme settings
 * @see dxpr_theme_helper_admin_paths()
 */
function dxpr_theme_helper_custom_theme() {
  if (arg(0) == 'admin' && arg(1) == 'appearance' && arg(2) == 'settings' && arg(3)) {
    $current_theme = check_plain(arg(3));
    return $current_theme;
  }
}

/**
 * Implements hook_block_info().
 */
function dxpr_theme_helper_block_info() {
  $blocks = array();
  $blocks['full_screen_search'] = array(
    'info' => t('Full screen search'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function dxpr_theme_helper_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'full_screen_search':
      if (user_access('search content')) {
        $block['content'] = _dxpr_theme_helper_search_block_content();
        return $block;
      }
      break;
  }
}

/**
 * Helper function to generate content for full_screen_search
 */
function _dxpr_theme_helper_search_block_content() {
  $search_form = drupal_get_form('search_block_form');
  $search_form['search_block_form']['#prefix'] = '<div class="full-screen-search-form-input">';
  $search_form['search_block_form']['#prefix'] .= '<label class="text-primary">' . t('Type and Press “enter” to Search') . '</label>';
  $search_form['search_block_form']['#suffix'] = '</div>';
  $search_form['search_block_form']['#attributes']['placeholder'] = '';
  $search_form['search_block_form']['#attributes']['autocomplete'] = 'off';
  $search_form['search_block_form']['#attributes']['class'][] = 'search-query';
  $search_form['#attributes']['class'][] = 'element-invisible';
  $search_form['#attributes']['class'][] = 'full-screen-search-form';
  $search_form['#attributes']['class'][] = 'element-invisible';

  // Remove bootstrap_bootstrap_search_form_wrapper
  $search_form['search_block_form']['#theme_wrappers'] = array();

  // Main search button
  $content['full_screen_search_button'] = array(
    '#type' => 'button',
    '#button_type' => 'button',
    '#value' => '<span class="icon glyphicon glyphicon-search"><div class="screenreader-text element-invisible">Search</div></span>',
    '#attributes' => array(
      'class' => array(
        'btn-link',
        'full-screen-search-button',
      ),
    ),
  );
  $content['search_form'] = $search_form;
  return $content;
}

Functions

Namesort descending Description
dxpr_theme_helper_admin_paths Implements hook_admin_paths().
dxpr_theme_helper_block_info Implements hook_block_info().
dxpr_theme_helper_block_view Implements hook_block_view().
dxpr_theme_helper_custom_theme Implements hook_custom_theme().
dxpr_theme_helper_preprocess_page Implements hook_preprocess_page().
_dxpr_theme_helper_search_block_content Helper function to generate content for full_screen_search