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-b6c619c6ed
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_mark/7.x
In Drupal 7, write the function `node_mark($nid, $timestamp)` (file modules/node/node.module) so that it does the following: Determines the type of marker to be displayed for a given node.
Parameters: - $nid: Node ID whose history supplies the "last viewed" timestamp. - $timestamp: Time which is compared against node's "last viewed" timestamp. Returns: One of the MARK constants. File: modules/node/node.module
function node_mark($nid, $timestamp) { global $user; $cache = &drupal_static(__FUNCTION__, array()); if (!$user->uid) { return MARK_READ; } if (!isset($cache[$nid])) { $cache[$nid] = node_last_viewed($nid); } if ($cache[$nid] == 0 && $timestamp > NODE_NEW_LIMIT) { return MARK_NEW; } elsei...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b6e55395b1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_form_block_admin_configure_submit/7.x
In Drupal 7, write the function `node_form_block_admin_configure_submit($form, &$form_state)` (file modules/node/node.module) so that it does the following: Form submission handler for node_form_block_admin_configure_alter().
File: modules/node/node.module
function node_form_block_admin_configure_submit($form, &$form_state) { db_delete('block_node_type') ->condition('module', $form_state['values']['module']) ->condition('delta', $form_state['values']['delta']) ->execute(); $query = db_insert('block_node_type')->fields(array('type', 'module', 'delta')); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b6ef7ab89a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_generate_file/7.x
Implement `simpletest_generate_file($filename, $width, $lines, $type = 'binary-text')` in PHP for Drupal 7. Required behavior: Generate test file.
File: modules/simpletest/simpletest.module
function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') { $text = ''; for ($i = 0; $i < $lines; $i++) { // Generate $width - 1 characters to leave space for the "\n" character. for ($j = 0; $j < $width - 1; $j++) { switch ($type) { case 'text': $text .= ch...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b70366e82b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_drupal/7.x
I need the code for `install_drupal($settings = array())` in Drupal 7 (includes/install.core.inc). It must do this: Installs Drupal either interactively or via an array of passed-in settings.
The Drupal installation happens in a series of steps, which may be spread out over multiple page requests. Each request begins by trying to determine the last completed installation step (also known as a "task"), if one is available from a previous request. Control is then passed to the task handler, which processes th...
function install_drupal($settings = array()) { global $install_state; // Initialize the installation state with the settings that were passed in, // as well as a boolean indicating whether or not this is an interactive // installation. $interactive = empty($settings); $install_state = $settings + array('int...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b70678632a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_user_cancel/7.x
Implement `statistics_user_cancel($edit, $account, $method)` in PHP for Drupal 7. Required behavior: Implements hook_user_cancel().
File: modules/statistics/statistics.module
function statistics_user_cancel($edit, $account, $method) { switch ($method) { case 'user_cancel_reassign': db_update('accesslog') ->fields(array('uid' => 0)) ->condition('uid', $account->uid) ->execute(); break; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b71743bf06
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_provider_invoke/7.x
In Drupal 7, write the function `language_provider_invoke($provider_id, $provider = NULL)` (file includes/language.inc) so that it does the following: Helper function used to cache the language negotiation providers results.
Parameters: - $provider_id: The language negotiation provider's identifier. - $provider: (optional) An associative array of information about the provider to be invoked (see hook_language_negotiation_info() for details). If not passed in, it will be loaded through language_negotiation_info(). Returns: A language objec...
function language_provider_invoke($provider_id, $provider = NULL) { $results = &drupal_static(__FUNCTION__); if (!isset($results[$provider_id])) { global $user; // Get languages grouped by status and select only the enabled ones. $languages = language_list('enabled'); $languages = $languages[1]; ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b71bc01da6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21authorize.inc/function/authorize_filetransfer_form_submit/7.x
Implement `authorize_filetransfer_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for authorize_filetransfer_form().
File: includes/authorize.inc
function authorize_filetransfer_form_submit($form, &$form_state) { global $base_url; switch ($form_state['triggering_element']['#name']) { case 'process_updates': // Save the connection settings to the DB. $filetransfer_backend = $form_state['values']['connection_settings']['authorize_filetransfer_...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b71e7d5dff
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_publish_action/7.x
I need the code for `node_publish_action($node, $context = array())` in Drupal 7 (modules/node/node.module). It must do this: Sets the status of a node to 1 (published).
Parameters: - $node: A node object. - $context: (optional) Array of additional information about what triggered the action. Not used for this action. File: modules/node/node.module
function node_publish_action($node, $context = array()) { $node->status = NODE_PUBLISHED; watchdog('action', 'Set @type %title to published.', array('@type' => node_type_get_name($node), '%title' => $node->title)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b72f8148d5
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_image/7.x
Implement `theme_image($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for an image.
Parameters: - $variables: An associative array containing: - path: Either the path of the image file (relative to base_path()) or a full URL. - width: The width of the image (if known). - height: The height of the image (if known). - alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0 always require...
function theme_image($variables) { $attributes = $variables['attributes']; $attributes['src'] = file_create_url($variables['path']); foreach (array('width', 'height', 'alt', 'title') as $key) { if (isset($variables[$key])) { $attributes[$key] = $variables[$key]; } } return '<img' . drupal_att...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b73b2f298b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_menu_load/7.x
In Drupal 7, write the function `field_ui_menu_load($field_name, $entity_type, $bundle_name, $bundle_pos, $map)` (file modules/field_ui/field_ui.module) so that it does the following: Menu loader; Load a field instance based on field and bundle name.
Parameters: - $field_name: The name of the field, as contained in the path. - $entity_type: The name of the entity. - $bundle_name: The name of the bundle, as contained in the path. - $bundle_pos: The position of $bundle_name in $map. - $map: The translated menu router path argument map. Returns: The field instance ar...
function field_ui_menu_load($field_name, $entity_type, $bundle_name, $bundle_pos, $map) { // Extract the actual bundle name from the translated argument map. // The menu router path to manage fields of an entity can be shared among // multiple bundles. For example: // - admin/structure/types/manage/%node_type/f...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b7709fb793
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_filter_info/7.x
Implement `filter_filter_info()` in PHP for Drupal 7. Required behavior: Implements hook_filter_info().
File: modules/filter/filter.module
function filter_filter_info() { $filters['filter_html'] = array( 'title' => t('Limit allowed HTML tags'), 'process callback' => '_filter_html', 'settings callback' => '_filter_html_settings', 'default settings' => array( 'allowed_html' => '<a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b77b13a1c3
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_get_content_headers/7.x
I need the code for `file_get_content_headers($file)` in Drupal 7 (includes/file.inc). It must do this: Examines a file object and returns appropriate content headers for download.
Parameters: - $file: A file object. Returns: An associative array of headers, as expected by file_transfer(). File: includes/file.inc
function file_get_content_headers($file) { $type = mime_header_encode($file->filemime); return array( 'Content-Type' => $type, 'Content-Length' => $file->filesize, 'Cache-Control' => 'private', ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b7842e8a25
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_router_build/7.x
Implement `menu_router_build()` in PHP for Drupal 7. Required behavior: Collects and alters the menu definitions.
File: includes/menu.inc
function menu_router_build() { // We need to manually call each module so that we can know which module // a given item came from. $callbacks = array(); foreach (module_implements('menu') as $module) { $router_items = call_user_func($module . '_menu'); if (isset($router_items) && is_array($router_items)...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b7865c6cf7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_edit_form_validate/7.x
Implement `shortcut_set_edit_form_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Validation handler for shortcut_set_edit_form().
File: modules/shortcut/shortcut.admin.inc
function shortcut_set_edit_form_validate($form, &$form_state) { // Check to prevent a duplicate title, if the title was edited from its // original value. if ($form_state['values']['title'] != $form_state['values']['shortcut_set']->title && shortcut_set_title_exists($form_state['values']['title'])) { form_set...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b78e191284
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_build_js_cache/7.x
In Drupal 7, write the function `drupal_build_js_cache($files)` (file includes/common.inc) so that it does the following: Aggregates JavaScript files into a cache file in the files directory.
The file name for the JavaScript cache file is generated from the hash of the aggregated contents of the files in $files. This forces proxies and browsers to download new JavaScript when the JavaScript changes. The cache file name is retrieved on a page load via a lookup variable that contains an associative array. Th...
function drupal_build_js_cache($files) { $contents = ''; $uri = ''; $map = variable_get('drupal_js_cache_files', array()); // Create a new array so that only the file names are used to create the hash. // This prevents new aggregates from being created unnecessarily. $js_data = array(); foreach ($files as...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b7b65f5117
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_options/7.x
In Drupal 7, write the function `image_style_options($include_empty = TRUE, $output = CHECK_PLAIN)` (file modules/image/image.module) so that it does the following: Gets an array of image styles suitable for using as select list options.
Parameters: - $include_empty: If TRUE a <none> option will be inserted in the options array. - $output: Optional flag determining how the options will be sanitized on output. Leave this at the default (CHECK_PLAIN) if you are using the output of this function directly in an HTML context, such as for checkbox or radio b...
function image_style_options($include_empty = TRUE, $output = CHECK_PLAIN) { $styles = image_styles(); $options = array(); if ($include_empty && !empty($styles)) { $options[''] = t('<none>'); } foreach ($styles as $name => $style) { $options[$name] = ($output == PASS_THROUGH) ? $style['label'] : check...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b7c55db7f8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_widget_settings_form/7.x
I need the code for `text_field_widget_settings_form($field, $instance)` in Drupal 7 (modules/field/modules/text/text.module). It must do this: Implements hook_field_widget_settings_form().
File: modules/field/modules/text/text.module
function text_field_widget_settings_form($field, $instance) { $widget = $instance['widget']; $settings = $widget['settings']; if ($widget['type'] == 'text_textfield') { $form['size'] = array( '#type' => 'textfield', '#title' => t('Size of textfield'), '#default_value' => $settings['size'], ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b7e0e5c1e5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/theme_filter_guidelines/7.x
I need the code for `theme_filter_guidelines($variables)` in Drupal 7 (modules/filter/filter.module). It must do this: Returns HTML for guidelines for a text format.
Parameters: - $variables: An associative array containing: - format: An object representing a text format. File: modules/filter/filter.module
function theme_filter_guidelines($variables) { $format = $variables['format']; $attributes['class'][] = 'filter-guidelines-item'; $attributes['class'][] = 'filter-guidelines-' . $format->format; $output = '<div' . drupal_attributes($attributes) . '>'; $output .= '<h3>' . check_plain($format->name) . '</h3>'; ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b7e32c187e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21unicode.inc/function/mime_header_decode/7.x
Implement `mime_header_decode($header)` in PHP for Drupal 7. Required behavior: Decodes MIME/HTTP encoded header values.
Parameters: - $header: The header to decode. Returns (string): The mime-decoded header. File: includes/unicode.inc
function mime_header_decode($header) { // First step: encoded chunks followed by other encoded chunks (need to collapse whitespace) $header = preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=\s+(?==\?)/', '_mime_header_decode', $header); // Second step: remaining chunks (do not collapse whitespace) ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b7e660736a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_cancel/7.x
In Drupal 7, write the function `profile_user_cancel($edit, $account, $method)` (file modules/profile/profile.module) so that it does the following: Implements hook_user_cancel().
File: modules/profile/profile.module
function profile_user_cancel($edit, $account, $method) { switch ($method) { case 'user_cancel_reassign': db_delete('profile_value') ->condition('uid', $account->uid) ->execute(); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b7f1f5cd1d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_validate/7.x
Give me the example code for `hook_node_validate($node, $form, &$form_state)` in Drupal 7. Hook description: Perform node validation before a node is created or updated.
This hook is invoked from node_validate(), after a user has finished editing the node and is previewing or submitting it. It is invoked at the end of all the standard validation steps, and after the type-specific hook_validate() is invoked. To indicate a validation error, use form_set_error(). Note: Changes made to t...
function hook_node_validate($node, $form, &$form_state) { if (isset($node->end) && isset($node->start)) { if ($node->start > $node->end) { form_set_error('time', t('An event may not end before it starts.')); } } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b8089077c5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/_node_rankings/7.x
Implement `_node_rankings(SelectQueryExtender $query)` in PHP for Drupal 7. Required behavior: Gathers the rankings from the hook_ranking() implementations.
Parameters: - $query: A query object that has been extended with the Search DB Extender. File: modules/node/node.module
function _node_rankings(SelectQueryExtender $query) { if ($ranking = module_invoke_all('ranking')) { $tables = &$query->getTables(); foreach ($ranking as $rank => $values) { if ($node_rank = variable_get('node_rank_' . $rank, 0)) { // If the table defined in the ranking isn't already joined, the...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b80b6b8920
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_purge/7.x
In Drupal 7, write the function `language_negotiation_purge()` (file includes/language.inc) so that it does the following: Removes any unused language negotiation providers from the configuration.
File: includes/language.inc
function language_negotiation_purge() { // Ensure that we are getting the defined language negotiation information. An // invocation of module_enable() or module_disable() could outdate the cached // information. drupal_static_reset('language_negotiation_info'); drupal_static_reset('language_types_info'); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b816b1212f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_seek_screen/7.x
Implement `locale_translate_seek_screen()` in PHP for Drupal 7. Required behavior: String search screen.
File: modules/locale/locale.admin.inc
function locale_translate_seek_screen() { // Add CSS. drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css'); $elements = drupal_get_form('locale_translation_filter_form'); $output = drupal_render($elements); $output .= _locale_translate_seek(); return $output; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b83c7ed6f0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_load/7.x
Give me the example code for `hook_load($nodes)` in Drupal 7. Hook description: Act on nodes being loaded from the database.
This is a node-type-specific hook, which is invoked only for the node type being affected. See Parameters: - $nodes: An array of the nodes being loaded, keyed by nid. For a detailed usage example, see node_example.module. File: modules/node/node.api.php
function hook_load($nodes) { $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes))); foreach ($result as $record) { $nodes[$record->nid]->foo = $record->foo; } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b83e4d52e8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_block_list_alter/7.x
In Drupal 7, write the function `dashboard_block_list_alter(&$blocks)` (file modules/dashboard/dashboard.module) so that it does the following: Implements hook_block_list_alter().
Skip rendering dashboard blocks when not on the dashboard page itself. This prevents expensive dashboard blocks from causing performance issues on pages where they will never be displayed. File: modules/dashboard/dashboard.module
function dashboard_block_list_alter(&$blocks) { if (!dashboard_is_visible()) { foreach ($blocks as $key => $block) { if (in_array($block->region, dashboard_regions())) { unset($blocks[$key]); } } } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b84e21cc5b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/_search_index_truncate/7.x
Implement `_search_index_truncate(&$text)` in PHP for Drupal 7. Required behavior: Helper function for array_walk in search_index_split.
File: modules/search/search.module
function _search_index_truncate(&$text) { if (is_numeric($text)) { $text = ltrim($text, '0'); } $text = truncate_utf8($text, 50); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b8707b9370
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_theme/7.x
In Drupal 7, write the function `book_theme()` (file modules/book/book.module) so that it does the following: Implements hook_theme().
File: modules/book/book.module
function book_theme() { return array( 'book_navigation' => array( 'variables' => array('book_link' => NULL), 'template' => 'book-navigation', ), 'book_export_html' => array( 'variables' => array('title' => NULL, 'contents' => NULL, 'depth' => NULL), 'template' => 'book-export-html'...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b88839bb87
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/template_preprocess_aggregator_summary_items/7.x
I need the code for `template_preprocess_aggregator_summary_items(&$variables)` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Processes variables for aggregator-summary-items.tpl.php.
File: modules/aggregator/aggregator.pages.inc
function template_preprocess_aggregator_summary_items(&$variables) { $variables['title'] = check_plain($variables['source']->title); $variables['summary_list'] = theme('item_list', array('items' => $variables['summary_items'])); $variables['source_url'] = $variables['source']->url; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b8a5941c40
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_invoke/7.x
Implement `ajax_command_invoke($selector, $method, array $arguments = array())` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'invoke' command.
The 'invoke' command will instruct the client to invoke the given jQuery method with the supplied arguments on the elements matched by the given selector. Intended for simple jQuery commands, such as attr(), addClass(), removeClass(), toggleClass(), etc. This command is implemented by Drupal.ajax.prototype.commands.in...
function ajax_command_invoke($selector, $method, array $arguments = array()) { return array( 'command' => 'invoke', 'selector' => $selector, 'method' => $method, 'arguments' => $arguments, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b8a5cf2c7b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_view/7.x
In Drupal 7, show an example implementation for `hook_entity_view($entity, $type, $view_mode, $langcode)` (modules/system/system.api.php): Act on entities being assembled before rendering.
Parameters: - $entity: The entity object. - $type: The type of entity being rendered (i.e. node, user, comment). - $view_mode: The view mode the entity is rendered in. - $langcode: The language code used for rendering. The module may add elements to $entity->content prior to rendering. The structure of $entity->content...
function hook_entity_view($entity, $type, $view_mode, $langcode) { $entity->content['my_additional_field'] = array( '#markup' => $additional_field, '#weight' => 10, '#theme' => 'mymodule_my_additional_field', ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b8e816c3ad
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_drupal_goto_alter/7.x
In Drupal 7, show an example implementation for `hook_drupal_goto_alter(&$path, &$options, &$http_response_code)` (modules/system/system.api.php): Change the page the user is sent to by drupal_goto().
Parameters: - $path: A Drupal path or a full URL. - $options: An associative array of additional URL options to pass to url(). - $http_response_code: The HTTP status code to use for the redirection. See drupal_goto() for more information. File: modules/system/system.api.php
function hook_drupal_goto_alter(&$path, &$options, &$http_response_code) { // A good addition to misery module. $http_response_code = 500; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b90eb37a81
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_user_presave/7.x
Implement `user_user_presave(&$edit, $account, $category)` in PHP for Drupal 7. Required behavior: Implements hook_user_presave().
File: modules/user/user.module
function user_user_presave(&$edit, $account, $category) { if ($category == 'account' || $category == 'register') { if (!empty($edit['picture_upload'])) { $edit['picture'] = $edit['picture_upload']; } // Delete picture if requested, and if no replacement picture was given. elseif (!empty($edit['p...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b91d8ae959
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_load/7.x
Implement `image_gd_load(stdClass $image)` in PHP for Drupal 7. Required behavior: GD helper function to create an image resource from a file.
Parameters: - $image: An image object. The $image->resource value will populated by this call. Returns: TRUE or FALSE, based on success. File: modules/system/image.gd.inc
function image_gd_load(stdClass $image) { $extension = str_replace('jpg', 'jpeg', $image->info['extension']); $function = 'imagecreatefrom' . $extension; if (function_exists($function) && $image->resource = $function($image->source)) { if (imageistruecolor($image->resource)) { return TRUE; } els...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b92300041c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_form_field_validate/7.x
In Drupal 7, write the function `entity_form_field_validate($entity_type, $form, &$form_state)` (file includes/common.inc) so that it does the following: Attaches field API validation to entity forms.
File: includes/common.inc
function entity_form_field_validate($entity_type, $form, &$form_state) { // All field attach API functions act on an entity object, but during form // validation, we don't have one. $form_state contains the entity as it was // prior to processing the current form submission, and we must not update it // until w...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b924d9f41e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/_tracker_remove/7.x
In Drupal 7, write the function `_tracker_remove($nid, $uid = NULL, $changed = NULL)` (file modules/tracker/tracker.module) so that it does the following: Cleans up indexed data when nodes or comments are removed.
Parameters: - $nid: The node ID. - $uid: The author of the node or comment. - $changed: The last changed timestamp of the node. File: modules/tracker/tracker.module
function _tracker_remove($nid, $uid = NULL, $changed = NULL) { $node = db_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject(); // The user only keeps his or her subscription if both of the following are true: // (1) The node exists. // (2) The user i...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b93664b4f5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_block_info_alter/7.x
In Drupal 7, write the function `dashboard_block_info_alter(&$blocks, $theme, $code_blocks)` (file modules/dashboard/dashboard.module) so that it does the following: Implements hook_block_info_alter().
File: modules/dashboard/dashboard.module
function dashboard_block_info_alter(&$blocks, $theme, $code_blocks) { $admin_theme = variable_get('admin_theme'); if (($admin_theme && $theme == $admin_theme) || (!$admin_theme && $theme == variable_get('theme_default', 'bartik'))) { foreach ($blocks as $module => &$module_blocks) { foreach ($module_block...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b93ae58751
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.install/function/openid_schema/7.x
Implement `openid_schema()` in PHP for Drupal 7. Required behavior: Implements hook_schema().
File: modules/openid/openid.install
function openid_schema() { $schema['openid_association'] = array( 'description' => 'Stores temporary shared key association information for OpenID authentication.', 'fields' => array( 'idp_endpoint_uri' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, '...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b9447bab80
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_requirements_severity/7.x
Implement `drupal_requirements_severity(&$requirements)` in PHP for Drupal 7. Required behavior: Extracts the highest severity from the requirements array.
Parameters: - $requirements: An array of requirements, in the same format as is returned by hook_requirements(). Returns: The highest severity in the array. File: includes/install.inc
function drupal_requirements_severity(&$requirements) { $severity = REQUIREMENT_OK; foreach ($requirements as $requirement) { if (isset($requirement['severity'])) { $severity = max($severity, $requirement['severity']); } } return $severity; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b945f0f974
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21actions.inc/function/actions_get_all_actions/7.x
Implement `actions_get_all_actions()` in PHP for Drupal 7. Required behavior: Retrieves all action instances from the database.
This function differs from the actions_list() function, which gathers actions by invoking hook_action_info(). The actions returned by this function and the actions returned by actions_list() are partially synchronized. Non-configurable actions from hook_action_info() implementations are put into the database when actio...
function actions_get_all_actions() { $actions = db_query("SELECT aid, type, callback, parameters, label FROM {actions}")->fetchAllAssoc('aid', PDO::FETCH_ASSOC); foreach ($actions as &$action) { $action['configurable'] = (bool) $action['parameters']; unset($action['parameters']); unset($action['aid']); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b94ae49302
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_view/7.x
In Drupal 7, show an example implementation for `hook_node_view($node, $view_mode, $langcode)` (modules/node/node.api.php): Act on a node that is being assembled before rendering.
The module may add elements to $node->content prior to rendering. This hook will be called after hook_view(). The structure of $node->content is a renderable array as expected by drupal_render(). When $view_mode is 'rss', modules can also add extra RSS elements and namespaces to $node->rss_elements and $node->rss_name...
function hook_node_view($node, $view_mode, $langcode) { $node->content['my_additional_field'] = array( '#markup' => $additional_field, '#weight' => 10, '#theme' => 'mymodule_my_additional_field', ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b955aa589c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_category_validate/7.x
I need the code for `aggregator_form_category_validate($form, &$form_state)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Form validation handler for aggregator_form_category().
File: modules/aggregator/aggregator.admin.inc
function aggregator_form_category_validate($form, &$form_state) { if ($form_state['values']['op'] == t('Save')) { // Check for duplicate titles if (isset($form_state['values']['cid'])) { $category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title AND cid <> :cid", array(':title' => ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b9665093fe
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_configure_form_submit/7.x
In Drupal 7, write the function `install_configure_form_submit($form, &$form_state)` (file includes/install.core.inc) so that it does the following: Form submission handler for install_configure_form().
File: includes/install.core.inc
function install_configure_form_submit($form, &$form_state) { global $user; variable_set('site_name', $form_state['values']['site_name']); variable_set('site_mail', $form_state['values']['site_mail']); variable_set('date_default_timezone', $form_state['values']['date_default_timezone']); variable_set('site_d...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b96addd692
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/theme_node_recent_content/7.x
In Drupal 7, write the function `theme_node_recent_content($variables)` (file modules/node/node.module) so that it does the following: Returns HTML for a recent node to be displayed in the recent content block.
Parameters: - $variables: An associative array containing: - node: A node object. File: modules/node/node.module
function theme_node_recent_content($variables) { $node = $variables['node']; $output = '<div class="node-title">'; $output .= l($node->title, 'node/' . $node->nid); $output .= theme('mark', array('type' => node_mark($node->nid, $node->changed))); $output .= '</div><div class="node-author">'; $output .= the...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b970814abc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_cron/7.x
In Drupal 7, write the function `node_cron()` (file modules/node/node.module) so that it does the following: Implements hook_cron().
File: modules/node/node.module
function node_cron() { db_delete('history') ->condition('timestamp', NODE_NEW_LIMIT, '<') ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b970860323
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_page_alter/7.x
I need the code for `announcements_feed_page_alter(&$page)` in Drupal 7 (modules/announcements_feed/announcements_feed.module). It must do this: Implements hook_page_alter().
File: modules/announcements_feed/announcements_feed.module
function announcements_feed_page_alter(&$page) { if (isset($page['page_top']['toolbar'])) { // If the toolbar is available, add a pre-render function to add the class. $page['page_top']['toolbar']['#pre_render'][] = 'announcements_feed_toolbar_pre_render_alter'; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b97ff810ee
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_assign_owner_action_submit/7.x
In Drupal 7, write the function `node_assign_owner_action_submit($form, $form_state)` (file modules/node/node.module) so that it does the following: Saves settings form for node_assign_owner_action().
File: modules/node/node.module
function node_assign_owner_action_submit($form, $form_state) { // Username can change, so we need to store the ID, not the username. $uid = db_query('SELECT uid from {users} WHERE name = :name', array(':name' => $form_state['values']['owner_name']))->fetchField(); return array('owner_uid' => $uid); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b98392cf69
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/drupal_help_arg/7.x
In Drupal 7, write the function `drupal_help_arg($arg = array())` (file includes/menu.inc) so that it does the following: Generates elements for the $arg array in the help hook.
File: includes/menu.inc
function drupal_help_arg($arg = array()) { // Note - the number of empty elements should be > MENU_MAX_PARTS. return $arg + array('', '', '', '', '', '', '', '', '', '', '', ''); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b99b750f34
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/_system_rebuild_module_data/7.x
Implement `_system_rebuild_module_data()` in PHP for Drupal 7. Required behavior: Helper function to scan and collect module .info data.
Returns: An associative array of module information. File: modules/system/system.module
function _system_rebuild_module_data() { // Find modules $modules = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0); // Include the installation profile in modules that are loaded. $profile = drupal_get_profile(); $modules[$profile] = new stdClass(); $modules[...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b9aa4c30ca
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_file_download_access/7.x
Implement `node_file_download_access($field, $entity_type, $entity)` in PHP for Drupal 7. Required behavior: Implements hook_file_download_access().
File: modules/node/node.module
function node_file_download_access($field, $entity_type, $entity) { if ($entity_type == 'node') { return node_access('view', $entity); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b9b4024fb8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_prev/7.x
In Drupal 7, write the function `book_prev($book_link)` (file modules/book/book.module) so that it does the following: Fetches the menu link for the previous page of the book.
Parameters: - $book_link: A fully loaded menu link that is part of the book hierarchy. Returns: A fully loaded menu link for the page before the one represented in $book_link. File: modules/book/book.module
function book_prev($book_link) { // If the parent is zero, we are at the start of a book. if ($book_link['plid'] == 0) { return NULL; } $flat = book_get_flat_menu($book_link); reset($flat); $curr = NULL; do { $prev = $curr; $curr = current($flat); $key = key($flat); next($flat); } wh...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b9bfdd1fbf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_delete_date_format_type_form/7.x
I need the code for `system_delete_date_format_type_form($form, &$form_state, $format_type)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Menu callback; present a form for deleting a date type.
File: modules/system/system.admin.inc
function system_delete_date_format_type_form($form, &$form_state, $format_type) { $form['format_type'] = array( '#type' => 'value', '#value' => $format_type, ); $type_info = system_get_date_types($format_type); $output = confirm_form($form, t('Are you sure you want to remove the date type %type?', ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b9d0e1e0ff
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_mail/7.x
In Drupal 7, show an example implementation for `hook_mail($key, &$message, $params)` (modules/system/system.api.php): Prepare a message based on parameters; called from drupal_mail().
Note that hook_mail(), unlike hook_mail_alter(), is only called on the $module argument to drupal_mail(), not all modules. Parameters: - $key: An identifier of the mail. - $message: An array to be filled in. Elements in this array include: - id: An ID to identify the mail sent. Look at module source code or drupal_mai...
function hook_mail($key, &$message, $params) { $account = $params['account']; $context = $params['context']; $variables = array( '%site_name' => variable_get('site_name', 'Drupal'), '%username' => format_username($account), ); if ($context['hook'] == 'taxonomy') { $entity = $params['entity']; ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b9db3e289d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_set_authmaps/7.x
In Drupal 7, write the function `user_set_authmaps($account, $authmaps)` (file modules/user/user.module) so that it does the following: Save mappings of which external authentication module(s) authenticated a user. Maps external usernames to user ids in the users table.
Parameters: - $account: A user object. - $authmaps: An associative array with a compound key and the username as the value. The key is made up of 'authname_' plus the name of the external authentication module. File: modules/user/user.module
function user_set_authmaps($account, $authmaps) { foreach ($authmaps as $key => $value) { $module = explode('_', $key, 2); if ($value) { db_merge('authmap') ->key(array( 'uid' => $account->uid, 'module' => $module[1], )) ->fields(array('authname' => $value)) ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b9dd68e682
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_widget_WIDGET_TYPE_form_alter/7.x
Give me the example code for `hook_field_widget_WIDGET_TYPE_form_alter(&$element, &$form_state, $context)` in Drupal 7. Hook description: Alter widget forms for a specific widget provided by another module.
Modules can implement hook_field_widget_WIDGET_TYPE_form_alter() to modify a specific widget form, rather than using hook_field_widget_form_alter() and checking the widget type. Parameters: - $element: The field widget form element as constructed by hook_field_widget_form(). - $form_state: An associative array contain...
function hook_field_widget_WIDGET_TYPE_form_alter(&$element, &$form_state, $context) { // Code here will only act on widgets of type WIDGET_TYPE. For example, // hook_field_widget_mymodule_autocomplete_form_alter() will only act on // widgets of type 'mymodule_autocomplete'. $element['#autocomplete_path'] = 'm...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b9ed04040b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_view_mode_prepare/7.x
Implement `entity_view_mode_prepare($entity_type, $entities, $view_mode, $langcode = NULL)` in PHP for Drupal 7. Required behavior: Invoke hook_entity_view_mode_alter().
If adding a new entity similar to nodes, comments or users, you should invoke this function during the ENTITY_build_content() or ENTITY_view_multiple() phases of rendering to allow other modules to alter the view mode during this phase. This function needs to be called before field_attach_prepare_view() to ensure that ...
function entity_view_mode_prepare($entity_type, $entities, $view_mode, $langcode = NULL) { if (!isset($langcode)) { $langcode = $GLOBALS['language_content']->language; } // To ensure hooks are never run after field_attach_prepare_view() only // process items without the entity_view_prepared flag. $entiti...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b9f875a753
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_default_region/7.x
Implement `system_default_region($theme)` in PHP for Drupal 7. Required behavior: Get the name of the default region for a given theme.
Parameters: - $theme: The name of a theme. Returns: A string that is the region name. File: modules/system/system.module
function system_default_region($theme) { $regions = system_region_list($theme, REGIONS_VISIBLE, FALSE); return $regions ? reset($regions) : ''; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ba6d309a3d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_language_name/7.x
Implement `locale_language_name($lang)` in PHP for Drupal 7. Required behavior: Returns a language name
File: modules/locale/locale.module
function locale_language_name($lang) { $list = &drupal_static(__FUNCTION__); if (!isset($list)) { $list = locale_language_list(); } return ($lang && isset($list[$lang])) ? $list[$lang] : t('All'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ba82467273
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_implode_tags/7.x
I need the code for `drupal_implode_tags($tags)` in Drupal 7 (includes/common.inc). It must do this: Implodes an array of tags into a string.
File: includes/common.inc
function drupal_implode_tags($tags) { $encoded_tags = array(); foreach ($tags as $tag) { // Commas and quotes in tag names are special cases, so encode them. if (strpos($tag, ',') !== FALSE || strpos($tag, '"') !== FALSE) { $tag = '"' . str_replace('"', '""', $tag) . '"'; } $encoded_tags[] = ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ba83da587c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/_field_sort_items_helper/7.x
Implement `_field_sort_items_helper($a, $b)` in PHP for Drupal 7. Required behavior: Sort function for items order. (copied form element_sort(), which acts on #weight keys)
File: modules/field/field.module
function _field_sort_items_helper($a, $b) { $a_weight = (is_array($a) ? $a['_weight'] : 0); $b_weight = (is_array($b) ? $b['_weight'] : 0); return $a_weight - $b_weight; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bac4c07c38
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_clear_opcode_cache/7.x
I need the code for `drupal_clear_opcode_cache($filepath)` in Drupal 7 (includes/bootstrap.inc). It must do this: Invalidates a PHP file from any active opcode caches.
If the opcode cache does not support the invalidation of individual files, the entire cache will be flushed. Parameters: - $filepath (string): The absolute path of the PHP file to invalidate. File: includes/bootstrap.inc
function drupal_clear_opcode_cache($filepath) { if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) { // Below PHP 5.3, clearstatcache does not accept any function parameters. clearstatcache(); } else { clearstatcache(TRUE, $filepath); } // Zend OPcache. if (function_exists('opcache_inval...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-baccab1a18
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_block_configure/7.x
I need the code for `node_block_configure($delta = '')` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_block_configure().
File: modules/node/node.module
function node_block_configure($delta = '') { $form = array(); if ($delta == 'recent') { $form['node_recent_block_count'] = array( '#type' => 'select', '#title' => t('Number of recent content items to display'), '#default_value' => variable_get('node_recent_block_count', 10), '#options' =...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bae996bc80
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_batch_by_language/7.x
I need the code for `locale_batch_by_language($langcode, $finished = NULL, $skip = array())` in Drupal 7 (includes/locale.inc). It must do this: Prepare a batch to import translations for all enabled modules in a given language.
Parameters: - $langcode: Language code to import translations for. - $finished: Optional finished callback for the batch. - $skip: Array of component names to skip. Used in the installer for the second pass import, when most components are already imported. Returns: A batch structure or FALSE if no files found. File:...
function locale_batch_by_language($langcode, $finished = NULL, $skip = array()) { // Collect all files to import for all enabled modules and themes. $files = array(); $components = array(); $query = db_select('system', 's'); $query->fields('s', array('name', 'filename')); $query->condition('s.status', 1); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-baec7dad7b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.admin.inc/function/statistics_access_log/7.x
Implement `statistics_access_log($aid)` in PHP for Drupal 7. Required behavior: Page callback: Gathers page access statistics suitable for rendering.
Parameters: - $aid: The unique accesslog ID. Returns: A render array containing page access statistics. If information for the page was not found, drupal_not_found() is called. File: modules/statistics/statistics.admin.inc
function statistics_access_log($aid) { $access = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = :aid', array(':aid' => $aid))->fetch(); if ($access) { $rows[] = array( array('data' => t('URL'), 'header' => TRUE), l(url($access->path, array('absolute'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bb094a0a29
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_permission/7.x
In Drupal 7, write the function `image_permission()` (file modules/image/image.module) so that it does the following: Implements hook_permission().
File: modules/image/image.module
function image_permission() { return array( 'administer image styles' => array( 'title' => t('Administer image styles'), 'description' => t('Create and modify styles for generating image modifications such as thumbnails.'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bb15dad650
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_form/7.x
In Drupal 7, write the function `forum_form($node, $form_state)` (file modules/forum/forum.module) so that it does the following: Implements hook_form().
File: modules/forum/forum.module
function forum_form($node, $form_state) { $type = node_type_get_type($node); $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => !empty($node->title) ? $node->title : '', '#required' => TRUE, '#weight' => -5 ); if (!empty($node->nid))...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bb45c06e6b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_edit_form_submit/7.x
Implement `locale_translate_edit_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process string editing form submissions.
Saves all translations of one string submitted from a form. File: modules/locale/locale.admin.inc
function locale_translate_edit_form_submit($form, &$form_state) { $lid = $form_state['values']['lid']; foreach ($form_state['values']['translations'] as $key => $value) { $translation = db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':languag...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bb46ce84b7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_files_database/7.x
I need the code for `system_get_files_database(&$files, $type)` in Drupal 7 (modules/system/system.module). It must do this: Retrieves the current status of an array of files in the system table.
Parameters: - $files: An array of files to check. - $type: The type of the files. File: modules/system/system.module
function system_get_files_database(&$files, $type) { // Extract current files from database. $result = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = :type", array(':type' => $type)); foreach ($result as $file) { if (isset($files[$file->name]) && is_object($fi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bb4f351a57
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.install/function/_update_7000_field_create_field/7.x
I need the code for `_update_7000_field_create_field(&$field)` in Drupal 7 (modules/field/field.install). It must do this: Utility function: create a field by writing directly to the database.
This function can be used for databases whose schema is at field module version 7000 or higher. File: modules/field/field.install
function _update_7000_field_create_field(&$field) { // Merge in default values.` $field += array( 'entity_types' => array(), 'cardinality' => 1, 'translatable' => FALSE, 'locked' => FALSE, 'settings' => array(), 'indexes' => array(), 'deleted' => 0, 'active' => 1, ); // Set stor...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bb5f235022
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_action_info/7.x
I need the code for `node_action_info()` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_action_info().
File: modules/node/node.module
function node_action_info() { return array( 'node_publish_action' => array( 'type' => 'node', 'label' => t('Publish content'), 'configurable' => FALSE, 'behavior' => array('changes_property'), 'triggers' => array('node_presave', 'comment_insert', 'comment_update', 'comment_delete'), ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bbb5c387dc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/_comment_update_node_statistics/7.x
Implement `_comment_update_node_statistics($nid)` in PHP for Drupal 7. Required behavior: Updates the comment statistics for a given node. This should be called any time a comment is added, deleted, or updated.
The following fields are contained in the node_comment_statistics table. - last_comment_timestamp: the timestamp of the last comment for this node or the node create stamp if no comments exist for the node. - last_comment_name: the name of the anonymous poster for the last comment - last_comment_uid: the uid of the pos...
function _comment_update_node_statistics($nid) { // Allow bulk updates and inserts to temporarily disable the // maintenance of the {node_comment_statistics} table. if (!variable_get('comment_maintain_node_statistics', TRUE)) { return; } $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :ni...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bbbe567216
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_switch_validate/7.x
In Drupal 7, write the function `shortcut_set_switch_validate($form, &$form_state)` (file modules/shortcut/shortcut.admin.inc) so that it does the following: Validation handler for shortcut_set_switch().
File: modules/shortcut/shortcut.admin.inc
function shortcut_set_switch_validate($form, &$form_state) { if ($form_state['values']['set'] == 'new') { // Check to prevent creating a shortcut set with an empty title. if (trim($form_state['values']['new']) == '') { form_set_error('new', t('The new set name is required.')); } // Check to prev...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bbcffb1d6d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/tracker_cron/7.x
I need the code for `tracker_cron()` in Drupal 7 (modules/tracker/tracker.module). It must do this: Implements hook_cron().
Updates tracking information for any items still to be tracked. The variable 'tracker_index_nid' is set to ((the last node ID that was indexed) - 1) and used to select the nodes to be processed. If there are no remaining nodes to process, 'tracker_index_nid' will be 0. File: modules/tracker/tracker.module
function tracker_cron() { $max_nid = variable_get('tracker_index_nid', 0); $batch_size = variable_get('tracker_batch_size', 1000); if ($max_nid > 0) { $last_nid = FALSE; $result = db_query_range('SELECT nid, uid, status FROM {node} WHERE nid <= :max_nid ORDER BY nid DESC', 0, $batch_size, array(':max_nid'...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bc040c225b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_fallback_get_candidates/7.x
I need the code for `language_fallback_get_candidates($type = LANGUAGE_TYPE_CONTENT)` in Drupal 7 (includes/language.inc). It must do this: Returns the possible fallback languages ordered by language weight.
Returns: An array of language codes. File: includes/language.inc
function language_fallback_get_candidates($type = LANGUAGE_TYPE_CONTENT) { $fallback_candidates = &drupal_static(__FUNCTION__); if (!isset($fallback_candidates)) { $fallback_candidates = array(); // Get languages ordered by weight. // Use array keys to avoid duplicated entries. foreach (language_l...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bc23066cea
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_file_download/7.x
In Drupal 7, write the function `user_file_download($uri)` (file modules/user/user.module) so that it does the following: Implements hook_file_download().
Ensure that user pictures (avatars) are always downloadable. File: modules/user/user.module
function user_file_download($uri) { if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) { $info = image_get_info($uri); return array('Content-Type' => $info['mime_type']); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bc2d780647
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_save/7.x
I need the code for `node_type_save($info)` in Drupal 7 (modules/node/node.module). It must do this: Saves a node type to the database.
Parameters: - $info (object): The node type to save; an object with the following properties: - type: A string giving the machine name of the node type. - name: A string giving the human-readable name of the node type. - base: A string that indicates the base string for hook functions. For example, 'node_content' is th...
function node_type_save($info) { $existing_type = !empty($info->old_type) ? $info->old_type : $info->type; $is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', 0, 1, array(':type' => $existing_type))->fetchField(); $type = node_type_set_defaults($info); $fields = array( 'typ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bc71b1b0c5
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_munge_filename/7.x
Implement `file_munge_filename($filename, $extensions, $alerts = TRUE)` in PHP for Drupal 7. Required behavior: Modifies a filename as needed for security purposes.
Munging a file name prevents unknown file extensions from masking exploit files. When web servers such as Apache decide how to process a URL request, they use the file extension. If the extension is not recognized, Apache skips that extension and uses the previous file extension. For example, if the file being requeste...
function file_munge_filename($filename, $extensions, $alerts = TRUE) { $original = $filename; // Allow potentially insecure uploads for very savvy users and admin if (!variable_get('allow_insecure_uploads', 0)) { // Remove any null bytes. See http://php.net/manual/security.filesystem.nullbytes.php $filen...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bc7df0d8bd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_create_stub_entity/7.x
Implement `entity_create_stub_entity($entity_type, $ids)` in PHP for Drupal 7. Required behavior: Helper function to assemble an object structure with initial ids.
This function can be seen as reciprocal to entity_extract_ids(). Parameters: - $entity_type: The entity type; e.g. 'node' or 'user'. - $ids: A numerically indexed array, as returned by entity_extract_ids(). Returns: An entity structure, initialized with the ids provided. File: includes/common.inc
function entity_create_stub_entity($entity_type, $ids) { $entity = new stdClass(); $info = entity_get_info($entity_type); $entity->{$info['entity keys']['id']} = $ids[0]; if (!empty($info['entity keys']['revision']) && isset($ids[1])) { $entity->{$info['entity keys']['revision']} = $ids[1]; } if (!empty...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bc965ddc66
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_extra_fields/7.x
I need the code for `field_info_extra_fields($entity_type, $bundle, $context)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns a list and settings of pseudo-field elements in a given bundle.
If $context is 'form', an array with the following structure: Parameters: - $entity_type: The type of entity; e.g. 'node' or 'user'. - $bundle: The bundle name. - $context: The context for which the list of pseudo-fields is requested. Either 'form' or 'display'. Returns: The array of pseudo-field elements in the bund...
function field_info_extra_fields($entity_type, $bundle, $context) { $cache = _field_info_field_cache(); $info = $cache->getBundleExtraFields($entity_type, $bundle); return isset($info[$context]) ? $info[$context] : array(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bc97b36658
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_list_alter/7.x
Give me the example code for `hook_block_list_alter(&$blocks)` in Drupal 7. Hook description: Act on blocks prior to rendering.
This hook allows you to add, remove or modify blocks in the block list. The block list contains the block definitions, not the rendered blocks. The blocks are rendered after the modules have had a chance to manipulate the block list. You can also set $block->content here, which will override the content of the block a...
function hook_block_list_alter(&$blocks) { global $language, $theme_key; // This example shows how to achieve language specific visibility setting for // blocks. $result = db_query('SELECT module, delta, language FROM {my_table}'); $block_languages = array(); foreach ($result as $record) { $block_lang...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-bca2376bb8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_categories/7.x
Give me the example code for `hook_user_categories()` in Drupal 7. Hook description: Define a list of user settings or profile information categories.
There are two steps to using hook_user_categories(): - Create the category with hook_user_categories(). - Display that category on the form ID of "user_profile_form" with hook_form_FORM_ID_alter(). Step one builds out the category but it won't be visible on your form until you explicitly tell it to do so. The funct...
function hook_user_categories() { return array(array( 'name' => 'account', 'title' => t('Account settings'), 'weight' => 1, )); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-bcb5396f41
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_schema_field_types/7.x
I need the code for `drupal_schema_field_types($table)` in Drupal 7 (includes/common.inc). It must do this: Retrieves the type for every field in a table schema.
Parameters: - $table: The name of the table from which to retrieve type information. Returns: An array of types, keyed by field name. File: includes/common.inc
function drupal_schema_field_types($table) { $table_schema = drupal_get_schema($table); $field_types = array(); foreach ($table_schema['fields'] as $field_name => $field_info) { $field_types[$field_name] = isset($field_info['type']) ? $field_info['type'] : NULL; } return $field_types; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bcc81acbeb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_category_submit/7.x
In Drupal 7, write the function `aggregator_form_category_submit($form, &$form_state)` (file modules/aggregator/aggregator.admin.inc) so that it does the following: Form submission handler for aggregator_form_category().
File: modules/aggregator/aggregator.admin.inc
function aggregator_form_category_submit($form, &$form_state) { if ($form_state['values']['op'] == t('Delete')) { $title = $form_state['values']['title']; // Unset the title. unset($form_state['values']['title']); } aggregator_save_category($form_state['values']); if (isset($form_state['values']['ci...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bd0727d3c8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.fetcher.inc/function/aggregator_aggregator_fetch_info/7.x
I need the code for `aggregator_aggregator_fetch_info()` in Drupal 7 (modules/aggregator/aggregator.fetcher.inc). It must do this: Implements hook_aggregator_fetch_info().
File: modules/aggregator/aggregator.fetcher.inc
function aggregator_aggregator_fetch_info() { return array( 'title' => t('Default fetcher'), 'description' => t('Downloads data from a URL using Drupal\'s HTTP request handler.'), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bd5659f621
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.install/function/overlay_enable/7.x
Implement `overlay_enable()` in PHP for Drupal 7. Required behavior: Implements hook_enable().
If the module is being enabled through the admin UI, and not from an installation profile, reopen the modules page in an overlay. File: modules/overlay/overlay.install
function overlay_enable() { if (strpos(current_path(), 'admin/modules') === 0) { // Flag for a redirect to <front>#overlay=admin/modules on hook_init(). $_SESSION['overlay_enable_redirect'] = 1; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bd56a06f40
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_fallback_format/7.x
I need the code for `filter_fallback_format()` in Drupal 7 (modules/filter/filter.module). It must do this: Returns the ID of the fallback text format that all users have access to.
The fallback text format is a regular text format in every respect, except it does not participate in the filter permission system and cannot be disabled. It needs to exist because any user who has permission to create formatted content must always have at least one text format they can use. Because the fallback forma...
function filter_fallback_format() { // This variable is automatically set in the database for all installations // of Drupal. In the event that it gets disabled or deleted somehow, there // is no safe default to return, since we do not want to risk making an // existing (and potentially unsafe) text format on t...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bd71523d0d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_delete_access/7.x
Implement `shortcut_set_delete_access($shortcut_set)` in PHP for Drupal 7. Required behavior: Access callback for deleting a shortcut set.
Parameters: - $shortcut_set: The shortcut set to be deleted. Returns: TRUE if the current user has access to delete shortcut sets and this is not the site-wide default set; FALSE otherwise. File: modules/shortcut/shortcut.module
function shortcut_set_delete_access($shortcut_set) { // Only admins can delete sets. if (!user_access('administer shortcuts')) { return FALSE; } // Never let the default shortcut set be deleted. if ($shortcut_set->set_name == SHORTCUT_DEFAULT_SET_NAME) { return FALSE; } return TRUE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bd795b8898
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.install/function/text_field_schema/7.x
Implement `text_field_schema($field)` in PHP for Drupal 7. Required behavior: Implements hook_field_schema().
File: modules/field/modules/text/text.install
function text_field_schema($field) { switch ($field['type']) { case 'text': $columns = array( 'value' => array( 'type' => 'varchar', 'length' => $field['settings']['max_length'], 'not null' => FALSE, ), ); break; case 'text_long': $columns...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bd7ccfb914
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.report.inc/function/theme_update_status_label/7.x
In Drupal 7, write the function `theme_update_status_label($variables)` (file modules/update/update.report.inc) so that it does the following: Returns HTML for a label to display for a project's update status.
Parameters: - $variables (array): An associative array containing: - status: The integer code for a project's current update status. File: modules/update/update.report.inc
function theme_update_status_label($variables) { switch ($variables['status']) { case UPDATE_NOT_SECURE: return '<span class="security-error">' . t('Security update required!') . '</span>'; case UPDATE_REVOKED: return '<span class="revoked">' . t('Revoked!') . '</span>'; case UPDATE_NOT_SUPP...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bd843ed94e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_permission/7.x
Implement `menu_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().
File: modules/menu/menu.module
function menu_permission() { return array( 'administer menu' => array( 'title' => t('Administer menus and menu items'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-bda146e193
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/_forum_topics_unread/7.x
Implement `_forum_topics_unread($term, $uid)` in PHP for Drupal 7. Required behavior: Calculates the number of new posts in a forum that the user has not yet read.
Nodes are new if they are newer than NODE_NEW_LIMIT. Parameters: - $term: The term ID of the forum. - $uid: The user ID. Returns: The number of new posts in the forum that have not been read by the user. File: modules/forum/forum.module
function _forum_topics_unread($term, $uid) { $query = db_select('node', 'n'); $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $term)); $query->leftJoin('history', 'h', 'n.nid = h.nid AND h.uid = :uid', array(':uid' => $uid)); $query->addExpression('COUNT(n.nid)', 'count'); return ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bdaed21a67
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_admin_blocks/7.x
I need the code for `dashboard_admin_blocks()` in Drupal 7 (modules/dashboard/dashboard.module). It must do this: Page callback: Builds the page for administering dashboard blocks.
This page reuses the Block module's administration form but limits editing to blocks that are available to appear on the dashboard. File: modules/dashboard/dashboard.module
function dashboard_admin_blocks() { global $theme_key; drupal_theme_initialize(); module_load_include('inc', 'block', 'block.admin'); // Prepare the blocks for the current theme, and remove those that are // currently displayed in non-dashboard regions. // @todo This assumes the current page is being displ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bdc1ae6638
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_comment/7.x
In Drupal 7, write the function `rdf_preprocess_comment(&$variables)` (file modules/rdf/rdf.module) so that it does the following: Implements MODULE_preprocess_HOOK().
File: modules/rdf/rdf.module
function rdf_preprocess_comment(&$variables) { $comment = $variables['comment']; if (!empty($comment->rdf_mapping['rdftype'])) { // Adds RDFa markup to the comment container. The about attribute specifies // the URI of the resource described within the HTML element, while the // typeof attribute indicat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bdd092a922
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render_cid_parts/7.x
Implement `drupal_render_cid_parts($granularity = NULL)` in PHP for Drupal 7. Required behavior: Returns cache ID parts for building a cache ID.
Parameters: - $granularity: One or more cache granularity constants. For example, to cache separately for each user, use DRUPAL_CACHE_PER_USER. To cache separately for each page and role, use the expression: @code DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE @endcode Returns: An array of cache ID parts, always contai...
function drupal_render_cid_parts($granularity = NULL) { global $theme, $base_root, $user; $cid_parts[] = $theme; // If Locale is enabled but we have only one language we do not need it as cid // part. if (drupal_multilingual()) { foreach (language_types_configurable() as $language_type) { $cid_part...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bdd7329b51
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_view/7.x
In Drupal 7, write the function `field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL, $options = array())` (file modules/field/field.attach.inc) so that it does the following: Returns a renderable array for the fields on an entity.
Each field is displayed according to the display options specified in the $instance definition for the given $view_mode. field_attach_prepare_view() and field_attach_view() are two halves of the same operation. It is safe to call field_attach_prepare_view() multiple times on the same entity before calling field_attach...
function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL, $options = array()) { // Validate $options since this is a new parameter added after Drupal 7 was // released. $options = is_array($options) ? $options : array(); // Determine the actual language to display for each field, given th...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-bddba78f0a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_field_attach_create_bundle/7.x
I need the code for `field_ui_field_attach_create_bundle($entity_type, $bundle)` in Drupal 7 (modules/field_ui/field_ui.module). It must do this: Implements hook_field_attach_create_bundle().
File: modules/field_ui/field_ui.module
function field_ui_field_attach_create_bundle($entity_type, $bundle) { // When a new bundle is created, the menu needs to be rebuilt to add our // menu item tabs. variable_set('menu_rebuild_needed', TRUE); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-be0b2cf9fb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_types_set/7.x
I need the code for `language_types_set()` in Drupal 7 (includes/language.inc). It must do this: Updates the language type configuration.
File: includes/language.inc
function language_types_set() { // Ensure that we are getting the defined language negotiation information. An // invocation of module_enable() or module_disable() could outdate the cached // information. drupal_static_reset('language_types_info'); drupal_static_reset('language_negotiation_info'); // Deter...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-be27e58bca
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_build_filter_query/7.x
In Drupal 7, write the function `user_build_filter_query(SelectQuery $query)` (file modules/user/user.module) so that it does the following: Extends a query object for user administration filters based on session.
Parameters: - $query: Query object that should be filtered. File: modules/user/user.module
function user_build_filter_query(SelectQuery $query) { $filters = user_filters(); // Extend Query with filter conditions. foreach (isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array() as $filter) { list($key, $value) = $filter; // This checks to see if this permission fil...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-be6bd84e3a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21image.inc/function/image_load/7.x
Implement `image_load($file, $toolkit = FALSE)` in PHP for Drupal 7. Required behavior: Loads an image file and returns an image object.
Any changes to the file are not saved until image_save() is called. Parameters: - $file: Path to an image file. - $toolkit: An optional, image toolkit name to override the default. Returns: An image object or FALSE if there was a problem loading the file. The image object has the following properties: - 'source' - Th...
function image_load($file, $toolkit = FALSE) { if (!$toolkit) { $toolkit = image_get_toolkit(); } if ($toolkit) { $image = new stdClass(); $image->source = $file; $image->info = image_get_info($file, $toolkit); if (isset($image->info) && is_array($image->info)) { $image->toolkit = $toolk...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-be758c5dc7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_admin_settings/7.x
In Drupal 7, write the function `forum_admin_settings($form)` (file modules/forum/forum.admin.inc) so that it does the following: Form constructor for the forum settings page.
File: modules/forum/forum.admin.inc
function forum_admin_settings($form) { $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500)); $form['forum_hot_topic'] = array('#type' => 'select', '#title' => t('Hot topic threshold'), '#default_value' => variable_get('forum_hot_topic', 15), ...
[ "code-task", "function" ]
2026-09-30T00:00:00