Table of Contents

drupal 7

Docs:

api:

Drupal Overview

Refer: refer: https://drupal.org/getting-started/before/overview Everyone planning and building Web solutions with Drupal benefits from understanding what a “hook” is—and why Drupal is not a CMS.

Everyone involved needs to understand that they can architect a Drupal site that offers a more-sophisticated set of features than a WordPress site, because Drupal is not a content management system (CMS); it is a content management framework.

For me now especially with Drupal 7, it is an excellent web application framework and we should be comparing it to the likes of Symfony and Zend Framework, rather than Joomla and Typo3.

Drupal Dataflow

If you want to go deeper with Drupal, you should understand how information flows between the system's layers. There are five main layers to consider:

Understand about drupal Dataflow

  1. data pool: At the base of the system is the collection of nodes—the data pool. Before anything can be displayed on the site, it must be input as data.
  2. Modules: The next layer up is where modules live. Modules are functional plugins that are either part of the Drupal core (they ship with Drupal) or they are contributed items that have been created by members of the Drupal community. Modules build on Drupal's core functionality, allowing you to:
    • customize the data items (fields) on your node types;
    • set up e-commerce;
    • programmatically sorting and display of content (custom output controlled by filters you define);
    • and more. There are thousands of different options within the fast-growing repository of contributed Drupal modules. They represent the innovation and collaborative effort of everyone from individuals to large corporations.
  3. blocks and menus: At the next layer, we find blocks and menus.
    • Blocks often provide the output from a module or can be created to display whatever you want, and then can be placed in various spots in your template (theme) layout. Blocks can be configured to output in various ways, as well as only showing on certain defined pages, or only for certain defined users.
    • Menus are navigators in Drupal, which defines the content coming on each defined menu path (relative url). Menus are core element of drupal which gives all the pages created in Drupal
  4. user permissions: Next are user permissions. This is where settings are configured to determine what different kinds of users are allowed to do and see. Permissions are defined for various roles, and in turn, users are assigned to these roles in order to grant them the defined permissions.
  5. Template: On the top layer is the site theme (the “skin”). This is made up predominantly of XHTML and CSS, with some PHP variables intermixed, so Drupal-generated content can go in the appropriate spots. Also included with each theme is a set of functions that can be used to override standard functions in the modules in order to provide complete control over how the modules generate their markup at output time. Templates can also be assigned on-the-fly based on user permissions.

This directional flow from bottom to top controls how Drupal works. And If you want some functionality not showing up, you can configure follow types below:

drupal startup

(drupal_bootstrap) and config

diagram


load system config

Overview about configs in drupal:

Default drupal will cache content of table variables and table system and load follow codes below:

SELECT cid, DATA, created, expire, serialized FROM cache_bootstrap WHERE cid IN ('variables');
SELECT cid, DATA, created, expire, serialized FROM cache_bootstrap WHERE cid IN ('bootstrap_modules')
SELECT cid, DATA, created, expire, serialized FROM cache_bootstrap WHERE cid IN ('system_list')
SELECT cid, DATA, created, expire, serialized FROM cache_bootstrap WHERE cid IN ('module_implements')

