Custom Views exposed form for Drupal

Take a look at views.module, add a line you will be able to get all the themes


$form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
drupal_set_message('

' . var_export($form['#theme'], true));

For an example result:
array (
0 => 'views_exposed_form__client_showcase__page',
1 => 'views_exposed_form__page',
2 => 'views_exposed_form__default',
3 => 'views_exposed_form__client_showcase',
4 => 'views_exposed_form',
)


A small drupal MySQL snippet


select uid, (select value from profile_values where fid=24 and uid=pv.uid) as c_bpartner_id, value from profile_values pv where uid in (select uid from profile_values where fid=24) and fid=17 order by c_bpartner_id


Remove DNS virus and any virus through free virus apps

I’ve found these best tools for totally scanning whole computer. Find them in Google, dudes!

1, Malwarebytes

2, RemoveIT Pro

– If you couldn’t open these sites, it’s obviously you have these virus in computer. Find these apps backup in other download source.


Disable subject field in Drupal comment

modulename.install

<?php

function modulename_update_6203(){

    $items = array();

    $types = node_get_types('types', NULL, TRUE);

    foreach($types as $type) {        

        variable_set('comment_subject_field_'. $type->type, 0);

    }

    return $items;

}


Extract HTML from PHP

Do not user regular expression, use DOMDocument instead

Function provided:

<?php

function parseHTMLURL($url = 'http://www.google.com') {    

    $content = file_get_contents($url);

    

    // removing some text for ignoring error

    $content = str_replace('id="special-offer-block"', "", $content);

    $dom = new DOMDocument();

    $html = $dom->loadHTML($content);

    

    $node = $dom->getElementById("node");

    

    // Go to level-2 div

    $divs = $node->getElementsByTagName("div");    

    foreach($divs as $k => $d) {        

        $node = $d;

        break;

    }

    

    $divs = $node->getElementsByTagName("div");    

    foreach($divs as $k => $d) {        

        $node = $d;

        break;

    }

        

    // get DomElement innerHTML

    $elem = $d;

    $innerHTML = ''; 

    $children = $elem->childNodes;

    foreach ($children as $child) {

            $tmp_doc = new DOMDocument();

            $tmp_doc->appendChild($tmp_doc->importNode($child,true));       

            $out = $tmp_doc->saveHTML();            

            $innerHTML .= $out;

    }         

    return $innterHTML;

}

*: Install php-xml for this extension


How to add Google Jquery, Jquery UI

Add these lines to header

<head>

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/themes/base/jquery-ui.css" />

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/jquery-ui.min.js"></script>

</head>


Firebug lite

Use below line and paste to URL to enable firebug for any websites at any browser

javascript:var%20firebug=document.createElement('script');firebug.setAttribute('src','http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js');document.body.appendChild(firebug);(function(){if(window.firebug.version){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);

 
In this blog post provider I can’t post a demo button, please go to this below ref link to view the demo:
http://www.makeuseof.com/tag/install-firebug-for-browsers-other-than-firefox/

Embed views in custom module

1. Embed code to module

<?php

/**

 * Implementation of hook_views_api.

 */

function modulename_views_views_api() {

  return array(

    'api' => 2,

    'path' => drupal_get_path('module', 'modulename'),

  );

}

2. Embed exported views to modulename.views_default.inc

<?php

/**

 * Implementation of hook_views_default_views().

 */

function modulename_views_default_views() {

  /*Exported views code paste here*/

 

  $views[$view->name] = $view;

  return $views;

}

+ More things: Overriding views from other module

1. Define override views code

<?php

/**

* Implementation of hook_views_default_views_alter().

*/

function modulename_views_default_views_alter(&$views) {   

  module_load_include('inc', 'modulename', 'modulename.views_default_override');

  $new_views = modulename_views_default_override_views();

  foreach($new_views as $key => $view) {

    if(array_key_exists($key, $views)) {

      if(is_object($view)){        

        $views[$key] = $view;

      }

    }

  }

}

2. Embed exported changed views to modulename.views_default_override.inc

<?php

 

function modulename_views_default_override_views() {

  /*Exported views code paste here*/

  

  $views[$view->name] = $view;

  return $views;

}


Update module to highest weight in Drupal

Define below code in modulename.install

Run update.php

<?php

 

function modulename_update_6201() {

  $items = array();

  $max_weight = db_result(db_query('SELECT MAX(weight) FROM {system}'));

  $items[] = update_sql('UPDATE {system} SET weight = ' . ($max_weight+1) . ' WHERE name = "modulename" AND type="module"');

  return $items;

}


Look and feel Drupal Form

Override elements and form themes in template.php

<?php

/**

 * Implementation of hook_theme().

 */

function modulename_theme() {

  $items = array();  

  $items['user_profile_form'] = $items['comment_form'] = array(

    'arguments' => array('form' => array()),    

    'template' => 'form-look-and-feel',    

    'preprocess functions' => array(

      'modulename_preprocess_form_buttons',      

    ),

  );  

  return $items;

}

 

function modulename_fieldset($element) {

  if(empty($element['#collapsible']) && ($element['#lookandfeel'] || $GLOBALS['lookandfeel'])) {

    $element['#attributes']['class'] .= ' fieldsetdiv';

    $element['#id'] = isset($element['#id']) ? $element['#id'] : strtolower(str_replace(' ', '-', $element['#title']));

    return '<div' . drupal_attributes($element['#attributes']) . ' id="'. $element['#id'] .'">' . ($element['#title'] ? '<h3 class="fieldsettitle">' . $element['#title'] . '</h3>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') . "</div>\n";    

  }

  if (!empty($element['#collapsible'])) {

    drupal_add_js('misc/collapse.js');

 

    if (!isset($element['#attributes']['class'])) {

      $element['#attributes']['class'] = '';

    }

 

    $element['#attributes']['class'] .= ' collapsible';

    if (!empty($element['#collapsed'])) {

      $element['#attributes']['class'] .= ' collapsed';

    }

  }

 

  return '<fieldset' . drupal_attributes($element['#attributes']) . '>' . ($element['#title'] ? '<legend>' . $element['#title'] . '</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') . "</fieldset>\n";

}

 

function modulename_textarea($element) {

  if($element['#lookandfeel'] || $GLOBALS['lookandfeel']) {  

    $element['#resizable'] = false;

  }

  return theme_textarea($element);

}

 

function modulename_select($element) {

  $select = '';

  $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';

  _form_set_class($element, array('form-select'));

  $multiple = $element['#multiple'];

  if($multiple) {

    $element['#attributes']['class'] .= ' form-multiselect';

  }

  return theme('form_element', $element, '<select name="' . $element['#name'] . '' . ($multiple ? '[]' : '') . '"' . ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) . ' id="' . $element['#id'] . '" ' . $size . '>' . form_select_options($element) . '</select>');

}

 

function modulename_checkbox($element) {

  _form_set_class($element, array('form-checkbox'));

  $checkbox = '<input ';

  $checkbox .= 'type="checkbox" ';

  $checkbox .= 'name="' . $element['#name'] . '" ';

  $checkbox .= 'id="' . $element['#id'] . '" ';

  $checkbox .= 'value="' . $element['#return_value'] . '" ';

  $checkbox .= $element['#value'] ? ' checked="checked" ' : ' ';

  $checkbox .= drupal_attributes($element['#attributes']) . ' />';

    

  if (!is_null($element['#title'])) {

    if($element['#lookandfeel'] || $GLOBALS['lookandfeel']) {    

      $checkbox = '<label class="option" for="' . $element['#id'] . '">' . $checkbox . '</label><label class="option">' . $element['#title'] . '</label>';

    }

    else {

      $checkbox = '<label class="option" for="' . $element['#id'] . '">' . $checkbox . ' ' . $element['#title'] . '</label>';

    }

  }

 

  unset($element['#title']);

  return theme('form_element', $element, $checkbox);

}

 

function modulename_form_element($element, $value) {    

  if($element['#lookandfeel'] || $GLOBALS['lookandfeel']) {    

    $t = get_t();

    if(!$element['#lookandfeel_inline']) {

      $moreclass = '';

      if(empty($element['#title'])) {

        $moreclass = ' notitle';

      }

      if($element['#attributes']['class']) {

        $moreclass .= ' ' . $element['#attributes']['class'];

      }      

      $output = '<div class="form-item form-item-'. $element['#type'] . $moreclass . '"';

      if (!empty($element['#id'])) {

        $output .= ' id="' . $element['#id'] . '-wrapper"';

      }    

      $output .= ">\n";

    }

    $required = !empty($element['#required']) ? '<span class="form-required" title="' . $t('This field is required.') . '">*</span>' : '';

 

    if (!empty($element['#title'])) {

      $title = $element['#title'];      

      if(strstr($element['#attributes']['class'], 'nofixtitle')) {

        $title .= ':';        

      }

      if (!empty($element['#id'])) {

        $output .= ' <label class="element" for="' . $element['#id'] . '">' . $t('!title', array('!title' => filter_xss_admin($title))) . "</label>\n";

      }

      else {

        $output .= ' <label class="element">' . $t('!title', array('!title' => filter_xss_admin($title))) . "</label>\n";

      }

    }

 

    $output .= " {$value}{$element['#suffix2']} {$required}\n";

    

    if(!$element['#lookandfeel_inline']) {

      $output .= "<div class='clear'></div>\n";

    }

 

    if (!empty($element['#description'])) {

      $output .= ' <div class="parentdescription description">' . $element['#description'] . "</div>\n";

    }

    if (!empty($element['#staticdescription'])) {

      $output .= ' <div class="staticdescription">' . $element['#staticdescription'] . "</div>\n";

    }

    

    if(!$element['#lookandfeel_inline']) {

      $output .= "</div>\n";

    }

 

    return $output;

  }

  $t = get_t();

 

  $output = '<div class="form-item"';

  if (!empty($element['#id'])) {

    $output .= ' id="' . $element['#id'] . '-wrapper"';

  }

  $output .= ">\n";

  $required = !empty($element['#required']) ? '<span class="form-required" title="' . $t('This field is required.') . '">*</span>' : '';

 

  if (!empty($element['#title'])) {

    $title = $element['#title'];

    if (!empty($element['#id'])) {

      $output .= ' <label for="' . $element['#id'] . '">' . $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) . "</label>\n";

    }

    else {

      $output .= ' <label>' . $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) . "</label>\n";

    }

  }

 

  $output .= " $value\n";

 

  if (!empty($element['#description'])) {

    $output .= ' <div class="description">' . $element['#description'] . "</div>\n";

  }

 

  $output .= "</div>\n";

 

  return $output;

}

 

