Drupal7 update hook dependencies


You sometimes find that update hooks run in an unwanted order that affects their behaviour or creates errors and makes your site crash. You can override this and specify the order that you want with the following hook in your .install file.

 function new_module_update_dependencies() {
  // Run new_module update after old_module update.
  $dependencies['new_module'][7001] = array(
    'old_module' => 7000,
  );
 
  return $dependencies;
 }
Advertisements

Move up metatag in Drupal 7


/**  
* Implements hook_html_head_alter().  
* moving og:title up in head element list  
*/ 
function mymodule_html_head_alter(&$head_elements) {  
  foreach ($head_elements as $key => $element) { 
    if($key == 'metatag_og:title') { 
      $head_elements[$key]['#weight'] = -999; 
    } 
  } 
}

Drupal Update Hook Dependencies


Sometimes, when developing an update hook, you might want it to run after or before a different module’s update hook. this is the way to do it:

Place the following code into your module’s mymodule.install file.

Where 7001 and 7140 are the hook update number.

/**
 * Implementation of hook_update_dependencies().
*/
function mymodule_update_dependencies() {
  // Make sure that mymodule runs after other_module
  $dependencies['mymodule'][7001] = 
 'other_module' => 7140,
);
  return $dependencies;
}

Add different scripts to the header in Drupal (meta, link..)


Now let’s imagine that you want to use a generic function to add different types of scripts to your header: <meta> <link>? <script>. This is the solution I’ve found.

Important: it took me few hours until I realized.

second parameter of drupal_add_html_head must be a unique string, so I’ve used the path to the script because they are in different files inside a folder structure. but you can use a random generator, or maybe a better solution, but keep in mind that must be unique.

$script = "<meta name="google-site-verification" content="xxxxx" />";
drupal_add_html_head(array('#type' => 'markup', '#markup' => $script), "$script");
$script = "<link rel="apple-touch-icon-precomposed" href="www.example.com" />";
drupal_add_html_head(array('#type' => 'markup', '#markup' => $script), "$script");

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);
}

How To Make A Bootstrap Drupal Sub Theme


And of course you’ll want to style it up a little bit, here you have an easy method to modify and compile the theme’s .less files

http://incident57.com/less/video/tutorial.mov

Source : http://drupal.tutsurf.com/ http://incident57.com/less/