sequence load files

  1. Load Config
    • D:\web\babies\.htaccess
    • D:\web\babies\index.php
    • D:\web\babies\includes\bootstrap.inc
    • D:\web\babies\sites\default\settings.php
  2. Load core system
    • D:\web\babies\includes\cache.inc
    • D:\web\babies\includes\database\database.inc
    • D:\web\babies\includes\lock.inc
    • D:\web\babies\includes\database\mysql\database.inc
    • D:\web\babies\includes\database\query.inc
    • D:\web\babies\includes\database\mysql\query.inc
    • D:\web\babies\includes\database\select.inc
    • D:\web\babies\includes\module.inc
    • D:\web\babies\sites\all\modules\devel\devel.module
    • D:\web\babies\includes\session.inc
    • D:\web\babies\modules\user\user.module
    • D:\web\babies\includes\entity.inc
    • D:\web\babies\includes\language.inc
    • D:\web\babies\includes\locale.inc
    • D:\web\babies\includes\common.inc
    • D:\web\babies\includes\path.inc
    • D:\web\babies\includes\theme.inc
    • D:\web\babies\includes\pager.inc
    • D:\web\babies\includes\menu.inc
    • D:\web\babies\includes\tablesort.inc
    • D:\web\babies\includes\file.inc
    • D:\web\babies\includes\stream_wrappers.inc
    • D:\web\babies\includes\unicode.inc
    • D:\web\babies\includes\image.inc
    • D:\web\babies\includes\form.inc
    • D:\web\babies\includes\mail.inc
    • D:\web\babies\includes\actions.inc
    • D:\web\babies\includes\ajax.inc
    • D:\web\babies\includes\token.inc
    • D:\web\babies\includes\errors.inc
  3. Load modules
    • D:\web\babies\modules\block\block.module
    • D:\web\babies\modules\comment\comment.module
    • D:\web\babies\modules\dashboard\dashboard.module
    • D:\web\babies\sites\all\modules\devel\devel_generate\devel_generate.module
    • D:\web\babies\modules\field\field.module
    • D:\web\babies\modules\field\field.crud.inc
    • D:\web\babies\modules\field\field.default.inc
    • D:\web\babies\modules\field\field.info.inc
    • D:\web\babies\modules\field\field.multilingual.inc
    • D:\web\babies\modules\field\field.attach.inc
    • D:\web\babies\modules\field\field.form.inc
    • D:\web\babies\modules\field\modules\field_sql_storage\field_sql_storage.module
    • D:\web\babies\modules\file\file.module
    • D:\web\babies\modules\file\file.field.inc
    • D:\web\babies\modules\filter\filter.module
    • D:\web\babies\modules\image\image.module
    • D:\web\babies\modules\image\image.field.inc
    • D:\web\babies\modules\locale\locale.module
    • D:\web\babies\modules\menu\menu.module
    • D:\web\babies\modules\node\node.module
    • D:\web\babies\modules\field\modules\options\options.module
    • D:\web\babies\modules\search\search.module
    • D:\web\babies\modules\system\system.module
    • D:\web\babies\modules\taxonomy\taxonomy.module
    • D:\web\babies\modules\field\modules\text\text.module
    • D:\web\babies\modules\toolbar\toolbar.module
  4. Load template
    • D:\web\babies\profiles\standard\standard.profile
    • D:\web\babies\themes\engines\phptemplate\phptemplate.engine
    • D:\web\babies\themes\professional_pro\template.php
    • D:\web\babies\sites\all\modules\devel\krumo\class.krumo.php
    • D:\web\babies\themes\professional_pro\templates\page.tpl.php
    • D:\web\babies\modules\search\search-block-form.tpl.php
    • D:\web\babies\modules\block\block.tpl.php
    • D:\web\babies\modules\system\region.tpl.php
    • D:\web\babies\themes\professional_pro\templates\node.tpl.php
    • D:\web\babies\modules\user\user-picture.tpl.php
    • D:\web\babies\modules\block\block.tpl.php
    • D:\web\babies\modules\system\region.tpl.php
    • D:\web\babies\modules\toolbar\toolbar.tpl.php
    • D:\web\babies\themes\professional_pro\templates\html.tpl.php

drupal modules and Hooks

Hooks: Hook is a PHP function. They provide a way for a module to extend the functionality of another module.


Hook when user enable,disable,uninstall module

refer:

Call Basic Hooks: hook_schema, hook_enable,hook_menu,hook_uninstall

/**
 * Implements hook_enable().
 */
function comment_enable() {
  // Insert records into the node_comment_statistics for nodes that are missing.
  $query = db_select('node', 'n');
  $query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid');
  $query->addField('n', 'created', 'last_comment_timestamp');
  $query->addField('n', 'uid', 'last_comment_uid');
  $query->addField('n', 'nid');
  $query->addExpression('0', 'comment_count');
  $query->addExpression('NULL', 'last_comment_name');
  $query->isNull('ncs.comment_count');
 
  db_insert('node_comment_statistics')
    ->from($query)
    ->execute();
}
/**
 * Implements hook_uninstall().
 */
