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-be78a3cae2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_settings_validate/7.x | I need the code for `image_gd_settings_validate($form, &$form_state)` in Drupal 7 (modules/system/image.gd.inc). It must do this: Validate the submitted GD settings. | File: modules/system/image.gd.inc | function image_gd_settings_validate($form, &$form_state) {
// Validate image quality range.
$value = $form_state['values']['image_jpeg_quality'];
if (!is_numeric($value) || $value < 0 || $value > 100) {
form_set_error('image_jpeg_quality', t('JPEG quality must be a number between 0 and 100.'));
}
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bea5b4affe | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_navigation_links_rebuild/7.x | In Drupal 7, write the function `_menu_navigation_links_rebuild($menu)` (file includes/menu.inc) so that it does the following: Builds menu links for the items in the menu router. | File: includes/menu.inc | function _menu_navigation_links_rebuild($menu) {
// Add normal and suggested items as links.
$menu_links = array();
foreach ($menu as $path => $item) {
if ($item['_visible']) {
$menu_links[$path] = $item;
$sort[$path] = $item['_number_parts'];
}
}
if ($menu_links) {
// Keep an array of... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bea65045e7 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_view_MODULE_DELTA_alter/7.x | In Drupal 7, show an example implementation for `hook_block_view_MODULE_DELTA_alter(&$data, $block)` (modules/block/block.api.php): Perform alterations to a specific block. | Modules can implement hook_block_view_MODULE_DELTA_alter() to modify a specific block, rather than implementing hook_block_view_alter().
Parameters:
- $data: The data as returned from the hook_block_view() implementation of the module that defined the block. This could be an empty array or NULL value (if the block is ... | function hook_block_view_MODULE_DELTA_alter(&$data, $block) {
// This code will only run for a specific block. For example, if MODULE_DELTA
// in the function definition above is set to "mymodule_somedelta", the code
// will only run on the "somedelta" block provided by the "mymodule" module.
// Change the tit... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-bead7ba51a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_modules_uninstall/7.x | I need the code for `system_modules_uninstall($form, $form_state = NULL)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Builds a form of currently disabled modules. | Parameters:
- $form_state: ['values'] Submitted form values.
Returns: A form array representing the currently disabled modules.
File: modules/system/system.admin.inc | function system_modules_uninstall($form, $form_state = NULL) {
// Make sure the install API is available.
include_once DRUPAL_ROOT . '/includes/install.inc';
// Display the confirm form if any modules have been submitted.
if (!empty($form_state['storage']) && $confirm_form = system_modules_uninstall_confirm_fo... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bec7241f61 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/_system_info_add_path/7.x | Implement `_system_info_add_path($info, $path)` in PHP for Drupal 7. Required behavior: Prefixes all values in an .info file array with a given path. | This helper function is mainly used to prefix all array values of an .info file property with a single given path (to the module or theme); e.g., to prefix all values of the 'stylesheets' or 'scripts' properties with the file path to the defining module/theme.
Parameters:
- $info: A nested array of data of an .info fi... | function _system_info_add_path($info, $path) {
foreach ($info as $key => $value) {
// Recurse into nested values until we reach the deepest level.
if (is_array($value)) {
$info[$key] = _system_info_add_path($info[$key], $path);
}
// Unset the original value's key and set the new value with prefi... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-becf51baa0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_cron/7.x | In Drupal 7, write the function `statistics_cron()` (file modules/statistics/statistics.module) so that it does the following: Implements hook_cron(). | File: modules/statistics/statistics.module | function statistics_cron() {
$statistics_timestamp = variable_get('statistics_day_timestamp', 0);
if ((REQUEST_TIME - $statistics_timestamp) >= 86400) {
// Reset day counts.
db_update('node_counter')
->fields(array('daycount' => 0))
->execute();
variable_set('statistics_day_timestamp', REQU... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-bed227678c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_delete_multiple/7.x | Implement `comment_delete_multiple($cids)` in PHP for Drupal 7. Required behavior: Delete comments and all their replies. | Parameters:
- $cids: The comment to delete.
File: modules/comment/comment.module | function comment_delete_multiple($cids) {
$comments = comment_load_multiple($cids);
if ($comments) {
$transaction = db_transaction();
try {
// Delete the comments.
db_delete('comment')
->condition('cid', array_keys($comments), 'IN')
->execute();
foreach ($comments as $comme... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bed5c52153 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_set_breadcrumb/7.x | In Drupal 7, write the function `drupal_set_breadcrumb($breadcrumb = NULL)` (file includes/common.inc) so that it does the following: Sets the breadcrumb trail for the current page. | Parameters:
- $breadcrumb: Array of links, starting with "home" and proceeding up to but not including the current page.
File: includes/common.inc | function drupal_set_breadcrumb($breadcrumb = NULL) {
$stored_breadcrumb = &drupal_static(__FUNCTION__);
if (isset($breadcrumb)) {
$stored_breadcrumb = $breadcrumb;
}
return $stored_breadcrumb;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bedbf195d1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/theme_file_widget_multiple/7.x | Implement `theme_file_widget_multiple($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a group of file upload widgets. | Parameters:
- $variables: An associative array containing: - element: A render element representing the widgets.
File: modules/file/file.field.inc | function theme_file_widget_multiple($variables) {
$element = $variables['element'];
// Special ID and classes for draggable tables.
$weight_class = $element['#id'] . '-weight';
$table_id = $element['#id'] . '-table';
// Build up a table of applicable fields.
$headers = array();
$headers[] = t('File info... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-beec628416 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/template_preprocess_comment_wrapper/7.x | I need the code for `template_preprocess_comment_wrapper(&$variables)` in Drupal 7 (modules/comment/comment.module). It must do this: Process variables for comment-wrapper.tpl.php. | File: modules/comment/comment.module | function template_preprocess_comment_wrapper(&$variables) {
// Provide contextual information.
$variables['node'] = $variables['content']['#node'];
$variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->type, COMMENT_MODE_THREADED);
// The comment form is optional and may not ex... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-befb0273d9 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_build_css_cache/7.x | I need the code for `drupal_build_css_cache($css)` in Drupal 7 (includes/common.inc). It must do this: Aggregates and optimizes CSS files into a cache file in the files directory. | The file name for the CSS cache file is generated from the hash of the aggregated contents of the files in $css. This forces proxies and browsers to download new CSS when the CSS changes.
The cache file name is retrieved on a page load via a lookup variable that contains an associative array. The array key is the hash... | function drupal_build_css_cache($css) {
$data = '';
$uri = '';
$map = variable_get('drupal_css_cache_files', array());
// Create a new array so that only the file names are used to create the hash.
// This prevents new aggregates from being created unnecessarily.
$css_data = array();
foreach ($css as $css... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bf03f92f93 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_assign_owner_action_form/7.x | Implement `node_assign_owner_action_form($context)` in PHP for Drupal 7. Required behavior: Generates the settings form for node_assign_owner_action(). | Parameters:
- $context: Array of additional information about what triggered the action. Includes the following elements: - 'owner_uid': User ID to assign to the node.
File: modules/node/node.module | function node_assign_owner_action_form($context) {
$description = t('The username of the user to which you would like to assign ownership.');
$count = db_query("SELECT COUNT(*) FROM {users}")->fetchField();
$owner_name = '';
if (isset($context['owner_uid'])) {
$owner_name = db_query("SELECT name FROM {users... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bf1af61d67 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_load/7.x | I need the code for `book_node_load($nodes, $types)` in Drupal 7 (modules/book/book.module). It must do this: Implements hook_node_load(). | File: modules/book/book.module | function book_node_load($nodes, $types) {
$result = db_query("SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid IN (:nids)", array(':nids' => array_keys($nodes)), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $record) {
$nodes[$record['nid']]->book = $record;
$nod... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-bf1c54022c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_submit/7.x | Give me the example code for `hook_field_attach_submit($entity_type, $entity, $form, &$form_state)` in Drupal 7. Hook description: Act on field_attach_submit(). | This hook is invoked after the field module has performed the operation.
Parameters:
- $entity_type: The type of $entity; for example, 'node' or 'user'.
- $entity: The entity for which an edit form is being submitted. The incoming form values have been extracted as field values of the $entity object.
- $form: The form... | function hook_field_attach_submit($entity_type, $entity, $form, &$form_state) {
// Sample case of an 'Empty the field' checkbox added on the form, allowing
// a given field to be emptied.
$values = drupal_array_get_nested_value($form_state['values'], $form['#parents']);
if (!empty($values['empty_field_foo'])) {... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-bf26135208 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_filetransfer_info/7.x | In Drupal 7, show an example implementation for `hook_filetransfer_info()` (modules/system/system.api.php): Register information about FileTransfer classes provided by a module. | The FileTransfer class allows transferring files over a specific type of connection. Core provides classes for FTP and SSH. Contributed modules are free to extend the FileTransfer base class to add other connection types, and if these classes are registered via hook_filetransfer_info(), those connection types will be a... | function hook_filetransfer_info() {
$info['sftp'] = array(
'title' => t('SFTP (Secure FTP)'),
'file' => 'sftp.filetransfer.inc',
'class' => 'FileTransferSFTP',
'weight' => 10,
);
return $info;
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-bf290972c7 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/_options_form_to_storage/7.x | In Drupal 7, write the function `_options_form_to_storage($element)` (file modules/field/modules/options/options.module) so that it does the following: Transforms submitted form values into field storage format. | File: modules/field/modules/options/options.module | function _options_form_to_storage($element) {
$values = array_values((array) $element['#value']);
$properties = $element['#properties'];
// On/off checkbox: transform '0 / 1' into the 'on / off' values.
if ($element['#type'] == 'checkbox') {
$values = array($values[0] ? $element['#on_value'] : $element['#o... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bf3682a0f3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_form_block_admin_display_form_alter/7.x | I need the code for `dashboard_form_block_admin_display_form_alter(&$form, &$form_state, $form_id)` in Drupal 7 (modules/dashboard/dashboard.module). It must do this: Implements hook_form_FORM_ID_alter(). | File: modules/dashboard/dashboard.module | function dashboard_form_block_admin_display_form_alter(&$form, &$form_state, $form_id) {
// Hide dashboard regions (and any blocks placed within them) from the block
// administration form and from the options list on that form. This
// function is called for both the dashboard block configuration form and the
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-bf58b4d3b1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_password/7.x | Implement `theme_password($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a password form element. | Parameters:
- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #title, #value, #description, #size, #maxlength, #required, #attributes.
File: includes/form.inc | function theme_password($variables) {
$element = $variables['element'];
$element['#attributes']['type'] = 'password';
element_set_attributes($element, array('id', 'name', 'size', 'maxlength'));
_form_set_class($element, array('form-text'));
return '<input' . drupal_attributes($element['#attributes']) . ' />'... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bfa1165df8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21session.inc/function/_drupal_session_delete_cookie/7.x | I need the code for `_drupal_session_delete_cookie($name, $secure = NULL)` in Drupal 7 (includes/session.inc). It must do this: Deletes the session cookie. | Parameters:
- $name: Name of session cookie to delete.
- $secure (boolean): Force the secure value of the cookie.
File: includes/session.inc | function _drupal_session_delete_cookie($name, $secure = NULL) {
global $is_https;
if (isset($_COOKIE[$name]) || (!$is_https && $secure === TRUE)) {
$params = session_get_cookie_params();
if ($secure !== NULL) {
$params['secure'] = $secure;
}
$options = array(
'expires' => REQUEST_TIME - ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bfad61715c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.module/function/_image_source_image_exists/7.x | Implement `_image_source_image_exists($image_uri, $token_is_valid)` in PHP for Drupal 7. Required behavior: Checks whether the provided source image exists. | When a valid token is provided for the image URI, this function is equivalent to calling file_exists($image_uri).
Parameters:
- $image_uri (string): The URI for the source image.
- $token_is_valid (bool): Whether a valid image token was supplied.
Returns (bool): Whether the source image exists.
File: modules/image/i... | function _image_source_image_exists($image_uri, $token_is_valid) {
$exists = file_exists($image_uri);
// If the file doesn't exist, we can stop here.
if (!$exists) {
return FALSE;
}
if ($token_is_valid) {
return TRUE;
}
if (file_uri_scheme($image_uri) !== 'public') {
return TRUE;
}
$im... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bfbebce1db | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7048/7.x | I need the code for `system_update_7048()` in Drupal 7 (modules/system/system.install). It must do this: Convert path languages from the empty string to LANGUAGE_NONE. | File: modules/system/system.install | function system_update_7048() {
db_update('url_alias')
->fields(array('language' => LANGUAGE_NONE))
->condition('language', '')
->execute();
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bfbf1f2186 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21file.inc/function/file_unmanaged_copy/7.x | I need the code for `file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXISTS_RENAME)` in Drupal 7 (includes/file.inc). It must do this: Copies a file to a new location without invoking the file API. | This is a powerful function that in many ways performs like an advanced
version of copy().
- Checks if $source and $destination are valid and readable/writable.
- If file already exists in $destination either the call will error out,
replace the file or rename the file based on the $replace parameter.
- If the $sourc... | function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
$original_source = $source;
// Assert that the source file actually exists.
if (!file_exists($source)) {
// @todo Replace drupal_set_message() calls with exceptions instead.
drupal_set_message(t('The specified fil... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bfd19bd13f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_calculate_project_data/7.x | Implement `update_calculate_project_data($available)` in PHP for Drupal 7. Required behavior: Calculates the current update status of all projects on the site. | The results of this function are expensive to compute, especially on sites with lots of modules or themes, since it involves a lot of comparisons and other operations. Therefore, we cache the results into the {cache_update} table using the 'update_project_data' cache ID. However, since this is not the data about availa... | function update_calculate_project_data($available) {
// Retrieve the projects from cache, if present.
$projects = update_project_cache('update_project_data');
// If $projects is empty, then the cache must be rebuilt.
// Otherwise, return the cached data and skip the rest of the function.
if (!empty($projects)... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bfe366b516 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.install/function/update_update_7001/7.x | In Drupal 7, write the function `update_update_7001()` (file modules/update/update.install) so that it does the following: Recreates cache_update table. | Converts fields that hold serialized variables from text to blob. Removes 'headers' column.
File: modules/update/update.install | function update_update_7001() {
$schema = system_schema_cache_7054();
db_drop_table('cache_update');
db_create_table('cache_update', $schema);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bfec598140 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_mapping_delete/7.x | In Drupal 7, write the function `rdf_mapping_delete($type, $bundle)` (file modules/rdf/rdf.module) so that it does the following: Deletes the mapping for the given bundle from the database. | Parameters:
- $type: The entity type the mapping refers to.
- $bundle: The bundle the mapping refers to.
Returns: Return boolean TRUE if mapping deleted, FALSE if not.
File: modules/rdf/rdf.module | function rdf_mapping_delete($type, $bundle) {
$num_rows = db_delete('rdf_mapping')
->condition('type', $type)
->condition('bundle', $bundle)
->execute();
return (bool) ($num_rows > 0);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-bffdb3c6a8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_menu/7.x | Implement `filter_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu(). | File: modules/filter/filter.module | function filter_menu() {
$items['filter/tips'] = array(
'title' => 'Compose tips',
'page callback' => 'filter_tips_long',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
'file' => 'filter.pages.inc',
);
$items['filter/tips/%filter_format'] = array(
'title' => 'Compose tips',
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c0033cfb7e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_block_info/7.x | Implement `forum_block_info()` in PHP for Drupal 7. Required behavior: Implements hook_block_info(). | File: modules/forum/forum.module | function forum_block_info() {
$blocks['active'] = array(
'info' => t('Active forum topics'),
'cache' => DRUPAL_CACHE_CUSTOM,
'properties' => array('administrative' => TRUE),
);
$blocks['new'] = array(
'info' => t('New forum topics'),
'cache' => DRUPAL_CACHE_CUSTOM,
'properties' => array('a... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c07b10b2cb | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_finished/7.x | In Drupal 7, write the function `install_finished(&$install_state)` (file includes/install.core.inc) so that it does the following: Finishes importing files at end of installation. | Parameters:
- $install_state: An array of information about the current installation state.
Returns: A message informing the user that the installation is complete.
File: includes/install.core.inc | function install_finished(&$install_state) {
drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_distribution_name())), PASS_THROUGH);
$messages = drupal_set_message();
$output = '<p>' . st('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_prof... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c085dd95b0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_install_schema/7.x | In Drupal 7, write the function `drupal_install_schema($module)` (file includes/common.inc) so that it does the following: Creates all tables defined in a module's hook_schema(). | Note: This function does not pass the module's schema through hook_schema_alter(). The module's tables will be created exactly as the module defines them.
Parameters:
- $module: The module for which the tables will be created.
File: includes/common.inc | function drupal_install_schema($module) {
$schema = drupal_get_schema_unprocessed($module);
_drupal_schema_initialize($schema, $module, FALSE);
foreach ($schema as $name => $table) {
db_create_table($name, $table);
}
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c09c604c2c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/timer_stop/7.x | In Drupal 7, write the function `timer_stop($name)` (file includes/bootstrap.inc) so that it does the following: Stops the timer with the specified name. | Parameters:
- $name: The name of the timer.
Returns: A timer array. The array contains the number of times the timer has been started and stopped (count) and the accumulated timer value in ms (time).
File: includes/bootstrap.inc | function timer_stop($name) {
global $timers;
if (isset($timers[$name]['start'])) {
$stop = microtime(TRUE);
$diff = round(($stop - $timers[$name]['start']) * 1000, 2);
if (isset($timers[$name]['time'])) {
$timers[$name]['time'] += $diff;
}
else {
$timers[$name]['time'] = $diff;
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c0a270a31a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_count_unpublished/7.x | Implement `comment_count_unpublished()` in PHP for Drupal 7. Required behavior: Returns a menu title which includes the number of unapproved comments. | File: modules/comment/comment.module | function comment_count_unpublished() {
$count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array(
':status' => COMMENT_NOT_PUBLISHED,
))->fetchField();
return t('Unapproved comments (@count)', array('@count' => $count));
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c0d6aa33a0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_overview_vocabularies/7.x | I need the code for `taxonomy_overview_vocabularies($form)` in Drupal 7 (modules/taxonomy/taxonomy.admin.inc). It must do this: Form builder to list and manage vocabularies. | File: modules/taxonomy/taxonomy.admin.inc | function taxonomy_overview_vocabularies($form) {
$vocabularies = taxonomy_get_vocabularies();
$form['#tree'] = TRUE;
foreach ($vocabularies as $vocabulary) {
$form[$vocabulary->vid]['#vocabulary'] = $vocabulary;
$form[$vocabulary->vid]['name'] = array('#markup' => check_plain($vocabulary->name));
$for... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c0e9429bd5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_widget_properties_alter/7.x | Give me the example code for `hook_field_widget_properties_alter(&$widget, $context)` in Drupal 7. Hook description: Alters the widget properties of a field instance before it gets displayed. | Note that instead of hook_field_widget_properties_alter(), which is called for all fields on all entity types, hook_field_widget_properties_ENTITY_TYPE_alter() may be used to alter widget properties for fields on a specific entity type only.
This hook is called once per field per added or edit entity. If the result of... | function hook_field_widget_properties_alter(&$widget, $context) {
// Change a widget's type according to the time of day.
$field = $context['field'];
if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_foo') {
$time = date('H');
$widget['type'] = $time < 12 ? 'widget_am' : 'widget_pm';... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c0ed0c21a1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/element_validate_integer_positive/7.x | In Drupal 7, write the function `element_validate_integer_positive($element, &$form_state)` (file includes/form.inc) so that it does the following: Form element validation handler for integer elements that must be positive. | File: includes/form.inc | function element_validate_integer_positive($element, &$form_state) {
$value = $element['#value'];
if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) {
form_error($element, t('%name must be a positive integer.', array('%name' => $element['#title'])));
}
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c10e347f7d | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_cron/7.x | Give me the example code for `hook_cron()` in Drupal 7. Hook description: Perform periodic actions. | Modules that require some commands to be executed periodically can implement hook_cron(). The engine will then call the hook whenever a cron run happens, as defined by the administrator. Typical tasks managed by hook_cron() are database maintenance, backups, recalculation of settings or parameters, automated mailing, a... | function hook_cron() {
// Short-running operation example, not using a queue:
// Delete all expired records since the last cron run.
$expires = variable_get('mymodule_cron_last_run', REQUEST_TIME);
db_delete('mymodule_table')
->condition('expires', $expires, '>=')
->execute();
variable_set('mymodule_c... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c11da9f501 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_dom_load/7.x | Implement `filter_dom_load($text)` in PHP for Drupal 7. Required behavior: Parses an HTML snippet and returns it as a DOM object. | This function loads the body part of a partial (X)HTML document and returns a full DOMDocument object that represents this document. You can use filter_dom_serialize() to serialize this DOMDocument back to a XHTML snippet.
Parameters:
- $text: The partial (X)HTML snippet to load. Invalid mark-up will be corrected on i... | function filter_dom_load($text) {
$dom_document = new DOMDocument();
// Ignore warnings during HTML soup loading.
@$dom_document->loadHTML('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c12472dacd | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_ip_blocking_delete/7.x | I need the code for `system_ip_blocking_delete($form, &$form_state, $iid)` in Drupal 7 (modules/system/system.admin.inc). It must do this: IP deletion confirm page. | File: modules/system/system.admin.inc | function system_ip_blocking_delete($form, &$form_state, $iid) {
$form['blocked_ip'] = array(
'#type' => 'value',
'#value' => $iid,
);
return confirm_form($form, t('Are you sure you want to delete %ip?', array('%ip' => $iid['ip'])), 'admin/config/people/ip-blocking', t('This action cannot be undone.'), t('... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c12743e398 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_formatter_prepare_view/7.x | In Drupal 7, show an example implementation for `hook_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays)` (modules/field/field.api.php): Allow formatters to load information for field values being displayed. | This should be used when a formatter needs to load additional information from the database in order to render a field, for example a reference field which displays properties of the referenced entities such as name or type.
This hook is called after the field type's own hook_field_prepare_view().
Unlike most other f... | function hook_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) {
$tids = array();
// Collect every possible term attached to any of the fieldable entities.
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
// Force... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c12da029a4 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_load/7.x | Give me the example code for `hook_field_storage_load($entity_type, $entities, $age, $fields, $options)` in Drupal 7. Hook description: Load field data for a set of entities. | This hook is invoked from field_attach_load() to ask the field storage module to load field data.
Modules implementing this hook should load field values and add them to objects in $entities. Fields with no values should be added as empty arrays.
Parameters:
- $entity_type: The type of entity, such as 'node' or 'user... | function hook_field_storage_load($entity_type, $entities, $age, $fields, $options) {
$load_current = $age == FIELD_LOAD_CURRENT;
foreach ($fields as $field_id => $ids) {
// By the time this hook runs, the relevant field definitions have been
// populated and cached in FieldInfo, so calling field_info_field... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c1338dcc42 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_info/7.x | Implement `image_field_info()` in PHP for Drupal 7. Required behavior: Implements hook_field_info(). | File: modules/image/image.field.inc | function image_field_info() {
return array(
'image' => array(
'label' => t('Image'),
'description' => t('This field stores the ID of an image file as an integer value.'),
'settings' => array(
'uri_scheme' => variable_get('file_default_scheme', 'public'),
'default_image' => 0,
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c182b21d36 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21actions.inc/function/actions_save/7.x | In Drupal 7, write the function `actions_save($function, $type, $params, $label, $aid = NULL)` (file includes/actions.inc) so that it does the following: Saves an action and its user-supplied parameter values to the database. | Parameters:
- $function: The name of the function to be called when this action is performed.
- $type: The type of action, to describe grouping and/or context, e.g., 'node', 'user', 'comment', or 'system'.
- $params: An associative array with parameter names as keys and parameter values as values.
- $label: A user-supp... | function actions_save($function, $type, $params, $label, $aid = NULL) {
// aid is the callback for singleton actions so we need to keep a separate
// table for numeric aids.
if (!$aid) {
$aid = db_next_id();
}
db_merge('actions')
->key(array('aid' => $aid))
->fields(array(
'callback' => $fu... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c18deba558 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/theme_field_multiple_value_form/7.x | In Drupal 7, write the function `theme_field_multiple_value_form($variables)` (file modules/field/field.form.inc) so that it does the following: Returns HTML for an individual form element. | Combine multiple values into a table with drag-n-drop reordering. TODO : convert to a template.
Parameters:
- $variables: An associative array containing: - element: A render element representing the form element.
File: modules/field/field.form.inc | function theme_field_multiple_value_form($variables) {
$element = $variables['element'];
$output = '';
if ($element['#cardinality'] > 1 || $element['#cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
$table_id = drupal_html_id($element['#field_name'] . '_values');
$order_class = $element['#field_name'] . '... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c19c0fa40f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21batch.inc/function/_batch_next_set/7.x | In Drupal 7, write the function `_batch_next_set()` (file includes/batch.inc) so that it does the following: Retrieves the next set in a batch. | If there is a subsequent set in this batch, assign it as the new set to process and execute its form submit handler (if defined), which may add further sets to this batch.
Returns: TRUE if a subsequent set was found in the batch.
File: includes/batch.inc | function _batch_next_set() {
$batch = &batch_get();
if (isset($batch['sets'][$batch['current_set'] + 1])) {
$batch['current_set']++;
$current_set = &_batch_current_set();
if (isset($current_set['form_submit']) && ($function = $current_set['form_submit']) && function_exists($function)) {
// We use ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c1a1d29f57 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21poll%21poll.install/function/poll_update_7003/7.x | In Drupal 7, write the function `poll_update_7003()` (file modules/poll/poll.install) so that it does the following: Change the weight column to normal int. | File: modules/poll/poll.install | function poll_update_7003() {
db_change_field('poll_choice', 'weight', 'weight', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The sort order of this choice among all choices for the same node.',
));
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c1ad401e76 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_delete_file/7.x | Implement `file_field_delete_file($item, $field, $entity_type, $id, $count = 1)` in PHP for Drupal 7. Required behavior: Decrements the usage count for a file and attempts to delete it. | This function only has an effect if the file being deleted is used only by File module.
Parameters:
- $item: The field item that contains a file array.
- $field: The field structure for the operation.
- $entity_type: The type of $entity.
- $id: The entity ID which contains the file being deleted.
- $count: (optional) ... | function file_field_delete_file($item, $field, $entity_type, $id, $count = 1) {
// To prevent the file field from deleting files it doesn't know about, check
// the file reference count. Temporary files can be deleted because they
// are not yet associated with any content at all.
$file = (object) $item;
$fil... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c1b6ae38f0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_role_insert/7.x | In Drupal 7, show an example implementation for `hook_user_role_insert($role)` (modules/user/user.api.php): Respond to creation of a new user role. | Modules implementing this hook can act on the user role object when saved to the database. It's recommended that you implement this hook if your module adds additional data to user roles object. The module should save its custom additions to the database.
Parameters:
- $role: A user role object.
File: modules/user/us... | function hook_user_role_insert($role) {
// Save extra fields provided by the module to user roles.
db_insert('my_module_table')
->fields(array(
'rid' => $role->rid,
'role_description' => $role->description,
))
->execute();
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c1da2ea725 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/url_is_external/7.x | Implement `url_is_external($path)` in PHP for Drupal 7. Required behavior: Returns TRUE if a path is external to Drupal (e.g. http://example.com). | If a path cannot be assessed by Drupal's menu handler, then we must treat it as potentially insecure.
Parameters:
- $path: The internal path or external URL being linked to, such as "node/34" or "http://example.com/foo".
Returns (Boolean): TRUE or FALSE, where TRUE indicates an external path.
File: includes/common.i... | function url_is_external($path) {
$path = (string) $path;
$colonpos = strpos($path, ':');
// Some browsers treat \ as / so normalize to forward slashes.
$path = str_replace('\\', '/', $path);
// If the path starts with 2 slashes then it is always considered an external
// URL without an explicit protocol pa... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c1fd014f99 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21openid%21openid.install/function/openid_update_6000/7.x | Implement `openid_update_6000()` in PHP for Drupal 7. Required behavior: Add a table to store nonces. | File: modules/openid/openid.install | function openid_update_6000() {
$schema['openid_nonce'] = array(
'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
'fields' => array(
'idp_endpoint_uri' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'UR... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c2142b0b92 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_batch_project_get/7.x | I need the code for `update_manager_batch_project_get($project, $url, &$context)` in Drupal 7 (modules/update/update.manager.inc). It must do this: Implements callback_batch_operation(). | Downloads, unpacks, and verifies a project.
This function assumes that the provided URL points to a file archive of some sort. The URL can have any scheme that we have a file stream wrapper to support. The file is downloaded to a local cache.
Parameters:
- $project (string): The short name of the project to download.... | function update_manager_batch_project_get($project, $url, &$context) {
// This is here to show the user that we are in the process of downloading.
if (!isset($context['sandbox']['started'])) {
$context['sandbox']['started'] = TRUE;
$context['message'] = t('Downloading %project', array('%project' => $project... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c22b91711f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.install/function/update_update_7000/7.x | In Drupal 7, write the function `update_update_7000()` (file modules/update/update.install) so that it does the following: Create a queue to store tasks for requests to fetch available update data. | File: modules/update/update.install | function update_update_7000() {
module_load_include('inc', 'system', 'system.queue');
$queue = DrupalQueue::get('update_fetch_tasks');
$queue->createQueue();
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c244b5d28c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_forms/7.x | Implement `dashboard_forms()` in PHP for Drupal 7. Required behavior: Implements hook_forms(). | File: modules/dashboard/dashboard.module | function dashboard_forms() {
// Reroute the dashboard configuration form to the main blocks administration
// form. This allows us to distinguish them by form ID in hook_form_alter().
$forms['dashboard_admin_display_form'] = array(
'callback' => 'block_admin_display_form',
);
return $forms;
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c2629fd5bc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_menu_local_tasks_alter/7.x | In Drupal 7, write the function `blog_menu_local_tasks_alter(&$data, $router_item, $root_path)` (file modules/blog/blog.module) so that it does the following: Implements hook_menu_local_tasks_alter(). | File: modules/blog/blog.module | function blog_menu_local_tasks_alter(&$data, $router_item, $root_path) {
global $user;
// Add action link to 'node/add/blog' on 'blog' page.
if ($root_path == 'blog') {
$item = menu_get_item('node/add/blog');
if ($item['access']) {
$item['title'] = t('Create new blog entry');
$data['actions']... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c26b752e46 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_fast_404/7.x | I need the code for `drupal_fast_404()` in Drupal 7 (includes/bootstrap.inc). It must do this: Returns a simple 404 Not Found page. | If fast 404 pages are enabled, and this is a matching page then print a simple 404 page and exit.
This function is called from drupal_deliver_html_page() at the time when a a normal 404 page is generated, but it can also optionally be called directly from settings.php to prevent a Drupal bootstrap on these pages. See ... | function drupal_fast_404() {
$exclude_paths = variable_get('404_fast_paths_exclude', FALSE);
if ($exclude_paths && !preg_match($exclude_paths, $_GET['q'])) {
$fast_paths = variable_get('404_fast_paths', FALSE);
if ($fast_paths && preg_match($fast_paths, $_GET['q'])) {
drupal_add_http_header('Status', ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c27b6e071a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_node/7.x | Implement `rdf_preprocess_node(&$variables)` in PHP for Drupal 7. Required behavior: Implements MODULE_preprocess_HOOK(). | File: modules/rdf/rdf.module | function rdf_preprocess_node(&$variables) {
// Adds RDFa markup to the node container. The about attribute specifies the
// URI of the resource described within the HTML element, while the @typeof
// attribute indicates its RDF type (e.g., foaf:Document, sioc:Person, and so
// on.)
$variables['attributes_arra... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c28ee9fe1c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_local_action/7.x | Implement `theme_menu_local_action($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a single local action link. | Parameters:
- $variables: An associative array containing: - element: A render element containing: - #link: A menu link array with 'title', 'href', and 'localized_options' keys.
File: includes/menu.inc | function theme_menu_local_action($variables) {
$link = $variables['element']['#link'];
$output = '<li>';
if (isset($link['href'])) {
$output .= l($link['title'], $link['href'], isset($link['localized_options']) ? $link['localized_options'] : array());
}
elseif (!empty($link['localized_options']['html']))... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c29290bb1c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21file.inc/function/file_load/7.x | In Drupal 7, write the function `file_load($fid)` (file includes/file.inc) so that it does the following: Loads a single file object from the database. | Parameters:
- $fid: A file ID.
Returns: An object representing the file, or FALSE if the file was not found.
File: includes/file.inc | function file_load($fid) {
$files = file_load_multiple(array($fid), array());
return reset($files);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c2a000974a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_block_info/7.x | Implement `system_block_info()` in PHP for Drupal 7. Required behavior: Implements hook_block_info(). | File: modules/system/system.module | function system_block_info() {
$blocks['main'] = array(
'info' => t('Main page content'),
// Cached elsewhere.
'cache' => DRUPAL_NO_CACHE,
// Auto-enable in 'content' region by default, which always exists.
// @see system_themes_page(), drupal_render_page()
'status' => 1,
'region' => 'con... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c2b1085a85 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_get_user_timezone/7.x | In Drupal 7, write the function `drupal_get_user_timezone()` (file includes/bootstrap.inc) so that it does the following: Returns the time zone of the current user. | File: includes/bootstrap.inc | function drupal_get_user_timezone() {
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) {
return $user->timezone;
}
else {
// Ignore PHP strict notice if time zone has not yet been set in the php.ini
// configuration.
return variable_get('date_default_... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c2cc0abc45 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_roles/7.x | Implement `user_roles($membersonly = FALSE, $permission = NULL)` in PHP for Drupal 7. Required behavior: Retrieve an array of roles matching specified conditions. | Parameters:
- $membersonly: Set this to TRUE to exclude the 'anonymous' role.
- $permission: A string containing a permission. If set, only roles containing that permission are returned.
Returns: An associative array with the role id as the key and the role name as value.
File: modules/user/user.module | function user_roles($membersonly = FALSE, $permission = NULL) {
$query = db_select('role', 'r');
$query->addTag('translatable');
$query->fields('r', array('rid', 'name'));
$query->orderBy('weight');
$query->orderBy('name');
if (!empty($permission)) {
$query->innerJoin('role_permission', 'p', 'r.rid = p.... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c2f34b34e4 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_theme/7.x | Implement `overlay_theme()` in PHP for Drupal 7. Required behavior: Implements hook_theme(). | File: modules/overlay/overlay.module | function overlay_theme() {
return array(
'overlay' => array(
'render element' => 'page',
'template' => 'overlay',
),
'overlay_disable_message' => array(
'render element' => 'element',
),
);
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c2fcf97a42 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_BASE_FORM_ID_alter/7.x | Give me the example code for `hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id)` in Drupal 7. Hook description: Provide a form-specific alteration for shared ('base') forms. | By default, when drupal_get_form() is called, Drupal looks for a function with the same name as the form ID, and uses that function to build the form. In contrast, base forms allow multiple form IDs to be mapped to a single base (also called 'factory') form function.
Modules can implement hook_form_BASE_FORM_ID_alter(... | function hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id) {
// Modification for the form with the given BASE_FORM_ID goes here. For
// example, if BASE_FORM_ID is "node_form", this code would run on every
// node form, regardless of node type.
// Add a checkbox to the node form about agreeing to te... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c31f0b5e78 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_get_term_by_name/7.x | I need the code for `taxonomy_get_term_by_name($name, $vocabulary = NULL)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Try to map a string to an existing term, as for glossary use. | Provides a case-insensitive and trimmed mapping, to maximize the likelihood of a successful match.
Parameters:
- $name: Name of the term to search for.
- $vocabulary: (optional) Vocabulary machine name to limit the search. Defaults to NULL.
Returns: An array of matching term objects.
File: modules/taxonomy/taxonomy.... | function taxonomy_get_term_by_name($name, $vocabulary = NULL) {
$conditions = array('name' => trim($name));
if (isset($vocabulary)) {
$vocabularies = taxonomy_vocabulary_get_names();
if (isset($vocabularies[$vocabulary])) {
$conditions['vid'] = $vocabularies[$vocabulary]->vid;
}
else {
/... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c32139e654 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/_file_generic_settings_max_filesize/7.x | In Drupal 7, write the function `_file_generic_settings_max_filesize($element, &$form_state)` (file modules/file/file.field.inc) so that it does the following: Element validate callback for the maximum upload size field. | Ensure a size that can be parsed by parse_size() has been entered.
File: modules/file/file.field.inc | function _file_generic_settings_max_filesize($element, &$form_state) {
if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) {
form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (ki... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c331d38484 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_flush_caches/7.x | I need the code for `system_flush_caches()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_flush_caches(). | File: modules/system/system.module | function system_flush_caches() {
// Rebuild list of date formats.
system_date_formats_rebuild();
// Reset the menu static caches.
menu_reset_static_cache();
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c340c625cd | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_menu/7.x | In Drupal 7, write the function `profile_menu()` (file modules/profile/profile.module) so that it does the following: Implements hook_menu(). | File: modules/profile/profile.module | function profile_menu() {
$items['profile'] = array(
'title' => 'User list',
'page callback' => 'profile_browse',
'access arguments' => array('access user profiles'),
'file' => 'profile.pages.inc',
'type' => MENU_SUGGESTED_ITEM,
);
$items['admin/config/people/profile'] = array(
'title' => ... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c353c09b3a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_page_alter/7.x | Implement `overlay_page_alter(&$page)` in PHP for Drupal 7. Required behavior: Implements hook_page_alter(). | File: modules/overlay/overlay.module | function overlay_page_alter(&$page) {
// If we are limiting rendering to a subset of page regions, deny access to
// all other regions so that they will not be processed.
if ($regions_to_render = overlay_get_regions_to_render()) {
$skipped_regions = array_diff(element_children($page), $regions_to_render);
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c357dbc8bd | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/dblog_theme/7.x | I need the code for `dblog_theme()` in Drupal 7 (modules/dblog/dblog.module). It must do this: Implements hook_theme(). | File: modules/dblog/dblog.module | function dblog_theme() {
return array(
'dblog_message' => array(
'variables' => array('event' => NULL, 'link' => FALSE),
'file' => 'dblog.admin.inc',
),
);
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c376b7c0a1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21contextual%21contextual.api.php/function/hook_contextual_links_view_alter/7.x | In Drupal 7, show an example implementation for `hook_contextual_links_view_alter(&$element, $items)` (modules/contextual/contextual.api.php): Alter a contextual links element before it is rendered. | This hook is invoked by contextual_pre_render_links(). The renderable array of #type 'contextual_links', containing the entire contextual links data that is passed in by reference. Further links may be added or existing links can be altered.
Parameters:
- $element: A renderable array representing the contextual links.... | function hook_contextual_links_view_alter(&$element, $items) {
// Add another class to all contextual link lists to facilitate custom
// styling.
$element['#attributes']['class'][] = 'custom-class';
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c378352953 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_field_storage_pre_update/7.x | In Drupal 7, write the function `forum_field_storage_pre_update($entity_type, $entity, &$skip_fields)` (file modules/forum/forum.module) so that it does the following: Implements hook_field_storage_pre_update(). | File: modules/forum/forum.module | function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
$first_call = &drupal_static(__FUNCTION__, array());
if ($entity_type == 'node' && _forum_node_check_node_type($entity)) {
// If the node is published, update the forum index.
if ($entity->status) {
// We don't maintain... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c38754538f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_trigger_error_with_delayed_logging/7.x | Implement `_drupal_trigger_error_with_delayed_logging($error_msg, $error_type = E_USER_NOTICE)` in PHP for Drupal 7. Required behavior: Invokes trigger_error() with logging delayed until the end of the request. | This is an alternative to PHP's trigger_error() function which can be used during low-level Drupal core operations that need to avoid being interrupted by a watchdog() call.
Normally, Drupal's error handler calls watchdog() in response to a trigger_error() call. However, this invokes hook_watchdog() which can run arbi... | function _drupal_trigger_error_with_delayed_logging($error_msg, $error_type = E_USER_NOTICE) {
$delay_logging = &drupal_static(__FUNCTION__, FALSE);
$delay_logging = TRUE;
trigger_error($error_msg, $error_type);
$delay_logging = FALSE;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c39657f646 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/_node_mass_update_helper/7.x | I need the code for `_node_mass_update_helper($nid, $updates)` in Drupal 7 (modules/node/node.admin.inc). It must do this: Updates individual nodes when fewer than 10 are queued. | Parameters:
- $nid: ID of node to update.
- $updates: Associative array of updates.
Returns (object): An updated node object.
File: modules/node/node.admin.inc | function _node_mass_update_helper($nid, $updates) {
$node = node_load($nid, NULL, TRUE);
// For efficiency manually save the original node before applying any changes.
$node->original = clone $node;
foreach ($updates as $name => $value) {
$node->$name = $value;
}
node_save($node);
return $node;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c39f91671b | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_js_alter/7.x | In Drupal 7, show an example implementation for `hook_js_alter(&$javascript)` (modules/system/system.api.php): Perform necessary alterations to the JavaScript before it is presented on the page. | Parameters:
- $javascript: An array of all JavaScript being presented on the page.
File: modules/system/system.api.php | function hook_js_alter(&$javascript) {
// Swap out jQuery to use an updated version of the library.
$javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c3bd93e1da | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_user_login/7.x | In Drupal 7, write the function `openid_user_login(&$edit, $account)` (file modules/openid/openid.module) so that it does the following: Implements hook_user_login(). | Save openid_identifier to visitor cookie.
File: modules/openid/openid.module | function openid_user_login(&$edit, $account) {
if (isset($_SESSION['openid'])) {
// The user has logged in via OpenID.
user_cookie_save(array_intersect_key($_SESSION['openid']['user_login_values'], array_flip(array('openid_identifier'))));
unset($_SESSION['openid']);
}
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c3c12918a5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_xrds_parse/7.x | In Drupal 7, write the function `_openid_xrds_parse($raw_xml)` (file modules/openid/openid.inc) so that it does the following: Parse an XRDS document. | Parameters:
- $raw_xml: A string containing the XRDS document.
Returns: An array of service entries.
File: modules/openid/openid.inc | function _openid_xrds_parse($raw_xml) {
$services = array();
// For PHP version >= 5.2.11, we can use this function to protect against
// malicious doctype declarations and other unexpected entity loading.
// However, we will not rely on it, and reject any XML with a DOCTYPE.
// libxml_disable_entity_loader(... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c3c85faed3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_render_template/7.x | Implement `theme_render_template($template_file, $variables)` in PHP for Drupal 7. Required behavior: Renders a system default template, which is essentially a PHP template. | Parameters:
- $template_file: The filename of the template to render.
- $variables: A keyed array of variables that will appear in the output.
Returns: The output generated by the template.
File: includes/theme.inc | function theme_render_template($template_file, $variables) {
// Extract the variables to a local namespace
extract($variables, EXTR_SKIP);
// Start output buffering
ob_start();
// Include the template file
include DRUPAL_ROOT . '/' . $template_file;
// End buffering and return its contents
return ob_... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c3cc53b3f3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_external_login_register/7.x | I need the code for `user_external_login_register($name, $module)` in Drupal 7 (modules/user/user.module). It must do this: Helper function for authentication modules. Either logs in or registers the current user, based on username. Either way, the global $user object is populated and login tasks are performed. | File: modules/user/user.module | function user_external_login_register($name, $module) {
$account = user_external_load($name);
if (!$account) {
// Register this new user.
$userinfo = array(
'name' => $name,
'pass' => user_password(),
'init' => $name,
'status' => 1,
'access' => REQUEST_TIME
);
$account ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c3ccf25d71 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21unicode.inc/function/drupal_convert_to_utf8/7.x | I need the code for `drupal_convert_to_utf8($data, $encoding)` in Drupal 7 (includes/unicode.inc). It must do this: Converts data to UTF-8. | Requires the iconv, GNU recode or mbstring PHP extension.
Parameters:
- $data: The data to be converted.
- $encoding: The encoding that the data is in.
Returns: Converted data or FALSE.
File: includes/unicode.inc | function drupal_convert_to_utf8($data, $encoding) {
if (function_exists('iconv')) {
$out = @iconv($encoding, 'utf-8', $data);
}
elseif (function_exists('mb_convert_encoding')) {
$out = @mb_convert_encoding($data, 'utf-8', $encoding);
}
elseif (function_exists('recode_string')) {
$out = @recode_str... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c3dfbf4e99 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_effect_delete/7.x | Implement `image_effect_delete($effect)` in PHP for Drupal 7. Required behavior: Deletes an image effect. | Parameters:
- $effect: An image effect array.
File: modules/image/image.module | function image_effect_delete($effect) {
db_delete('image_effects')->condition('ieid', $effect['ieid'])->execute();
$style = image_style_load(NULL, $effect['isid']);
image_style_flush($style);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c41b767fb8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_widget_form/7.x | In Drupal 7, write the function `number_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)` (file modules/field/modules/number/number.module) so that it does the following: Implements hook_field_widget_form(). | File: modules/field/modules/number/number.module | function number_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$value = isset($items[$delta]['value']) ? $items[$delta]['value'] : '';
// Substitute the decimal separator.
if ($field['type'] == 'number_decimal' || $field['type'] == 'number_float') {
$value = ... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c423bb12de | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21session.inc/function/drupal_save_session/7.x | I need the code for `drupal_save_session($status = NULL)` in Drupal 7 (includes/session.inc). It must do this: Determines whether to save session data of the current request. | This function allows the caller to temporarily disable writing of session data, should the request end while performing potentially dangerous operations, such as manipulating the global $user object. See http://drupal.org/node/218104 for usage.
Parameters:
- $status: Disables writing of session data when FALSE, (re-)e... | function drupal_save_session($status = NULL) {
// PHP session ID, session, and cookie handling happens in the global scope.
// This value has to persist across calls to drupal_static_reset(), since a
// potentially wrong or disallowed session would be written otherwise.
static $save_session = TRUE;
if (isset(... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c4264f0621 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_sort_featured/7.x | I need the code for `announcements_feed_sort_featured($a, $b)` in Drupal 7 (modules/announcements_feed/announcements_feed.inc). It must do this: Sort the elements of announcements_feed by values in comparison function. | File: modules/announcements_feed/announcements_feed.inc | function announcements_feed_sort_featured($a, $b) {
$a_value = (int) $a['_drupalorg']['featured'];
$b_value = (int) $b['_drupalorg']['featured'];
if ($a_value == $b_value) {
return 0;
}
return ($a_value < $b_value) ? -1 : 1;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c42d402536 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_update_7001/7.x | In Drupal 7, write the function `comment_update_7001()` (file modules/comment/comment.install) so that it does the following: Change comment status from published being 0 to being 1 | File: modules/comment/comment.install | function comment_update_7001() {
// Choose a temporary status value different from the existing status values.
$tmp_status = db_query('SELECT MAX(status) FROM {comments}')->fetchField() + 1;
$changes = array(
0 => $tmp_status,
1 => 0,
$tmp_status => 1,
);
foreach ($changes as $old => $new) {
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c43973f34d | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21trigger%21trigger.install/function/trigger_update_7000/7.x | Implement `trigger_update_7000()` in PHP for Drupal 7. Required behavior: Alter the "hook" field and drop the "op field" of {trigger_assignments}. | Increase the length of the "hook" field to 78 characters and adds operation names to the hook names, and drops the "op" field.
File: modules/trigger/trigger.install | function trigger_update_7000() {
db_drop_primary_key('trigger_assignments');
db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.'));
$r... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c45b8ad455 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_node_prepare/7.x | Implement `translation_node_prepare($node)` in PHP for Drupal 7. Required behavior: Implements hook_node_prepare(). | File: modules/translation/translation.module | function translation_node_prepare($node) {
// Only act if we are dealing with a content type supporting translations.
if (translation_supported_type($node->type) &&
// And it's a new node.
empty($node->nid) &&
// And the user has permission to translate content.
user_access('translate content') &&
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c462c8986c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render_collect_attached/7.x | In Drupal 7, write the function `drupal_render_collect_attached($elements, $return = FALSE)` (file includes/common.inc) so that it does the following: Collects #attached for an element and its children into a single array. | When caching elements, it is necessary to collect all libraries, JavaScript and CSS into a single array, from both the element itself and all child elements. This allows drupal_render() to add these back to the page when the element is returned from cache.
Parameters:
- $elements: The element to collect #attached from... | function drupal_render_collect_attached($elements, $return = FALSE) {
$attached = &drupal_static(__FUNCTION__, array());
// Collect all #attached for this element.
if (isset($elements['#attached'])) {
foreach ($elements['#attached'] as $key => $value) {
if (!isset($attached[$key])) {
$attached[... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c4649d8dc3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_forms/7.x | In Drupal 7, show an example implementation for `hook_forms($form_id, $args)` (modules/system/system.api.php): Map form_ids to form builder functions. | By default, when drupal_get_form() is called, the system will look for a function with the same name as the form ID, and use that function to build the form. If no such function is found, Drupal calls this hook. Modules implementing this hook can then provide their own instructions for mapping form IDs to constructor f... | function hook_forms($form_id, $args) {
// Simply reroute the (non-existing) $form_id 'mymodule_first_form' to
// 'mymodule_main_form'.
$forms['mymodule_first_form'] = array(
'callback' => 'mymodule_main_form',
);
// Reroute the $form_id and prepend an additional argument that gets passed to
// the 'mym... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-c48c604945 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_query_join_entity/7.x | In Drupal 7, write the function `_field_sql_storage_query_join_entity(SelectQuery $select_query, $entity_type, $field_base_table)` (file modules/field/modules/field_sql_storage/field_sql_storage.module) so that it does the following: Adds the base entity table to a field query object. | Parameters:
- $select_query (SelectQuery): A SelectQuery containing at least one table as specified by _field_sql_storage_tablename().
- $entity_type: The entity type for which the base table should be joined.
- $field_base_table: Name of a table in $select_query. As only INNER JOINs are used, it does not matter which.... | function _field_sql_storage_query_join_entity(SelectQuery $select_query, $entity_type, $field_base_table) {
$entity_info = entity_get_info($entity_type);
$entity_base_table = $entity_info['base table'];
$entity_field = $entity_info['entity keys']['id'];
$select_query->join($entity_base_table, $entity_base_table... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c4be321d44 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_prepare/7.x | In Drupal 7, write the function `book_node_prepare($node)` (file modules/book/book.module) so that it does the following: Implements hook_node_prepare(). | File: modules/book/book.module | function book_node_prepare($node) {
// Prepare defaults for the add/edit form.
if (empty($node->book) && (user_access('add content to books') || user_access('administer book outlines'))) {
$node->book = array();
if (empty($node->nid) && isset($_GET['parent']) && is_numeric($_GET['parent'])) {
// Hand... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c4da14bf40 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_requirements/7.x | I need the code for `image_requirements($phase)` in Drupal 7 (modules/image/image.install). It must do this: Implements hook_requirements() to check the PHP GD Library. | Parameters:
- $phase
File: modules/image/image.install | function image_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// Check for the PHP GD library.
if (function_exists('imagegd2')) {
$info = gd_info();
$requirements['image_gd'] = array(
'value' => $info['GD Version'],
);
// Check for filter and rot... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c4e7ee8287 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21profile%21profile.admin.inc/function/profile_field_form/7.x | I need the code for `profile_field_form($form, &$form_state, $arg = NULL)` in Drupal 7 (modules/profile/profile.admin.inc). It must do this: Menu callback: Generate a form to add/edit a user profile field. | File: modules/profile/profile.admin.inc | function profile_field_form($form, &$form_state, $arg = NULL) {
if (arg(4) == 'edit') {
if (is_numeric($arg)) {
$fid = $arg;
$edit = db_query('SELECT * FROM {profile_field} WHERE fid = :fid', array('fid' => $fid))->fetchAssoc();
if (!$edit) {
drupal_not_found();
return;
}... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c4f5252a6e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translation_filters/7.x | In Drupal 7, write the function `locale_translation_filters()` (file modules/locale/locale.admin.inc) so that it does the following: List locale translation filters that can be applied. | File: modules/locale/locale.admin.inc | function locale_translation_filters() {
$filters = array();
// Get all languages, except English
drupal_static_reset('language_list');
$languages = locale_language_list('name');
unset($languages['en']);
$filters['string'] = array(
'title' => t('String contains'),
'description' => t('Leave blank to... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c5203a7543 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_run_tasks/7.x | Implement `install_run_tasks(&$install_state)` in PHP for Drupal 7. Required behavior: Runs all tasks for the current installation request. | In the case of an interactive installation, all tasks will be attempted until one is reached that has output which needs to be displayed to the user, or until a page redirect is required. Otherwise, tasks will be attempted until the installation is finished.
Parameters:
- $install_state: An array of information about ... | function install_run_tasks(&$install_state) {
do {
// Obtain a list of tasks to perform. The list of tasks itself can be
// dynamic (e.g., some might be defined by the installation profile,
// which is not necessarily known until the earlier tasks have run),
// so we regenerate the remaining tasks bas... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c52b72fb66 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21update.inc/function/update_get_d6_session_name/7.x | In Drupal 7, write the function `update_get_d6_session_name()` (file includes/update.inc) so that it does the following: Constructs a session name compatible with a D6 environment. | Returns: D6-compatible session name string.
File: includes/update.inc | function update_get_d6_session_name() {
global $base_url, $cookie_domain;
$cookie_secure = ini_get('session.cookie_secure');
// If a custom cookie domain is set in settings.php, that variable forms
// the basis of the session name. Re-compute the D7 hashing method to find
// out if $cookie_domain was used as... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c53f5168eb | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_widget_error/7.x | I need the code for `text_field_widget_error($element, $error, $form, &$form_state)` in Drupal 7 (modules/field/modules/text/text.module). It must do this: Implements hook_field_widget_error(). | File: modules/field/modules/text/text.module | function text_field_widget_error($element, $error, $form, &$form_state) {
switch ($error['error']) {
case 'text_summary_max_length':
$error_element = $element[$element['#columns'][1]];
break;
default:
$error_element = $element[$element['#columns'][0]];
break;
}
form_error($error_... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c560d46552 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_submit/7.x | In Drupal 7, write the function `field_attach_submit($entity_type, $entity, $form, &$form_state, $options = array())` (file modules/field/field.attach.inc) so that it does the following: Perform necessary operations on field data submitted by a form. | Currently, this accounts for drag-and-drop reordering of field values, and filtering of empty values.
Parameters:
- $entity_type: The type of $entity; e.g. 'node' or 'user'.
- $entity: The entity being submitted. The 'bundle', 'id' and (if applicable) 'revision' keys should be present. The actual field values will be ... | function field_attach_submit($entity_type, $entity, $form, &$form_state, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();
// Extract field values from submitted values.
_field_invoke_default('ext... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c56c51831f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_container/7.x | Implement `theme_container($variables)` in PHP for Drupal 7. Required behavior: Returns HTML to wrap child elements in a container. | Used for grouped form items. Can also be used as a theme wrapper for any renderable element, to surround it with a <div> and add attributes such as classes or an HTML ID.
See the @link forms_api_reference.html Form API reference @endlink for more information on the #theme_wrappers render array property.
Parameters:
-... | function theme_container($variables) {
$element = $variables['element'];
// Ensure #attributes is set.
$element += array('#attributes' => array());
// Special handling for form elements.
if (isset($element['#array_parents'])) {
// Assign an html ID.
if (!isset($element['#attributes']['id'])) {
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c5844f4558 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_edit/7.x | In Drupal 7, write the function `book_admin_edit($form, $form_state, $node)` (file modules/book/book.admin.inc) so that it does the following: Form constructor for administering a single book's hierarchy. | Parameters:
- $node: The node of the top-level page in the book.
File: modules/book/book.admin.inc | function book_admin_edit($form, $form_state, $node) {
drupal_set_title($node->title);
$form['#node'] = $node;
_book_admin_table($node, $form);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save book pages'),
);
return $form;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c588a142ae | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_managed_file_validate/7.x | Implement `file_managed_file_validate(&$element, &$form_state)` in PHP for Drupal 7. Required behavior: An #element_validate callback for the managed_file element. | File: modules/file/file.module | function file_managed_file_validate(&$element, &$form_state) {
// If referencing an existing file, only allow if there are existing
// references. This prevents unmanaged files from being deleted if this
// item were to be deleted.
$clicked_button = end($form_state['triggering_element']['#parents']);
if ($cli... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-c58ae0794b | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_dependencies/7.x | I need the code for `forum_update_dependencies()` in Drupal 7 (modules/forum/forum.install). It must do this: Implements hook_update_dependencies(). | File: modules/forum/forum.install | function forum_update_dependencies() {
$dependencies['forum'][7003] = array(
// Forum update 7003 uses field API update functions, so must run after
// Field API has been enabled.
'system' => 7020,
// Forum update 7003 relies on updated taxonomy module schema. Ensure it
// runs after all taxonomy ... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-c5ba81f6e8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_field_update_forbid/7.x | I need the code for `list_field_update_forbid($field, $prior_field, $has_data)` in Drupal 7 (modules/field/modules/list/list.module). It must do this: Implements hook_field_update_forbid(). | File: modules/field/modules/list/list.module | function list_field_update_forbid($field, $prior_field, $has_data) {
if ($field['module'] == 'list' && $has_data) {
// Forbid any update that removes allowed values with actual data.
$lost_keys = array_diff(array_keys($prior_field['settings']['allowed_values']), array_keys($field['settings']['allowed_values']... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.