Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Tuesday, October 4, 2011

List out some hook function in drupal

hook_access->Define access restrictions.
hook_auth->Verify authentication of a user.
hook_block->Declare a block or set of blocks.
hook_comment ->Act on comments.
hook_cron->Perform periodic actions.
hook_db_rewrite_sql ->Add JOIN and WHERE statements to queries and decide whether the primary_field shall be made DISTINCT. For node objects, primary field is always called nid. For taxonomy terms, it is tid and for vocabularies it is vid. For comments, it is cid. Primary...
hook_delete->Respond to node deletion.
hook_elements->Allows modules to declare their own form element types and specify their default values.
hook_exit->Perform cleanup tasks.
hook_file_download ->Allow file downloads.
hook_filter->Define content filters.
hook_filter_tips->Provide tips for using filters.
hook_footer->Insert closing HTML.
hook_form->Display a node editing form.
hook_form_alter->Perform alterations before a form is rendered. One popular use of this hook is to add form elements to the node form.
hook_help->Provide online user help.
hook_info->Declare authentication scheme information.
hook_init->Perform setup tasks.
hook_insert->Respond to node insertion.
hook_install->Install the current version of the database schema.
hook_link->Define internal Drupal links.
hook_load->Load node-type-specific information.
hook_menu->Define menu items and page callbacks.
hook_nodeapi ->Act on nodes defined by other modules.
hook_node_grants->Grant access to nodes.
hook_node_info->Define the human-readable name of a node type.
hook_perm->Define user permissions.
hook_ping->Ping another server.
hook_prepare ->This is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.
hook_search->Define a custom search routine.
hook_search_preprocess->Preprocess text for the search index.
hook_settings->Declare administrative settings for a module.
hook_submit->This is a hook used by node modules. It is called after validation has succeeded and before insert/update. It is used to for actions which must happen only if the node is to be saved. Usually, $node is changed in some way and then the actual saving of...
hook_taxonomy->Act on taxonomy changes.
hook_update->Respond to node updating.
hook_update_index->Update Drupal's full-text index for this module.
hook_update_N->Perform a single update. For each patch which requires a database change add a new hook_update_N() which will be called by update.php.
hook_user->Act on user account actions.
hook_validate ->Verify a node editing form.
hook_view->Display a node.
hook_xmlrpc->Register XML-RPC callbacks.
module_hook->Determine whether a module implements a hook.
module_implements->Determine which modules are implementing a hook.
module_invoke->Invoke a hook in a particular module.
module_invoke_all->Invoke a hook in all enabled modules that implement it.

List out some functions in template.php

phptemplate_body_class($left, $right)
phptemplate_breadcrumb($breadcrumb)
phptemplate_preprocess_page(&$vars)
garland_preprocess_comment_wrapper(&$vars)
phptemplate_menu_local_tasks()
phptemplate_comment_submitted($comment)
phptemplate_node_submitted($node)
phptemplate_get_ie_styles()