/**

 * Preprocessor for handling form button for most forms.

 */

function modulename_preprocess_form_buttons(&$vars) {

  if (empty($vars['buttons']) || !element_children($vars['buttons'])) {

    if (isset($vars['form']['buttons']) && element_children($vars['form']['buttons'])) {

      $vars['buttons'] = $vars['form']['buttons'];

      unset($vars['form']['buttons']);

    }

    else {

      $vars['buttons'] = array();

      foreach (element_children($vars['form']) as $key) {

        if (isset($vars['form'][$key]['#type']) && in_array($vars['form'][$key]['#type'], array('submit', 'button'))) {

          $vars['buttons'][$key] = $vars['form'][$key];

          unset($vars['form'][$key]);

        }

      }

    }

  }

}

 

 

Form template form-look-and-feel.tpl.php

<?php

  $GLOBALS['lookandfeel'] = true;

  // ADD PLUGINS

  // select

  jquery_ui_add(array('ui.widget'));

  drupal_add_css(drupal_get_path('module','jquery_ui'). '/jquery.ui/themes/base/ui.all.css');

  drupal_add_js(path_to_theme() . '/js/ui.selectmenu.js');

  drupal_add_css(path_to_theme() . '/js/ui.selectmenu.css');

  drupal_add_js('

  $("document").ready(function() {

    $("div.form-look-and-feel select:not(.form-item-fivestar select)").selectmenu({style:"dropdown"});

  });

  ', 'inline');  

  

  // checkbox

  drupal_add_js(path_to_theme() . '/js/ui.checkbox.js');

  drupal_add_css(path_to_theme() . '/js/ui.checkbox.css');  

  drupal_add_js('

  $("document").ready(function() {

    $("div.form-look-and-feel input").filter(":checkbox,:radio").checkbox();

  });

  ', 'inline');  

  

  if(in_array($form['#id'], array('user-profile-form'))) {

    $GLOBALS['lookandfeel-inline'] = true;

    $moreformclass = ' form-look-and-feel-inline';

    $moreformclass .= ' form-look-and-feel-buttons-center';

  }

?>

<div class="form-look-and-feel<?php print $moreformclass; ?>">

  <?php       

  if(!@include($form['#id'] . '.tpl.php')) {      

    print drupal_render($form);

    print '<div class="buttons">' . drupal_render($buttons) . '</div>';

  }  

  ?>

</div>

<?php       

  unset($GLOBALS['lookandfeel'], $GLOBALS['lookandfeel-inline']);

?>

 

CSS + Images + JQuery UI 1.7 specific widgets + related modules will be attached in next update