/**
* Implementation of hook_menu().
*/
function addons_menu() {
$items['admin/links/usercontent'] = array(
'title' => 'User page banner',
'description' => 'Configure default image for user page.',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_page_content'),
'access arguments' => array('user page banner'),
);
return $items;
}
/**
* Implementation of hook_perm
*/
function addons_perm() {
return array('user page banner');
}
/**
* User page banner section
* @return <type>
*/
function user_page_content() {
$form['user_page'] = array(
'#type' => 'fieldset',
'#title' => t('Welcome, User page content'),
'#description' => t('Customize your user page content.')
);
$form['user_page']['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#size' => 50,'#weight' => 1, '#required' => TRUE, '#default_value' => $imgDetails->hp_title, '#description'=>'Type here to display the title for image or flash');
$form['user_page']['submit'] = array('#type' => 'submit', '#value' => "Submit", '#weight' => 7);
$form['user_page']['cancel'] = array('#value' => l('Cancel', 'admin/links/homecontent'), '#weight' => 8);
$form['#attributes'] = array('enctype' => "multipart/form-data");
/*
* do the relevant code to list the inserted records
* here one by one..
//$getQry = db_query("SELECT * FROM ..");
//$cnt=0;
//if (db_affected_rows($getQry) > 0) {
//while($homeObj = db_fetch_object($getQry)) {
//$cnt++;
//$rows[] = array(array('data'=>$cnt, 'width'=>'10%'), array('data'=>$homeObj->hp_title, 'width'=>'20%'), array('data'=>l('Edit', 'admin/links/homecontent/edit/'.$homeObj->hp_id).' / '.l('Delete', 'admin/links/homecontent/delete/'.$homeObj->hp_id), 'width'=>'20%'));
//}
//}
//else {
//$rows[] = array(array('data'=>"No Records Found!", 'colspan'=>3, 'align'=>'center'));
//}
*
* */
$headers = array("S.No", "Banner Title", "Actions");
$result = theme('table', $headers, $rows, array('width'=>'100%'));
$form['user_page']['report'] = array('#value' => $result, '#weight' => 12);
return $form;
}
/**
* user_page_content_validation()
* @param <type> $form
* @param <type> $form_state
*/
function user_page_content_validate ($form, &$form_state) {
$form_data = $form_state['values'];
if (!$form_data['title']){
form_set_error('', 'Please enter the banner title!');
}
}
/**
*
* @param <type> $form
* @param <type> $form_state
*/
function user_page_content_submit ($form, &$form_state) {
$form_data = $form_state['values'];
/* do the relevant code on form submission..
* like INSERT a record using
* db_query("INSERT INTO ..");
* */
drupal_set_message('Record inserted Sucessfully!');
}
Basics of Drupal, Techniques in drupal, Customizing the Drupal themes, Custom functions in drupal, Does and Dont in Drupal, Interview Question & Answers in Drupal etc.
Showing posts with label Custom drupal function. Show all posts
Showing posts with label Custom drupal function. Show all posts
Tuesday, May 17, 2011
Get Server Protocol in PHP
/* function return the Server protocol .. http or https based on the Server Settings */
function getServerProtocol() {
if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$protocol = "https";
} else {
$protocol = "http";
}
return $protocol;
}
function getServerProtocol() {
if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$protocol = "https";
} else {
$protocol = "http";
}
return $protocol;
}
Wrapper Function for String limit
Example #1
/**
* function to return the part of the string if overflows
*/
function limit_text ($text, $count) {
if (strlen($text) > $count) {
return substr($text, 0, ($count-2)) . '...';
}
return $text;
}
Example #2
$len An upper limit on the returned string length.
$wordsafe Flag to truncate at last space within the upper limit. Defaults to FALSE.
$dots Flag to add trailing dots. Defaults to FALSE.
Syntax:
Example:
echo truncate_utf8($continuumDetails['continuum_name'], 35, true, true);
/**
* function to return the part of the string if overflows
*/
function limit_text ($text, $count) {
if (strlen($text) > $count) {
return substr($text, 0, ($count-2)) . '...';
}
return $text;
}
Example #2
Truncate a UTF-8-encoded string safely to a number of characters.
Parameters
$string The string to truncate.$len An upper limit on the returned string length.
$wordsafe Flag to truncate at last space within the upper limit. Defaults to FALSE.
$dots Flag to add trailing dots. Defaults to FALSE.
Return value
The truncated string.Syntax:
truncate_utf8($string, $len, $wordsafe = FALSE, $dots = FALSE)Example:
echo truncate_utf8($continuumDetails['continuum_name'], 35, true, true);
Create new Global Menu in Drupal
Create a new Global Menu in Drupal like Content management, Site building, Site configuration etc.. After create this menu Click on the Dashboard link in the Admin panel. You can see the new menus.
/**
* Implementation of hook_menu().
*/
function addons_menu() {
$items['admin/links'] = array(
'title' => 'My Custom Links',
'description' => "Manage Custom Links.",
'position' => 'right',
'weight' => -10,
'page callback' => 'admin_display_block',
'access arguments' => array('access administration pages'),
);
$items['admin/links/websites'] = array(
'title' => t('My Custom sub link'),
'description' => "Manage Custom sub link.",
'page callback' => 'drupal_get_form',
'page arguments' => array('add_popular_website_form'),
'access callback'=>'user_access',
);
}
function admin_display_block() {
$item = menu_get_item();
if ($content = system_admin_menu_block($item)) {
$output = theme('admin_block_content', $content);
} else {
$output = t('You do not have any administrative items.');
}
return $output;
}
function add_popular_website_form(){
drupal_set_message("Coming soon..");
}
/**
* Implementation of hook_menu().
*/
function addons_menu() {
$items['admin/links'] = array(
'title' => 'My Custom Links',
'description' => "Manage Custom Links.",
'position' => 'right',
'weight' => -10,
'page callback' => 'admin_display_block',
'access arguments' => array('access administration pages'),
);
$items['admin/links/websites'] = array(
'title' => t('My Custom sub link'),
'description' => "Manage Custom sub link.",
'page callback' => 'drupal_get_form',
'page arguments' => array('add_popular_website_form'),
'access callback'=>'user_access',
);
}
function admin_display_block() {
$item = menu_get_item();
if ($content = system_admin_menu_block($item)) {
$output = theme('admin_block_content', $content);
} else {
$output = t('You do not have any administrative items.');
}
return $output;
}
function add_popular_website_form(){
drupal_set_message("Coming soon..");
}
Hooks in Drupal
Allow modules to interact with the Drupal core.
Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.
To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.
The available hooks to implement are explained here in the Hooks section of the developer documentation. The string "hook" is used as a placeholder for the module name in the hook definitions. For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().
Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.
To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.
The available hooks to implement are explained here in the Hooks section of the developer documentation. The string "hook" is used as a placeholder for the module name in the hook definitions. For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().
Functions & methods
| Name | Description |
|---|
| Name | Description |
|---|---|
| custom_url_rewrite_inbound | custom_url_rewrite_inbound is not a hook, it's a function you can add to settings.php to alter incoming requests so they map to a Drupal path. This function is called before modules are loaded and the menu system is initialized and it changes… |
| custom_url_rewrite_outbound | custom_url_rewrite_outbound is not a hook, it's a function you can add to settings.php to alter all links generated by Drupal. This function is called from url(). This function is called very frequently (100+ times per page) so performance… |
| hook_access | Define access restrictions. |
| hook_actions_delete | Execute code after an action is deleted. |
| hook_action_info | Declare information about one or more Drupal actions. |
| hook_action_info_alter | Alter the actions declared by another module. |
| hook_block | Declare a block or set of blocks. |
| hook_boot | Perform setup tasks. See also, hook_init. |
| hook_comment | Respond to comment actions. |
| hook_cron | Perform periodic actions. |
| hook_db_rewrite_sql | Rewrite database queries, usually for access control. |
| hook_delete | Respond to node deletion. |
| hook_disable | Perform necessary actions before module is disabled. |
| hook_elements | Allows modules to declare their own Forms API element types and specify their default values. |
| hook_enable | Perform necessary actions after module is enabled. |
| hook_exit | Perform cleanup tasks. |
| hook_file_download | Control access to private file downloads and specify HTTP headers. |
| hook_filter | Define content filters. |
| hook_filter_tips | Provide tips for using filters. |
| hook_flush_caches | Add a list of cache tables to be cleared. |
| hook_footer | Insert closing HTML. |
| hook_form | Display a node editing form. |
| hook_forms | Map form_ids to builder functions. |
| hook_form_alter | Perform alterations before a form is rendered. |
| hook_form_FORM_ID_alter | Provide a form-specific alteration instead of the global hook_form_alter(). |
| hook_help | Provide online user help. |
| hook_hook_info | Expose a list of triggers (events) that users can assign actions to. |
| hook_init | Perform setup tasks. See also, hook_boot. |
| hook_insert | Respond to node insertion. |
| hook_install | Install the current version of the database schema, and any other setup tasks. |
| hook_link | Define internal Drupal links. |
| hook_link_alter | Perform alterations before links on a node or comment are rendered. |
| hook_load | Load node-type-specific information. |
| hook_locale | Allows modules to define their own text groups that can be translated. |
| hook_mail | Prepare a message based on parameters; called from drupal_mail(). |
| hook_mail_alter | Alter any aspect of email sent by Drupal. You can use this hook to add a common site footer to all outgoing email, add extra header fields, and/or modify the email in any way. HTML-izing the outgoing email is one possibility. See also drupal_mail(). |
| hook_menu | Define menu items and page callbacks. |
| hook_menu_alter | Alter the data being saved to the {menu_router} table after hook_menu is invoked. |
| hook_menu_link_alter | Alter the data being saved to the {menu_links} table by menu_link_save(). |
| hook_nodeapi | Act on nodes defined by other modules. |
| hook_node_access_records | Set permissions for a node to be written to the database. |
| hook_node_grants | Inform the node access system what permissions the user has. |
| hook_node_info | Define module-provided node types. |
| hook_node_operations | Add mass node operations. |
| hook_node_type | Act on node type changes. |
| hook_openid | Allow modules to modify the OpenID request parameters. |
| 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_profile_alter | Alter profile items before they are rendered. |
| hook_requirements | Check installation requirements and do status reporting. |
| hook_schema | Define the current version of the database schema. |
| hook_schema_alter | Perform alterations to existing database schemas. |
| hook_search | Define a custom search routine. |
| hook_search_preprocess | Preprocess text for the search index. |
| hook_system_info_alter | Alter the information parsed from module and theme .info files |
| hook_taxonomy | Act on taxonomy changes. |
| hook_term_path | Allows modules to provide an alternative path for the terms it manages. |
| hook_theme | Register a module (or theme's) theme implementations. |
| hook_theme_registry_alter | Alter the theme registry information returned from hook_theme(). |
| hook_translated_menu_link_alter | Alter a menu link after it's translated, but before it's rendered. |
| hook_translation_link_alter | Perform alterations on translation links. |
| hook_uninstall | Remove any information that the module sets. |
| hook_update | Respond to node updating. |
| hook_update_index | Update Drupal's full-text index for this module. |
| hook_update_last_removed | Return a number which is no longer available as hook_update_N(). |
| hook_update_N | Perform a single update. |
| hook_update_projects_alter | Alter the list of projects before fetching data and comparing versions. |
| hook_update_status_alter | Alter the information about available updates for projects. |
| hook_user | Act on user account actions. |
| hook_user_operations | Add mass user operations. |
| hook_validate | Verify a node editing form. |
| hook_view | Display a node. |
| hook_watchdog | Log an event message |
| 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. |
| page_cache_fastpath | Outputs a cached page. |
Helper function in Drupal
Helper function is a type of functions used in Drupal. Helper functions are started with underscore to the function name. Ex:
_db_query() is an Helper function to db_query() function.
Subscribe to:
Posts (Atom)