theme_preprocess_node(&$vars) {
theme_preprocess_page(&$vars) {
theme_preprocess_block(&$vars) {
theme_filter_tips_more_info()
theme_filter_tips()
theme_button($element) {

Monday, October 3, 2011

List out the drupal query functions

The following query functions are used in
db_connect - Initialize a database connection.
db_query - Execute query
db_result - Return an individual result field from the previous query.
db_affected_rows - Determine the number of rows changed by the preceding query.
db_rewrite_sql - Rewrites node, taxonomy and comment queries. Use it for listing queries
db_create_table -Create a new table from a Drupal table definition.
db_field_names - Return an array of field names from an array of key/index column specifiers.
db_query_range - Runs a limited-range query in the active database.
db_fetch_array - Fetch one result row from the previous query as an array
db_fetch_object - Fetch one result row from the previous query as an object.
db_error - Determine whether the previous query caused an error.
db_lock_table - Lock a table.
db_unlock_tables - Unlock all locked tables.
db_table_exists - Check if a table exists.
db_column_exists - Check if a column exists in the given table.

Tuesday, September 27, 2011

Hook functions in Drupal 6.

hook_access->Define access restrictions.

hook_auth->Verify authentication of a user.

hook_block->Declare a block or set of blocks.

hook_comment ->Act on comments.

hook_cron->Perform periodic actions.

hook_db_rewrite_sql ->Add JOIN and WHERE statements to queries and decide whether the primary_field shall be made DISTINCT. For node objects, primary field is always called nid. For taxonomy terms, it is tid and for vocabularies it is vid. For comments, it is cid. Primary...

hook_delete->Respond to node deletion.

hook_elements->Allows modules to declare their own form element types and specify their default values.

hook_exit->Perform cleanup tasks.

hook_file_download ->Allow file downloads.

hook_filter->Define content filters.

hook_filter_tips->Provide tips for using filters.

hook_footer->Insert closing HTML.

hook_form->Display a node editing form.

hook_form_alter->Perform alterations before a form is rendered. One popular use of this hook is to add form elements to the node form.

hook_help->Provide online user help.

hook_info->Declare authentication scheme information.

hook_init->Perform setup tasks.

hook_insert->Respond to node insertion.

hook_install->Install the current version of the database schema.

hook_link->Define internal Drupal links.

hook_load->Load node-type-specific information.

hook_menu->Define menu items and page callbacks.

hook_nodeapi ->Act on nodes defined by other modules.

hook_node_grants->Grant access to nodes.

hook_node_info->Define the human-readable name of a node type.

hook_perm->Define user permissions.

hook_ping->Ping another server.

hook_prepare ->This is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.

hook_search->Define a custom search routine.

hook_search_preprocess->Preprocess text for the search index.

hook_settings->Declare administrative settings for a module.

hook_submit->This is a hook used by node modules. It is called after validation has succeeded and before insert/update. It is used to for actions which must happen only if the node is to be saved. Usually, $node is changed in some way and then the actual saving of...

hook_taxonomy->Act on taxonomy changes.

hook_update->Respond to node updating.

hook_update_index->Update Drupal's full-text index for this module.

hook_update_N->Perform a single update. For each patch which requires a database change add a new hook_update_N() which will be called by update.php.

hook_user->Act on user account actions.

hook_validate ->Verify a node editing form.

hook_view->Display a node.

hook_xmlrpc->Register XML-RPC callbacks.

module_hook->Determine whether a module implements a hook.

module_implements->Determine which modules are implementing a hook.

module_invoke->Invoke a hook in a particular module.

module_invoke_all->Invoke a hook in all enabled modules that implement it.

Template function in Drupal

function phptemplate_body_class($left_top, $left_bottom, $right) - Sets the body-tag class attribute.

function phptemplate_comment_wrapper($content, $node) - Allow themable wrapping of all comments.

function phptemplate_preprocess_page(&$vars) { - Override or insert PHPTemplate variables into the templates.

function phptemplate_breadcrumb($breadcrumb) {

function fastlivemail_menu_tree($tree) {

function fastlivemail_menu_item_link($link) {

function fastlivemail_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {

function fastlivemail_button($element) {

function fastlivemail_tablesort_indicator($style) {

function phptemplate_get_ie_styles() { - Generates IE CSS links for LTR and RTL languages.

Monday, September 26, 2011

Drupal AHAH Delete button not working properly

1) Click on create content
2) Upload an image
3) and press Delete button

This causes the form to submit, instead of doing the ajax call, and the item is not deleted.
Seems that when you upload an image, the image_upload_js function rebuilds the form, and the ahah of the Delete button does not work.
You can check this because after uploading an image the class of the Delete button isclass="form-submit" instead of class="form-submit ahah-processed".

When the form is fully submitted, then the Delete button class is class="form-submit ahah-processed" and it works.

Maybe the del button ahah content doesn't work if it hasn't been initialized in the $(document).ready because it didn't exists in the .ready event.
Perhaps loading initially the button as "hidden" may be a solution ?

Ans:

Before sending the response to JSON...Add the following lines...
==========
// AHAH is not being nice to us and doesn't know the "other" button (that is,
// either "Upload" or "Delete") yet. Which in turn causes it not to attach
// AHAH behaviours after replacing the element. So we need to tell it first.

// Loop through the JS settings and find the settings needed for our buttons.
$javascript = drupal_add_js(NULL, NULL);
$filefield_ahah_settings = array();
if (isset($javascript['setting'])) {
foreach ($javascript['setting'] as $settings) {
if (isset($settings['ahah'])) {
foreach ($settings['ahah'] as $id => $ahah_settings) {
if (strpos($id, 'ahah-more') || strpos($id, 'ahah-remove')) {
$filefield_ahah_settings[$id] = $ahah_settings;
}
}
}
}
}

// Add the AHAH settings needed for our new buttons.
if (!empty($filefield_ahah_settings)) {
$output_settings = 'jQuery.extend(Drupal.settings.ahah, '. drupal_to_js($filefield_ahah_settings) .');';
}

File field and AHAH button not working together in dynamic form

I faced some problem with file filed and AHAH button both together. But File field and AHAH button not working together.
For some reason, file uploads don't like drupal_json() with its manual setting of the text/javascript HTTP header. So use this one instead.

Solution:
==========
Instead of using
"drupal_json(array('status' => TRUE, 'data' => $output));"
need to use
" print drupal_to_js ( array ( 'status' => TRUE, 'data' => $output ) ); exit "

First uploaded picture not overwrite when resubmit the user picture

1. Upload a user picture
2. delete the picture
3. resubmit another picture.

Error: The first picture was not replaced.

delete all caching mechanisms (Website/browser) and retry.

Ans:

We can't change the core module(user.module). So we can change in hook_user. May be this will get error when we upgrade the version.

Another way to change the user picture.

Use hook_user function, in switch case, rename the file path with timestamp and update user table as same file path

Example:

function hook_user($op, &$edit, &$account, $category = NULL) {
switch($op){
case 'after_update':
case 'after_update':
$old_filename = $account->picture;
$filename = basename($account->picture);
$fileArray = explode('.', $filename);
$finalFilename = $fileArray[0].'-'.time().'.'.$fileArray[1];
$pictureArray = explode('/', $account->picture);
$pictureArray[count($pictureArray)-1]=$finalFilename;
$picturePath = implode('/', $pictureArray);
$account->picture = $picturePath;
rename($old_filename, $picturePath);
db_query("UPDATE users SET picture='$picturePath' WHERE uid=%d", $account->uid);
break;
}
}

This will work.

Drupal 6 Schema

Drupal Schema API allows to declare their database tables in a structured array. And provides API functions for creating, dropping, and changing tables, columns, keys, and indexes in a table.


Create "module.install" file under the module.

Create the following hook function to add schema,

hook_schema()
hook_install()
hook_uninstall()

// Define a table
function hook_shema(){
// Define table array
For example:
$schema['node'] = array(
'fields' => array(
'nid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => t('Primary Key'),
),
'status' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Status.'),
),
),
'primary key' => array('nid'),
);
}

// Install all the tables while enable the module form list
function hook_install() {
drupal_install_schema(hook);
}

// Drop the all tables while uninstall the module
function hook_uninstall() {
drupal_uninstall_schema(hook);
}

// Add one row to table
drupal_write_record(table_name, $record_object);

// Update a row in a table
drupal_write_record(table_name, $record_object, primary_key);

Drupal 6 Installation Profile

Installation profiles combine provide site features and functions for a specific type of site as a single download containing Drupal core, contributed modules, themes, and pre-defined configuration. Once installed, installation profiles can be configured and customized the same as traditionally-built Drupal sites. It will help to create new drupal instance
with minimum requirements.

Profile folder name: root/profiles/new-profile

Create the following files/folders under profiles folder(new-profile):
modules - folder
themes - folder
new-profile.profile - file

Inside this new-profile.profile file , you will write the following hook_profile_funcs().

• new-profile_profile_modules() - Core, Contributed and customized modules
to be enabled when this profile is installed
• new-profile_profile_details() - description of the profile for the
initial installation screen
• new-profile_profile_tasks() - list of tasks that this profile supports
(functions, initial database changes).

List of Modules in Drupal 6

The following module list are using in Durpal 6.
1. Core - Mandatory
System
User
Node
Block
Filter
2. Core - Optional
Aggregator
Blog
Forums
Profile
Comments
Locale
Help
Throttle
Search
Upload
Update
etc.,
3. Contributed Modules
Image
CCk
Views
Date
Filefield
FCKEditor
Thickbox
etc.,
4. Custom modules
User can create custom modules and use.