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-167a254441
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_preview/7.x
Implement `node_preview($node)` in PHP for Drupal 7. Required behavior: Generates a node preview.
Parameters: - $node: The node to preview. Returns: An HTML-formatted string of a node preview. File: modules/node/node.pages.inc
function node_preview($node) { // Clone the node before previewing it to prevent the node itself from being // modified. $cloned_node = clone $node; if (node_access('create', $cloned_node) || node_access('update', $cloned_node)) { _field_invoke_multiple('load', 'node', array($cloned_node->nid => $cloned_nod...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-168d1a6dc6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_parse_plural_forms/7.x
Implement `_locale_import_parse_plural_forms($pluralforms, $filepath)` in PHP for Drupal 7. Required behavior: Parses a Plural-Forms entry from a Gettext Portable Object file header
Parameters: - $pluralforms: A string containing the Plural-Forms entry. - $filepath: A string containing the filepath. Returns: An array containing the number of plurals and a formula in PHP for computing the plural form. File: includes/locale.inc
function _locale_import_parse_plural_forms($pluralforms, $filepath) { // First, delete all whitespace $pluralforms = strtr($pluralforms, array(" " => "", "\t" => "")); // Select the parts that define nplurals and plural $nplurals = strstr($pluralforms, "nplurals="); if (strpos($nplurals, ";")) { $nplural...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-168e039da4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_vocabulary_static_reset/7.x
Implement `taxonomy_vocabulary_static_reset($ids = NULL)` in PHP for Drupal 7. Required behavior: Clear all static cache variables for vocabularies.
Parameters: - $ids: An array of ids to reset in entity controller cache. File: modules/taxonomy/taxonomy.module
function taxonomy_vocabulary_static_reset($ids = NULL) { drupal_static_reset('taxonomy_vocabulary_get_names'); entity_get_controller('taxonomy_vocabulary')->resetCache($ids); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-16c0224b8b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_reset_link_weights/7.x
Implement `shortcut_set_reset_link_weights(&$shortcut_set)` in PHP for Drupal 7. Required behavior: Resets the link weights in a shortcut set to match their current order.
This function can be used, for example, when a new shortcut link is added to the set. If the link is added to the end of the array and this function is called, it will force that link to display at the end of the list. Parameters: - $shortcut_set (object): An object representing a shortcut set. The link weights of the...
function shortcut_set_reset_link_weights(&$shortcut_set) { $weight = -50; foreach ($shortcut_set->links as &$link) { $link['weight'] = $weight; $weight++; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-17109eedc9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/theme_rdf_template_variable_wrapper/7.x
In Drupal 7, write the function `theme_rdf_template_variable_wrapper($variables)` (file modules/rdf/rdf.module) so that it does the following: Returns HTML for a template variable wrapped in an HTML element with the RDF attributes.
This is called by rdf_process() shortly before the theme system renders a template file. It is called once for each template variable for which additional attributes are needed. While template files are responsible for rendering the attributes for the template's primary object (via the $attributes variable), title (via...
function theme_rdf_template_variable_wrapper($variables) { $output = $variables['content']; if (!empty($output) && !empty($variables['attributes'])) { $attributes = drupal_attributes($variables['attributes']); $output = $variables['inline'] ? "<span$attributes>$output</span>" : "<div$attributes>$output</div...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1724d6c5db
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_switch_access/7.x
I need the code for `shortcut_set_switch_access($account = NULL)` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Access callback for switching the shortcut set assigned to a user account.
Parameters: - $account (object): (optional) The user account whose shortcuts will be switched. If not set, permissions will be checked for switching the logged-in user's own shortcut set. Returns: TRUE if the current user has access to switch the shortcut set of the provided account, FALSE otherwise. File: modules/sh...
function shortcut_set_switch_access($account = NULL) { global $user; if (user_access('administer shortcuts')) { // Administrators can switch anyone's shortcut set. return TRUE; } if (!user_access('switch shortcut sets')) { // The user has no permission to switch anyone's shortcut set. return F...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1727ff2deb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_valid_test_ua/7.x
I need the code for `drupal_valid_test_ua()` in Drupal 7 (includes/bootstrap.inc). It must do this: Returns the test prefix if this is an internal request from SimpleTest.
Returns: Either the simpletest prefix (the string "simpletest" followed by any number of digits) or FALSE if the user agent does not contain a valid HMAC and timestamp. File: includes/bootstrap.inc
function drupal_valid_test_ua() { // No reason to reset this. static $test_prefix; if (isset($test_prefix)) { return $test_prefix; } if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)$/", $_SERVER['HTTP_USER_AGENT'], $matches)) { list(, $prefix, $time, $salt, $hma...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-17306ceacb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_load/7.x
I need the code for `profile_user_load($users)` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_user_load().
File: modules/profile/profile.module
function profile_user_load($users) { $result = db_query('SELECT f.name, f.type, v.uid, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid IN (:uids)', array(':uids' => array_keys($users))); foreach ($result as $record) { if (empty($users[$record->uid]->{$record->name})) { ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-173631a85d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_scheme_form_validate/7.x
I need the code for `color_scheme_form_validate($form, &$form_state)` in Drupal 7 (modules/color/color.module). It must do this: Form validation handler for color_scheme_form().
File: modules/color/color.module
function color_scheme_form_validate($form, &$form_state) { // Only accept hexadecimal CSS color strings to avoid XSS upon use. foreach ($form_state['values']['palette'] as $key => $color) { if (!color_valid_hexadecimal_string($color)) { form_set_error('palette][' . $key, t('%name must be a valid hexadecim...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-17371c381f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_purge_field/7.x
I need the code for `field_purge_field($field)` in Drupal 7 (modules/field/field.crud.inc). It must do this: Purges a field record from the database.
This function assumes all instances for the field has already been purged, and should only be called by field_purge_batch(). Parameters: - $field: The field record to purge. File: modules/field/field.crud.inc
function field_purge_field($field) { $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => 1)); if (count($instances) > 0) { throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field['field_name']))); } ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1754592880
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_hook_info_alter/7.x
In Drupal 7, show an example implementation for `hook_hook_info_alter(&$hooks)` (modules/system/system.api.php): Alter information from hook_hook_info().
Parameters: - $hooks: Information gathered by module_hook_info() from other modules' implementations of hook_hook_info(). Alter this array directly. See hook_hook_info() for information on what this may contain. File: modules/system/system.api.php
function hook_hook_info_alter(&$hooks) { // Our module wants to completely override the core tokens, so make // sure the core token hooks are not found. $hooks['token_info']['group'] = 'mytokens'; $hooks['tokens']['group'] = 'mytokens'; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-175635d43f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_search_info/7.x
Implement `user_search_info()` in PHP for Drupal 7. Required behavior: Implements hook_search_info().
File: modules/user/user.module
function user_search_info() { return array( 'title' => 'Users', ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-175e36a13d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_login/7.x
Give me the example code for `hook_user_login(&$form_state, $account)` in Drupal 7. Hook description: The user just logged in.
Parameters: - $form_state: A keyed array containing the current state of the login form. - $account: The user object on which the operation was just performed. File: modules/user/user.api.php
function hook_user_login(&$form_state, $account) { // If the user has a NULL time zone, notify them to set a time zone. if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) { drupal_set_message(t('Configure your <a href="@user-edit">account time zone...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-176301d31a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_update/7.x
I need the code for `book_node_update($node)` in Drupal 7 (modules/book/book.module). It must do this: Implements hook_node_update().
File: modules/book/book.module
function book_node_update($node) { if (!empty($node->book['bid'])) { if ($node->book['bid'] == 'new') { // New nodes that are their own book. $node->book['bid'] = $node->nid; } $node->book['nid'] = $node->nid; $node->book['menu_name'] = book_menu_name($node->book['bid']); _book_update_...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-177ee084ea
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_overview/7.x
In Drupal 7, write the function `forum_overview($form, &$form_state)` (file modules/forum/forum.admin.inc) so that it does the following: Form constructor for the forum overview form.
Returns a form for controlling the hierarchy of existing forums and containers. File: modules/forum/forum.admin.inc
function forum_overview($form, &$form_state) { module_load_include('inc', 'taxonomy', 'taxonomy.admin'); $vid = variable_get('forum_nav_vocabulary', ''); $vocabulary = taxonomy_vocabulary_load($vid); $form = taxonomy_overview_terms($form, $form_state, $vocabulary); foreach (element_children($form) as $key) ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1785202b02
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21language.inc/function/language_types_configurable/7.x
I need the code for `language_types_configurable($stored = TRUE)` in Drupal 7 (includes/language.inc). It must do this: Returns only the configurable language types.
A language type maybe configurable or fixed. A fixed language type is a type whose language negotiation providers are module-defined and not altered through the user interface. Parameters: - $stored: Optional. By default retrieves values from the 'language_types' variable to avoid unnecessary hook invocations. If set ...
function language_types_configurable($stored = TRUE) { $configurable = &drupal_static(__FUNCTION__); if ($stored && !isset($configurable)) { $types = variable_get('language_types', drupal_language_types()); $configurable = array_keys(array_filter($types)); } if (!$stored) { $result = array(); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1799687e44
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_field_extra_fields/7.x
Implement `node_field_extra_fields()` in PHP for Drupal 7. Required behavior: Implements hook_field_extra_fields().
File: modules/node/node.module
function node_field_extra_fields() { $extra = array(); foreach (node_type_get_types() as $type) { if ($type->has_title) { $extra['node'][$type->type] = array( 'form' => array( 'title' => array( 'label' => $type->title_label, 'description' => t('Node module elemen...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-179a780333
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_export_traverse/7.x
In Drupal 7, write the function `book_export_traverse($tree, $visit_func)` (file modules/book/book.module) so that it does the following: Traverses the book tree to build printable or exportable output.
During the traversal, the $visit_func() callback is applied to each node and is called recursively for each child of the node (in weight, title order). Parameters: - $tree: A subtree of the book menu hierarchy, rooted at the current page. - $visit_func: A function callback to be called upon visiting a node in the tree...
function book_export_traverse($tree, $visit_func) { $output = ''; foreach ($tree as $data) { // Note- access checking is already performed when building the tree. if ($node = node_load($data['link']['nid'], FALSE)) { $children = ''; if ($data['below']) { $children = book_export_travers...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-179ba0dec4
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21image.inc/function/image_dimensions_scale/7.x
Implement `image_dimensions_scale(array &$dimensions, $width = NULL, $height = NULL, $upscale = FALSE)` in PHP for Drupal 7. Required behavior: Scales image dimensions while maintaining aspect ratio.
The resulting dimensions can be smaller for one or both target dimensions. Parameters: - $dimensions: Dimensions to be modified - an array with components width and height, in pixels. - $width: The target width, in pixels. If this value is NULL then the scaling will be based only on the height value. - $height: The ta...
function image_dimensions_scale(array &$dimensions, $width = NULL, $height = NULL, $upscale = FALSE) { $aspect = $dimensions['height'] / $dimensions['width']; // Calculate one of the dimensions from the other target dimension, // ensuring the same aspect ratio as the source dimensions. If one of the // target ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-17c0564274
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_schema_alter/7.x
Give me the example code for `hook_schema_alter(&$schema)` in Drupal 7. Hook description: Perform alterations to existing database schemas.
When a module modifies the database structure of another module (by changing, adding or removing fields, keys or indexes), it should implement hook_schema_alter() to update the default $schema to take its changes into account. See hook_schema() for details on the schema definition structure. Parameters: - $schema: Ne...
function hook_schema_alter(&$schema) { // Add field to existing schema. $schema['users']['fields']['timezone_id'] = array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Per-user timezone configuration.', ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-17df751a6e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.admin.inc/function/comment_multiple_delete_confirm/7.x
I need the code for `comment_multiple_delete_confirm($form, &$form_state)` in Drupal 7 (modules/comment/comment.admin.inc). It must do this: List the selected comments and verify that the admin wants to delete them.
Parameters: - $form_state: An associative array containing the current state of the form. Returns: TRUE if the comments should be deleted, FALSE otherwise. File: modules/comment/comment.admin.inc
function comment_multiple_delete_confirm($form, &$form_state) { $edit = $form_state['input']; $form['comments'] = array( '#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE, ); // array_filter() returns only elements with actual values. $comment_counter = 0; foreach (array_filter($edit['...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-17fb7acbd4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_formatter_settings_summary/7.x
Implement `text_field_formatter_settings_summary($field, $instance, $view_mode)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_settings_summary().
File: modules/field/modules/text/text.module
function text_field_formatter_settings_summary($field, $instance, $view_mode) { $display = $instance['display'][$view_mode]; $settings = $display['settings']; $summary = ''; if (strpos($display['type'], '_trimmed') !== FALSE) { $summary = t('Trimmed limit: @trim_length characters', array('@trim_length' =>...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-180ef85060
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/_batch_queue/7.x
I need the code for `_batch_queue($batch_set)` in Drupal 7 (includes/form.inc). It must do this: Returns a queue object for a batch set.
Parameters: - $batch_set: The batch set. Returns: The queue object. File: includes/form.inc
function _batch_queue($batch_set) { static $queues; // The class autoloader is not available when running update.php, so make // sure the files are manually included. if (!isset($queues)) { $queues = array(); require_once DRUPAL_ROOT . '/modules/system/system.queue.inc'; require_once DRUPAL_ROOT . ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-182bd89ae1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_widget_field/7.x
Implement `field_widget_field($element, $form_state)` in PHP for Drupal 7. Required behavior: Retrieves the field definition for a widget's helper callbacks.
Widgets helper element callbacks (such as #process, #element_validate, #value_callback, ...) should use field_widget_field() and field_widget_instance() instead of field_info_field() and field_info_instance() when they need to access field or instance properties. See hook_field_widget_form() for more details. Paramete...
function field_widget_field($element, $form_state) { $field_state = field_form_get_state($element['#field_parents'], $element['#field_name'], $element['#language'], $form_state); return $field_state['field']; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1831f946a8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_field_extra_fields/7.x
I need the code for `poll_field_extra_fields()` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_field_extra_fields().
File: modules/poll/poll.module
function poll_field_extra_fields() { $extra['node']['poll'] = array( 'form' => array( 'choice_wrapper' => array( 'label' => t('Poll choices'), 'description' => t('Poll choices'), 'weight' => -4, ), 'settings' => array( 'label' => t('Poll settings'), 'descr...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1832cf1062
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/function/hook_filter_info/7.x
In Drupal 7, show an example implementation for `hook_filter_info()` (modules/filter/filter.api.php): Define content filters.
User submitted content is passed through a group of filters before it is output in HTML, in order to remove insecure or unwanted parts, correct or enhance the formatting, transform special keywords, etc. A group of filters is referred to as a "text format". Administrators can create as many text formats as needed. Indi...
function hook_filter_info() { $filters['filter_html'] = array( 'title' => t('Limit allowed HTML tags'), 'description' => t('Allows you to restrict the HTML tags the user can use. It will also remove harmful content such as JavaScript events, JavaScript URLs and CSS styles from those tags that are not removed....
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-183f151ba5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_prepare_instance/7.x
In Drupal 7, write the function `_field_info_prepare_instance($instance, $field)` (file modules/field/field.info.inc) so that it does the following: Prepares an instance definition for 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($instance, $field) { $cache = _field_info_field_cache(); return $cache->prepareInstance($instance, $field['type']); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-187389a884
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_edit_submit/7.x
I need the code for `shortcut_link_edit_submit($form, &$form_state)` in Drupal 7 (modules/shortcut/shortcut.admin.inc). It must do this: Submit handler for shortcut_link_edit().
File: modules/shortcut/shortcut.admin.inc
function shortcut_link_edit_submit($form, &$form_state) { // Normalize the path in case it is an alias. $shortcut_path = drupal_get_normal_path($form_state['values']['shortcut_link']['link_path']); if (empty($shortcut_path)) { $shortcut_path = '<front>'; } $form_state['values']['shortcut_link']['link_path...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1876ae7981
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7081/7.x
In Drupal 7, write the function `system_update_7081()` (file modules/system/system.install) so that it does the following: Remove the Drupal 6 default install profile if it is still in the database.
File: modules/system/system.install
function system_update_7081() { // Sites which used the default install profile in Drupal 6 and then updated // to Drupal 7.44 or earlier will still have a record of this install profile // in the database that needs to be deleted. db_delete('system') ->condition('filename', 'profiles/default/default.profil...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-188cf7bc15
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_date/7.x
In Drupal 7, write the function `xmlrpc_date($time)` (file includes/xmlrpc.inc) so that it does the following: Converts a PHP or ISO date/time to an XML-RPC object.
Parameters: - $time: A PHP timestamp or an ISO date-time string. Returns (object): An XML-RPC time/date object. File: includes/xmlrpc.inc
function xmlrpc_date($time) { $xmlrpc_date = new stdClass(); $xmlrpc_date->is_date = TRUE; // $time can be a PHP timestamp or an ISO one if (is_numeric($time)) { $xmlrpc_date->year = gmdate('Y', $time); $xmlrpc_date->month = gmdate('m', $time); $xmlrpc_date->day = gmdate('d', $time); $xmlrpc_dat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-18bd2ae644
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.authorize.inc/function/update_authorize_run_install/7.x
I need the code for `update_authorize_run_install($filetransfer, $project, $updater_name, $local_url)` in Drupal 7 (modules/update/update.authorize.inc). It must do this: Installs a new project when invoked by authorize.php.
Callback for system_authorized_init() in update_manager_install_form_submit(). Parameters: - $filetransfer (FileTransfer): The FileTransfer object created by authorize.php for use during this operation. - $project (string): The canonical project short name (e.g., {system}.name). - $updater_name (string): The name of t...
function update_authorize_run_install($filetransfer, $project, $updater_name, $local_url) { $operations[] = array( 'update_authorize_batch_copy_project', array( $project, $updater_name, $local_url, $filetransfer, ), ); // @todo Instantiate our Updater to set the human-readable...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-18bfbac78c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_form_build_preview/7.x
I need the code for `comment_form_build_preview($form, &$form_state)` in Drupal 7 (modules/comment/comment.module). It must do this: Build a preview from submitted form values.
File: modules/comment/comment.module
function comment_form_build_preview($form, &$form_state) { $comment = comment_form_submit_build_comment($form, $form_state); $form_state['comment_preview'] = comment_preview($comment); $form_state['rebuild'] = TRUE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-18d25bf394
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_install_tasks_alter/7.x
In Drupal 7, show an example implementation for `hook_install_tasks_alter(&$tasks, $install_state)` (modules/system/system.api.php): Alter the full list of installation tasks.
This hook is invoked on the install profile in install_tasks(). Parameters: - $tasks: An array of all available installation tasks, including those provided by Drupal core. You can modify this array to change or replace any part of the Drupal installation process that occurs after the installation profile is selected....
function hook_install_tasks_alter(&$tasks, $install_state) { // Replace the "Choose language" installation task provided by Drupal core // with a custom callback function defined by this installation profile. $tasks['install_select_locale']['function'] = 'myprofile_locale_selection'; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-18d890c4e6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_tableselect_value/7.x
I need the code for `form_type_tableselect_value($element, $input = FALSE)` in Drupal 7 (includes/form.inc). It must do this: Determines the value for a tableselect form element.
Parameters: - $element: The form element whose value is being populated. - $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned. Returns: The data that will appear in $form_state['values'] for this element, or nothing to use the default. File: inclu...
function form_type_tableselect_value($element, $input = FALSE) { // If $element['#multiple'] == FALSE, then radio buttons are displayed and // the default value handling is used. if (isset($element['#multiple']) && $element['#multiple']) { // Checkboxes are being displayed with the default value coming from t...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-18db3e3441
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_form_user_profile_form_alter/7.x
Implement `contact_form_user_profile_form_alter(&$form, &$form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter().
Add the enable personal contact form to an individual user's account page. File: modules/contact/contact.module
function contact_form_user_profile_form_alter(&$form, &$form_state) { if ($form['#user_category'] == 'account') { $account = $form['#user']; $form['contact'] = array( '#type' => 'fieldset', '#title' => t('Contact settings'), '#weight' => 5, '#collapsible' => TRUE, ); $form['con...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-18ddab7b7d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_preprocess_block/7.x
In Drupal 7, write the function `system_preprocess_block(&$variables)` (file modules/system/system.module) so that it does the following: Implements hook_preprocess_block().
File: modules/system/system.module
function system_preprocess_block(&$variables) { // System menu blocks should get the same class as menu module blocks. if ($variables['block']->module == 'system' && in_array($variables['block']->delta, array_keys(menu_list_system_menus()))) { $variables['classes_array'][] = 'block-menu'; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-18e27bc844
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_entity_info/7.x
In Drupal 7, write the function `comment_entity_info()` (file modules/comment/comment.module) so that it does the following: Implements hook_entity_info().
File: modules/comment/comment.module
function comment_entity_info() { $return = array( 'comment' => array( 'label' => t('Comment'), 'base table' => 'comment', 'uri callback' => 'comment_uri', 'fieldable' => TRUE, 'controller class' => 'CommentController', 'entity keys' => array( 'id' => 'cid', 'bun...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-18ff7ce2c0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_format_form_validate/7.x
Implement `filter_admin_format_form_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for filter_admin_format_form().
File: modules/filter/filter.admin.inc
function filter_admin_format_form_validate($form, &$form_state) { $format_format = trim($form_state['values']['format']); $format_name = trim($form_state['values']['name']); // Ensure that the values to be saved later are exactly the ones validated. form_set_value($form['format'], $format_format, $form_state);...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19052011e1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_block_configure/7.x
Implement `book_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().
File: modules/book/book.module
function book_block_configure($delta = '') { $block = array(); $options = array( 'all pages' => t('Show block on all pages'), 'book pages' => t('Show block only on book pages'), ); $form['book_block_mode'] = array( '#type' => 'radios', '#title' => t('Book navigation block display'), '#option...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-19101bb763
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_theme_enable/7.x
Implement `system_theme_enable()` in PHP for Drupal 7. Required behavior: Menu callback; Enables a theme.
File: modules/system/system.admin.inc
function system_theme_enable() { 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 recognize...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1915008171
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_presave/7.x
In Drupal 7, write the function `field_attach_presave($entity_type, $entity)` (file modules/field/field.attach.inc) so that it does the following: Perform necessary operations just before fields data get saved.
We take no specific action here, we just give other modules the opportunity to act. Parameters: - $entity_type: The type of $entity; e.g. 'node' or 'user'. - $entity: The entity with fields to process. File: modules/field/field.attach.inc
function field_attach_presave($entity_type, $entity) { _field_invoke('presave', $entity_type, $entity); // Let other modules act on presaving the entity. module_invoke_all('field_attach_presave', $entity_type, $entity); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-193fc83197
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_strip_dangerous_protocols/7.x
I need the code for `drupal_strip_dangerous_protocols($uri)` in Drupal 7 (includes/common.inc). It must do this: Strips dangerous protocols (e.g. 'javascript:') from a URI.
This function must be called for all URIs within user-entered input prior to being output to an HTML attribute value. It is often called as part of check_url() or filter_xss(), but those functions return an HTML-encoded string, so this function can be called independently when the output needs to be a plain-text string...
function drupal_strip_dangerous_protocols($uri) { static $allowed_protocols; if (!isset($allowed_protocols)) { $allowed_protocols = array_flip(variable_get('filter_allowed_protocols', array('ftp', 'http', 'https', 'irc', 'mailto', 'news', 'nntp', 'rtsp', 'sftp', 'ssh', 'tel', 'telnet', 'webcal'))); } // I...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-194ec2e05d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_rename_bundle/7.x
Give me the example code for `hook_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new)` in Drupal 7. Hook description: Act on field_attach_rename_bundle().
This hook is invoked after the field module has performed the operation. See field_attach_rename_bundle() for details and arguments. File: modules/field/field.api.php
function hook_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { // Update the extra weights variable with new information. if ($bundle_old !== $bundle_new) { $extra_weights = variable_get('field_extra_weights', array()); if (isset($info[$entity_type][$bundle_old])) { $extra_weights[...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-19514bfa9a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_library_alter/7.x
I need the code for `locale_library_alter(&$libraries, $module)` in Drupal 7 (modules/locale/locale.module). It must do this: Implement hook_library_alter().
Provides the language support for the jQuery UI Date Picker. File: modules/locale/locale.module
function locale_library_alter(&$libraries, $module) { if ($module == 'system' && isset($libraries['ui.datepicker'])) { global $language; // locale.datepicker.js should be added in the JS_LIBRARY group, so that // this attach behavior will execute early. JS_LIBRARY is the default for // hook_library_in...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19546df251
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_storage_delete/7.x
I need the code for `field_sql_storage_field_storage_delete($entity_type, $entity, $fields)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_field_storage_delete().
This function deletes data for all fields for an entity from the database. File: modules/field/modules/field_sql_storage/field_sql_storage.module
function field_sql_storage_field_storage_delete($entity_type, $entity, $fields) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); foreach (field_info_instances($entity_type, $bundle) as $instance) { if (isset($fields[$instance['field_id']])) { $field = field_info_field_by_id($instan...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1961450a13
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_category/7.x
In Drupal 7, write the function `aggregator_form_category($form, &$form_state, $edit = array('title' => '', 'description' => '', 'cid' => NULL))` (file modules/aggregator/aggregator.admin.inc) so that it does the following: Form constructor to add/edit/delete aggregator categories.
Parameters: - $edit: An associative array containing: - title: A string to use for the category title. - description: A string to use for the category description. - cid: The category ID. File: modules/aggregator/aggregator.admin.inc
function aggregator_form_category($form, &$form_state, $edit = array('title' => '', 'description' => '', 'cid' => NULL)) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $edit['title'], '#maxlength' => 64, '#required' => TRUE, ); $form['description'] = a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19725d8f21
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.multilingual.inc/function/_field_language_suggestion/7.x
I need the code for `_field_language_suggestion($available_languages, $language_suggestion, $field_name)` in Drupal 7 (modules/field/field.multilingual.inc). It must do this: Process the given language suggestion based on the available languages.
If a non-empty language suggestion is provided it must appear among the available languages, otherwise it will be ignored. Parameters: - $available_languages: An array of valid language codes. - $language_suggestion: A language code or an array of language codes keyed by field name. - $field_name: The name of the fiel...
function _field_language_suggestion($available_languages, $language_suggestion, $field_name) { // Handle possible language suggestions. if (!empty($language_suggestion)) { // We might have an array of language suggestions keyed by field name. if (is_array($language_suggestion) && isset($language_suggestion[...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1974f8d251
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_unpack/7.x
Implement `drupal_unpack($obj, $field = 'data')` in PHP for Drupal 7. Required behavior: Unserializes and appends elements from a serialized string.
Parameters: - $obj: The object to which the elements are appended. - $field: The attribute of $obj whose value should be unserialized. File: includes/bootstrap.inc
function drupal_unpack($obj, $field = 'data') { if ($obj->$field && $data = unserialize($obj->$field)) { foreach ($data as $key => $value) { if (!empty($key) && !isset($obj->$key)) { $obj->$key = $value; } } } return $obj; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-197999f2a9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_remove/7.x
In Drupal 7, write the function `aggregator_remove($feed)` (file modules/aggregator/aggregator.module) so that it does the following: Removes all items from a feed.
Parameters: - $feed: An object describing the feed to be cleared. File: modules/aggregator/aggregator.module
function aggregator_remove($feed) { _aggregator_get_variables(); // Call hook_aggregator_remove() on all modules. module_invoke_all('aggregator_remove', $feed); // Reset feed. db_update('aggregator_feed') ->condition('fid', $feed->fid) ->fields(array( 'checked' => 0, 'hash' => '', 'e...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1980f72ad9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_clear_update_disk_cache/7.x
Implement `update_clear_update_disk_cache()` in PHP for Drupal 7. Required behavior: Clears the temporary files and directories based on file age from disk.
File: modules/update/update.module
function update_clear_update_disk_cache() { // List of update module cache directories. Do not create the directories if // they do not exist. $directories = array( _update_manager_cache_directory(FALSE), _update_manager_extract_directory(FALSE), ); // Search for files and directories in base folder ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-198c20c6bf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_block_view/7.x
In Drupal 7, write the function `forum_block_view($delta = '')` (file modules/forum/forum.module) so that it does the following: Implements hook_block_view().
Generates a block containing the currently active forum topics and the most recently added forum topics. File: modules/forum/forum.module
function forum_block_view($delta = '') { $query = db_select('forum_index', 'f') ->fields('f') ->addTag('node_access'); switch ($delta) { case 'active': $title = t('Active forum topics'); $query ->orderBy('f.last_comment_timestamp', 'DESC') ->range(0, variable_get('forum_block...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-198c7f9861
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/template_preprocess_profile_listing/7.x
Implement `template_preprocess_profile_listing(&$variables)` in PHP for Drupal 7. Required behavior: Process variables for profile-listing.tpl.php.
The $variables array contains the following arguments: - $account - $fields File: modules/profile/profile.module
function template_preprocess_profile_listing(&$variables) { $variables['user_picture'] = theme('user_picture', array('account' => $variables['account'])); $variables['name'] = theme('username', array('account' => $variables['account'])); $variables['profile'] = array(); // Supply filtered version of $fields th...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19930b15ef
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_get_options/7.x
Implement `form_get_options($element, $key)` in PHP for Drupal 7. Required behavior: Returns the indexes of a select element's options matching a given key.
This function is useful if you need to modify the options that are already in a form element; for example, to remove choices which are not valid because of additional filters imposed by another module. One example might be altering the choices in a taxonomy selector. To correctly handle the case of a multiple hierarchy...
function form_get_options($element, $key) { $keys = array(); foreach ($element['#options'] as $index => $choice) { if (is_array($choice)) { return FALSE; } elseif (is_object($choice)) { if (isset($choice->option[$key])) { $keys[] = $index; } } elseif ($index == $key) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19956108bd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_toolbar_pre_render_alter/7.x
Implement `announcements_feed_toolbar_pre_render_alter($toolbar)` in PHP for Drupal 7. Required behavior: Pre-render function for adding default class to announcement link.
File: modules/announcements_feed/announcements_feed.module
function announcements_feed_toolbar_pre_render_alter($toolbar) { $path = drupal_get_path('module', 'announcements_feed'); $toolbar['#attached']['css'][] = $path . '/announcements_feed-toolbar.css'; module_load_include('inc', 'announcements_feed'); foreach ($toolbar['toolbar_menu']['#links'] as &$link) { if ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19a1dc492d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/template_preprocess_node/7.x
Implement `template_preprocess_node(&$variables)` in PHP for Drupal 7. Required behavior: Processes variables for node.tpl.php
Most themes utilize their own copy of node.tpl.php. The default is located inside "modules/node/node.tpl.php". Look in there for the full list of variables. The $variables array contains the following arguments: - $node - $view_mode - $page File: modules/node/node.module
function template_preprocess_node(&$variables) { $variables['view_mode'] = $variables['elements']['#view_mode']; // Provide a distinct $teaser boolean. $variables['teaser'] = $variables['view_mode'] == 'teaser'; $variables['node'] = $variables['elements']['#node']; $node = $variables['node']; $variables['d...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19b314ce93
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_fetch/7.x
Implement `announcements_feed_fetch($force = FALSE)` in PHP for Drupal 7. Required behavior: Fetches the feed either from a local cache or fresh remotely.
The feed follows the "JSON Feed" format: - https://www.jsonfeed.org/version/1.1/ The structure of an announcement item in the feed is: - id: Id. - title: Title of the announcement. - content_html: Announcement teaser. - url: URL - date_modified: Last updated timestamp. - date_published: Created timestamp. ...
function announcements_feed_fetch($force = FALSE) { $announcements = cache_get('announcements_feed'); if ($force || empty($announcements)) { $announcements_feed_json_url = variable_get('announcements_feed_json_url', ANNOUNCEMENTS_FEED_DEFAULT_JSON_URL); $response = drupal_http_request($announcements_feed_js...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19c8f42cda
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_form_main/7.x
In Drupal 7, write the function `forum_form_main($type, $edit = array())` (file modules/forum/forum.admin.inc) so that it does the following: Page callback: Returns a form for creating a new forum or container.
Parameters: - $type: What is being added. Possible values are 'forum' and 'container'. - $edit: (optional) Associative array containing a forum term to be edited. Defaults to an empty array. Returns: A form for creating a new forum or container. File: modules/forum/forum.admin.inc
function forum_form_main($type, $edit = array()) { $edit = (array) $edit; if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) { return drupal_get_form('forum_confirm_delete', $edit['tid']); } switch ($type) { case 'forum': return drupal_get_form('forum_form_forum...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-19dabe34be
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_system_info_alter/7.x
In Drupal 7, write the function `dashboard_system_info_alter(&$info, $file, $type)` (file modules/dashboard/dashboard.module) so that it does the following: Implements hook_system_info_alter().
Add regions to each theme to store the dashboard blocks. File: modules/dashboard/dashboard.module
function dashboard_system_info_alter(&$info, $file, $type) { if ($type == 'theme') { // Add the dashboard regions (the "inactive" region should always appear // last in the list, for usability reasons). $dashboard_regions = dashboard_region_descriptions(); if (isset($dashboard_regions['dashboard_inact...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-19ebad5fe1
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21xmlrpcs.inc/function/xmlrpc_server_call/7.x
In Drupal 7, write the function `xmlrpc_server_call($xmlrpc_server, $methodname, $args)` (file includes/xmlrpcs.inc) so that it does the following: Dispatches an XML-RPC request and any parameters to the appropriate handler.
Parameters: - $xmlrpc_server (object): Object containing information about this XML-RPC server, the methods it provides, their signatures, etc. - $methodname (string): The external XML-RPC method name; e.g., 'system.methodHelp'. - $args (array): Array containing any parameters that are to be sent along with the request...
function xmlrpc_server_call($xmlrpc_server, $methodname, $args) { // Make sure parameters are in an array if ($args && !is_array($args)) { $args = array($args); } // Has this method been mapped to a Drupal function by us or by modules? if (!isset($xmlrpc_server->callbacks[$methodname])) { return xmlrp...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a067026fd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.install/function/list_update_7001/7.x
Implement `list_update_7001()` in PHP for Drupal 7. Required behavior: Rename the list field types and change 'allowed_values' format.
File: modules/field/modules/list/list.install
function list_update_7001() { $fields = _update_7000_field_read_fields(array('module' => 'list')); foreach ($fields as $field) { $update = array(); // Translate the old string format into the new array format. $allowed_values = $field['settings']['allowed_values']; if (is_string($allowed_values)) {...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a187f7eda
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_delete/7.x
Implement `file_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items)` in PHP for Drupal 7. Required behavior: Implements hook_field_delete().
File: modules/file/file.field.inc
function file_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); // Delete all file usages within this entity. foreach ($items as $delta => $item) { file_field_delete_file($item, $field, $entity_type, $id, 0); }...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1a2747dec5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_get_projects/7.x
I need the code for `update_get_projects()` in Drupal 7 (modules/update/update.compare.inc). It must do this: Fetches an array of installed and enabled projects.
This is only responsible for generating an array of projects (taking into account projects that include more than one module or theme). Other information like the specific version and install type (official release, dev snapshot, etc) is handled later in update_process_project_info() since that logic is only required w...
function update_get_projects() { $projects = &drupal_static(__FUNCTION__, array()); if (empty($projects)) { // Retrieve the projects from cache, if present. $projects = update_project_cache('update_project_projects'); if (empty($projects)) { // Still empty, so we have to rebuild the cache. $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a28d5d36f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/simpletest_test_form/7.x
I need the code for `simpletest_test_form($form)` in Drupal 7 (modules/simpletest/simpletest.pages.inc). It must do this: List tests arranged in groups that can be selected and run.
File: modules/simpletest/simpletest.pages.inc
function simpletest_test_form($form) { $form['tests'] = array( '#type' => 'fieldset', '#title' => t('Tests'), '#description' => t('Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.'), ); $form['tests']['table'] = array( '#theme' => 'simpletest_test_table', ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a4b290ef8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_switcher_session/7.x
Implement `locale_language_switcher_session($type, $path)` in PHP for Drupal 7. Required behavior: Return the session language switcher block.
File: includes/locale.inc
function locale_language_switcher_session($type, $path) { drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css'); $param = variable_get('locale_language_negotiation_session_param', 'language'); $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $GLOBALS[$type]->language; $languages ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a5a077636
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_insert/7.x
Implement `poll_insert($node)` in PHP for Drupal 7. Required behavior: Implements hook_insert().
File: modules/poll/poll.module
function poll_insert($node) { if (!user_access('administer nodes')) { // Make sure all votes are 0 initially foreach ($node->choice as $i => $choice) { $node->choice[$i]['chvotes'] = 0; } $node->active = 1; } db_insert('poll') ->fields(array( 'nid' => $node->nid, 'runtime' =...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1a717d726a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_http_build_query/7.x
In Drupal 7, write the function `drupal_http_build_query(array $query, $parent = '')` (file includes/common.inc) so that it does the following: Parses an array into a valid, rawurlencoded query string.
This differs from http_build_query() as we need to rawurlencode() (instead of urlencode()) all query parameters. Parameters: - $query: The query parameter array to be processed, e.g. $_GET. - $parent: Internal use only. Used to build the $query array key for nested items. Returns: A rawurlencoded string which can be ...
function drupal_http_build_query(array $query, $parent = '') { $params = array(); foreach ($query as $key => $value) { $key = $parent ? $parent . rawurlencode('[' . $key . ']') : rawurlencode($key); // Recurse into children. if (is_array($value)) { $params[] = drupal_http_build_query($value, $ke...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a756c8b34
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/theme_filter_admin_overview/7.x
Implement `theme_filter_admin_overview($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the text format administration overview form.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/filter/filter.admin.inc
function theme_filter_admin_overview($variables) { $form = $variables['form']; $rows = array(); foreach (element_children($form['formats']) as $id) { $form['formats'][$id]['weight']['#attributes']['class'] = array('text-format-order-weight'); $rows[] = array( 'data' => array( drupal_render(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a89c84ada
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_preprocess_block/7.x
I need the code for `garland_preprocess_block(&$variables)` in Drupal 7 (themes/garland/template.php). It must do this: Override or insert variables into the block template.
File: themes/garland/template.php
function garland_preprocess_block(&$variables) { $variables['title_attributes_array']['class'][] = 'title'; $variables['classes_array'][] = 'clearfix'; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1a97d75113
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/theme_overlay_disable_message/7.x
Implement `theme_overlay_disable_message($variables)` in PHP for Drupal 7. Required behavior: Returns the HTML for the message about how to disable the overlay.
Parameters: - $variables: An associative array with an 'element' element, which itself is an associative array containing: - profile_link: The link to this user's account. - dismiss_message_link: The link to dismiss the overlay. File: modules/overlay/overlay.module
function theme_overlay_disable_message($variables) { $element = $variables['element']; // Add CSS classes to hide the links from most sighted users, while keeping // them accessible to screen-reader users and keyboard-only users. To assist // screen-reader users, this message appears in both the parent and chi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1aa3559eea
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_custom_theme/7.x
In Drupal 7, write the function `system_custom_theme()` (file modules/system/system.module) so that it does the following: Implements hook_custom_theme().
File: modules/system/system.module
function system_custom_theme() { if (user_access('view the administration theme') && path_is_admin(current_path())) { return variable_get('admin_theme'); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1ab6665f94
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_access_view_all_nodes/7.x
In Drupal 7, write the function `node_access_view_all_nodes($account = NULL)` (file modules/node/node.module) so that it does the following: Determines whether the user has a global viewing grant for all nodes.
Checks to see whether any module grants global 'view' access to a user account; global 'view' access is encoded in the {node_access} table as a grant with nid=0. If no node access modules are enabled, node.module defines such a global 'view' access grant. This function is called when a node listing query is tagged wit...
function node_access_view_all_nodes($account = NULL) { global $user; if (!$account) { $account = $user; } // Statically cache results in an array keyed by $account->uid. $access = &drupal_static(__FUNCTION__); if (isset($access[$account->uid])) { return $access[$account->uid]; } // If no modul...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1abbcfce3b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.admin.inc/function/statistics_top_visitors/7.x
Implement `statistics_top_visitors()` in PHP for Drupal 7. Required behavior: Page callback: Displays the "top visitors" page.
This displays the pages with the top number of visitors in a given time interval that haven't been flushed yet. The flush interval is set on the statistics settings form, but is dependent on cron running. Returns: A render array containing the top visitors information. File: modules/statistics/statistics.admin.inc
function statistics_top_visitors() { $header = array( array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'), array('data' => t('Visitor'), 'field' => 'u.name'), array('data' => t('Total page generation time'), 'field' => 'total'), array('data' => user_access('block IP addresses') ? t('Opera...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1abde71718
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_icon_path/7.x
Implement `file_icon_path($file, $icon_directory = NULL)` in PHP for Drupal 7. Required behavior: Creates a path to the icon for a file object.
Parameters: - $file: A file object. - $icon_directory: (optional) A path to a directory of icons to be used for files. Defaults to the value of the "file_icon_directory" variable. Returns: A string to the icon as a local path, or FALSE if an appropriate icon could not be found. File: modules/file/file.module
function file_icon_path($file, $icon_directory = NULL) { // Use the default set of icons if none specified. if (!isset($icon_directory)) { $icon_directory = variable_get('file_icon_directory', drupal_get_path('module', 'file') . '/icons'); } // If there's an icon matching the exact mimetype, go for it. $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1ac53d6751
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_access/7.x
In Drupal 7, show an example implementation for `hook_field_access($op, $field, $entity_type, $entity, $account)` (modules/field/field.api.php): Determine whether the user has access to a given field.
This hook is invoked from field_access() to let modules block access to operations on fields. If no module returns FALSE, the operation is allowed. Parameters: - $op: The operation to be performed. Possible values: 'edit', 'view'. - $field: The field on which the operation is to be performed. - $entity_type: The type ...
function hook_field_access($op, $field, $entity_type, $entity, $account) { if ($field['field_name'] == 'field_of_interest' && $op == 'edit') { return user_access('edit field of interest', $account); } return TRUE; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-1ad889a590
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_search_preprocess/7.x
In Drupal 7, show an example implementation for `hook_search_preprocess($text)` (modules/search/search.api.php): Preprocess text for search.
This hook is called to preprocess both the text added to the search index and the keywords users have submitted for searching. Possible uses: - Adding spaces between words of Chinese or Japanese text. - Stemming words down to their root words to allow matches between, for instance, walk, walked, walking, and walks i...
function hook_search_preprocess($text) { // Do processing on $text return $text; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-1ad924f2bf
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_state_defaults/7.x
I need the code for `install_state_defaults()` in Drupal 7 (includes/install.core.inc). It must do this: Returns an array of default settings for the global installation state.
The installation state is initialized with these settings at the beginning of each page request. They may evolve during the page request, but they are initialized again once the next request begins. Non-interactive Drupal installations can override some of these default settings by passing in an array to the installat...
function install_state_defaults() { $defaults = array( // The current task being processed. 'active_task' => NULL, // The last task that was completed during the previous installation // request. 'completed_task' => NULL, // This becomes TRUE only when Drupal's system module is installed. ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1b01f163b7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_boot/7.x
In Drupal 7, show an example implementation for `hook_boot()` (modules/system/system.api.php): Perform setup tasks for all page requests.
This hook is run at the beginning of the page request. It is typically used to set up global parameters that are needed later in the request. Only use this hook if your code must run even for cached page views. This hook is called before the theme, modules, or most include files are loaded into memory. It happens whil...
function hook_boot() { // We need user_access() in the shutdown function. Make sure it gets loaded. drupal_load('module', 'user'); drupal_register_shutdown_function('devel_shutdown'); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-1b15b16631
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contextual%21contextual.module/function/contextual_permission/7.x
Implement `contextual_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().
File: modules/contextual/contextual.module
function contextual_permission() { return array( 'access contextual links' => array( 'title' => t('Use contextual links'), 'description' => t('Use contextual links to perform actions related to elements on a page.'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1b1972dcb4
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_library/7.x
In Drupal 7, write the function `drupal_get_library($module, $name = NULL)` (file includes/common.inc) so that it does the following: Retrieves information for a JavaScript/CSS library.
Library information is statically cached. Libraries are keyed by module for several reasons: - Libraries are not unique. Multiple modules might ship with the same library in a different version or variant. This registry cannot (and does not attempt to) prevent library conflicts. - Modules implementing and thereby d...
function drupal_get_library($module, $name = NULL) { $libraries = &drupal_static(__FUNCTION__, array()); if (!isset($libraries[$module])) { // Retrieve all libraries associated with the module. $module_libraries = module_invoke($module, 'library'); if (empty($module_libraries)) { $module_librarie...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1b3aeef176
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_permissions_submit/7.x
In Drupal 7, write the function `user_admin_permissions_submit($form, &$form_state)` (file modules/user/user.admin.inc) so that it does the following: Save permissions selected on the administer permissions page.
File: modules/user/user.admin.inc
function user_admin_permissions_submit($form, &$form_state) { foreach ($form_state['values']['role_names'] as $rid => $name) { user_role_change_permissions($rid, $form_state['values'][$rid]); } drupal_set_message(t('The changes have been saved.')); // Clear the cached pages and blocks. cache_clear_all()...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1b59703342
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_widget_info/7.x
Give me the example code for `hook_field_widget_info()` in Drupal 7. Hook description: Expose Field API widget types.
Returns: An array describing the widget types implemented by the module. The keys are widget type names. To avoid name clashes, widget type names should be prefixed with the name of the module that exposes them. The values are arrays describing the widget type, with the following key/value pairs: - label: The human-rea...
function hook_field_widget_info() { return array( 'text_textfield' => array( 'label' => t('Text field'), 'field types' => array('text'), 'settings' => array('size' => 60), 'behaviors' => array( 'multiple values' => FIELD_BEHAVIOR_DEFAULT, 'default value' => FIELD_BEHAVIOR_D...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-1b66f5b3e7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_presave/7.x
In Drupal 7, write the function `book_node_presave($node)` (file modules/book/book.module) so that it does the following: Implements hook_node_presave().
File: modules/book/book.module
function book_node_presave($node) { // Always save a revision for non-administrators. if (!empty($node->book['bid']) && !user_access('administer nodes')) { $node->revision = 1; // The database schema requires a log message for every revision. if (!isset($node->log)) { $node->log = ''; } } ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1b67df0151
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_export_wrap/7.x
In Drupal 7, write the function `_locale_export_wrap($str, $len)` (file includes/locale.inc) so that it does the following: Custom word wrapping for Portable Object (Template) files.
File: includes/locale.inc
function _locale_export_wrap($str, $len) { $words = explode(' ', $str); $return = array(); $cur = ""; $nstr = 1; while (count($words)) { $word = array_shift($words); if ($nstr) { $cur = $word; $nstr = 0; } elseif (strlen("$cur $word") > $len) { $return[] = $cur . " "; ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1b76cbf430
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess_page/7.x
Implement `template_preprocess_page(&$variables)` in PHP for Drupal 7. Required behavior: Preprocess variables for page.tpl.php
Most themes utilize their own copy of page.tpl.php. The default is located inside "modules/system/page.tpl.php". Look in there for the full list of variables. Uses the arg() function to generate a series of page template suggestions based on the current path. Any changes to variables in this preprocessor should also ...
function template_preprocess_page(&$variables) { // Move some variables to the top level for themer convenience and template cleanliness. $variables['show_messages'] = $variables['page']['#show_messages']; foreach (system_region_list($GLOBALS['theme'], REGIONS_ALL, FALSE) as $region_key) { if (!isset($variab...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1b80b7e331
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7019/7.x
Implement `user_update_7019()` in PHP for Drupal 7. Required behavior: Ensure there is a combined index on {authmap}.uid and {authmap}.module.
File: modules/user/user.install
function user_update_7019() { // Check first in case it was already added manually. if (!db_index_exists('authmap', 'uid_module')) { db_add_index('authmap', 'uid_module', array('uid', 'module')); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1b8cfa2c75
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_database_errors/7.x
In Drupal 7, write the function `install_database_errors($database, $settings_file)` (file includes/install.core.inc) so that it does the following: Checks a database connection and returns any errors.
File: includes/install.core.inc
function install_database_errors($database, $settings_file) { global $databases; $errors = array(); // Check database type. $database_types = drupal_get_database_types(); $driver = $database['driver']; if (!isset($database_types[$driver])) { $errors['driver'] = st("In your %settings_file file you have ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1ba1c92ca8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/theme_status_report/7.x
I need the code for `theme_status_report($variables)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Returns HTML for the status report.
This theme function is dependent on install.inc being loaded, because that's where the constants are defined. Parameters: - $variables: An associative array containing: - requirements: An array of requirements/status items. Each requirement is an associative array containing the following elements: - title: The name o...
function theme_status_report($variables) { $requirements = $variables['requirements']; $severities = array( REQUIREMENT_INFO => array( 'title' => t('Info'), 'class' => 'info', ), REQUIREMENT_OK => array( 'title' => t('OK'), 'class' => 'ok', ), REQUIREMENT_WARNING => array...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1ba7bebd0a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_user_delete/7.x
In Drupal 7, write the function `poll_user_delete($account)` (file modules/poll/poll.module) so that it does the following: Implements hook_user_delete().
File: modules/poll/poll.module
function poll_user_delete($account) { db_delete('poll_vote') ->condition('uid', $account->uid) ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1baab824b0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_load/7.x
Implement `forum_node_load($nodes)` in PHP for Drupal 7. Required behavior: Implements hook_node_load().
File: modules/forum/forum.module
function forum_node_load($nodes) { $node_vids = array(); foreach ($nodes as $node) { if (_forum_node_check_node_type($node)) { $node_vids[] = $node->vid; } } if (!empty($node_vids)) { $query = db_select('forum', 'f'); $query ->fields('f', array('nid', 'tid')) ->condition('f.vid...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1bb14806a1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_vocabulary_confirm_reset_alphabetical/7.x
In Drupal 7, write the function `taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vid)` (file modules/taxonomy/taxonomy.admin.inc) so that it does the following: Form builder to confirm resetting a vocabulary to alphabetical order.
File: modules/taxonomy/taxonomy.admin.inc
function taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vid) { $vocabulary = taxonomy_vocabulary_load($vid); $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); $form['vid'] = array('#type' => 'value', '#value' => $vid); $form['machine_name'] = array('#type' => 'value', '...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1bbb69edfb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_display_ENTITY_TYPE_alter/7.x
Give me the example code for `hook_field_display_ENTITY_TYPE_alter(&$display, $context)` in Drupal 7. Hook description: Alters the display settings of a field on a given entity type before it gets displayed.
Modules can implement hook_field_display_ENTITY_TYPE_alter() to alter display settings for fields on a specific entity type, rather than implementing hook_field_display_alter(). This hook is called once per field per displayed entity. If the result of the hook involves reading from the database, it is highly recommend...
function hook_field_display_ENTITY_TYPE_alter(&$display, $context) { // Leave field labels out of the search index. if ($context['view_mode'] == 'search_index') { $display['label'] = 'hidden'; } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-1bbf86635f
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_language_types/7.x
In Drupal 7, write the function `drupal_language_types()` (file includes/bootstrap.inc) so that it does the following: Returns a list of the built-in language types.
Returns: An array of key-values pairs where the key is the language type and the value is its configurability. File: includes/bootstrap.inc
function drupal_language_types() { return array( LANGUAGE_TYPE_INTERFACE => TRUE, LANGUAGE_TYPE_CONTENT => FALSE, LANGUAGE_TYPE_URL => FALSE, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1bc1dad456
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_replace/7.x
In Drupal 7, write the function `ajax_command_replace($selector, $html, $settings = NULL)` (file includes/ajax.inc) so that it does the following: Creates a Drupal Ajax 'insert/replaceWith' command.
The 'insert/replaceWith' command instructs the client to use jQuery's replaceWith() method to replace each element matched matched by the given selector with the given HTML. This command is implemented by Drupal.ajax.prototype.commands.insert() defined in misc/ajax.js. Parameters: - $selector: A jQuery selector strin...
function ajax_command_replace($selector, $html, $settings = NULL) { return array( 'command' => 'insert', 'method' => 'replaceWith', 'selector' => $selector, 'data' => $html, 'settings' => $settings, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1bcbfb8542
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_deliver_page/7.x
I need the code for `drupal_deliver_page($page_callback_result, $default_delivery_callback = NULL)` in Drupal 7 (includes/common.inc). It must do this: Delivers a page callback result to the browser in the appropriate format.
This function is most commonly called by menu_execute_active_handler(), but can also be called by error conditions such as drupal_not_found(), drupal_access_denied(), and drupal_site_offline(). When a user requests a page, index.php calls menu_execute_active_handler(), which calls the 'page callback' function register...
function drupal_deliver_page($page_callback_result, $default_delivery_callback = NULL) { if (!isset($default_delivery_callback) && ($router_item = menu_get_item())) { $default_delivery_callback = $router_item['delivery_callback']; } $delivery_callback = !empty($default_delivery_callback) ? $default_delivery_c...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1bd039a97e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_token_value/7.x
I need the code for `form_type_token_value($element, $input = FALSE)` in Drupal 7 (includes/form.inc). It must do this: Determines the value for form's token value.
Parameters: - $element: The form element whose value is being populated. - $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned. Returns: The data that will appear in $form_state['values'] for this element, or nothing to use the default. File: inclu...
function form_type_token_value($element, $input = FALSE) { if ($input !== FALSE) { return (string) $input; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1bd6da8fe6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_maintenance_theme/7.x
I need the code for `drupal_maintenance_theme()` in Drupal 7 (includes/bootstrap.inc). It must do this: Enables use of the theme system without requiring database access.
Loads and initializes the theme system for site installs, updates and when the site is in maintenance mode. This also applies when the database fails. File: includes/bootstrap.inc
function drupal_maintenance_theme() { require_once DRUPAL_ROOT . '/includes/theme.maintenance.inc'; _drupal_maintenance_theme(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1bf2eade31
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_cancel_methods_alter/7.x
Give me the example code for `hook_user_cancel_methods_alter(&$methods)` in Drupal 7. Hook description: Modify account cancellation methods.
By implementing this hook, modules are able to add, customize, or remove account cancellation methods. All defined methods are turned into radio button form elements by user_cancel_methods() after this hook is invoked. The following properties can be defined for each method: - title: The radio button's title. - descrip...
function hook_user_cancel_methods_alter(&$methods) { // Limit access to disable account and unpublish content method. $methods['user_cancel_block_unpublish']['access'] = user_access('administer site configuration'); // Remove the content re-assigning method. unset($methods['user_cancel_reassign']); // Add a...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-1c147ef308
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_node_delete/7.x
In Drupal 7, write the function `statistics_node_delete($node)` (file modules/statistics/statistics.module) so that it does the following: Implements hook_node_delete().
File: modules/statistics/statistics.module
function statistics_node_delete($node) { // clean up statistics table when node is deleted db_delete('node_counter') ->condition('nid', $node->nid) ->execute(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-1c2478f61c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/_tracker_myrecent_access/7.x
In Drupal 7, write the function `_tracker_myrecent_access($account)` (file modules/tracker/tracker.module) so that it does the following: Access callback for tracker/%user_uid_optional.
File: modules/tracker/tracker.module
function _tracker_myrecent_access($account) { // This path is only allowed for authenticated users looking at their own content. return $account->uid && ($GLOBALS['user']->uid == $account->uid) && user_access('access content'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-1c4a23b0fd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_revision_tablename/7.x
In Drupal 7, write the function `_field_sql_storage_revision_tablename($field)` (file modules/field/modules/field_sql_storage/field_sql_storage.module) so that it does the following: Generate a table name for a field revision archive table.
Parameters: - $name: The field structure. Returns: A string containing the generated name for the database table File: modules/field/modules/field_sql_storage/field_sql_storage.module
function _field_sql_storage_revision_tablename($field) { if ($field['deleted']) { return "field_deleted_revision_{$field['id']}"; } else { return "field_revision_{$field['field_name']}"; } }
[ "code-task", "function" ]
2026-09-30T00:00:00