Remove unnecessary CSS in Drupal 6 & 7


add the function to the template.php file in your theme folder

 

Drupal 6

function mytheme_preprocess_page(&$vars){
 $css = $vars['css'];
//core modules
 unset($css['all']['module']['modules/node/node.css']);
//contrib
 unset($css['all']['module']['sites/all/modules/contrib/filefield/filefield.css']);
//custom
unset($css['all']['module']['sites/all/modules/custom/mymodule/mymodule.css']);
//theme css
unset($css['all']['theme']['sites/all/themes/mytheme/mytheme.css']);

 $vars['styles'] = drupal_get_css($css);
}

 

Drupal 7

 

function mymodule_css_alter(&$css) {
  $exclude = array(
 //core
   'modules/system/maintenance.css' => FALSE,
//contrib
    'sites/all/modules/contrib/module/module.css' => FALSE,
//custom
    'sites/all/modules/custom/module/module.css' => FALSE,
//theme
    'sites/all/themes/mytheme/mytheme.css' => FALSE,
  );
  $css = array_diff_key($css, $exclude);
}
Advertisements

Creating a custom form from a module in Drupal 6


Permissions

This will check if the user has permissions to view the form

function myform_perm() {
  return array('access myform content');
}

Path

What url will lead us to the form, useful to start it with ‘admin’ so non-admin users can’t access it.

function myform_menu() {
  $items = array();
  $items['path/to/my/form'] = array(
    'title' => t('My Form'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('myform_form'),
    'access arguments' => array('access myform content'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

Form

function myform_form() {
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send')
  );
  return $form;
}

 Validation

function myForm_validate($node, &$form) {
  if (isset($node->end) && isset($node->start)) {
    if ($node->start > $node->end) {
      form_set_error('time', t('An event may not end before it starts.'));
    }
  }
}

How to force a Webform to be an admin page (Drupal 6)


I’ve created a WebForm and I’ve been modifying it with hook_form_alter inside a custom module. Another thing I wanted to do is make the page be an admin page, I did changed the path to ‘admin/mypath’ but it didn’t worked.The solution I’ve come with is divided in two parts:

1- Show the admin theme

function mymodule_init(){
$path = drupal_get_path_alias($_GET['q']);
 if($path == 'admin/mypath'){
 global $custom_theme;
 $custom_theme = variable_get('admin_theme', '0');
 drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
 }
}

2- Restrict the access

function mymodule_nodeapi (&$node, $op){ 
// Load the currently logged in user. 
global $user; 
if($node->path == 'admin/mypath' && $op == 'view'){
if(user_is_anonymous()){
 drupal_access_denied();
 }
 // Check if the user has the 'ATD Staff' role.
 else if (in_array('my_allowed_role', $user->roles)) {
 drupal_access_denied();
 }
 }
 }

No need to say, if somebody has a better solution please write a comment here.