Skip to main content

Posts

Showing posts from February, 2016

How to use "hook_theme" and "hook_preprocess" function in drupal7 custom module?

mymodule.module <?php   /**    * Implementation of hook_menu().    */   function mymodule_menu() {     $items['products'] = array(       'title' => 'Products',       'page callback' => 'products_by_categories',       'access callback' => TRUE,       'type' => MENU_CALLBACK,     );     return $items;   }   /**    * Products By Categories Function    */   function products_by_categories() {     return theme('products');   }   /**    * Implements hook_theme().    */   function mymodule_theme() {     return array(       'products' => array(         'variables' => array(),         'template' => 'templates/products-template',       ),         ...

How to use another site database in drupal7?

I am bulding a drupal7 site then i want to fetch some data from another website database. so how to link another website database in drupal 7. There are some tricks which are following: First goto "setting.php" file of drupal 7 site then make some changes in setting.php which are below: <?php   $databases = array(     'drupal_site_database' => array(       'default' => array(         'database' => 'drupalsite',         'username' => 'test',         'password' => 'test',         'host' => 'localhost',         'port' => '',         'driver' => 'mysql',         'prefix' => '',       ),     ),     'another_site_database' => array(       'default' => array(         'database' => 'anothersite', ...

How to use join query in drupal7?

<?php     $query = db_select('xcart_products_categories', 'xpc');     $query->join('xcart_products_lng_en', 'xpd', 'xpc.productid = xpd.productid');     $query->join('xcart_pricing', 'xpp', 'xpc.productid = xpp.productid');     $query->join('xcart_products', 'xp', 'xpc.productid = xp.productid');     $query->condition('xpc.categoryid', $cid);     $query->fields('xpc',array())                ->fields('xpd',array('product','descr','fulldescr'))                ->fields('xpp',array())                ->fields('xp',array('avail','add_date'))                ->orderBy('price', 'ASC');     $xcart_products_info = $query->execute()->fetchAll(); ?>

How to use insert,update and delete query in drupal6 and drupal7?

INSERT STATEMENT <?php   // Drupal 6   db_query("INSERT INTO {mytable} (intvar, stringvar, floatvar) VALUES (%d, '%s', %f)", 5, 'hello world', 3.14);   // Drupal 7   $id = db_insert('mytable')           ->fields(array('intvar' => 5,'stringvar' => 'hello world','floatvar' => 3.14))           ->execute(); ?> UPDATE STATEMENT. <?php   //Drupal 6   db_query("UPDATE {node} SET title='%s', status=%d WHERE uid=%d", 'hello world', 1, 5);   //Drupal 7   db_update('node')     ->fields(array('title' => 'hello world', 'status' => 1))     ->condition('uid', 5)     ->execute(); ?> DELETE STATEMENT. <?php   //Drupal 6   db_query("DELETE FROM {node} WHERE uid=%d AND created < %d", 5, REQUEST_TIME - 3600);   //Drupal 7   db_delete('node')     ->condition('uid', ...

Important Sources of Druapl 8

Official docs Drupal 8 Updates and How to Help Creating Drupal 8.x modules D7 to D8 upgrade tutorial: Pants module Writing module .info.yml files (Drupal 8.x) REST: exposing data as RESTful web services Change records for Drupal core What Drupal 8 API changes are still outstanding D8DX: Improving the D8 developer experience Drupal 8 is Coming Soon! PHP Docs Classes and Objects Code Examples Using Drupal 8's new route controllers Drupal 8 Module Development, Part 1: Getting Started Drupal 8 Module Development, Part 2: Forms Step-by-step: Converting modules from Drupal 7 to Drupal 8 A practical example for converting a Drupal 7 module to work with Drupal 8 Theming in Drupal 8 - Conversion of themes to Twig Twigify converts Drupal 7 phpTemplate themes into Drupal 8 Twig themes Drupal 8 Field API series part 1: field formatters Routing Example in Drupal 8 Controlling Access to Drupal 8 Routes with Access Checks Drupal 8 Field API series part 2: field widget...

Learn Form Api in Drupal 6

This blog is for drupal begginers, this blog has feature of Form API. There are following steps of drupal form api which we use in custom modules these are follow :- 1. Basic Form 2. Basic Form with Submit Button 3. Basic Form with fieldsets 4. Basic Form with Fieldsets and validation 5. Basic Form with additional element attributes 6. Basic form with validate handler 7. Basic form with submit handler 8. Basic form with button validation 9. Basic form with button form state check 1. Basic Form :- This is very basic form which is showing in below code snipet. <?php   function rahul_module_menu() {     $items = array();     $items['rahul_module/form'] = array(       'title' => 'My form',       'page callback' => 'drupal_get_form',       'page arguments' => array('rahul_module_my_form'),       'access arguments' => array('access content'),       'descrip...

How to use EntityFieldQuery in Drupal 7 ?

A full-rounded EntityFieldQuery example. @see: http://drupal.org/node/1343708 <?php   $query = new EntityFieldQuery();   $query->entityCondition('entity_type', 'node')     ->entityCondition('bundle', 'article')     ->propertyCondition('status', 1)     ->fieldCondition('field_news_types', 'value', 'spotlight', '=')     ->fieldCondition('field_photo', 'fid', 'NULL', '!=')     ->fieldCondition('field_faculty_tag', 'tid', $value)     ->fieldCondition('field_news_publishdate', 'value', $year. '%', 'like')     ->range(0, 10)     ->addMetaData('account', user_load(1)); // Run the query as user 1.   $result = $query->execute();   if (isset($result['node'])) {     $nids = array_keys($result['node']);     $nodes = entity_load('node', $nids);   } ?>

What is MySQL and why we use MySQL ?

What is MySql ? SQL is Structured Query Language,which is computer language for storing,manipulating and retrieving data stored in relational database. MySQL is standard language for Relation Database System. All relational database management systems like MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as standard database language. Why MYSQL ? 1. Allow users to access data in relational database managements systems. 2. Allow users to describe the data. 3. Allow users to define the data in database and manipulate that data. 4. Allow users to create and drop database and tables. 5. Allow users to create view, stored procedure, functions in a database. 6. Allow users to set permissions on tables, procedures and views. MySQL Commands 1. DDL- Data Definition Language :- CREATE,ALTER,DROP 2. DML- Data Manipulation Language :- INSERT,UPDATE,DELETE 3. DCL- Data Control Language :-GRANT,REVOKE 4. DQL- Data Query Language :- SELECT