Dataset Viewer
Auto-converted to Parquet Duplicate
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-000fdb7f8a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_7011/7.x
I need the code for `forum_update_7011()` in Drupal 7 (modules/forum/forum.install). It must do this: Update {forum_index} so that only published nodes are indexed.
File: modules/forum/forum.install
function forum_update_7011() { $select = db_select('node', 'n') ->fields('n', array('nid')) ->condition('status', 0 ); db_delete('forum_index') ->condition('nid', $select, 'IN') ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-002fcc3b1e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_modules_enabled/7.x
In Drupal 7, write the function `comment_modules_enabled($modules)` (file modules/comment/comment.install) so that it does the following: Implements hook_modules_enabled().
Creates comment body fields for node types existing before the comment module is enabled. We use hook_modules_enabled() rather than hook_enable() so we can react to node types of existing modules, and those of modules being enabled both before and after comment module in the loop of module_enable(). There is a separat...
function comment_modules_enabled($modules) { // Only react if comment module is one of the modules being enabled. // hook_node_type_insert() is used to create body fields while the comment // module is enabled. if (in_array('comment', $modules)) { // Ensure that the list of node types reflects newly enabled...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-003a489bce
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_formatter_settings_form/7.x
In Drupal 7, write the function `number_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state)` (file modules/field/modules/number/number.module) so that it does the following: Implements hook_field_formatter_settings_form().
File: modules/field/modules/number/number.module
function number_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { $display = $instance['display'][$view_mode]; $settings = $display['settings']; $element = array(); if ($display['type'] == 'number_decimal' || $display['type'] == 'number_integer') { $options = array( ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-00460d0541
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_menu/7.x
Implement `announcements_feed_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu().
File: modules/announcements_feed/announcements_feed.module
function announcements_feed_menu() { $items['admin/announcements_feed'] = array( 'title' => 'Announcements', 'description' => 'Announcements and updates posted by the drupal.org community.', 'page callback' => 'announcements_feed_get_announcements', 'access arguments' => array('access announcements'),...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-0074d8bf9a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_form_alter/7.x
In Drupal 7, write the function `locale_form_alter(&$form, &$form_state, $form_id)` (file modules/locale/locale.module) so that it does the following: Implements hook_form_alter().
Adds language fields to user forms. File: modules/locale/locale.module
function locale_form_alter(&$form, &$form_state, $form_id) { // Only alter user forms if there is more than one language. if (drupal_multilingual()) { // Display language selector when either creating a user on the admin // interface or editing a user account. if ($form_id == 'user_register_form' || ($f...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-007c0e05e4
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_pre_render_fieldset/7.x
I need the code for `form_pre_render_fieldset($element)` in Drupal 7 (includes/form.inc). It must do this: Adds members of this group as actual elements for rendering.
Parameters: - $element: An associative array containing the properties and children of the fieldset. Returns: The modified element with all group members. File: includes/form.inc
function form_pre_render_fieldset($element) { // Fieldsets may be rendered outside of a Form API context. if (!isset($element['#parents']) || !isset($element['#groups'])) { return $element; } // Inject group member elements belonging to this group. $parents = implode('][', $element['#parents']); $childr...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0082a95e0b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_ranking/7.x
Implement `node_ranking()` in PHP for Drupal 7. Required behavior: Implements hook_ranking().
File: modules/node/node.module
function node_ranking() { // Create the ranking array and add the basic ranking options. $ranking = array( 'relevance' => array( 'title' => t('Keyword relevance'), // Average relevance values hover around 0.15 'score' => 'i.relevance', ), 'sticky' => array( 'title' => t('Content ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-009e8dd8e9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_page_view/7.x
I need the code for `node_page_view($node)` in Drupal 7 (modules/node/node.module). It must do this: Menu callback: Displays a single node.
Parameters: - $node: The node object. Returns: A page array suitable for use by drupal_render(). File: modules/node/node.module
function node_page_view($node) { // If there is a menu link to this node, the link becomes the last part // of the active trail, and the link name becomes the page title. // Thus, we must explicitly set the page title to be the node title. drupal_set_title($node->title); $uri = entity_uri('node', $node); //...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-00b1d78c6b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_block_configure/7.x
Implement `statistics_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().
File: modules/statistics/statistics.module
function statistics_block_configure($delta = '') { // Popular content block settings $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40)); $form['statistics_block_top_day_num'] = array('#type' => 'select', '#title' => t("Number of day's top views to d...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-00b53eaf51
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_translate_seek_query/7.x
In Drupal 7, write the function `_locale_translate_seek_query()` (file includes/locale.inc) so that it does the following: Build array out of search criteria specified in request variables
File: includes/locale.inc
function _locale_translate_seek_query() { $query = &drupal_static(__FUNCTION__); if (!isset($query)) { $query = array(); $fields = array('string', 'language', 'translation', 'group'); foreach ($fields as $field) { if (isset($_SESSION['locale_translation_filter'][$field])) { $query[$field] ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-00c76000f2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/template_preprocess_forums/7.x
I need the code for `template_preprocess_forums(&$variables)` in Drupal 7 (modules/forum/forum.module). It must do this: Preprocesses variables for forums.tpl.php.
Parameters: - $variables: An array containing the following elements: - forums: An array of all forum objects to display for the given taxonomy term ID. If tid = 0 then all the top-level forums are displayed. - topics: An array of all the topics in the current forum. - parents: An array of taxonomy term objects that ar...
function template_preprocess_forums(&$variables) { global $user; $vid = variable_get('forum_nav_vocabulary', 0); $vocabulary = taxonomy_vocabulary_load($vid); $title = !empty($vocabulary->name) ? $vocabulary->name : ''; // Breadcrumb navigation: $breadcrumb[] = l(t('Home'), NULL); if ($variables['tid'])...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-00d3568baf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7020/7.x
Implement `system_update_7020()` in PHP for Drupal 7. Required behavior: Enable field and field_ui modules.
File: modules/system/system.install
function system_update_7020() { $module_list = array('field_sql_storage', 'field', 'field_ui'); module_enable($module_list, FALSE); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0101b18898
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_block_view/7.x
I need the code for `profile_block_view($delta = '')` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_block_view().
File: modules/profile/profile.module
function profile_block_view($delta = '') { if (user_access('access user profiles')) { $output = ''; if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) { $node = node_load(arg(1)); $account = user_load($node->uid); if ($use_fields = variable_get('profile_block_author_fields', arra...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-010b545374
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_page_additions/7.x
I need the code for `comment_node_page_additions($node)` in Drupal 7 (modules/comment/comment.module). It must do this: Build the comment-related elements for node detail pages.
Parameters: - $node: A node object. File: modules/comment/comment.module
function comment_node_page_additions($node) { $additions = array(); // Only attempt to render comments if the node has visible comments. // Unpublished comments are not included in $node->comment_count, so show // comments unconditionally if the user is an administrator. if (($node->comment_count && user_acc...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0118bdfe6b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/_translation_tab_access/7.x
Implement `_translation_tab_access($node)` in PHP for Drupal 7. Required behavior: Access callback: Checks that the user has permission to 'translate content'.
Only displays the translation tab for nodes that are not language-neutral of types that have translation enabled. Parameters: - $node: A node object. Returns: TRUE if the translation tab should be displayed, FALSE otherwise. File: modules/translation/translation.module
function _translation_tab_access($node) { if (entity_language('node', $node) != LANGUAGE_NONE && translation_supported_type($node->type) && node_access('view', $node)) { return user_access('translate content'); } return FALSE; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-013ab038e0
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess/7.x
In Drupal 7, write the function `template_preprocess(&$variables, $hook)` (file includes/theme.inc) so that it does the following: Adds a default set of helper variables for variable processors and templates.
This function is called for theme hooks implemented as templates only, not for theme hooks implemented as functions. This preprocess function is the first in the sequence of preprocessing and processing functions that is called when preparing variables for a template. See theme() for more details about the full sequenc...
function template_preprocess(&$variables, $hook) { global $user; static $count = array(); // Track run count for each hook to provide zebra striping. See // "template_preprocess_block()" which provides the same feature specific to // blocks. $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-014c21bd6b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_batch_import/7.x
I need the code for `_locale_batch_import($filepath, &$context)` in Drupal 7 (includes/locale.inc). It must do this: Implements callback_batch_operation().
Perform interface translation import as a batch step. Parameters: - $filepath: Path to a file to import. - $results: Contains a list of files imported. File: includes/locale.inc
function _locale_batch_import($filepath, &$context) { // The filename is either {langcode}.po or {prefix}.{langcode}.po, so // we can extract the language code to use for the import from the end. if (preg_match('!(/|\.)([^\./]+)\.po$!', $filepath, $langcode)) { $file = (object) array('filename' => drupal_base...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-015fd2cfd5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_managed_file_pre_render/7.x
In Drupal 7, write the function `file_managed_file_pre_render($element)` (file modules/file/file.module) so that it does the following: #pre_render callback to hide display of the upload or remove controls.
Upload controls are hidden when a file is already uploaded. Remove controls are hidden when there is no file attached. Controls are hidden here instead of in file_managed_file_process(), because #access for these buttons depends on the managed_file element's #value. See the documentation of form_builder() for more deta...
function file_managed_file_pre_render($element) { // If we already have a file, we don't want to show the upload controls. if (!empty($element['#value']['fid'])) { $element['upload']['#access'] = FALSE; $element['upload_button']['#access'] = FALSE; } // If we don't already have a file, there is nothing ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-01660485e5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_action_info/7.x
Implement `comment_action_info()` in PHP for Drupal 7. Required behavior: Implements hook_action_info().
File: modules/comment/comment.module
function comment_action_info() { return array( 'comment_publish_action' => array( 'label' => t('Publish comment'), 'type' => 'comment', 'configurable' => FALSE, 'behavior' => array('changes_property'), 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'), ),...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-01813c9222
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/drupal_find_theme_functions/7.x
I need the code for `drupal_find_theme_functions($cache, $prefixes)` in Drupal 7 (includes/theme.inc). It must do this: Allows themes and/or theme engines to discover overridden theme functions.
Parameters: - $cache: The existing cache of theme hooks to test against. - $prefixes: An array of prefixes to test, in reverse order of importance. Returns: $implementations The functions found, suitable for returning from hook_theme; File: includes/theme.inc
function drupal_find_theme_functions($cache, $prefixes) { $implementations = array(); $functions = get_defined_functions(); $theme_functions = preg_grep('/^(' . implode(')|(', $prefixes) . ')_/', $functions['user']); foreach ($cache as $hook => $info) { foreach ($prefixes as $prefix) { // Find theme ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0193916d78
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_schema_unprocessed/7.x
Implement `drupal_get_schema_unprocessed($module, $table = NULL)` in PHP for Drupal 7. Required behavior: Returns the unprocessed and unaltered version of a module's schema.
Use this function only if you explicitly need the original specification of a schema, as it was defined in a module's hook_schema(). No additional default values will be set, hook_schema_alter() is not invoked and these unprocessed definitions won't be cached. To retrieve the schema after hook_schema_alter() has been i...
function drupal_get_schema_unprocessed($module, $table = NULL) { // Load the .install file to get hook_schema. module_load_install($module); $schema = module_invoke($module, 'schema'); if (isset($table) && isset($schema[$table])) { return $schema[$table]; } elseif (!empty($schema)) { return $schema...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-01afc8d830
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21password.inc/function/_password_generate_salt/7.x
In Drupal 7, write the function `_password_generate_salt($count_log2)` (file includes/password.inc) so that it does the following: Generates a random base 64-encoded salt prefixed with settings for the hash.
Proper use of salts may defeat a number of attacks, including: - The ability to try candidate passwords against multiple hashes at once. - The ability to use pre-hashed lists of candidate passwords. - The ability to determine whether two users have the same (or different) password without actually having to guess...
function _password_generate_salt($count_log2) { $output = '$S$'; // Ensure that $count_log2 is within set bounds. $count_log2 = _password_enforce_log2_boundaries($count_log2); // We encode the final log2 iteration count in base 64. $itoa64 = _password_itoa64(); $output .= $itoa64[$count_log2]; // 6 bytes ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-01c0f248cb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_form/7.x
Give me the example code for `hook_form($node, &$form_state)` in Drupal 7. Hook description: Display a node editing form.
This is a node-type-specific hook, which is invoked only for the node type being affected. See Parameters: - $node: The node being added or edited. - $form_state: The form state array. Returns: An array containing the title and any custom form elements to be displayed in the node editing form. File: modules/node/nod...
function hook_form($node, &$form_state) { $type = node_type_get_type($node); $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => !empty($node->title) ? $node->title : '', '#required' => TRUE, '#weight' => -5 ); $form['field1'] = arra...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-01d61f53fc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_overview_form/7.x
I need the code for `menu_overview_form($form, &$form_state, $menu)` in Drupal 7 (modules/menu/menu.admin.inc). It must do this: Form for editing an entire menu tree at once.
Shows for one menu the menu links accessible to the current user and relevant operations. File: modules/menu/menu.admin.inc
function menu_overview_form($form, &$form_state, $menu) { global $menu_admin; $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/menu.css'); $sql = " SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback,...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-01edf67b12
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_item/7.x
I need the code for `menu_get_item($path = NULL, $router_item = NULL)` in Drupal 7 (includes/menu.inc). It must do this: Gets a router item.
Parameters: - $path: The path; for example, 'node/5'. The function will find the corresponding node/% item and return that. Defaults to the current path. - $router_item: Internal use only. Returns: The router item or, if an error occurs in _menu_translate(), FALSE. A router item is an associative array corresponding t...
function menu_get_item($path = NULL, $router_item = NULL) { $router_items = &drupal_static(__FUNCTION__); if (!isset($path)) { $path = $_GET['q']; } if (isset($router_item)) { $router_items[$path] = $router_item; } if (!isset($router_items[$path])) { // Rebuild if we know it's needed, or if the ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-01f300594b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21batch.inc/function/_batch_api_percentage/7.x
I need the code for `_batch_api_percentage($total, $current)` in Drupal 7 (includes/batch.inc). It must do this: Formats the percent completion for a batch set.
Parameters: - $total: The total number of operations. - $current: The number of the current operation. This may be a floating point number rather than an integer in the case of a multi-step operation that is not yet complete; in that case, the fractional part of $current represents the fraction of the operation that ha...
function _batch_api_percentage($total, $current) { if (!$total || $total == $current) { // If $total doesn't evaluate as true or is equal to the current set, then // we're finished, and we can return "100". $percentage = "100"; } else { // We add a new digit at 200, 2000, etc. (since, for example,...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0207606169
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.multilingual.inc/function/field_valid_language/7.x
In Drupal 7, write the function `field_valid_language($langcode, $default = TRUE)` (file modules/field/field.multilingual.inc) so that it does the following: Ensures that a given language code is valid.
Checks whether the given language is one of the enabled languages. Otherwise, it returns the current, global language; or the site's default language, if the additional parameter $default is TRUE. Parameters: - $langcode: The language code to validate. - $default: Whether to return the default language code or the cur...
function field_valid_language($langcode, $default = TRUE) { $enabled_languages = field_content_languages(); if (in_array($langcode, $enabled_languages)) { return $langcode; } global $language_content; return $default ? language_default('language') : $language_content->language; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-02085339a0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_field_overview_form_validate_add_existing/7.x
I need the code for `_field_ui_field_overview_form_validate_add_existing($form, &$form_state)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Validates the 'add existing field' row of field_ui_field_overview_form().
File: modules/field_ui/field_ui.admin.inc
function _field_ui_field_overview_form_validate_add_existing($form, &$form_state) { // The form element might be absent if no existing fields can be added to // this bundle. if (isset($form_state['values']['fields']['_add_existing_field'])) { $field = $form_state['values']['fields']['_add_existing_field']; ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0208d01a54
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7015/7.x
Implement `node_update_7015()` in PHP for Drupal 7. Required behavior: Enable node types that may have been erroneously disabled in Drupal 7.36.
File: modules/node/node.install
function node_update_7015() { db_update('node_type') ->fields(array('disabled' => 0)) ->condition('base', 'node_content') ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-021abfe821
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_block_view_pre_render/7.x
Implement `forum_block_view_pre_render($elements)` in PHP for Drupal 7. Required behavior: Render API callback: Lists nodes based on the element's #query property.
This function can be used as a #pre_render callback. File: modules/forum/forum.module
function forum_block_view_pre_render($elements) { $result = $elements['#query']->execute(); if ($node_title_list = node_title_list($result)) { $elements['forum_list'] = $node_title_list; $elements['forum_more'] = array('#theme' => 'more_link', '#url' => 'forum', '#title' => t('Read the latest forum topics.'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0222f8b712
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.pages.inc/function/statistics_node_tracker/7.x
Implement `statistics_node_tracker()` in PHP for Drupal 7. Required behavior: Page callback: Displays statistics for a node.
Returns: A render array containing node statistics. If information for the node was not found, this will deliver a page not found error via drupal_not_found(). File: modules/statistics/statistics.pages.inc
function statistics_node_tracker() { if ($node = node_load(arg(1))) { $header = array( array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), array('data' => t('Referrer'), 'field' => 'a.url'), array('data' => t('User'), 'field' => 'u.name'), array('data' => t('Op...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-023f2e9e5f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_sync_field_status/7.x
In Drupal 7, write the function `field_sync_field_status()` (file modules/field/field.module) so that it does the following: Refreshes the 'active' and 'storage_active' columns for fields.
File: modules/field/field.module
function field_sync_field_status() { // Refresh the 'active' and 'storage_active' columns according to the current // set of enabled modules. $modules = module_list(); foreach ($modules as $module_name) { field_associate_fields($module_name); } db_update('field_config') ->fields(array('active' => 0)...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-024a3fb0e8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_help/7.x
I need the code for `user_help($path, $arg)` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_help().
File: modules/user/user.module
function user_help($path, $arg) { global $user; switch ($path) { case 'admin/help#user': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The User module allows users to register, log in, and log out. It also allows users with proper permissions to manage user rol...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-024f59c2fd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_widget_settings/7.x
In Drupal 7, write the function `field_info_widget_settings($type)` (file modules/field/field.info.inc) so that it does the following: Returns a field widget's default settings.
Parameters: - $type: A widget type name. Returns: The widget type's default settings, as provided by hook_field_widget_info(), or an empty array if type or settings are undefined. File: modules/field/field.info.inc
function field_info_widget_settings($type) { $info = field_info_widget_types($type); return isset($info['settings']) ? $info['settings'] : array(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-025140ac5c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_field_by_id/7.x
I need the code for `field_info_field_by_id($field_id)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns data about an individual field, given a field ID.
Parameters: - $field_id: The id of the field to retrieve. $field_id can refer to a deleted field, but not an inactive one. Returns: The field array, as returned by field_read_fields(), with an additional element 'bundles', whose value is an array of all the bundles this field belongs to. File: modules/field/field.inf...
function field_info_field_by_id($field_id) { $cache = _field_info_field_cache(); return $cache->getFieldById($field_id); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-02615b3afc
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_process_html/7.x
Implement `garland_process_html(&$variables)` in PHP for Drupal 7. Required behavior: Override or insert variables into the html template.
File: themes/garland/template.php
function garland_process_html(&$variables) { // Hook into color.module if (module_exists('color')) { _color_html_alter($variables); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0275a35427
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_test_get_all/7.x
I need the code for `simpletest_test_get_all()` in Drupal 7 (modules/simpletest/simpletest.module). It must do this: Get a list of all of the tests provided by the system.
The list of test classes is loaded from the registry where it looks for files ending in ".test". Once loaded the test list is cached and stored in a static variable. In order to list tests provided by disabled modules hook_registry_files_alter() is used to forcefully add them to the registry. PSR-0 classes are found b...
function simpletest_test_get_all() { $groups = &drupal_static(__FUNCTION__); if (!$groups) { // Register a simple class loader for PSR-0 test classes. simpletest_classloader_register(); // Load test information from cache if available, otherwise retrieve the // information from each tests getInfo(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-028c54d71e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_form_node_type_form_alter/7.x
I need the code for `field_ui_form_node_type_form_alter(&$form, $form_state)` in Drupal 7 (modules/field_ui/field_ui.module). It must do this: Implements hook_form_FORM_ID_alter().
Adds a button 'Save and add fields' to the 'Create content type' form. File: modules/field_ui/field_ui.module
function field_ui_form_node_type_form_alter(&$form, $form_state) { // We want to display the button only on add page. if (empty($form['#node_type']->type)) { $form['actions']['save_continue'] = array( '#type' => 'submit', '#value' => t('Save and add fields'), '#weight' => 45, ); $form[...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-02a8b82b19
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7015/7.x
I need the code for `user_update_7015()` in Drupal 7 (modules/user/user.install). It must do this: Change {users}.signature_format into varchar.
File: modules/user/user.install
function user_update_7015() { db_change_field('users', 'signature_format', 'signature_format', array( 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'description' => 'The {filter_format}.format of the signature.', )); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-02b1ee8314
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_archiver_info/7.x
I need the code for `system_archiver_info()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_archiver_info().
File: modules/system/system.module
function system_archiver_info() { $archivers['tar'] = array( 'class' => 'ArchiverTar', 'extensions' => array('tar', 'tgz', 'tar.gz', 'tar.bz2'), ); if (function_exists('zip_open')) { $archivers['zip'] = array( 'class' => 'ArchiverZip', 'extensions' => array('zip'), ); } return $arc...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-02d440dd6d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_edit_validate/7.x
In Drupal 7, write the function `book_admin_edit_validate($form, &$form_state)` (file modules/book/book.admin.inc) so that it does the following: Form validation handler for book_admin_edit().
Checks that the book has not been changed while using the form. File: modules/book/book.admin.inc
function book_admin_edit_validate($form, &$form_state) { if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) { form_set_error('', t('This book has been modified by another user, the changes could not be saved.')); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-02e57f1d46
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/_text_sanitize/7.x
Implement `_text_sanitize($instance, $langcode, $item, $column)` in PHP for Drupal 7. Required behavior: Sanitizes the 'value' or 'summary' data of a text value.
Depending on whether the field instance uses text processing, data is run through check_plain() or check_markup(). Parameters: - $instance: The instance definition. - $langcode: The language associated to $item. - $item: The field value to sanitize. - $column: The column to sanitize (either 'value' or 'summary'). Ret...
function _text_sanitize($instance, $langcode, $item, $column) { // If the value uses a cacheable text format, text_field_load() precomputes // the sanitized string. if (isset($item["safe_$column"])) { return $item["safe_$column"]; } if ($item[$column] === '') { return ''; } return $instance['setti...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-02fdc2b771
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_add_date_formats_form_submit/7.x
In Drupal 7, write the function `system_add_date_formats_form_submit($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Process new date format string submission.
File: modules/system/system.admin.inc
function system_add_date_formats_form_submit($form, &$form_state) { $format = array(); $format['format'] = trim($form_state['values']['date_format']); $format['type'] = 'custom'; $format['locked'] = 0; if (!empty($form_state['values']['dfid'])) { system_date_format_save($format, $form_state['values']['dfi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0310d573d9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/_dblog_get_message_types/7.x
In Drupal 7, write the function `_dblog_get_message_types()` (file modules/dblog/dblog.module) so that it does the following: Gathers a list of uniquely defined database log message types.
Returns (array): List of uniquely defined database log message types. File: modules/dblog/dblog.module
function _dblog_get_message_types() { $types = array(); $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type'); foreach ($result as $object) { $types[] = $object->type; } return $types; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0341d0d156
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_help/7.x
Implement `menu_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().
File: modules/menu/menu.module
function menu_help($path, $arg) { switch ($path) { case 'admin/help#menu': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Menu module provides an interface for managing menus. A menu is a hierarchical collection of links, which can be within or external to the ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-03574cf63b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_process/7.x
Implement `template_process(&$variables, $hook)` in PHP for Drupal 7. Required behavior: Adds helper variables derived from variables defined during preprocessing.
When preparing variables for a theme hook implementation, all 'preprocess' functions run first, then all 'process' functions (see theme() for details about the full sequence). This function serializes array variables manipulated during the preprocessing phase into strings for convenient use by templates. As with templ...
function template_process(&$variables, $hook) { // Flatten out classes. $variables['classes'] = implode(' ', $variables['classes_array']); // Flatten out attributes, title_attributes, and content_attributes. // Because this function can be called very often, and often with empty // attributes, optimize perfo...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-038d6722fc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_node_update_index/7.x
Implement `search_node_update_index($node)` in PHP for Drupal 7. Required behavior: Implements hook_node_update_index().
File: modules/search/search.module
function search_node_update_index($node) { // Transplant links to a node into the target node. $result = db_query("SELECT caption FROM {search_node_links} WHERE nid = :nid", array(':nid' => $node->nid), array('target' => 'slave')); $output = array(); foreach ($result as $link) { $output[] = $link->caption; ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-039ab61e8b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_username/7.x
Implement `rdf_preprocess_username(&$variables)` in PHP for Drupal 7. Required behavior: Implements MODULE_preprocess_HOOK().
File: modules/rdf/rdf.module
function rdf_preprocess_username(&$variables) { // Because xml:lang is set on the HTML element that wraps the page, the // username inherits this language attribute. However, since the username // might not be transliterated to the same language that the content is in, // we do not want it to inherit the langua...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-03a772d0d5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_file_move/7.x
Implement `user_file_move($file, $source)` in PHP for Drupal 7. Required behavior: Implements hook_file_move().
File: modules/user/user.module
function user_file_move($file, $source) { // If a user's picture is replaced with a new one, update the record in // the users table. if (isset($file->fid) && isset($source->fid) && $file->fid != $source->fid) { db_update('users') ->fields(array( 'picture' => $file->fid, )) ->conditi...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-03e5f4241d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/_node_types_build/7.x
I need the code for `_node_types_build($rebuild = FALSE)` in Drupal 7 (modules/node/node.module). It must do this: Builds and returns the list of available node types.
The list of types is built by invoking hook_node_info() on all modules and comparing this information with the node types in the {node_type} table. These two information sources are not synchronized during module installation until node_types_rebuild() is called. Parameters: - $rebuild: TRUE to rebuild node types. Equ...
function _node_types_build($rebuild = FALSE) { $cid = 'node_types:' . $GLOBALS['language']->language; if (!$rebuild) { $_node_types = &drupal_static(__FUNCTION__); if (isset($_node_types)) { return $_node_types; } if ($cache = cache_get($cid)) { $_node_types = $cache->data; return...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-03ee44f890
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.admin.inc/function/contact_category_delete_form_submit/7.x
I need the code for `contact_category_delete_form_submit($form, &$form_state)` in Drupal 7 (modules/contact/contact.admin.inc). It must do this: Form submission handler for contact_category_delete_form().
File: modules/contact/contact.admin.inc
function contact_category_delete_form_submit($form, &$form_state) { $contact = $form['contact']['#value']; db_delete('contact') ->condition('cid', $contact['cid']) ->execute(); drupal_set_message(t('Category %category has been deleted.', array('%category' => $contact['category']))); watchdog('contact'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-03fb5373dd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21image.inc/function/image_save/7.x
In Drupal 7, write the function `image_save(stdClass $image, $destination = NULL)` (file includes/image.inc) so that it does the following: Closes the image and saves the changes to a file.
Parameters: - $image: An image object returned by image_load(). The object's 'info' property will be updated if the file is saved successfully. - $destination: Destination path where the image should be saved. If it is empty the original image file will be overwritten. Returns: TRUE on success, FALSE on failure. File...
function image_save(stdClass $image, $destination = NULL) { if (empty($destination)) { $destination = $image->source; } if ($return = image_toolkit_invoke('save', $image, array($destination))) { // Clear the cached file size and refresh the image information. clearstatcache(); $image->info = image...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-04006d91dc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_help/7.x
I need the code for `statistics_help($path, $arg)` in Drupal 7 (modules/statistics/statistics.module). It must do this: Implements hook_help().
File: modules/statistics/statistics.module
function statistics_help($path, $arg) { switch ($path) { case 'admin/help#statistics': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Statistics module shows you how often a given page is viewed, who viewed it, the previous page the user visited (referrer URL),...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-0426e54396
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_form_validate/7.x
In Drupal 7, write the function `profile_user_form_validate($form, &$form_state)` (file modules/profile/profile.module) so that it does the following: Form validation handler for the user register/profile form.
File: modules/profile/profile.module
function profile_user_form_validate($form, &$form_state) { $result = _profile_get_fields($form['#user_category'], $form['#user_category'] == 'register'); foreach ($result as $field) { if (!empty($form_state['values'][$field->name])) { if ($field->type == 'url' && !valid_url($form_state['values'][$field->n...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0450fedd46
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_purge/7.x
Give me the example code for `hook_field_storage_purge($entity_type, $entity, $field, $instance)` in Drupal 7. Hook description: Remove field storage information when field data is purged.
Called from field_purge_data() to allow the field storage module to delete field data information. Parameters: - $entity_type: The type of $entity; for example, 'node' or 'user'. - $entity: The pseudo-entity whose field data to delete. - $field: The (possibly deleted) field whose data is being purged. - $instance: The...
function hook_field_storage_purge($entity_type, $entity, $field, $instance) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); $table_name = _field_sql_storage_tablename($field); $revision_name = _field_sql_storage_revision_tablename($field); db_delete($table_name) ->condition('entity_...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-0472a21e20
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_date_format_types_alter/7.x
In Drupal 7, show an example implementation for `hook_date_format_types_alter(&$types)` (modules/system/system.api.php): Modify existing date types.
Allows other modules to modify existing date types like 'long'. Called by _system_date_format_types_build(). For instance, A module may use this hook to apply settings across all date types, such as locking all date types so they appear to be provided by the system. Parameters: - $types: A list of date types. Each dat...
function hook_date_format_types_alter(&$types) { foreach ($types as $name => $type) { $types[$name]['locked'] = 1; } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-0473e75be7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_entity_info_alter/7.x
In Drupal 7, write the function `forum_entity_info_alter(&$info)` (file modules/forum/forum.module) so that it does the following: Implements hook_entity_info_alter().
File: modules/forum/forum.module
function forum_entity_info_alter(&$info) { // Take over URI construction for taxonomy terms that are forums. if ($vid = variable_get('forum_nav_vocabulary', 0)) { // Within hook_entity_info(), we can't invoke entity_load() as that would // cause infinite recursion, so we call taxonomy_vocabulary_get_names()...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-04949cf640
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_rdf_mapping/7.x
Implement `node_rdf_mapping()` in PHP for Drupal 7. Required behavior: Implements hook_rdf_mapping().
File: modules/node/node.module
function node_rdf_mapping() { return array( array( 'type' => 'node', 'bundle' => RDF_DEFAULT_BUNDLE, 'mapping' => array( 'rdftype' => array('sioc:Item', 'foaf:Document'), 'title' => array( 'predicates' => array('dc:title'), ), 'created' => array( ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-0494c22ca2
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_css/7.x
Implement `ajax_command_css($selector, $argument)` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'css' command.
The 'css' command will instruct the client to use the jQuery css() method to apply the CSS arguments to elements matched by the given selector. This command is implemented by Drupal.ajax.prototype.commands.css() defined in misc/ajax.js. Parameters: - $selector: A jQuery selector string. If the command is a response t...
function ajax_command_css($selector, $argument) { return array( 'command' => 'css', 'selector' => $selector, 'argument' => $argument, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-04974522ca
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_delete_menu_confirm/7.x
I need the code for `menu_delete_menu_confirm($form, &$form_state, $menu)` in Drupal 7 (modules/menu/menu.admin.inc). It must do this: Build a confirm form for deletion of a custom menu.
File: modules/menu/menu.admin.inc
function menu_delete_menu_confirm($form, &$form_state, $menu) { $form['#menu'] = $menu; $caption = ''; $num_links = db_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = :menu", array(':menu' => $menu['menu_name']))->fetchField(); if ($num_links) { $caption .= '<p>' . format_plural($num_links, '<str...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-049fa22d57
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_deliver/7.x
In Drupal 7, write the function `ajax_deliver($page_callback_result)` (file includes/ajax.inc) so that it does the following: Packages and sends the result of a page callback as an Ajax response.
This function is the equivalent of drupal_deliver_html_page(), but for Ajax requests. Like that function, it: - Adds needed HTTP headers. - Prints rendered output. - Performs end-of-request tasks. Parameters: - $page_callback_result: The result of a page callback. Can be one of: - NULL: to indicate no content. - An in...
function ajax_deliver($page_callback_result) { // Browsers do not allow JavaScript to read the contents of a user's local // files. To work around that, the jQuery Form plugin submits forms containing // a file input element to an IFRAME, instead of using XHR. Browsers do not // normally expect JSON strings as ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-04d6d23c80
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_desaturate/7.x
I need the code for `image_gd_desaturate(stdClass $image)` in Drupal 7 (modules/system/image.gd.inc). It must do this: Convert an image resource to grayscale.
Note that transparent GIFs loose transparency when desaturated. Parameters: - $image: An image object. The $image->resource value will be modified by this call. Returns: TRUE or FALSE, based on success. File: modules/system/image.gd.inc
function image_gd_desaturate(stdClass $image) { // PHP installations using non-bundled GD do not have imagefilter. if (!function_exists('imagefilter')) { watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-04dafff6db
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_formatter_prepare_view/7.x
Implement `taxonomy_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_prepare_view().
This preloads all taxonomy terms for multiple loaded objects at once and unsets values for invalid terms that do not exist. File: modules/taxonomy/taxonomy.module
function taxonomy_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) { // F...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-04f661437e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_user_view/7.x
Implement `blog_user_view($account)` in PHP for Drupal 7. Required behavior: Implements hook_user_view().
File: modules/blog/blog.module
function blog_user_view($account) { if (user_access('create blog content', $account)) { $account->content['summary']['blog'] = array( '#type' => 'user_profile_item', '#title' => t('Blog'), // l() escapes the attributes, so we should not escape !username here. '#markup' => l(t('View recent...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-04f8d5d4bf
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_attributes/7.x
I need the code for `drupal_attributes(array $attributes = array())` in Drupal 7 (includes/common.inc). It must do this: Converts an associative array to an XML/HTML tag attribute string.
Each array key and its value will be formatted into an attribute string. If a value is itself an array, then its elements are concatenated to a single space-delimited string (for example, a class attribute with multiple values). Attribute values are sanitized by running them through check_plain(). Attribute names are ...
function drupal_attributes(array $attributes = array()) { foreach ($attributes as $attribute => &$data) { $data = implode(' ', (array) $data); $data = $attribute . '="' . check_plain($data) . '"'; } return $attributes ? ' ' . implode(' ', $attributes) : ''; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0500051ad4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.install/function/filter_update_7003/7.x
Implement `filter_update_7003()` in PHP for Drupal 7. Required behavior: Upgrade the {filter} table for core filters.
File: modules/filter/filter.install
function filter_update_7003() { // Duplicates the {filters} table since core cannot take care of the potential // contributed module filters. db_rename_table('filters', 'd6_upgrade_filter'); // Creates the Drupal 7 filter table. $filter_table = array( 'description' => 'Table that maps filters (HTML corre...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-051bb95452
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_hook_info/7.x
I need the code for `system_hook_info()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_hook_info().
File: modules/system/system.module
function system_hook_info() { $hooks['token_info'] = array( 'group' => 'tokens', ); $hooks['token_info_alter'] = array( 'group' => 'tokens', ); $hooks['tokens'] = array( 'group' => 'tokens', ); $hooks['tokens_alter'] = array( 'group' => 'tokens', ); return $hooks; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-0520c8f124
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_install_system/7.x
In Drupal 7, write the function `drupal_install_system()` (file includes/install.inc) so that it does the following: Installs the system module.
Separated from the installation of other modules so core system functions can be made available while other modules are installed. File: includes/install.inc
function drupal_install_system() { $system_path = drupal_get_path('module', 'system'); require_once DRUPAL_ROOT . '/' . $system_path . '/system.install'; module_invoke('system', 'install'); $system_versions = drupal_get_schema_versions('system'); $system_version = $system_versions ? max($system_versions) : S...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-05262ce4b3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.api.php/function/hook_field_formatter_settings_form/7.x
Give me the example code for `hook_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state)` in Drupal 7. Hook description: Specify the form elements for a formatter's settings.
This hook is only invoked if hook_field_formatter_settings_summary() returns a non-empty value. Parameters: - $field: The field structure being configured. - $instance: The instance structure being configured. - $view_mode: The view mode being configured. - $form: The (entire) configuration form array, which will usua...
function hook_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { $display = $instance['display'][$view_mode]; $settings = $display['settings']; $element = array(); if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') { $element['trim_len...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-0529b9ae92
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_load/7.x
In Drupal 7, write the function `drupal_load($type, $name)` (file includes/bootstrap.inc) so that it does the following: Includes a file with the provided type and name.
This prevents including a theme, engine, module, etc., more than once. Parameters: - $type: The type of item to load (i.e. theme, theme_engine, module). - $name: The name of the item to load. Returns: TRUE if the item is loaded or has already been loaded. File: includes/bootstrap.inc
function drupal_load($type, $name) { // Once a file is included this can't be reversed during a request so do not // use drupal_static() here. static $files = array(); if (isset($files[$type][$name])) { return TRUE; } $filename = drupal_get_filename($type, $name); if ($filename) { include_once ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0567c250ca
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7012/7.x
Implement `user_update_7012(&$sandbox)` in PHP for Drupal 7. Required behavior: Add the user's pictures to the {file_managed} table and make them managed files.
File: modules/user/user.install
function user_update_7012(&$sandbox) { $picture_field = array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => "Foreign key: {file_managed}.fid of user's picture.", ); if (!isset($sandbox['progress'])) { // Check that the field hasn't been updated in an aborted run of t...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-057889df3a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_expand_cjk/7.x
Implement `search_expand_cjk($matches)` in PHP for Drupal 7. Required behavior: Splits CJK (Chinese, Japanese, Korean) text into tokens.
The Search module matches exact words, where a word is defined to be a sequence of characters delimited by spaces or punctuation. CJK languages are written in long strings of characters, though, not split up into words. So in order to allow search matching, we split up CJK text into tokens consisting of consecutive, ov...
function search_expand_cjk($matches) { $min = variable_get('minimum_word_size', 3); $str = $matches[0]; $length = drupal_strlen($str); // If the text is shorter than the minimum word size, don't tokenize it. if ($length <= $min) { return ' ' . $str . ' '; } $tokens = ' '; // Build a FIFO queue of ch...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-05845550a9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_get_project_name/7.x
Implement `update_get_project_name($file)` in PHP for Drupal 7. Required behavior: Determines what project a given file object belongs to.
Parameters: - $file: A file object as returned by system_get_files_database(). Returns: The canonical project short name. File: modules/update/update.compare.inc
function update_get_project_name($file) { $project_name = ''; if (isset($file->info['project'])) { $project_name = $file->info['project']; } elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core') === 0)) { $project_name = 'drupal'; } return $project_name; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-059e5d5699
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_explode_tags/7.x
I need the code for `drupal_explode_tags($tags)` in Drupal 7 (includes/common.inc). It must do this: Explodes a string of tags into an array.
File: includes/common.inc
function drupal_explode_tags($tags) { // This regexp allows the following types of user input: // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x'; preg_match_all($regexp, $tags, $matches); $typed_tags = array_unique($matches[1]); $ta...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-059e5f4f53
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_cron_queue_info_alter/7.x
Give me the example code for `hook_cron_queue_info_alter(&$queues)` in Drupal 7. Hook description: Alter cron queue information before cron runs.
Called by drupal_cron_run() to allow modules to alter cron queue settings before any jobs are processesed. Parameters: - $queues (array): An array of cron queue information. File: modules/system/system.api.php
function hook_cron_queue_info_alter(&$queues) { // This site has many feeds so let's spend 90 seconds on each cron run // updating feeds instead of the default 60. $queues['aggregator_feeds']['time'] = 90; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-05d8e65ff5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.admin.inc/function/search_admin_settings/7.x
I need the code for `search_admin_settings($form)` in Drupal 7 (modules/search/search.admin.inc). It must do this: Menu callback: displays the search module settings page.
File: modules/search/search.admin.inc
function search_admin_settings($form) { // Collect some stats $remaining = 0; $total = 0; foreach (variable_get('search_active_modules', array('node', 'user')) as $module) { if ($status = module_invoke($module, 'search_status')) { $remaining += $status['remaining']; $total += $status['total']; ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-05f028997d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_local_tasks_alter/7.x
In Drupal 7, show an example implementation for `hook_menu_local_tasks_alter(&$data, $router_item, $root_path)` (modules/system/system.api.php): Alter tabs and actions displayed on the page before they are rendered.
This hook is invoked by menu_local_tasks(). The system-determined tabs and actions are passed in by reference. Additional tabs or actions may be added, or existing items altered. Each tab or action is an associative array containing: - #theme: The theme function to use to render. - #link: An associative array containi...
function hook_menu_local_tasks_alter(&$data, $router_item, $root_path) { // Add an action linking to node/add to all pages. $data['actions']['output'][] = array( '#theme' => 'menu_local_task', '#link' => array( 'title' => t('Add new content'), 'href' => 'node/add', 'localized_options' => a...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-0601fb205a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_insert/7.x
I need the code for `file_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items)` in Drupal 7 (modules/file/file.field.inc). It must do this: Implements hook_field_insert().
File: modules/file/file.field.inc
function file_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); // Add a new usage of each uploaded file. foreach ($items as $item) { $file = (object) $item; file_usage_add($file, 'file', $entity_type, $id); ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-060853deb3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_update/7.x
Implement `dashboard_update()` in PHP for Drupal 7. Required behavior: Sets the new weight of each region according to the drag-and-drop order.
File: modules/dashboard/dashboard.module
function dashboard_update() { drupal_theme_initialize(); global $theme_key; // Check the form token to make sure we have a valid request. if (!empty($_REQUEST['form_token']) && drupal_valid_token($_REQUEST['form_token'], 'dashboard-update')) { parse_str($_REQUEST['regions'], $regions); foreach ($regions...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-060978aa1e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7015/7.x
I need the code for `system_update_7015()` in Drupal 7 (modules/system/system.install). It must do this: Change the user logout path.
File: modules/system/system.install
function system_update_7015() { db_update('menu_links') ->fields(array('link_path' => 'user/logout')) ->condition('link_path', 'logout') ->execute(); db_update('menu_links') ->fields(array('router_path' => 'user/logout')) ->condition('router_path', 'logout') ->execute(); db_update('menu_l...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0630af2457
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_insert/7.x
In Drupal 7, show an example implementation for `hook_user_insert(&$edit, $account, $category)` (modules/user/user.api.php): A user account was created.
The module should save its custom additions to the user object into the database. Parameters: - $edit: The array of form values submitted by the user. - $account: The user object on which the operation is being performed. - $category: The active category of user information being edited. File: modules/user/user.api.p...
function hook_user_insert(&$edit, $account, $category) { db_insert('mytable') ->fields(array( 'myfield' => $edit['myfield'], 'uid' => $account->uid, )) ->execute(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-063c76e4d4
7
drupal_api_code
https://api.drupal.org/api/drupal/update.php/function/update_script_selection_form/7.x
Implement `update_script_selection_form($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form constructor for the list of available database module updates.
File: update.php
function update_script_selection_form($form, &$form_state) { $count = 0; $incompatible_count = 0; $form['start'] = array( '#tree' => TRUE, '#type' => 'fieldset', '#collapsed' => TRUE, '#collapsible' => TRUE, ); // Ensure system.module's updates appear first. $form['start']['system'] = array...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-064128b484
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_help/7.x
Implement `text_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().
File: modules/field/modules/text/text.module
function text_help($path, $arg) { switch ($path) { case 'admin/help#text': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t("The Text module defines various text field types for the Field module. A text field may contain plain text only, or optionally, may use Drupal'...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-068565f655
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21errors.inc/function/_drupal_error_handler_real/7.x
In Drupal 7, write the function `_drupal_error_handler_real($error_level, $message, $filename, $line)` (file includes/errors.inc) so that it does the following: Provides custom PHP error handling.
Parameters: - $error_level: The level of the error raised. - $message: The error message. - $filename: The filename that the error was raised in. - $line: The line number the error was raised at. File: includes/errors.inc
function _drupal_error_handler_real($error_level, $message, $filename, $line) { if ($error_level & error_reporting()) { $types = drupal_error_levels(); list($severity_msg, $severity_level) = $types[$error_level]; $caller = _drupal_get_last_caller(debug_backtrace()); if (!function_exists('filter_xss_a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-068abc2538
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/template_preprocess_poll_vote/7.x
In Drupal 7, write the function `template_preprocess_poll_vote(&$variables)` (file modules/poll/poll.module) so that it does the following: Themes the voting form for a poll.
Inputs: $form File: modules/poll/poll.module
function template_preprocess_poll_vote(&$variables) { $form = $variables['form']; $variables['choice'] = drupal_render($form['choice']); $variables['title'] = check_plain($form['#node']->title); $variables['vote'] = drupal_render($form['vote']); $variables['rest'] = drupal_render_children($form); $variables...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-069521f212
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/theme_aggregator_categorize_items/7.x
In Drupal 7, write the function `theme_aggregator_categorize_items($variables)` (file modules/aggregator/aggregator.pages.inc) so that it does the following: Returns HTML for the aggregator page list form for assigning categories.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/aggregator/aggregator.pages.inc
function theme_aggregator_categorize_items($variables) { $form = $variables['form']; $output = drupal_render($form['feed_source']); $rows = array(); if (!empty($form['items'])) { foreach (element_children($form['items']) as $key) { $rows[] = array( drupal_render($form['items'][$key]), ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-06ece89526
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.install/function/menu_update_7003/7.x
I need the code for `menu_update_7003(&$sandbox)` in Drupal 7 (modules/menu/menu.install). It must do this: Add missing custom menus to active menus list.
File: modules/menu/menu.install
function menu_update_7003(&$sandbox) { // Make sure all custom menus are present in the active menus variable so that // their items may appear in the active trail. // @see menu_set_active_menu_names() $active_menus = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus())); $update_var...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-06f0243c43
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_date_formats/7.x
In Drupal 7, write the function `system_get_date_formats($type = NULL)` (file modules/system/system.module) so that it does the following: Gets the list of defined date formats and attributes.
Parameters: - $type: (optional) The date type name. Returns: An associative array of date formats. The top-level keys are the names of the date types that the date formats belong to. The values are in turn associative arrays keyed by the format string, with the following keys: - dfid: The date format ID. - format: The...
function system_get_date_formats($type = NULL) { $date_formats = &drupal_static(__FUNCTION__); if (!isset($date_formats)) { $date_formats = _system_date_formats_build(); } return $type ? (isset($date_formats[$type]) ? $date_formats[$type] : FALSE) : $date_formats; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-0711a37df9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_cache_clear/7.x
I need the code for `field_cache_clear()` in Drupal 7 (modules/field/field.module). It must do this: Clear the field info and field data caches.
File: modules/field/field.module
function field_cache_clear() { cache_clear_all('*', 'cache_field', TRUE); field_info_cache_clear(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-07555f0f06
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_form_element_validate/7.x
Implement `path_form_element_validate($element, &$form_state, $complete_form)` in PHP for Drupal 7. Required behavior: Form element validation handler for URL alias form element.
File: modules/path/path.module
function path_form_element_validate($element, &$form_state, $complete_form) { // Trim the submitted value. $alias = trim($form_state['values']['path']['alias']); if (!empty($alias)) { form_set_value($element['alias'], $alias, $form_state); // Node language (Locale module) needs special care. Since the lan...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-076229816c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/filter_xss/7.x
In Drupal 7, write the function `filter_xss($string, $allowed_tags = array('a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd'))` (file includes/common.inc) so that it does the following: Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.
Based on kses by Ulf Harnhammar, see http://sourceforge.net/projects/kses. For examples of various XSS attacks, see: http://ha.ckers.org/xss.html. This code does four things: - Removes characters and constructs that can trick browsers. - Makes sure all HTML entities are well-formed. - Makes sure all HTML tags and attr...
function filter_xss($string, $allowed_tags = array('a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd')) { // Only operate on valid UTF-8 strings. This is necessary to prevent cross // site scripting issues on Internet Explorer 6. if (!drupal_validate_utf8($string)) { return ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-076252b590
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_system_theme_engine_info/7.x
In Drupal 7, show an example implementation for `hook_system_theme_engine_info()` (modules/system/system.api.php): Return additional theme engines provided by modules.
This hook is invoked from _system_rebuild_theme_data() and allows modules to register additional theme engines outside of the regular 'themes/engines' directories of a Drupal installation. Returns: An associative array. Each key is the system name of a theme engine and each value is the corresponding path to the theme...
function hook_system_theme_engine_info() { $theme_engines['izumi'] = drupal_get_path('module', 'mymodule') . '/izumi/izumi.engine'; return $theme_engines; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-07805ccc32
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_block_denied/7.x
Implement `drupal_block_denied($ip)` in PHP for Drupal 7. Required behavior: Handles denied users.
Parameters: - $ip: IP address to check. Prints a message and exits if access is denied. File: includes/bootstrap.inc
function drupal_block_denied($ip) { // Deny access to blocked IP addresses - t() is not yet available. if (drupal_is_denied($ip)) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.'; exit(); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-078546b1ee
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_math_div/7.x
I need the code for `_openid_math_div($x, $y)` in Drupal 7 (modules/openid/openid.inc). It must do this: Calls the div function from the available math library for OpenID.
File: modules/openid/openid.inc
function _openid_math_div($x, $y) { $library = _openid_get_math_library(); switch ($library) { case 'gmp': return gmp_div($x, $y); case 'bcmath': return bcdiv($x, $y); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-078ef4d1ab
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_validate_utf8/7.x
I need the code for `drupal_validate_utf8($text)` in Drupal 7 (includes/bootstrap.inc). It must do this: Checks whether a string is valid UTF-8.
All functions designed to filter input should use drupal_validate_utf8 to ensure they operate on valid UTF-8 strings to prevent bypass of the filter. When text containing an invalid UTF-8 lead byte (0xC0 - 0xFF) is presented as UTF-8 to Internet Explorer 6, the program may misinterpret subsequent bytes. When these sub...
function drupal_validate_utf8($text) { if (strlen((string) $text) == 0) { return TRUE; } // With the PCRE_UTF8 modifier 'u', preg_match() fails silently on strings // containing invalid UTF-8 byte sequences. It does not reject character // codes above U+10FFFF (represented by 4 or more octets), though. ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-07b83f73c7
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21bartik%21template.php/function/bartik_preprocess_block/7.x
I need the code for `bartik_preprocess_block(&$variables)` in Drupal 7 (themes/bartik/template.php). It must do this: Override or insert variables into the block template.
File: themes/bartik/template.php
function bartik_preprocess_block(&$variables) { // In the header region visually hide block titles. if ($variables['block']->region == 'header') { $variables['title_attributes_array']['class'][] = 'element-invisible'; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-07bbf08e15
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/theme_field/7.x
Implement `theme_field($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a field.
This is the default theme implementation to display the value of a field. Theme developers who are comfortable with overriding theme functions may do so in order to customize this markup. This function can be overridden with varying levels of specificity. For example, for a field named 'body' displayed on the 'article'...
function theme_field($variables) { $output = ''; // Render the label, if it's not hidden. if (!$variables['label_hidden']) { $output .= '<div class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . ':&nbsp;</div>'; } // Render the items. $output .= '<div class="field-items"...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-07ca60b4ec
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_actions/7.x
I need the code for `form_process_actions($element, &$form_state)` in Drupal 7 (includes/form.inc). It must do this: Processes a form actions container element.
Parameters: - $element: An associative array containing the properties and children of the form actions container. - $form_state: The $form_state array for the form this element belongs to. Returns: The processed element. File: includes/form.inc
function form_process_actions($element, &$form_state) { $element['#attributes']['class'][] = 'form-actions'; return $element; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-07de549c21
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_normalization_method_info/7.x
In Drupal 7, show an example implementation for `hook_openid_normalization_method_info()` (modules/openid/openid.api.php): Allow modules to declare OpenID normalization methods.
The discovery function callbacks will be called in turn with an unique parameter, the identifier to normalize. They have to return a normalized identifier, or NULL if the identifier is not in a form they can handle. The first normalization method that succeed (return a value that is not NULL) will stop the normalizati...
function hook_openid_normalization_method_info() { return array( 'new_normalization_idea' => '_my_normalization_method', ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-0815af898d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_map_assoc/7.x
Implement `drupal_map_assoc($array, $function = NULL)` in PHP for Drupal 7. Required behavior: Forms an associative array from a linear array.
This function walks through the provided array and constructs an associative array out of it. The keys of the resulting array will be the values of the input array. The values will be the same as the keys unless a function is specified, in which case the output of the function is used for the values instead. Parameter...
function drupal_map_assoc($array, $function = NULL) { // array_combine() fails with empty arrays: // http://bugs.php.net/bug.php?id=34857. $array = !empty($array) ? array_combine($array, $array) : array(); if (is_callable($function)) { $array = array_map($function, $array); } return $array; }
[ "code-task", "function" ]
2026-09-30T00:00:00
End of preview. Expand in Data Studio

Drupal 7 Dataset API

Drupal 7 reached end of life in early 2025, but plenty of sites still run on it, and the people maintaining them still need good answers. This dataset is meant to help with that: 7,952 examples about the Drupal 7 API, taken only from api.drupal.org. You can use it to fine-tune a model, to test how well a model knows Drupal 7, or as reference material for a retrieval (RAG) setup.

Everything is in English. It was put together by Daniel Ricardo Ramirez Marin as part of the Codicem project in Danemar Parceros.

What's inside

There are two configurations, so you can pick the one that fits what you're doing:

Config Examples What you get
reference 4,382 A question about an API symbol, with its exact signature and a short explanation as the answer
code 3,570 A coding task ("write the function X that...") with the real function body as the answer

In reference you'll find 4,010 functions, 247 constants, 91 classes and 34 globals. In code there are 2,501 functions, 739 hook implementations and 330 hook definition examples (the ones that come from *.api.php files).

Fields

Every record has the same fields in both configs:

Field What it is
id A stable identifier
drupal_version Always "7"
source_type drupal_api_reference or drupal_api_code
source_url The api.drupal.org page the example comes from
instruction The question or the task
context In code: the description, parameters and return value. Empty in reference
response The answer: signature plus explanation (reference), or the function source (code)
tags The kind of example
created_at When it was generated

A code example

{
  "instruction": "In Drupal 7, write the function `actions_do($action_ids, $object = NULL, ...)` (file includes/actions.inc) so that it does the following: Performs a given list of actions by executing their callback functions.",
  "context": "Given the IDs of actions to perform, this function finds out what the callback functions for the actions are by querying the database. ...\n\nParameters:\n- $action_ids: ...\n\nFile: includes/actions.inc",
  "response": "function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a2 = NULL) {\n  // $stack tracks the number of recursive calls.\n  static $stack;\n  ..."
}

A reference example

{
  "instruction": "What does the comment_unpublish_action function do in Drupal 7?",
  "response": "function comment_unpublish_action($comment, $context = array()): Unpublishes a comment by setting its status to COMMENT_NOT_PUBLISHED and logs the action in watchdog."
}

How it was made

The two configs were built differently, so it's worth knowing which is which.

code didn't involve any model. It comes straight from the official Drupal 7 source code (core 7.104-dev). Each task is written from the function's docblock, and the answer is the function body copied exactly as it is, indentation included.

reference did involve models. For each api.drupal.org page, several language models proposed a question and an answer, and other models acted as judges, throwing out any pair that made things up or didn't copy the signature exactly. Those pairs were first written in Spanish and then machine-translated into English. The signature is never translated, and a translation was only accepted if every code identifier from the original (variables, function and constant names, quoted strings) came through untouched. So the questions and explanations in reference are AI-generated text, based only on what the page says.

What was left out

To keep the quality up, these were left out:

  • simpletest scaffolding, which is mostly setUp and getInfo boilerplate (1,294)
  • explanations that were empty or too short (35)
  • signatures that don't appear word for word on the source page (5)
  • anything that mentions another Drupal version (20)
  • possible personal data (5)
  • translations that didn't pass validation (28)
  • class methods, because their source isn't a page that could be verified on api.drupal.org (413)

After the dataset was built

Once the dataset was fully created, I verified the data by hand, and then used it to fine-tune a Qwen 7B model.

License

The whole dataset is released under the GPL-2.0 or later, That's the license api.drupal.org itself declares for all of its code and documentation, and since this dataset is derived from that content, it keeps the same terms. Records don't carry a license field of their own because the license applies to the dataset as a whole.

If you use it, please keep the license and the reference to the source (source_url). Whether training a model on GPL content, or sharing that model, brings obligations of its own is still an open legal question, so if you plan to redistribute model weights, it's worth talking to someone who can advise you.

Drupal is a registered trademark of Dries Buytaert. This is an independent project and has no affiliation with, or endorsement from, the Drupal Association or the Drupal project.

Things to keep in mind

  • The manual check was a verification, not a line-by-line review. The reference examples were checked by models during generation, and the translation was done by a model too, so some explanations may be a bit off. The code in code is official. I did verify that the fine-tuned Qwen 7B model uses Drupal 7 better than before, and it worked.
  • It's Drupal 7 only, so it doesn't apply to Drupal 8 and later.
  • Coverage isn't complete. There are no class methods and no tests, and in code functions with fewer than 2 lines of body or more than 6,000 characters are left out.

Citation

If this dataset is useful for your work, you can cite it like this:

@misc{danemarparceros/drupal7-dataset-api,
  title  = {Drupal 7 Dataset API},
  author = {Ramirez Marin, Daniel Ricardo},
  year   = {2026},
  note   = {Dataset derived from api.drupal.org, GPL-2.0-or-later license}
}
Downloads last month
58