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-3e8a449809
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_view_mode_alter/7.x
In Drupal 7, show an example implementation for `hook_entity_view_mode_alter(&$view_mode, $context)` (modules/system/system.api.php): Change the view mode of an entity that is being displayed.
Parameters: - $view_mode (string): The view_mode that is to be used to display the entity. - $context (array): Array with contextual information, including: - entity_type: The type of the entity that is being viewed. - entity: The entity object. - langcode: The langcode the entity is being viewed in. File: modules/sys...
function hook_entity_view_mode_alter(&$view_mode, $context) { // For nodes, change the view mode when it is teaser. if ($context['entity_type'] == 'node' && $view_mode == 'teaser') { $view_mode = 'my_custom_view_mode'; } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-3ed6435c43
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_simplify/7.x
I need the code for `search_simplify($text)` in Drupal 7 (modules/search/search.module). It must do this: Simplifies a string according to indexing rules.
Parameters: - $text: Text to simplify. Returns: Simplified text. File: modules/search/search.module
function search_simplify($text) { // Decode entities to UTF-8 $text = decode_entities($text); // Lowercase $text = drupal_strtolower($text); // Call an external processor for word handling. search_invoke_preprocess($text); // Simple CJK handling if (variable_get('overlap_cjk', TRUE)) { $text = pr...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3ed9b3371c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/_drupal_default_html_head/7.x
Implement `_drupal_default_html_head()` in PHP for Drupal 7. Required behavior: Returns elements that are always displayed in the HEAD tag of the HTML page.
File: includes/common.inc
function _drupal_default_html_head() { // Add default elements. Make sure the Content-Type comes first because the // IE browser may be vulnerable to XSS via encoding attacks from any content // that comes before this META tag, such as a TITLE tag. $elements['system_meta_content_type'] = array( '#type' => '...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3edfabf931
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_view_results/7.x
In Drupal 7, write the function `poll_view_results($node, $view_mode, $block = FALSE)` (file modules/poll/poll.module) so that it does the following: Generates a graphical representation of the results of a poll.
File: modules/poll/poll.module
function poll_view_results($node, $view_mode, $block = FALSE) { // Make sure that choices are ordered by their weight. uasort($node->choice, 'drupal_sort_weight'); // Count the votes and find the maximum. $total_votes = 0; $max_votes = 0; foreach ($node->choice as $choice) { if (isset($choice['chvotes'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3f22db44a5
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_radio/7.x
Implement `theme_radio($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a radio button form element.
Note: The input "name" attribute needs to be sanitized before output, which is currently done by passing all attributes to drupal_attributes(). Parameters: - $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #required, #return_...
function theme_radio($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'radio'; element_set_attributes($element, array('id', 'name', '#return_value' => 'value')); if (isset($element['#return_value']) && $element['#value'] !== FALSE && $element['#value'] == $element['#return_valu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3f2943a1b2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_permission_name/7.x
Implement `filter_permission_name($format)` in PHP for Drupal 7. Required behavior: Returns the machine-readable permission name for a provided text format.
Parameters: - $format: An object representing a text format. Returns: The machine-readable permission name, or FALSE if the provided text format is malformed or is the fallback format (which is available to all users). File: modules/filter/filter.module
function filter_permission_name($format) { if (isset($format->format) && $format->format != filter_fallback_format()) { return 'use text format ' . $format->format; } return FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3f321344e8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_ranking/7.x
In Drupal 7, write the function `comment_ranking()` (file modules/comment/comment.module) so that it does the following: Implements hook_ranking().
File: modules/comment/comment.module
function comment_ranking() { return array( 'comments' => array( 'title' => t('Number of comments'), 'join' => array( 'type' => 'LEFT', 'table' => 'node_comment_statistics', 'alias' => 'node_comment_statistics', 'on' => 'node_comment_statistics.nid = i.sid', ), ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-3f357c43e8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_clear_page_cache/7.x
Implement `_menu_clear_page_cache()` in PHP for Drupal 7. Required behavior: Clears the page and block caches at most twice per page load.
File: includes/menu.inc
function _menu_clear_page_cache() { $cache_cleared = &drupal_static(__FUNCTION__, 0); // Clear the page and block caches, but at most twice, including at // the end of the page load when there are multiple links saved or deleted. if ($cache_cleared == 0) { cache_clear_all(); // Keep track of which men...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3f49818adb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.api.php/function/hook_dashboard_regions/7.x
In Drupal 7, show an example implementation for `hook_dashboard_regions()` (modules/dashboard/dashboard.api.php): Add regions to the dashboard.
Returns: An array whose keys are the names of the dashboard regions and whose values are the titles that will be displayed in the blocks administration interface. The keys are also used as theme wrapper functions. File: modules/dashboard/dashboard.api.php
function hook_dashboard_regions() { // Define a new dashboard region. Your module can also then define // theme_mymodule_dashboard_region() as a theme wrapper function to control // the region's appearance. return array('mymodule_dashboard_region' => "My module's dashboard region"); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-3f9e24007a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_write_record/7.x
Implement `drupal_write_record($table, &$record, $primary_keys = array())` in PHP for Drupal 7. Required behavior: Saves (inserts or updates) a record to the database based upon the schema.
Do not use drupal_write_record() within hook_update_N() functions, since the database schema cannot be relied upon when a user is running a series of updates. Instead, use db_insert() or db_update() to save the record. Parameters: - $table: The name of the table; this must be defined by a hook_schema() implementation....
function drupal_write_record($table, &$record, $primary_keys = array()) { // Standardize $primary_keys to an array. if (is_string($primary_keys)) { $primary_keys = array($primary_keys); } $schema = drupal_get_schema($table); if (empty($schema)) { return FALSE; } $object = (object) $record; $fi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3fbd52b36a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_project_status_sort/7.x
I need the code for `_update_project_status_sort($a, $b)` in Drupal 7 (modules/update/update.module). It must do this: Orders projects based on their status.
Callback for uasort() within update_requirements(). File: modules/update/update.module
function _update_project_status_sort($a, $b) { // The status constants are numerically in the right order, so we can // usually subtract the two to compare in the order we want. However, // negative status values should be treated as if they are huge, since we // always want them at the bottom of the list. $a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3fc89eb83e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_delete/7.x
Implement `poll_delete($node)` in PHP for Drupal 7. Required behavior: Implements hook_delete().
File: modules/poll/poll.module
function poll_delete($node) { db_delete('poll') ->condition('nid', $node->nid) ->execute(); db_delete('poll_choice') ->condition('nid', $node->nid) ->execute(); db_delete('poll_vote') ->condition('nid', $node->nid) ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-3fccbd3700
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_delete_revision/7.x
Implement `field_attach_delete_revision($entity_type, $entity)` in PHP for Drupal 7. Required behavior: Delete field data for a single revision of an existing entity. The passed entity must have a revision id attribute.
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_delete_revision($entity_type, $entity) { _field_invoke('delete_revision', $entity_type, $entity); list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); // Collect the storage backends used by the fields in the entities. $storages = array(); foreach (field_info_instances...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-3ffda884af
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_7004/7.x
Implement `image_update_7004()` in PHP for Drupal 7. Required behavior: Use a large setting (512 and 1024 characters) for the length of the image alt and title fields.
File: modules/image/image.install
function image_update_7004() { $alt_spec = array( 'type' => 'varchar', 'length' => 512, 'not null' => FALSE, ); $title_spec = array( 'type' => 'varchar', 'length' => 1024, 'not null' => FALSE, ); $fields = _update_7000_field_read_fields(array( 'module' => 'image', 'storage_ty...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4027fb270f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_view_multiple/7.x
I need the code for `taxonomy_term_view_multiple($terms, $view_mode = 'teaser', $weight = 0, $langcode = NULL)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Constructs a drupal_render() style array from an array of loaded terms.
Parameters: - $terms: An array of taxonomy terms as returned by taxonomy_term_load_multiple(). - $view_mode: View mode, e.g. 'full', 'teaser'... - $weight: An integer representing the weight of the first taxonomy term in the list. - $langcode: (optional) A language code to use for rendering. Defaults to the global cont...
function taxonomy_term_view_multiple($terms, $view_mode = 'teaser', $weight = 0, $langcode = NULL) { $build = array(); $entities_by_view_mode = entity_view_mode_prepare('taxonomy_term', $terms, $view_mode, $langcode); foreach ($entities_by_view_mode as $entity_view_mode => $entities) { field_attach_prepare_vi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-403b1734e2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.tokens.inc/function/node_token_info/7.x
Implement `node_token_info()` in PHP for Drupal 7. Required behavior: Implements hook_token_info().
File: modules/node/node.tokens.inc
function node_token_info() { $type = array( 'name' => t('Nodes'), 'description' => t('Tokens related to individual content items, or "nodes".'), 'needs-data' => 'node', ); // Core tokens for nodes. $node['nid'] = array( 'name' => t("Content ID"), 'description' => t('The unique ID of the con...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-408efa0ddb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_build_content/7.x
In Drupal 7, write the function `node_build_content($node, $view_mode = 'full', $langcode = NULL)` (file modules/node/node.module) so that it does the following: Builds a structured array representing the node's content.
The content built for the node (field values, comments, file attachments or other node components) will vary depending on the $view_mode parameter. Drupal core defines the following view modes for nodes, with the following default use cases: - full (default): node is being displayed on its own page (node/123) - te...
function node_build_content($node, $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { $langcode = $GLOBALS['language_content']->language; } // Remove previously built content, if exists. $node->content = array(); // Allow modules to change the view mode. $view_mode = key(entity_view_mod...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-409e339be7
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21session.inc/function/drupal_session_destroy_uid/7.x
Implement `drupal_session_destroy_uid($uid)` in PHP for Drupal 7. Required behavior: Ends a specific user's session(s).
Parameters: - $uid: User ID. File: includes/session.inc
function drupal_session_destroy_uid($uid) { // Nothing to do if we are not allowed to change the session. if (!drupal_save_session()) { return; } db_delete('sessions') ->condition('uid', $uid) ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-409f440e66
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.parser.inc/function/aggregator_element_start/7.x
In Drupal 7, write the function `aggregator_element_start($parser, $name, $attributes)` (file modules/aggregator/aggregator.parser.inc) so that it does the following: Performs an action when an opening tag is encountered.
Callback function used by xml_parse() within aggregator_parse_feed(). File: modules/aggregator/aggregator.parser.inc
function aggregator_element_start($parser, $name, $attributes) { global $item, $element, $tag, $items, $channel; $name = strtolower($name); switch ($name) { case 'image': case 'textinput': case 'summary': case 'tagline': case 'subtitle': case 'logo': case 'info': $element = $nam...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-40d2b48aff
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_static/7.x
Implement `&drupal_static($name, $default_value = NULL, $reset = FALSE)` in PHP for Drupal 7. Required behavior: Provides central static variable storage.
All functions requiring a static variable to persist or cache data within a single page request are encouraged to use this function unless it is absolutely certain that the static variable will not need to be reset during the page request. By centralizing static variable storage through this function, other functions c...
function &drupal_static($name, $default_value = NULL, $reset = FALSE) { static $data = array(), $default = array(); // First check if dealing with a previously defined static variable. if (isset($data[$name]) || array_key_exists($name, $data)) { // Non-NULL $name and both $data[$name] and $default[$name] stat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-40d689703d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_message_parse/7.x
Implement `xmlrpc_message_parse($xmlrpc_message)` in PHP for Drupal 7. Required behavior: Parses an XML-RPC message.
If parsing fails, the faultCode and faultString will be added to the message object. Parameters: - $xmlrpc_message: An object generated by xmlrpc_message(). Returns: TRUE if parsing succeeded; FALSE otherwise. File: includes/xmlrpc.inc
function xmlrpc_message_parse($xmlrpc_message) { $xmlrpc_message->_parser = xml_parser_create(); // Set XML parser to take the case of tags into account. xml_parser_set_option($xmlrpc_message->_parser, XML_OPTION_CASE_FOLDING, FALSE); // Set XML parser callback functions xml_set_element_handler($xmlrpc_messag...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-40fae1b6cb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_link_insert/7.x
Give me the example code for `hook_menu_link_insert($link)` in Drupal 7. Hook description: Inform modules that a menu link has been created.
This hook is used to notify modules that menu items have been created. 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_insert($link) { // In our sample case, we track menu items as editing sections // of the site. These are stored in our table as 'disabled' items. $record['mlid'] = $link['mlid']; $record['menu_name'] = $link['menu_name']; $record['status'] = 0; drupal_write_record('menu_example', $re...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-4111f2a27f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_submit/7.x
Give me the example code for `hook_node_submit($node, $form, &$form_state)` in Drupal 7. Hook description: Act on a node after validated form values have been copied to it.
This hook is invoked when a node form is submitted with either the "Save" or "Preview" button, after form values have been copied to the form state's node object, but before the node is saved or previewed. It is a chance for modules to adjust the node's properties from what they are simply after a copy from $form_state...
function hook_node_submit($node, $form, &$form_state) { // Decompose the selected menu parent option into 'menu_name' and 'plid', if // the form used the default parent selection widget. if (!empty($form_state['values']['menu']['parent'])) { list($node->menu['menu_name'], $node->menu['plid']) = explode(':', $...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-41274b839f
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/element_sort/7.x
In Drupal 7, write the function `element_sort($a, $b)` (file includes/common.inc) so that it does the following: Function used by uasort to sort structured arrays by weight.
File: includes/common.inc
function element_sort($a, $b) { $a_weight = (is_array($a) && isset($a['#weight'])) ? $a['#weight'] : 0; $b_weight = (is_array($b) && isset($b['#weight'])) ? $b['#weight'] : 0; if ($a_weight == $b_weight) { return 0; } return ($a_weight < $b_weight) ? -1 : 1; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-412775b638
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_url_inbound_alter/7.x
In Drupal 7, show an example implementation for `hook_url_inbound_alter(&$path, $original_path, $path_language)` (modules/system/system.api.php): Alters inbound URL requests.
Parameters: - $path: The path being constructed, which, if a path alias, has been resolved to a Drupal path by the database, and which also may have been altered by other modules before this one. - $original_path: The original path, before being checked for path aliases or altered by any modules. - $path_language: The ...
function hook_url_inbound_alter(&$path, $original_path, $path_language) { // Create the path user/me/edit, which allows a user to edit their account. if (preg_match('|^user/me/edit(/.*)?|', $path, $matches)) { global $user; $path = 'user/' . $user->uid . '/edit' . $matches[1]; } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-41379b2f04
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_names/7.x
I need the code for `menu_get_names()` in Drupal 7 (includes/menu.inc). It must do this: Build a list of named menus.
File: includes/menu.inc
function menu_get_names() { $names = &drupal_static(__FUNCTION__); if (empty($names)) { $names = db_select('menu_links') ->distinct() ->fields('menu_links', array('menu_name')) ->orderBy('menu_name') ->execute()->fetchCol(); } return $names; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-413c95ecc1
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_router_cache/7.x
Implement `_menu_router_cache($new_menu = NULL)` in PHP for Drupal 7. Required behavior: Stores the menu router if we have it in memory.
File: includes/menu.inc
function _menu_router_cache($new_menu = NULL) { $menu = &drupal_static(__FUNCTION__); if (isset($new_menu)) { $menu = $new_menu; } return $menu; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-41532fb1be
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_overview_form_submit/7.x
Implement `locale_languages_overview_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process language overview form submissions, updating existing languages.
File: modules/locale/locale.admin.inc
function locale_languages_overview_form_submit($form, &$form_state) { $languages = language_list(); $default = language_default(); $url_prefixes = variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX; $enabled_count = 0; foreac...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-41a6dd50cc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/template_preprocess_aggregator_item/7.x
I need the code for `template_preprocess_aggregator_item(&$variables)` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Processes variables for aggregator-item.tpl.php.
File: modules/aggregator/aggregator.pages.inc
function template_preprocess_aggregator_item(&$variables) { $item = $variables['item']; $variables['feed_url'] = check_url($item->link); $variables['feed_title'] = check_plain($item->title); $variables['content'] = aggregator_filter_xss($item->description); $variables['source_url'] = ''; $variables['sourc...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-41bad8771b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_mapping_save/7.x
Implement `rdf_mapping_save($mapping)` in PHP for Drupal 7. Required behavior: Saves an RDF mapping to the database.
Takes a mapping structure returned by hook_rdf_mapping() implementations and creates or updates a record mapping for each encountered entity type/bundle pair. If available, adds default values for non-existent mapping keys. Parameters: - $mapping: The RDF mapping to save, as an array. Returns: Status flag indicating ...
function rdf_mapping_save($mapping) { // In the case where a field has a mapping defined in the default entity // mapping, but a mapping is not specified in the bundle-specific mapping, // then use the default mapping for that field. $mapping['mapping'] += _rdf_get_default_mapping($mapping['type']); $status ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-41d13b8a68
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_theme/7.x
Give me the example code for `hook_theme($existing, $type, $theme, $path)` in Drupal 7. Hook description: Register a module (or theme's) theme implementations.
The implementations declared by this hook have two purposes: either they specify how a particular render array is to be rendered as HTML (this is usually the case if the theme function is assigned to the render array's #theme property), or they return the HTML that should be returned by an invocation of theme(). See P...
function hook_theme($existing, $type, $theme, $path) { return array( 'forum_display' => array( 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), ), 'forum_list' => array( 'variables' => array('forums' => NULL...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-41dbfe76a1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/_field_invoke_multiple/7.x
In Drupal 7, write the function `_field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b = NULL, $options = array())` (file modules/field/field.attach.inc) so that it does the following: Invoke a field hook across fields on multiple entities.
Parameters: - $op: Possible operations include: - load - prepare_view For all other operations, use _field_invoke() / field_invoke_default() instead. - $entity_type: The type of $entity; e.g. 'node' or 'user'. - $entities: An array of entities, keyed by entity id. - $a: - The $age parameter in the 'load' operation. - O...
function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b = NULL, $options = array()) { // Merge default options. $default_options = array( 'default' => FALSE, 'deleted' => FALSE, 'language' => NULL, ); $options += $default_options; $fields = array(); $grouped_instances = ar...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-41e2dbb020
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_system_info_alter/7.x
In Drupal 7, write the function `user_system_info_alter(&$info, $file, $type)` (file modules/user/user.module) so that it does the following: Implements hook_system_info_alter().
Drupal 7 ships with two methods to add additional fields to users: Profile module, a legacy module dating back from 2002, and Field API integration with users. While Field API support for users currently provides less end user features, the inefficient data storage mechanism of Profile module, as well as its lack of co...
function user_system_info_alter(&$info, $file, $type) { if ($type == 'module' && $file->name == 'profile' && db_table_exists('profile_field')) { $info['hidden'] = FALSE; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-41f41e81e6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_configure_form/7.x
In Drupal 7, write the function `install_configure_form($form, &$form_state, &$install_state)` (file includes/install.core.inc) so that it does the following: Form constructor for a form to configure the new site.
Parameters: - $install_state: An array of information about the current installation state. File: includes/install.core.inc
function install_configure_form($form, &$form_state, &$install_state) { drupal_set_title(st('Configure site')); // Warn about settings.php permissions risk $settings_dir = conf_path(); $settings_file = $settings_dir . '/settings.php'; // Check that $_POST is empty so we only show this message when the form i...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-41f91e0f70
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.pages.inc/function/book_remove_form_submit/7.x
Implement `book_remove_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for book_remove_form().
File: modules/book/book.pages.inc
function book_remove_form_submit($form, &$form_state) { $node = $form['#node']; if (_book_node_is_removable($node)) { menu_link_delete($node->book['mlid']); db_delete('book') ->condition('nid', $node->nid) ->execute(); drupal_set_message(t('The post has been removed from the book.')); } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4208313a21
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_url_parse_email_links/7.x
In Drupal 7, write the function `_filter_url_parse_email_links($match)` (file modules/filter/filter.module) so that it does the following: Makes links out of e-mail addresses.
Callback for preg_replace_callback() within _filter_url(). File: modules/filter/filter.module
function _filter_url_parse_email_links($match) { // The $i:th parenthesis in the regexp contains the URL. $i = 0; $match[$i] = decode_entities($match[$i]); $caption = check_plain(_filter_url_trim($match[$i])); $match[$i] = check_plain($match[$i]); return '<a href="mailto:' . $match[$i] . '">' . $caption . ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-421342c714
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_process_project_info/7.x
I need the code for `update_process_project_info(&$projects)` in Drupal 7 (modules/update/update.compare.inc). It must do this: Determines version and type information for currently installed projects.
Processes the list of projects on the system to figure out the currently installed versions, and other information that is required before we can compare against the available releases to produce the status report. Parameters: - $projects: Array of project information from update_get_projects(). File: modules/update/...
function update_process_project_info(&$projects) { foreach ($projects as $key => $project) { // Assume an official release until we see otherwise. $install_type = 'official'; $info = $project['info']; if (isset($info['version'])) { // Check for development snapshots if (preg_match('@(dev...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-422d4554b5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7005/7.x
In Drupal 7, write the function `system_update_7005()` (file modules/system/system.install) so that it does the following: Remove throttle columns and variables.
File: modules/system/system.install
function system_update_7005() { db_drop_field('blocks', 'throttle'); db_drop_field('system', 'throttle'); variable_del('throttle_user'); variable_del('throttle_anonymous'); variable_del('throttle_level'); variable_del('throttle_probability_limiter'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-42362897c3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_request_refresh/7.x
I need the code for `overlay_request_refresh($region)` in Drupal 7 (modules/overlay/overlay.module). It must do this: Requests that the parent window refreshes a particular page region.
Parameters: - $region: The name of the page region to refresh. The parent window will trigger a refresh of this region on the next page load. File: modules/overlay/overlay.module
function overlay_request_refresh($region) { $class = drupal_region_class($region); $_SESSION['overlay_regions_to_refresh'][] = array($class => $region); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4243783207
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate_image_resolution/7.x
In Drupal 7, write the function `file_validate_image_resolution(stdClass $file, $maximum_dimensions = 0, $minimum_dimensions = 0)` (file includes/file.inc) so that it does the following: Verifies that image dimensions are within the specified maximum and minimum.
Non-image files will be ignored. If an image toolkit is available the image will be scaled to fit within the desired maximum dimensions. Parameters: - $file: A Drupal file object. This function may resize the file affecting its size. - $maximum_dimensions: An optional string in the form WIDTHxHEIGHT e.g. '640x480' or ...
function file_validate_image_resolution(stdClass $file, $maximum_dimensions = 0, $minimum_dimensions = 0) { $errors = array(); // Check first that the file is an image. if ($info = image_get_info($file->uri)) { if ($maximum_dimensions) { // Check that it is smaller than the given dimensions. list...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-424fd58694
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_set_active_item/7.x
In Drupal 7, write the function `menu_set_active_item($path)` (file includes/menu.inc) so that it does the following: Sets the active path, which determines which page is loaded.
Note that this may not have the desired effect unless invoked very early in the page load, such as during hook_boot(), or unless you call menu_execute_active_handler() to generate your page output. Parameters: - $path: A Drupal path - not a path alias. File: includes/menu.inc
function menu_set_active_item($path) { $_GET['q'] = $path; // Since the active item has changed, the active menu trail may also be out // of date. drupal_static_reset('menu_set_active_trail'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4287840d7c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/_locale_languages_common_controls/7.x
In Drupal 7, write the function `_locale_languages_common_controls(&$form, $language = NULL)` (file modules/locale/locale.admin.inc) so that it does the following: Common elements of the language addition and editing form.
Parameters: - $form: A parent form item (or empty array) to add items below. - $language: Language object to edit. File: modules/locale/locale.admin.inc
function _locale_languages_common_controls(&$form, $language = NULL) { if (!is_object($language)) { $language = new stdClass(); } if (isset($language->language)) { $form['langcode_view'] = array( '#type' => 'item', '#title' => t('Language code'), '#markup' => $language->language ); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-429bfe102a
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21bartik%21template.php/function/bartik_field__taxonomy_term_reference/7.x
In Drupal 7, write the function `bartik_field__taxonomy_term_reference($variables)` (file themes/bartik/template.php) so that it does the following: Implements theme_field__field_type().
File: themes/bartik/template.php
function bartik_field__taxonomy_term_reference($variables) { $output = ''; // Render the label, if it's not hidden. if (!$variables['label_hidden']) { $output .= '<h3 class="field-label">' . $variables['label'] . ': </h3>'; } // Render the items. $output .= ($variables['element']['#label_display'] == ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-42a623f1f2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.install/function/menu_update_7000/7.x
I need the code for `menu_update_7000()` in Drupal 7 (modules/menu/menu.install). It must do this: Migrate the "Default menu for content" setting to individual node types.
File: modules/menu/menu.install
function menu_update_7000() { // Act only on sites originally on Drupal 6 that have a custom "Default menu // for content" setting. $default_node_menu = variable_get('menu_default_node_menu'); if (isset($default_node_menu)) { // Remove variable no longer used in Drupal 7. variable_del('menu_default_node...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-42d9be7ede
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_exception_handler/7.x
Implement `_drupal_exception_handler($exception)` in PHP for Drupal 7. Required behavior: Provides custom PHP exception handling.
Uncaught exceptions are those not enclosed in a try/catch block. They are always fatal: the execution of the script will stop as soon as the exception handler exits. Parameters: - $exception: The exception object that was thrown. File: includes/bootstrap.inc
function _drupal_exception_handler($exception) { require_once DRUPAL_ROOT . '/includes/errors.inc'; try { // Log the message to the watchdog and return an error page to the user. _drupal_log_error(_drupal_decode_exception($exception), TRUE); } catch (Exception $exception2) { // Add a 500 status cod...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-42da2f9fe3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/_book_flatten_menu/7.x
In Drupal 7, write the function `_book_flatten_menu($tree, &$flat)` (file modules/book/book.module) so that it does the following: Recursively converts a tree of menu links to a flat array.
Parameters: - $tree: A tree of menu links in an array. - $flat: A flat array of the menu links from $tree, passed by reference. File: modules/book/book.module
function _book_flatten_menu($tree, &$flat) { foreach ($tree as $data) { if (!$data['link']['hidden']) { $flat[$data['link']['mlid']] = $data['link']; if ($data['below']) { _book_flatten_menu($data['below'], $flat); } } } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4307acdcaa
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_block_list_alter/7.x
I need the code for `block_block_list_alter(&$blocks)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_block_list_alter().
Checks the page, user role, and user-specific visibility settings. Removes the block if the visibility conditions are not met. File: modules/block/block.module
function block_block_list_alter(&$blocks) { global $user, $theme_key; // Build an array of roles for each block. $block_roles = array(); $result = db_query('SELECT module, delta, rid FROM {block_role}'); foreach ($result as $record) { $block_roles[$record->module][$record->delta][] = $record->rid; } ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4322e6fb0c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7003/7.x
In Drupal 7, write the function `node_update_7003()` (file modules/node/node.install) so that it does the following: Remove the node_counter if the statistics module is uninstalled.
File: modules/node/node.install
function node_update_7003() { if (drupal_get_installed_schema_version('statistics') == SCHEMA_UNINSTALLED) { db_drop_table('node_counter'); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4336cac78a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_clear_css_cache/7.x
Implement `drupal_clear_css_cache()` in PHP for Drupal 7. Required behavior: Deletes old cached CSS files.
File: includes/common.inc
function drupal_clear_css_cache() { variable_del('drupal_css_cache_files'); file_scan_directory('public://css', '/.*/', array('callback' => 'drupal_delete_file_if_stale')); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4344d28515
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_get_palette/7.x
Implement `color_get_palette($theme, $default = FALSE)` in PHP for Drupal 7. Required behavior: Retrieves the color palette for a particular theme.
File: modules/color/color.module
function color_get_palette($theme, $default = FALSE) { // Fetch and expand default palette. $info = color_get_info($theme); $palette = $info['schemes']['default']['colors']; // Load variable. return $default ? $palette : variable_get('color_' . $theme . '_palette', $palette); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-434c1635dc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_openid_discovery_method_info/7.x
Implement `openid_openid_discovery_method_info()` in PHP for Drupal 7. Required behavior: Implements hook_openid_discovery_method_info().
Define standard discovery methods. File: modules/openid/openid.module
function openid_openid_discovery_method_info() { // The discovery process will stop as soon as one discovery method succeed. // We first attempt to discover XRI-based identifiers, then standard XRDS // identifiers via Yadis and HTML-based discovery, conforming to the OpenID 2.0 // specification. return array(...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-436667d552
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_pre_render_conditional_form_element/7.x
In Drupal 7, write the function `form_pre_render_conditional_form_element($element)` (file includes/form.inc) so that it does the following: Adds form element theming to an element if its title or description is set.
This is used as a pre render function for checkboxes and radios. File: includes/form.inc
function form_pre_render_conditional_form_element($element) { $t = get_t(); // Set the element's title attribute to show #title as a tooltip, if needed. if (isset($element['#title']) && $element['#title_display'] == 'attribute') { $element['#attributes']['title'] = $element['#title']; if (!empty($element[...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-437c1e69bc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_summary/7.x
In Drupal 7, write the function `text_summary($text, $format = NULL, $size = NULL)` (file modules/field/modules/text/text.module) so that it does the following: Generate a trimmed, formatted version of a text field value.
If the end of the summary is not indicated using the <!--break--> delimiter then we generate the summary automatically, trying to end it at a sensible place such as the end of a paragraph, a line break, or the end of a sentence (in that order of preference). Parameters: - $text: The content for which a summary will be...
function text_summary($text, $format = NULL, $size = NULL) { // If the input text is NULL, return unchanged. if (is_null($text)) { return NULL; } if (!isset($size)) { // What used to be called 'teaser' is now called 'summary', but // the variable 'teaser_length' is preserved for backwards compatib...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-438462ad25
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/ip_address/7.x
In Drupal 7, write the function `ip_address()` (file includes/bootstrap.inc) so that it does the following: Returns the IP address of the client machine.
If Drupal is behind a reverse proxy, we use the X-Forwarded-For header instead of $_SERVER['REMOTE_ADDR'], which would be the IP address of the proxy server, and not the client's. The actual header name can be configured by the reverse_proxy_header variable. Returns: IP address of client machine, adjusted for reverse ...
function ip_address() { $ip_address = &drupal_static(__FUNCTION__); if (!isset($ip_address)) { $ip_address = $_SERVER['REMOTE_ADDR']; if (variable_get('reverse_proxy', 0)) { $reverse_proxy_header = variable_get('reverse_proxy_header', 'HTTP_X_FORWARDED_FOR'); if (!empty($_SERVER[$reverse_proxy...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-438ef633a0
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.inc/function/st/7.x
Implement `st($string, array $args = array(), array $options = array())` in PHP for Drupal 7. Required behavior: Translates a string when some systems are not available.
Used during the install process, when database, theme, and localization system is possibly not yet available. Use t() if your code will never run during the Drupal installation phase. Use st() if your code will only run during installation and never any other time. Use get_t() if your code could run in either circumst...
function st($string, array $args = array(), array $options = array()) { static $locale_strings = NULL; global $install_state; if (empty($options['context'])) { $options['context'] = ''; } if (!isset($locale_strings)) { $locale_strings = array(); if (isset($install_state['parameters']['profile'])...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-43d7319f28
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/_node_index_node/7.x
In Drupal 7, write the function `_node_index_node($node)` (file modules/node/node.module) so that it does the following: Indexes a single node.
Parameters: - $node: The node to index. File: modules/node/node.module
function _node_index_node($node) { $node = node_load($node->nid); // Save the changed time of the most recent indexed node, for the search // results half-life calculation. variable_set('node_cron_last', $node->changed); // Render the node. $build = node_view($node, 'search_index'); unset($build['#theme...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-43db7495ab
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_block_info/7.x
I need the code for `poll_block_info()` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_block_info().
File: modules/poll/poll.module
function poll_block_info() { $blocks['recent']['info'] = t('Most recent poll'); $blocks['recent']['properties']['administrative'] = TRUE; return $blocks; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-43e2a201ba
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21cache.inc/function/_cache_get_object/7.x
In Drupal 7, write the function `_cache_get_object($bin)` (file includes/cache.inc) so that it does the following: Gets the cache object for a cache bin.
By default, this returns an instance of the DrupalDatabaseCache class. Classes implementing DrupalCacheInterface can register themselves both as a default implementation and for specific bins. Parameters: - $bin: The cache bin for which the cache object should be returned. Returns: DrupalCacheInterface The cache obje...
function _cache_get_object($bin) { // We do not use drupal_static() here because we do not want to change the // storage of a cache bin mid-request. static $cache_objects; if (!isset($cache_objects[$bin])) { $class = variable_get('cache_class_' . $bin); if (!isset($class)) { $class = variable_get(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-43fe7ebeca
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_admin_compact_mode/7.x
Implement `system_admin_compact_mode()` in PHP for Drupal 7. Required behavior: Determines whether the current user is in compact mode.
Compact mode shows certain administration pages with less description text, such as the configuration page and the permissions page. Whether the user is in compact mode is determined by a cookie, which is set for the user by system_admin_compact_page(). If the user does not have the cookie, the default value is given...
function system_admin_compact_mode() { // PHP converts dots into underscores in cookie names to avoid problems with // its parser, so we use a converted cookie name. return isset($_COOKIE['Drupal_visitor_admin_compact_mode']) ? $_COOKIE['Drupal_visitor_admin_compact_mode'] : variable_get('admin_compact_mode', FAL...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44164e994d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_aggregate_css/7.x
Implement `drupal_aggregate_css(&$css_groups)` in PHP for Drupal 7. Required behavior: Default callback to aggregate CSS files and inline content.
Having the browser load fewer CSS files results in much faster page loads than when it loads many small files. This function aggregates files within the same group into a single file unless the site-wide setting to do so is disabled (commonly the case during site development). To optimize download, it also compresses t...
function drupal_aggregate_css(&$css_groups) { $preprocess_css = (variable_get('preprocess_css', FALSE) && !defined('MAINTENANCE_MODE')); // For each group that needs aggregation, aggregate its items. foreach ($css_groups as $key => $group) { switch ($group['type']) { // If a file group can be aggregate...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4417437df6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_set_error/7.x
Implement `form_set_error($name = NULL, $message = '', $limit_validation_errors = NULL)` in PHP for Drupal 7. Required behavior: Files an error against a form element.
When a validation error is detected, the validator calls form_set_error() to indicate which element needs to be changed and provide an error message. This causes the Form API to not execute the form submit handlers, and instead to re-display the form to the user with the corresponding elements rendered with an 'error' ...
function form_set_error($name = NULL, $message = '', $limit_validation_errors = NULL) { $form = &drupal_static(__FUNCTION__, array()); $sections = &drupal_static(__FUNCTION__ . ':limit_validation_errors'); if (isset($limit_validation_errors)) { $sections = $limit_validation_errors; } if (isset($name) && ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-441b385669
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_widget_types/7.x
In Drupal 7, write the function `field_info_widget_types($widget_type = NULL)` (file modules/field/field.info.inc) so that it does the following: Returns information about field widgets from hook_field_widget_info().
Parameters: - $widget_type: (optional) A widget type name. If omitted, all widget types will be returned. Returns: Either a single widget type description, as provided by hook_field_widget_info(), or an array of all existing widget types, keyed by widget type name. File: modules/field/field.info.inc
function field_info_widget_types($widget_type = NULL) { $info = _field_info_collate_types(); $widget_types = $info['widget types']; if ($widget_type) { if (isset($widget_types[$widget_type])) { return $widget_types[$widget_type]; } } else { return $widget_types; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44243ec4be
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_batch_by_component/7.x
Implement `locale_batch_by_component($components, $finished = '_locale_batch_system_finished')` in PHP for Drupal 7. Required behavior: Prepare a batch to run when installing modules or enabling themes.
This batch will import translations for the newly added components in all the languages already set up on the site. Parameters: - $components: An array of component (theme and/or module) names to import translations for. - $finished: Optional finished callback for the batch. File: includes/locale.inc
function locale_batch_by_component($components, $finished = '_locale_batch_system_finished') { $files = array(); $languages = language_list('enabled'); unset($languages[1]['en']); if (count($languages[1])) { $language_list = join('|', array_keys($languages[1])); // Collect all files to import for all $c...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4432a1bba9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21form.api.php/function/callback_batch_finished/7.x
Give me the example code for `callback_batch_finished($success, $results, $operations)` in Drupal 7. Hook description: Complete a batch process.
Callback for batch_set(). This callback may be specified in a batch to perform clean-up operations, or to analyze the results of the batch operations. Parameters: - $success: A boolean indicating whether the batch has completed successfully. - $results: The value set in $context['results'] by callback_batch_operation...
function callback_batch_finished($success, $results, $operations) { if ($success) { // Here we do something meaningful with the results. $message = t("!count items were processed.", array( '!count' => count($results), )); $message .= theme('item_list', array('items' => $results)); drupal_s...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-443752092f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_multiple_role_edit/7.x
In Drupal 7, write the function `user_multiple_role_edit($accounts, $operation, $rid)` (file modules/user/user.module) so that it does the following: Callback function for admin mass adding/deleting a user role.
File: modules/user/user.module
function user_multiple_role_edit($accounts, $operation, $rid) { // The role name is not necessary as user_save() will reload the user // object, but some modules' hook_user() may look at this first. $role_name = db_query('SELECT name FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchField(); switch (...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44423df338
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/confirm_form/7.x
Implement `confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm')` in PHP for Drupal 7. Required behavior: Generates a form array for a confirmation form.
This function returns a complete form array for confirming an action. The form contains a confirm button as well as a cancellation link that allows a user to abort the action. If the submit handler for a form that implements confirm_form() is invoked, the user successfully confirmed the action. You should never direct...
function confirm_form($form, $question, $path, $description = NULL, $yes = NULL, $no = NULL, $name = 'confirm') { $description = isset($description) ? $description : t('This action cannot be undone.'); // Prepare cancel link. if (isset($_GET['destination'])) { $options = drupal_parse_url($_GET['destination']...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-444c409eb3
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_valid_path/7.x
I need the code for `drupal_valid_path($path, $dynamic_allowed = FALSE)` in Drupal 7 (includes/path.inc). It must do this: Checks a path exists and the current user has access to it.
Parameters: - $path: The path to check. - $dynamic_allowed: Whether paths with menu wildcards (like user/%) should be allowed. Returns: TRUE if it is a valid path AND the current user has access permission, FALSE otherwise. File: includes/path.inc
function drupal_valid_path($path, $dynamic_allowed = FALSE) { global $menu_admin; // We indicate that a menu administrator is running the menu access check. $menu_admin = TRUE; if ($path == '<front>' || url_is_external($path)) { $item = array('access' => TRUE); } elseif ($dynamic_allowed && preg_match('...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4454ad080f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21content_types.inc/function/node_type_delete_confirm_submit/7.x
Implement `node_type_delete_confirm_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process content type delete confirm submissions.
File: modules/node/content_types.inc
function node_type_delete_confirm_submit($form, &$form_state) { node_type_delete($form_state['values']['type']); variable_del('node_preview_' . $form_state['values']['type']); $t_args = array('%name' => $form_state['values']['name']); drupal_set_message(t('The content type %name has been deleted.', $t_args)); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-445fe27e1d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_link_href/7.x
Implement `_openid_link_href($rel, $html)` in PHP for Drupal 7. Required behavior: Pull the href attribute out of an html link element.
File: modules/openid/openid.inc
function _openid_link_href($rel, $html) { $rel = preg_quote($rel); preg_match('|<link\s+rel=["\'](.*)' . $rel . '(.*)["\'](.*)/?>|iUs', $html, $matches); if (isset($matches[3])) { preg_match('|href=["\']([^"]+)["\']|iU', $matches[3], $href); return trim($href[1]); } return FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44634ffbb3
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_environment_initialize/7.x
Implement `drupal_environment_initialize()` in PHP for Drupal 7. Required behavior: Initializes the PHP environment.
File: includes/bootstrap.inc
function drupal_environment_initialize() { if (!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = ''; } if (!isset($_SERVER['SERVER_PROTOCOL']) || ($_SERVER['SERVER_PROTOCOL'] != 'HTTP/1.0' && $_SERVER['SERVER_PROTOCOL'] != 'HTTP/1.1')) { $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0'; } if (is...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4478faa2e7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/theme_image_resize_summary/7.x
In Drupal 7, write the function `theme_image_resize_summary($variables)` (file modules/image/image.admin.inc) so that it does the following: Returns HTML for a summary of an image resize effect.
Parameters: - $variables: An associative array containing: - data: The current configuration for this resize effect. File: modules/image/image.admin.inc
function theme_image_resize_summary($variables) { $data = $variables['data']; if ($data['width'] && $data['height']) { return check_plain($data['width']) . 'x' . check_plain($data['height']); } else { return ($data['width']) ? t('width @width', array('@width' => $data['width'])) : t('height @height', a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4487223e97
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/template_preprocess_user_profile_category/7.x
Implement `template_preprocess_user_profile_category(&$variables)` in PHP for Drupal 7. Required behavior: Process variables for user-profile-category.tpl.php.
The $variables array contains the following arguments: - $element File: modules/user/user.pages.inc
function template_preprocess_user_profile_category(&$variables) { $variables['title'] = check_plain($variables['element']['#title']); $variables['profile_items'] = $variables['element']['#children']; $variables['attributes'] = ''; if (isset($variables['element']['#attributes'])) { $variables['attributes'] =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-448c12923c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_unpack/7.x
Implement `_color_unpack($hex, $normalize = FALSE)` in PHP for Drupal 7. Required behavior: Converts a hex color into an RGB triplet.
File: modules/color/color.module
function _color_unpack($hex, $normalize = FALSE) { $hex = substr($hex, 1); if (strlen($hex) == 3) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } $c = hexdec($hex); for ($i = 16; $i >= 0; $i -= 8) { $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1); } return $out; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-448dedef6e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_get_switch_links/7.x
Implement `language_negotiation_get_switch_links($type, $path)` in PHP for Drupal 7. Required behavior: Returns the language switch links for the given language.
Parameters: - $type: The language negotiation type. - $path: The internal path the switch links will be relative to. Returns: A keyed array of links ready to be themed. File: includes/language.inc
function language_negotiation_get_switch_links($type, $path) { $links = FALSE; $negotiation = variable_get("language_negotiation_$type", array()); // Only get the languages if we have more than one. if (count(language_list()) >= 2) { $language = language_initialize($type); } foreach ($negotiation as $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44ba1276e6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_log_read/7.x
Implement `simpletest_log_read($test_id, $prefix, $test_class, $during_test = FALSE)` in PHP for Drupal 7. Required behavior: Read the error log and report any errors as assertion failures.
The errors in the log should only be fatal errors since any other errors will have been recorded by the error handler. Parameters: - $test_id: The test ID to which the log relates. - $prefix: The database prefix to which the log relates. - $test_class: The test class to which the log relates. - $during_test: Indicates...
function simpletest_log_read($test_id, $prefix, $test_class, $during_test = FALSE) { $log = 'public://' . ($during_test ? '' : '/simpletest/' . substr($prefix, 10)) . '/error.log'; $found = FALSE; if (file_exists($log)) { foreach (file($log) as $line) { if (preg_match('/\[.*?\] (.*?): (.*?) in (.*) on l...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44c373b491
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.install/function/book_uninstall/7.x
In Drupal 7, write the function `book_uninstall()` (file modules/book/book.install) so that it does the following: Implements hook_uninstall().
File: modules/book/book.install
function book_uninstall() { variable_del('book_allowed_types'); variable_del('book_child_type'); variable_del('book_block_mode'); // Delete menu links. db_delete('menu_links') ->condition('module', 'book') ->execute(); menu_cache_clear_all(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-44c81c3361
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7004/7.x
I need the code for `node_update_7004()` in Drupal 7 (modules/node/node.install). It must do this: Extend the existing default preview and teaser settings to all node types.
File: modules/node/node.install
function node_update_7004() { // Get original settings and all types. $original_length = variable_get('teaser_length', 600); $original_preview = variable_get('node_preview', 0); // Map old preview setting to new values order. $original_preview ? $original_preview = 2 : $original_preview = 1; node_type_cach...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44ce7d8f58
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_ignore_slave/7.x
Implement `db_ignore_slave()` in PHP for Drupal 7. Required behavior: Sets a session variable specifying the lag time for ignoring a slave server.
File: includes/database/database.inc
function db_ignore_slave() { $connection_info = Database::getConnectionInfo(); // Only set ignore_slave_server if there are slave servers being used, which // is assumed if there are more than one. if (count($connection_info) > 1) { // Five minutes is long enough to allow the slave to break and resume /...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44d8a2fa57
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/_book_parent_select/7.x
In Drupal 7, write the function `_book_parent_select($book_link)` (file modules/book/book.module) so that it does the following: Builds the parent selection form element for the node form or outline tab.
This function is also called when generating a new set of options during the Ajax callback, so an array is returned that can be used to replace an existing form element. Parameters: - $book_link: A fully loaded menu link that is part of the book hierarchy. Returns: A parent selection form element. File: modules/book...
function _book_parent_select($book_link) { if (variable_get('menu_override_parent_selector', FALSE)) { return array(); } // Offer a message or a drop-down to choose a different parent page. $form = array( '#type' => 'hidden', '#value' => -1, '#prefix' => '<div id="edit-book-plid-wrapper">', ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44eeeee251
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.processor.inc/function/aggregator_aggregator_process/7.x
I need the code for `aggregator_aggregator_process($feed)` in Drupal 7 (modules/aggregator/aggregator.processor.inc). It must do this: Implements hook_aggregator_process().
File: modules/aggregator/aggregator.processor.inc
function aggregator_aggregator_process($feed) { if (is_object($feed)) { if (is_array($feed->items)) { foreach ($feed->items as $item) { // Save this item. Try to avoid duplicate entries as much as possible. If // we find a duplicate entry, we resolve it and pass along its ID is such ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-44f2bebef1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_predefined_form/7.x
I need the code for `locale_languages_predefined_form($form)` in Drupal 7 (modules/locale/locale.admin.inc). It must do this: Predefined language setup form.
File: modules/locale/locale.admin.inc
function locale_languages_predefined_form($form) { $predefined = _locale_prepare_predefined_list(); $form['language list'] = array('#type' => 'fieldset', '#title' => t('Predefined language'), '#collapsible' => TRUE, ); $form['language list']['langcode'] = array('#type' => 'select', '#title' => t('La...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44f74c5ef0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_save_stylesheet/7.x
Implement `_color_save_stylesheet($file, $style, &$paths)` in PHP for Drupal 7. Required behavior: Saves the rewritten stylesheet to disk.
File: modules/color/color.module
function _color_save_stylesheet($file, $style, &$paths) { $filepath = file_unmanaged_save_data($style, $file, FILE_EXISTS_REPLACE); $paths['files'][] = $filepath; // Set standard file permissions for webserver-generated files. drupal_chmod($file); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44f91993c7
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_all_data/7.x
Implement `menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL)` in PHP for Drupal 7. Required behavior: Gets the data structure representing a named menu tree.
Since this can be the full tree including hidden items, the data returned may be used for generating an an admin interface or a select. Parameters: - $menu_name: The named menu links to return - $link: A fully loaded menu link, or NULL. If a link is supplied, only the path to root will be included in the returned tree...
function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) { $tree = &drupal_static(__FUNCTION__, array()); // Use $mlid as a flag for whether the data being loaded is for the whole tree. $mlid = isset($link['mlid']) ? $link['mlid'] : 0; // Generate a cache ID (cid) specific for this $menu_name, ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-44ff8d54e5
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_css/7.x
In Drupal 7, write the function `drupal_add_css($data = NULL, $options = NULL)` (file includes/common.inc) so that it does the following: Adds a cascading stylesheet to the stylesheet queue.
Calling drupal_static_reset('drupal_add_css') will clear all cascading stylesheets added so far. If CSS aggregation/compression is enabled, all cascading style sheets added with $options['preprocess'] set to TRUE will be merged into one aggregate file and compressed by removing all extraneous white space. Preprocessed...
function drupal_add_css($data = NULL, $options = NULL) { $css = &drupal_static(__FUNCTION__, array()); $count = &drupal_static(__FUNCTION__ . '_count', 0); // If the $css variable has been reset with drupal_static_reset(), there is // no longer any CSS being tracked, so set the counter back to 0 also. if (co...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4500fda5f3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_install/7.x
In Drupal 7, write the function `image_install()` (file modules/image/image.install) so that it does the following: Implements hook_install().
File: modules/image/image.install
function image_install() { // Create the styles directory and ensure it's writable. $directory = file_default_scheme() . '://styles'; file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-451a1b2003
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_destination/7.x
I need the code for `file_destination($destination, $replace)` in Drupal 7 (includes/file.inc). It must do this: Determines the destination path for a file.
Parameters: - $destination: A string specifying the desired final URI or filepath. - $replace: Replace behavior when the destination file already exists. - FILE_EXISTS_REPLACE - Replace the existing file. - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique. - FILE_EXISTS_ERROR - Do nothing...
function file_destination($destination, $replace) { $basename = drupal_basename($destination); if (!drupal_validate_utf8($basename)) { throw new RuntimeException(sprintf("Invalid filename '%s'", $basename)); } if (file_exists($destination)) { switch ($replace) { case FILE_EXISTS_REPLACE: /...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-452426d360
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.install/function/contact_update_7001/7.x
In Drupal 7, write the function `contact_update_7001()` (file modules/contact/contact.install) so that it does the following: Rename the administer contact forms permission.
File: modules/contact/contact.install
function contact_update_7001() { db_update('role_permission') ->fields(array('permission' => 'administer contact forms')) ->condition('permission', 'administer site-wide contact form') ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4551a2882f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_style_save/7.x
Give me the example code for `hook_image_style_save($style)` in Drupal 7. Hook description: Respond to image style updating.
This hook enables modules to update settings that might be affected by changes to an image. For example, updating a module specific variable to reflect a change in the image style's name. Parameters: - $style: The image style array that is being updated. File: modules/image/image.api.php
function hook_image_style_save($style) { // If a module defines an image style and that style is renamed by the user // the module should update any references to that style. if (isset($style['old_name']) && $style['old_name'] == variable_get('mymodule_image_style', '')) { variable_set('mymodule_image_style',...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-45944c6a5c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_form/7.x
I need the code for `field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array())` in Drupal 7 (modules/field/field.attach.inc). It must do this: Add form elements for all fields for an entity to a form structure.
The form elements for the entity's fields are added by reference as direct children in the $form parameter. This parameter can be a full form structure (most common case for entity edit forms), or a sub-element of a larger form. By default, submitted field values appear at the top-level of $form_state['values']. A dif...
function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array()) { // Validate $options since this is a new parameter added after Drupal 7 was // released. $options = is_array($options) ? $options : array(); // Set #parents to 'top-level' by default. $form += arra...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-459875c462
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_message_tag_close/7.x
In Drupal 7, write the function `xmlrpc_message_tag_close($parser, $tag)` (file includes/xmlrpc.inc) so that it does the following: Handles closing tags for XML parsing in xmlrpc_message_parse().
File: includes/xmlrpc.inc
function xmlrpc_message_tag_close($parser, $tag) { $xmlrpc_message = xmlrpc_message_get(); $value_flag = FALSE; switch ($tag) { case 'int': case 'i4': $value = (int)trim($xmlrpc_message->current_tag_contents); $value_flag = TRUE; break; case 'double': $value = (double)trim($xm...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-459fa3b04f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_schema/7.x
Implement `image_schema()` in PHP for Drupal 7. Required behavior: Implements hook_schema().
File: modules/image/image.install
function image_schema() { $schema = array(); $schema['cache_image'] = drupal_get_schema_unprocessed('system', 'cache'); $schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.'; $schema['image_styles'] = array( 'description' => 'Stores...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-45b614d6d9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_permission/7.x
In Drupal 7, write the function `block_permission()` (file modules/block/block.module) so that it does the following: Implements hook_permission().
File: modules/block/block.module
function block_permission() { return array( 'administer blocks' => array( 'title' => t('Administer blocks'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-45b7a018d0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/int2vancode/7.x
I need the code for `int2vancode($i = 0)` in Drupal 7 (modules/comment/comment.module). It must do this: Generate vancode.
Consists of a leading character indicating length, followed by N digits with a numerical value in base 36. Vancodes can be sorted as strings without messing up numerical order. It goes: 00, 01, 02, ..., 0y, 0z, 110, 111, ... , 1zy, 1zz, 2100, 2101, ..., 2zzy, 2zzz, 31000, 31001, ... File: modules/comment/comment.modu...
function int2vancode($i = 0) { $num = base_convert((int) $i, 10, 36); $length = strlen($num); return chr($length + ord('0') - 1) . $num; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-45c24af707
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_settings_form/7.x
I need the code for `field_ui_field_settings_form($form, &$form_state, $instance)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Form constructor for the field settings edit page.
File: modules/field_ui/field_ui.admin.inc
function field_ui_field_settings_form($form, &$form_state, $instance) { $bundle = $instance['bundle']; $entity_type = $instance['entity_type']; $field = field_info_field($instance['field_name']); drupal_set_title($instance['label']); $description = '<p>' . t('These settings apply to the %field field everywh...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-45c48b9772
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/_options_get_options/7.x
In Drupal 7, write the function `_options_get_options($field, $instance, $properties, $entity_type, $entity)` (file modules/field/modules/options/options.module) so that it does the following: Collects the options for a field.
File: modules/field/modules/options/options.module
function _options_get_options($field, $instance, $properties, $entity_type, $entity) { // Get the list of options. $options = (array) module_invoke($field['module'], 'options_list', $field, $instance, $entity_type, $entity); // Sanitize the options. _options_prepare_options($options, $properties); if (!$pro...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-45f134eaca
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_comment_delete/7.x
I need the code for `search_comment_delete($comment)` in Drupal 7 (modules/search/search.module). It must do this: Implements hook_comment_delete().
File: modules/search/search.module
function search_comment_delete($comment) { // Reindex the node when comments are deleted. search_touch_node($comment->nid); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-45f13f1fbf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_help/7.x
I need the code for `trigger_help($path, $arg)` in Drupal 7 (modules/trigger/trigger.module). It must do this: Implements hook_help().
File: modules/trigger/trigger.module
function trigger_help($path, $arg) { // Generate help text for admin/structure/trigger/(module) tabs. $matches = array(); if (preg_match('|^admin/structure/trigger/(.*)$|', $path, $matches)) { $explanation = '<p>' . t('Triggers are events on your site, such as new content being added or a user logging in. The...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-4626b11bdc
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21module.inc/function/module_load_install/7.x
In Drupal 7, write the function `module_load_install($module)` (file includes/module.inc) so that it does the following: Loads a module's installation hooks.
Parameters: - $module: The name of the module (without the .module extension). Returns: The name of the module's install file, if successful; FALSE otherwise. File: includes/module.inc
function module_load_install($module) { // Make sure the installation API is available include_once DRUPAL_ROOT . '/includes/install.inc'; return module_load_include('install', $module); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-462e42b58e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_prepare_instance_display/7.x
In Drupal 7, write the function `_field_info_prepare_instance_display($field, $display)` (file modules/field/field.info.inc) so that it does the following: Adapts display specifications to the current run-time context.
The functionality has moved to the FieldInfo class. This function is kept as a backwards-compatibility layer. See http://drupal.org/node/1915646. File: modules/field/field.info.inc
function _field_info_prepare_instance_display($field, $display) { $cache = _field_info_field_cache(); return $cache->prepareInstanceDisplay($display, $field['type']); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-4641cde0e8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_configure_rebuild_confirm_submit/7.x
I need the code for `node_configure_rebuild_confirm_submit($form, &$form_state)` in Drupal 7 (modules/node/node.admin.inc). It must do this: Handler for wipe confirmation
File: modules/node/node.admin.inc
function node_configure_rebuild_confirm_submit($form, &$form_state) { node_access_rebuild(TRUE); $form_state['redirect'] = 'admin/reports/status'; }
[ "code-task", "function" ]
2026-09-30T00:00:00