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-2ac84fd9a1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_logout/7.x
Implement `user_logout()` in PHP for Drupal 7. Required behavior: Menu callback; logs the current user out, and redirects to the home page.
File: modules/user/user.pages.inc
function user_logout() { user_logout_current_user(); drupal_goto(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ad926d0fb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_field_cache/7.x
I need the code for `_field_info_field_cache()` in Drupal 7 (modules/field/field.info.inc). It must do this: Retrieves the FieldInfo object for the current request.
Returns: FieldInfo An instance of the FieldInfo class. File: modules/field/field.info.inc
function _field_info_field_cache() { // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { $drupal_static_fast['field_info_field_cache'] = &drupal_static(__FUNCTION__); } $field_info = &$drupal_static_fast['field_info_...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2afd84b007
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_exit/7.x
I need the code for `drupal_exit($destination = NULL)` in Drupal 7 (includes/common.inc). It must do this: Performs end-of-request tasks.
In some cases page requests need to end without calling drupal_page_footer(). In these cases, call drupal_exit() instead. There should rarely be a reason to call exit instead of drupal_exit(); Parameters: - $destination: If this function is called from drupal_goto(), then this argument will be a fully-qualified URL th...
function drupal_exit($destination = NULL) { if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) { if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') { module_invoke_all('exit', $destination); } drupal_session_commit(); } exit; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2afe329ab7
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21image.inc/function/image_resize/7.x
In Drupal 7, write the function `image_resize(stdClass $image, $width, $height)` (file includes/image.inc) so that it does the following: Resizes an image to the given dimensions (ignoring aspect ratio).
Parameters: - $image: An image object returned by image_load(). - $width: The target width, in pixels. - $height: The target height, in pixels. Returns: TRUE on success, FALSE on failure. File: includes/image.inc
function image_resize(stdClass $image, $width, $height) { $width = (int) round($width); $height = (int) round($height); return image_toolkit_invoke('resize', $image, array($width, $height)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2afea4f6c3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_edit_menu/7.x
Implement `menu_edit_menu($form, &$form_state, $type, $menu = array())` in PHP for Drupal 7. Required behavior: Menu callback; Build the form that handles the adding/editing of a custom menu.
File: modules/menu/menu.admin.inc
function menu_edit_menu($form, &$form_state, $type, $menu = array()) { $system_menus = menu_list_system_menus(); $menu += array( 'menu_name' => '', 'old_name' => !empty($menu['menu_name']) ? $menu['menu_name'] : '', 'title' => '', 'description' => '', ); // Allow menu_edit_menu_submit() and othe...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2b0095f9e3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_edit_form_validate/7.x
In Drupal 7, write the function `locale_translate_edit_form_validate($form, &$form_state)` (file modules/locale/locale.admin.inc) so that it does the following: Validate string editing form submissions.
File: modules/locale/locale.admin.inc
function locale_translate_edit_form_validate($form, &$form_state) { // Locale string check is needed for default textgroup only. $safe_check_needed = $form_state['values']['textgroup'] == 'default'; foreach ($form_state['values']['translations'] as $key => $value) { if ($safe_check_needed && !locale_string_is...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2b012c6b1d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_form_get_state/7.x
I need the code for `field_form_get_state($parents, $field_name, $langcode, &$form_state)` in Drupal 7 (modules/field/field.form.inc). It must do this: Retrieves processing information about a field from $form_state.
Parameters: - $parents: The array of #parents where the field lives in the form. - $field_name: The field name. - $langcode: The language in which the field values are entered. - $form_state: The form state. Returns: An array with the following key/data pairs: - field: the field definition array, - instance: the field...
function field_form_get_state($parents, $field_name, $langcode, &$form_state) { $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode); return drupal_array_get_nested_value($form_state, $form_state_parents); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2b2bd10460
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_update_7000/7.x
In Drupal 7, write the function `locale_update_7000()` (file modules/locale/locale.install) so that it does the following: Add context field index and allow longer location.
File: modules/locale/locale.install
function locale_update_7000() { db_drop_index('locales_source', 'source'); db_add_index('locales_source', 'source_context', array(array('source', 30), 'context')); // Also drop the 'textgroup_location' index added by the i18nstrings module // of the i18n project, which prevents the below schema update from run...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2b489ab446
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/_node_mass_update_batch_process/7.x
Implement `_node_mass_update_batch_process($nodes, $updates, &$context)` in PHP for Drupal 7. Required behavior: Implements callback_batch_operation().
Executes a batch operation for node_mass_update(). Parameters: - $nodes (array): An array of node IDs. - $updates (array): Associative array of updates. - $context (array): An array of contextual key/values. File: modules/node/node.admin.inc
function _node_mass_update_batch_process($nodes, $updates, &$context) { if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['max'] = count($nodes); $context['sandbox']['nodes'] = $nodes; } // Process nodes by groups of 5. $count = min(5, count($co...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2b6f5a8525
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_parse_message/7.x
In Drupal 7, write the function `_openid_parse_message($message)` (file modules/openid/openid.inc) so that it does the following: Convert a direct communication message into an associative array.
File: modules/openid/openid.inc
function _openid_parse_message($message) { $parsed_message = array(); $items = explode("\n", $message); foreach ($items as $item) { $parts = explode(':', $item, 2); if (count($parts) == 2) { $parsed_message[$parts[0]] = $parts[1]; } } return $parsed_message; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2b8c39ca11
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21mail.inc/function/_drupal_html_to_mail_urls/7.x
I need the code for `_drupal_html_to_mail_urls($match = NULL, $reset = FALSE)` in Drupal 7 (includes/mail.inc). It must do this: Keeps track of URLs and replaces them with placeholder tokens.
Callback for preg_replace_callback() within drupal_html_to_text(). File: includes/mail.inc
function _drupal_html_to_mail_urls($match = NULL, $reset = FALSE) { global $base_url, $base_path; static $urls = array(), $regexp; if ($reset) { // Reset internal URL list. $urls = array(); } else { if (empty($regexp)) { $regexp = '@^' . preg_quote($base_path, '@') . '@'; } if ($mat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2bcbf5ac97
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_parse_header/7.x
I need the code for `_locale_import_parse_header($header)` in Drupal 7 (includes/locale.inc). It must do this: Parses a Gettext Portable Object file header
Parameters: - $header: A string containing the complete header. Returns: An associative array of key-value pairs. File: includes/locale.inc
function _locale_import_parse_header($header) { $header_parsed = array(); $lines = array_map('trim', explode("\n", $header)); foreach ($lines as $line) { if ($line) { list($tag, $contents) = explode(":", $line, 2); $header_parsed[trim($tag)] = trim($contents); } } return $header_parsed; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c09a6f5e6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_help/7.x
I need the code for `block_help($path, $arg)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_help().
File: modules/block/block.module
function block_help($path, $arg) { switch ($path) { case 'admin/help#block': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Block module allows you to create boxes of content, which are rendered into an area, or region, of one or more pages of a website. The co...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2c2ddb7868
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/template_preprocess_comment/7.x
I need the code for `template_preprocess_comment(&$variables)` in Drupal 7 (modules/comment/comment.module). It must do this: Process variables for comment.tpl.php.
File: modules/comment/comment.module
function template_preprocess_comment(&$variables) { $comment = $variables['elements']['#comment']; $node = $variables['elements']['#node']; $variables['comment'] = $comment; $variables['node'] = $node; $variables['author'] = theme('username', array('account' => $comment)); $variables['created'] ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c385351d7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_get_roles_by_format/7.x
I need the code for `filter_get_roles_by_format($format)` in Drupal 7 (modules/filter/filter.module). It must do this: Retrieves a list of roles that are allowed to use a given text format.
Parameters: - $format: An object representing the text format. Returns: An array of role names, keyed by role ID. File: modules/filter/filter.module
function filter_get_roles_by_format($format) { // Handle the fallback format upfront (all roles have access to this format). if ($format->format == filter_fallback_format()) { return user_roles(); } // Do not list any roles if the permission does not exist. $permission = filter_permission_name($format); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c5842955b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_may_be_available/7.x
Implement `lock_may_be_available($name)` in PHP for Drupal 7. Required behavior: Check if lock acquired by a different process may be available.
If an existing lock has expired, it is removed. Parameters: - $name: The name of the lock. Returns: TRUE if there is no lock or it was removed, FALSE otherwise. File: includes/lock.inc
function lock_may_be_available($name) { $lock = db_query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc(); if (!$lock) { return TRUE; } $expire = (float) $lock['expire']; $now = microtime(TRUE); if ($now > $expire) { // We check two conditions to pre...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c58f5247c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.maintenance.inc/function/theme_authorize_report/7.x
Implement `theme_authorize_report($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a results report of an operation run by authorize.php.
Parameters: - $variables: An associative array containing: - messages: An array of result messages. File: includes/theme.maintenance.inc
function theme_authorize_report($variables) { $messages = $variables['messages']; $output = ''; if (!empty($messages)) { $output .= '<div id="authorize-results">'; foreach ($messages as $heading => $logs) { $items = array(); foreach ($logs as $number => $log_message) { if ($number === ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c89fe44a8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.pages.inc/function/comment_approve/7.x
Implement `comment_approve($cid)` in PHP for Drupal 7. Required behavior: Menu callback; publish specified comment.
Parameters: - $cid: A comment identifier. File: modules/comment/comment.pages.inc
function comment_approve($cid) { if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], "comment/$cid/approve")) { return MENU_ACCESS_DENIED; } if ($comment = comment_load($cid)) { $comment->status = COMMENT_PUBLISHED; comment_save($comment); drupal_set_message(t('Comment approved.'));...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c9099285d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_page_set_cache/7.x
In Drupal 7, write the function `drupal_page_set_cache()` (file includes/common.inc) so that it does the following: Stores the current page in the cache.
If page_compression is enabled, a gzipped version of the page is stored in the cache to avoid compressing the output on each request. The cache entry is unzipped in the relatively rare event that the page is requested by a client without gzip support. Page compression requires the PHP zlib extension (http://php.net/ma...
function drupal_page_set_cache() { global $base_root; if (drupal_page_is_cacheable()) { // Check whether the current page might be compressed. $page_compressed = variable_get('page_compression', TRUE) && extension_loaded('zlib'); $cache = (object) array( 'cid' => $base_root . request_uri(), ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c96570bba
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_get_filename_perform_file_scan/7.x
Implement `_drupal_get_filename_perform_file_scan($type, $name)` in PHP for Drupal 7. Required behavior: Performs a file system scan to search for a system resource.
Parameters: - $type: The type of the item (theme, theme_engine, module, profile). - $name: The name of the item for which the filename is requested. Returns: The filename of the requested item or FALSE if the item is not found. File: includes/bootstrap.inc
function _drupal_get_filename_perform_file_scan($type, $name) { // The location of files will not change during the request, so do not use // drupal_static(). static $dirs = array(), $files = array(); // We have a consistent directory naming: modules, themes... $dir = $type . 's'; if ($type == 'theme_engin...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c96d74247
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21language.api.php/function/hook_language_negotiation_info/7.x
In Drupal 7, show an example implementation for `hook_language_negotiation_info()` (modules/system/language.api.php): Define language negotiation providers.
Returns: An associative array of language negotiation provider definitions. The keys are provider identifiers, and the values are associative arrays defining each provider, with the following elements: - types: An array of allowed language types. If a language negotiation provider does not specify which language types ...
function hook_language_negotiation_info() { return array( 'custom_language_provider' => array( 'callbacks' => array( 'language' => 'custom_language_provider_callback', 'switcher' => 'custom_language_switcher_callback', 'url_rewrite' => 'custom_language_url_rewrite_callback', ),...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-2c98c4c7f7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.admin.inc/function/profile_admin_settings_autocomplete/7.x
In Drupal 7, write the function `profile_admin_settings_autocomplete($string)` (file modules/profile/profile.admin.inc) so that it does the following: Retrieve a pipe delimited string of autocomplete suggestions for profile categories
File: modules/profile/profile.admin.inc
function profile_admin_settings_autocomplete($string) { $matches = array(); $result = db_select('profile_field') ->fields('profile_field', array('category')) ->condition('category', db_like($string) . '%', 'LIKE') ->range(0, 10) ->execute(); foreach ($result as $data) { $matches[$data->catego...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2c9bda2b32
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_node_get_translations/7.x
Implement `translation_node_get_translations($tnid)` in PHP for Drupal 7. Required behavior: Gets all nodes in a given translation set.
Parameters: - $tnid: The translation source nid of the translation set, the identifier of the node used to derive all translations in the set. Returns (Array): of partial node objects (nid, title, language) representing all nodes in the translation set, in effect all translations of node $tnid, including node $tnid it...
function translation_node_get_translations($tnid) { if (is_numeric($tnid) && $tnid) { $translations = &drupal_static(__FUNCTION__, array()); if (!isset($translations[$tnid])) { $translations[$tnid] = array(); $result = db_select('node', 'n') ->fields('n', array('nid', 'type', 'uid', 'stat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2caca1ec89
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_actions_delete_form/7.x
I need the code for `system_actions_delete_form($form, &$form_state, $action)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Create the form for confirmation of deleting an action.
File: modules/system/system.admin.inc
function system_actions_delete_form($form, &$form_state, $action) { $form['aid'] = array( '#type' => 'hidden', '#value' => $action->aid, ); return confirm_form($form, t('Are you sure you want to delete the action %action?', array('%action' => $action->label)), 'admin/config/system/actions/manage',...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2cbdc955ed
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21registry.inc/function/_registry_parse_files/7.x
I need the code for `_registry_parse_files($files)` in Drupal 7 (includes/registry.inc). It must do this: Parse all changed files and save their interface and class listings.
Parse all files that have changed since the registry was last built, and save their interface and class listings. Parameters: - $files: The list of files to check and parse. File: includes/registry.inc
function _registry_parse_files($files) { $parsed_files = array(); foreach ($files as $filename => $file) { if (file_exists($filename)) { $hash = hash_file('sha256', $filename); if (empty($file['hash']) || $file['hash'] != $hash) { $file['hash'] = $hash; $parsed_files[$filename] = $fi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2cc6369868
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_get_parents_all/7.x
I need the code for `taxonomy_get_parents_all($tid)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Find all ancestors of a given term ID.
File: modules/taxonomy/taxonomy.module
function taxonomy_get_parents_all($tid) { $cache = &drupal_static(__FUNCTION__, array()); if (isset($cache[$tid])) { return $cache[$tid]; } $parents = array(); if ($term = taxonomy_term_load($tid)) { $parents[] = $term; $n = 0; while ($parent = taxonomy_get_parents($parents[$n]->tid)) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ccccf7912
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/drupal_find_theme_templates/7.x
I need the code for `drupal_find_theme_templates($cache, $extension, $path)` in Drupal 7 (includes/theme.inc). It must do this: Allows themes and/or theme engines to easily discover overridden templates.
Parameters: - $cache: The existing cache of theme hooks to test against. - $extension: The extension that these templates will have. - $path: The path to search. File: includes/theme.inc
function drupal_find_theme_templates($cache, $extension, $path) { $implementations = array(); // Collect paths to all sub-themes grouped by base themes. These will be // used for filtering. This allows base themes to have sub-themes in its // folder hierarchy without affecting the base themes template discover...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ce222d3ea
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_export_screen/7.x
Implement `locale_translate_export_screen()` in PHP for Drupal 7. Required behavior: User interface for the translation export screen.
File: modules/locale/locale.admin.inc
function locale_translate_export_screen() { // Get all languages, except English drupal_static_reset('language_list'); $names = locale_language_list('name'); unset($names['en']); $output = ''; // Offer translation export if any language is set up. if (count($names)) { $elements = drupal_get_form('loca...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ce98b9041
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_theme/7.x
I need the code for `options_theme()` in Drupal 7 (modules/field/modules/options/options.module). It must do this: Implements hook_theme().
File: modules/field/modules/options/options.module
function options_theme() { return array( 'options_none' => array( 'variables' => array('instance' => NULL, 'option' => NULL), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2d0ac726c2
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_vertical_tabs/7.x
In Drupal 7, write the function `theme_vertical_tabs($variables)` (file includes/form.inc) so that it does the following: Returns HTML for an element's children fieldsets as vertical tabs.
Parameters: - $variables: An associative array containing: - element: An associative array containing the properties and children of the fieldset. Properties used: #children. File: includes/form.inc
function theme_vertical_tabs($variables) { $element = $variables['element']; // Add required JavaScript and Stylesheet. drupal_add_library('system', 'drupal.vertical-tabs'); $output = '<h2 class="element-invisible">' . t('Vertical Tabs') . '</h2>'; $output .= '<div class="vertical-tabs-panes">' . $element['#...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2d0c6af0d3
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_uri_normalize_dot_segments/7.x
Implement `file_uri_normalize_dot_segments($uri)` in PHP for Drupal 7. Required behavior: Normalize dot segments in a URI.
Parameters: - $uri: A stream, referenced as "scheme://target". Returns (string): The URI with dot segments removed and slashes as directory separator. File: includes/file.inc
function file_uri_normalize_dot_segments($uri) { $scheme = file_uri_scheme($uri); if (file_stream_wrapper_valid_scheme($scheme)) { $target = file_uri_target($uri); if ($target !== FALSE) { if (!in_array($scheme, variable_get('file_sa_core_2023_005_schemes', array()))) { $class = file_stream_...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2d0e48a8c0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_7002/7.x
In Drupal 7, write the function `forum_update_7002()` (file modules/forum/forum.install) so that it does the following: Add new index to forum_index table.
File: modules/forum/forum.install
function forum_update_7002() { db_drop_index('forum_index', 'forum_topics'); db_add_index('forum_index', 'forum_topics', array('nid', 'tid', 'sticky', 'last_comment_timestamp')); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2d2167715d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/dblog_watchdog/7.x
Implement `dblog_watchdog(array $log_entry)` in PHP for Drupal 7. Required behavior: Implements hook_watchdog().
Note: Some values may be truncated to meet database column size restrictions. File: modules/dblog/dblog.module
function dblog_watchdog(array $log_entry) { if (!function_exists('drupal_substr')) { require_once DRUPAL_ROOT . '/includes/unicode.inc'; } try { Database::getConnection('default', 'default')->insert('watchdog') ->fields(array( 'uid' => $log_entry['uid'], 'type' => drupal_substr($log_...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2d274e28a9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_admin_paths/7.x
In Drupal 7, write the function `node_admin_paths()` (file modules/node/node.module) so that it does the following: Implements hook_admin_paths().
File: modules/node/node.module
function node_admin_paths() { if (variable_get('node_admin_theme')) { $paths = array( 'node/*/edit' => TRUE, 'node/*/delete' => TRUE, 'node/*/revisions' => TRUE, 'node/*/revisions/*/revert' => TRUE, 'node/*/revisions/*/delete' => TRUE, 'node/add' => TRUE, 'node/add/*' => ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2d324e6b6e
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_info/7.x
Implement `field_sql_storage_field_storage_info()` in PHP for Drupal 7. Required behavior: Implements hook_field_storage_info().
File: modules/field/modules/field_sql_storage/field_sql_storage.module
function field_sql_storage_field_storage_info() { return array( 'field_sql_storage' => array( 'label' => t('Default SQL storage'), 'description' => t('Stores fields in the local SQL database, using per-field tables.'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2d4bad5dec
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.api.php/function/hook_taxonomy_term_load/7.x
Give me the example code for `hook_taxonomy_term_load($terms)` in Drupal 7. Hook description: Act on taxonomy terms when loaded.
Modules implementing this hook can act on the term objects returned by taxonomy_term_load_multiple(). For performance reasons, information to be added to term objects should be loaded in a single query for all terms where possible. Since terms are stored and retrieved from cache during a page request, avoid altering ...
function hook_taxonomy_term_load($terms) { $result = db_select('mytable', 'm') ->fields('m', array('tid', 'foo')) ->condition('m.tid', array_keys($terms), 'IN') ->execute(); foreach ($result as $record) { $terms[$record->tid]->foo = $record->foo; } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-2d4e6284e4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_site_information_settings/7.x
I need the code for `system_site_information_settings()` in Drupal 7 (modules/system/system.admin.inc). It must do this: Form builder; The general site information form.
File: modules/system/system.admin.inc
function system_site_information_settings() { $form['site_information'] = array( '#type' => 'fieldset', '#title' => t('Site details'), ); $form['site_information']['site_name'] = array( '#type' => 'textfield', '#title' => t('Site name'), '#default_value' => variable_get('site_name', 'Drupal'),...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2d551730f9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.pages.inc/function/book_export_html/7.x
In Drupal 7, write the function `book_export_html($nid)` (file modules/book/book.pages.inc) so that it does the following: Generates HTML for export when invoked by book_export().
The given node is embedded to its absolute depth in a top level section. For example, a child node with depth 2 in the hierarchy is contained in (otherwise empty) <div> elements corresponding to depth 0 and depth 1. This is intended to support WYSIWYG output - e.g., level 3 sections always look like level 3 sections, n...
function book_export_html($nid) { if (user_access('access printer-friendly version')) { $node = node_load($nid); if (isset($node->book)) { $tree = book_menu_subtree_data($node->book); $contents = book_export_traverse($tree, 'book_node_export'); return theme('book_export_html', array('title' ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2d7039bea4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/_contact_personal_tab_access/7.x
Implement `_contact_personal_tab_access($account)` in PHP for Drupal 7. Required behavior: Menu access callback for a user's personal contact form.
Parameters: - $account: The user object of the user whose contact form is being requested. File: modules/contact/contact.module
function _contact_personal_tab_access($account) { global $user; // Anonymous users cannot have contact forms. if (!$account->uid) { return FALSE; } // User administrators should always have access to personal contact forms. if (user_access('administer users')) { return TRUE; } // Users may no...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2d779fd188
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_help/7.x
Implement `field_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().
File: modules/field/field.module
function field_help($path, $arg) { switch ($path) { case 'admin/help#field': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Field module allows custom data fields to be defined for <em>entity</em> types (entities include content items, comments, user accounts, ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2d8df769ea
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/theme_filter_admin_format_filter_order/7.x
I need the code for `theme_filter_admin_format_filter_order($variables)` in Drupal 7 (modules/filter/filter.admin.inc). It must do this: Returns HTML for a text format's filter order form.
Parameters: - $variables: An associative array containing: - element: A render element representing the form. File: modules/filter/filter.admin.inc
function theme_filter_admin_format_filter_order($variables) { $element = $variables['element']; // Filter order (tabledrag). $rows = array(); foreach (element_children($element, TRUE) as $name) { $element[$name]['weight']['#attributes']['class'][] = 'filter-order-weight'; $rows[] = array( 'data' ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2d9bb82c33
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_role_update/7.x
In Drupal 7, show an example implementation for `hook_user_role_update($role)` (modules/user/user.api.php): Respond to updates to a user role.
Modules implementing this hook can act on the user role object when updated. It's recommended that you implement this hook if your module adds additional data to user roles object. The module should save its custom additions to the database. Parameters: - $role: A user role object. File: modules/user/user.api.php
function hook_user_role_update($role) { // Save extra fields provided by the module to user roles. db_merge('my_module_table') ->key(array('rid' => $role->rid)) ->fields(array( 'role_description' => $role->description )) ->execute(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-2da03bdb2a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load_by_mail/7.x
In Drupal 7, write the function `user_load_by_mail($mail)` (file modules/user/user.module) so that it does the following: Fetch a user object by email address.
Parameters: - $mail: String with the account's e-mail address. 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_mail($mail) { $users = user_load_multiple(array(), array('mail' => $mail)); return reset($users); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2db23f3c25
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_update/7.x
Implement `file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items)` in PHP for Drupal 7. Required behavior: Implements hook_field_update().
Checks for files that have been removed from the object. File: modules/file/file.field.inc
function file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { // Check whether the field is defined on the object. if (!isset($entity->{$field['field_name']})) { // We cannot check for removed files if the field is not defined. return; } list($id, $vid, $bundle) = entity_ex...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2ddb3028fc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_page_last/7.x
In Drupal 7, write the function `aggregator_page_last()` (file modules/aggregator/aggregator.pages.inc) so that it does the following: Page callback: Displays the most recent items gathered from any feed.
Returns: The rendered list of items for the feed. File: modules/aggregator/aggregator.pages.inc
function aggregator_page_last() { drupal_add_feed('aggregator/rss', variable_get('site_name', 'Drupal') . ' ' . t('aggregator')); $items = aggregator_feed_items_load('sum'); return _aggregator_page_list($items, arg(1)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2defe6517e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_retrieve_form/7.x
In Drupal 7, write the function `drupal_retrieve_form($form_id, &$form_state)` (file includes/form.inc) so that it does the following: Retrieves the structured array that defines a given form.
Parameters: - $form_id: The unique string identifying the desired form. If a function with that name exists, it is called to build the form array. Modules that need to generate the same form (or very similar forms) using different $form_ids can implement hook_forms(), which maps different $form_id values to the proper ...
function drupal_retrieve_form($form_id, &$form_state) { $forms = &drupal_static(__FUNCTION__); // Record the $form_id. $form_state['build_info']['form_id'] = $form_id; // Record the filepath of the include file containing the original form, so // the form builder callbacks can be loaded when the form is bei...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e00f0816c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/_field_sort_items_value_helper/7.x
In Drupal 7, write the function `_field_sort_items_value_helper($a, $b)` (file modules/field/field.module) so that it does the following: Same as above, using ['_weight']['#value']
File: modules/field/field.module
function _field_sort_items_value_helper($a, $b) { $a_weight = (is_array($a) && isset($a['_weight']['#value']) ? $a['_weight']['#value'] : 0); $b_weight = (is_array($b) && isset($b['_weight']['#value']) ? $b['_weight']['#value'] : 0); return $a_weight - $b_weight; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e107a1ab5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_delete_date_format_type_form_submit/7.x
In Drupal 7, write the function `system_delete_date_format_type_form_submit($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Delete a configured date type.
File: modules/system/system.admin.inc
function system_delete_date_format_type_form_submit($form, &$form_state) { if ($form_state['values']['confirm']) { $type_info = system_get_date_types($form_state['values']['format_type']); system_date_format_type_delete($form_state['values']['format_type']); drupal_set_message(t('Removed date type %type.'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e349c1023
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_install_tasks/7.x
Give me the example code for `hook_install_tasks(&$install_state)` in Drupal 7. Hook description: Return an array of tasks to be performed by an installation profile.
Any tasks you define here will be run, in order, after the installer has finished the site configuration step but before it has moved on to the final import of languages and the end of the installation. This is invoked by install_tasks(). You can have any number of custom tasks to perform during this phase. Each task...
function hook_install_tasks(&$install_state) { // Here, we define a variable to allow tasks to indicate that a particular, // processor-intensive batch process needs to be triggered later on in the // installation. $myprofile_needs_batch_processing = variable_get('myprofile_needs_batch_processing', FALSE); $t...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-2e3c662c27
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_inactive_message/7.x
Implement `field_ui_inactive_message($entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Displays a message listing the inactive fields of a given bundle.
File: modules/field_ui/field_ui.admin.inc
function field_ui_inactive_message($entity_type, $bundle) { $inactive_instances = field_ui_inactive_instances($entity_type, $bundle); if (!empty($inactive_instances)) { $field_types = field_info_field_types(); $widget_types = field_info_widget_types(); foreach ($inactive_instances as $field_name => $in...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e62f27d42
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_select_options/7.x
In Drupal 7, write the function `form_select_options($element, $choices = NULL)` (file includes/form.inc) so that it does the following: Converts an array of options into HTML, for use in select list form elements.
This function calls itself recursively to obtain the values for each optgroup within the list of options and when the function encounters an object with an 'options' property inside $element['#options']. Parameters: - $element (array): An associative array containing the following key-value pairs: - #multiple: Optiona...
function form_select_options($element, $choices = NULL) { if (!isset($choices)) { $choices = $element['#options']; } // array_key_exists() accommodates the rare event where $element['#value'] is NULL. // isset() fails in this situation. $value_valid = isset($element['#value']) || array_key_exists('#value'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e770ea267
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_uninstall/7.x
I need the code for `locale_uninstall()` in Drupal 7 (modules/locale/locale.install). It must do this: Implements hook_uninstall().
File: modules/locale/locale.install
function locale_uninstall() { // Delete all JavaScript translation files. $locale_js_directory = 'public://' . variable_get('locale_js_directory', 'languages'); if (is_dir($locale_js_directory)) { $files = db_query('SELECT language, javascript FROM {languages}'); foreach ($files as $file) { if (!em...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2e7c80d54c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_effect_info_alter/7.x
In Drupal 7, show an example implementation for `hook_image_effect_info_alter(&$effects)` (modules/image/image.api.php): Alter the information provided in hook_image_effect_info().
Parameters: - $effects: The array of image effects, keyed on the machine-readable effect name. File: modules/image/image.api.php
function hook_image_effect_info_alter(&$effects) { // Override the Image module's crop effect with more options. $effects['image_crop']['effect callback'] = 'mymodule_crop_effect'; $effects['image_crop']['dimensions callback'] = 'mymodule_crop_dimensions'; $effects['image_crop']['form callback'] = 'mymodule_cro...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-2e7ea00e92
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_get_path_alias/7.x
Implement `drupal_get_path_alias($path = NULL, $path_language = NULL)` in PHP for Drupal 7. Required behavior: Given an internal Drupal path, return the alias set by the administrator.
If no path is provided, the function will return the alias of the current page. Parameters: - $path: An internal Drupal path. - $path_language: An optional language code to look up the path in. Returns: An aliased path if one was found, or the original path if no alias was found. File: includes/path.inc
function drupal_get_path_alias($path = NULL, $path_language = NULL) { // If no path is specified, use the current page's path. if ($path == NULL) { $path = $_GET['q']; } $result = $path; if ($alias = drupal_lookup_path('alias', $path, $path_language)) { $result = $alias; } return $result; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e7ed801eb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21session.inc/function/drupal_session_initialize/7.x
In Drupal 7, write the function `drupal_session_initialize()` (file includes/session.inc) so that it does the following: Initializes the session handler, starting a session if needed.
File: includes/session.inc
function drupal_session_initialize() { global $user, $is_https; session_set_save_handler('_drupal_session_open', '_drupal_session_close', '_drupal_session_read', '_drupal_session_write', '_drupal_session_destroy', '_drupal_session_garbage_collection'); // We use !empty() in the following check to ensure that bl...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e8072d289
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21image.inc/function/image_get_toolkit/7.x
I need the code for `image_get_toolkit()` in Drupal 7 (includes/image.inc). It must do this: Gets the name of the currently used toolkit.
Returns (String): containing the name of the selected toolkit, or FALSE on error. File: includes/image.inc
function image_get_toolkit() { static $toolkit; if (!isset($toolkit)) { $toolkits = image_get_available_toolkits(); $toolkit = variable_get('image_toolkit', 'gd'); if (!isset($toolkits[$toolkit]) || !function_exists('image_' . $toolkit . '_load')) { // The selected toolkit isn't available so retu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e89c64284
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/theme_comment_post_forbidden/7.x
Implement `theme_comment_post_forbidden($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a "you can't post comments" notice.
Parameters: - $variables: An associative array containing: - node: The comment node. File: modules/comment/comment.module
function theme_comment_post_forbidden($variables) { $node = $variables['node']; global $user; // Since this is expensive to compute, we cache it so that a page with many // comments only has to query the database once for all the links. $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL); if...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2e931de923
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail_format_display_name/7.x
Implement `drupal_mail_format_display_name($string)` in PHP for Drupal 7. Required behavior: Return a RFC-2822 compliant "display-name" component.
The "display-name" component is used in mail header "Originator" fields (From, Sender, Reply-to) to give a human-friendly description of the address, i.e. From: My Display Name <xyz@example.org>. RFC-822 and RFC-2822 define its syntax and rules. This method gets as input a string to be used as "display-name" and format...
function drupal_mail_format_display_name($string) { // Make sure we don't process html-encoded characters. They may create // unneeded trouble if left encoded, besides they will be correctly // processed if decoded. $string = decode_entities($string); // If string contains non-ASCII characters it must be (sh...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ea86c4c8a
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_css_alter/7.x
Implement `seven_css_alter(&$css)` in PHP for Drupal 7. Required behavior: Implements hook_css_alter().
File: themes/seven/template.php
function seven_css_alter(&$css) { // Use Seven's vertical tabs style instead of the default one. if (isset($css['misc/vertical-tabs.css'])) { $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'seven') . '/vertical-tabs.css'; $css['misc/vertical-tabs.css']['type'] = 'file'; } if (isset($c...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2eafaab565
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_block_latest_poll_view/7.x
I need the code for `poll_block_latest_poll_view($node)` in Drupal 7 (modules/poll/poll.module). It must do this: Return content for 'latest poll' block.
Parameters: - $node: The node object to load. File: modules/poll/poll.module
function poll_block_latest_poll_view($node) { // This is necessary for shared objects because PHP doesn't copy objects, but // passes them by reference. So when the objects are cached it can result in // the wrong output being displayed on subsequent calls. The cloning and // unsetting of $node->content preve...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2eb9f913fb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21pager.inc/function/pager_find_page/7.x
I need the code for `pager_find_page($element = 0)` in Drupal 7 (includes/pager.inc). It must do this: Returns the current page being requested for display within a pager.
Parameters: - $element: An optional integer to distinguish between multiple pagers on one page. Returns: The number of the current requested page, within the pager represented by $element. This is determined from the URL query parameter $_GET['page'], or 0 by default. Note that this number may differ from the actual p...
function pager_find_page($element = 0) { $page = isset($_GET['page']) ? $_GET['page'] : ''; $page_array = explode(',', $page); if (!isset($page_array[$element])) { $page_array[$element] = 0; } return (int) $page_array[$element]; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ebc4934d8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21authorize.inc/function/authorize_filetransfer_form_validate/7.x
I need the code for `authorize_filetransfer_form_validate($form, &$form_state)` in Drupal 7 (includes/authorize.inc). It must do this: Form validation handler for authorize_filetransfer_form().
File: includes/authorize.inc
function authorize_filetransfer_form_validate($form, &$form_state) { // Only validate the form if we have collected all of the user input and are // ready to proceed with updating or installing. if ($form_state['triggering_element']['#name'] != 'process_updates') { return; } if (isset($form_state['values...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ece66a96a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_existing_field_options/7.x
Implement `field_ui_existing_field_options($entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Returns an array of existing fields to be added to a bundle.
File: modules/field_ui/field_ui.admin.inc
function field_ui_existing_field_options($entity_type, $bundle) { $info = array(); $field_types = field_info_field_types(); foreach (field_info_instances() as $existing_entity_type => $bundles) { foreach ($bundles as $existing_bundle => $instances) { // No need to look in the current bundle. if (...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ecfc7f4b9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/format_rss_item/7.x
Implement `format_rss_item($title, $link, $description, $args = array())` in PHP for Drupal 7. Required behavior: Formats a single RSS item.
Arbitrary elements may be added using the $args associative array. File: includes/common.inc
function format_rss_item($title, $link, $description, $args = array()) { $output = "<item>\n"; $output .= ' <title>' . check_plain($title) . "</title>\n"; $output .= ' <link>' . check_url($link) . "</link>\n"; $output .= ' <description>' . check_plain($description) . "</description>\n"; $output .= format_xml_...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ed7397b5a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_theme_settings_validate/7.x
In Drupal 7, write the function `system_theme_settings_validate($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Validator for the system_theme_settings() form.
File: modules/system/system.admin.inc
function system_theme_settings_validate($form, &$form_state) { // Handle file uploads. $validators = array('file_validate_is_image' => array()); // Check for a new uploaded logo. $file = file_save_upload('logo_upload', $validators); if (isset($file)) { // File upload was attempted. if ($file) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ef2f888d5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.install/function/dblog_update_7003/7.x
Implement `dblog_update_7003()` in PHP for Drupal 7. Required behavior: Account for possible legacy systems where dblog was not installed.
File: modules/dblog/dblog.install
function dblog_update_7003() { if (!db_table_exists('watchdog')) { db_create_table('watchdog', drupal_get_schema_unprocessed('dblog', 'watchdog')); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f2bc0eaf6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_teaser/7.x
In Drupal 7, write the function `poll_teaser($node)` (file modules/poll/poll.module) so that it does the following: Creates a simple teaser that lists all the choices.
This is primarily used for RSS. File: modules/poll/poll.module
function poll_teaser($node) { $teaser = NULL; if (is_array($node->choice)) { foreach ($node->choice as $choice) { if ($choice['chtext'] != '') { $teaser .= '* ' . check_plain($choice['chtext']) . "\n"; } } } return $teaser; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f3a3a7830
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/theme_image_widget/7.x
In Drupal 7, write the function `theme_image_widget($variables)` (file modules/image/image.field.inc) so that it does the following: Returns HTML for an image field widget.
Parameters: - $variables: An associative array containing: - element: A render element representing the image field widget. File: modules/image/image.field.inc
function theme_image_widget($variables) { $element = $variables['element']; $output = ''; $output .= '<div class="image-widget form-managed-file clearfix">'; if (isset($element['preview'])) { $output .= '<div class="image-preview">'; $output .= drupal_render($element['preview']); $output .= '</div>...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f44ab99a9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_override_server_variables/7.x
I need the code for `drupal_override_server_variables($variables = array())` in Drupal 7 (includes/bootstrap.inc). It must do this: Sets appropriate server variables needed for command line scripts to work.
This function can be called by command line scripts before bootstrapping Drupal, to ensure that the page loads with the desired server parameters. This is because many parts of Drupal assume that they are running in a web browser and therefore use information from the global PHP $_SERVER variable that does not get set ...
function drupal_override_server_variables($variables = array()) { // Allow the provided URL to override any existing values in $_SERVER. if (isset($variables['url'])) { $url = parse_url($variables['url']); if (isset($url['host'])) { $_SERVER['HTTP_HOST'] = $url['host']; } if (isset($url['path'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f4c2e45d9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.install/function/filter_update_7008/7.x
I need the code for `filter_update_7008()` in Drupal 7 (modules/filter/filter.install). It must do this: Grant usage of all text formats to user roles having the 'administer filters' permission.
File: modules/filter/filter.install
function filter_update_7008() { // Build the list of permissions to grant. $permissions = array(); foreach (db_query('SELECT format FROM {filter_format}')->fetchCol() as $format_id) { if ($format_id != variable_get('filter_fallback_format')) { $permissions[] = 'use text format ' . $format_id; } } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f65949b90
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/_menu_get_menu_weight_delta/7.x
In Drupal 7, write the function `_menu_get_menu_weight_delta($menu_names, $max_delta = NULL)` (file modules/menu/menu.module) so that it does the following: Calculate the delta for the weight element for a given set of menus.
Parameters: - $menu_names (string|array): Menu name or an array of menu names. - $max_delta (int): Optional maximum value. Returns (int): Delta value. File: modules/menu/menu.module
function _menu_get_menu_weight_delta($menu_names, $max_delta = NULL) { if (is_string($menu_names)) { $menu_names = array($menu_names); } $weight_info = db_query("SELECT MAX(weight) AS max_weight, MIN(weight) as min_weight FROM {menu_links} WHERE menu_name IN (:menu_names)", array(':menu_names' => $menu_name...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f6b2ca4ae
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_date/7.x
I need the code for `form_process_date($element)` in Drupal 7 (includes/form.inc). It must do this: Expands a date element into year, month, and day select elements.
File: includes/form.inc
function form_process_date($element) { // Default to current date if (empty($element['#value'])) { $element['#value'] = array( 'day' => format_date(REQUEST_TIME, 'custom', 'j'), 'month' => format_date(REQUEST_TIME, 'custom', 'n'), 'year' => format_date(REQUEST_TIME, 'custom', 'Y'), ); } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f9096e730
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_load/7.x
Implement `menu_load($menu_name)` in PHP for Drupal 7. Required behavior: Load the data for a single custom menu.
Parameters: - $menu_name: The unique name of a custom menu to load. Returns (Array): defining the custom menu, or FALSE if the menu doesn't exist. File: modules/menu/menu.module
function menu_load($menu_name) { $all_menus = menu_load_all(); return isset($all_menus[$menu_name]) ? $all_menus[$menu_name] : FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2f919259d1
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_changed/7.x
Implement `ajax_command_changed($selector, $asterisk = '')` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'changed' command.
This command instructs the client to mark each of the elements matched by the given selector as 'ajax-changed'. This command is implemented by Drupal.ajax.prototype.commands.changed() defined in misc/ajax.js. Parameters: - $selector: A jQuery selector string. If the command is a response to a request from an #ajax fo...
function ajax_command_changed($selector, $asterisk = '') { return array( 'command' => 'changed', 'selector' => $selector, 'asterisk' => $asterisk, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fa1607ae0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_multiple_value_form/7.x
Implement `field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state)` in PHP for Drupal 7. Required behavior: Special handling to create form elements for multiple values.
Handles generic features for multiple fields: - number of widgets - AHAH-'add more' button - drag-n-drop value reordering File: modules/field/field.form.inc
function field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state) { $field_name = $field['field_name']; $parents = $form['#parents']; // Determine the number of widgets to display. switch ($field['cardinality']) { case FIELD_CARDINALITY_UNLIMITED: $field_state = field_for...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fa439cc9e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_admin/7.x
I need the code for `shortcut_set_admin()` in Drupal 7 (modules/shortcut/shortcut.admin.inc). It must do this: Menu page callback: builds the page for administering shortcut sets.
File: modules/shortcut/shortcut.admin.inc
function shortcut_set_admin() { $shortcut_sets = shortcut_sets(); $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 4)); $rows = array(); foreach ($shortcut_sets as $set) { $row = array( check_plain($set->title), l(t('list links'), "admin/config/user-interface/shortcut/$s...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fa8a5a453
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_process_states/7.x
I need the code for `drupal_process_states(&$elements)` in Drupal 7 (includes/common.inc). It must do this: Adds JavaScript to change the state of an element based on another element.
A "state" means a certain property on a DOM element, such as "visible" or "checked". A state can be applied to an element, depending on the state of another element on the page. In general, states depend on HTML attributes and DOM element properties, which change due to user interaction. Since states are driven by Jav...
function drupal_process_states(&$elements) { $elements['#attached']['library'][] = array('system', 'drupal.states'); $elements['#attached']['js'][] = array( 'type' => 'setting', 'data' => array('states' => array('#' . $elements['#id'] => $elements['#states'])), ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fae25f851
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_get_assigned_actions/7.x
I need the code for `trigger_get_assigned_actions($hook)` in Drupal 7 (modules/trigger/trigger.module). It must do this: Gets the action IDs of actions to be executed for a hook.
Parameters: - $hook: The name of the hook being fired. Returns: An array whose keys are action IDs that the user has associated with this trigger, and whose values are arrays containing the action type and label. File: modules/trigger/trigger.module
function trigger_get_assigned_actions($hook) { $actions = &drupal_static(__FUNCTION__, array()); if (!isset($actions[$hook])) { $actions[$hook] = db_query("SELECT ta.aid, a.type, a.label FROM {trigger_assignments} ta LEFT JOIN {actions} a ON ta.aid = a.aid WHERE ta.hook = :hook ORDER BY ta.weight", array( ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2faeb79bd2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_view_alter/7.x
In Drupal 7, show an example implementation for `hook_block_view_alter(&$data, $block)` (modules/block/block.api.php): Perform alterations to the content of a block.
This hook allows you to modify any data returned by hook_block_view(). Note that instead of hook_block_view_alter(), which is called for all blocks, you can also use hook_block_view_MODULE_DELTA_alter() to alter a specific block. Parameters: - $data: The data as returned from the hook_block_view() implementation of t...
function hook_block_view_alter(&$data, $block) { // Remove the contextual links on all blocks that provide them. if (is_array($data['content']) && isset($data['content']['#contextual_links'])) { unset($data['content']['#contextual_links']); } // Add a theme wrapper function defined by the current module to ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-2fb7a614e2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_resize/7.x
I need the code for `image_gd_resize(stdClass $image, $width, $height)` in Drupal 7 (modules/system/image.gd.inc). It must do this: Scale an image to the specified size using GD.
Parameters: - $image: An image object. The $image->resource, $image->info['width'], and $image->info['height'] values will be modified by this call. - $width: The new width of the resized image, in pixels. - $height: The new height of the resized image, in pixels. Returns: TRUE or FALSE, based on success. File: modul...
function image_gd_resize(stdClass $image, $width, $height) { $res = image_gd_create_tmp($image, $width, $height); if (!imagecopyresampled($res, $image->resource, 0, 0, 0, 0, $width, $height, $image->info['width'], $image->info['height'])) { return FALSE; } imagedestroy($image->resource); // Update image...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fbb4fc6e4
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_pre_render_markup/7.x
Implement `drupal_pre_render_markup($elements)` in PHP for Drupal 7. Required behavior: #pre_render callback to append contents in #markup to #children.
This needs to be a #pre_render callback, because eventually assigned #theme_wrappers will expect the element's rendered content in #children. Note that if also a #theme is defined for the element, then the result of the theme callback will override #children. Parameters: - $elements: A structured array using the #mark...
function drupal_pre_render_markup($elements) { $elements['#children'] = $elements['#markup']; return $elements; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fc26fe147
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_instances/7.x
Implement `field_info_instances($entity_type = NULL, $bundle_name = NULL)` in PHP for Drupal 7. Required behavior: Retrieves information about field instances.
Use of this function to retrieve instances across separate bundles (i.e. when the $bundle parameter is NULL) should be avoided when possible, since it loads and statically caches a potentially large array of information. Use field_info_field_map() instead. When retrieving the instances of a specific bundle (i.e. when ...
function field_info_instances($entity_type = NULL, $bundle_name = NULL) { $cache = _field_info_field_cache(); if (!isset($entity_type)) { return $cache->getInstances(); } if (!isset($bundle_name)) { return $cache->getInstances($entity_type); } return $cache->getBundleInstances($entity_type, $bundl...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fccb5ed06
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_encode_message/7.x
I need the code for `_openid_encode_message($message)` in Drupal 7 (modules/openid/openid.inc). It must do this: Encode a message from _openid_create_message for HTTP Post
File: modules/openid/openid.inc
function _openid_encode_message($message) { $encoded_message = ''; $items = explode("\n", $message); foreach ($items as $item) { $parts = explode(':', $item, 2); if (count($parts) == 2) { if ($encoded_message != '') { $encoded_message .= '&'; } $encoded_message .= rawurlencode(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2fd643421e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_filetransfer_info/7.x
Implement `system_filetransfer_info()` in PHP for Drupal 7. Required behavior: Implements hook_filetransfer_info().
File: modules/system/system.module
function system_filetransfer_info() { $backends = array(); // This is the default, will be available on most systems. if (function_exists('ftp_connect')) { $backends['ftp'] = array( 'title' => t('FTP'), 'class' => 'FileTransferFTP', 'file' => 'ftp.inc', 'file path' => 'includes/filetr...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2fe60ed96e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_admin_demo/7.x
Implement `block_admin_demo($theme = NULL)` in PHP for Drupal 7. Required behavior: Menu callback for admin/structure/block/demo.
File: modules/block/block.admin.inc
function block_admin_demo($theme = NULL) { drupal_add_css(drupal_get_path('module', 'block') . '/block.css'); return ''; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2ff1e6584b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_get_any/7.x
Implement `language_negotiation_get_any($provider_id)` in PHP for Drupal 7. Required behavior: Checks if the language negotiation provider is enabled for any language type.
Parameters: - $provider_id: The language negotiation provider ID. Returns: TRUE if there is at least one language type for which the given language provider is enabled, FALSE otherwise. File: includes/language.inc
function language_negotiation_get_any($provider_id) { foreach (language_types_configurable() as $type) { if (language_negotiation_get($type, $provider_id)) { return TRUE; } } return FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-30119df06f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_get_plural/7.x
Implement `locale_get_plural($count, $langcode = NULL)` in PHP for Drupal 7. Required behavior: Returns plural form index for a specific number.
The index is computed from the formula of this language. Parameters: - $count: Number to return plural for. - $langcode: Optional language code to translate to a language other than what is used to display the page. Returns: The numeric index of the plural variant to use for this $langcode and $count combination or -...
function locale_get_plural($count, $langcode = NULL) { global $language; // Used to locally cache the plural formulas for all languages. $plural_formulas = &drupal_static(__FUNCTION__, array()); // Used to store precomputed plural indexes corresponding to numbers // individually for each language. $plural...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-301920ec6f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_update_index/7.x
Give me the example code for `hook_update_index()` in Drupal 7. Hook description: Update the search index for this module.
This hook is called every cron run if search.module is enabled, your module has implemented hook_search_info(), and your module has been set as an active search module on the Search settings page (admin/config/search/settings). It allows your module to add items to the built-in search index using search_index(), or to ...
function hook_update_index() { $limit = (int)variable_get('search_cron_limit', 100); $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit); foreach ($result as $n...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-3025d540ab
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.api.php/function/hook_field_instance_settings_form/7.x
In Drupal 7, show an example implementation for `hook_field_instance_settings_form($field, $instance)` (modules/field_ui/field_ui.api.php): Add settings to an instance field settings form.
Invoked from field_ui_field_edit_form() to allow the module defining the field to add settings for a field instance. Parameters: - $field: The field structure being configured. - $instance: The instance structure being configured. Returns: The form definition for the field instance settings. File: modules/field_ui/f...
function hook_field_instance_settings_form($field, $instance) { $settings = $instance['settings']; $form['text_processing'] = array( '#type' => 'radios', '#title' => t('Text processing'), '#default_value' => $settings['text_processing'], '#options' => array( t('Plain text'), t('Filtered...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-306c96bf95
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_release_all/7.x
In Drupal 7, write the function `lock_release_all($lock_id = NULL)` (file includes/lock.inc) so that it does the following: Release all previously acquired locks.
File: includes/lock.inc
function lock_release_all($lock_id = NULL) { global $locks; $locks = array(); if (empty($lock_id)) { $lock_id = _lock_id(); } db_delete('semaphore') ->condition('value', $lock_id) ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3089b2351c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/template_preprocess_menu_tree/7.x
I need the code for `template_preprocess_menu_tree(&$variables)` in Drupal 7 (includes/menu.inc). It must do this: Implements template_preprocess_HOOK() for theme_menu_tree().
File: includes/menu.inc
function template_preprocess_menu_tree(&$variables) { $variables['#tree'] = $variables['tree']; $variables['tree'] = $variables['tree']['#children']; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-309122a7bd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_uid_optional_load/7.x
In Drupal 7, write the function `user_uid_optional_load($uid = NULL)` (file modules/user/user.module) so that it does the following: Load either a specified or the current user account.
Parameters: - $uid: An optional user ID of the user to load. If not provided, the current user's ID will be used. Returns: A fully-loaded $user object upon successful user load, FALSE if user cannot be loaded. File: modules/user/user.module
function user_uid_optional_load($uid = NULL) { if (!isset($uid)) { $uid = $GLOBALS['user']->uid; } return user_load($uid); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-30ba83f360
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_set_expanded_menus/7.x
Implement `_menu_set_expanded_menus()` in PHP for Drupal 7. Required behavior: Updates a list of menus with expanded items.
File: includes/menu.inc
function _menu_set_expanded_menus() { $names = db_query("SELECT menu_name FROM {menu_links} WHERE expanded <> 0 GROUP BY menu_name")->fetchCol(); variable_set('menu_expanded', $names); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-30c0745357
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_retrieve_file/7.x
In Drupal 7, write the function `system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME)` (file modules/system/system.module) so that it does the following: Attempts to get a file using drupal_http_request and to store it locally.
Parameters: - $url (string): The URL of the file to grab. - $destination (string): Stream wrapper URI specifying where the file should be placed. If a directory path is provided, the file is saved into that directory under its original name. If the path contains a filename as well, that one will be used instead. If thi...
function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME) { $parsed_url = parse_url($url); if (!isset($destination)) { $path = file_build_uri(drupal_basename($parsed_url['path'])); } else { if (is_dir(drupal_realpath($destination))) { // Prevent URIs...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-30c1d58324
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_get_blocks_by_region/7.x
I need the code for `block_get_blocks_by_region($region)` in Drupal 7 (modules/block/block.module). It must do this: Gets a renderable array of a region containing all enabled blocks.
Parameters: - $region: The requested region. Returns: A renderable array of a region containing all enabled blocks. File: modules/block/block.module
function block_get_blocks_by_region($region) { $build = array(); if ($list = block_list($region)) { $build = _block_get_renderable_array($list); } return $build; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-30c459a63e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_prepare_view/7.x
Give me the example code for `hook_entity_prepare_view($entities, $type, $langcode)` in Drupal 7. Hook description: Act on entities as they are being prepared for view.
Allows you to operate on multiple entities as they are being prepared for view. Only use this if attaching the data during the entity_load() phase is not appropriate, for example when attaching other 'entity' style objects. Parameters: - $entities: The entities keyed by entity ID. - $type: The type of entities being l...
function hook_entity_prepare_view($entities, $type, $langcode) { // Load a specific node into the user object for later theming. if ($type == 'user') { $nodes = mymodule_get_user_nodes(array_keys($entities)); foreach ($entities as $uid => $entity) { $entity->user_node = $nodes[$uid]; } } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-30c4bc706d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_array_transpose/7.x
I need the code for `options_array_transpose($array)` in Drupal 7 (modules/field/modules/options/options.module). It must do this: Manipulates a 2D array to reverse rows and columns.
The default data storage for fields is delta first, column names second. This is sometimes inconvenient for field modules, so this function can be used to present the data in an alternate format. Parameters: - $array: The array to be transposed. It must be at least two-dimensional, and the subarrays must all have the ...
function options_array_transpose($array) { $result = array(); if (is_array($array)) { foreach ($array as $key1 => $value1) { if (is_array($value1)) { foreach ($value1 as $key2 => $value2) { if (!isset($result[$key2])) { $result[$key2] = array(); } $result[...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-30d558cf4c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7003/7.x
Implement `system_update_7003()` in PHP for Drupal 7. Required behavior: Update {blocked_ips} with valid IP addresses from {access}.
File: modules/system/system.install
function system_update_7003() { $messages = array(); $type = 'host'; $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array( ':status' => 0, ':type' => $type, )); foreach ($result as $blocked) { if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_N...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-30f5a82720
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_attach_rename_bundle/7.x
I need the code for `field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_field_attach_rename_bundle().
File: modules/field/modules/field_sql_storage/field_sql_storage.module
function field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { // We need to account for deleted or inactive fields and instances. $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle_new), array('include_deleted' => TRUE, 'include_inactive' => ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-310011cdb0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_block_view/7.x
Implement `user_block_view($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_view().
File: modules/user/user.module
function user_block_view($delta = '') { global $user; $block = array(); switch ($delta) { case 'login': // For usability's sake, avoid showing two login forms on one page. if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) { $block['subject'] = t('User login'); $bloc...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00