function comment_uninstall() {
  // Delete comment_body field.
  field_delete_field('comment_body');
 
  // Remove variables.
  variable_del('comment_block_count');
  $node_types = array_keys(node_type_get_types());
  foreach ($node_types as $node_type) {
    field_attach_delete_bundle('comment', 'comment_node_' . $node_type);
    variable_del('comment_' . $node_type);
    variable_del('comment_anonymous_' . $node_type);
    variable_del('comment_controls_' . $node_type);
    variable_del('comment_default_mode_' . $node_type);
    variable_del('comment_default_order_' . $node_type);
    variable_del('comment_default_per_page_' . $node_type);
    variable_del('comment_form_location_' . $node_type);
    variable_del('comment_preview_' . $node_type);
    variable_del('comment_subject_field_' . $node_type);
  }
}
/**
 * Implements hook_menu().
 */
function comment_menu() {
  $items['admin/content/comment'] = array(
    'title' => 'Comments',
    'description' => 'List and edit site comments and the comment approval queue.',
    'page callback' => 'comment_admin',
    'access arguments' => array('administer comments'),
    'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
    'file' => 'comment.admin.inc',
  );
  // Tabs begin here.
  $items['admin/content/comment/new'] = array(
    'title' => 'Published comments',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/content/comment/approval'] = array(
    'title' => 'Unapproved comments',
    'title callback' => 'comment_count_unpublished',
    'page arguments' => array('approval'),
    'access arguments' => array('administer comments'),
    'type' => MENU_LOCAL_TASK,
  );
  $items['comment/%'] = array(
    'title' => 'Comment permalink',
    'page callback' => 'comment_permalink',
    'page arguments' => array(1),
    'access arguments' => array('access comments'),
  );
  $items['comment/%/view'] = array(
    'title' => 'View comment',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  // Every other comment path uses %, but this one loads the comment directly,
  // so we don't end up loading it twice (in the page and access callback).
  $items['comment/%comment/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'comment_edit_page',
    'page arguments' => array(1),
    'access callback' => 'comment_access',
    'access arguments' => array('edit', 1),
    'type' => MENU_LOCAL_TASK,
    'weight' => 0,
  );
.................
Ư
/**
 * Implements hook_schema().
 */
function comment_schema() {
  $schema['comment'] = array(
    'description' => 'Stores comments and associated data.',
    'fields' => array(
      'cid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique comment ID.',
      ),
      'pid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {comment}.cid to which this comment is a reply. If set to 0, this comment is not a reply to an existing comment.',
      ),
......................      
}

Hook_menu

Define menu items and page callbacks:

Below are example code for hook_menu in node module

Hook_schema

Overview about Hook_schema:

Example code:

Hook for block


Basic hooks: hook_block_info, hook_block_configure, hook_block_save, hook_block_view

Permissions, Access Control: hook_permission

hook_permission define user permissions for module. When hook_permission is defined, we can see permission settings at link /admin/people/permissions

Form

Research form hook in module user

  1. Define 'page callback' for menu /user
    /**
     * Implements hook_menu().
     */
    function user_menu() {
    ................
    $items['user'] = array(
        'title' => 'User account',
        'title callback' => 'user_menu_title',
        'page callback' => 'user_page',
        'access callback' => TRUE,
        'file' => 'user.pages.inc',
        'weight' => -10,
        'menu_name' => 'user-menu',
      );
    ................
    }
  2. implement 'page callback' for menu /user: 'user_page'
    /**
     * Access callback for path /user.
     *
     * Displays user profile if user is logged in, or login form for anonymous
     * users.
     */
    function user_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item('user/' . $user->uid);
        return menu_execute_active_handler(NULL, FALSE);
      }
      else {
        return drupal_get_form('user_login');
      }
    }
  3. drupal_get_form('user_login') will call auto define form function user_login($form, &$form_state):
    /**user_login($form, &$form_state)
     * Form builder; the main user login form.
     *
     * @ingroup forms
     */
    function user_login($form, &$form_state) {
      global $user;
     
      // If we are already logged on, go to the user page instead.
      if ($user->uid) {
        drupal_goto('user/' . $user->uid);
      }
     
      // Display login form:
      $form['name'] = array('#type' => 'textfield',
        '#title' => t('Username'),
        '#size' => 60,
        '#maxlength' => USERNAME_MAX_LENGTH,
        '#required' => TRUE,
      );
     
      $form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
      $form['pass'] = array('#type' => 'password',
        '#title' => t('Password'),
        '#description' => t('Enter the password that accompanies your username.'),
        '#required' => TRUE,
      );
      $form['#validate'] = user_login_default_validators();
      $form['actions'] = array('#type' => 'actions');
      $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
     
      return $form;
    }

  4. User Submit user, pass → valiate functions will be called to check data validated
    /**
     * A FAPI validate handler. Sets an error if supplied username has been blocked.
     */
    function user_login_name_validate($form, &$form_state) {
      if (isset($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) {
        // Blocked in user administration.
        form_set_error('name', t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name'])));
      }
    }
    /**
     * A validate handler on the login form. Check supplied username/password
     * against local users table. If successful, $form_state['uid']
     * is set to the matching user ID.
     */
    function user_login_authenticate_validate($form, &$form_state) {
      $password = trim($form_state['values']['pass']);
      if (!empty($form_state['values']['name']) && !empty($password)) {
        // Do not allow any login from the current user's IP if the limit has been
        // reached. Default is 50 failed attempts allowed in one hour. This is
        // independent of the per-user limit to catch attempts from one IP to log
        // in to many different user accounts.  We have a reasonably high limit
        // since there may be only one apparent IP for all users at an institution.
        if (!flood_is_allowed('failed_login_attempt_ip', variable_get('user_failed_login_ip_limit', 50), variable_get('user_failed_login_ip_window', 3600))) {
          $form_state['flood_control_triggered'] = 'ip';
          return;
        }
        $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
        if ($account) {
          if (variable_get('user_failed_login_identifier_uid_only', FALSE)) {
            // Register flood events based on the uid only, so they apply for any
            // IP address. This is the most secure option.
            $identifier = $account->uid;
          }
          else {
            // The default identifier is a combination of uid and IP address. This
            // is less secure but more resistant to denial-of-service attacks that
            // could lock out all users with public user names.
            $identifier = $account->uid . '-' . ip_address();
          }
          $form_state['flood_control_user_identifier'] = $identifier;
     
          // Don't allow login if the limit for this user has been reached.
          // Default is to allow 5 failed attempts every 6 hours.
          if (!flood_is_allowed('failed_login_attempt_user', variable_get('user_failed_login_user_limit', 5), variable_get('user_failed_login_user_window', 21600), $identifier)) {
            $form_state['flood_control_triggered'] = 'user';
            return;
          }
        }
        // We are not limited by flood control, so try to authenticate.
        // Set $form_state['uid'] as a flag for user_login_final_validate().
        $form_state['uid'] = user_authenticate($form_state['values']['name'], $password);
      }
    }
    /**
     * The final validation handler on the login form.
     *
     * Sets a form error if user has not been authenticated, or if too many
     * logins have been attempted. This validation function should always
     * be the last one.
     */
    function user_login_final_validate($form, &$form_state) {
      if (empty($form_state['uid'])) {
        // Always register an IP-based failed login event.
        flood_register_event('failed_login_attempt_ip', variable_get('user_failed_login_ip_window', 3600));
        // Register a per-user failed login event.
        if (isset($form_state['flood_control_user_identifier'])) {
          flood_register_event('failed_login_attempt_user', variable_get('user_failed_login_user_window', 21600), $form_state['flood_control_user_identifier']);
        }
     
        if (isset($form_state['flood_control_triggered'])) {
          if ($form_state['flood_control_triggered'] == 'user') {
            form_set_error('name', format_plural(variable_get('user_failed_login_user_limit', 5), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
          }
          else {
            // We did not find a uid, so the limit is IP-based.
            form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array('@url' => url('user/password'))));
          }
        }
        else {
          form_set_error('name', t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password'))));
          watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
        }
      }
      elseif (isset($form_state['flood_control_user_identifier'])) {
        // Clear past failures for this user so as not to block a user who might
        // log in and out more than once in an hour.
        flood_clear_event('failed_login_attempt_user', $form_state['flood_control_user_identifier']);
      }
    }
  5. If all function validate are OK, submit form will be called
    function user_login_submit($form, &$form_state) {
      global $user;
      $user = user_load($form_state['uid']);
      $form_state['redirect'] = 'user/' . $user->uid;
     
      user_login_finalize($form_state);
    }

theme hooks

hook_theme define all themes in module, and all themes will begin with prefix theme_, with these defines, we can call function theme(…) to display the theme

Define new hooks in drupal

core drupal API, constants and global variables

core drupal API

constants and global variables

drupal theme

drupal theme stark

drupal theme start using original themes and templates of drupal and don't have any custom changes

Original datas which drupal theme stark using:

custom drupal theme

refer: https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme/7

Investigate custom codes in drupal theme professional_pro:

How to override theme_* functions and *.tpl.php in drupal

change css,js and custom layout(region) in .info

Multisite Configuration

Understand about multisite in drupal

refer:

If you are running more than one Drupal site, you can simplify management and upgrading of your sites by using the multi-site feature. Multi-site allows you to share a single Drupal installation including:

This is particularly useful for managing the code since each upgrade only needs to be done once. Each site will have:

so each site will have its own content, settings, enabled modules, and enabled theme. However, the sites are sharing a code base and web document root, so there may be security concerns with multiple administrators

Steps to create new site

To create a new site using a shared Drupal code base you must complete the following steps:

Option: Edit directory alias for site in sites/sites.php

If you want using www1.babies.vn and www2.babies.vn to access the configuration of sites/www.babies.vn, Edit sites/sites.php with below content:

$sites['www1.babies.vn'] = 'www.babies.vn';
$sites['www2.babies.vn'] = 'www.babies.vn';

Or If want moving sites/www.babies.vn to sites/babiesvn, you must change the sites/sites.php to:

$sites['www1.babies.vn'] = 'babiesvn';
$sites['www2.babies.vn'] = 'babiesvn';

Drupal scripts

Run drupal with PHP CLI

php scripts/drupal.sh http://www.babies.vn/node

Change drupal admin password

  1. Step1: Generate password hash
    php scripts/password-hash.sh 8941362
    password: 8941362               hash: $S$Dr/zxP8rFxQjRGsaRpaqcA.HElcEFfExJJ80N.jlnyesqeg.emwJ
  2. Step2: Update password in drupal database:
    UPDATE users SET pass ='$S$Dr/zxP8rFxQjRGsaRpaqcA.HElcEFfExJJ80N.jlnyesqeg.emwJ' WHERE uid = 1;

Run drupal test

script drupal test only run on linux or windows with cygwin was installed

Dump drupal database

Generates content for a Drupal 7 database to test the upgrade process

php ./scripts/dump-database-d7.sh

Drupal basic updates

Drupal editor

Editor with eclipse: Eclipse PDT(PHP Development Tool)

Editor with notepad++:

  1. Step1: Go to Settings → Style Configurator
  2. Step2: Then select Language PHP to edit User ext to values below:
    module install inc engine  install inc engine theme

Update default theme in database

UPDATE variable SET VALUE='s:6:"bartik"' WHERE name = 'theme_default';
TRUNCATE cache;
TRUNCATE cache_bootstrap;
TRUNCATE cache_block;
TRUNCATE cache_menu;
TRUNCATE cache_form;

Enable drupal module in database

check module name in file .info(if filename is page_manager.info ⇒ module name is page_manager) and update below query

UPDATE system SET STATUS=1 WHERE name='ctools';

Step by step create content types in theme

Note: Erase all cache tables before create new content type Or clear all caches in admin

Artile and Basic Page

Article:

Basic Page:

Below are content of node_type table after add Article and Basic Page:

type name base module
articleArticlenode_contentnode
pageBasic pagenode_contentnode

create custom field Term Taxonomy(Category) for article content type

Required: Install module taxonomy

Step1: Go to Structure → Taxonomy to add new Vocabulary name article_tags with list terms: Xã Hội, Kinh Tế …
Step2: Create custom field Term Taxonomy for article content type ⇒ from label tags will auto create below information:

Next you click Term reference and select Vocabulary with name article_tags for contenty Article Below are content of tables from database:

entity_type bundle deleted entity_id revision_id language delta field_tags_tid
node article 0 26 26 und 0 4
node article 0 27 27 und 0 5
tidvidnamedescriptionformatweightuuid
4 1 News NULL NULL 0 a1588461-ff28-486c-b066-61d6e5b41da4
5 1 Design NULL NULL 0 bce05cc9-3f42-4866-bb68-041db771a815

drupal clear database cache

TRUNCATE TABLE cache;
TRUNCATE TABLE cache_admin_menu;
TRUNCATE TABLE cache_block;
TRUNCATE TABLE cache_bootstrap;
TRUNCATE TABLE cache_field;
TRUNCATE TABLE cache_filter;
TRUNCATE TABLE cache_form;
TRUNCATE TABLE cache_image;
TRUNCATE TABLE cache_l10n_update;
TRUNCATE TABLE cache_libraries;
TRUNCATE TABLE cache_media_xml;
TRUNCATE TABLE cache_menu;
TRUNCATE TABLE cache_page;
TRUNCATE TABLE cache_panels;
TRUNCATE TABLE cache_path;
TRUNCATE TABLE cache_rules;
TRUNCATE TABLE cache_token;
TRUNCATE TABLE cache_update;
TRUNCATE TABLE cache_variable;
TRUNCATE TABLE cache_views;
TRUNCATE TABLE cache_views_data;

change administration theme

Go to apperance at the view Administration theme select:

change basic informations(site name, email,slogan,homepage, language, performance) in system configuration

All basic Informations will be updated in Configuration menu

  1. change site information(site name, e-mail address, slogan, default front page(homepage), and number of posts per page): Go to Configuration→System→Site Information
  2. change language:
    • Required: Install Locale module before configure
    • Go to configuration→Regional and Language
      • Using Translate interface to import .po file
      • Using Languages for Configure languages for content and the user interface.
  3. config performance: Go to configuration→development→performance
  4. configuration→media→file system: tmp
  5. configuration→content authoring→text formats: configure full HTML → remove all filters

disable title of Main Menu

Go to structure→blocks and click to configure main menu block, In the 'Main Menu' Block page, you input the Block Title is <none> and click button save

drupal7 custom template

refer: https://www.drupal.org/node/1089656

custom theme node base on content type

refer: https://www.drupal.org/node/17565

Search in drupal source the keyword 'node_' to see all the theme_hook_suggestions for node, for example:

  $variables['theme_hook_suggestions'][] = 'node__' . $node->type;
  $variables['theme_hook_suggestions'][] = 'node__' . $node->nid;

⇒ we can use node–{node→type}.tpl.php to create custom template for any node type

The file node.tpl.php is used to theme certain types of nodes. To theme individual content types in different ways, you need to create a file node-[type].tpl.php in your theme's folder, where [type] is the machine readable name of the content type

For Drupal 6 (Use – for Drupal 7):

custom block and region template

In Drupal 7 template files for block are searched in the following order:

If the block delta key uses a hyphen, (-), replace this with an underscore (_).

custom field template

pattern file: field–[type|name[–content-type]|content-type].tpl.php Drupal will use the most specific template it finds:

  1. field–field-name–content-type.tpl.php
  2. field–content-type.tpl.php
  3. field–field-name.tpl.php
  4. field–field-type.tpl.php

Drupal custom modules

drupal custom fields

Field (core) and Field UI (core)

File (core)

Provides file upload fields

entity

References

Provides User and Node reference fields

ctools and views

Views: Creates lists of entities, like content and users(The same view architecture in database engine)

uninstall view database

DROP TABLE cache_views;
DROP TABLE cache_views_data;
DROP TABLE views_display;
DROP TABLE views_view;

select, filter and format display in view

The Views main editor is where you'll spend most of your time. There are a dizzying amount of options available. Instead, think of these as two main functions:

custom template in view

refer: http://www.wdtutorials.com/2011/06/29/drupal-7-how-create-custom-template-view#.VGBhA_msXPo custom template will be updated in code or in database

Hit the Theme: Information under Advanced tab to display theme information dialog

And below are information of template file for view in theme information dialog

custom template for display node and comment in view:

$vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name;
$vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display;
$vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name;
$vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display;

experience

To active the changes in view we need to actions one of below methods:

Page manager and panels

The Page manager and Panels modules used to be one and the same project, originally created as an alternative to Drupal's block system. A simplified description of the two modules is:

Features module

We use features module to export and import features of drupal. Below are step by step to action:

  1. Step1 Export: Go to structure→feature, click tab Create Feature
    • First we select content type contact and faq with name contact_faq:
    • Next we click button download feature → we will be received the file contact_faq.tar which define new module for these features
  2. Step2 Import: We will extract the contact_faq.tar to sites/all/modules and install this module ⇒ the module will import all features to database
  3. Step3: After import, we will remove the module contact_faq:
    rm -rf sites/all/modules/contact_faq