How a render a field from a node in a separate block (specific to theme seven and display in sidebar_first , fieldname field_tags) function modname_page_alter(&$page){ //check is node page $node_page=isset($page['content']['system_main']['nodes'])?$page['content']['system_main']['nodes']:0; if($node_page){ foreach($node_page as $key=>$value){ // is a field named field_tags in the node array if(isset($value['field_tags'])){ //if field is there, render in another block and then […]
Scenario: A module which was enabled cannot be found in the module listing, and the folder does exist. The reason for this happening that I have seen is by mistake the module file was also copied into another module directory. How to rectify: Drupal 7 $modules = drupal_system_listing(‘/^’ . DRUPAL_PHP_FUNCTION_PATTERN . ‘\.module$/’, ‘modules’, ‘name’, […]
I recently realized that i have too many drafts in my blogs, so i am trying to my best to finish them all up in this weekend Drupal 7 introduced a new concept of entities, to know more read this link Below I am going to create an entity module for creating personal contacts for […]
Javascript functions have some interesting features If the function is not anonymous then it is stored in a variable having the name as the function For example: function addStuff(num1, num2){ return num1+num2; } alert(addStuff); The output is the body of the function alert(addStuff.length); The output is the number of named arguments, as in 2 for […]
One of the most important functions in Drupal is the t function. It stands for translate, but it does quite a lot more. Basic Syntax t($string, array $args = array(), array $options = array()) Link on the API $string: A string containing the English string to translate. $args: An associative array of replacements to make […]
From Drupal 6 single hook_user, in Drupal 7 each accepted value of $op argument in hook_user has been created into a little new hook, yeah real cute. Leaving alone the teeny weeny sarcasm there, I have actually seem Drupal 6 hook_user implementation which have run into a couple of pages of code, so cleaner code […]
I was playing around in hook_mail yesterday in Drupal 7 and got this warning. This took two minutes resolution time after opening the said file. This was my code. $message['body']=$body; After looking into the file I realised that Drupal expected $message['body'] to be an array. So simple change $message['body'][]=$body; Eureka, it works.
One of the simple questions in Drupal usually is how to create a custom hook Drupal 6 Version: You have created a module called pokeppl (poke people) And you have a function for this poke like below where $poker is the account object of the poker (usually that will be the current user object) and […]
hook_admin_paths Define administrative paths. No arguments Usages seems to have presentational value only. Used for two purposes Whether a given url when clicked should open in the overlay Whether a given url if the administrative theme is set, should be presented in the admin theme. To use declare an array of admin paths for your […]
Scenario: The system admin wants to change the css of blocks, or add background images to the site. This is not the entire code, but just a pointer on how to get it done. Create a module called mydynamic_css Just Add the following code. function mydynamic_css_preprocess_page(&$variables){ global $base_url; $mycss=”body{ background-image:url(‘sites/default/retro_blue_background.jpg’); } #block-user-1{ background-image:url(‘sites/default/sand.png’); } “; […]