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-85c715a45d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_router/7.x
In Drupal 7, write the function `menu_get_router()` (file includes/menu.inc) so that it does the following: Gets the menu router.
File: includes/menu.inc
function menu_get_router() { // Check first if we have it in memory already. $menu = _menu_router_cache(); if (empty($menu)) { list($menu, $masks) = menu_router_build(); } return $menu; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-85cbff06c2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_clear_cache_submit/7.x
In Drupal 7, write the function `system_clear_cache_submit($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Submit callback; clear system caches.
File: modules/system/system.admin.inc
function system_clear_cache_submit($form, &$form_state) { drupal_flush_all_caches(); drupal_set_message(t('Caches cleared.')); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-85cc3af85d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_theme/7.x
Implement `menu_theme()` in PHP for Drupal 7. Required behavior: Implements hook_theme().
File: modules/menu/menu.module
function menu_theme() { return array( 'menu_overview_form' => array( 'file' => 'menu.admin.inc', 'render element' => 'form', ), 'menu_admin_overview' => array( 'file' => 'menu.admin.inc', 'variables' => array('title' => NULL, 'name' => NULL, 'description' => NULL), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-85d83bd4c0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_cache_reset/7.x
In Drupal 7, write the function `node_type_cache_reset()` (file modules/node/node.module) so that it does the following: Clears the node type cache.
File: modules/node/node.module
function node_type_cache_reset() { cache_clear_all('node_types:', 'cache', TRUE); drupal_static_reset('_node_types_build'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-85de8f32a8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_form_alter/7.x
Implement `profile_form_alter(&$form, &$form_state, $form_id)` in PHP for Drupal 7. Required behavior: Implements hook_form_alter().
File: modules/profile/profile.module
function profile_form_alter(&$form, &$form_state, $form_id) { if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) { return; } $form['#validate'][] = 'profile_user_form_validate'; $account = $form['#user']; $result = _profile_get_fields($form['#user_category'], $form['#user_category...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-85f01e897a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_is_empty/7.x
Implement `taxonomy_field_is_empty($item, $field)` in PHP for Drupal 7. Required behavior: Implements hook_field_is_empty().
File: modules/taxonomy/taxonomy.module
function taxonomy_field_is_empty($item, $field) { if (!is_array($item) || (empty($item['tid']) && (string) $item['tid'] !== '0')) { return TRUE; } return FALSE; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-85fc718e48
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_view/7.x
In Drupal 7, show an example implementation for `hook_block_view($delta = '')` (modules/block/block.api.php): Return a rendered or renderable view of a block.
Parameters: - $delta: Which block to render. This is a unique identifier for the block within the module, defined in hook_block_info(). Returns: Either an empty array so the block will not be shown or an array containing the following elements: - subject: The default localized title of the block. If the block does not...
function hook_block_view($delta = '') { // This example is adapted from node.module. $block = array(); switch ($delta) { case 'syndicate': $block['subject'] = t('Syndicate'); $block['content'] = array( '#theme' => 'feed_icon', '#url' => 'rss.xml', '#title' => t('Syndicate'...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-86049a9a90
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.api.php/function/hook_path_update/7.x
Give me the example code for `hook_path_update($path)` in Drupal 7. Hook description: Respond to a path being updated.
Parameters: - $path: An associative array containing the following keys: - source: The internal system path. - alias: The URL alias. - pid: Unique path alias identifier. - language: The language of the alias. File: modules/path/path.api.php
function hook_path_update($path) { db_update('mytable') ->fields(array('alias' => $path['alias'])) ->condition('pid', $path['pid']) ->execute(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-862d13b394
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_user_dismiss_message/7.x
I need the code for `overlay_user_dismiss_message()` in Drupal 7 (modules/overlay/overlay.module). It must do this: Page callback: Dismisses the overlay accessibility message for this user.
Returns: A render array for a page containing a list of content. File: modules/overlay/overlay.module
function overlay_user_dismiss_message() { global $user; // It's unlikely, but possible that "access overlay" permission is granted to // the anonymous role. In this case, we do not display the message to disable // the overlay, so there is nothing to dismiss. Also, protect against // cross-site request forger...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-86542eed14
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_update_form_submit/7.x
Implement `update_manager_update_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for update_manager_update_form().
Sets up a batch that downloads, extracts, and verifies the selected releases. File: modules/update/update.manager.inc
function update_manager_update_form_submit($form, &$form_state) { $projects = array(); foreach (array('projects', 'disabled_projects') as $type) { if (!empty($form_state['values'][$type])) { $projects = array_merge($projects, array_keys(array_filter($form_state['values'][$type]))); } } $operations...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-865a635559
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_modules_uninstalled/7.x
Implement `node_modules_uninstalled($modules)` in PHP for Drupal 7. Required behavior: Implements hook_modules_uninstalled().
Cleanup {block_node_type} table from modules' blocks. File: modules/node/node.module
function node_modules_uninstalled($modules) { db_delete('block_node_type') ->condition('module', $modules, 'IN') ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-86638fd4d5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_cancel/7.x
In Drupal 7, show an example implementation for `hook_user_cancel($edit, $account, $method)` (modules/user/user.api.php): Act on user account cancellations.
This hook is invoked from user_cancel() before a user account is canceled. Depending on the account cancellation method, the module should either do nothing, unpublish content, or anonymize content. See user_cancel_methods() for the list of default account cancellation methods provided by User module. Modules may add f...
function hook_user_cancel($edit, $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': // Unpublish nodes (current revisions). module_load_include('inc', 'node', 'node.admin'); $nodes = db_select('node', 'n') ->fields('n', array('nid')) ->condition('uid', $a...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-8664d8d516
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.install/function/block_schema/7.x
I need the code for `block_schema()` in Drupal 7 (modules/block/block.install). It must do this: Implements hook_schema().
File: modules/block/block.install
function block_schema() { $schema['block'] = array( 'description' => 'Stores block settings, such as region and visibility settings.', 'fields' => array( 'bid' => array( 'type' => 'serial', 'not null' => TRUE, 'description' => 'Primary Key: Unique block ID.', ), 'modu...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-86721fc878
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_update/7.x
Give me the example code for `hook_field_update($entity_type, $entity, $field, $instance, $langcode, &$items)` in Drupal 7. Hook description: Define custom update behavior for this module's field data.
This hook is invoked from field_attach_update() on the module that defines a field, during the process of updating an entity object (node, taxonomy term, etc.). It is invoked just before the data for this field on the particular entity object is updated into field storage. Only field modules that are storing or trackin...
function hook_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node') { $first_call = &drupal_static(__FUNCTION__, array()); // We don't maintain data fo...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-867bcffc57
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21content_types.inc/function/node_overview_types/7.x
In Drupal 7, write the function `node_overview_types()` (file modules/node/content_types.inc) so that it does the following: Displays the content type admin overview page.
File: modules/node/content_types.inc
function node_overview_types() { $types = node_type_get_types(); $names = node_type_get_names(); $field_ui = module_exists('field_ui') && user_access('administer fields'); $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => $field_ui ? '4' : '2')); $rows = array(); foreach ($names as $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-867f106bc3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.install/function/trigger_update_7001/7.x
Implement `trigger_update_7001()` in PHP for Drupal 7. Required behavior: Increase the length of the "hook" field to 78 characters.
This is a separate function for those who ran an older version of trigger_update_7000() that did not do this. File: modules/trigger/trigger.install
function trigger_update_7001() { db_drop_primary_key('trigger_assignments'); db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.', ), arra...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8690d94384
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_translated_menu_link_alter/7.x
I need the code for `user_translated_menu_link_alter(&$link)` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_translated_menu_link_alter().
File: modules/user/user.module
function user_translated_menu_link_alter(&$link) { // Hide the "User account" link for anonymous users. if ($link['link_path'] == 'user' && $link['module'] == 'system' && !$GLOBALS['user']->uid) { $link['hidden'] = 1; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-86965b5bef
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_get_cache/7.x
I need the code for `form_get_cache($form_build_id, &$form_state)` in Drupal 7 (includes/form.inc). It must do this: Fetches a form from cache.
File: includes/form.inc
function form_get_cache($form_build_id, &$form_state) { if ($cached = cache_get('form_' . $form_build_id, 'cache_form')) { $form = $cached->data; global $user; if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && !$user->uid)) { if ($c...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-869e09a826
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_exit/7.x
Give me the example code for `hook_exit($destination = NULL)` in Drupal 7. Hook description: Perform cleanup tasks.
This hook is run at the end of most regular page requests. It is often used for page logging and specialized cleanup. This hook MUST NOT print anything because by the time it runs the response is already sent to the browser. Only use this hook if your code must run even for cached page views. If you have code which mu...
function hook_exit($destination = NULL) { db_update('counter') ->expression('hits', 'hits + 1') ->condition('type', 1) ->execute(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-86a6cb098b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_process_maintenance_page/7.x
Implement `template_process_maintenance_page(&$variables)` in PHP for Drupal 7. Required behavior: Theme process function for theme_maintenance_field().
The variables array generated here is a mirror of template_process_html(). This processor will run its course when theme_maintenance_page() is invoked. File: includes/theme.inc
function template_process_maintenance_page(&$variables) { $variables['head'] = drupal_get_html_head(); $variables['css'] = drupal_add_css(); $variables['styles'] = drupal_get_css(); $variables['scripts'] = drupal_get_js(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-86b2046b50
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_form_node_type_form_alter/7.x
Implement `menu_form_node_type_form_alter(&$form, $form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter().
Adds menu options to the node type form. File: modules/menu/menu.module
function menu_form_node_type_form_alter(&$form, $form_state) { $menu_options = menu_get_menus(); $type = $form['#node_type']; $form['menu'] = array( '#type' => 'fieldset', '#title' => t('Menu settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#attached' => array( 'js' => array(dr...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-86d92ef2a9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_process_form/7.x
In Drupal 7, write the function `ajax_process_form($element, &$form_state)` (file includes/ajax.inc) so that it does the following: Form element processing handler for the #ajax form property.
Parameters: - $element: An associative array containing the properties of the element. Returns: The processed element. File: includes/ajax.inc
function ajax_process_form($element, &$form_state) { $element = ajax_pre_render_element($element); if (!empty($element['#ajax_processed'])) { $form_state['cache'] = TRUE; } return $element; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-86dd02d659
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.install/function/contact_install/7.x
In Drupal 7, write the function `contact_install()` (file modules/contact/contact.install) so that it does the following: Implements hook_install().
File: modules/contact/contact.install
function contact_install() { // Insert a default contact category. db_insert('contact') ->fields(array( 'category' => 'Website feedback', 'recipients' => variable_get('site_mail', ini_get('sendmail_from')), 'selected' => 1, 'reply' => '', )) ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-86e261c274
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_add_inline/7.x
Implement `shortcut_link_add_inline($shortcut_set)` in PHP for Drupal 7. Required behavior: Menu page callback: creates a new link in the provided shortcut set.
After completion, redirects the user back to where they came from. Parameters: - $shortcut_set: Returned from shortcut_set_load(). File: modules/shortcut/shortcut.admin.inc
function shortcut_link_add_inline($shortcut_set) { if (isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'shortcut-add-link') && shortcut_valid_link($_GET['link'])) { $item = menu_get_item($_GET['link']); $title = ($item && $item['title']) ? $item['title'] : $_GET['name']; $link = array(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-86f51d6d48
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_load/7.x
Implement `taxonomy_term_load($tid)` in PHP for Drupal 7. Required behavior: Return the term object matching a term ID.
Parameters: - $tid: A term's ID Returns: A taxonomy term object, or FALSE if the term was not found. Results are statically cached. File: modules/taxonomy/taxonomy.module
function taxonomy_term_load($tid) { if (!is_numeric($tid)) { return FALSE; } $term = taxonomy_term_load_multiple(array($tid), array()); return $term ? $term[$tid] : FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-870f48f1e5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7053/7.x
Implement `system_update_7053()` in PHP for Drupal 7. Required behavior: Upgrade standard blocks and menus.
File: modules/system/system.install
function system_update_7053() { if (db_table_exists('menu_custom')) { // Create the same menus as in menu_install(). db_insert('menu_custom') ->fields(array('menu_name' => 'user-menu', 'title' => 'User Menu', 'description' => "The <em>User</em> menu contains links related to the user's account, as well ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8711d78c76
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_array_nested_key_exists/7.x
In Drupal 7, write the function `drupal_array_nested_key_exists(array $array, array $parents)` (file includes/common.inc) so that it does the following: Determines whether a nested array contains the requested keys.
This helper function should be used when the depth of the array element to be checked may vary (that is, the number of parent keys is variable). See drupal_array_set_nested_value() for details. It is primarily used for form structures and renderable arrays. If it is required to also get the value of the checked nested...
function drupal_array_nested_key_exists(array $array, array $parents) { // Although this function is similar to PHP's array_key_exists(), its // arguments should be consistent with drupal_array_get_nested_value(). $key_exists = NULL; drupal_array_get_nested_value($array, $parents, $key_exists); return $key_ex...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8726acef36
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_image_toolkits/7.x
Give me the example code for `hook_image_toolkits()` in Drupal 7. Hook description: Define image toolkits provided by this module.
The file which includes each toolkit's functions must be included in this hook. The toolkit's functions must be named image_toolkitname_operation(). where the operation may be: - 'load': Required. See image_gd_load() for usage. - 'save': Required. See image_gd_save() for usage. - 'settings': Optional. See image_...
function hook_image_toolkits() { return array( 'working' => array( 'title' => t('A toolkit that works.'), 'available' => TRUE, ), 'broken' => array( 'title' => t('A toolkit that is "broken" and will not be listed.'), 'available' => FALSE, ), ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-872842c16a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_switcher_url/7.x
In Drupal 7, write the function `locale_language_switcher_url($type, $path)` (file includes/locale.inc) so that it does the following: Return the URL language switcher block. Translation links may be provided by other modules.
File: includes/locale.inc
function locale_language_switcher_url($type, $path) { $languages = language_list('enabled'); $links = array(); foreach ($languages[1] as $language) { $links[$language->language] = array( 'href' => $path, 'title' => $language->native, 'language' => $language, 'attributes' ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-873a492b68
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_block_view/7.x
In Drupal 7, write the function `blog_block_view($delta = '')` (file modules/blog/blog.module) so that it does the following: Implements hook_block_view().
Displays the most recent 10 blog titles. File: modules/blog/blog.module
function blog_block_view($delta = '') { global $user; if (user_access('access content')) { $result = db_select('node', 'n') ->fields('n', array('nid', 'title', 'created')) ->condition('type', 'blog') ->condition('status', 1) ->orderBy('created', 'DESC') ->range(0, variable_get('bl...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8749d80649
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_close/7.x
I need the code for `db_close(array $options = array())` in Drupal 7 (includes/database/database.inc). It must do this: Closes the active database connection.
Parameters: - $options: An array of options to control which connection is closed. Only the target key has any meaning in this case. File: includes/database/database.inc
function db_close(array $options = array()) { if (empty($options['target'])) { $options['target'] = NULL; } Database::closeConnection($options['target']); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-874b9a60d4
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_export_po/7.x
I need the code for `_locale_export_po($language = NULL, $output = NULL)` in Drupal 7 (includes/locale.inc). It must do this: Write a generated PO or POT file to the output.
Parameters: - $language: Language object to generate the output for, or NULL if generating translation template. - $output: The PO(T) file to output as a string. See _locale_export_generate_po() on how it can be generated. File: includes/locale.inc
function _locale_export_po($language = NULL, $output = NULL) { // Log the export event. if (isset($language)) { $filename = $language->language . '.po'; watchdog('locale', 'Exported %locale translation file: %filename.', array('%locale' => $language->name, '%filename' => $filename)); } else { $filen...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-874f135f2c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.install/function/block_update_7007/7.x
In Drupal 7, write the function `block_update_7007()` (file modules/block/block.install) so that it does the following: Change {block_custom}.format into varchar.
File: modules/block/block.install
function block_update_7007() { db_change_field('block_custom', 'format', 'format', array( 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'description' => 'The {filter_format}.format of the block body.', )); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-87602c2964
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21batch.inc/function/_batch_finished/7.x
Implement `_batch_finished()` in PHP for Drupal 7. Required behavior: Ends the batch processing.
Call the 'finished' callback of each batch set to allow custom handling of the results and resolve page redirection. File: includes/batch.inc
function _batch_finished() { $batch = &batch_get(); // Execute the 'finished' callbacks for each batch set, if defined. foreach ($batch['sets'] as $batch_set) { if (isset($batch_set['finished'])) { // Check if the set requires an additional file for function definitions. if (isset($batch_set['fil...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-877c1982d1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_format_load/7.x
Implement `filter_format_load($format_id)` in PHP for Drupal 7. Required behavior: Loads a text format object from the database.
Parameters: - $format_id: The format ID. Returns: A fully-populated text format object, if the requested format exists and is enabled. If the format does not exist, or exists in the database but has been marked as disabled, FALSE is returned. File: modules/filter/filter.module
function filter_format_load($format_id) { $formats = filter_formats(); return isset($formats[$format_id]) ? $formats[$format_id] : FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-877eed4688
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_prepare_view/7.x
In Drupal 7, show an example implementation for `hook_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items)` (modules/field/field.api.php): Prepare field values prior to display.
This hook is invoked before the field values are handed to formatters for display, and runs before the formatters' own hook_field_formatter_prepare_view(). Unlike most other field hooks, this hook operates on multiple entities. The $entities, $instances and $items parameters are arrays keyed by entity ID. For performa...
function hook_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { // Sample code from image.module: if there are no images specified at all, // use the default image. foreach ($entities as $id => $entity) { if (empty($items[$id]) && $field['settings']['default_image']) { ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-87a10e092c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_mark/7.x
Implement `theme_mark($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a marker for new or updated content.
Parameters: - $variables: An associative array containing: - type: Number representing the marker type to display. See MARK_NEW, MARK_UPDATED, MARK_READ. File: includes/theme.inc
function theme_mark($variables) { $type = $variables['type']; global $user; if ($user->uid) { if ($type == MARK_NEW) { return ' <span class="marker">' . t('new') . '</span>'; } elseif ($type == MARK_UPDATED) { return ' <span class="marker">' . t('updated') . '</span>'; } } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-87ac6b6827
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_purge_instance/7.x
Implement `field_purge_instance($instance)` in PHP for Drupal 7. Required behavior: Purges a field instance record from the database.
This function assumes all data for the instance has already been purged, and should only be called by field_purge_batch(). Parameters: - $instance: The instance record to purge. File: modules/field/field.crud.inc
function field_purge_instance($instance) { db_delete('field_config_instance') ->condition('id', $instance['id']) ->execute(); // Notify the storage engine. $field = field_info_field_by_id($instance['field_id']); module_invoke($field['storage']['module'], 'field_storage_purge_instance', $instance); /...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-87b3883ba2
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_update_forbid/7.x
I need the code for `field_sql_storage_field_update_forbid($field, $prior_field, $has_data)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_field_update_forbid().
Forbid any field update that changes column definitions if there is any data. File: modules/field/modules/field_sql_storage/field_sql_storage.module
function field_sql_storage_field_update_forbid($field, $prior_field, $has_data) { if ($has_data && $field['columns'] != $prior_field['columns']) { throw new FieldUpdateForbiddenException("field_sql_storage cannot change the schema for an existing field with data."); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-87d86bd96e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_categorize_items/7.x
In Drupal 7, write the function `aggregator_categorize_items($items, $feed_source = '')` (file modules/aggregator/aggregator.pages.inc) so that it does the following: Form constructor to build the page list form.
Parameters: - $items: An array of the feed items. - $feed_source: (optional) The feed source URL. Defaults to an empty string. Returns (array): An array of FAPI elements. File: modules/aggregator/aggregator.pages.inc
function aggregator_categorize_items($items, $feed_source = '') { $form['#submit'][] = 'aggregator_categorize_items_submit'; $form['#theme'] = 'aggregator_categorize_items'; $form['feed_source'] = array( '#value' => $feed_source, ); $categories = array(); $done = FALSE; $form['items'] = array(); $fo...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-87e0ce060c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_date_format_types/7.x
In Drupal 7, show an example implementation for `hook_date_format_types()` (modules/system/system.api.php): Define additional date types.
Next to the 'long', 'medium' and 'short' date types defined in core, any module can define additional types that can be used when displaying dates, by implementing this hook. A date type is basically just a name for a date format. Date types are used in the administration interface: a user can assign date format types...
function hook_date_format_types() { // Define the core date format types. return array( 'long' => t('Long'), 'medium' => t('Medium'), 'short' => t('Short'), ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-87e30cf016
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21module.inc/function/module_enable/7.x
I need the code for `module_enable($module_list, $enable_dependencies = TRUE)` in Drupal 7 (includes/module.inc). It must do this: Enables or installs a given list of modules.
Definitions: - "Enabling" is the process of activating a module for use by Drupal. - "Disabling" is the process of deactivating a module. - "Installing" is the process of enabling it for the first time or after it has been uninstalled. - "Uninstalling" is the process of removing all traces of a module. Order of even...
function module_enable($module_list, $enable_dependencies = TRUE) { if ($enable_dependencies) { // Get all module data so we can find dependencies and sort. $module_data = system_rebuild_module_data(); // Create an associative array with weights as values. $module_list = array_flip(array_values($modul...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-87ebe20fd1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_user_presave/7.x
I need the code for `block_user_presave(&$edit, $account, $category)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_user_presave().
File: modules/block/block.module
function block_user_presave(&$edit, $account, $category) { if (isset($edit['block'])) { $edit['data']['block'] = $edit['block']; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-881976a079
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_delete_links/7.x
I need the code for `menu_delete_links($menu_name)` in Drupal 7 (includes/menu.inc). It must do this: Deletes all links for a menu.
Parameters: - $menu_name: The name of the menu whose links will be deleted. File: includes/menu.inc
function menu_delete_links($menu_name) { $links = menu_load_links($menu_name); foreach ($links as $link) { // To speed up the deletion process, we reset some link properties that // would trigger re-parenting logic in _menu_delete_item() and // _menu_update_parental_status(). $link['has_children'] =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-881be8bec6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_drupal_goto_alter/7.x
In Drupal 7, write the function `overlay_drupal_goto_alter(&$path, &$options, &$http_response_code)` (file modules/overlay/overlay.module) so that it does the following: Implements hook_drupal_goto_alter().
File: modules/overlay/overlay.module
function overlay_drupal_goto_alter(&$path, &$options, &$http_response_code) { if (overlay_get_mode() == 'child') { // The authorize.php script bootstraps Drupal to a very low level, where // the PHP code that is necessary to close the overlay properly will not be // loaded. Therefore, if we are redirectin...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-881d393983
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_type_update/7.x
In Drupal 7, write the function `book_node_type_update($type)` (file modules/book/book.module) so that it does the following: Implements hook_node_type_update().
Updates the Book module's persistent variables if the machine-readable name of a node type is changed. File: modules/book/book.module
function book_node_type_update($type) { if (!empty($type->old_type) && $type->old_type != $type->type) { // Update the list of node types that are allowed to be added to books. $allowed_types = variable_get('book_allowed_types', array('book')); $key = array_search($type->old_type, $allowed_types); if...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8824f02695
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_title_list/7.x
I need the code for `statistics_title_list($dbfield, $dbrows)` in Drupal 7 (modules/statistics/statistics.module). It must do this: Returns the most viewed content of all time, today, or the last-viewed node.
Parameters: - $dbfield: The database field to use, one of: - 'totalcount': Integer that shows the top viewed content of all time. - 'daycount': Integer that shows the top viewed content for today. - 'timestamp': Integer that shows only the last viewed node. - $dbrows: The number of rows to be returned. Returns (Select...
function statistics_title_list($dbfield, $dbrows) { if (in_array($dbfield, array('totalcount', 'daycount', 'timestamp'))) { $query = db_select('node', 'n'); $query->addTag('node_access'); $query->join('node_counter', 's', 'n.nid = s.nid'); $query->join('users', 'u', 'n.uid = u.uid'); return $quer...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-882b83c141
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_delete_instance/7.x
Give me the example code for `hook_field_storage_delete_instance($instance)` in Drupal 7. Hook description: Act on deletion of a field instance.
This hook is invoked from field_delete_instance() to ask the field storage module to mark all information stored for the field instance for deletion. Parameters: - $instance: The instance being deleted. File: modules/field/field.api.php
function hook_field_storage_delete_instance($instance) { $field = field_info_field($instance['field_name']); $table_name = _field_sql_storage_tablename($field); $revision_name = _field_sql_storage_revision_tablename($field); db_update($table_name) ->fields(array('deleted' => 1)) ->condition('entity_type...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-8840f0e43c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_permission/7.x
Implement `simpletest_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().
File: modules/simpletest/simpletest.module
function simpletest_permission() { return array( 'administer unit tests' => array( 'title' => t('Administer tests'), 'restrict access' => TRUE, ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-884b1149f9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/_user_cancel_session_regenerate/7.x
I need the code for `_user_cancel_session_regenerate()` in Drupal 7 (modules/user/user.module). It must do this: Implements callback_batch_finished().
Finished batch processing callback for cancelling a user account. File: modules/user/user.module
function _user_cancel_session_regenerate() { // Regenerate the users session instead of calling session_destroy() as we // want to preserve any messages that might have been set. drupal_session_regenerate(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-884ea0cac8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_item_delete_form/7.x
In Drupal 7, write the function `menu_item_delete_form($form, &$form_state, $item)` (file modules/menu/menu.admin.inc) so that it does the following: Build a confirm form for deletion of a single menu link.
File: modules/menu/menu.admin.inc
function menu_item_delete_form($form, &$form_state, $item) { $form['#item'] = $item; return confirm_form($form, t('Are you sure you want to delete the custom menu link %item?', array('%item' => $item['link_title'])), 'admin/structure/menu/manage/' . $item['menu_name']); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8874dac38f
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_create_field/7.x
I need the code for `field_sql_storage_field_storage_create_field($field)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_field_storage_create_field().
File: modules/field/modules/field_sql_storage/field_sql_storage.module
function field_sql_storage_field_storage_create_field($field) { $schema = _field_sql_storage_schema($field); foreach ($schema as $name => $table) { db_create_table($name, $table); } drupal_get_schema(NULL, TRUE); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-88788d35a5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_edit_form/7.x
I need the code for `locale_translate_edit_form($form, &$form_state, $lid)` in Drupal 7 (modules/locale/locale.admin.inc). It must do this: User interface for string editing.
File: modules/locale/locale.admin.inc
function locale_translate_edit_form($form, &$form_state, $lid) { // Fetch source string, if possible. $source = db_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject(); if (!$source) { drupal_set_message(t('String not found.'), 'erro...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-887fb81d4a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/_template_preprocess_default_variables/7.x
Implement `_template_preprocess_default_variables()` in PHP for Drupal 7. Required behavior: Returns hook-independent variables to template_preprocess().
File: includes/theme.inc
function _template_preprocess_default_variables() { global $user; // Variables that don't depend on a database connection. $variables = array( 'attributes_array' => array(), 'title_attributes_array' => array(), 'content_attributes_array' => array(), 'title_prefix' => array(), 'title_suffix' =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-888c03d501
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/update_fetch_data_batch/7.x
In Drupal 7, write the function `update_fetch_data_batch(&$context)` (file modules/update/update.fetch.inc) so that it does the following: Implements callback_batch_operation().
Processes a step in batch for fetching available update data. Parameters: - $context: Reference to an array used for Batch API storage. File: modules/update/update.fetch.inc
function update_fetch_data_batch(&$context) { $queue = DrupalQueue::get('update_fetch_tasks'); if (empty($context['sandbox']['max'])) { $context['finished'] = 0; $context['sandbox']['max'] = $queue->numberOfItems(); $context['sandbox']['progress'] = 0; $context['message'] = t('Checking available upd...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-88d2817df2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_theme/7.x
Implement `simpletest_theme()` in PHP for Drupal 7. Required behavior: Implements hook_theme().
File: modules/simpletest/simpletest.module
function simpletest_theme() { return array( 'simpletest_test_table' => array( 'render element' => 'table', 'file' => 'simpletest.pages.inc', ), 'simpletest_result_summary' => array( 'render element' => 'form', 'file' => 'simpletest.pages.inc', ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-88d6d2f98c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_registry_files_alter/7.x
Give me the example code for `hook_registry_files_alter(&$files, $modules)` in Drupal 7. Hook description: Perform necessary alterations to the list of files parsed by the registry.
Modules can manually modify the list of files before the registry parses them. The $modules array provides the .info file information, which includes the list of files registered to each module. Any files in the list can then be added to the list of files that the registry will parse, or modify attributes of a file. A...
function hook_registry_files_alter(&$files, $modules) { foreach ($modules as $module) { // Only add test files for disabled modules, as enabled modules should // already include any test files they provide. if (!$module->status) { $dir = $module->dir; foreach ($module->info['files'] as $file) ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-88ee07148d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_read_instance/7.x
Implement `field_read_instance($entity_type, $field_name, $bundle, $include_additional = array())` in PHP for Drupal 7. Required behavior: Reads a single instance record from the database.
Generally, you should use field_info_instance() instead, as it provides caching and allows other modules the opportunity to append additional formatters, widgets, and other information. Parameters: - $entity_type: The type of entity to which the field is bound. - $field_name: The field name to read. - $bundle: The bun...
function field_read_instance($entity_type, $field_name, $bundle, $include_additional = array()) { $instances = field_read_instances(array('entity_type' => $entity_type, 'field_name' => $field_name, 'bundle' => $bundle), $include_additional); return $instances ? current($instances) : FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-88f0cd049e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_get_all_announcements/7.x
I need the code for `announcements_feed_get_all_announcements()` in Drupal 7 (modules/announcements_feed/announcements_feed.inc). It must do this: Generate an array of announcements with keys.
Returns (array): An array of announcements. File: modules/announcements_feed/announcements_feed.inc
function announcements_feed_get_all_announcements() { $announcements = announcements_feed_fetch(); $announcements_feed = array(); foreach ($announcements as $announcement) { $announcements_feed[] = array( 'id' => $announcement['id'], 'title' => $announcement['title'], 'link' => $announcement...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-88ff9e53b2
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_secondary_local_tasks/7.x
In Drupal 7, write the function `menu_secondary_local_tasks()` (file includes/menu.inc) so that it does the following: Returns the rendered local tasks at the second level.
File: includes/menu.inc
function menu_secondary_local_tasks() { $links = menu_local_tasks(1); // Do not display single tabs. return ($links['tabs']['count'] > 1 ? $links['tabs']['output'] : ''); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-89158db883
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_date_format_save/7.x
In Drupal 7, write the function `locale_date_format_save($langcode, $type, $format)` (file includes/locale.inc) so that it does the following: Save locale specific date formats to the database.
Parameters: - $langcode: Language code, can be 2 characters, e.g. 'en' or 5 characters, e.g. 'en-CA'. - $type: Date format type, e.g. 'short', 'medium'. - $format: The date format string. File: includes/locale.inc
function locale_date_format_save($langcode, $type, $format) { $locale_format = array(); $locale_format['language'] = $langcode; $locale_format['type'] = $type; $locale_format['format'] = $format; $is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE language = :langcode AND type = :t...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-891d0675c2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_info/7.x
I need the code for `number_field_info()` in Drupal 7 (modules/field/modules/number/number.module). It must do this: Implements hook_field_info().
File: modules/field/modules/number/number.module
function number_field_info() { return array( 'number_integer' => array( 'label' => t('Integer'), 'description' => t('This field stores a number in the database as an integer.'), 'instance_settings' => array('min' => '', 'max' => '', 'prefix' => '', 'suffix' => ''), 'default_widget' => 'num...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-89233f30e6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_send_email_action_form/7.x
In Drupal 7, write the function `system_send_email_action_form($context)` (file modules/system/system.module) so that it does the following: Return a form definition so the Send email action can be configured.
Parameters: - $context: Default values (if we are editing an existing action instance). Returns: Form definition. File: modules/system/system.module
function system_send_email_action_form($context) { // Set default values for form. if (!isset($context['recipient'])) { $context['recipient'] = ''; } if (!isset($context['subject'])) { $context['subject'] = ''; } if (!isset($context['message'])) { $context['message'] = ''; } $form['recipien...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8931ae5af8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_batch_language_finished/7.x
In Drupal 7, write the function `_locale_batch_language_finished($success, $results)` (file includes/locale.inc) so that it does the following: Implements callback_batch_finished().
Finished callback of language addition locale import batch. Inform the user of translation files imported. File: includes/locale.inc
function _locale_batch_language_finished($success, $results) { if ($success) { drupal_set_message(format_plural(count($results), 'One translation file imported for the enabled modules.', '@count translation files imported for the enabled modules.')); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-893540a9c4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_submit/7.x
Implement `node_submit($node)` in PHP for Drupal 7. Required behavior: Prepares node for saving by populating author and creation date.
Parameters: - $node: A node object. Returns: An updated node object. File: modules/node/node.module
function node_submit($node) { // A user might assign the node author by entering a user name in the node // form, which we then need to translate to a user ID. if (isset($node->name)) { if ($account = user_load_by_name($node->name)) { $node->uid = $account->uid; } else { $node->uid = 0; ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8940383f67
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/_forum_node_check_node_type/7.x
Implement `_forum_node_check_node_type($node)` in PHP for Drupal 7. Required behavior: Checks whether a node can be used in a forum, based on its content type.
Parameters: - $node: A node object. Returns (Boolean): indicating if the node can be assigned to a forum. File: modules/forum/forum.module
function _forum_node_check_node_type($node) { // Fetch information about the forum field. $field = field_info_instance('node', 'taxonomy_forums', $node->type); return is_array($field); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-895b717d6d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/theme_update_manager_update_form/7.x
Implement `theme_update_manager_update_form($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the first page in the process of updating projects.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/update/update.manager.inc
function theme_update_manager_update_form($variables) { $form = $variables['form']; $last = variable_get('update_last_check', 0); $output = theme('update_last_check', array('last' => $last)); $output .= drupal_render_children($form); return $output; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-89684b2de2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_user_logout/7.x
Implement `trigger_user_logout($account)` in PHP for Drupal 7. Required behavior: Implements hook_user_logout().
File: modules/trigger/trigger.module
function trigger_user_logout($account) { $edit = array(); _trigger_user('user_logout', $edit, $account); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8968ac9b3e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_render/7.x
I need the code for `ajax_render($commands = array())` in Drupal 7 (includes/ajax.inc). It must do this: Renders a commands array into JSON.
Parameters: - $commands: A list of macro commands generated by the use of ajax_command_*() functions. File: includes/ajax.inc
function ajax_render($commands = array()) { // Although ajax_deliver() does this, some contributed and custom modules // render Ajax responses without using that delivery callback. ajax_set_verification_header(); // Ajax responses aren't rendered with html.tpl.php, so we have to call // drupal_get_css() and ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-896c8f8fd2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_delete_form/7.x
Implement `shortcut_set_delete_form($form, &$form_state, $shortcut_set)` in PHP for Drupal 7. Required behavior: Form callback: builds the confirmation form for deleting a shortcut set.
Parameters: - $form: An associative array containing the structure of the form. - $form_state: An associative array containing the current state of the form. - $shortcut_set (object): An object representing the shortcut set, as returned from shortcut_set_load(). Returns: An array representing the form definition. Fil...
function shortcut_set_delete_form($form, &$form_state, $shortcut_set) { $form['shortcut_set'] = array( '#type' => 'value', '#value' => $shortcut_set->set_name, ); // Find out how many users are directly assigned to this shortcut set, and // make a message. $number = db_query('SELECT COUNT(*) FROM {sh...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-898005156e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_validate/7.x
I need the code for `taxonomy_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_field_validate().
Taxonomy field settings allow for either a single vocabulary ID, multiple vocabulary IDs, or sub-trees of a vocabulary to be specified as allowed values, although only the first of these is supported via the field UI. Confirm that terms entered as values meet at least one of these conditions. Possible error codes: - '...
function taxonomy_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { // Build an array of existing term IDs so they can be loaded with // taxonomy_term_load_multiple(); foreach ($items as $delta => $item) { if (!empty($item['tid']) && $item['tid'] !== 'autocreate') { ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8988e9ffd9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_detect_database_types/7.x
I need the code for `drupal_detect_database_types()` in Drupal 7 (includes/install.inc). It must do this: Detects all supported databases that are compiled into PHP.
Returns: An array of database types compiled into PHP. File: includes/install.inc
function drupal_detect_database_types() { $databases = drupal_get_database_types(); foreach ($databases as $driver => $installer) { $databases[$driver] = $installer->name(); } return $databases; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-898ad7166e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_widget_process/7.x
Implement `image_field_widget_process($element, &$form_state, $form)` in PHP for Drupal 7. Required behavior: An element #process callback for the image_image field type.
Expands the image_image type to include the alt and title fields. File: modules/image/image.field.inc
function image_field_widget_process($element, &$form_state, $form) { $item = $element['#value']; $item['fid'] = $element['fid']['#value']; $instance = field_widget_instance($element, $form_state); $settings = $instance['settings']; $widget_settings = $instance['widget']['settings']; $element['#theme'] = ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-89cba4b8f3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load_by_name/7.x
Implement `user_load_by_name($name)` in PHP for Drupal 7. Required behavior: Fetch a user object by account name.
Parameters: - $name: String with the account's user name. Returns: A fully-loaded $user object upon successful user load or FALSE if user cannot be loaded. File: modules/user/user.module
function user_load_by_name($name) { $users = user_load_multiple(array(), array('name' => $name)); return reset($users); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-89e34b0613
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21authorize.inc/function/_authorize_filetransfer_connection_settings_set_defaults/7.x
In Drupal 7, write the function `_authorize_filetransfer_connection_settings_set_defaults(&$element, $key, array $defaults)` (file includes/authorize.inc) so that it does the following: Sets the default settings on a file transfer connection form recursively.
The default settings for the file transfer connection forms are saved in the database. The settings are stored as a nested array in the case of a settings form that has fieldsets or otherwise uses a nested structure. Therefore, to properly add defaults, we need to walk through all the children form elements and process...
function _authorize_filetransfer_connection_settings_set_defaults(&$element, $key, array $defaults) { // If we're operating on a form element which isn't a fieldset, and we have // a default setting saved, stash it in #default_value. if (!empty($key) && isset($defaults[$key]) && isset($element['#type']) && $eleme...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-89ed4b795a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render_children/7.x
I need the code for `drupal_render_children(&$element, $children_keys = NULL)` in Drupal 7 (includes/common.inc). It must do this: Renders children of an element and concatenates them.
Parameters: - $element (array): The structured array whose children shall be rendered. - $children_keys (array): (optional) If the keys of the element's children are already known, they can be passed in to save another run of element_children(). Returns (string): The rendered HTML of all children of the element. File...
function drupal_render_children(&$element, $children_keys = NULL) { if ($children_keys === NULL) { $children_keys = element_children($element); } $output = ''; foreach ($children_keys as $key) { if (!empty($element[$key])) { $output .= drupal_render($element[$key]); } } return $output; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-89f849d9e9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_is_empty/7.x
Implement `number_field_is_empty($item, $field)` in PHP for Drupal 7. Required behavior: Implements hook_field_is_empty().
File: modules/field/modules/number/number.module
function number_field_is_empty($item, $field) { if (empty($item['value']) && (string) $item['value'] !== '0') { return TRUE; } return FALSE; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-89fc329c06
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_parse_js_file/7.x
In Drupal 7, write the function `_locale_parse_js_file($filepath)` (file includes/locale.inc) so that it does the following: Parses a JavaScript file, extracts strings wrapped in Drupal.t() and Drupal.formatPlural() and inserts them into the database.
File: includes/locale.inc
function _locale_parse_js_file($filepath) { global $language; // The file path might contain a query string, so make sure we only use the // actual file. $parsed_url = drupal_parse_url($filepath); $filepath = $parsed_url['path']; // Load the JavaScript file. $file = file_get_contents($filepath); // Ma...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8a008042d9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_module_admin_tasks/7.x
I need the code for `system_get_module_admin_tasks($module, $info)` in Drupal 7 (modules/system/system.module). It must do this: Generate a list of tasks offered by a specified module.
Parameters: - $module: Module name. - $info: The module's information, as provided by system_get_info(). Returns: An array of task links. File: modules/system/system.module
function system_get_module_admin_tasks($module, $info) { $links = &drupal_static(__FUNCTION__); if (!isset($links)) { $links = array(); $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC)); $query->join('menu_router', 'm', 'm.path = ml.router_path'); $query ->fields('ml'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8a1fd35e28
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_load/7.x
I need the code for `shortcut_set_load($set_name)` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Loads the data for a shortcut set.
Parameters: - $set_name: The name of the shortcut set to load. Returns (object): If the shortcut set exists, an object containing the following properties: - 'set_name': The internal name of the shortcut set. - 'title': The title of the shortcut set. - 'links': An array of links associated with this shortcut set. If t...
function shortcut_set_load($set_name) { $set = db_select('shortcut_set', 'ss') ->fields('ss') ->condition('set_name', $set_name) ->execute() ->fetchObject(); if (!$set) { return FALSE; } $set->links = menu_load_links($set_name); return $set; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8a257a0383
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21content_types.inc/function/theme_node_admin_overview/7.x
In Drupal 7, write the function `theme_node_admin_overview($variables)` (file modules/node/content_types.inc) so that it does the following: Returns HTML for a node type description for the content type admin overview page.
Parameters: - $variables: An associative array containing: - name: The human-readable name of the content type. - type: An object containing the 'type' (machine name) and 'description' of the content type. File: modules/node/content_types.inc
function theme_node_admin_overview($variables) { $name = $variables['name']; $type = $variables['type']; $output = check_plain($name); $output .= ' <small>' . t('(Machine name: @type)', array('@type' => $type->type)) . '</small>'; $output .= '<div class="description">' . filter_xss_admin($type->description) ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8a2dcd4975
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_update_build_id/7.x
I need the code for `ajax_command_update_build_id($form)` in Drupal 7 (includes/ajax.inc). It must do this: Creates a Drupal Ajax 'update_build_id' command.
This command updates the value of a hidden form_build_id input element on a form. It requires the form passed in to have keys for both the old build ID in #build_id_old and the new build ID in #build_id. The primary use case for this Ajax command is to serve a new build ID to a form served from the cache to an anonymo...
function ajax_command_update_build_id($form) { return array( 'command' => 'updateBuildId', 'old' => $form['#build_id_old'], 'new' => $form['#build_id'], ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8a49d3e56a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_comment_insert/7.x
I need the code for `search_comment_insert($comment)` in Drupal 7 (modules/search/search.module). It must do this: Implements hook_comment_insert().
File: modules/search/search.module
function search_comment_insert($comment) { // Reindex the node when comments are added. search_touch_node($comment->nid); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8a6afc5bb6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_block_save/7.x
Implement `aggregator_block_save($delta = '', $edit = array())` in PHP for Drupal 7. Required behavior: Implements hook_block_save().
File: modules/aggregator/aggregator.module
function aggregator_block_save($delta = '', $edit = array()) { list($type, $id) = explode('-', $delta); if ($type == 'category') { db_update('aggregator_category') ->fields(array('block' => $edit['block'])) ->condition('cid', $id) ->execute(); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8a8386f033
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_cancel_confirm/7.x
Implement `user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '')` in PHP for Drupal 7. Required behavior: Menu callback; Cancel a user account via e-mail confirmation link.
File: modules/user/user.pages.inc
function user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '') { // Time out in seconds until cancel URL expires; 24 hours = 86400 seconds. $timeout = 86400; $current = REQUEST_TIME; // Basic validation of arguments. if (isset($account->data['user_cancel_method']) && !empty($timestamp) && !empty($...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8a886aedfa
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.admin.inc/function/path_admin_form/7.x
Implement `path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'language' => LANGUAGE_NONE, 'pid' => NULL))` in PHP for Drupal 7. Required behavior: Form constructor for the path administration form.
Parameters: - $path: An array containing the path ID, source, alias, and language code. File: modules/path/path.admin.inc
function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'language' => LANGUAGE_NONE, 'pid' => NULL)) { $form['source'] = array( '#type' => 'textfield', '#title' => t('Existing system path'), '#default_value' => $path['source'], '#maxlength' => 255, '#size' => 45,...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8a944e8f09
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21update.inc/function/update_resolve_dependencies/7.x
In Drupal 7, write the function `update_resolve_dependencies($starting_updates)` (file includes/update.inc) so that it does the following: Resolves dependencies in a set of module updates, and orders them correctly.
This function receives a list of requested module updates and determines an appropriate order to run them in such that all update dependencies are met. Any updates whose dependencies cannot be met are included in the returned array but have the key 'allowed' set to FALSE; the calling function should take responsibility...
function update_resolve_dependencies($starting_updates) { // Obtain a dependency graph for the requested update functions. $update_functions = update_get_update_function_list($starting_updates); $graph = update_build_dependency_graph($update_functions); // Perform the depth-first search and sort the results. ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8aa440316c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_get_preferred/7.x
In Drupal 7, write the function `menu_link_get_preferred($path = NULL, $selected_menu = NULL)` (file includes/menu.inc) so that it does the following: Looks up the preferred menu link for a given system path.
Parameters: - $path: The path; for example, 'node/5'. The function will find the corresponding menu link ('node/5' if it exists, or fallback to 'node/%'). - $selected_menu: The name of a menu used to restrict the search for a preferred menu link. If not specified, all the menus returned by menu_get_active_menu_names() ...
function menu_link_get_preferred($path = NULL, $selected_menu = NULL) { $preferred_links = &drupal_static(__FUNCTION__); if (!isset($path)) { $path = $_GET['q']; } if (empty($selected_menu)) { // Use an illegal menu name as the key for the preferred menu link. $selected_menu = MENU_PREFERRED_LINK;...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8aaa863b5c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/_field_ui_bundle_admin_path/7.x
In Drupal 7, write the function `_field_ui_bundle_admin_path($entity_type, $bundle_name)` (file modules/field_ui/field_ui.module) so that it does the following: Determines the administration path for a bundle.
File: modules/field_ui/field_ui.module
function _field_ui_bundle_admin_path($entity_type, $bundle_name) { $bundles = field_info_bundles($entity_type); $bundle_info = $bundles[$bundle_name]; if (isset($bundle_info['admin'])) { return isset($bundle_info['admin']['real path']) ? $bundle_info['admin']['real path'] : $bundle_info['admin']['path']; } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8ab9366041
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_page_get_cache/7.x
Implement `drupal_page_get_cache($check_only = FALSE)` in PHP for Drupal 7. Required behavior: Retrieves the current page from the cache.
Note: we do not serve cached pages to authenticated users, or to anonymous users when $_SESSION is non-empty. $_SESSION may contain status messages from a form submission, the contents of a shopping cart, or other user- specific content that should not be cached and displayed to other users. Parameters: - $check_only:...
function drupal_page_get_cache($check_only = FALSE) { global $base_root; static $cache_hit = FALSE; if ($check_only) { return $cache_hit; } if (drupal_page_is_cacheable()) { $cache = cache_get($base_root . request_uri(), 'cache_page'); if ($cache !== FALSE) { $cache_hit = TRUE; } r...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8acf828fb0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_7005/7.x
Implement `image_update_7005()` in PHP for Drupal 7. Required behavior: Add a column to the 'image_style' table to store administrative labels.
File: modules/image/image.install
function image_update_7005() { $field = array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The style administrative name.', ); db_add_field('image_styles', 'label', $field); // Do a direct query here, rather than calling image_styles(), // ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8ad34be3c8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_container/7.x
In Drupal 7, write the function `form_process_container($element, &$form_state)` (file includes/form.inc) so that it does the following: Processes a container element.
Parameters: - $element: An associative array containing the properties and children of the container. - $form_state: The $form_state array for the form this element belongs to. Returns: The processed element. File: includes/form.inc
function form_process_container($element, &$form_state) { // Generate the ID of the element if it's not explicitly given. if (!isset($element['#id'])) { $element['#id'] = drupal_html_id(implode('-', $element['#parents']) . '-wrapper'); } return $element; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8adfec71d7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_date_format_delete/7.x
Implement `system_date_format_delete($dfid)` in PHP for Drupal 7. Required behavior: Deletes a date format from the database.
Parameters: - $dfid: The date format ID. File: modules/system/system.module
function system_date_format_delete($dfid) { db_delete('date_formats') ->condition('dfid', $dfid) ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8b07310c10
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21engines%21phptemplate%21phptemplate.engine/function/phptemplate_init/7.x
I need the code for `phptemplate_init($template)` in Drupal 7 (themes/engines/phptemplate/phptemplate.engine). It must do this: Implements hook_init().
File: themes/engines/phptemplate/phptemplate.engine
function phptemplate_init($template) { $file = dirname($template->filename) . '/template.php'; if (file_exists($file)) { include_once DRUPAL_ROOT . '/' . $file; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8b0bed0b22
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_field_formatter_info/7.x
I need the code for `list_field_formatter_info()` in Drupal 7 (modules/field/modules/list/list.module). It must do this: Implements hook_field_formatter_info().
File: modules/field/modules/list/list.module
function list_field_formatter_info() { return array( 'list_default' => array( 'label' => t('Default'), 'field types' => array('list_integer', 'list_float', 'list_text', 'list_boolean'), ), 'list_key' => array( 'label' => t('Key'), 'field types' => array('list_integer', 'list_float'...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8b1a030df7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.install/function/update_install/7.x
In Drupal 7, write the function `update_install()` (file modules/update/update.install) so that it does the following: Implements hook_install().
File: modules/update/update.install
function update_install() { $queue = DrupalQueue::get('update_fetch_tasks', TRUE); $queue->createQueue(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8b1f9bcd17
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_field_schema/7.x
Implement `taxonomy_field_schema($field)` in PHP for Drupal 7. Required behavior: Implements hook_field_schema().
File: modules/taxonomy/taxonomy.install
function taxonomy_field_schema($field) { return array( 'columns' => array( 'tid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, ), ), 'indexes' => array( 'tid' => array('tid'), ), 'foreign keys' => array( 'tid' => array( ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-8b1fde1bc5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_progress_implementation/7.x
In Drupal 7, write the function `file_progress_implementation()` (file modules/file/file.module) so that it does the following: Determines the preferred upload progress implementation.
Returns: A string indicating which upload progress system is available. Either "apc" or "uploadprogress". If neither are available, returns FALSE. File: modules/file/file.module
function file_progress_implementation() { static $implementation; if (!isset($implementation)) { $implementation = FALSE; // We prefer the PECL extension uploadprogress because it supports multiple // simultaneous uploads. APC only supports one at a time. if (extension_loaded('uploadprogress')) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8b287e0037
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.install/function/dblog_update_7001/7.x
Implement `dblog_update_7001()` in PHP for Drupal 7. Required behavior: Update the {watchdog} table.
File: modules/dblog/dblog.install
function dblog_update_7001() { // Allow NULL values for links. db_change_field('watchdog', 'link', 'link', array( 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => '', 'description' => 'Link to view the result of the event.', )); // Add an index on uid. db_add_index(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-8b2a7773dd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.api.php/function/hook_aggregator_parse_info/7.x
In Drupal 7, show an example implementation for `hook_aggregator_parse_info()` (modules/aggregator/aggregator.api.php): Specify the title and short description of your parser.
The title and the description provided are shown within the configuration page. Use as title the human readable name of the parser and as description a brief (40 to 80 characters) explanation of the parser's functionality. This hook is only called if your module implements hook_aggregator_parse(). If this hook is not ...
function hook_aggregator_parse_info() { return array( 'title' => t('Default parser'), 'description' => t('Default parser for RSS, Atom and RDF feeds.'), ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00