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-c5c1057ce6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_view_multiple/7.x
Implement `comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL)` in PHP for Drupal 7. Required behavior: Construct a drupal_render() style array from an array of loaded comments.
Parameters: - $comments: An array of comments as returned by comment_load_multiple(). - $node: The node the comments are attached to. - $view_mode: View mode, e.g. 'full', 'teaser'... - $weight: An integer representing the weight of the first comment in the list. - $langcode: A string indicating the language field valu...
function comment_view_multiple($comments, $node, $view_mode = 'full', $weight = 0, $langcode = NULL) { $build = array(); $entities_by_view_mode = entity_view_mode_prepare('comment', $comments, $view_mode, $langcode); foreach ($entities_by_view_mode as $entity_view_mode => $entities) { field_attach_prepare_vie...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c5c7e0442e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_insert/7.x
In Drupal 7, write the function `comment_node_insert($node)` (file modules/comment/comment.module) so that it does the following: Implements hook_node_insert().
File: modules/comment/comment.module
function comment_node_insert($node) { // Allow bulk updates and inserts to temporarily disable the // maintenance of the {node_comment_statistics} table. if (variable_get('comment_maintain_node_statistics', TRUE)) { db_insert('node_comment_statistics') ->fields(array( 'nid' => $node->nid, ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c5d684185b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_block_view/7.x
In Drupal 7, write the function `locale_block_view($type)` (file modules/locale/locale.module) so that it does the following: Implements hook_block_view().
Displays a language switcher. Only show if we have at least two languages. File: modules/locale/locale.module
function locale_block_view($type) { if (drupal_multilingual()) { $path = drupal_is_front_page() ? '<front>' : $_GET['q']; $links = language_negotiation_get_switch_links($type, $path); if (isset($links->links)) { drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css'); $class = "la...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c5e9a94855
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_block_info/7.x
I need the code for `locale_block_info()` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_block_info().
File: modules/locale/locale.module
function locale_block_info() { include_once DRUPAL_ROOT . '/includes/language.inc'; $block = array(); $info = language_types_info(); foreach (language_types_configurable(FALSE) as $type) { $block[$type] = array( 'info' => t('Language switcher (@type)', array('@type' => $info[$type]['name'])), //...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c60cfb36bb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/_trigger_normalize_user_context/7.x
In Drupal 7, write the function `_trigger_normalize_user_context($type, $account)` (file modules/trigger/trigger.module) so that it does the following: Loads associated objects for user triggers.
When an action is called in a context that does not match its type, the object that the action expects must be retrieved. For example, when an action that works on nodes is called during the user hook, the node object is not available since the user hook doesn't pass it. So here we load the object the action expects. ...
function _trigger_normalize_user_context($type, $account) { // Note that comment-type actions are not supported in user contexts, // because we wouldn't know which comment to choose. switch ($type) { // An action that works with nodes is being called in a user context. // If a single node is being viewed,...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c62668c722
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_association/7.x
Implement `openid_association($op_endpoint)` in PHP for Drupal 7. Required behavior: Attempt to create a shared secret with the OpenID Provider.
Parameters: - $op_endpoint: URL of the OpenID Provider endpoint. Returns: $assoc_handle The association handle. File: modules/openid/openid.module
function openid_association($op_endpoint) { module_load_include('inc', 'openid'); // Remove Old Associations: db_delete('openid_association') ->where('created + expires_in < :request_time', array(':request_time' => REQUEST_TIME)) ->execute(); // Check to see if we have an association for this IdP alre...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c6270ef62d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate_extensions/7.x
Implement `file_validate_extensions(stdClass $file, $extensions)` in PHP for Drupal 7. Required behavior: Checks that the filename ends with an allowed extension.
Parameters: - $file: A Drupal file object. - $extensions: A string with a space separated list of allowed extensions. Returns: An array. If the file extension is not allowed, it will contain an error message. File: includes/file.inc
function file_validate_extensions(stdClass $file, $extensions) { $errors = array(); $regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i'; if (!preg_match($regex, $file->filename)) { $errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c62cdbf4a3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_load/7.x
In Drupal 7, write the function `text_field_load($entity_type, $entities, $field, $instances, $langcode, &$items)` (file modules/field/modules/text/text.module) so that it does the following: Implements hook_field_load().
Where possible, generate the sanitized version of each field early so that it is cached in the field cache. This avoids looking up from the filter cache separately. File: modules/field/modules/text/text.module
function text_field_load($entity_type, $entities, $field, $instances, $langcode, &$items) { foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { // Only process items with a cacheable format, the rest will be handled // by formatters if needed. if (empty($instances[...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c63a248f07
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7049/7.x
I need the code for `system_update_7049()` in Drupal 7 (modules/system/system.install). It must do this: Rename 'Default' profile to 'Standard.'
File: modules/system/system.install
function system_update_7049() { if (variable_get('install_profile', 'standard') == 'default') { variable_set('install_profile', 'standard'); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c63ab0481e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/theme_system_modules_uninstall/7.x
In Drupal 7, write the function `theme_system_modules_uninstall($variables)` (file modules/system/system.admin.inc) so that it does the following: Returns HTML for a table of currently disabled modules.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/system/system.admin.inc
function theme_system_modules_uninstall($variables) { $form = $variables['form']; // No theming for the confirm form. if (isset($form['confirm'])) { return drupal_render($form); } // Table headers. $header = array(t('Uninstall'), t('Name'), t('Description'), ); // Display table. $rows =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c650f996b9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_tag_new/7.x
Implement `node_tag_new($node)` in PHP for Drupal 7. Required behavior: Updates the 'last viewed' timestamp of the specified node for current user.
Parameters: - $node: A node object. File: modules/node/node.module
function node_tag_new($node) { global $user; if ($user->uid) { db_merge('history') ->key(array( 'uid' => $user->uid, 'nid' => $node->nid, )) ->fields(array('timestamp' => REQUEST_TIME)) ->execute(); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c654a973b7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.admin.inc/function/search_admin_reindex_submit/7.x
Implement `search_admin_reindex_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for reindex button on search_admin_settings_form().
File: modules/search/search.admin.inc
function search_admin_reindex_submit($form, &$form_state) { // send the user to the confirmation page $form_state['redirect'] = 'admin/config/search/settings/reindex'; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c65f3d228c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21drupal_web_test_case.php/function/simpletest_verbose/7.x
In Drupal 7, write the function `simpletest_verbose($message, $original_file_directory = NULL, $test_class = NULL)` (file modules/simpletest/drupal_web_test_case.php) so that it does the following: Logs verbose message in a text file.
If verbose mode is enabled then page requests will be dumped to a file and presented on the test result screen. The messages will be placed in a file located in the simpletest directory in the original file system. Parameters: - $message: The verbose message to be stored. - $original_file_directory: The original file ...
function simpletest_verbose($message, $original_file_directory = NULL, $test_class = NULL) { static $file_directory = NULL, $class = NULL, $id = 1, $verbose = NULL; // Will pass first time during setup phase, and when verbose is TRUE. if (!isset($original_file_directory) && !$verbose) { return FALSE; } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c681d8b672
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_system_update/7.x
In Drupal 7, write the function `locale_system_update($components)` (file modules/locale/locale.module) so that it does the following: Imports translations when new modules or themes are installed.
This function will either import translation for the component change right away, or start a batch if more files need to be imported. Parameters: - $components: An array of component (theme and/or module) names to import translations for. File: modules/locale/locale.module
function locale_system_update($components) { include_once DRUPAL_ROOT . '/includes/locale.inc'; if ($batch = locale_batch_by_component($components)) { batch_set($batch); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c69227e32e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_save_action/7.x
I need the code for `node_save_action($node)` in Drupal 7 (modules/node/node.module). It must do this: Saves a node.
Parameters: - $node: The node to be saved. File: modules/node/node.module
function node_save_action($node) { node_save($node); watchdog('action', 'Saved @type %title', array('@type' => node_type_get_name($node), '%title' => $node->title)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c6a0a05984
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_block_configure/7.x
Implement `blog_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().
File: modules/blog/blog.module
function blog_block_configure($delta = '') { if ($delta == 'recent') { $form['blog_block_count'] = array( '#type' => 'select', '#title' => t('Number of recent blog posts to display'), '#default_value' => variable_get('blog_block_count', 10), '#options' => drupal_map_assoc(array(2, 3, 4, 5,...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c6d8ec52dc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_form_submit/7.x
Implement `forum_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for forum_form_forum() and forum_form_container().
File: modules/forum/forum.admin.inc
function forum_form_submit($form, &$form_state) { if ($form['form_id']['#value'] == 'forum_form_container') { $container = TRUE; $type = t('forum container'); } else { $container = FALSE; $type = t('forum'); } $term = (object) $form_state['values']; $status = taxonomy_term_save($term); sw...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c6ee2949f0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_type_update/7.x
I need the code for `comment_node_type_update($info)` in Drupal 7 (modules/comment/comment.module). It must do this: Implements hook_node_type_update().
File: modules/comment/comment.module
function comment_node_type_update($info) { if (!empty($info->old_type) && $info->type != $info->old_type) { field_attach_rename_bundle('comment', 'comment_node_' . $info->old_type, 'comment_node_' . $info->type); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c711800416
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_url_split_prefix/7.x
In Drupal 7, write the function `language_url_split_prefix($path, $languages)` (file includes/language.inc) so that it does the following: Splits the given path into prefix and actual path.
Parse the given path and return the language object identified by the prefix and the actual path. Parameters: - $path: The path to split. - $languages: An array of valid languages. Returns: An array composed of: - A language object corresponding to the identified prefix on success, FALSE otherwise. - The path without...
function language_url_split_prefix($path, $languages) { $args = empty($path) ? array() : explode('/', $path); $prefix = array_shift($args); // Search prefix within enabled languages. foreach ($languages as $language) { if (!empty($language->prefix) && $language->prefix == $prefix) { // Rebuild $path ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c728c55257
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_title_list/7.x
I need the code for `node_title_list($result, $title = NULL)` in Drupal 7 (modules/node/node.module). It must do this: Gathers a listing of links to nodes.
Parameters: - $result: A database result object from a query to fetch node entities. If your query joins the {node_comment_statistics} table so that the comment_count field is available, a title attribute will be added to show the number of comments. - $title: A heading for the resulting list. Returns: A renderable ar...
function node_title_list($result, $title = NULL) { $items = array(); $num_rows = FALSE; foreach ($result as $node) { $items[] = l($node->title, 'node/' . $node->nid, !empty($node->comment_count) ? array('attributes' => array('title' => format_plural($node->comment_count, '1 comment', '@count comments'))) : ar...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c74264e138
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_date_format_type_save/7.x
I need the code for `system_date_format_type_save($type)` in Drupal 7 (modules/system/system.module). It must do this: Saves a date type to the database.
Parameters: - $type: A date type array containing the following keys: - type: The machine-readable name of the date type. - title: The human-readable name of the date type. - locked: A boolean indicating whether or not this date type should be configurable from the user interface. - is_new: A boolean indicating whether...
function system_date_format_type_save($type) { $info = array(); $info['type'] = $type['type']; $info['title'] = $type['title']; $info['locked'] = $type['locked']; // Update date_format table. if (!empty($type['is_new'])) { drupal_write_record('date_format_type', $info); } else { drupal_write_re...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c745c1e9da
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/_format_date_callback/7.x
In Drupal 7, write the function `_format_date_callback(array $matches = NULL, $new_langcode = NULL)` (file includes/common.inc) so that it does the following: Translates a formatted date string.
Callback for preg_replace_callback() within format_date(). File: includes/common.inc
function _format_date_callback(array $matches = NULL, $new_langcode = NULL) { // We cache translations to avoid redundant and rather costly calls to t(). static $cache, $langcode; if (!isset($matches)) { $langcode = $new_langcode; return; } $code = $matches[1]; $string = $matches[2]; if (!isset...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c75637cc72
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.effects.inc/function/image_resize_effect/7.x
Implement `image_resize_effect(&$image, $data)` in PHP for Drupal 7. Required behavior: Image effect callback; Resize an image resource.
Parameters: - $image: An image object returned by image_load(). - $data: An array of attributes to use when performing the resize effect with the following items: - "width": An integer representing the desired width in pixels. - "height": An integer representing the desired height in pixels. Returns: TRUE on success. ...
function image_resize_effect(&$image, $data) { if (!image_resize($image, $data['width'], $data['height'])) { watchdog('image', 'Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c75ad9a422
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_custom_block_form/7.x
In Drupal 7, write the function `block_custom_block_form($edit = array())` (file modules/block/block.module) so that it does the following: Form constructor for the custom block form.
Parameters: - $edit: (optional) An associative array of information retrieved by block_custom_get_block() if an existing block is being edited, or an empty array otherwise. Defaults to array(). File: modules/block/block.module
function block_custom_block_form($edit = array()) { $edit += array( 'info' => '', 'body' => '', ); $form['info'] = array( '#type' => 'textfield', '#title' => t('Block description'), '#default_value' => $edit['info'], '#maxlength' => 64, '#description' => t('A brief description of your ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c761391609
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_css_alter/7.x
In Drupal 7, write the function `locale_css_alter(&$css)` (file modules/locale/locale.module) so that it does the following: Implements hook_css_alter().
This function checks all CSS files currently added via drupal_add_css() and and checks to see if a related right to left CSS file should be included. File: modules/locale/locale.module
function locale_css_alter(&$css) { global $language; // If the current language is RTL, add the CSS file with the RTL overrides. if ($language->direction == LANGUAGE_RTL) { foreach ($css as $data => $item) { // Only provide RTL overrides for files. if ($item['type'] == 'file') { $rtl_path...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c7681caede
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_admin_configure_submit/7.x
I need the code for `block_admin_configure_submit($form, &$form_state)` in Drupal 7 (modules/block/block.admin.inc). It must do this: Form submission handler for block_admin_configure().
File: modules/block/block.admin.inc
function block_admin_configure_submit($form, &$form_state) { if (!form_get_errors()) { $transaction = db_transaction(); try { db_update('block') ->fields(array( 'visibility' => (int) $form_state['values']['visibility'], 'pages' => trim($form_state['values']['pages']), ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c76dab21d6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.effects.inc/function/image_desaturate_effect/7.x
I need the code for `image_desaturate_effect(&$image, $data)` in Drupal 7 (modules/image/image.effects.inc). It must do this: Image effect callback; Desaturate (grayscale) an image resource.
Parameters: - $image: An image object returned by image_load(). - $data: An array of attributes to use when performing the desaturate effect. Returns: TRUE on success. FALSE on failure to desaturate image. File: modules/image/image.effects.inc
function image_desaturate_effect(&$image, $data) { if (!image_desaturate($image)) { watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c77f61a08b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_update_ready_form/7.x
In Drupal 7, write the function `update_manager_update_ready_form($form, &$form_state)` (file modules/update/update.manager.inc) so that it does the following: Form constructor for the update ready form.
Build the form when the site is ready to update (after downloading). This form is an intermediary step in the automated update workflow. It is presented to the site administrator after all the required updates have been downloaded and verified. The point of this page is to encourage the user to backup their site, give...
function update_manager_update_ready_form($form, &$form_state) { if (!_update_manager_check_backends($form, 'update')) { return $form; } $form['backup'] = array( '#prefix' => '<strong>', '#markup' => t('Back up your database and site before you continue. <a href="@backup_url">Learn how</a>.', array('...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c7930799b9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21form.api.php/function/callback_batch_operation/7.x
In Drupal 7, show an example implementation for `callback_batch_operation($MULTIPLE_PARAMS, &$context)` (modules/system/form.api.php): Perform a single batch operation.
Callback for batch_set(). Parameters: - $MULTIPLE_PARAMS: Additional parameters specific to the batch. These are specified in the array passed to batch_set(). - $context: The batch context array, passed by reference. This contains the following properties: - 'finished': A float number between 0 and 1 informing the pro...
function callback_batch_operation($MULTIPLE_PARAMS, &$context) { if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField(); } // For this ex...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-c796594115
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_help/7.x
Implement `path_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().
File: modules/path/path.module
function path_help($path, $arg) { switch ($path) { case 'admin/help#path': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Path module allows you to specify an alias, or custom URL, for any existing internal system path. Aliases should not be confused with URL r...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c79b5aef44
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_project_cache/7.x
In Drupal 7, write the function `update_project_cache($cid)` (file modules/update/update.compare.inc) so that it does the following: Retrieves data from {cache_update} or empties the cache when necessary.
Two very expensive arrays computed by this module are the list of all installed modules and themes (and .info data, project associations, etc), and the current status of the site relative to the currently available releases. These two arrays are cached in the {cache_update} table and used whenever possible. The cache i...
function update_project_cache($cid) { $projects = array(); // On certain paths, we should clear the cache and recompute the projects for // update status of the site to avoid presenting stale information. $q = $_GET['q']; $paths = array( 'admin/modules', 'admin/modules/update', 'admin/appearance'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c7ca28da59
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_toc/7.x
In Drupal 7, write the function `book_toc($bid, $depth_limit, $exclude = array())` (file modules/book/book.module) so that it does the following: Returns an array of book pages in table of contents order.
Parameters: - $bid: The ID of the book whose pages are to be listed. - $depth_limit: Any link deeper than this value will be excluded (along with its children). - $exclude: Optional array of menu link ID values. Any link whose menu link ID is in this array will be excluded (along with its children). Returns: An array ...
function book_toc($bid, $depth_limit, $exclude = array()) { $tree = menu_tree_all_data(book_menu_name($bid)); $toc = array(); _book_toc_recurse($tree, '', $toc, $exclude, $depth_limit); return $toc; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c7f93b1648
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_manager_unique_identifier/7.x
Implement `_update_manager_unique_identifier()` in PHP for Drupal 7. Required behavior: Returns a short unique identifier for this Drupal installation.
Returns: An eight character string uniquely identifying this Drupal installation. File: modules/update/update.module
function _update_manager_unique_identifier() { $id = &drupal_static(__FUNCTION__, ''); if (empty($id)) { $id = substr(hash('sha256', drupal_get_hash_salt()), 0, 8); } return $id; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c80050ee90
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_file_scan_cache/7.x
I need the code for `&_drupal_file_scan_cache()` in Drupal 7 (includes/bootstrap.inc). It must do this: Returns the current list of cached file system scan results.
Returns: An associative array tracking the most recent file scan results for all files that have had scans performed. The keys are the type and name of the item that was searched for, and the values can be either: - Boolean FALSE if the item was not found in the file system. - A string pointing to the location where th...
function &_drupal_file_scan_cache() { $file_scans = &drupal_static(__FUNCTION__, array()); // The file scan results are stored in a persistent cache (in addition to the // static cache) but because this function can be called before the // persistent cache is available, we must merge any items that were found ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c834ca1631
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_schema/7.x
Give me the example code for `hook_schema()` in Drupal 7. Hook description: Define the current version of the database schema.
A Drupal schema definition is an array structure representing one or more tables and their related keys and indexes. A schema is defined by hook_schema() which must live in your module's .install file. This hook is called at install and uninstall time, and in the latter case, it cannot rely on the .module file being l...
function hook_schema() { $schema['node'] = array( // Example (partial) specification for table "node". 'description' => 'The base table for nodes.', 'fields' => array( 'nid' => array( 'description' => 'The primary identifier for a node.', 'type' => 'serial', 'unsigned' => TRU...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-c838914d6a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_admin_paths/7.x
I need the code for `user_admin_paths()` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_admin_paths().
File: modules/user/user.module
function user_admin_paths() { $paths = array( 'user/*/cancel' => TRUE, 'user/*/edit' => TRUE, 'user/*/edit/*' => TRUE, ); return $paths; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c840cff41c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_taxonomy_term_delete/7.x
Implement `taxonomy_taxonomy_term_delete($term)` in PHP for Drupal 7. Required behavior: Implements hook_taxonomy_term_delete().
File: modules/taxonomy/taxonomy.module
function taxonomy_taxonomy_term_delete($term) { if (variable_get('taxonomy_maintain_index_table', TRUE)) { // Clean up the {taxonomy_index} table when terms are deleted. db_delete('taxonomy_index')->condition('tid', $term->tid)->execute(); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c85e375178
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/theme_user_admin_roles/7.x
Implement `theme_user_admin_roles($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the role order and new role form.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/user/user.admin.inc
function theme_user_admin_roles($variables) { $form = $variables['form']; $header = array(t('Name'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2)); foreach (element_children($form['roles']) as $rid) { $name = $form['roles'][$rid]['#role']->name; $row = array(); if (in_array($rid, arr...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c8610ea70f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_date_format_form/7.x
Implement `locale_date_format_form($form, &$form_state, $langcode)` in PHP for Drupal 7. Required behavior: Provide date localization configuration options to users.
File: modules/locale/locale.admin.inc
function locale_date_format_form($form, &$form_state, $langcode) { $languages = locale_language_list('native'); $language_name = $languages[$langcode]; // Display the current language name. $form['language'] = array( '#type' => 'item', '#title' => t('Language'), '#markup' => check_plain($language_n...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c865dda5a4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_overview_form_submit/7.x
In Drupal 7, write the function `field_ui_field_overview_form_submit($form, &$form_state)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Form submission handler for field_ui_field_overview_form().
File: modules/field_ui/field_ui.admin.inc
function field_ui_field_overview_form_submit($form, &$form_state) { $form_values = $form_state['values']['fields']; $entity_type = $form['#entity_type']; $bundle = $form['#bundle']; $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle); $bundle_settings = field_bundle_settings($entity_type, $bundl...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c86ad68e68
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_valid_email_address_alter/7.x
Give me the example code for `hook_valid_email_address_alter(&$valid, $mail)` in Drupal 7. Hook description: Alter core e-mail validation.
This hook is called immediately after core e-mail validation takes place and gives other modules a chance to override it. This is useful in cases where you want to have stricter or looser validation standards than that provided by Drupal core. Parameters: - $valid: Boolean value referencing the validation result. - $m...
function hook_valid_email_address_alter(&$valid, $mail) { if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $mail)) { list($username, $domain) = explode('@', $mail); // Check DNS records. if (checkdnsrr($domain, 'MX')) { $valid = TRUE; } } $valid = FA...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-c8749a78b1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_update_index/7.x
In Drupal 7, show an example implementation for `hook_node_update_index($node)` (modules/node/node.api.php): Act on a node being indexed for searching.
This hook is invoked during search indexing, after node_load(), and after the result of node_view() is added as $node->rendered to the node object. Parameters: - $node: The node being indexed. Returns (string): Additional node information to be indexed. File: modules/node/node.api.php
function hook_node_update_index($node) { $text = ''; $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED)); foreach ($comments as $comment) { $text .= '<h2>' . check_plain($comment->subject) . '...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-c87e6592ac
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_dependencies/7.x
Implement `node_update_dependencies()` in PHP for Drupal 7. Required behavior: Implements hook_update_dependencies().
File: modules/node/node.install
function node_update_dependencies() { // node_update_7006() migrates node data to fields and therefore must run // after all Field modules have been enabled, which happens in // system_update_7027(). It also needs to query the {filter_format} table to // get a list of existing text formats, so it must run after...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c8a8fbe572
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_node_update/7.x
In Drupal 7, write the function `taxonomy_node_update($node)` (file modules/taxonomy/taxonomy.module) so that it does the following: Implements hook_node_update().
File: modules/taxonomy/taxonomy.module
function taxonomy_node_update($node) { // Always rebuild the node's taxonomy index entries on node save. taxonomy_delete_node_index($node); taxonomy_build_node_index($node); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c8a9b9b9ce
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7000/7.x
I need the code for `system_update_7000()` in Drupal 7 (modules/system/system.install). It must do this: Rename blog and forum permissions to be consistent with other content types.
File: modules/system/system.install
function system_update_7000() { $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid"); foreach ($result as $role) { $renamed_permission = $role->perm; $renamed_permission = preg_replace('/(?<=^|,\ )create\ blog\ entries(?=,|$)/', 'create blog content', $renamed_permission); $renamed_perm...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c8e51e494b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/element_set_attributes/7.x
I need the code for `element_set_attributes(array &$element, array $map)` in Drupal 7 (includes/common.inc). It must do this: Sets HTML attributes based on element properties.
Parameters: - $element: The renderable element to process. - $map: An associative array whose keys are element property names and whose values are the HTML attribute names to set for corresponding the property; e.g., array('#propertyname' => 'attributename'). If both names are identical except for the leading '#', then...
function element_set_attributes(array &$element, array $map) { foreach ($map as $property => $attribute) { // If the key is numeric, the attribute name needs to be taken over. if (is_int($property)) { $property = '#' . $attribute; } // Do not overwrite already existing attributes. if (isset(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c8e6d748a9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_field_update_field/7.x
In Drupal 7, write the function `image_field_update_field($field, $prior_field, $has_data)` (file modules/image/image.module) so that it does the following: Implements hook_field_update_field().
File: modules/image/image.module
function image_field_update_field($field, $prior_field, $has_data) { if ($field['type'] != 'image') { return; } // The value of a managed_file element can be an array if #extended == TRUE. $fid_new = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['setti...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c90ff3ca41
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/callback_queue_worker/7.x
Give me the example code for `callback_queue_worker($queue_item_data)` in Drupal 7. Hook description: Work on a single queue item.
Callback for hook_cron_queue_info(). Parameters: - $queue_item_data: The data that was passed to DrupalQueueInterface::createItem() when the item was queued. File: modules/system/system.api.php
function callback_queue_worker($queue_item_data) { $node = node_load($queue_item_data); $node->title = 'Updated title'; node_save($node); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-c939abbba4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_prepare/7.x
Implement `comment_node_prepare($node)` in PHP for Drupal 7. Required behavior: Implements hook_node_prepare().
File: modules/comment/comment.module
function comment_node_prepare($node) { if (!isset($node->comment)) { $node->comment = variable_get("comment_$node->type", COMMENT_NODE_OPEN); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c95f71778b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21path.inc/function/path_get_admin_paths/7.x
I need the code for `path_get_admin_paths()` in Drupal 7 (includes/path.inc). It must do this: Gets a list of administrative and non-administrative paths.
Returns (array): An associative array containing the following keys: 'admin': An array of administrative paths and regular expressions in a format suitable for drupal_match_path(). 'non_admin': An array of non-administrative paths and regular expressions. File: includes/path.inc
function path_get_admin_paths() { $patterns = &drupal_static(__FUNCTION__); if (!isset($patterns)) { $paths = module_invoke_all('admin_paths'); drupal_alter('admin_paths', $paths); // Combine all admin paths into one array, and likewise for non-admin paths, // for easier handling. $patterns = ar...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c97626d2f2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_permission/7.x
Implement `search_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().
File: modules/search/search.module
function search_permission() { return array( 'administer search' => array( 'title' => t('Administer search'), ), 'search content' => array( 'title' => t('Use search'), ), 'use advanced search' => array( 'title' => t('Use advanced search'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c97764bf47
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_array_set_nested_value/7.x
In Drupal 7, write the function `drupal_array_set_nested_value(array &$array, array $parents, $value, $force = FALSE)` (file includes/common.inc) so that it does the following: Sets a value in a nested array with variable depth.
This helper function should be used when the depth of the array element you are changing may vary (that is, the number of parent keys is variable). It is primarily used for form structures and renderable arrays. Example: Parameters: - $array: A reference to the array to modify. - $parents: An array of parent keys, st...
function drupal_array_set_nested_value(array &$array, array $parents, $value, $force = FALSE) { $ref = &$array; foreach ($parents as $parent) { // PHP auto-creates container arrays and NULL entries without error if $ref // is NULL, but throws an error if $ref is set, but not an array. if ($force && isse...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9862706a5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_last_viewed/7.x
In Drupal 7, write the function `node_last_viewed($nid)` (file modules/node/node.module) so that it does the following: Retrieves the timestamp for the current user's last view of a specified node.
Parameters: - $nid: A node ID. Returns: If a node has been previously viewed by the user, the timestamp in seconds of when the last view occurred; otherwise, zero. File: modules/node/node.module
function node_last_viewed($nid) { global $user; $history = &drupal_static(__FUNCTION__, array()); if (!isset($history[$nid])) { $history[$nid] = db_query("SELECT timestamp FROM {history} WHERE uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $nid))->fetchObject(); } return (isset($histo...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c988f0ce25
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_region_content/7.x
Implement `drupal_get_region_content($region = NULL, $delimiter = ' ')` in PHP for Drupal 7. Required behavior: Gets assigned content for a given region.
Parameters: - $region: A specified region to fetch content for. If NULL, all regions will be returned. - $delimiter: Content to be inserted between imploded array elements. File: includes/common.inc
function drupal_get_region_content($region = NULL, $delimiter = ' ') { $content = drupal_add_region_content(); if (isset($region)) { if (isset($content[$region]) && is_array($content[$region])) { return implode($delimiter, $content[$region]); } } else { foreach (array_keys($content) as $region...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9c0b400f4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_formats_reset/7.x
In Drupal 7, write the function `filter_formats_reset()` (file modules/filter/filter.module) so that it does the following: Resets the text format caches.
File: modules/filter/filter.module
function filter_formats_reset() { cache_clear_all('filter_formats', 'cache', TRUE); cache_clear_all('filter_list_format', 'cache', TRUE); drupal_static_reset('filter_list_format'); drupal_static_reset('filter_formats'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9d1378d14
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_custom_block_delete/7.x
In Drupal 7, write the function `block_custom_block_delete($form, &$form_state, $module, $delta)` (file modules/block/block.admin.inc) so that it does the following: Form constructor for the custom block deletion form.
Parameters: - $module: The name of the module that implements the block to be deleted. This should always equal 'block' since it only allows custom blocks to be deleted. - $delta: The unique ID of the block within the context of $module. File: modules/block/block.admin.inc
function block_custom_block_delete($form, &$form_state, $module, $delta) { $block = block_load($module, $delta); $custom_block = block_custom_block_get($block->delta); $form['info'] = array('#type' => 'hidden', '#value' => $custom_block['info'] ? $custom_block['info'] : $custom_block['title']); $form['bid'] = a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9d417ebc6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_value/7.x
I need the code for `xmlrpc_value($data, $type = FALSE)` in Drupal 7 (includes/xmlrpc.inc). It must do this: Turns a data structure into objects with 'data' and 'type' attributes.
Parameters: - $data: The data structure. - $type: Optional type to assign to $data. Returns (object): An XML-RPC data object containing the input $data. File: includes/xmlrpc.inc
function xmlrpc_value($data, $type = FALSE) { $xmlrpc_value = new stdClass(); $xmlrpc_value->data = $data; if (!$type) { $type = xmlrpc_value_calculate_type($xmlrpc_value); } $xmlrpc_value->type = $type; if ($type == 'struct') { // Turn all the values in the array into new xmlrpc_values foreach ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9e05cabfe
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_filter_keyword/7.x
I need the code for `image_filter_keyword($value, $current_pixels, $new_pixels)` in Drupal 7 (modules/image/image.module). It must do this: Accepts a keyword (center, top, left, etc) and returns it as a pixel offset.
Parameters: - $value - $current_pixels - $new_pixels File: modules/image/image.module
function image_filter_keyword($value, $current_pixels, $new_pixels) { switch ($value) { case 'top': case 'left': return 0; case 'bottom': case 'right': return $current_pixels - $new_pixels; case 'center': return $current_pixels / 2 - $new_pixels / 2; } return $value; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9e259f5b9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/_trigger_normalize_node_context/7.x
I need the code for `_trigger_normalize_node_context($type, $node)` in Drupal 7 (modules/trigger/trigger.module). It must do this: Loads associated objects for node triggers.
When an action is called in a context that does not match its type, the object that the action expects must be retrieved. For example, when an action that works on users is called during a node hook implementation, the user object is not available since the node hook call doesn't pass it. So here we load the object the...
function _trigger_normalize_node_context($type, $node) { // Note that comment-type actions are not supported in node contexts, // because we wouldn't know which comment to choose. switch ($type) { // An action that works on users is being called in a node context. // Load the user object of the node's aut...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9e28e079f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_autocomplete_validate/7.x
In Drupal 7, write the function `taxonomy_autocomplete_validate($element, &$form_state)` (file modules/taxonomy/taxonomy.module) so that it does the following: Form element validate handler for taxonomy term autocomplete element.
File: modules/taxonomy/taxonomy.module
function taxonomy_autocomplete_validate($element, &$form_state) { // Autocomplete widgets do not send their tids in the form, so we must detect // them here and process them independently. $value = array(); if ($tags = $element['#value']) { // Collect candidate vocabularies. $field = field_widget_field(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9e3a9378d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_view_page/7.x
In Drupal 7, write the function `user_view_page($account)` (file modules/user/user.module) so that it does the following: Page callback wrapper for user_view().
File: modules/user/user.module
function user_view_page($account) { // An administrator may try to view a non-existent account, // so we give them a 404 (versus a 403 for non-admins). return is_object($account) ? user_view($account) : MENU_NOT_FOUND; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9ecd97291
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/theme_node_add_list/7.x
Implement `theme_node_add_list($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a list of available node types for node creation.
Parameters: - $variables: An associative array containing: - content: An array of content types. File: modules/node/node.pages.inc
function theme_node_add_list($variables) { $content = $variables['content']; $output = ''; if ($content) { $output = '<dl class="node-type-list">'; foreach ($content as $item) { $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>'; $output .= '<dd>' . fil...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9f12a4543
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_overlay_parent_initialize/7.x
In Drupal 7, write the function `overlay_overlay_parent_initialize()` (file modules/overlay/overlay.module) so that it does the following: Implements hook_overlay_parent_initialize().
File: modules/overlay/overlay.module
function overlay_overlay_parent_initialize() { // Let the client side know which paths are administrative. $paths = path_get_admin_paths(); foreach ($paths as &$type) { $type = str_replace('<front>', variable_get('site_frontpage', 'node'), $type); } drupal_add_js(array('overlay' => array('paths' => $paths...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-c9fa0829c0
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_custom_theme/7.x
I need the code for `menu_get_custom_theme($initialize = FALSE)` in Drupal 7 (includes/menu.inc). It must do this: Gets the custom theme for the current page, if there is one.
Parameters: - $initialize: This parameter should only be used internally; it is set to TRUE in order to force the custom theme to be initialized for the current page request. Returns: The machine-readable name of the custom theme, if there is one. File: includes/menu.inc
function menu_get_custom_theme($initialize = FALSE) { $custom_theme = &drupal_static(__FUNCTION__); // Skip this if the site is offline or being installed or updated, since the // menu system may not be correctly initialized then. if ($initialize && !_menu_site_is_offline(TRUE) && (!defined('MAINTENANCE_MODE') ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-c9fc89bc54
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_page_sources/7.x
In Drupal 7, write the function `aggregator_page_sources()` (file modules/aggregator/aggregator.pages.inc) so that it does the following: Page callback: Displays all the feeds used by the aggregator.
Returns: An HTML-formatted string. File: modules/aggregator/aggregator.pages.inc
function aggregator_page_sources() { $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.description, f.image ORDER BY last DESC, f.title'); $output = ''; foreach ($result as...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca09423749
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21password.inc/function/_password_get_count_log2/7.x
Implement `_password_get_count_log2($setting)` in PHP for Drupal 7. Required behavior: Parse the log2 iteration count from a stored hash or setting string.
File: includes/password.inc
function _password_get_count_log2($setting) { $itoa64 = _password_itoa64(); return strpos($itoa64, $setting[3]); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca0eb6999c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_delete_revision/7.x
In Drupal 7, show an example implementation for `hook_field_storage_delete_revision($entity_type, $entity, $fields)` (modules/field/field.api.php): Delete a single revision of field data for an entity.
This hook is invoked from field_attach_delete_revision() to ask the field storage module to delete field revision data. Deleting the current (most recently written) revision is not allowed as has undefined results. Parameters: - $entity_type: The entity type of entity, such as 'node' or 'user'. - $entity: The entity ...
function hook_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_revision_tablename(...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-ca0f941a73
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_help/7.x
I need the code for `filter_help($path, $arg)` in Drupal 7 (modules/filter/filter.module). It must do this: Implements hook_help().
File: modules/filter/filter.module
function filter_help($path, $arg) { switch ($path) { case 'admin/help#filter': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Filter module allows administrators to configure text formats. A text format defines the HTML tags, codes, and other input allowed in c...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-ca17922448
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_update_form_validate/7.x
I need the code for `update_manager_update_form_validate($form, &$form_state)` in Drupal 7 (modules/update/update.manager.inc). It must do this: Form validation handler for update_manager_update_form().
Ensures that at least one project is selected. File: modules/update/update.manager.inc
function update_manager_update_form_validate($form, &$form_state) { if (!empty($form_state['values']['projects'])) { $enabled = array_filter($form_state['values']['projects']); } if (!empty($form_state['values']['disabled_projects'])) { $disabled = array_filter($form_state['values']['disabled_projects']);...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca21c22266
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_js/7.x
Implement `drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALSE)` in PHP for Drupal 7. Required behavior: Returns a themed presentation of all JavaScript code for the current page.
References to JavaScript files are placed in a certain order: first, all 'core' files, then all 'module' and finally all 'theme' JavaScript files are added to the page. Then, all settings are output, followed by 'inline' JavaScript code. If running update.php, all preprocessing is disabled. Note that hook_js_alter(&$j...
function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALSE) { if (!isset($javascript)) { $javascript = drupal_add_js(); } // If no JavaScript items have been added, or if the only JavaScript items // that have been added are JavaScript settings (which don't do anything // without a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca2cc8b894
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.admin.inc/function/_search_get_module_names/7.x
I need the code for `_search_get_module_names()` in Drupal 7 (modules/search/search.admin.inc). It must do this: Helper function to get real module names.
File: modules/search/search.admin.inc
function _search_get_module_names() { $search_info = search_get_info(TRUE); $system_info = system_get_info('module'); $names = array(); foreach ($search_info as $module => $info) { $names[$module] = $system_info[$module]['name']; } asort($names, SORT_STRING); return $names; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca2e3e5bfa
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7066/7.x
Implement `system_update_7066()` in PHP for Drupal 7. Required behavior: Migrate the 'file_directory_temp' variable.
File: modules/system/system.install
function system_update_7066() { $d6_file_directory_temp = variable_get('file_directory_temp', file_directory_temp()); variable_set('file_temporary_path', $d6_file_directory_temp); variable_del('file_directory_temp'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca3763a65f
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_region_content/7.x
I need the code for `drupal_add_region_content($region = NULL, $data = NULL)` in Drupal 7 (includes/common.inc). It must do this: Adds content to a specified region.
Parameters: - $region: Page region the content is added to. - $data: Content to be added. File: includes/common.inc
function drupal_add_region_content($region = NULL, $data = NULL) { static $content = array(); if (isset($region) && isset($data)) { $content[$region][] = $data; } return $content; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca4a24c80c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_cid_parts_alter/7.x
In Drupal 7, show an example implementation for `hook_block_cid_parts_alter(&$cid_parts, $block)` (modules/block/block.api.php): Act on block cache ID (cid) parts before the cid is generated.
This hook allows you to add, remove or modify the custom keys used to generate a block cache ID (by default, these keys are set to the block module and delta). These keys will be combined with the standard ones provided by drupal_render_cid_parts() to generate the final block cache ID. To change the cache granularity ...
function hook_block_cid_parts_alter(&$cid_parts, $block) { global $user; // This example shows how to cache a block based on the user's timezone. $cid_parts[] = $user->timezone; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-ca75f186d1
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_list_system_menus/7.x
In Drupal 7, write the function `menu_list_system_menus()` (file includes/menu.inc) so that it does the following: Returns an array containing the names of system-defined (default) menus.
File: includes/menu.inc
function menu_list_system_menus() { return array( 'navigation' => 'Navigation', 'management' => 'Management', 'user-menu' => 'User menu', 'main-menu' => 'Main menu', ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca7cb46b7b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render_cid_create/7.x
I need the code for `drupal_render_cid_create($elements)` in Drupal 7 (includes/common.inc). It must do this: Creates the cache ID for a renderable element.
This creates the cache ID string, either by returning the #cache['cid'] property if present or by building the cache ID out of the #cache['keys'] and, optionally, the #cache['granularity'] properties. Parameters: - $elements: A renderable array. Returns: The cache ID string, or FALSE if the element may not be cached....
function drupal_render_cid_create($elements) { if (isset($elements['#cache']['cid'])) { return $elements['#cache']['cid']; } elseif (isset($elements['#cache']['keys'])) { $granularity = isset($elements['#cache']['granularity']) ? $elements['#cache']['granularity'] : NULL; // Merge in additional cache ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca7d557897
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_status/7.x
In Drupal 7, write the function `system_status($check = FALSE)` (file modules/system/system.admin.inc) so that it does the following: Menu callback: displays the site status report. Can also be used as a pure check.
Parameters: - $check: If true, only returns a boolean whether there are system status errors. File: modules/system/system.admin.inc
function system_status($check = FALSE) { // Load .install files include_once DRUPAL_ROOT . '/includes/install.inc'; drupal_load_updates(); // Check run-time requirements and status information. $requirements = module_invoke_all('requirements', 'runtime'); usort($requirements, '_system_sort_requirements'); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca7e95e54e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_multiple_cancel_confirm_submit/7.x
I need the code for `user_multiple_cancel_confirm_submit($form, &$form_state)` in Drupal 7 (modules/user/user.module). It must do this: Submit handler for mass-account cancellation form.
File: modules/user/user.module
function user_multiple_cancel_confirm_submit($form, &$form_state) { global $user; if ($form_state['values']['confirm']) { foreach ($form_state['values']['accounts'] as $uid => $value) { // Prevent programmatic form submissions from cancelling user 1. if ($uid <= 1) { continue; } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca8655bc2d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_delete/7.x
I need the code for `shortcut_set_delete($shortcut_set)` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Deletes a shortcut set.
Note that the default set cannot be deleted. Parameters: - $shortcut_set: An object representing the shortcut set to delete. Returns: TRUE if the set was deleted, FALSE otherwise. File: modules/shortcut/shortcut.module
function shortcut_set_delete($shortcut_set) { // Don't allow deletion of the system default shortcut set. if ($shortcut_set->set_name == SHORTCUT_DEFAULT_SET_NAME) { return FALSE; } // First, delete any user assignments for this set, so that each of these // users will go back to using whatever default s...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ca8d9c970d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_block_info/7.x
I need the code for `shortcut_block_info()` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Implements hook_block_info().
File: modules/shortcut/shortcut.module
function shortcut_block_info() { $blocks['shortcuts']['info'] = t('Shortcuts'); // Shortcut blocks can't be cached because each menu item can have a custom // access callback. menu.inc manages its own caching. $blocks['shortcuts']['cache'] = DRUPAL_NO_CACHE; return $blocks; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-caac98d40c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_admin_paths/7.x
I need the code for `openid_admin_paths()` in Drupal 7 (modules/openid/openid.module). It must do this: Implements hook_admin_paths().
File: modules/openid/openid.module
function openid_admin_paths() { $paths = array( 'user/*/openid' => TRUE, 'user/*/openid/delete' => TRUE, ); return $paths; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-cac13965d7
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_bootstrap_page_cache/7.x
Implement `_drupal_bootstrap_page_cache()` in PHP for Drupal 7. Required behavior: Attempts to serve a page from the cache.
File: includes/bootstrap.inc
function _drupal_bootstrap_page_cache() { global $user; // Allow specifying special cache handlers in settings.php, like // using memcached or files for storing cache information. require_once DRUPAL_ROOT . '/includes/cache.inc'; foreach (variable_get('cache_backends', array()) as $include) { require_onc...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cac1db1217
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_edit_form_validate/7.x
In Drupal 7, write the function `field_ui_field_edit_form_validate($form, &$form_state)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Form validation handler for field_ui_field_edit_form().
File: modules/field_ui/field_ui.admin.inc
function field_ui_field_edit_form_validate($form, &$form_state) { // Take the incoming values as the $instance definition, so that the 'default // value' gets validated using the instance settings being submitted. $instance = $form_state['values']['instance']; $field_name = $instance['field_name']; if (isset...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cad373a7c7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_rdf_mapping/7.x
In Drupal 7, write the function `poll_rdf_mapping()` (file modules/poll/poll.module) so that it does the following: Implements hook_rdf_mapping().
File: modules/poll/poll.module
function poll_rdf_mapping() { return array( array( 'type' => 'node', 'bundle' => 'poll', 'mapping' => array( 'rdftype' => array('sioc:Post', 'sioct:Poll'), ), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-cad39ba8e2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_admin_paths/7.x
I need the code for `shortcut_admin_paths()` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Implements hook_admin_paths().
File: modules/shortcut/shortcut.module
function shortcut_admin_paths() { $paths = array( 'user/*/shortcuts' => TRUE, ); return $paths; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-cadd3cfb0e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/_comment_body_field_create/7.x
Implement `_comment_body_field_create($info)` in PHP for Drupal 7. Required behavior: Creates a comment_body field instance for a given node type.
File: modules/comment/comment.module
function _comment_body_field_create($info) { // Create the field if needed. if (!field_read_field('comment_body', array('include_inactive' => TRUE))) { $field = array( 'field_name' => 'comment_body', 'type' => 'text_long', 'entity_types' => array('comment'), ); field_create_field($fiel...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cadf4a3b09
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_import_form_submit/7.x
Implement `locale_translate_import_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process the locale import form submission.
File: modules/locale/locale.admin.inc
function locale_translate_import_form_submit($form, &$form_state) { $validators = array('file_validate_extensions' => array('po')); // Ensure we have the file uploaded if ($file = file_save_upload('file', $validators)) { // Add language, if not yet supported drupal_static_reset('language_list'); $lan...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-caf2453b33
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21tablesort.inc/function/tablesort_get_order/7.x
In Drupal 7, write the function `tablesort_get_order($headers)` (file includes/tablesort.inc) so that it does the following: Determines the current sort criterion.
Parameters: - $headers: An array of column headers in the format described in theme_table(). Returns: An associative array describing the criterion, containing the keys: - "name": The localized title of the table column. - "sql": The name of the database field to sort on. File: includes/tablesort.inc
function tablesort_get_order($headers) { $order = isset($_GET['order']) ? $_GET['order'] : ''; foreach ($headers as $header) { if (is_array($header)) { if (isset($header['data']) && $order == $header['data']) { $default = $header; break; } if (empty($default) && isset($header[...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cb17f79a14
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_prepare_response/7.x
Implement `ajax_prepare_response($page_callback_result)` in PHP for Drupal 7. Required behavior: Converts the return value of a page callback into an Ajax commands array.
Parameters: - $page_callback_result: The result of a page callback. Can be one of: - NULL: to indicate no content. - An integer menu status constant: to indicate an error condition. - A string of HTML content. - A renderable array of content. Returns: An Ajax commands array that can be passed to ajax_render(). File: ...
function ajax_prepare_response($page_callback_result) { $commands = array(); if (!isset($page_callback_result)) { // Simply delivering an empty commands array is sufficient. This results // in the Ajax request being completed, but nothing being done to the page. } elseif (is_int($page_callback_result)) ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cb5a3cd029
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21image.inc/function/image_scale_and_crop/7.x
In Drupal 7, write the function `image_scale_and_crop(stdClass $image, $width, $height)` (file includes/image.inc) so that it does the following: Scales an image to the exact width and height given.
This function achieves the target aspect ratio by cropping the original image equally on both sides, or equally on the top and bottom. This function is useful to create uniform sized avatars from larger images. The resulting image always has the exact target dimensions. Parameters: - $image: An image object returned ...
function image_scale_and_crop(stdClass $image, $width, $height) { $scale = max($width / $image->info['width'], $height / $image->info['height']); $x = ($image->info['width'] * $scale - $width) / 2; $y = ($image->info['height'] * $scale - $height) / 2; if (image_resize($image, $image->info['width'] * $scale, $i...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cb6f1ec3c5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_form_node_form_alter/7.x
I need the code for `book_form_node_form_alter(&$form, &$form_state, $form_id)` in Drupal 7 (modules/book/book.module). It must do this: Implements hook_form_BASE_FORM_ID_alter() for node_form().
Adds the book fieldset to the node form. File: modules/book/book.module
function book_form_node_form_alter(&$form, &$form_state, $form_id) { $node = $form['#node']; $access = user_access('administer book outlines'); if (!$access) { if (user_access('add content to books') && ((!empty($node->book['mlid']) && !empty($node->nid)) || book_type_is_allowed($node->type))) { // Alre...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-cb7b3eefd8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/theme_rdf_metadata/7.x
In Drupal 7, write the function `theme_rdf_metadata($variables)` (file modules/rdf/rdf.module) so that it does the following: Returns HTML for a series of empty spans for exporting RDF metadata in RDFa.
Sometimes it is useful to export data which is not semantically present in the HTML output. For example, a hierarchy of comments is visible for a human but not for machines because this hiearchy is not present in the DOM tree. We can express it in RDFa via empty <span> tags. These aren't visible and give machines extra...
function theme_rdf_metadata($variables) { $output = ''; foreach ($variables['metadata'] as $attributes) { // Add a class so that developers viewing the HTML source can see why there // are empty <span> tags in the document. $attributes['class'][] = 'rdf-meta'; $attributes['class'][] = 'element-hidde...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cb9c680f9b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/_drupal_flush_css_js/7.x
In Drupal 7, write the function `_drupal_flush_css_js()` (file includes/common.inc) so that it does the following: Changes the dummy query string added to all CSS and JavaScript files.
Changing the dummy query string appended to CSS and JavaScript files forces all browsers to reload fresh files. File: includes/common.inc
function _drupal_flush_css_js() { // The timestamp is converted to base 36 in order to make it more compact. variable_set('css_js_query_string', base_convert(REQUEST_TIME, 10, 36)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cbb4c8c314
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/theme_file_formatter_table/7.x
I need the code for `theme_file_formatter_table($variables)` in Drupal 7 (modules/file/file.field.inc). It must do this: Returns HTML for a file attachments table.
Parameters: - $variables: An associative array containing: - items: An array of file attachments. File: modules/file/file.field.inc
function theme_file_formatter_table($variables) { $header = array(t('Attachment'), t('Size')); $rows = array(); foreach ($variables['items'] as $delta => $item) { $rows[] = array( theme('file_link', array('file' => (object) $item)), format_size($item['filesize']), ); } return empty($rows)...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cbb84082bb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7076/7.x
In Drupal 7, write the function `system_update_7076()` (file modules/system/system.install) so that it does the following: Convert menu_links query strings into arrays.
File: modules/system/system.install
function system_update_7076() { $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC)) ->fields('ml', array('mlid', 'options')); foreach ($query->execute() as $menu_link) { if (strpos($menu_link['options'], 'query') !== FALSE) { $menu_link['options'] = unserialize($menu_link['optio...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cbd7f0ecf2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/template_preprocess_field/7.x
I need the code for `template_preprocess_field(&$variables, $hook)` in Drupal 7 (modules/field/field.module). It must do this: Theme preprocess function for theme_field() and field.tpl.php.
File: modules/field/field.module
function template_preprocess_field(&$variables, $hook) { $element = $variables['element']; // There's some overhead in calling check_plain() so only call it if the label // variable is being displayed. Otherwise, set it to NULL to avoid PHP // warnings if a theme implementation accesses the variable even when ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cbdf3c768e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_base_page_theme/7.x
Implement `ajax_base_page_theme()` in PHP for Drupal 7. Required behavior: Theme callback for Ajax requests.
Many different pages can invoke an Ajax request to system/ajax or another generic Ajax path. It is almost always desired for an Ajax response to be rendered using the same theme as the base page, because most themes are built with the assumption that they control the entire page, so if the CSS for two themes are both l...
function ajax_base_page_theme() { if (!empty($_POST['ajax_page_state']['theme']) && !empty($_POST['ajax_page_state']['theme_token'])) { $theme = $_POST['ajax_page_state']['theme']; $token = $_POST['ajax_page_state']['theme_token']; // Prevent a request forgery from giving a person access to a theme they ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cbeb50243f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_verify_assertion_signature/7.x
Implement `openid_verify_assertion_signature($service, $association, $response)` in PHP for Drupal 7. Required behavior: Verify the signature of the response received from the OpenID provider.
Parameters: - $service: Array describing the OpenID provider. - $association: Information on the association with the OpenID provider. - $response: Array of response values from the provider. Returns: TRUE if the signature is valid and covers all fields required to be signed. File: modules/openid/openid.module
function openid_verify_assertion_signature($service, $association, $response) { if ($service['version'] == 2) { // OpenID Authentication 2.0, section 10.1: // These keys must always be signed. $mandatory_keys = array('op_endpoint', 'return_to', 'response_nonce', 'assoc_handle'); if (isset($response['o...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-cbfe46e9d1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_info/7.x
Give me the example code for `hook_field_info()` in Drupal 7. Hook description: Define Field API field types.
Along with this hook, you also need to implement other hooks. See Returns: An array whose keys are field type names and whose values are arrays describing the field type, with the following key/value pairs: - label: The human-readable name of the field type. - description: A short description for the field type. - set...
function hook_field_info() { return array( 'text' => array( 'label' => t('Text'), 'description' => t('This field stores varchar text in the database.'), 'settings' => array('max_length' => 255), 'instance_settings' => array('text_processing' => 0), 'default_widget' => 'text_textfield...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-cbff19687d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_terms_static_reset/7.x
Implement `taxonomy_terms_static_reset()` in PHP for Drupal 7. Required behavior: Clear all static cache variables for terms.
File: modules/taxonomy/taxonomy.module
function taxonomy_terms_static_reset() { drupal_static_reset('taxonomy_term_count_nodes'); drupal_static_reset('taxonomy_get_tree'); drupal_static_reset('taxonomy_get_tree:parents'); drupal_static_reset('taxonomy_get_tree:terms'); drupal_static_reset('taxonomy_get_parents'); drupal_static_reset('taxonomy_ge...
[ "code-task", "function" ]
2026-09-30T00:00:00