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-4d10dfe70d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_simplify_excerpt_match/7.x
Implement `search_simplify_excerpt_match($key, $text, $offset, $boundary)` in PHP for Drupal 7. Required behavior: Find words in the original text that matched via search_simplify().
This is called in search_excerpt() if an exact match is not found in the text, so that we can find the derived form that matches. Parameters: - $key: The keyword to find. - $text: The text to search for the keyword. - $offset: Offset position in $text to start searching at. - $boundary: Text to include in a regular ex...
function search_simplify_excerpt_match($key, $text, $offset, $boundary) { $pos = NULL; $simplified_key = search_simplify($key); $simplified_text = search_simplify($text); // Return immediately if simplified key or text are empty. if (!$simplified_key || !$simplified_text) { return FALSE; } // Check ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d1248107b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_select/7.x
Implement `db_select($table, $alias = NULL, array $options = array())` in PHP for Drupal 7. Required behavior: Returns a new SelectQuery object for the active database.
Parameters: - $table: The base table for this query. May be a string or another SelectQuery object. If a query object is passed, it will be used as a subselect. - $alias: The alias for the base table of this query. - $options: An array of options to control how the query operates. Returns: SelectQuery A new SelectQuer...
function db_select($table, $alias = NULL, array $options = array()) { if (empty($options['target'])) { $options['target'] = 'default'; } return Database::getConnection($options['target'])->select($table, $alias, $options); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d2b2348b8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_get_available/7.x
Implement `update_get_available($refresh = FALSE)` in PHP for Drupal 7. Required behavior: Tries to get update information from cache and refreshes it when necessary.
In addition to checking the cache lifetime, this function also ensures that there are no .info files for enabled modules or themes that have a newer modification timestamp than the last time we checked for available update data. If any .info file was modified, it almost certainly means a new version of something was in...
function update_get_available($refresh = FALSE) { module_load_include('inc', 'update', 'update.compare'); $needs_refresh = FALSE; // Grab whatever data we currently have cached in the DB. $available = _update_get_cached_available_releases(); $num_avail = count($available); $projects = update_get_projects(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d2fe2e6c9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_edit_menu_submit/7.x
In Drupal 7, write the function `menu_edit_menu_submit($form, &$form_state)` (file modules/menu/menu.admin.inc) so that it does the following: Submit function for adding or editing a custom menu.
File: modules/menu/menu.admin.inc
function menu_edit_menu_submit($form, &$form_state) { $menu = $form_state['values']; $path = 'admin/structure/menu/manage/'; if ($form['#insert']) { // Add 'menu-' to the menu name to help avoid name-space conflicts. $menu['menu_name'] = 'menu-' . $menu['menu_name']; $link['link_title'] = $menu['title...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d387d20e9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_update/7.x
In Drupal 7, write the function `field_attach_update($entity_type, $entity)` (file modules/field/field.attach.inc) so that it does the following: Save field data for an existing entity.
When calling this function outside an entity save operation be sure to clear caches for the entity: Parameters: - $entity_type: The type of $entity; e.g. 'node' or 'user'. - $entity: The entity with fields to save. File: modules/field/field.attach.inc
function field_attach_update($entity_type, $entity) { _field_invoke('update', $entity_type, $entity); list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); // Let any module update field data before the storage engine, accumulating // saved fields along the way. $skip_fields = array(); for...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d44de3150
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_button/7.x
In Drupal 7, write the function `theme_button($variables)` (file includes/form.inc) so that it does the following: Returns HTML for a button form element.
Parameters: - $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #attributes, #button_type, #name, #value. File: includes/form.inc
function theme_button($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'submit'; element_set_attributes($element, array('id', 'name', 'value')); // Remove name attribute, if empty, for W3C compliance. if (isset($element['#attributes']['name']) && $element['#attributes']['name...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d496369ab
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_archiver_info/7.x
Give me the example code for `hook_archiver_info()` in Drupal 7. Hook description: Declare archivers to the system.
An archiver is a class that is able to package and unpackage one or more files into a single possibly compressed file. Common examples of such files are zip files and tar.gz files. All archiver classes must implement ArchiverInterface. Each entry should be keyed on a unique value, and specify three additional keys: ...
function hook_archiver_info() { return array( 'tar' => array( 'class' => 'ArchiverTar', 'extensions' => array('tar', 'tar.gz', 'tar.bz2'), ), ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4d55aab7cb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/element_info/7.x
In Drupal 7, write the function `element_info($type)` (file includes/common.inc) so that it does the following: Retrieves the default properties for the defined element type.
Parameters: - $type: An element type as defined by hook_element_info(). File: includes/common.inc
function element_info($type) { // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { $drupal_static_fast['cache'] = &drupal_static(__FUNCTION__); } $cache = &$drupal_static_fast['cache']; if (!isset($cache)) { $c...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d610c7ee5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_delete_form/7.x
Implement `image_style_delete_form($form, &$form_state, $style)` in PHP for Drupal 7. Required behavior: Form builder; Form for deleting an image style.
Parameters: - $style: An image style array. File: modules/image/image.admin.inc
function image_style_delete_form($form, &$form_state, $style) { $form_state['image_style'] = $style; $replacement_styles = array_diff_key(image_style_options(TRUE, PASS_THROUGH), array($style['name'] => '')); $form['replacement'] = array( '#title' => t('Replacement style'), '#type' => 'select', '#opt...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4d683387bc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_info/7.x
In Drupal 7, show an example implementation for `hook_entity_info()` (modules/system/system.api.php): Inform the base system and the Field API about one or more entity types.
Inform the system about one or more entity types (i.e., object types that can be loaded via entity_load() and, optionally, to which fields can be attached). Returns: An array whose keys are entity type names and whose values identify properties of those types that the system needs to know about: - label: The human-rea...
function hook_entity_info() { $return = array( 'node' => array( 'label' => t('Node'), 'controller class' => 'NodeController', 'base table' => 'node', 'revision table' => 'node_revision', 'uri callback' => 'node_uri', 'fieldable' => TRUE, 'translation' => array( 'l...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4db47b7ecd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_download_batch_finished/7.x
I need the code for `update_manager_download_batch_finished($success, $results)` in Drupal 7 (modules/update/update.manager.inc). It must do this: Implements callback_batch_finished().
Batch callback: Performs actions when the download batch is completed. Parameters: - $success: TRUE if the batch operation was successful, FALSE if there were errors. - $results: An associative array of results from the batch operation. File: modules/update/update.manager.inc
function update_manager_download_batch_finished($success, $results) { if (!empty($results['errors'])) { $error_list = array( 'title' => t('Downloading updates failed:'), 'items' => $results['errors'], ); drupal_set_message(theme('item_list', $error_list), 'error'); } elseif ($success) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4de6229492
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7.x
Implement `drupal_render(&$elements)` in PHP for Drupal 7. Required behavior: Renders HTML given a structured array tree.
Recursively iterates over each of the array elements, generating HTML code. Renderable arrays have two kinds of key/value pairs: properties and children. Properties have keys starting with '#' and their values influence how the array will be rendered. Children are all elements whose keys do not start with a '#'. Their...
function drupal_render(&$elements) { // Early-return nothing if user does not have access. if (empty($elements) || !is_array($elements) || (isset($elements['#access']) && !$elements['#access'])) { return ''; } // Do not print elements twice. if (!empty($elements['#printed'])) { return ''; } // T...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4de87012d9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_form_node_type_form_alter/7.x
Implement `comment_form_node_type_form_alter(&$form, $form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter().
File: modules/comment/comment.module
function comment_form_node_type_form_alter(&$form, $form_state) { if (isset($form['type'])) { $form['comment'] = array( '#type' => 'fieldset', '#title' => t('Comment settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'additional_settings', '#attributes' => ar...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4e03a7330c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_write_compare/7.x
In Drupal 7, write the function `_field_sql_storage_write_compare($field, $entity1, $entity2)` (file modules/field/modules/field_sql_storage/field_sql_storage.module) so that it does the following: Compare a single field value for both entities and tell us if it changed.
Parameters: - $field (array): Loaded field structure. - $entity1 (object): First entity to compare. - $entity2 (object): Second entity to compare. Returns (bool): True if field value changed, false otherwise. File: modules/field/modules/field_sql_storage/field_sql_storage.module
function _field_sql_storage_write_compare($field, $entity1, $entity2) { $field_name = $field['field_name']; if (empty($entity1->$field_name) && empty($entity2->$field_name)) { // Both are empty we can safely assume that it did not change. return FALSE; } if (!isset($entity1->$field_name) || !isset($enti...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4e1a3e3b07
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.admin.inc/function/path_admin_delete_confirm/7.x
Implement `path_admin_delete_confirm($form, &$form_state, $path)` in PHP for Drupal 7. Required behavior: Form constructor for the path deletion form.
Parameters: - $path: The path alias that will be deleted. File: modules/path/path.admin.inc
function path_admin_delete_confirm($form, &$form_state, $path) { if (user_access('administer url aliases')) { $form_state['path'] = $path; return confirm_form( $form, t('Are you sure you want to delete path alias %title?', array('%title' => $path['alias'])), 'admin/config/search/path' ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4e30195d44
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/variable_initialize/7.x
I need the code for `variable_initialize($conf = array())` in Drupal 7 (includes/bootstrap.inc). It must do this: Loads the persistent variable table.
The variable table is composed of values that have been saved in the table with variable_set() as well as those explicitly specified in the configuration file. File: includes/bootstrap.inc
function variable_initialize($conf = array()) { // NOTE: caching the variables improves performance by 20% when serving // cached pages. if ($cached = cache_get('variables', 'cache_bootstrap')) { $variables = $cached->data; } else { // Cache miss. Avoid a stampede by acquiring a lock. If the lock fail...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4e6bf40cd9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_form_node_form_alter/7.x
Implement `translation_form_node_form_alter(&$form, &$form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_BASE_FORM_ID_alter() for node_form().
Alters language fields on node edit forms when a translation is about to be created. File: modules/translation/translation.module
function translation_form_node_form_alter(&$form, &$form_state) { if (translation_supported_type($form['#node']->type)) { $node = $form['#node']; $languages = language_list('enabled'); $disabled_languages = isset($languages[0]) ? $languages[0] : FALSE; $translator_widget = $disabled_languages && user_...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4e78944048
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_view/7.x
I need the code for `poll_view($node, $view_mode)` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_view().
File: modules/poll/poll.module
function poll_view($node, $view_mode) { if (!empty($node->allowvotes) && empty($node->show_results)) { $node->content['poll_view_voting'] = drupal_get_form('poll_view_voting', $node); } else { $node->content['poll_view_results'] = array('#markup' => poll_view_results($node, $view_mode)); } return $nod...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4e9cdfe884
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_effect_load/7.x
I need the code for `image_effect_load($ieid, $style_name, $include = NULL)` in Drupal 7 (modules/image/image.module). It must do this: Loads a single image effect.
Parameters: - $ieid: The image effect ID. - $style_name: The image style name. - $include: If set, this loader will restrict to a specific type of image style, may be one of the defined Image style storage constants. Returns: An image effect array, consisting of the following keys: - "ieid": The unique image effect ID...
function image_effect_load($ieid, $style_name, $include = NULL) { if (($style = image_style_load($style_name, NULL, $include)) && isset($style['effects'][$ieid])) { return $style['effects'][$ieid]; } return FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4ea7d31dc8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpcs.inc/function/xmlrpc_server_multicall/7.x
Implement `xmlrpc_server_multicall($methodcalls)` in PHP for Drupal 7. Required behavior: Dispatches multiple XML-RPC requests.
Parameters: - $methodcalls (array): An array of XML-RPC requests to make. Each request is an array with the following elements: - methodName: Name of the method to invoke. - params: Parameters to pass to the method. Returns: An array of the results of each request. File: includes/xmlrpcs.inc
function xmlrpc_server_multicall($methodcalls) { // See http://www.xmlrpc.com/discuss/msgReader$1208 // To avoid multicall expansion attacks, limit the number of duplicate method // calls allowed with a default of 1. Set to -1 for unlimited. $duplicate_method_limit = variable_get('xmlrpc_multicall_duplicate_met...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4eacef8527
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_export/7.x
I need the code for `book_node_export($node, $children = '')` in Drupal 7 (modules/book/book.module). It must do this: Generates printer-friendly HTML for a node.
Parameters: - $node: The node that will be output. - $children: (optional) All the rendered child nodes within the current node. Defaults to an empty string. Returns: The HTML generated for the given node. File: modules/book/book.module
function book_node_export($node, $children = '') { $build = node_view($node, 'print'); unset($build['#theme']); // @todo Rendering should happen in the template using render(). $node->rendered = drupal_render($build); return theme('book_node_export_html', array('node' => $node, 'children' => $children)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4eb442cab7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_html/7.x
I need the code for `_filter_html($text, $filter)` in Drupal 7 (modules/filter/filter.module). It must do this: Implements callback_filter_process().
Provides filtering of input into accepted HTML. File: modules/filter/filter.module
function _filter_html($text, $filter) { $allowed_tags = preg_split('/\s+|<|>/', $filter->settings['allowed_html'], -1, PREG_SPLIT_NO_EMPTY); $text = filter_xss($text, $allowed_tags); if ($filter->settings['filter_html_nofollow']) { $html_dom = filter_dom_load($text); $links = $html_dom->getElementsByTagN...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4ebdaa526e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/_blog_post_exists/7.x
In Drupal 7, write the function `_blog_post_exists($account)` (file modules/blog/blog.module) so that it does the following: Helper function to determine if a user has blog posts already.
File: modules/blog/blog.module
function _blog_post_exists($account) { return (bool)db_select('node', 'n') ->fields('n', array('nid')) ->condition('type', 'blog') ->condition('uid', $account->uid) ->condition('status', 1) ->range(0, 1) ->addTag('node_access') ->execute() ->fetchField(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4ed322629f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_info_max_weight/7.x
Give me the example code for `hook_field_info_max_weight($entity_type, $bundle, $context)` in Drupal 7. Hook description: Returns the maximum weight for the entity components handled by the module.
Field API takes care of fields and 'extra_fields'. This hook is intended for third-party modules adding other entity components (e.g. field_group). Parameters: - $entity_type: The type of entity; e.g. 'node' or 'user'. - $bundle: The bundle name. - $context: The context for which the maximum weight is requested. Eithe...
function hook_field_info_max_weight($entity_type, $bundle, $context) { $weights = array(); foreach (my_module_entity_additions($entity_type, $bundle, $context) as $addition) { $weights[] = $addition['weight']; } return $weights ? max($weights) : NULL; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4eec9ec7af
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_ranking/7.x
In Drupal 7, show an example implementation for `hook_ranking()` (modules/node/node.api.php): Provide additional methods of scoring for core search results for nodes.
A node's search score is used to rank it among other nodes matched by the search, with the highest-ranked nodes appearing first in the search listing. For example, a module allowing users to vote on content could expose an option to allow search results' rankings to be influenced by the average voting score of a node....
function hook_ranking() { // If voting is disabled, we can avoid returning the array, no hard feelings. if (variable_get('vote_node_enabled', TRUE)) { return array( 'vote_average' => array( 'title' => t('Average vote'), // Note that we use i.sid, the search index's search item id, rather t...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4f4f1bab6a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_theme/7.x
I need the code for `user_theme()` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_theme().
File: modules/user/user.module
function user_theme() { return array( 'user_picture' => array( 'variables' => array('account' => NULL), 'template' => 'user-picture', ), 'user_profile' => array( 'render element' => 'elements', 'template' => 'user-profile', 'file' => 'user.pages.inc', ), 'user_profile...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4f6105ef79
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_dependencies/7.x
I need the code for `image_update_dependencies()` in Drupal 7 (modules/image/image.install). It must do this: Implements hook_update_dependencies().
File: modules/image/image.install
function image_update_dependencies() { $dependencies['image'][7002] = array( // Image update 7002 uses field API functions, so must run after // Field API has been enabled. 'system' => 7020, ); return $dependencies; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4f79be79a5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_7003/7.x
In Drupal 7, write the function `forum_update_7003()` (file modules/forum/forum.install) so that it does the following: Rename field to 'taxonomy_forums'.
File: modules/forum/forum.install
function forum_update_7003() { $messages = array(); $new_field_name = 'taxonomy_forums'; // Test to see if the taxonomy_forums field exists. $fields = _update_7000_field_read_fields(array('field_name' => $new_field_name)); if ($fields) { // Since the field exists, we're done. return; } // Calcu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4f7e77f690
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_install/7.x
Implement `node_install()` in PHP for Drupal 7. Required behavior: Implements hook_install().
File: modules/node/node.install
function node_install() { // Populate the node access table. db_insert('node_access') ->fields(array( 'nid' => 0, 'gid' => 0, 'realm' => 'all', 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0, )) ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4f821769cd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_menu_site_status_alter/7.x
I need the code for `user_menu_site_status_alter(&$menu_site_status, $path)` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_menu_site_status_alter().
File: modules/user/user.module
function user_menu_site_status_alter(&$menu_site_status, $path) { if ($menu_site_status == MENU_SITE_OFFLINE) { // If the site is offline, log out unprivileged users. if (user_is_logged_in() && !user_access('access site in maintenance mode')) { module_load_include('pages.inc', 'user', 'user'); use...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4fa27a831b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21syslog%21syslog.module/function/syslog_watchdog/7.x
In Drupal 7, write the function `syslog_watchdog(array $log_entry)` (file modules/syslog/syslog.module) so that it does the following: Implements hook_watchdog().
File: modules/syslog/syslog.module
function syslog_watchdog(array $log_entry) { global $base_url; $log_init = &drupal_static(__FUNCTION__, FALSE); if (!$log_init) { $log_init = TRUE; $default_facility = defined('LOG_LOCAL0') ? LOG_LOCAL0 : LOG_USER; openlog(variable_get('syslog_identity', 'drupal'), LOG_NDELAY, variable_get('syslog_f...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4ff1ba24cf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.tokens.inc/function/system_tokens/7.x
Implement `system_tokens($type, $tokens, array $data = array(), array $options = array())` in PHP for Drupal 7. Required behavior: Implements hook_tokens().
File: modules/system/system.tokens.inc
function system_tokens($type, $tokens, array $data = array(), array $options = array()) { $url_options = array('absolute' => TRUE); if (isset($options['language'])) { $url_options['language'] = $options['language']; $language_code = $options['language']->language; } else { $language_code = NULL; }...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-500668f0b1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_themes_disabled/7.x
Give me the example code for `hook_themes_disabled($theme_list)` in Drupal 7. Hook description: Respond to themes being disabled.
Parameters: - $theme_list (array): Array containing the names of the themes being disabled. File: modules/system/theme.api.php
function hook_themes_disabled($theme_list) { // Clear all update module caches. _update_cache_clear(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-500dd5f400
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/_simpletest_batch_operation/7.x
Implement `_simpletest_batch_operation($test_list_init, $test_id, &$context)` in PHP for Drupal 7. Required behavior: Implements callback_batch_operation().
File: modules/simpletest/simpletest.module
function _simpletest_batch_operation($test_list_init, $test_id, &$context) { simpletest_classloader_register(); // Get working values. if (!isset($context['sandbox']['max'])) { // First iteration: initialize working values. $test_list = $test_list_init; $context['sandbox']['max'] = count($test_list); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5019066a26
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.admin.inc/function/profile_field_delete_submit/7.x
In Drupal 7, write the function `profile_field_delete_submit($form, &$form_state)` (file modules/profile/profile.admin.inc) so that it does the following: Process a field delete form submission.
File: modules/profile/profile.admin.inc
function profile_field_delete_submit($form, &$form_state) { db_delete('profile_field') ->condition('fid', $form_state['values']['fid']) ->execute(); db_delete('profile_value') ->condition('fid', $form_state['values']['fid']) ->execute(); cache_clear_all(); drupal_set_message(t('The field %fiel...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-501b812fe2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_form_taxonomy_form_term_alter/7.x
In Drupal 7, write the function `forum_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id)` (file modules/forum/forum.module) so that it does the following: Implements hook_form_FORM_ID_alter() for taxonomy_form_term().
File: modules/forum/forum.module
function forum_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) { $vid = variable_get('forum_nav_vocabulary', 0); if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) { // Hide multiple parents select from forum terms. $form['relations']['parent']['#access'] = FALSE; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-503fc49b51
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_library/7.x
Give me the example code for `hook_library()` in Drupal 7. Hook description: Registers JavaScript/CSS libraries associated with a module.
Modules implementing this return an array of arrays. The key to each sub-array is the machine readable name of the library. Each library may contain the following items: - 'title': The human readable name of the library. - 'website': The URL of the library's web site. - 'version': A string specifying the version of th...
function hook_library() { // Library One. $libraries['library-1'] = array( 'title' => 'Library One', 'website' => 'http://example.com/library-1', 'version' => '1.2', 'js' => array( drupal_get_path('module', 'my_module') . '/library-1.js' => array(), ), 'css' => array( drupal_get_...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-5040990c03
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_edit_page/7.x
Implement `comment_edit_page($comment)` in PHP for Drupal 7. Required behavior: Page callback for comment editing.
File: modules/comment/comment.module
function comment_edit_page($comment) { drupal_set_title(t('Edit comment %comment', array('%comment' => $comment->subject)), PASS_THROUGH); $node = node_load($comment->nid); return drupal_get_form("comment_node_{$node->type}_form", $comment); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-505cb7b2f5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_effect_info/7.x
In Drupal 7, show an example implementation for `hook_image_effect_info()` (modules/image/image.api.php): Define information about image effects provided by a module.
This hook enables modules to define image manipulation effects for use with an image style. Returns: An array of image effects. This array is keyed on the machine-readable effect name. Each effect is defined as an associative array containing the following items: - "label": The human-readable name of the effect. - "ef...
function hook_image_effect_info() { $effects = array(); $effects['mymodule_resize'] = array( 'label' => t('Resize'), 'help' => t('Resize an image to an exact set of dimensions, ignoring aspect ratio.'), 'effect callback' => 'mymodule_resize_effect', 'dimensions callback' => 'mymodule_resize_dimensi...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-508de4cf44
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/_openid_xrds_discovery/7.x
In Drupal 7, write the function `_openid_xrds_discovery($claimed_id)` (file modules/openid/openid.module) so that it does the following: OpenID discovery method: perform a XRDS discovery.
Returns: An array of discovered services and claimed identifier or NULL. See openid_discovery() for more specific information. File: modules/openid/openid.module
function _openid_xrds_discovery($claimed_id) { $services = array(); $xrds_url = $claimed_id; $scheme = @parse_url($xrds_url, PHP_URL_SCHEME); if ($scheme == 'http' || $scheme == 'https') { // For regular URLs, try Yadis resolution first, then HTML-based discovery $headers = array('Accept' => 'applicati...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-50960c58a5
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_verify_settings/7.x
I need the code for `install_verify_settings()` in Drupal 7 (includes/install.core.inc). It must do this: Verifies the existing settings in settings.php.
File: includes/install.core.inc
function install_verify_settings() { global $databases; // Verify existing settings (if any). if (!empty($databases) && install_verify_pdo()) { $database = $databases['default']['default']; drupal_static_reset('conf_path'); $settings_file = './' . conf_path(FALSE) . '/settings.php'; $errors = ins...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5097650be2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_load/7.x
Give me the example code for `hook_user_load($users)` in Drupal 7. Hook description: Act on user objects when loaded from the database.
Due to the static cache in user_load_multiple() you should not use this hook to modify the user properties returned by the {users} table itself since this may result in unreliable results when loading from cache. Parameters: - $users: An array of user objects, indexed by uid. File: modules/user/user.api.php
function hook_user_load($users) { $result = db_query('SELECT uid, foo FROM {my_table} WHERE uid IN (:uids)', array(':uids' => array_keys($users))); foreach ($result as $record) { $users[$record->uid]->foo = $record->foo; } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-50c4dd2224
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_registry_check_code/7.x
I need the code for `_registry_check_code($type, $name = NULL)` in Drupal 7 (includes/bootstrap.inc). It must do this: Checks for a resource in the registry.
Parameters: - $type: The type of resource we are looking up, or one of the constants REGISTRY_RESET_LOOKUP_CACHE or REGISTRY_WRITE_LOOKUP_CACHE, which signal that we should reset or write the cache, respectively. - $name: The name of the resource, or NULL if either of the REGISTRY_* constants is passed in. Returns: TR...
function _registry_check_code($type, $name = NULL) { static $lookup_cache, $cache_update_needed; if ($type == 'class' && class_exists($name) || $type == 'interface' && interface_exists($name) || $type == 'trait' && trait_exists($name)) { return TRUE; } if (!isset($lookup_cache)) { $lookup_cache = arra...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-50c7d5af57
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.admin.inc/function/profile_field_delete/7.x
In Drupal 7, write the function `profile_field_delete($form, &$form_state, $fid)` (file modules/profile/profile.admin.inc) so that it does the following: Menu callback; deletes a field from all user profiles.
File: modules/profile/profile.admin.inc
function profile_field_delete($form, &$form_state, $fid) { $field = db_query("SELECT title FROM {profile_field} WHERE fid = :fid", array(':fid' => $fid))->fetchObject(); if (!$field) { drupal_not_found(); return; } $form['fid'] = array('#type' => 'value', '#value' => $fid); $form['title'] = array('#ty...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-50f10c00a9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21update.inc/function/update_parse_db_url/7.x
I need the code for `update_parse_db_url($db_url, $db_prefix)` in Drupal 7 (includes/update.inc). It must do this: Parse pre-Drupal 7 database connection URLs and return D7 compatible array.
Returns: Drupal 7 DBTNG compatible array of database connection information. File: includes/update.inc
function update_parse_db_url($db_url, $db_prefix) { $databases = array(); if (!is_array($db_url)) { $db_url = array('default' => $db_url); } foreach ($db_url as $database => $url) { $url = parse_url($url); $databases[$database]['default'] = array( // MySQLi uses the mysql driver. 'driver...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-50fd00b362
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/template_preprocess_user_picture/7.x
I need the code for `template_preprocess_user_picture(&$variables)` in Drupal 7 (modules/user/user.module). It must do this: Process variables for user-picture.tpl.php.
The $variables array contains the following arguments: - $account: A user, node or comment object with 'name', 'uid' and 'picture' fields. File: modules/user/user.module
function template_preprocess_user_picture(&$variables) { $variables['user_picture'] = ''; if (variable_get('user_pictures', 0)) { $account = $variables['account']; if (!empty($account->picture)) { // @TODO: Ideally this function would only be passed file objects, but // since there's a lot of le...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-510b00140e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_schema/7.x
I need the code for `forum_schema()` in Drupal 7 (modules/forum/forum.install). It must do this: Implements hook_schema().
File: modules/forum/forum.install
function forum_schema() { $schema['forum'] = array( 'description' => 'Stores the relationship of nodes to forum terms.', 'fields' => array( 'nid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'The {node}.nid of...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-5114eb60fc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/_system_default_theme_features/7.x
In Drupal 7, write the function `_system_default_theme_features()` (file modules/system/system.module) so that it does the following: Returns an array of default theme features.
File: modules/system/system.module
function _system_default_theme_features() { return array( 'logo', 'favicon', 'name', 'slogan', 'node_user_picture', 'comment_user_picture', 'comment_user_verification', 'main_menu', 'secondary_menu', ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5116bab265
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7067/7.x
I need the code for `system_update_7067()` in Drupal 7 (modules/system/system.install). It must do this: Grant administrators permission to view the administration theme.
File: modules/system/system.install
function system_update_7067() { // Users with access to administration pages already see the administration // theme in some places (if one is enabled on the site), so we want them to // continue seeing it. $admin_roles = user_roles(FALSE, 'access administration pages'); foreach (array_keys($admin_roles) as $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-512269b101
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_update_7000/7.x
In Drupal 7, write the function `comment_update_7000()` (file modules/comment/comment.install) so that it does the following: Rename comment display setting variables.
File: modules/comment/comment.install
function comment_update_7000() { $types = _update_7000_node_get_types(); foreach ($types as $type => $type_object) { variable_del('comment_default_order' . $type); // Drupal 6 had four display modes: // - COMMENT_MODE_FLAT_COLLAPSED = 1 // - COMMENT_MODE_FLAT_EXPANDED = 2 // - COMMENT_MODE_THRE...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5124983f4d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_theme/7.x
Implement `toolbar_theme($existing, $type, $theme, $path)` in PHP for Drupal 7. Required behavior: Implements hook_theme().
File: modules/toolbar/toolbar.module
function toolbar_theme($existing, $type, $theme, $path) { $items['toolbar'] = array( 'render element' => 'toolbar', 'template' => 'toolbar', 'path' => drupal_get_path('module', 'toolbar'), ); $items['toolbar_toggle'] = array( 'variables' => array( 'collapsed' => NULL, 'attributes' => a...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-5141e3f26c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_roles_order_submit/7.x
I need the code for `user_admin_roles_order_submit($form, &$form_state)` in Drupal 7 (modules/user/user.admin.inc). It must do this: Form submit function. Update the role weights.
File: modules/user/user.admin.inc
function user_admin_roles_order_submit($form, &$form_state) { foreach ($form_state['values']['roles'] as $rid => $role_values) { $role = $form['roles'][$rid]['#role']; $role->weight = $role_values['weight']; user_role_save($role); } drupal_set_message(t('The role settings have been updated.')); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-51449da558
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_full_redirect_url/7.x
Implement `install_full_redirect_url($install_state)` in PHP for Drupal 7. Required behavior: Returns the complete URL redirected to during an installation request.
Parameters: - $install_state: An array of information about the current installation state. Returns: The complete URL to redirect to. File: includes/install.core.inc
function install_full_redirect_url($install_state) { global $base_url; return $base_url . '/' . install_redirect_url($install_state); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5146e7e944
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_edit_access/7.x
I need the code for `shortcut_set_edit_access($shortcut_set = NULL)` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Access callback for editing a shortcut set.
Parameters: - $shortcut_set (object): (optional) The shortcut set to be edited. If not set, the current user's shortcut set will be used. Returns: TRUE if the current user has access to edit the shortcut set, FALSE otherwise. File: modules/shortcut/shortcut.module
function shortcut_set_edit_access($shortcut_set = NULL) { // Sufficiently-privileged users can edit their currently displayed shortcut // set, but not other sets. Shortcut administrators can edit any set. if (user_access('administer shortcuts')) { return TRUE; } if (user_access('customize shortcut links')...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-516fb965aa
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21module.inc/function/module_disable/7.x
In Drupal 7, write the function `module_disable($module_list, $disable_dependents = TRUE)` (file includes/module.inc) so that it does the following: Disables a given set of modules.
Parameters: - $module_list (string[]): An array of module names. - $disable_dependents (bool): If TRUE, dependent modules will automatically be added and disabled in the correct order. This incurs a significant performance cost, so use FALSE if you know $module_list is already complete and in the correct order. File: ...
function module_disable($module_list, $disable_dependents = TRUE) { if ($disable_dependents) { // Get all module data so we can find dependents and sort. $module_data = system_rebuild_module_data(); // Create an associative array with weights as values. $module_list = array_flip(array_values($module_l...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-516fd56cb6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_settings_form_submit/7.x
In Drupal 7, write the function `system_settings_form_submit($form, &$form_state)` (file modules/system/system.module) so that it does the following: Form submission handler for system_settings_form().
If you want node type configure style handling of your checkboxes, add an array_filter value to your form. File: modules/system/system.module
function system_settings_form_submit($form, &$form_state) { // Exclude unnecessary elements. form_state_values_clean($form_state); foreach ($form_state['values'] as $key => $value) { if (is_array($value) && isset($form_state['values']['array_filter'])) { $value = array_keys(array_filter($value)); }...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-517098c43e
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_preprocess_region/7.x
Implement `garland_preprocess_region(&$variables)` in PHP for Drupal 7. Required behavior: Override or insert variables into the region template.
File: themes/garland/template.php
function garland_preprocess_region(&$variables) { if ($variables['region'] == 'header') { $variables['classes_array'][] = 'clearfix'; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-517806755f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_info_alter/7.x
In Drupal 7, show an example implementation for `hook_field_storage_info_alter(&$info)` (modules/field/field.api.php): Perform alterations on Field API storage types.
Parameters: - $info: An array with information on storage types returned by hook_field_storage_info() implementations. File: modules/field/field.api.php
function hook_field_storage_info_alter(&$info) { // Add a setting to a storage type. $info['field_sql_storage']['settings'] += array( 'mymodule_additional_setting' => 'default value', ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-519165e8fb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.effects.inc/function/image_crop_effect/7.x
Implement `image_crop_effect(&$image, $data)` in PHP for Drupal 7. Required behavior: Image effect callback; Crop an image resource.
Parameters: - $image: An image object returned by image_load(). - $data: An array of attributes to use when performing the crop effect with the following items: - "width": An integer representing the desired width in pixels. - "height": An integer representing the desired height in pixels. - "anchor": A string describi...
function image_crop_effect(&$image, $data) { // Set sane default values. $data += array( 'anchor' => 'center-center', ); list($x, $y) = explode('-', $data['anchor']); $x = image_filter_keyword($x, $image->info['width'], $data['width']); $y = image_filter_keyword($y, $image->info['height'], $data['heigh...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-519a9fa7b6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_file_download/7.x
I need the code for `file_file_download($uri, $field_type = 'file')` in Drupal 7 (modules/file/file.module). It must do this: Implements hook_file_download().
This function takes an extra parameter $field_type so that it may be re-used by other File-like modules, such as Image. File: modules/file/file.module
function file_file_download($uri, $field_type = 'file') { global $user; // Get the file record based on the URI. If not in the database just return. $files = file_load_multiple(array(), array('uri' => $uri)); if (count($files)) { foreach ($files as $item) { // Since some database servers sometimes us...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-51b2a88ab5
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21mail.inc/function/_drupal_html_to_text_pad/7.x
Implement `_drupal_html_to_text_pad($text, $pad, $prefix = '')` in PHP for Drupal 7. Required behavior: Pads the last line with the given character.
File: includes/mail.inc
function _drupal_html_to_text_pad($text, $pad, $prefix = '') { // Remove last line break. $text = substr($text, 0, -1); // Calculate needed padding space and add it. if (($p = strrpos($text, "\n")) === FALSE) { $p = -1; } $n = max(0, 79 - (strlen($text) - $p) - strlen($prefix)); // Add prefix and padd...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-51cc883546
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_theme_disable/7.x
In Drupal 7, write the function `system_theme_disable()` (file modules/system/system.admin.inc) so that it does the following: Menu callback; Disables a theme.
File: modules/system/system.admin.inc
function system_theme_disable() { if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'system-theme-operation-link')) { $theme = $_REQUEST['theme']; // Get current list of themes. $themes = list_themes(); // Check if the specified theme is one recogniz...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-51cc8dcb30
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_update_7003/7.x
Implement `comment_update_7003()` in PHP for Drupal 7. Required behavior: Split {comment}.timestamp into 'created' and 'changed', improve indexing on {comment}.
File: modules/comment/comment.install
function comment_update_7003() { // Drop the old indexes. db_drop_index('comment', 'status'); db_drop_index('comment', 'pid'); // Create a created column. db_add_field('comment', 'created', array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, )); // Rename the timestamp column to chan...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-51d1488c66
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_dependencies/7.x
In Drupal 7, write the function `taxonomy_update_dependencies()` (file modules/taxonomy/taxonomy.install) so that it does the following: Implements hook_update_dependencies().
File: modules/taxonomy/taxonomy.install
function taxonomy_update_dependencies() { // taxonomy_update_7004() migrates taxonomy term data to fields and therefore // must run after all Field modules have been enabled, which happens in // system_update_7027(). $dependencies['taxonomy'][7004] = array( 'system' => 7027, ); return $dependencies; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-51fcbb632b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_uri_scheme/7.x
Implement `file_uri_scheme($uri)` in PHP for Drupal 7. Required behavior: Returns the scheme of a URI (e.g. a stream).
Parameters: - $uri: A stream, referenced as "scheme://target". Returns: A string containing the name of the scheme, or FALSE if none. For example, the URI "public://example.txt" would return "public". File: includes/file.inc
function file_uri_scheme($uri) { $position = strpos((string) $uri, '://'); return $position ? substr($uri, 0, $position) : FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-520370d6b1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_overview_form/7.x
In Drupal 7, write the function `locale_languages_overview_form()` (file modules/locale/locale.admin.inc) so that it does the following: User interface for the language overview screen.
File: modules/locale/locale.admin.inc
function locale_languages_overview_form() { drupal_static_reset('language'); $languages = language_list('language'); $options = array(); $form['weight'] = array('#tree' => TRUE); foreach ($languages as $langcode => $language) { $options[$langcode] = ''; if ($language->enabled) { $enabled[] = $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-520f72e86d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_filter_form_submit/7.x
Implement `dblog_filter_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for dblog_filter_form().
File: modules/dblog/dblog.admin.inc
function dblog_filter_form_submit($form, &$form_state) { $op = $form_state['values']['op']; $filters = dblog_filters(); switch ($op) { case t('Filter'): foreach ($filters as $name => $filter) { if (isset($form_state['values'][$name])) { $_SESSION['dblog_overview_filter'][$name] = $form...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5210f540bc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_revision_list/7.x
In Drupal 7, write the function `node_revision_list($node)` (file modules/node/node.module) so that it does the following: Returns a list of all the existing revision numbers.
Parameters: - $node: The node object. Returns: An associative array keyed by node revision number. File: modules/node/node.module
function node_revision_list($node) { $revisions = array(); $result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revision} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = :nid ORDER BY r.vid DESC', array(':nid' => $nod...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5228222ee7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_form_submit/7.x
I need the code for `image_style_form_submit($form, &$form_state)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Submit handler for saving an image style.
File: modules/image/image.admin.inc
function image_style_form_submit($form, &$form_state) { // Update the image style. $style = $form_state['image_style']; $style['name'] = $form_state['values']['name']; $style['label'] = $form_state['values']['label']; // Update image effect weights. if (!empty($form_state['values']['effects'])) { forea...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5234468ce8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_run_cron/7.x
In Drupal 7, write the function `system_run_cron()` (file modules/system/system.admin.inc) so that it does the following: Menu callback: run cron manually.
File: modules/system/system.admin.inc
function system_run_cron() { if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'run-cron')) { return MENU_ACCESS_DENIED; } // Run cron manually if (drupal_cron_run()) { drupal_set_message(t('Cron ran successfully.')); } else { drupal_set_message(t('Cron run failed.'), 'error'); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-523950fdfa
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_permission/7.x
In Drupal 7, write the function `field_permission()` (file modules/field/field.module) so that it does the following: Implements hook_permission().
File: modules/field/field.module
function field_permission() { return array( 'administer fields' => array( 'title' => t('Administer fields'), 'description' => t('Additional permissions are required based on what the fields are attached to (for example, <a href="@url">administer content types</a> to manage fields attached to content)....
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-5239aa1a5c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_value_get_xml/7.x
I need the code for `xmlrpc_value_get_xml($xmlrpc_value)` in Drupal 7 (includes/xmlrpc.inc). It must do this: Generates XML representing the given value.
Parameters: - $xmlrpc_value: A value to be represented in XML. Returns: XML representation of $xmlrpc_value. File: includes/xmlrpc.inc
function xmlrpc_value_get_xml($xmlrpc_value) { switch ($xmlrpc_value->type) { case 'boolean': return '<boolean>' . (($xmlrpc_value->data) ? '1' : '0') . '</boolean>'; case 'int': return '<int>' . $xmlrpc_value->data . '</int>'; case 'double': return '<double>' . $xmlrpc_value->data . '...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-52419d4ee6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_widget_uri/7.x
Implement `file_field_widget_uri($field, $instance, $data = array())` in PHP for Drupal 7. Required behavior: Determines the URI for a file field instance.
Parameters: - $field: A field array. - $instance: A field instance array. - $data: An array of token objects to pass to token_replace(). Returns: A file directory URI with tokens replaced. File: modules/file/file.field.inc
function file_field_widget_uri($field, $instance, $data = array()) { $destination = trim($instance['settings']['file_directory'], '/'); // Replace tokens. $destination = token_replace($destination, $data); return $field['settings']['uri_scheme'] . '://' . $destination; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5252c614c1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/_simpletest_batch_finished/7.x
I need the code for `_simpletest_batch_finished($success, $results, $operations, $elapsed)` in Drupal 7 (modules/simpletest/simpletest.module). It must do this: Implements callback_batch_finished().
File: modules/simpletest/simpletest.module
function _simpletest_batch_finished($success, $results, $operations, $elapsed) { if ($success) { drupal_set_message(t('The test run finished in @elapsed.', array('@elapsed' => $elapsed))); } else { // Use the test_id passed as a parameter to _simpletest_batch_operation(). $test_id = $operations[0][1][...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5260ba9633
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_node_view/7.x
In Drupal 7, write the function `translation_node_view($node, $view_mode)` (file modules/translation/translation.module) so that it does the following: Implements hook_node_view().
Displays translation links with language names if this node is part of a translation set. If no language provider is enabled, "fall back" to simple links built through the result of translation_node_get_translations(). File: modules/translation/translation.module
function translation_node_view($node, $view_mode) { // If the site has no translations or is not multilingual we have no content // translation links to display. if (isset($node->tnid) && drupal_multilingual() && $translations = translation_node_get_translations($node->tnid)) { $languages = language_list('ena...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-52681eda00
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_init/7.x
Implement `update_init()` in PHP for Drupal 7. Required behavior: Implements hook_init().
File: modules/update/update.module
function update_init() { if (arg(0) == 'admin' && user_access('administer site configuration')) { switch ($_GET['q']) { // These pages don't need additional nagging. case 'admin/appearance/update': case 'admin/appearance/install': case 'admin/modules/update': case 'admin/modules/inst...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-526a83b62e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_select_service/7.x
Implement `_openid_select_service(array $services)` in PHP for Drupal 7. Required behavior: Select a service element.
The procedure is described in OpenID Authentication 2.0, section 7.3.2. A new entry is added to the returned array with the key 'version' and the value 1 or 2 specifying the protocol version used by the service. Parameters: - $services: An array of service arrays as returned by openid_discovery(). Returns: The selec...
function _openid_select_service(array $services) { // Extensible Resource Identifier (XRI) Resolution Version 2.0, section 4.3.3: // Find the service with the highest priority (lowest integer value). If there // is a tie, select a random one, not just the first in the XML document. shuffle($services); $select...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-528167b441
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.api.php/function/hook_file_download_access_alter/7.x
In Drupal 7, show an example implementation for `hook_file_download_access_alter(&$grants, $file_item, $entity_type, $entity)` (modules/file/file.api.php): Alter the access rules applied to a file download.
Entities that implement file management set the access rules for their individual files. Module may use this hook to create custom access rules for file downloads. Parameters: - $grants: An array of grants gathered by hook_file_download_access(). The array is keyed by the module that defines the entity type's access c...
function hook_file_download_access_alter(&$grants, $file_item, $entity_type, $entity) { // For our example module, we always enforce the rules set by node module. if (isset($grants['node'])) { $grants = array('node' => $grants['node']); } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-528280b36a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_block_save/7.x
Implement `statistics_block_save($delta = '', $edit = array())` in PHP for Drupal 7. Required behavior: Implements hook_block_save().
File: modules/statistics/statistics.module
function statistics_block_save($delta = '', $edit = array()) { variable_set('statistics_block_top_day_num', $edit['statistics_block_top_day_num']); variable_set('statistics_block_top_all_num', $edit['statistics_block_top_all_num']); variable_set('statistics_block_top_last_num', $edit['statistics_block_top_last_nu...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-528588df42
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7006/7.x
Implement `taxonomy_update_7006()` in PHP for Drupal 7. Required behavior: Add {taxonomy_term_data}.format column.
File: modules/taxonomy/taxonomy.install
function taxonomy_update_7006() { db_add_field('taxonomy_term_data', 'format', array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'The {filter_format}.format of the description.', )); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-528758cb1c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_link_update/7.x
In Drupal 7, show an example implementation for `hook_menu_link_update($link)` (modules/system/system.api.php): Inform modules that a menu link has been updated.
This hook is used to notify modules that menu items have been updated. Contributed modules may use the information to perform actions based on the information entered into the menu system. Parameters: - $link: Associative array defining a menu link as passed into menu_link_save(). File: modules/system/system.api.php
function hook_menu_link_update($link) { // If the parent menu has changed, update our record. $menu_name = db_query("SELECT menu_name FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid']))->fetchField(); if ($menu_name != $link['menu_name']) { db_update('menu_example') ->fields(array(...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-52a4c634bd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_uri/7.x
I need the code for `node_uri($node)` in Drupal 7 (modules/node/node.module). It must do this: Implements callback_entity_info_uri().
File: modules/node/node.module
function node_uri($node) { return array( 'path' => 'node/' . $node->nid, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-52c932935c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_styles/7.x
In Drupal 7, write the function `image_styles()` (file modules/image/image.module) so that it does the following: Gets an array of all styles and their settings.
Returns: An array of styles keyed by the image style ID (isid). File: modules/image/image.module
function image_styles() { $styles = &drupal_static(__FUNCTION__); // Grab from cache or build the array. if (!isset($styles)) { if ($cache = cache_get('image_styles', 'cache')) { $styles = $cache->data; } else { $styles = array(); // Select the module-defined styles. foreach ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-52d4721fcd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21authorize.inc/function/authorize_filetransfer_form/7.x
Implement `authorize_filetransfer_form($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form constructor for the file transfer authorization form.
Allows the user to choose a FileTransfer type and supply credentials. File: includes/authorize.inc
function authorize_filetransfer_form($form, &$form_state) { global $base_url, $is_https; $form = array(); // If possible, we want to post this form securely via HTTPS. $form['#https'] = TRUE; // CSS we depend on lives in modules/system/maintenance.css, which is loaded // via the default maintenance theme....
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-52d5f5ce77
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_clean_url_settings/7.x
In Drupal 7, write the function `system_clean_url_settings($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Form builder; Configure clean URL settings.
File: modules/system/system.admin.inc
function system_clean_url_settings($form, &$form_state) { $available = FALSE; $conflict = FALSE; // If the request URI is a clean URL, clean URLs must be available. // Otherwise, run a test. if (strpos(request_uri(), '?q=') === FALSE && strpos(request_uri(), '&q=') === FALSE) { $available = TRUE; } e...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-5306190554
7
drupal_api_code
https://api.drupal.org/api/drupal/update.php/function/update_access_denied_page/7.x
I need the code for `update_access_denied_page()` in Drupal 7 (update.php). It must do this: Renders a 403 access denied page for update.php.
Returns: Rendered HTML warning with 403 status. File: update.php
function update_access_denied_page() { drupal_add_http_header('Status', '403 Forbidden'); watchdog('access denied', 'update.php', NULL, WATCHDOG_WARNING); drupal_set_title('Access denied'); return '<p>Access denied. You are not authorized to access this page. Log in using either an account with the <em>administ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-53375ac9fd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_pre_render_scripts/7.x
Implement `drupal_pre_render_scripts(array $elements)` in PHP for Drupal 7. Required behavior: The #pre_render callback for the "scripts" element.
This callback adds elements needed for <script> tags to be rendered. Parameters: - $elements (array): A render array containing: - '#items': The JS items as returned by drupal_add_js() and altered by drupal_get_js(). Returns (array): The $elements variable passed as argument with two more children keys: - "scripts": ...
function drupal_pre_render_scripts(array $elements) { $preprocess_js = (variable_get('preprocess_js', FALSE) && !defined('MAINTENANCE_MODE')); // A dummy query-string is added to filenames, to gain control over // browser-caching. The string changes on every update or full cache // flush, forcing browsers to l...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-53712ff348
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_update_dependencies/7.x
In Drupal 7, show an example implementation for `hook_update_dependencies()` (modules/system/system.api.php): Return an array of information about module update dependencies.
This can be used to indicate update functions from other modules that your module's update functions depend on, or vice versa. It is used by the update system to determine the appropriate order in which updates should be run, as well as to search for missing dependencies. Implementations of this hook should be placed ...
function hook_update_dependencies() { // Indicate that the mymodule_update_7000() function provided by this module // must run after the another_module_update_7002() function provided by the // 'another_module' module. $dependencies['mymodule'][7000] = array( 'another_module' => 7002, ); // Indicate tha...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-5388fe1f2e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21cache.inc/function/cache_clear_all/7.x
I need the code for `cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE)` in Drupal 7 (includes/cache.inc). It must do this: Expires data from the cache.
If called with the arguments $cid and $bin set to NULL or omitted, then expirable entries will be cleared from the cache_page and cache_block bins, and the $wildcard argument is ignored. Parameters: - $cid: If set, the cache ID or an array of cache IDs. Otherwise, all cache entries that can expire are deleted. The $wi...
function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) { if (!isset($cid) && !isset($bin)) { // Clear the block cache first, so stale data will // not end up in the page cache. if (module_exists('block')) { cache_clear_all(NULL, 'cache_block'); } cache_clear_all(NULL, 'cache_p...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-539ee340d1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_mail/7.x
In Drupal 7, write the function `user_mail($key, &$message, $params)` (file modules/user/user.module) so that it does the following: Implements hook_mail().
File: modules/user/user.module
function user_mail($key, &$message, $params) { $language = $message['language']; $variables = array('user' => $params['account']); $message['subject'] .= _user_mail_text($key . '_subject', $language, $variables); $message['body'][] = _user_mail_text($key . '_body', $language, $variables); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-53a0360b39
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_provider_weight/7.x
Implement `language_provider_weight($provider)` in PHP for Drupal 7. Required behavior: Returns the passed language negotiation provider weight or a default value.
Parameters: - $provider: A language negotiation provider data structure. Returns: A numeric weight. File: includes/language.inc
function language_provider_weight($provider) { $default = is_numeric($provider) ? $provider : 0; return isset($provider['weight']) && is_numeric($provider['weight']) ? $provider['weight'] : $default; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-53a789a981
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.pages.inc/function/taxonomy_autocomplete/7.x
I need the code for `taxonomy_autocomplete($field_name = '', $tags_typed = '')` in Drupal 7 (modules/taxonomy/taxonomy.pages.inc). It must do this: Page callback: Outputs JSON for taxonomy autocomplete suggestions.
Path: taxonomy/autocomplete This callback outputs term name suggestions in response to Ajax requests made by the taxonomy autocomplete widget for taxonomy term reference fields. The output is a JSON object of plain-text term suggestions, keyed by the user-entered value with the completed term name appended. Term name...
function taxonomy_autocomplete($field_name = '', $tags_typed = '') { // If the request has a '/' in the search text, then the menu system will have // split it into multiple arguments, recover the intended $tags_typed. $args = func_get_args(); // Shift off the $field_name argument. array_shift($args); $tags...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-53edbccfa6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_entity_info/7.x
In Drupal 7, write the function `system_entity_info()` (file modules/system/system.module) so that it does the following: Implements hook_entity_info().
File: modules/system/system.module
function system_entity_info() { return array( 'file' => array( 'label' => t('File'), 'base table' => 'file_managed', 'entity keys' => array( 'id' => 'fid', 'label' => 'filename', ), 'static cache' => FALSE, ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-540751732f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21language.api.php/function/hook_language_types_info/7.x
In Drupal 7, show an example implementation for `hook_language_types_info()` (modules/system/language.api.php): Define language types.
Returns: An associative array of language type definitions. The keys are the identifiers, which are also used as names for global variables representing the types in the bootstrap phase. The values are associative arrays that may contain the following elements: - name: The human-readable language type identifier. - des...
function hook_language_types_info() { return array( 'custom_language_type' => array( 'name' => t('Custom language'), 'description' => t('A custom language type.'), ), 'fixed_custom_language_type' => array( 'fixed' => array('custom_language_provider'), ), ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-54393e1ea6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.install/function/book_schema/7.x
I need the code for `book_schema()` in Drupal 7 (modules/book/book.install). It must do this: Implements hook_schema().
File: modules/book/book.install
function book_schema() { $schema['book'] = array( 'description' => 'Stores book outline information. Uniquely connects each node in the outline to a link in {menu_links}', 'fields' => array( 'mlid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default'...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-5465e51033
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_formatter_view/7.x
Implement `taxonomy_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_view().
File: modules/taxonomy/taxonomy.module
function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); // Terms whose tid is 'autocreate' do not exist // yet and $item['taxonomy_term'] is not set. Theme such terms as // just their name. switch ($display['type']) { case 'taxo...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-5474ec0859
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_load_updates/7.x
I need the code for `drupal_load_updates()` in Drupal 7 (includes/install.inc). It must do this: Loads .install files for installed modules to initialize the update system.
File: includes/install.inc
function drupal_load_updates() { foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema_version) { if ($schema_version > -1) { module_load_install($module); } } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-54b82320e5
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_html_class/7.x
Implement `drupal_html_class($class)` in PHP for Drupal 7. Required behavior: Prepares a string for use as a valid class name.
Do not pass one string containing multiple classes as they will be incorrectly concatenated with dashes, i.e. "one two" will become "one-two". Parameters: - $class: The class name to clean. Returns: The cleaned class name. File: includes/common.inc
function drupal_html_class($class) { // The output of this function will never change, so this uses a normal // static instead of drupal_static(). static $classes = array(); if (!isset($classes[$class])) { $classes[$class] = drupal_clean_css_identifier(drupal_strtolower($class)); } return $classes[$cla...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-54baa2b236
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_set_preferred_header_name/7.x
I need the code for `_drupal_set_preferred_header_name($name = NULL)` in Drupal 7 (includes/bootstrap.inc). It must do this: Sets the preferred name for the HTTP header.
Header names are case-insensitive, but for maximum compatibility they should follow "common form" (see RFC 2617, section 4.2). File: includes/bootstrap.inc
function _drupal_set_preferred_header_name($name = NULL) { static $header_names = array(); if (!isset($name)) { return $header_names; } $header_names[strtolower($name)] = $name; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-54c1b07a0f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_custom_theme/7.x
In Drupal 7, write the function `_block_custom_theme($theme = NULL)` (file modules/block/block.module) so that it does the following: Theme callback for the block configuration pages.
Parameters: - $theme: The theme whose blocks are being configured. If not set, the default theme is assumed. Returns: The theme that should be used for the block configuration page, or NULL to indicate that the default theme should be used. File: modules/block/block.module
function _block_custom_theme($theme = NULL) { // We return exactly what was passed in, to guarantee that the page will // always be displayed using the theme whose blocks are being configured. return $theme; }
[ "code-task", "function" ]
2026-09-30T00:00:00