id
stringlengths
22
22
drupal_version
stringclasses
1 value
source_type
stringclasses
1 value
source_url
stringlengths
70
167
instruction
stringlengths
87
500
context
stringlengths
16
10.7k
response
stringlengths
68
5.97k
tags
listlengths
2
2
created_at
timestamp[s]date
2026-09-30 00:00:00
2026-09-30 00:00:00
api-drupal7-465ad90289
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7079/7.x
Implement `system_update_7079()` in PHP for Drupal 7. Required behavior: Convert the 'filesize' column in {file_managed} to a bigint.
File: modules/system/system.install
function system_update_7079() { $spec = array( 'description' => 'The size of the file in bytes.', 'type' => 'int', 'size' => 'big', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ); db_change_field('file_managed', 'filesize', 'filesize', $spec); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-465c684d9c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.api.php/function/hook_trigger_info/7.x
Give me the example code for `hook_trigger_info()` in Drupal 7. Hook description: Declare triggers (events) for users to assign actions to.
This hook is used by the trigger module to create a list of triggers (events) that users can assign actions to. Your module is responsible for detecting that the events have occurred, calling trigger_get_assigned_actions() to find out which actions the user has associated with your trigger, and then calling actions_do(...
function hook_trigger_info() { return array( 'node' => array( 'node_presave' => array( 'label' => t('When either saving new content or updating existing content'), ), 'node_insert' => array( 'label' => t('After saving new content'), ), 'node_update' => array( ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4669eef2d1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_delete_form_submit/7.x
In Drupal 7, write the function `shortcut_set_delete_form_submit($form, &$form_state)` (file modules/shortcut/shortcut.admin.inc) so that it does the following: Submit handler for shortcut_set_delete_form().
File: modules/shortcut/shortcut.admin.inc
function shortcut_set_delete_form_submit($form, &$form_state) { $shortcut_set = shortcut_set_load($form_state['values']['shortcut_set']); shortcut_set_delete($shortcut_set); $form_state['redirect'] = 'admin/config/user-interface/shortcut'; drupal_set_message(t('The shortcut set %title has been deleted.', array(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-468b0e51a4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/_tracker_add/7.x
In Drupal 7, write the function `_tracker_add($nid, $uid, $changed)` (file modules/tracker/tracker.module) so that it does the following: Updates indexing tables when a node is added, updated, or commented on.
Parameters: - $nid: A node ID. - $uid: The node or comment author. - $changed: The node updated timestamp or comment timestamp. File: modules/tracker/tracker.module
function _tracker_add($nid, $uid, $changed) { $node = db_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject(); // Adding a comment can only increase the changed timestamp, so our // calculation here is simple. $changed = max($node->changed, $changed); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-46b9d4c8c4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.install/function/aggregator_update_7004/7.x
Implement `aggregator_update_7004()` in PHP for Drupal 7. Required behavior: Add index on timestamp.
File: modules/aggregator/aggregator.install
function aggregator_update_7004() { if (!db_index_exists('aggregator_item', 'timestamp')) { db_add_index('aggregator_item', 'timestamp', array('timestamp')); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-46cdf72904
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_modules_uninstalled/7.x
I need the code for `block_modules_uninstalled($modules)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_modules_uninstalled().
Cleans up {block} and {block_role} tables from modules' blocks. File: modules/block/block.module
function block_modules_uninstalled($modules) { db_delete('block') ->condition('module', $modules, 'IN') ->execute(); db_delete('block_role') ->condition('module', $modules, 'IN') ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-46d349786e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7001/7.x
In Drupal 7, write the function `taxonomy_update_7001()` (file modules/taxonomy/taxonomy.install) so that it does the following: Rename taxonomy tables.
File: modules/taxonomy/taxonomy.install
function taxonomy_update_7001() { db_rename_table('term_data', 'taxonomy_term_data'); db_rename_table('term_hierarchy', 'taxonomy_term_hierarchy'); db_rename_table('term_node', 'taxonomy_term_node'); db_rename_table('term_relation', 'taxonomy_term_relation'); db_rename_table('term_synonym', 'taxonomy_term_syn...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-46d7f1ecbc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_load/7.x
I need the code for `file_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age)` in Drupal 7 (modules/file/file.field.inc). It must do this: Implements hook_field_load().
File: modules/file/file.field.inc
function file_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { $fids = array(); foreach ($entities as $id => $entity) { // Load the files from the files table. foreach ($items[$id] as $delta => $item) { if (!empty($item['fid'])) { $fids[] = $item['fid']; ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-46e1f157ca
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_login_final_validate/7.x
In Drupal 7, write the function `user_login_final_validate($form, &$form_state)` (file modules/user/user.module) so that it does the following: 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. File: modules/user/user.module
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_s...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-46e1f6b36b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_array_diff_assoc_recursive/7.x
Implement `drupal_array_diff_assoc_recursive($array1, $array2)` in PHP for Drupal 7. Required behavior: Recursively computes the difference of arrays with additional index check.
This is a version of array_diff_assoc() that supports multidimensional arrays. Parameters: - $array1 (array): The array to compare from. - $array2 (array): The array to compare to. Returns (array): Returns an array containing all the values from array1 that are not present in array2. File: includes/common.inc
function drupal_array_diff_assoc_recursive($array1, $array2) { $difference = array(); foreach ($array1 as $key => $value) { if (is_array($value)) { if (!array_key_exists($key, $array2) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = drupal_array...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-46ee01ca1b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_modules_disabled/7.x
In Drupal 7, write the function `filter_modules_disabled($modules)` (file modules/filter/filter.module) so that it does the following: Implements hook_modules_disabled().
File: modules/filter/filter.module
function filter_modules_disabled($modules) { // Reset the static cache of module-provided filters, in case any of the // newly disabled modules defined or altered any filters. drupal_static_reset('filter_get_filters'); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-47002b57f3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/_trigger_user/7.x
Implement `_trigger_user($hook, &$edit, $account, $category = NULL)` in PHP for Drupal 7. Required behavior: Calls action functions for user triggers.
Parameters: - $hook: The hook that called this function. - $edit: Edit variable passed in to the hook or empty array if not needed. - $account: Account variable passed in to the hook. - $method: Method variable passed in to the hook or NULL if not needed. File: modules/trigger/trigger.module
function _trigger_user($hook, &$edit, $account, $category = NULL) { // Keep objects for reuse so that changes actions make to objects can persist. static $objects; $aids = trigger_get_assigned_actions($hook); $context = array( 'group' => 'user', 'hook' => $hook, 'form_values' => &$edit, ); forea...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-472dcd917b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_date_format_reset_form/7.x
In Drupal 7, write the function `locale_date_format_reset_form($form, &$form_state, $langcode)` (file modules/locale/locale.admin.inc) so that it does the following: Reset locale specific date formats to the global defaults.
Parameters: - $langcode: Language code, e.g. 'en'. File: modules/locale/locale.admin.inc
function locale_date_format_reset_form($form, &$form_state, $langcode) { $form['langcode'] = array('#type' => 'value', '#value' => $langcode); $languages = language_list(); return confirm_form($form, t('Are you sure you want to reset the date formats for %language to the global defaults?', array('%language' =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-473190612e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/_xmlrpc/7.x
I need the code for `_xmlrpc($url, $args, $options = array())` in Drupal 7 (includes/xmlrpc.inc). It must do this: Performs one or more XML-RPC requests.
Parameters: - $url: An absolute URL of the XML-RPC endpoint, e.g., http://example.com/xmlrpc.php - $args: An associative array whose keys are the methods to call and whose values are the arguments to pass to the respective method. If multiple methods are specified, a system.multicall is performed. - $options: (optional...
function _xmlrpc($url, $args, $options = array()) { xmlrpc_clear_error(); if (count($args) > 1) { $multicall_args = array(); foreach ($args as $method => $call) { $multicall_args[] = array('methodName' => $method, 'params' => $call); } $method = 'system.multicall'; $args = array($multicall...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4732b03fa8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_revert_form_submit/7.x
In Drupal 7, write the function `image_style_revert_form_submit($form, &$form_state)` (file modules/image/image.admin.inc) so that it does the following: Submit handler to convert an overridden style to its default.
File: modules/image/image.admin.inc
function image_style_revert_form_submit($form, &$form_state) { drupal_set_message(t('The %style style has been reverted to its defaults.', array('%style' => $form_state['image_style']['label']))); image_default_style_revert($form_state['image_style']); $form_state['redirect'] = 'admin/config/media/image-styles'; ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-473ae69d4c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/_comment_get_modes/7.x
Implement `_comment_get_modes()` in PHP for Drupal 7. Required behavior: Return an array of viewing modes for comment listings.
We can't use a global variable array because the locale system is not initialized yet when the comment module is loaded. File: modules/comment/comment.module
function _comment_get_modes() { return array( COMMENT_MODE_FLAT => t('Flat list'), COMMENT_MODE_THREADED => t('Threaded list') ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4742d467df
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.fetcher.inc/function/aggregator_aggregator_fetch/7.x
In Drupal 7, write the function `aggregator_aggregator_fetch($feed)` (file modules/aggregator/aggregator.fetcher.inc) so that it does the following: Implements hook_aggregator_fetch().
File: modules/aggregator/aggregator.fetcher.inc
function aggregator_aggregator_fetch($feed) { $feed->source_string = FALSE; // Generate conditional GET headers. $headers = array(); if ($feed->etag) { $headers['If-None-Match'] = $feed->etag; } if ($feed->modified) { $headers['If-Modified-Since'] = gmdate(DATE_RFC7231, $feed->modified); } // ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-474e9d13c0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_prepare_translation/7.x
In Drupal 7, write the function `field_attach_prepare_translation($entity_type, $entity, $langcode, $source_entity, $source_langcode)` (file modules/field/field.attach.inc) so that it does the following: Prepares an entity for translation.
This function is used to fill-in the form default values for Field API fields while performing entity translation. By default it copies all the source values in the given source language to the new entity and assigns them the target language. This is used as part of the 'per entity' translation pattern, which is imple...
function field_attach_prepare_translation($entity_type, $entity, $langcode, $source_entity, $source_langcode) { $options = array('language' => $langcode); // Copy source field values into the entity to be prepared. _field_invoke_default('prepare_translation', $entity_type, $entity, $source_entity, $source_langcod...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4759ea4193
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.api.php/function/hook_comment_view/7.x
Give me the example code for `hook_comment_view($comment, $view_mode, $langcode)` in Drupal 7. Hook description: The comment is being viewed. This hook can be used to add additional data to the comment before theming.
Parameters: - $comment: Passes in the comment the action is being performed on. - $view_mode: View mode, e.g. 'full', 'teaser'... - $langcode: The language code used for rendering. File: modules/comment/comment.api.php
function hook_comment_view($comment, $view_mode, $langcode) { // how old is the comment $comment->time_ago = time() - $comment->changed; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-47639e5210
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_json_output/7.x
In Drupal 7, write the function `drupal_json_output($var = NULL)` (file includes/common.inc) so that it does the following: Returns data in JSON format.
This function should be used for JavaScript callback functions returning data in JSON format. It sets the header for JavaScript output. Parameters: - $var: (optional) If set, the variable will be converted to JSON and output. File: includes/common.inc
function drupal_json_output($var = NULL) { // We are returning JSON, so tell the browser. drupal_add_http_header('Content-Type', 'application/json'); if (isset($var)) { echo drupal_json_encode($var); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-476ceb4482
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_menu/7.x
In Drupal 7, write the function `block_menu()` (file modules/block/block.module) so that it does the following: Implements hook_menu().
File: modules/block/block.module
function block_menu() { $default_theme = variable_get('theme_default', 'bartik'); $items['admin/structure/block'] = array( 'title' => 'Blocks', 'description' => 'Configure what block content appears in your site\'s sidebars and other regions.', 'page callback' => 'block_admin_display', 'page argumen...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-479ba3bbb9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_translate/7.x
Implement `_menu_translate(&$router_item, $map, $to_arg = FALSE)` in PHP for Drupal 7. Required behavior: Handles dynamic path translation and menu access control.
When a user arrives on a page such as node/5, this function determines what "5" corresponds to, by inspecting the page's menu path definition, node/%node. This will call node_load(5) to load the corresponding node object. It also works in reverse, to allow the display of tabs and menu items which contain these dynamic...
function _menu_translate(&$router_item, $map, $to_arg = FALSE) { if ($to_arg && !empty($router_item['to_arg_functions'])) { // Fill in missing path elements, such as the current uid. _menu_link_map_translate($map, $router_item['to_arg_functions']); } // The $path_map saves the pieces of the path as string...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-47e51e778c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_is_empty/7.x
In Drupal 7, show an example implementation for `hook_field_is_empty($item, $field)` (modules/field/field.api.php): Define what constitutes an empty item for a field type.
Parameters: - $item: An item that may or may not be empty. - $field: The field to which $item belongs. Returns: TRUE if $field's type considers $item not to contain any data; FALSE otherwise. File: modules/field/field.api.php
function hook_field_is_empty($item, $field) { if (empty($item['value']) && (string) $item['value'] !== '0') { return TRUE; } return FALSE; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-481be3f068
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_uri/7.x
Implement `user_uri($user)` in PHP for Drupal 7. Required behavior: Implements callback_entity_info_uri().
File: modules/user/user.module
function user_uri($user) { return array( 'path' => 'user/' . $user->uid, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4830dc5684
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.pages.inc/function/contact_personal_form_submit/7.x
I need the code for `contact_personal_form_submit($form, &$form_state)` in Drupal 7 (modules/contact/contact.pages.inc). It must do this: Form submission handler for contact_personal_form().
File: modules/contact/contact.pages.inc
function contact_personal_form_submit($form, &$form_state) { global $user, $language; $values = $form_state['values']; $values['sender'] = clone $user; $values['sender']->name = $values['name']; $values['sender']->mail = $values['mail']; // Save the anonymous user information to a cookie for reuse. if (...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-48352f49ce
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_date_delete_format_form/7.x
In Drupal 7, write the function `system_date_delete_format_form($form, &$form_state, $dfid)` (file modules/system/system.admin.inc) so that it does the following: Menu callback; present a form for deleting a date format.
File: modules/system/system.admin.inc
function system_date_delete_format_form($form, &$form_state, $dfid) { $form['dfid'] = array( '#type' => 'value', '#value' => $dfid, ); $format = system_get_date_format($dfid); $output = confirm_form($form, t('Are you sure you want to remove the format %format?', array('%format' => format_date(REQUE...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-486c81bf18
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_mail_alter/7.x
Give me the example code for `hook_mail_alter(&$message)` in Drupal 7. Hook description: Alter an email message created with the drupal_mail() function.
hook_mail_alter() allows modification of email messages created and sent with drupal_mail(). Usage examples include adding and/or changing message text, message fields, and message headers. Email messages sent using functions other than drupal_mail() will not invoke hook_mail_alter(). For example, a contributed module...
function hook_mail_alter(&$message) { if ($message['id'] == 'modulename_messagekey') { if (!example_notifications_optin($message['to'], $message['id'])) { // If the recipient has opted to not receive such messages, cancel // sending. $message['send'] = FALSE; return; } $message['bo...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-486dbd144c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/_menu_parents_recurse/7.x
Implement `_menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit)` in PHP for Drupal 7. Required behavior: Recursive helper function for menu_parent_options().
File: modules/menu/menu.module
function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) { foreach ($tree as $data) { if ($data['link']['depth'] > $depth_limit) { // Don't iterate through any links on this level. break; } if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >=...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4882b9fc62
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_update_field/7.x
In Drupal 7, write the function `field_update_field($field)` (file modules/field/field.crud.inc) so that it does the following: Updates a field.
Any module may forbid any update for any reason. For example, the field's storage module might forbid an update if it would change the storage schema while data for the field exists. A field type module might forbid an update if it would change existing data's semantics, or if there are external dependencies on field s...
function field_update_field($field) { // Check that the specified field exists. $prior_field = field_read_field($field['field_name']); if (empty($prior_field)) { throw new FieldException('Attempt to update a non-existent field.'); } // Use the prior field values for anything not specifically set by the n...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-48880a1e43
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_help/7.x
Give me the example code for `hook_help($path, $arg)` in Drupal 7. Hook description: Provide online user help.
By implementing hook_help(), a module can make documentation available to the user for the module as a whole, or for specific paths. Help for developers should usually be provided via function header comments in the code, or in special API example files. The page-specific help information provided by this hook appears...
function hook_help($path, $arg) { switch ($path) { // Main module help for the block module case 'admin/help#block': return '<p>' . t('Blocks are boxes of content rendered into an area, or region, of a web page. The default theme Bartik, for example, implements the regions "Sidebar first", "Sidebar seco...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-48988be758
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_usage_add/7.x
Implement `file_usage_add(stdClass $file, $module, $type, $id, $count = 1)` in PHP for Drupal 7. Required behavior: Records that a module is using a file.
This usage information will be queried during file_delete() to ensure that a file is not in use before it is physically removed from disk. Examples: - A module that associates files with nodes, so $type would be 'node' and $id would be the node's nid. Files for all revisions are stored within a single nid. - The U...
function file_usage_add(stdClass $file, $module, $type, $id, $count = 1) { db_merge('file_usage') ->key(array( 'fid' => $file->fid, 'module' => $module, 'type' => $type, 'id' => $id, )) ->fields(array('count' => $count)) ->expression('count', 'count + :count', array(':count' =>...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-489b0f52db
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_block_view/7.x
I need the code for `system_block_view($delta = '')` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_block_view().
Generate a block with a promotional link to Drupal.org and all system menu blocks. File: modules/system/system.module
function system_block_view($delta = '') { $block = array(); switch ($delta) { case 'main': $block['subject'] = NULL; $block['content'] = drupal_set_page_content(); return $block; case 'powered-by': $block['subject'] = NULL; $block['content'] = theme('system_powered_by'); ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-48aa904f06
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_init/7.x
I need the code for `locale_init()` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_init().
Initialize date formats according to the user's current locale. File: modules/locale/locale.module
function locale_init() { global $conf, $language; include_once DRUPAL_ROOT . '/includes/locale.inc'; // For each date type (e.g. long, short), get the localized date format // for the user's current language and override the default setting for it // in $conf. This should happen on all pages except the date ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-48be1defaa
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21authorize.inc/function/authorize_run_operation/7.x
In Drupal 7, write the function `authorize_run_operation($filetransfer)` (file includes/authorize.inc) so that it does the following: Runs the operation specified in $_SESSION['authorize_operation'].
Parameters: - $filetransfer: The FileTransfer object to use for running the operation. File: includes/authorize.inc
function authorize_run_operation($filetransfer) { $operation = $_SESSION['authorize_operation']; unset($_SESSION['authorize_operation']); if (!empty($operation['page_title'])) { drupal_set_title($operation['page_title']); } require_once DRUPAL_ROOT . '/' . $operation['file']; call_user_func_array($ope...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-48d89b7e20
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21unicode.inc/function/drupal_strtoupper/7.x
In Drupal 7, write the function `drupal_strtoupper($text)` (file includes/unicode.inc) so that it does the following: Uppercase a UTF-8 string.
Parameters: - $text: The string to run the operation on. Returns (string): The string in uppercase. File: includes/unicode.inc
function drupal_strtoupper($text) { global $multibyte; if ($multibyte == UNICODE_MULTIBYTE) { return mb_strtoupper($text); } else { // Use C-locale for ASCII-only uppercase $text = strtoupper($text); // Case flip Latin-1 accented letters $text = preg_replace_callback('/\xC3[\xA0-\xB6\xB8-\xB...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-48ed14ed6e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.default.inc/function/field_default_validate/7.x
I need the code for `field_default_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors)` in Drupal 7 (modules/field/field.default.inc). It must do this: Generic field validation handler.
Possible error codes: - 'field_cardinality': The number of values exceeds the field cardinality. Parameters: - $entity_type: The type of $entity. - $entity: The entity for the operation. - $field: The field structure for the operation. - $instance: The instance structure for $field on $entity's bundle. - $langcode: Th...
function field_default_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { // Filter out empty values. $items = _field_filter_items($field, $items); // Check that the number of values doesn't exceed the field cardinality. // For form submitted values, this can only happen with 'mu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-490e0257f7
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_label/7.x
In Drupal 7, write the function `entity_label($entity_type, $entity)` (file includes/common.inc) so that it does the following: Returns the label of an entity.
See the 'label callback' component of the hook_entity_info() return value for more information. Parameters: - $entity_type: The entity type; e.g., 'node' or 'user'. - $entity: The entity for which to generate the label. Returns: The entity label, or FALSE if not found. File: includes/common.inc
function entity_label($entity_type, $entity) { $label = FALSE; $info = entity_get_info($entity_type); if (isset($info['label callback']) && function_exists($info['label callback'])) { $label = $info['label callback']($entity, $entity_type); } elseif (!empty($info['entity keys']['label']) && isset($entity-...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4918484336
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/update_fetch_data_finished/7.x
Implement `update_fetch_data_finished($success, $results)` in PHP for Drupal 7. Required behavior: Implements callback_batch_finished().
Performs actions when all fetch tasks have been completed. Parameters: - $success: TRUE if the batch operation was successful; FALSE if there were errors. - $results: An associative array of results from the batch operation, including the key 'updated' which holds the total number of projects we fetched available upda...
function update_fetch_data_finished($success, $results) { if ($success) { if (!empty($results)) { if (!empty($results['updated'])) { drupal_set_message(format_plural($results['updated'], 'Checked available update data for one project.', 'Checked available update data for @count projects.')); }...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-491c335288
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_node_add_list/7.x
In Drupal 7, write the function `seven_node_add_list($variables)` (file themes/seven/template.php) so that it does the following: Display the list of available node types for node creation.
File: themes/seven/template.php
function seven_node_add_list($variables) { $content = $variables['content']; $output = ''; if ($content) { $output = '<ul class="admin-list">'; foreach ($content as $item) { $output .= '<li class="clearfix">'; $output .= '<span class="label">' . l($item['title'], $item['href'], $item['localize...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-493727b7cd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21registry.inc/function/_registry_update/7.x
I need the code for `_registry_update()` in Drupal 7 (includes/registry.inc). It must do this: Does the work for registry_update().
File: includes/registry.inc
function _registry_update() { // The registry serves as a central autoloader for all classes, including // the database query builders. However, the registry rebuild process // requires write ability to the database, which means having access to the // query builders that require the registry in order to be loa...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-49639e9818
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_url_outbound_alter/7.x
I need the code for `locale_url_outbound_alter(&$path, &$options, $original_path)` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_url_outbound_alter().
Rewrite outbound URLs with language based prefixes. File: modules/locale/locale.module
function locale_url_outbound_alter(&$path, &$options, $original_path) { // Only modify internal URLs. if (!$options['external'] && drupal_multilingual()) { static $drupal_static_fast; if (!isset($drupal_static_fast)) { $drupal_static_fast['callbacks'] = &drupal_static(__FUNCTION__); } $callbac...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-496e7a11f3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.install/function/_update_7000_user_role_grant_permissions/7.x
In Drupal 7, write the function `_update_7000_user_role_grant_permissions($rid, array $permissions, $module)` (file modules/user/user.install) so that it does the following: Utility function: grant a set of permissions to a role during update.
This function is valid for a database schema version 7000. Parameters: - $rid: The role ID. - $permissions: An array of permissions names. - $module: The name of the module defining the permissions. File: modules/user/user.install
function _update_7000_user_role_grant_permissions($rid, array $permissions, $module) { // Grant new permissions for the role. foreach ($permissions as $name) { db_merge('role_permission') ->key(array( 'rid' => $rid, 'permission' => $name, )) ->fields(array( 'module' => ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4975c82930
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_close_dialog/7.x
In Drupal 7, write the function `overlay_close_dialog($redirect = NULL, $redirect_options = array())` (file modules/overlay/overlay.module) so that it does the following: Requests that the overlay closes when the page is displayed.
Parameters: - $redirect: (optional) The path that should open in the parent window after the overlay closes. If not set, no redirect will be performed on the parent window. - $redirect_options: (optional) An associative array of options to use when generating the redirect URL. File: modules/overlay/overlay.module
function overlay_close_dialog($redirect = NULL, $redirect_options = array()) { $settings = array( 'overlayChild' => array( 'closeOverlay' => TRUE, ), ); // Tell the child window to perform the redirection when requested to. if (isset($redirect)) { $settings['overlayChild']['redirect'] = url($...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-498c4b0936
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_uninstall/7.x
I need the code for `taxonomy_uninstall()` in Drupal 7 (modules/taxonomy/taxonomy.install). It must do this: Implements hook_uninstall().
File: modules/taxonomy/taxonomy.install
function taxonomy_uninstall() { // Remove variables. variable_del('taxonomy_override_selector'); variable_del('taxonomy_terms_per_page_admin'); // Remove taxonomy_term bundles. $vocabularies = db_query("SELECT machine_name FROM {taxonomy_vocabulary}")->fetchCol(); foreach ($vocabularies as $vocabulary) { ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-498f544745
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_query_field_conditions/7.x
In Drupal 7, write the function `_field_sql_storage_query_field_conditions(EntityFieldQuery $query, SelectQuery $select_query, $conditions, $table_aliases, $column_callback)` (file modules/field/modules/field_sql_storage/field_sql_storage.module) so that it does the following: Adds field (meta) conditions to the given ...
Parameters: - $query (EntityFieldQuery): The field query object to be processed. - $select_query (SelectQuery): The SelectQuery that should get grouping conditions. - $table_aliases: An associative array of table aliases keyed by field index. - $column_callback: A callback that should return the column name to be used ...
function _field_sql_storage_query_field_conditions(EntityFieldQuery $query, SelectQuery $select_query, $conditions, $table_aliases, $column_callback) { $groups = &drupal_static(__FUNCTION__, array()); foreach ($conditions as $key => $condition) { $table_alias = $table_aliases[$key]; $field = $condition['fie...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4996413535
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_storage_delete_revision/7.x
Implement `field_sql_storage_field_storage_delete_revision($entity_type, $entity, $fields)` in PHP for Drupal 7. Required behavior: Implements hook_field_storage_delete_revision().
This function actually deletes the data from the database. File: modules/field/modules/field_sql_storage/field_sql_storage.module
function field_sql_storage_field_storage_delete_revision($entity_type, $entity, $fields) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); if (isset($vid)) { foreach ($fields as $field_id) { $field = field_info_field_by_id($field_id); $revision_name = _field_sql_storage_revisi...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4999f38655
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_preprocess_html/7.x
Implement `garland_preprocess_html(&$variables)` in PHP for Drupal 7. Required behavior: Override or insert variables into the html template.
File: themes/garland/template.php
function garland_preprocess_html(&$variables) { // Toggle fixed or fluid width. if (theme_get_setting('garland_width') == 'fluid') { $variables['classes_array'][] = 'fluid-width'; } // Add conditional CSS for IE6. drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => ar...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-49bee2942d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_page_alter/7.x
In Drupal 7, write the function `_color_page_alter(&$vars)` (file modules/color/color.module) so that it does the following: Replaces the logo with a color-altered logo.
A theme that supports the color module should call this function from its THEME_process_page() function, so that the correct logo is included when page.tpl.php is rendered. File: modules/color/color.module
function _color_page_alter(&$vars) { global $theme_key; // Override logo. $logo = variable_get('color_' . $theme_key . '_logo'); if ($logo && $vars['logo'] && preg_match('!' . $theme_key . '/logo.png$!', $vars['logo'])) { $vars['logo'] = file_create_url($logo); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-49ce42e2df
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_po/7.x
I need the code for `_locale_import_po($file, $langcode, $mode, $group = NULL)` in Drupal 7 (includes/locale.inc). It must do this: Parses Gettext Portable Object file information and inserts into database
Parameters: - $file: Drupal file object corresponding to the PO file to import. - $langcode: Language code. - $mode: Should existing translations be replaced LOCALE_IMPORT_KEEP or LOCALE_IMPORT_OVERWRITE. - $group: Text group to import PO file into (eg. 'default' for interface translations). File: includes/locale.inc
function _locale_import_po($file, $langcode, $mode, $group = NULL) { // Check if we have the language already in the database. if (!db_query("SELECT COUNT(language) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) { drupal_set_message(t('The language selected for imp...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-49d959149f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_authorized_batch_process/7.x
I need the code for `system_authorized_batch_process()` in Drupal 7 (modules/system/system.module). It must do this: Use authorize.php to run batch_process().
File: modules/system/system.module
function system_authorized_batch_process() { $finish_url = system_authorized_get_url(); $process_url = system_authorized_batch_processing_url(); batch_process($finish_url, $process_url); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-49e259b459
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_menu/7.x
In Drupal 7, write the function `translation_menu()` (file modules/translation/translation.module) so that it does the following: Implements hook_menu().
File: modules/translation/translation.module
function translation_menu() { $items = array(); $items['node/%node/translate'] = array( 'title' => 'Translate', 'page callback' => 'translation_node_overview', 'page arguments' => array(1), 'access callback' => '_translation_tab_access', 'access arguments' => array(1), 'type' => MENU_LOCAL_T...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-49eeb9ad5d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/_system_theme_settings_validate_path/7.x
Implement `_system_theme_settings_validate_path($path)` in PHP for Drupal 7. Required behavior: Helper function for the system_theme_settings form.
Attempts to validate normal system paths, paths relative to the public files directory, or stream wrapper URIs. If the given path is any of the above, returns a valid path or URI that the theme system can display. Parameters: - $path: A path relative to the Drupal root or to the public files directory, or a stream wra...
function _system_theme_settings_validate_path($path) { // Absolute local file paths are invalid. if (drupal_realpath($path) == $path) { return FALSE; } // A path relative to the Drupal root or a fully qualified URI is valid. if (is_file($path)) { return $path; } // Prepend 'public://' for relative...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-49f04161c8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_query_temporary/7.x
Implement `db_query_temporary($query, array $args = array(), array $options = array())` in PHP for Drupal 7. Required behavior: Executes a SELECT query string and saves the result set to a temporary table.
The execution of the query string happens against the active database. Parameters: - $query: The prepared SELECT statement query to run. Although it will accept both named and unnamed placeholders, named placeholders are strongly preferred as they are more self-documenting. - $args: An array of values to substitute in...
function db_query_temporary($query, array $args = array(), array $options = array()) { if (empty($options['target'])) { $options['target'] = 'default'; } return Database::getConnection($options['target'])->queryTemporary($query, $args, $options); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4a1a2c8aa7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_authentication/7.x
Implement `openid_authentication($response)` in PHP for Drupal 7. Required behavior: Authenticate a user or attempt registration.
Parameters: - $response: Response values from the OpenID Provider. File: modules/openid/openid.module
function openid_authentication($response) { $identity = $response['openid.claimed_id']; $account = user_external_load($identity); // Tries to load user account if user_external_load fails due to possibly // incompletely stored OpenID identifier in the authmap. if (!isset($account->uid) && variable_get('openi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4a1aa83fe1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_verify_assertion_return_url/7.x
I need the code for `openid_verify_assertion_return_url($service, $response)` in Drupal 7 (modules/openid/openid.module). It must do this: Verify that openid.return_to matches the current URL.
See OpenID Authentication 2.0, section 11.1. While OpenID Authentication 1.1, section 4.3 does not mandate return_to verification, the received return_to should still match these constraints. Parameters: - $service: Array describing the OpenID provider. - $response: Array of response values from the provider. Return...
function openid_verify_assertion_return_url($service, $response) { global $base_url; $return_to_parts = parse_url($response['openid.return_to']); $base_url_parts = parse_url($base_url); $current_parts = parse_url($base_url_parts['scheme'] .'://'. $base_url_parts['host'] . request_uri()); if ($return_to_par...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4a1be3c89c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_opml_validate/7.x
In Drupal 7, write the function `aggregator_form_opml_validate($form, &$form_state)` (file modules/aggregator/aggregator.admin.inc) so that it does the following: Form validation handler for aggregator_form_opml().
File: modules/aggregator/aggregator.admin.inc
function aggregator_form_opml_validate($form, &$form_state) { // If both fields are empty or filled, cancel. if (empty($form_state['values']['remote']) == empty($_FILES['files']['name']['upload'])) { form_set_error('remote', t('You must <em>either</em> upload a file or enter a URL.')); } // Validate the UR...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4a2c1886c2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_widget_info/7.x
Implement `taxonomy_field_widget_info()` in PHP for Drupal 7. Required behavior: Implements hook_field_widget_info().
File: modules/taxonomy/taxonomy.module
function taxonomy_field_widget_info() { return array( 'taxonomy_autocomplete' => array( 'label' => t('Autocomplete term widget (tagging)'), 'field types' => array('taxonomy_term_reference'), 'settings' => array( 'size' => 60, 'autocomplete_path' => 'taxonomy/autocomplete', ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4a477bd594
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21update.inc/function/update_fix_d7_block_deltas/7.x
In Drupal 7, write the function `update_fix_d7_block_deltas(&$sandbox, $renamed_deltas, $moved_deltas)` (file includes/update.inc) so that it does the following: A helper function that modules can use to assist with the transformation from numeric block deltas to string block deltas during the 6.x -> 7.x upgrade.
Parameters: - $sandbox: An array holding data for the batch process. - $renamed_deltas: An associative array. Keys are module names, values an associative array mapping the old block deltas to the new block deltas for the module. Example: @code $renamed_deltas = array( 'mymodule' => array( 0 => 'mymodule-block-1', 1 =>...
function update_fix_d7_block_deltas(&$sandbox, $renamed_deltas, $moved_deltas) { // Loop through each block and make changes to the block tables. // Only run this the first time through the batch update. if (!isset($sandbox['progress'])) { // Determine whether to use the old or new block table names. $blo...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4a7607f9c1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_user_delete/7.x
In Drupal 7, write the function `statistics_user_delete($account)` (file modules/statistics/statistics.module) so that it does the following: Implements hook_user_delete().
File: modules/statistics/statistics.module
function statistics_user_delete($account) { db_delete('accesslog') ->condition('uid', $account->uid) ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4a815b14a6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_install/7.x
Implement `forum_install()` in PHP for Drupal 7. Required behavior: Implements hook_install().
File: modules/forum/forum.install
function forum_install() { // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module. db_update('system') ->fields(array('weight' => 1)) ->condition('name', 'forum') ->execute(); // Forum topics are published by default, but do not have any other default // options set (fo...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4a83c6331c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_default_value_widget/7.x
I need the code for `field_ui_default_value_widget($field, $instance, &$form, &$form_state)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Builds the default value fieldset for a given field instance.
File: modules/field_ui/field_ui.admin.inc
function field_ui_default_value_widget($field, $instance, &$form, &$form_state) { $field_name = $field['field_name']; $element = array( '#type' => 'fieldset', '#title' => t('Default value'), '#collapsible' => FALSE, '#tree' => TRUE, '#description' => t('The default value for this field, used wh...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4a8787a9b4
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21unicode.inc/function/_mime_header_decode/7.x
In Drupal 7, write the function `_mime_header_decode($matches)` (file includes/unicode.inc) so that it does the following: Decodes encoded header data passed from mime_header_decode().
Callback for preg_replace_callback() within mime_header_decode(). Parameters: - $matches: The array of matches from preg_replace_callback(). Returns (string): The mime-decoded string. File: includes/unicode.inc
function _mime_header_decode($matches) { // Regexp groups: // 1: Character set name // 2: Escaping method (Q or B) // 3: Encoded data $data = ($matches[2] == 'B') ? base64_decode($matches[3]) : str_replace('_', ' ', quoted_printable_decode($matches[3])); if (strtolower($matches[1]) != 'utf-8') { $data =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4a95b7ed22
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_switch_submit/7.x
Implement `shortcut_set_switch_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Submit handler for shortcut_set_switch().
File: modules/shortcut/shortcut.admin.inc
function shortcut_set_switch_submit($form, &$form_state) { global $user; $account = $form_state['values']['account']; if ($form_state['values']['set'] == 'new') { // Save a new shortcut set with links copied from the user's default set. $default_set = shortcut_default_set($account); $set = (object) a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4aa6e61b85
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_file_delete/7.x
Implement `user_file_delete($file)` in PHP for Drupal 7. Required behavior: Implements hook_file_delete().
File: modules/user/user.module
function user_file_delete($file) { // Remove any references to the file. db_update('users') ->fields(array('picture' => 0)) ->condition('picture', $file->fid) ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4abc5f10ea
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_access_needs_rebuild/7.x
I need the code for `node_access_needs_rebuild($rebuild = NULL)` in Drupal 7 (modules/node/node.module). It must do this: Flags or unflags the node access grants for rebuilding.
If the argument isn't specified, the current value of the flag is returned. When the flag is set, a message is displayed to users with 'access administration pages' permission, pointing to the 'rebuild' confirm form. This can be used as an alternative to direct node_access_rebuild calls, allowing administrators to deci...
function node_access_needs_rebuild($rebuild = NULL) { if (!isset($rebuild)) { return variable_get('node_access_needs_rebuild', FALSE); } elseif ($rebuild) { variable_set('node_access_needs_rebuild', TRUE); } else { variable_del('node_access_needs_rebuild'); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4ac1849416
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21module.inc/function/module_invoke/7.x
I need the code for `module_invoke($module, $hook)` in Drupal 7 (includes/module.inc). It must do this: Invokes a hook in a particular module.
All arguments are passed by value. Use drupal_alter() if you need to pass arguments by reference. Parameters: - $module: The name of the module (without the .module extension). - $hook: The name of the hook to invoke. Returns: The return value of the hook implementation. File: includes/module.inc
function module_invoke($module, $hook) { $args = func_get_args(); // Remove $module and $hook from the arguments. unset($args[0], $args[1]); if (module_hook($module, $hook)) { return call_user_func_array($module . '_' . $hook, $args); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4aee66b6d3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_build_node_index/7.x
Implement `taxonomy_build_node_index($node)` in PHP for Drupal 7. Required behavior: Builds and inserts taxonomy index entries for a given node.
The index lists all terms that are related to a given node entity, and is therefore maintained at the entity level. Parameters: - $node: The node object. File: modules/taxonomy/taxonomy.module
function taxonomy_build_node_index($node) { // We maintain a denormalized table of term/node relationships, containing // only data for current, published nodes. $status = NULL; if (variable_get('taxonomy_maintain_index_table', TRUE)) { // If a node property is not set in the node object when node_save() is...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4af110a0e6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_item_delete_form_submit/7.x
In Drupal 7, write the function `menu_item_delete_form_submit($form, &$form_state)` (file modules/menu/menu.admin.inc) so that it does the following: Process menu delete form submissions.
File: modules/menu/menu.admin.inc
function menu_item_delete_form_submit($form, &$form_state) { $item = $form['#item']; menu_link_delete($item['mlid']); $t_args = array('%title' => $item['link_title']); drupal_set_message(t('The menu link %title has been deleted.', $t_args)); watchdog('menu', 'Deleted menu link %title.', $t_args, WATCHDOG_NOTI...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4b59950b3d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_update_field/7.x
Give me the example code for `hook_field_storage_update_field($field, $prior_field, $has_data)` in Drupal 7. Hook description: Update the storage information for a field.
This is invoked on the field's storage module from field_update_field(), before the new field information is saved to the database. The field storage module should update its storage tables to agree with the new field information. If there is a problem, the field storage module should throw an exception. Parameters: -...
function hook_field_storage_update_field($field, $prior_field, $has_data) { if (!$has_data) { // There is no data. Re-create the tables completely. $prior_schema = _field_sql_storage_schema($prior_field); foreach ($prior_schema as $name => $table) { db_drop_table($name, $table); } $schema = ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4b6f25a88f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_url_settings/7.x
In Drupal 7, write the function `_filter_url_settings($form, &$form_state, $filter, $format, $defaults)` (file modules/filter/filter.module) so that it does the following: Implements callback_filter_settings().
Provides settings for the URL filter. File: modules/filter/filter.module
function _filter_url_settings($form, &$form_state, $filter, $format, $defaults) { $filter->settings += $defaults; $settings['filter_url_length'] = array( '#type' => 'textfield', '#title' => t('Maximum link text length'), '#default_value' => $filter->settings['filter_url_length'], '#size' => 5, ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4b78656d57
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_process_page/7.x
I need the code for `template_process_page(&$variables)` in Drupal 7 (includes/theme.inc). It must do this: Process variables for page.tpl.php
Perform final addition of variables before passing them into the template. To customize these variables, simply set them in an earlier step. File: includes/theme.inc
function template_process_page(&$variables) { if (!isset($variables['breadcrumb'])) { // Build the breadcrumb last, so as to increase the chance of being able to // re-use the cache of an already rendered menu containing the active link // for the current page. // @see menu_tree_page_data() $varia...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4baaabbc0d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_expression_insert/7.x
I need the code for `search_expression_insert($expression, $option, $value = NULL)` in Drupal 7 (modules/search/search.module). It must do this: Adds a module-specific search option to a search expression.
Search options are added using search_expression_insert(), and retrieved using search_expression_extract(). They take the form option:value, and are added to the ordinary keywords in the search expression. Parameters: - $expression: The search expression to add to. - $option: The name of the option to add to the searc...
function search_expression_insert($expression, $option, $value = NULL) { // Remove any previous values stored with $option. $expression = trim(preg_replace('/(^| )' . $option . ':[^ ]*/i', '', $expression)); // Set new value, if provided. if (isset($value)) { $expression .= ' ' . $option . ':' . trim($valu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4bb6e0416f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_confirm_delete_submit/7.x
Implement `forum_confirm_delete_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for forum_confirm_delete().
File: modules/forum/forum.admin.inc
function forum_confirm_delete_submit($form, &$form_state) { taxonomy_term_delete($form_state['values']['tid']); drupal_set_message(t('The forum %term and all sub-forums have been deleted.', array('%term' => $form_state['values']['name']))); watchdog('content', 'forum: deleted %term and all its sub-forums.', array...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4bc93741d8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_node_update/7.x
I need the code for `path_node_update($node)` in Drupal 7 (modules/path/path.module). It must do this: Implements hook_node_update().
File: modules/path/path.module
function path_node_update($node) { if (isset($node->path)) { $path = $node->path; $path['alias'] = isset($path['alias']) ? trim($path['alias']) : ''; // Delete old alias if user erased it. if (!empty($path['pid']) && !$path['alias']) { path_delete($path['pid']); } path_node_insert($node)...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4bd43c0c47
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_permission/7.x
Implement `announcements_feed_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().
File: modules/announcements_feed/announcements_feed.module
function announcements_feed_permission() { return array( 'access announcements' => array( 'title' => t('View official announcements related to Drupal'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4bd459dabd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_move_uploaded_file/7.x
In Drupal 7, write the function `drupal_move_uploaded_file($filename, $uri)` (file includes/file.inc) so that it does the following: Moves an uploaded file to a new location.
PHP's move_uploaded_file() does not properly support streams if safe_mode or open_basedir are enabled, so this function fills that gap. Compatibility: normal paths and stream wrappers. Parameters: - $filename: The filename of the uploaded file. - $uri: A string containing the destination URI of the file. Returns: TR...
function drupal_move_uploaded_file($filename, $uri) { $result = @move_uploaded_file($filename, $uri); // PHP's move_uploaded_file() does not properly support streams if safe_mode // or open_basedir are enabled so if the move failed, try finding a real path // and retry the move operation. if (!$result) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4bde488d97
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_cancel_url/7.x
In Drupal 7, write the function `user_cancel_url($account)` (file modules/user/user.module) so that it does the following: Generates a URL to confirm an account cancellation request.
Parameters: - $account (object): The user account object, which must contain at least the following properties: - uid: The user ID number. - pass: The hashed user password string. - login: The UNIX timestamp of the user's last login. Returns: A unique URL that may be used to confirm the cancellation of the user accoun...
function user_cancel_url($account) { $timestamp = REQUEST_TIME; return url("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid, $account->mail), array('absolute' => TRUE)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4bdebe8dcb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_resize_form/7.x
In Drupal 7, write the function `image_resize_form($data)` (file modules/image/image.admin.inc) so that it does the following: Form structure for the image resize form.
Note that this is not a complete form, it only contains the portion of the form for configuring the resize options. Therefore it does not not need to include metadata about the effect, nor a submit button. Parameters: - $data: The current configuration for this resize effect. File: modules/image/image.admin.inc
function image_resize_form($data) { $form['width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => isset($data['width']) ? $data['width'] : '', '#field_suffix' => ' ' . t('pixels'), '#required' => TRUE, '#size' => 10, '#element_validate' => array('image_effect_...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4be046f6f1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/simpletest_result_status_image/7.x
Implement `simpletest_result_status_image($status)` in PHP for Drupal 7. Required behavior: Get the appropriate image for the status.
Parameters: - $status: Status string, either: pass, fail, exception. Returns: HTML image or false. File: modules/simpletest/simpletest.pages.inc
function simpletest_result_status_image($status) { // $map does not use drupal_static() as its value never changes. static $map; if (!isset($map)) { $map = array( 'pass' => theme('image', array('path' => 'misc/watchdog-ok.png', 'width' => 18, 'height' => 18, 'alt' => t('Pass'))), 'fail' => theme(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4be08a73b6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_settings_form/7.x
I need the code for `system_settings_form($form)` in Drupal 7 (modules/system/system.module). It must do this: Sets up a form to save information automatically.
This function adds a submit handler and a submit button to a form array. The submit function saves all the data in the form, using variable_set(), to variables named the same as the keys in the form array. Note that this means you should normally prefix your form array keys with your module name, so that they are uniqu...
function system_settings_form($form) { $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); if (!empty($_POST) && form_get_errors()) { drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); }...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4be8c0ddba
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_unpublish_by_keyword_action/7.x
Implement `node_unpublish_by_keyword_action($node, $context)` in PHP for Drupal 7. Required behavior: Unpublishes a node containing certain keywords.
Parameters: - $node: A node object to modify. - $context: Array with the following elements: - 'keywords': Array of keywords. If any keyword is present in the rendered node, the node's status flag is set to unpublished. File: modules/node/node.module
function node_unpublish_by_keyword_action($node, $context) { foreach ($context['keywords'] as $keyword) { $elements = node_view(clone $node); if (strpos(drupal_render($elements), $keyword) !== FALSE || strpos($node->title, $keyword) !== FALSE) { $node->status = NODE_NOT_PUBLISHED; watchdog('action...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4c0f1aca7a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7006/7.x
I need the code for `user_update_7006(&$sandbox)` in Drupal 7 (modules/user/user.install). It must do this: Add module data to {role_permission}.
File: modules/user/user.install
function user_update_7006(&$sandbox) { $module_field = array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => "The module declaring the permission.", ); // Check that the field hasn't been updated in an aborted run of this // update. if (!db_fiel...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4c18b9f3d4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_action_info/7.x
I need the code for `user_action_info()` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_action_info().
File: modules/user/user.module
function user_action_info() { return array( 'user_block_user_action' => array( 'label' => t('Block current user'), 'type' => 'user', 'configurable' => FALSE, 'triggers' => array('any'), ), 'user_unblock_user_action' => array( 'label' => t('Unblock current user'), 'type'...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4c217555d6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/theme_simpletest_test_table/7.x
In Drupal 7, write the function `theme_simpletest_test_table($variables)` (file modules/simpletest/simpletest.pages.inc) so that it does the following: Returns HTML for a test list generated by simpletest_test_form() into a table.
Parameters: - $variables: An associative array containing: - table: A render element representing the table. File: modules/simpletest/simpletest.pages.inc
function theme_simpletest_test_table($variables) { $table = $variables['table']; drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css'); drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js'); drupal_add_js('misc/tableselect.js'); // Create header for test selection t...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4c3687423a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7017/7.x
I need the code for `user_update_7017()` in Drupal 7 (modules/user/user.install). It must do this: Update email templates to use new tokens.
This function upgrades customized email templates from the old !token format to the new core tokens format. Additionally, in Drupal 7 we no longer e-mail plain text passwords to users, and there is no token for a plain text password in the new token system. Therefore, it also modifies any saved templates using the old ...
function user_update_7017() { $message = ''; $tokens = array( '!site' => '[site:name]', '!username' => '[user:name]', '!mailto' => '[user:mail]', '!login_uri' => '[site:login-url]', '!uri_brief' => '[site:url-brief]', '!edit_uri' => '[user:edit-url]', '!login_url' => '[user:one-time-log...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4c57317356
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/arg/7.x
In Drupal 7, write the function `arg($index = NULL, $path = NULL)` (file includes/bootstrap.inc) so that it does the following: Returns a component of the current Drupal path.
When viewing a page at the path "admin/structure/types", for example, arg(0) returns "admin", arg(1) returns "structure", and arg(2) returns "types". Avoid use of this function where possible, as resulting code is hard to read. In menu callback functions, attempt to use named arguments. See the explanation in menu.inc...
function arg($index = NULL, $path = NULL) { // Even though $arguments doesn't need to be resettable for any functional // reasons (the result of explode() does not depend on any run-time // information), it should be resettable anyway in case a module needs to // free up the memory used by it. // Use the adva...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4c6d9959be
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_update_7005/7.x
Implement `locale_update_7005()` in PHP for Drupal 7. Required behavior: Increase {locales_languages}.formula column's length.
File: modules/locale/locale.install
function locale_update_7005() { db_change_field('languages', 'formula', 'formula', array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'Plural formula in PHP code to evaluate to get plural indexes.', )); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4c76b17f04
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_link/7.x
In Drupal 7, write the function `theme_menu_link(array $variables)` (file includes/menu.inc) so that it does the following: Returns HTML for a menu link and submenu.
Parameters: - $variables: An associative array containing: - element: Structured array data for a menu link. File: includes/menu.inc
function theme_menu_link(array $variables) { $element = $variables['element']; $sub_menu = ''; if ($element['#below']) { $sub_menu = drupal_render($element['#below']); } $output = l($element['#title'], $element['#href'], $element['#localized_options']); return '<li' . drupal_attributes($element['#attri...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4c7ebed149
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_form_node_form_alter/7.x
In Drupal 7, write the function `locale_form_node_form_alter(&$form, &$form_state)` (file modules/locale/locale.module) so that it does the following: Implements hook_form_BASE_FORM_ID_alter().
File: modules/locale/locale.module
function locale_form_node_form_alter(&$form, &$form_state) { if (isset($form['#node']->type) && locale_multilingual_node_type($form['#node']->type)) { $form['language'] = array( '#type' => 'select', '#title' => t('Language'), '#default_value' => (isset($form['#node']->language) ? $form['#node']-...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4c94f8fc0a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_block_configure/7.x
Implement `user_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().
File: modules/user/user.module
function user_block_configure($delta = '') { global $user; switch ($delta) { case 'new': $form['user_block_whois_new_count'] = array( '#type' => 'select', '#title' => t('Number of users to display'), '#default_value' => variable_get('user_block_whois_new_count', 5), '#opti...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4cb1d3b1da
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_send_email_action_submit/7.x
I need the code for `system_send_email_action_submit($form, $form_state)` in Drupal 7 (modules/system/system.module). It must do this: Process system_send_email_action form submissions.
File: modules/system/system.module
function system_send_email_action_submit($form, $form_state) { $form_values = $form_state['values']; // Process the HTML form to store configuration. The keyed array that // we return will be serialized to the database. $params = array( 'recipient' => $form_values['recipient'], 'subject' => $form_valu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4cbab091e7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_block_info/7.x
In Drupal 7, write the function `node_block_info()` (file modules/node/node.module) so that it does the following: Implements hook_block_info().
File: modules/node/node.module
function node_block_info() { $blocks['syndicate']['info'] = t('Syndicate'); // Not worth caching. $blocks['syndicate']['cache'] = DRUPAL_NO_CACHE; $blocks['recent']['info'] = t('Recent content'); $blocks['recent']['properties']['administrative'] = TRUE; return $blocks; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4cc0da2d0b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.tokens.inc/function/statistics_tokens/7.x
I need the code for `statistics_tokens($type, $tokens, array $data = array(), array $options = array())` in Drupal 7 (modules/statistics/statistics.tokens.inc). It must do this: Implements hook_tokens().
File: modules/statistics/statistics.tokens.inc
function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) { $url_options = array('absolute' => TRUE); $replacements = array(); if ($type == 'node' & !empty($data['node'])) { $node = $data['node']; foreach ($tokens as $name => $original) { if ($name == 'total-count...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4cc11cbfd1
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_from_session/7.x
In Drupal 7, write the function `locale_language_from_session($languages)` (file includes/locale.inc) so that it does the following: Identify language from a request/session parameter.
Parameters: - $languages: An array of valid language objects. Returns: A valid language code on success, FALSE otherwise. File: includes/locale.inc
function locale_language_from_session($languages) { $param = variable_get('locale_language_negotiation_session_param', 'language'); // Request parameter: we need to update the session parameter only if we have // an authenticated user. if (isset($_GET[$param]) && isset($languages[$langcode = $_GET[$param]])) {...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4cc6a17998
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_shutdown_function/7.x
In Drupal 7, write the function `_drupal_shutdown_function()` (file includes/bootstrap.inc) so that it does the following: Executes registered shutdown functions.
File: includes/bootstrap.inc
function _drupal_shutdown_function() { $callbacks = &drupal_register_shutdown_function(); // Set the CWD to DRUPAL_ROOT as it is not guaranteed to be the same as it // was in the normal context of execution. chdir(DRUPAL_ROOT); try { // Manually iterate over the array instead of using a foreach loop. ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4cc93841c6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_access_rebuild/7.x
In Drupal 7, write the function `node_access_rebuild($batch_mode = FALSE)` (file modules/node/node.module) so that it does the following: Rebuilds the node access database.
This is occasionally needed by modules that make system-wide changes to access levels. When the rebuild is required by an admin-triggered action (e.g module settings form), calling node_access_needs_rebuild(TRUE) instead of node_access_rebuild() lets the user perform his changes and actually rebuild only once he is don...
function node_access_rebuild($batch_mode = FALSE) { db_delete('node_access')->execute(); // Only recalculate if the site is using a node_access module. if (count(module_implements('node_grants'))) { if ($batch_mode) { $batch = array( 'title' => t('Rebuilding content access permissions'), ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4ce4d0010c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_formats/7.x
In Drupal 7, write the function `filter_formats($account = NULL)` (file modules/filter/filter.module) so that it does the following: Retrieves a list of text formats, ordered by weight.
Parameters: - $account: (optional) If provided, only those formats that are allowed for this user account will be returned. All formats will be returned otherwise. Defaults to NULL. Returns: An array of text format objects, keyed by the format ID and ordered by weight. File: modules/filter/filter.module
function filter_formats($account = NULL) { global $language; $formats = &drupal_static(__FUNCTION__, array()); // All available formats are cached for performance. if (!isset($formats['all'])) { if ($cache = cache_get("filter_formats:{$language->language}")) { $formats['all'] = $cache->data; } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4ced2d9cda
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_pack/7.x
I need the code for `_color_pack($rgb, $normalize = FALSE)` in Drupal 7 (modules/color/color.module). It must do this: Converts an RGB triplet to a hex color.
File: modules/color/color.module
function _color_pack($rgb, $normalize = FALSE) { $out = 0; foreach ($rgb as $k => $v) { $out |= (((int) ($v * ($normalize ? 255 : 1))) << (16 - $k * 8)); } return '#' . str_pad(dechex($out), 6, 0, STR_PAD_LEFT); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4ced455611
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_actions_delete/7.x
In Drupal 7, show an example implementation for `hook_actions_delete($aid)` (modules/system/system.api.php): Executes code after an action is deleted.
Parameters: - $aid: The action ID. File: modules/system/system.api.php
function hook_actions_delete($aid) { db_delete('actions_assignments') ->condition('aid', $aid) ->execute(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4d0076f222
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/theme_taxonomy_overview_vocabularies/7.x
I need the code for `theme_taxonomy_overview_vocabularies($variables)` in Drupal 7 (modules/taxonomy/taxonomy.admin.inc). It must do this: Returns HTML for the vocabulary overview form as a sortable list of vocabularies.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/taxonomy/taxonomy.admin.inc
function theme_taxonomy_overview_vocabularies($variables) { $form = $variables['form']; $rows = array(); foreach (element_children($form) as $key) { if (isset($form[$key]['name'])) { $vocabulary = &$form[$key]; $row = array(); $row[] = drupal_render($vocabulary['name']); if (isset($...
[ "code-task", "function" ]
2026-09-30T00:00:00