{"id": "api-drupal7-000fdb7f8a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_7011/7.x", "instruction": "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.", "context": "File: modules/forum/forum.install", "response": "function forum_update_7011() {\n $select = db_select('node', 'n')\n ->fields('n', array('nid'))\n ->condition('status', 0 );\n\n db_delete('forum_index')\n ->condition('nid', $select, 'IN')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-002fcc3b1e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_modules_enabled/7.x", "instruction": "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().", "context": "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().\n\nThere is a separate comment bundle for each node type to allow for per-node-type customization of comment fields. Each one of these bundles needs a comment body field instance. A comment bundle is needed even for node types whose comments are disabled by default, because individual nodes may override that default.\n\nFile: modules/comment/comment.install", "response": "function comment_modules_enabled($modules) {\n // Only react if comment module is one of the modules being enabled.\n // hook_node_type_insert() is used to create body fields while the comment\n // module is enabled.\n if (in_array('comment', $modules)) {\n // Ensure that the list of node types reflects newly enabled modules.\n node_types_rebuild();\n\n // Create comment body fields for each node type, if needed.\n foreach (node_type_get_types() as $type => $info) {\n _comment_body_field_create($info);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-003a489bce", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_formatter_settings_form/7.x", "instruction": "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().", "context": "File: modules/field/modules/number/number.module", "response": "function number_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {\n $display = $instance['display'][$view_mode];\n $settings = $display['settings'];\n\n $element = array();\n\n if ($display['type'] == 'number_decimal' || $display['type'] == 'number_integer') {\n $options = array(\n '' => t(''),\n '.' => t('Decimal point'),\n ',' => t('Comma'),\n ' ' => t('Space'),\n );\n $element['thousand_separator'] = array(\n '#type' => 'select',\n '#title' => t('Thousand marker'),\n '#options' => $options,\n '#default_value' => $settings['thousand_separator'],\n );\n\n if ($display['type'] == 'number_decimal') {\n $element['decimal_separator'] = array(\n '#type' => 'select',\n '#title' => t('Decimal marker'),\n '#options' => array('.' => t('Decimal point'), ',' => t('Comma')),\n '#default_value' => $settings['decimal_separator'],\n );\n $element['scale'] = array(\n '#type' => 'select',\n '#title' => t('Scale'),\n '#options' => drupal_map_assoc(range(0, 10)),\n '#default_value' => $settings['scale'],\n '#description' => t('The number of digits to the right of the decimal.'),\n );\n }\n\n $element['prefix_suffix'] = array(\n '#type' => 'checkbox',\n '#title' => t('Display prefix and suffix.'),\n '#default_value' => $settings['prefix_suffix'],\n );\n }\n\n return $element;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-00460d0541", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_menu/7.x", "instruction": "Implement `announcements_feed_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu().", "context": "File: modules/announcements_feed/announcements_feed.module", "response": "function announcements_feed_menu() {\n $items['admin/announcements_feed'] = array(\n 'title' => 'Announcements',\n 'description' => 'Announcements and updates posted by the drupal.org community.',\n 'page callback' => 'announcements_feed_get_announcements',\n 'access arguments' => array('access announcements'),\n 'position' => 'left',\n 'weight' => 2,\n 'file' => 'announcements_feed.inc',\n 'options' => array(\n 'attributes' => array(\n 'class' => array('announcement-menu-class'),\n ),\n ),\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0074d8bf9a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_form_alter/7.x", "instruction": "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().", "context": "Adds language fields to user forms.\n\nFile: modules/locale/locale.module", "response": "function locale_form_alter(&$form, &$form_state, $form_id) {\n // Only alter user forms if there is more than one language.\n if (drupal_multilingual()) {\n // Display language selector when either creating a user on the admin\n // interface or editing a user account.\n if ($form_id == 'user_register_form' || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {\n locale_language_selector_form($form, $form_state, $form['#user']);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-007c0e05e4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_pre_render_fieldset/7.x", "instruction": "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.", "context": "Parameters:\n- $element: An associative array containing the properties and children of the fieldset.\n\nReturns: The modified element with all group members.\n\nFile: includes/form.inc", "response": "function form_pre_render_fieldset($element) {\n // Fieldsets may be rendered outside of a Form API context.\n if (!isset($element['#parents']) || !isset($element['#groups'])) {\n return $element;\n }\n // Inject group member elements belonging to this group.\n $parents = implode('][', $element['#parents']);\n $children = element_children($element['#groups'][$parents]);\n if (!empty($children)) {\n foreach ($children as $key) {\n // Break references and indicate that the element should be rendered as\n // group member.\n $child = (array) $element['#groups'][$parents][$key];\n $child['#group_fieldset'] = TRUE;\n // Inject the element as new child element.\n $element[] = $child;\n\n $sort = TRUE;\n }\n // Re-sort the element's children if we injected group member elements.\n if (isset($sort)) {\n $element['#sorted'] = FALSE;\n }\n }\n\n if (isset($element['#group'])) {\n $group = $element['#group'];\n // If this element belongs to a group, but the group-holding element does\n // not exist, we need to render it (at its original location).\n if (!isset($element['#groups'][$group]['#group_exists'])) {\n // Intentionally empty to clarify the flow; we simply return $element.\n }\n // If we injected this element into the group, then we want to render it.\n elseif (!empty($element['#group_fieldset'])) {\n // Intentionally empty to clarify the flow; we simply return $element.\n }\n // Otherwise, this element belongs to a group and the group exists, so we do\n // not render it.\n elseif (element_children($element['#groups'][$group])) {\n $element['#printed'] = TRUE;\n }\n }\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0082a95e0b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_ranking/7.x", "instruction": "Implement `node_ranking()` in PHP for Drupal 7. Required behavior: Implements hook_ranking().", "context": "File: modules/node/node.module", "response": "function node_ranking() {\n // Create the ranking array and add the basic ranking options.\n $ranking = array(\n 'relevance' => array(\n 'title' => t('Keyword relevance'),\n // Average relevance values hover around 0.15\n 'score' => 'i.relevance',\n ),\n 'sticky' => array(\n 'title' => t('Content is sticky at top of lists'),\n // The sticky flag is either 0 or 1, which is automatically normalized.\n 'score' => 'n.sticky',\n ),\n 'promote' => array(\n 'title' => t('Content is promoted to the front page'),\n // The promote flag is either 0 or 1, which is automatically normalized.\n 'score' => 'n.promote',\n ),\n );\n\n // Add relevance based on creation or changed date.\n if ($node_cron_last = variable_get('node_cron_last', 0)) {\n $ranking['recent'] = array(\n 'title' => t('Recently posted'),\n // Exponential decay with half-life of 6 months, starting at last indexed node\n 'score' => 'POW(2.0, (GREATEST(n.created, n.changed) - :node_cron_last) * 6.43e-8)',\n 'arguments' => array(':node_cron_last' => $node_cron_last),\n );\n }\n return $ranking;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-009e8dd8e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_page_view/7.x", "instruction": "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.", "context": "Parameters:\n- $node: The node object.\n\nReturns: A page array suitable for use by drupal_render().\n\nFile: modules/node/node.module", "response": "function node_page_view($node) {\n // If there is a menu link to this node, the link becomes the last part\n // of the active trail, and the link name becomes the page title.\n // Thus, we must explicitly set the page title to be the node title.\n drupal_set_title($node->title);\n $uri = entity_uri('node', $node);\n // Set the node path as the canonical URL to prevent duplicate content.\n drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);\n // Set the non-aliased path as a default shortlink.\n drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);\n return node_show($node);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-00b1d78c6b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_block_configure/7.x", "instruction": "Implement `statistics_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().", "context": "File: modules/statistics/statistics.module", "response": "function statistics_block_configure($delta = '') {\n // Popular content block settings\n $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40));\n $form['statistics_block_top_day_num'] = array('#type' => 'select', '#title' => t(\"Number of day's top views to display\"), '#default_value' => variable_get('statistics_block_top_day_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in \"day\" list.'));\n $form['statistics_block_top_all_num'] = array('#type' => 'select', '#title' => t('Number of all time views to display'), '#default_value' => variable_get('statistics_block_top_all_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in \"all time\" list.'));\n $form['statistics_block_top_last_num'] = array('#type' => 'select', '#title' => t('Number of most recent views to display'), '#default_value' => variable_get('statistics_block_top_last_num', 0), '#options' => $numbers, '#description' => t('How many content items to display in \"recently viewed\" list.'));\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-00b53eaf51", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_translate_seek_query/7.x", "instruction": "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", "context": "File: includes/locale.inc", "response": "function _locale_translate_seek_query() {\n $query = &drupal_static(__FUNCTION__);\n if (!isset($query)) {\n $query = array();\n $fields = array('string', 'language', 'translation', 'group');\n foreach ($fields as $field) {\n if (isset($_SESSION['locale_translation_filter'][$field])) {\n $query[$field] = $_SESSION['locale_translation_filter'][$field];\n }\n }\n }\n return $query;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-00c76000f2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/template_preprocess_forums/7.x", "instruction": "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.", "context": "Parameters:\n- $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 are ancestors of the current term ID. - tid: Taxonomy term ID of the current forum. - sortby: One of the following integers indicating the sort criteria: - 1: Date - newest first. - 2: Date - oldest first. - 3: Posts with the most comments first. - 4: Posts with the least comments first. - forum_per_page: The maximum number of topics to display per page.\n\nFile: modules/forum/forum.module", "response": "function template_preprocess_forums(&$variables) {\n global $user;\n\n $vid = variable_get('forum_nav_vocabulary', 0);\n $vocabulary = taxonomy_vocabulary_load($vid);\n $title = !empty($vocabulary->name) ? $vocabulary->name : '';\n\n // Breadcrumb navigation:\n $breadcrumb[] = l(t('Home'), NULL);\n if ($variables['tid']) {\n $breadcrumb[] = l($vocabulary->name, 'forum');\n }\n if ($variables['parents']) {\n $variables['parents'] = array_reverse($variables['parents']);\n foreach ($variables['parents'] as $p) {\n if ($p->tid == $variables['tid']) {\n $title = $p->name;\n }\n else {\n $breadcrumb[] = l($p->name, 'forum/' . $p->tid);\n }\n }\n }\n drupal_set_breadcrumb($breadcrumb);\n drupal_set_title($title);\n\n if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) {\n if (!empty($variables['forums'])) {\n $variables['forums'] = theme('forum_list', $variables);\n }\n else {\n $variables['forums'] = '';\n }\n\n if ($variables['tid'] && !in_array($variables['tid'], variable_get('forum_containers', array()))) {\n $variables['topics'] = theme('forum_topic_list', $variables);\n drupal_add_feed('taxonomy/term/' . $variables['tid'] . '/feed', 'RSS - ' . $title);\n }\n else {\n $variables['topics'] = '';\n }\n\n // Provide separate template suggestions based on what's being output. Topic id is also accounted for.\n // Check both variables to be safe then the inverse. Forums with topic ID's take precedence.\n if ($variables['forums'] && !$variables['topics']) {\n $variables['theme_hook_suggestions'][] = 'forums__containers';\n $variables['theme_hook_suggestions'][] = 'forums__' . $variables['tid'];\n $variables['theme_hook_suggestions'][] = 'forums__containers__' . $variables['tid'];\n }\n elseif (!$variables['forums'] && $variables['topics']) {\n $variables['theme_hook_suggestions'][] = 'forums__topics';\n $variables['theme_hook_suggestions'][] = 'forums__' . $variables['tid'];\n $variables['theme_hook_suggestions'][] = 'forums__topics__' . $variables['tid'];\n }\n else {\n $variables['theme_hook_suggestions'][] = 'forums__' . $variables['tid'];\n }\n\n }\n else {\n drupal_set_title(t('No forums defined'));\n $variables['forums'] = '';\n $variables['topics'] = '';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-00d3568baf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7020/7.x", "instruction": "Implement `system_update_7020()` in PHP for Drupal 7. Required behavior: Enable field and field_ui modules.", "context": "File: modules/system/system.install", "response": "function system_update_7020() {\n $module_list = array('field_sql_storage', 'field', 'field_ui');\n module_enable($module_list, FALSE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0101b18898", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_block_view/7.x", "instruction": "I need the code for `profile_block_view($delta = '')` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_block_view().", "context": "File: modules/profile/profile.module", "response": "function profile_block_view($delta = '') {\n if (user_access('access user profiles')) {\n $output = '';\n if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) {\n $node = node_load(arg(1));\n $account = user_load($node->uid);\n\n if ($use_fields = variable_get('profile_block_author_fields', array())) {\n // Compile a list of fields to show.\n $fields = array();\n $result = db_query('SELECT * FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));\n foreach ($result as $record) {\n // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions.\n if (isset($use_fields[$record->name]) && $use_fields[$record->name]) {\n $fields[] = $record;\n }\n }\n }\n\n if (!empty($fields)) {\n $profile = _profile_update_user_fields($fields, $account);\n $output .= theme('profile_block', array('account' => $account, 'fields' => $profile));\n }\n\n if (isset($use_fields['user_profile']) && $use_fields['user_profile']) {\n $output .= '
' . l(t('View full user profile'), 'user/' . $account->uid) . '
';\n }\n }\n\n if ($output) {\n $block['subject'] = t('About %name', array('%name' => format_username($account)));\n $block['content'] = $output;\n return $block;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-010b545374", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_page_additions/7.x", "instruction": "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.", "context": "Parameters:\n- $node: A node object.\n\nFile: modules/comment/comment.module", "response": "function comment_node_page_additions($node) {\n $additions = array();\n\n // Only attempt to render comments if the node has visible comments.\n // Unpublished comments are not included in $node->comment_count, so show\n // comments unconditionally if the user is an administrator.\n if (($node->comment_count && user_access('access comments')) || user_access('administer comments')) {\n $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);\n $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);\n if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {\n $comments = comment_load_multiple($cids);\n if ($comments) {\n comment_prepare_thread($comments);\n $build = comment_view_multiple($comments, $node);\n $build['pager']['#theme'] = 'pager';\n $additions['comments'] = $build;\n }\n elseif ($node->comment_count > 0) {\n // Comment count has got out of line, update it.\n db_query(\"UPDATE {node_comment_statistics} SET comment_count = 0 WHERE nid = :nid\", array(':nid' => $node->nid));\n }\n }\n }\n\n // Append comment form if needed.\n if (user_access('post comments') && $node->comment == COMMENT_NODE_OPEN && (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_BELOW)) {\n $build = drupal_get_form(\"comment_node_{$node->type}_form\", (object) array('nid' => $node->nid));\n $additions['comment_form'] = $build;\n }\n\n if ($additions) {\n $additions += array(\n '#theme' => 'comment_wrapper__node_' . $node->type,\n '#node' => $node,\n 'comments' => array(),\n 'comment_form' => array(),\n );\n }\n\n return $additions;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0118bdfe6b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/_translation_tab_access/7.x", "instruction": "Implement `_translation_tab_access($node)` in PHP for Drupal 7. Required behavior: Access callback: Checks that the user has permission to 'translate content'.", "context": "Only displays the translation tab for nodes that are not language-neutral of types that have translation enabled.\n\nParameters:\n- $node: A node object.\n\nReturns: TRUE if the translation tab should be displayed, FALSE otherwise.\n\nFile: modules/translation/translation.module", "response": "function _translation_tab_access($node) {\n if (entity_language('node', $node) != LANGUAGE_NONE && translation_supported_type($node->type) && node_access('view', $node)) {\n return user_access('translate content');\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-013ab038e0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess/7.x", "instruction": "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.", "context": "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 sequence.\n\nFile: includes/theme.inc", "response": "function template_preprocess(&$variables, $hook) {\n global $user;\n static $count = array();\n\n // Track run count for each hook to provide zebra striping. See\n // \"template_preprocess_block()\" which provides the same feature specific to\n // blocks.\n $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;\n $variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';\n $variables['id'] = $count[$hook]++;\n\n // Tell all templates where they are located.\n $variables['directory'] = path_to_theme();\n\n // Initialize html class attribute for the current hook.\n $variables['classes_array'] = array(drupal_html_class($hook));\n\n // Merge in variables that don't depend on hook and don't change during a\n // single page request.\n // Use the advanced drupal_static() pattern, since this is called very often.\n static $drupal_static_fast;\n if (!isset($drupal_static_fast)) {\n $drupal_static_fast['default_variables'] = &drupal_static(__FUNCTION__);\n }\n $default_variables = &$drupal_static_fast['default_variables'];\n // Global $user object shouldn't change during a page request once rendering\n // has started, but if there's an edge case where it does, re-fetch the\n // variables appropriate for the new user.\n if (!isset($default_variables) || ($user !== $default_variables['user'])) {\n $default_variables = _template_preprocess_default_variables();\n }\n $variables += $default_variables;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-014c21bd6b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_batch_import/7.x", "instruction": "I need the code for `_locale_batch_import($filepath, &$context)` in Drupal 7 (includes/locale.inc). It must do this: Implements callback_batch_operation().", "context": "Perform interface translation import as a batch step.\n\nParameters:\n- $filepath: Path to a file to import.\n- $results: Contains a list of files imported.\n\nFile: includes/locale.inc", "response": "function _locale_batch_import($filepath, &$context) {\n // The filename is either {langcode}.po or {prefix}.{langcode}.po, so\n // we can extract the language code to use for the import from the end.\n if (preg_match('!(/|\\.)([^\\./]+)\\.po$!', $filepath, $langcode)) {\n $file = (object) array('filename' => drupal_basename($filepath), 'uri' => $filepath);\n _locale_import_read_po('db-store', $file, LOCALE_IMPORT_KEEP, $langcode[2]);\n $context['results'][] = $filepath;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-015fd2cfd5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_managed_file_pre_render/7.x", "instruction": "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.", "context": "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 detailed information about the relationship between #process, #value, and #access.\n\nBecause #access is set here, it affects display only and does not prevent JavaScript or other untrusted code from submitting the form as though access were enabled. The form processing functions for these elements should not assume that the buttons can't be \"clicked\" just because they are not displayed.\n\nFile: modules/file/file.module", "response": "function file_managed_file_pre_render($element) {\n // If we already have a file, we don't want to show the upload controls.\n if (!empty($element['#value']['fid'])) {\n $element['upload']['#access'] = FALSE;\n $element['upload_button']['#access'] = FALSE;\n }\n // If we don't already have a file, there is nothing to remove.\n else {\n $element['remove_button']['#access'] = FALSE;\n }\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-01660485e5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_action_info/7.x", "instruction": "Implement `comment_action_info()` in PHP for Drupal 7. Required behavior: Implements hook_action_info().", "context": "File: modules/comment/comment.module", "response": "function comment_action_info() {\n return array(\n 'comment_publish_action' => array(\n 'label' => t('Publish comment'),\n 'type' => 'comment',\n 'configurable' => FALSE,\n 'behavior' => array('changes_property'),\n 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),\n ),\n 'comment_unpublish_action' => array(\n 'label' => t('Unpublish comment'),\n 'type' => 'comment',\n 'configurable' => FALSE,\n 'behavior' => array('changes_property'),\n 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),\n ),\n 'comment_unpublish_by_keyword_action' => array(\n 'label' => t('Unpublish comment containing keyword(s)'),\n 'type' => 'comment',\n 'configurable' => TRUE,\n 'behavior' => array('changes_property'),\n 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),\n ),\n 'comment_save_action' => array(\n 'label' => t('Save comment'),\n 'type' => 'comment',\n 'configurable' => FALSE,\n 'triggers' => array('comment_insert', 'comment_update'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-01813c9222", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/drupal_find_theme_functions/7.x", "instruction": "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.", "context": "Parameters:\n- $cache: The existing cache of theme hooks to test against.\n- $prefixes: An array of prefixes to test, in reverse order of importance.\n\nReturns: $implementations The functions found, suitable for returning from hook_theme;\n\nFile: includes/theme.inc", "response": "function drupal_find_theme_functions($cache, $prefixes) {\n $implementations = array();\n $functions = get_defined_functions();\n $theme_functions = preg_grep('/^(' . implode(')|(', $prefixes) . ')_/', $functions['user']);\n\n foreach ($cache as $hook => $info) {\n foreach ($prefixes as $prefix) {\n // Find theme functions that implement possible \"suggestion\" variants of\n // registered theme hooks and add those as new registered theme hooks.\n // The 'pattern' key defines a common prefix that all suggestions must\n // start with. The default is the name of the hook followed by '__'. An\n // 'base hook' key is added to each entry made for a found suggestion,\n // so that common functionality can be implemented for all suggestions of\n // the same base hook. To keep things simple, deep hierarchy of\n // suggestions is not supported: each suggestion's 'base hook' key\n // refers to a base hook, not to another suggestion, and all suggestions\n // are found using the base hook's pattern, not a pattern from an\n // intermediary suggestion.\n $pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');\n if (!isset($info['base hook']) && !empty($pattern)) {\n $matches = preg_grep('/^' . $prefix . '_' . $pattern . '/', $theme_functions);\n if ($matches) {\n foreach ($matches as $match) {\n $new_hook = substr($match, strlen($prefix) + 1);\n $arg_name = isset($info['variables']) ? 'variables' : 'render element';\n $implementations[$new_hook] = array(\n 'function' => $match,\n $arg_name => $info[$arg_name],\n 'base hook' => $hook,\n );\n }\n }\n }\n // Find theme functions that implement registered theme hooks and include\n // that in what is returned so that the registry knows that the theme has\n // this implementation.\n if (function_exists($prefix . '_' . $hook)) {\n $implementations[$hook] = array(\n 'function' => $prefix . '_' . $hook,\n );\n }\n }\n }\n\n return $implementations;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0193916d78", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_schema_unprocessed/7.x", "instruction": "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.", "context": "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 invoked use drupal_get_schema().\n\nThis function can be used to retrieve a schema specification in hook_schema(), so it allows you to derive your tables from existing specifications.\n\nIt is also used by drupal_install_schema() and drupal_uninstall_schema() to ensure that a module's tables are created exactly as specified without any changes introduced by a module that implements hook_schema_alter().\n\nParameters:\n- $module: The module to which the table belongs.\n- $table: The name of the table. If not given, the module's complete schema is returned.\n\nFile: includes/common.inc", "response": "function drupal_get_schema_unprocessed($module, $table = NULL) {\n // Load the .install file to get hook_schema.\n module_load_install($module);\n $schema = module_invoke($module, 'schema');\n\n if (isset($table) && isset($schema[$table])) {\n return $schema[$table];\n }\n elseif (!empty($schema)) {\n return $schema;\n }\n return array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-01afc8d830", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21password.inc/function/_password_generate_salt/7.x", "instruction": "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.", "context": "Proper use of salts may defeat a number of attacks, including:\n - The ability to try candidate passwords against multiple hashes at once.\n - The ability to use pre-hashed lists of candidate passwords.\n - The ability to determine whether two users have the same (or different)\n password without actually having to guess one of the passwords.\n\nParameters:\n- $count_log2: Integer that determines the number of iterations used in the hashing process. A larger value is more secure, but takes more time to complete.\n\nReturns: A 12 character string containing the iteration count and a random salt.\n\nFile: includes/password.inc", "response": "function _password_generate_salt($count_log2) {\n $output = '$S$';\n // Ensure that $count_log2 is within set bounds.\n $count_log2 = _password_enforce_log2_boundaries($count_log2);\n // We encode the final log2 iteration count in base 64.\n $itoa64 = _password_itoa64();\n $output .= $itoa64[$count_log2];\n // 6 bytes is the standard salt for a portable phpass hash.\n $output .= _password_base64_encode(drupal_random_bytes(6), 6);\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-01c0f248cb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_form/7.x", "instruction": "Give me the example code for `hook_form($node, &$form_state)` in Drupal 7. Hook description: Display a node editing form.", "context": "This is a node-type-specific hook, which is invoked only for the node type being affected. See\n\nParameters:\n- $node: The node being added or edited.\n- $form_state: The form state array.\n\nReturns: An array containing the title and any custom form elements to be displayed in the node editing form.\n\nFile: modules/node/node.api.php", "response": "function hook_form($node, &$form_state) {\n $type = node_type_get_type($node);\n\n $form['title'] = array(\n '#type' => 'textfield',\n '#title' => check_plain($type->title_label),\n '#default_value' => !empty($node->title) ? $node->title : '',\n '#required' => TRUE, '#weight' => -5\n );\n\n $form['field1'] = array(\n '#type' => 'textfield',\n '#title' => t('Custom field'),\n '#default_value' => $node->field1,\n '#maxlength' => 127,\n );\n $form['selectbox'] = array(\n '#type' => 'select',\n '#title' => t('Select box'),\n '#default_value' => $node->selectbox,\n '#options' => array(\n 1 => 'Option A',\n 2 => 'Option B',\n 3 => 'Option C',\n ),\n '#description' => t('Choose an option.'),\n );\n\n return $form;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-01d61f53fc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_overview_form/7.x", "instruction": "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.", "context": "Shows for one menu the menu links accessible to the current user and relevant operations.\n\nFile: modules/menu/menu.admin.inc", "response": "function menu_overview_form($form, &$form_state, $menu) {\n global $menu_admin;\n $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/menu.css');\n $sql = \"\n SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*\n FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path\n WHERE ml.menu_name = :menu\n ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC\";\n $result = db_query($sql, array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));\n $links = array();\n foreach ($result as $item) {\n $links[] = $item;\n }\n $link_count = db_query(\"SELECT COUNT(*) AS counter FROM {menu_links} WHERE menu_name = :menu AND link_path NOT LIKE :link_path\", array(':menu' => $menu['menu_name'], ':link_path' => '%\\%%'))->fetchObject();\n $counter = intval($link_count->counter / 2 ) + 1;\n\n $tree = menu_tree_data($links);\n $node_links = array();\n menu_tree_collect_node_links($tree, $node_links);\n // We indicate that a menu administrator is running the menu access check.\n $menu_admin = TRUE;\n menu_tree_check_access($tree, $node_links);\n $menu_admin = FALSE;\n\n $delta = _menu_get_menu_weight_delta($menu['menu_name'], $counter);\n $form = array_merge($form, _menu_overview_tree_form($tree, $delta));\n $form['#menu'] = $menu;\n\n if (element_children($form)) {\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save configuration'),\n );\n }\n else {\n $form['#empty_text'] = t('There are no menu links yet. Add link.', array('@link' => url('admin/structure/menu/manage/'. $form['#menu']['menu_name'] .'/add')));\n }\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-01edf67b12", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_item/7.x", "instruction": "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.", "context": "Parameters:\n- $path: The path; for example, 'node/5'. The function will find the corresponding node/% item and return that. Defaults to the current path.\n- $router_item: Internal use only.\n\nReturns: The router item or, if an error occurs in _menu_translate(), FALSE. A router item is an associative array corresponding to one row in the menu_router table. The value corresponding to the key 'map' holds the loaded objects. The value corresponding to the key 'access' is TRUE if the current user can access this page. The values corresponding to the keys 'title', 'page_arguments', 'access_arguments', and 'theme_arguments' will be filled in based on the database values and the objects loaded.\n\nFile: includes/menu.inc", "response": "function menu_get_item($path = NULL, $router_item = NULL) {\n $router_items = &drupal_static(__FUNCTION__);\n if (!isset($path)) {\n $path = $_GET['q'];\n }\n if (isset($router_item)) {\n $router_items[$path] = $router_item;\n }\n if (!isset($router_items[$path])) {\n // Rebuild if we know it's needed, or if the menu masks are missing which\n // occurs rarely, likely due to a race condition of multiple rebuilds.\n if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {\n if (_menu_check_rebuild()) {\n menu_rebuild();\n }\n }\n $original_map = arg(NULL, $path);\n\n $parts = array_slice($original_map, 0, MENU_MAX_PARTS);\n $ancestors = menu_get_ancestors($parts);\n $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();\n\n if ($router_item) {\n // Allow modules to alter the router item before it is translated and\n // checked for access.\n drupal_alter('menu_get_item', $router_item, $path, $original_map);\n\n $map = _menu_translate($router_item, $original_map);\n $router_item['original_map'] = $original_map;\n if ($map === FALSE) {\n $router_items[$path] = FALSE;\n return FALSE;\n }\n if ($router_item['access']) {\n $router_item['map'] = $map;\n $router_item['page_arguments'] = array_merge(menu_unserialize($router_item['page_arguments'], $map), array_slice($map, $router_item['number_parts']));\n $router_item['theme_arguments'] = array_merge(menu_unserialize($router_item['theme_arguments'], $map), array_slice($map, $router_item['number_parts']));\n }\n }\n $router_items[$path] = $router_item;\n }\n return $router_items[$path];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-01f300594b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21batch.inc/function/_batch_api_percentage/7.x", "instruction": "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.", "context": "Parameters:\n- $total: The total number of operations.\n- $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 has been completed.\n\nReturns: The properly formatted percentage, as a string. We output percentages using the correct number of decimal places so that we never print \"100%\" until we are finished, but we also never print more decimal places than are meaningful.\n\nFile: includes/batch.inc", "response": "function _batch_api_percentage($total, $current) {\n if (!$total || $total == $current) {\n // If $total doesn't evaluate as true or is equal to the current set, then\n // we're finished, and we can return \"100\".\n $percentage = \"100\";\n }\n else {\n // We add a new digit at 200, 2000, etc. (since, for example, 199/200\n // would round up to 100% if we didn't).\n $decimal_places = max(0, floor(log10($total / 2.0)) - 1);\n do {\n // Calculate the percentage to the specified number of decimal places.\n $percentage = sprintf('%01.' . $decimal_places . 'f', round($current / $total * 100, $decimal_places));\n // When $current is an integer, the above calculation will always be\n // correct. However, if $current is a floating point number (in the case\n // of a multi-step batch operation that is not yet complete), $percentage\n // may be erroneously rounded up to 100%. To prevent that, we add one\n // more decimal place and try again.\n $decimal_places++;\n } while ($percentage == '100');\n }\n return $percentage;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0207606169", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.multilingual.inc/function/field_valid_language/7.x", "instruction": "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.", "context": "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.\n\nParameters:\n- $langcode: The language code to validate.\n- $default: Whether to return the default language code or the current language code in case $langcode is invalid.\n\nReturns: A valid language code.\n\nFile: modules/field/field.multilingual.inc", "response": "function field_valid_language($langcode, $default = TRUE) {\n $enabled_languages = field_content_languages();\n if (in_array($langcode, $enabled_languages)) {\n return $langcode;\n }\n global $language_content;\n return $default ? language_default('language') : $language_content->language;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-02085339a0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_field_overview_form_validate_add_existing/7.x", "instruction": "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().", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function _field_ui_field_overview_form_validate_add_existing($form, &$form_state) {\n // The form element might be absent if no existing fields can be added to\n // this bundle.\n if (isset($form_state['values']['fields']['_add_existing_field'])) {\n $field = $form_state['values']['fields']['_add_existing_field'];\n\n // Validate if any information was provided in the 'add existing field' row.\n if (array_filter(array($field['label'], $field['field_name'], $field['widget_type']))) {\n // Missing label.\n if (!$field['label']) {\n form_set_error('fields][_add_existing_field][label', t('Add existing field: you need to provide a label.'));\n }\n\n // Missing existing field name.\n if (!$field['field_name']) {\n form_set_error('fields][_add_existing_field][field_name', t('Add existing field: you need to select a field.'));\n }\n\n // Missing widget type.\n if (!$field['widget_type']) {\n form_set_error('fields][_add_existing_field][widget_type', t('Add existing field: you need to select a widget.'));\n }\n // Wrong widget type.\n elseif ($field['field_name'] && ($existing_field = field_info_field($field['field_name']))) {\n $widget_types = field_ui_widget_type_options($existing_field['type']);\n if (!isset($widget_types[$field['widget_type']])) {\n form_set_error('fields][_add_existing_field][widget_type', t('Add existing field: invalid widget.'));\n }\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0208d01a54", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7015/7.x", "instruction": "Implement `node_update_7015()` in PHP for Drupal 7. Required behavior: Enable node types that may have been erroneously disabled in Drupal 7.36.", "context": "File: modules/node/node.install", "response": "function node_update_7015() {\n db_update('node_type')\n ->fields(array('disabled' => 0))\n ->condition('base', 'node_content')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-021abfe821", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_block_view_pre_render/7.x", "instruction": "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.", "context": "This function can be used as a #pre_render callback.\n\nFile: modules/forum/forum.module", "response": "function forum_block_view_pre_render($elements) {\n $result = $elements['#query']->execute();\n if ($node_title_list = node_title_list($result)) {\n $elements['forum_list'] = $node_title_list;\n $elements['forum_more'] = array('#theme' => 'more_link', '#url' => 'forum', '#title' => t('Read the latest forum topics.'));\n }\n return $elements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0222f8b712", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.pages.inc/function/statistics_node_tracker/7.x", "instruction": "Implement `statistics_node_tracker()` in PHP for Drupal 7. Required behavior: Page callback: Displays statistics for a node.", "context": "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().\n\nFile: modules/statistics/statistics.pages.inc", "response": "function statistics_node_tracker() {\n if ($node = node_load(arg(1))) {\n\n $header = array(\n array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),\n array('data' => t('Referrer'), 'field' => 'a.url'),\n array('data' => t('User'), 'field' => 'u.name'),\n array('data' => t('Operations')));\n\n $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');\n $query->join('users', 'u', 'a.uid = u.uid');\n\n $query\n ->fields('a', array('aid', 'timestamp', 'url', 'uid'))\n ->fields('u', array('name'))\n ->condition(db_or()\n ->condition('a.path', 'node/' . $node->nid)\n ->condition('a.path', 'node/' . $node->nid . '/%', 'LIKE'))\n ->limit(30)\n ->orderByHeader($header);\n\n $result = $query->execute();\n $rows = array();\n foreach ($result as $log) {\n $rows[] = array(\n array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),\n _statistics_link($log->url),\n theme('username', array('account' => $log)),\n l(t('details'), \"admin/reports/access/$log->aid\"),\n );\n }\n\n drupal_set_title($node->title);\n $build['statistics_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#empty' => t('No statistics available.'),\n );\n $build['statistics_pager'] = array('#theme' => 'pager');\n return $build;\n }\n return MENU_NOT_FOUND;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-023f2e9e5f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_sync_field_status/7.x", "instruction": "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.", "context": "File: modules/field/field.module", "response": "function field_sync_field_status() {\n // Refresh the 'active' and 'storage_active' columns according to the current\n // set of enabled modules.\n $modules = module_list();\n foreach ($modules as $module_name) {\n field_associate_fields($module_name);\n }\n db_update('field_config')\n ->fields(array('active' => 0))\n ->condition('module', $modules, 'NOT IN')\n ->execute();\n db_update('field_config')\n ->fields(array('storage_active' => 0))\n ->condition('storage_module', $modules, 'NOT IN')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-024a3fb0e8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_help/7.x", "instruction": "I need the code for `user_help($path, $arg)` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_help().", "context": "File: modules/user/user.module", "response": "function user_help($path, $arg) {\n global $user;\n\n switch ($path) {\n case 'admin/help#user':\n $output = '';\n $output .= '

' . t('About') . '

';\n $output .= '

' . t('The User module allows users to register, log in, and log out. It also allows users with proper permissions to manage user roles (used to classify users) and permissions associated with those roles. For more information, see the online handbook entry for User module.', array('@user' => 'http://drupal.org/documentation/modules/user')) . '

';\n $output .= '

' . t('Uses') . '

';\n $output .= '
';\n $output .= '
' . t('Creating and managing users') . '
';\n $output .= '
' . t('The User module allows users with the appropriate permissions to create user accounts through the People administration page, where they can also assign users to one or more roles, and block or delete user accounts. If allowed, users without accounts (anonymous users) can create their own accounts on the Create new account page.', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-user')), '@people' => url('admin/people'), '@register' => url('user/register'))) . '
';\n $output .= '
' . t('User roles and permissions') . '
';\n $output .= '
' . t('Roles are used to group and classify users; each user can be assigned one or more roles. By default there are two roles: anonymous user (users that are not logged in) and authenticated user (users that are registered and logged in). Depending on choices you made when you installed Drupal, the installation process may have defined more roles, and you can create additional custom roles on the Roles page. After creating roles, you can set permissions for each role on the Permissions page. Granting a permission allows users who have been assigned a particular role to perform an action on the site, such as viewing a particular type of content, editing or creating content, administering settings for a particular module, or using a particular function of the site (such as search).', array('@permissions_user' => url('admin/people/permissions'), '@roles' => url('admin/people/permissions/roles'))) . '
';\n $output .= '
' . t('Account settings') . '
';\n $output .= '
' . t('The Account settings page allows you to manage settings for the displayed name of the anonymous user role, personal contact forms, user registration, and account cancellation. On this page you can also manage settings for account personalization (including signatures and user pictures), and adapt the text for the e-mail messages that are sent automatically during the user registration process.', array('@accounts' => url('admin/config/people/accounts'))) . '
';\n $output .= '
';\n return $output;\n case 'admin/people/create':\n return '

' . t(\"This web page allows administrators to register new users. Users' e-mail addresses and usernames must be unique.\") . '

';\n case 'admin/people/permissions':\n return '

' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the Roles page to create a role). Two important roles to consider are Authenticated Users and Administrators. Any permissions granted to the Authenticated Users role will be given to any user who can log into your site. You can make any role the Administrator role for the site, meaning this will be granted all new permissions automatically. You can do this on the User Settings page. You should be careful to ensure that only trusted users are given this access and level of control of your site.', array('@role' => url('admin/people/permissions/roles'), '@settings' => url('admin/config/people/accounts'))) . '

';\n case 'admin/people/permissions/roles':\n $output = '

' . t('Roles allow you to fine tune the security and administration of Drupal. A role defines a group of users that have certain privileges as defined on the permissions page. Examples of roles include: anonymous user, authenticated user, moderator, administrator and so on. In this area you will define the names and order of the roles on your site. It is recommended to order your roles from least permissive (anonymous user) to most permissive (administrator). To delete a role choose \"edit role\".', array('@permissions' => url('admin/people/permissions'))) . '

';\n $output .= '

' . t('By default, Drupal comes with two user roles:') . '

';\n $output .= '';\n return $output;\n case 'admin/config/people/accounts/fields':\n return '

' . t('This form lets administrators add, edit, and arrange fields for storing user data.') . '

';\n case 'admin/config/people/accounts/display':\n return '

' . t('This form lets administrators configure how fields should be displayed when rendering a user profile page.') . '

';\n case 'admin/people/search':\n return '

' . t('Enter a simple pattern (\"*\" may be used as a wildcard match) to search for a username or e-mail address. For example, one may search for \"br\" and Drupal might return \"brian\", \"brad\", and \"brenda@example.com\".') . '

';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-024f59c2fd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_widget_settings/7.x", "instruction": "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.", "context": "Parameters:\n- $type: A widget type name.\n\nReturns: The widget type's default settings, as provided by hook_field_widget_info(), or an empty array if type or settings are undefined.\n\nFile: modules/field/field.info.inc", "response": "function field_info_widget_settings($type) {\n $info = field_info_widget_types($type);\n return isset($info['settings']) ? $info['settings'] : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-025140ac5c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_field_by_id/7.x", "instruction": "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.", "context": "Parameters:\n- $field_id: The id of the field to retrieve. $field_id can refer to a deleted field, but not an inactive one.\n\nReturns: 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.\n\nFile: modules/field/field.info.inc", "response": "function field_info_field_by_id($field_id) {\n $cache = _field_info_field_cache();\n return $cache->getFieldById($field_id);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-02615b3afc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_process_html/7.x", "instruction": "Implement `garland_process_html(&$variables)` in PHP for Drupal 7. Required behavior: Override or insert variables into the html template.", "context": "File: themes/garland/template.php", "response": "function garland_process_html(&$variables) {\n // Hook into color.module\n if (module_exists('color')) {\n _color_html_alter($variables);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0275a35427", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_test_get_all/7.x", "instruction": "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.", "context": "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.\n\nPSR-0 classes are found by searching the designated directory for each module for files matching the PSR-0 standard.\n\nReturns: An array of tests keyed with the groups specified in each of the tests getInfo() method and then keyed by the test class. An example of the array structure is provided below. @code $groups['Blog'] => array( 'BlogTestCase' => array( 'name' => 'Blog functionality', 'description' => 'Create, view, edit, delete, ...', 'group' => 'Blog', ), ); @endcode\n\nFile: modules/simpletest/simpletest.module", "response": "function simpletest_test_get_all() {\n $groups = &drupal_static(__FUNCTION__);\n\n if (!$groups) {\n // Register a simple class loader for PSR-0 test classes.\n simpletest_classloader_register();\n\n // Load test information from cache if available, otherwise retrieve the\n // information from each tests getInfo() method.\n if ($cache = cache_get('simpletest', 'cache')) {\n $groups = $cache->data;\n }\n else {\n // Select all classes in files ending with .test.\n $classes = db_query(\"SELECT name FROM {registry} WHERE type = :type AND filename LIKE :name\", array(':type' => 'class', ':name' => '%.test'))->fetchCol();\n\n // Also discover PSR-0 test classes, if the PHP version allows it.\n if (version_compare(PHP_VERSION, '5.3') > 0) {\n\n // Select all PSR-0 and PSR-4 classes in the Tests namespace of all\n // modules.\n $system_list = db_query(\"SELECT name, filename FROM {system}\")->fetchAllKeyed();\n\n foreach ($system_list as $name => $filename) {\n $module_dir = DRUPAL_ROOT . '/' . dirname($filename);\n // Search both the 'lib/Drupal/mymodule' directory (for PSR-0 classes)\n // and the 'src' directory (for PSR-4 classes).\n foreach(array('lib/Drupal/' . $name, 'src') as $subdir) {\n // Build directory in which the test files would reside.\n $tests_dir = $module_dir . '/' . $subdir . '/Tests';\n // Scan it for test files if it exists.\n if (is_dir($tests_dir)) {\n $files = file_scan_directory($tests_dir, '/.*\\.php/');\n if (!empty($files)) {\n foreach ($files as $file) {\n // Convert the file name into the namespaced class name.\n $replacements = array(\n '/' => '\\\\',\n $module_dir . '/' => '',\n 'lib/' => '',\n 'src/' => 'Drupal\\\\' . $name . '\\\\',\n '.php' => '',\n );\n $classes[] = strtr($file->uri, $replacements);\n }\n }\n }\n }\n }\n }\n\n // Check that each class has a getInfo() method and store the information\n // in an array keyed with the group specified in the test information.\n $groups = array();\n foreach ($classes as $class) {\n // Test classes need to implement getInfo() to be valid.\n if (class_exists($class) && method_exists($class, 'getInfo')) {\n $info = call_user_func(array($class, 'getInfo'));\n\n // If this test class requires a non-existing module, skip it.\n if (!empty($info['dependencies'])) {\n foreach ($info['dependencies'] as $module) {\n // Pass FALSE as fourth argument so no error gets created for\n // the missing file.\n $found_module = drupal_get_filename('module', $module, NULL, FALSE);\n if (!$found_module) {\n continue 2;\n }\n }\n }\n\n $groups[$info['group']][$class] = $info;\n }\n }\n\n // Sort the groups and tests within the groups by name.\n uksort($groups, 'strnatcasecmp');\n foreach ($groups as $group => &$tests) {\n uksort($tests, 'strnatcasecmp');\n }\n\n // Allow modules extending core tests to disable originals.\n drupal_alter('simpletest', $groups);\n cache_set('simpletest', $groups);\n }\n }\n return $groups;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-028c54d71e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_form_node_type_form_alter/7.x", "instruction": "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().", "context": "Adds a button 'Save and add fields' to the 'Create content type' form.\n\nFile: modules/field_ui/field_ui.module", "response": "function field_ui_form_node_type_form_alter(&$form, $form_state) {\n // We want to display the button only on add page.\n if (empty($form['#node_type']->type)) {\n $form['actions']['save_continue'] = array(\n '#type' => 'submit',\n '#value' => t('Save and add fields'),\n '#weight' => 45,\n );\n $form['#submit'][] = 'field_ui_form_node_type_form_submit';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-02a8b82b19", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7015/7.x", "instruction": "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.", "context": "File: modules/user/user.install", "response": "function user_update_7015() {\n db_change_field('users', 'signature_format', 'signature_format', array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n 'description' => 'The {filter_format}.format of the signature.',\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-02b1ee8314", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_archiver_info/7.x", "instruction": "I need the code for `system_archiver_info()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_archiver_info().", "context": "File: modules/system/system.module", "response": "function system_archiver_info() {\n $archivers['tar'] = array(\n 'class' => 'ArchiverTar',\n 'extensions' => array('tar', 'tgz', 'tar.gz', 'tar.bz2'),\n );\n if (function_exists('zip_open')) {\n $archivers['zip'] = array(\n 'class' => 'ArchiverZip',\n 'extensions' => array('zip'),\n );\n }\n return $archivers;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-02d440dd6d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_edit_validate/7.x", "instruction": "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().", "context": "Checks that the book has not been changed while using the form.\n\nFile: modules/book/book.admin.inc", "response": "function book_admin_edit_validate($form, &$form_state) {\n if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) {\n form_set_error('', t('This book has been modified by another user, the changes could not be saved.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-02e57f1d46", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/_text_sanitize/7.x", "instruction": "Implement `_text_sanitize($instance, $langcode, $item, $column)` in PHP for Drupal 7. Required behavior: Sanitizes the 'value' or 'summary' data of a text value.", "context": "Depending on whether the field instance uses text processing, data is run through check_plain() or check_markup().\n\nParameters:\n- $instance: The instance definition.\n- $langcode: The language associated to $item.\n- $item: The field value to sanitize.\n- $column: The column to sanitize (either 'value' or 'summary').\n\nReturns: The sanitized string.\n\nFile: modules/field/modules/text/text.module", "response": "function _text_sanitize($instance, $langcode, $item, $column) {\n // If the value uses a cacheable text format, text_field_load() precomputes\n // the sanitized string.\n if (isset($item[\"safe_$column\"])) {\n return $item[\"safe_$column\"];\n }\n if ($item[$column] === '') {\n return '';\n }\n return $instance['settings']['text_processing'] ? check_markup($item[$column], $item['format'], $langcode) : check_plain($item[$column]);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-02fdc2b771", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_add_date_formats_form_submit/7.x", "instruction": "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.", "context": "File: modules/system/system.admin.inc", "response": "function system_add_date_formats_form_submit($form, &$form_state) {\n $format = array();\n $format['format'] = trim($form_state['values']['date_format']);\n $format['type'] = 'custom';\n $format['locked'] = 0;\n if (!empty($form_state['values']['dfid'])) {\n system_date_format_save($format, $form_state['values']['dfid']);\n drupal_set_message(t('Custom date format updated.'));\n }\n else {\n $format['is_new'] = 1;\n system_date_format_save($format);\n drupal_set_message(t('Custom date format added.'));\n }\n\n $form_state['redirect'] = 'admin/config/regional/date-time/formats';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0310d573d9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/_dblog_get_message_types/7.x", "instruction": "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.", "context": "Returns (array): List of uniquely defined database log message types.\n\nFile: modules/dblog/dblog.module", "response": "function _dblog_get_message_types() {\n $types = array();\n\n $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');\n foreach ($result as $object) {\n $types[] = $object->type;\n }\n\n return $types;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0341d0d156", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_help/7.x", "instruction": "Implement `menu_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/menu/menu.module", "response": "function menu_help($path, $arg) {\n switch ($path) {\n case 'admin/help#menu':\n $output = '';\n $output .= '

' . t('About') . '

';\n $output .= '

' . 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 site, generally used for navigation. Each menu is rendered in a block that can be enabled and positioned through the Blocks administration page. You can view and manage menus on the Menus administration page. For more information, see the online handbook entry for the Menu module.', array('@blocks' => url('admin/structure/block'), '@menus' => url('admin/structure/menu'), '@menu' => 'http://drupal.org/documentation/modules/menu/')) . '

';\n $output .= '

' . t('Uses') . '

';\n $output .= '
';\n $output .= '
' . t('Managing menus') . '
';\n $output .= '
' . t('Users with the Administer menus and menu items permission can add, edit and delete custom menus on the Menus administration page. Custom menus can be special site menus, menus of external links, or any combination of internal and external links. You may create an unlimited number of additional menus, each of which will automatically have an associated block. By selecting list links, you can add, edit, or delete links for a given menu. The links listing page provides a drag-and-drop interface for controlling the order of links, and creating a hierarchy within the menu.', array('@menu' => url('admin/structure/menu'), '@add-menu' => url('admin/structure/menu/add'))) . '
';\n $output .= '
' . t('Displaying menus') . '
';\n $output .= '
' . t('After you have created a menu, you must enable and position the associated block on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '
';\n $output .= '
';\n return $output;\n case 'admin/structure/menu/add':\n return '

' . t('You can enable the newly-created block for this menu on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '

';\n }\n if ($path == 'admin/structure/menu' && module_exists('block')) {\n return '

' . t('Each menu has a corresponding block that is managed on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '

';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-03574cf63b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_process/7.x", "instruction": "Implement `template_process(&$variables, $hook)` in PHP for Drupal 7. Required behavior: Adds helper variables derived from variables defined during preprocessing.", "context": "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).\n\nThis function serializes array variables manipulated during the preprocessing phase into strings for convenient use by templates. As with template_preprocess(), this function does not get called for theme hooks implemented as functions.\n\nFile: includes/theme.inc", "response": "function template_process(&$variables, $hook) {\n // Flatten out classes.\n $variables['classes'] = implode(' ', $variables['classes_array']);\n\n // Flatten out attributes, title_attributes, and content_attributes.\n // Because this function can be called very often, and often with empty\n // attributes, optimize performance by only calling drupal_attributes() if\n // necessary.\n $variables['attributes'] = $variables['attributes_array'] ? drupal_attributes($variables['attributes_array']) : '';\n $variables['title_attributes'] = $variables['title_attributes_array'] ? drupal_attributes($variables['title_attributes_array']) : '';\n $variables['content_attributes'] = $variables['content_attributes_array'] ? drupal_attributes($variables['content_attributes_array']) : '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-038d6722fc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_node_update_index/7.x", "instruction": "Implement `search_node_update_index($node)` in PHP for Drupal 7. Required behavior: Implements hook_node_update_index().", "context": "File: modules/search/search.module", "response": "function search_node_update_index($node) {\n // Transplant links to a node into the target node.\n $result = db_query(\"SELECT caption FROM {search_node_links} WHERE nid = :nid\", array(':nid' => $node->nid), array('target' => 'slave'));\n $output = array();\n foreach ($result as $link) {\n $output[] = $link->caption;\n }\n if (count($output)) {\n return '(' . implode(', ', $output) . ')';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-039ab61e8b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_username/7.x", "instruction": "Implement `rdf_preprocess_username(&$variables)` in PHP for Drupal 7. Required behavior: Implements MODULE_preprocess_HOOK().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_preprocess_username(&$variables) {\n // Because xml:lang is set on the HTML element that wraps the page, the\n // username inherits this language attribute. However, since the username\n // might not be transliterated to the same language that the content is in,\n // we do not want it to inherit the language attribute, so we set the\n // attribute to an empty string.\n if (empty($variables['attributes_array']['xml:lang'])) {\n $variables['attributes_array']['xml:lang'] = '';\n }\n\n // $variables['account'] is a pseudo account object, and as such, does not\n // contain the RDF mappings for the user. In the case of nodes and comments,\n // it contains the mappings for the node or comment object instead. However,\n // while the RDF mappings are available from a full user_load(), this should\n // be avoided for performance reasons. Since the type and bundle for users is\n // already known, call rdf_mapping_load() directly.\n $rdf_mapping = rdf_mapping_load('user', 'user');\n\n // The profile URI is used to identify the user account. The about attribute\n // is used to set the URI as the default subject of the predicates embedded\n // as RDFa in the child elements. Even if the user profile is not accessible\n // to the current user, we use its URI in order to identify the user in RDF.\n // We do not use this attribute for the anonymous user because we do not have\n // a user profile URI for it (only a homepage which cannot be used as user\n // profile in RDF.)\n if ($variables['uid'] > 0) {\n $variables['attributes_array']['about'] = url('user/' . $variables['uid']);\n }\n\n $attributes = array();\n // The typeof attribute specifies the RDF type(s) of this resource. They\n // are defined in the 'rdftype' property of the user RDF mapping.\n if (!empty($rdf_mapping['rdftype'])) {\n $attributes['typeof'] = $rdf_mapping['rdftype'];\n }\n // Annotate the username in RDFa. A property attribute is used with an empty\n // datatype attribute to ensure the username is parsed as a plain literal\n // in RDFa 1.0 and 1.1.\n if (!empty($rdf_mapping['name'])) {\n $attributes['property'] = $rdf_mapping['name']['predicates'];\n $attributes['datatype'] = '';\n }\n // Add the homepage RDFa markup if present.\n if (!empty($variables['homepage']) && !empty($rdf_mapping['homepage'])) {\n $attributes['rel'] = $rdf_mapping['homepage']['predicates'];\n }\n // The remaining attributes can have multiple values listed, with whitespace\n // separating the values in the RDFa attributes\n // (see http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes).\n // Therefore, merge rather than override so as not to clobber values set by\n // earlier preprocess functions.\n $variables['attributes_array'] = array_merge_recursive($variables['attributes_array'], $attributes);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-03a772d0d5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_file_move/7.x", "instruction": "Implement `user_file_move($file, $source)` in PHP for Drupal 7. Required behavior: Implements hook_file_move().", "context": "File: modules/user/user.module", "response": "function user_file_move($file, $source) {\n // If a user's picture is replaced with a new one, update the record in\n // the users table.\n if (isset($file->fid) && isset($source->fid) && $file->fid != $source->fid) {\n db_update('users')\n ->fields(array(\n 'picture' => $file->fid,\n ))\n ->condition('picture', $source->fid)\n ->execute();\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-03e5f4241d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/_node_types_build/7.x", "instruction": "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.", "context": "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.\n\nParameters:\n- $rebuild: TRUE to rebuild node types. Equivalent to calling node_types_rebuild().\n\nReturns: An object with two properties: - names: Associative array of the names of node types, keyed by the type. - types: Associative array of node type objects, keyed by the type. Both of these arrays will include new types that have been defined by hook_node_info() implementations but not yet saved in the {node_type} table. These are indicated in the type object by $type->is_new being set to the value 1. These arrays will also include obsolete types: types that were previously defined by modules that have now been disabled, or for whatever reason are no longer being defined in hook_node_info() implementations, but are still in the database. These are indicated in the type object by $type->disabled being set to TRUE.\n\nFile: modules/node/node.module", "response": "function _node_types_build($rebuild = FALSE) {\n $cid = 'node_types:' . $GLOBALS['language']->language;\n\n if (!$rebuild) {\n $_node_types = &drupal_static(__FUNCTION__);\n if (isset($_node_types)) {\n return $_node_types;\n }\n if ($cache = cache_get($cid)) {\n $_node_types = $cache->data;\n return $_node_types;\n }\n }\n\n $_node_types = (object) array('types' => array(), 'names' => array());\n\n foreach (module_implements('node_info') as $module) {\n $info_array = module_invoke($module, 'node_info');\n foreach ($info_array as $type => $info) {\n $info['type'] = $type;\n $_node_types->types[$type] = node_type_set_defaults($info);\n $_node_types->types[$type]->module = $module;\n $_node_types->names[$type] = $info['name'];\n }\n }\n $query = db_select('node_type', 'nt')\n ->addTag('translatable')\n ->addTag('node_type_access')\n ->fields('nt')\n ->orderBy('nt.type', 'ASC');\n if (!$rebuild) {\n $query->condition('disabled', 0);\n }\n foreach ($query->execute() as $type_object) {\n $type_db = $type_object->type;\n // Original disabled value.\n $disabled = $type_object->disabled;\n // Check for node types from disabled modules and mark their types for removal.\n // Types defined by the node module in the database (rather than by a separate\n // module using hook_node_info) have a base value of 'node_content'. The isset()\n // check prevents errors on old (pre-Drupal 7) databases.\n if (isset($type_object->base) && $type_object->base != 'node_content' && empty($_node_types->types[$type_db])) {\n $type_object->disabled = TRUE;\n }\n if (isset($_node_types->types[$type_db])) {\n $type_object->disabled = FALSE;\n }\n if (!isset($_node_types->types[$type_db]) || $type_object->modified) {\n $_node_types->types[$type_db] = $type_object;\n $_node_types->names[$type_db] = $type_object->name;\n\n if ($type_db != $type_object->orig_type) {\n unset($_node_types->types[$type_object->orig_type]);\n unset($_node_types->names[$type_object->orig_type]);\n }\n }\n $_node_types->types[$type_db]->disabled = $type_object->disabled;\n $_node_types->types[$type_db]->disabled_changed = $disabled != $type_object->disabled;\n }\n\n if ($rebuild) {\n foreach ($_node_types->types as $type => $type_object) {\n if (!empty($type_object->is_new) || !empty($type_object->disabled_changed)) {\n node_type_save($type_object);\n }\n }\n }\n\n asort($_node_types->names);\n\n cache_set($cid, $_node_types);\n\n return $_node_types;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-03ee44f890", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.admin.inc/function/contact_category_delete_form_submit/7.x", "instruction": "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().", "context": "File: modules/contact/contact.admin.inc", "response": "function contact_category_delete_form_submit($form, &$form_state) {\n $contact = $form['contact']['#value'];\n\n db_delete('contact')\n ->condition('cid', $contact['cid'])\n ->execute();\n\n drupal_set_message(t('Category %category has been deleted.', array('%category' => $contact['category'])));\n watchdog('contact', 'Category %category has been deleted.', array('%category' => $contact['category']), WATCHDOG_NOTICE);\n\n $form_state['redirect'] = 'admin/structure/contact';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-03fb5373dd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21image.inc/function/image_save/7.x", "instruction": "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.", "context": "Parameters:\n- $image: An image object returned by image_load(). The object's 'info' property will be updated if the file is saved successfully.\n- $destination: Destination path where the image should be saved. If it is empty the original image file will be overwritten.\n\nReturns: TRUE on success, FALSE on failure.\n\nFile: includes/image.inc", "response": "function image_save(stdClass $image, $destination = NULL) {\n if (empty($destination)) {\n $destination = $image->source;\n }\n if ($return = image_toolkit_invoke('save', $image, array($destination))) {\n // Clear the cached file size and refresh the image information.\n clearstatcache();\n $image->info = image_get_info($destination, $image->toolkit);\n\n if (drupal_chmod($destination)) {\n return $return;\n }\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-04006d91dc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_help/7.x", "instruction": "I need the code for `statistics_help($path, $arg)` in Drupal 7 (modules/statistics/statistics.module). It must do this: Implements hook_help().", "context": "File: modules/statistics/statistics.module", "response": "function statistics_help($path, $arg) {\n switch ($path) {\n case 'admin/help#statistics':\n $output = '';\n $output .= '

' . t('About') . '

';\n $output .= '

' . t('The Statistics module shows you how often a given page is viewed, who viewed it, the previous page the user visited (referrer URL), and when it was viewed. These statistics are useful in determining how users are visiting and navigating your site. For more information, see the online handbook entry for the Statistics module.', array('@statistics' => url('http://drupal.org/documentation/modules/statistics/'))) . '

';\n $output .= '

' . t('Uses') . '

';\n $output .= '
';\n $output .= '
' . t('Managing logs') . '
';\n $output .= '
' . t('To enable collection of statistics, the Enable access log checkbox on the Statistics settings page must be checked. The Discard access logs older than setting on the settings page specifies the length of time entries are kept in the log before they are deleted. This setting requires a correctly configured cron maintenance task to run.', array('@statistics-settings' => url('admin/config/system/statistics'), '@cron' => 'http://drupal.org/cron')) . '
';\n $output .= '
' . t('Viewing site usage') . '
';\n $output .= '
' . t('The Statistics module can help you break down details about your users and how they are using the site. The module offers four reports:');\n $output .= '
  • ' . t('Recent hits displays information about the latest activity on your site, including the URL and title of the page that was accessed, the user name (if available) and the IP address of the viewer.', array('@recent-hits' => url('admin/reports/hits'))) . '
  • ';\n $output .= '
  • ' . t('Top referrers displays where visitors came from (referrer URL).', array('@top-referrers' => url('admin/reports/referrers'))) . '
  • ';\n $output .= '
  • ' . t('Top pages displays a list of pages ordered by how often they were viewed.', array('@top-pages' => url('admin/reports/pages'))) . '
  • ';\n $output .= '
  • ' . t('Top visitors shows you the most active visitors for your site and allows you to ban abusive visitors.', array('@top-visitors' => url('admin/reports/visitors'))) . '
';\n $output .= '
' . t('Displaying popular content') . '
';\n $output .= '
' . t('The module includes a Popular content block that displays the most viewed pages today and for all time, and the last content viewed. To use the block, enable Count content views on the statistics settings page, and then you can enable and configure the block on the blocks administration page.', array('@statistics-settings' => url('admin/config/system/statistics'), '@blocks' => url('admin/structure/block'))) . '
';\n $output .= '
' . t('Page view counter') . '
';\n $output .= '
' . t('The Statistics module includes a counter for each page that increases whenever the page is viewed. To use the counter, enable Count content views on the statistics settings page, and set the necessary permissions (View content hits) so that the counter is visible to the users.', array('@statistics-settings' => url('admin/config/system/statistics'), '@permissions' => url('admin/people/permissions', array('fragment' => 'module-statistics')))) . '
';\n $output .= '
';\n return $output;\n case 'admin/config/system/statistics':\n return '

' . t('Settings for the statistical information that Drupal will keep about the site. See site statistics for the actual information.', array('@statistics' => url('admin/reports/hits'))) . '

';\n case 'admin/reports/hits':\n return '

' . t(\"This page displays the site's most recent hits.\") . '

';\n case 'admin/reports/referrers':\n return '

' . t('This page displays all external referrers, or external references to your website.') . '

';\n case 'admin/reports/visitors':\n return '

' . t(\"When you ban a visitor, you prevent the visitor's IP address from accessing your site. Unlike blocking a user, banning a visitor works even for anonymous users. This is most commonly used to block resource-intensive bots or web crawlers.\") . '

';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0426e54396", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_form_validate/7.x", "instruction": "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.", "context": "File: modules/profile/profile.module", "response": "function profile_user_form_validate($form, &$form_state) {\n $result = _profile_get_fields($form['#user_category'], $form['#user_category'] == 'register');\n foreach ($result as $field) {\n if (!empty($form_state['values'][$field->name])) {\n if ($field->type == 'url' && !valid_url($form_state['values'][$field->name], TRUE)) {\n form_set_error($field->name, t('The value provided for %field is not a valid URL.', array('%field' => $field->title)));\n }\n }\n elseif ($field->required && !user_access('administer users')) {\n form_set_error($field->name, t('The field %field is required.', array('%field' => $field->title)));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0450fedd46", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_purge/7.x", "instruction": "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.", "context": "Called from field_purge_data() to allow the field storage module to delete field data information.\n\nParameters:\n- $entity_type: The type of $entity; for example, 'node' or 'user'.\n- $entity: The pseudo-entity whose field data to delete.\n- $field: The (possibly deleted) field whose data is being purged.\n- $instance: The deleted field instance whose data is being purged.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_purge($entity_type, $entity, $field, $instance) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n $table_name = _field_sql_storage_tablename($field);\n $revision_name = _field_sql_storage_revision_tablename($field);\n db_delete($table_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $id)\n ->execute();\n db_delete($revision_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $id)\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0472a21e20", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_date_format_types_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_date_format_types_alter(&$types)` (modules/system/system.api.php): Modify existing date types.", "context": "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.\n\nParameters:\n- $types: A list of date types. Each date type is keyed by the machine-readable name and the values are associative arrays containing: - is_new: Set to FALSE to override previous settings. - module: The name of the module that created the date type. - type: The machine-readable date type name. - title: The human-readable date type name. - locked: Specifies that the date type is system-provided.\n\nFile: modules/system/system.api.php", "response": "function hook_date_format_types_alter(&$types) {\n foreach ($types as $name => $type) {\n $types[$name]['locked'] = 1;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0473e75be7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_entity_info_alter/7.x", "instruction": "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().", "context": "File: modules/forum/forum.module", "response": "function forum_entity_info_alter(&$info) {\n // Take over URI construction for taxonomy terms that are forums.\n if ($vid = variable_get('forum_nav_vocabulary', 0)) {\n // Within hook_entity_info(), we can't invoke entity_load() as that would\n // cause infinite recursion, so we call taxonomy_vocabulary_get_names()\n // instead of taxonomy_vocabulary_load(). All we need is the machine name\n // of $vid, so retrieving and iterating all the vocabulary names is somewhat\n // inefficient, but entity info is cached across page requests, and an\n // iteration of all vocabularies once per cache clearing isn't a big deal,\n // and is done as part of taxonomy_entity_info() anyway.\n foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) {\n if ($vid == $vocabulary->vid) {\n $info['taxonomy_term']['bundles'][$machine_name]['uri callback'] = 'forum_uri';\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-04949cf640", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_rdf_mapping/7.x", "instruction": "Implement `node_rdf_mapping()` in PHP for Drupal 7. Required behavior: Implements hook_rdf_mapping().", "context": "File: modules/node/node.module", "response": "function node_rdf_mapping() {\n return array(\n array(\n 'type' => 'node',\n 'bundle' => RDF_DEFAULT_BUNDLE,\n 'mapping' => array(\n 'rdftype' => array('sioc:Item', 'foaf:Document'),\n 'title' => array(\n 'predicates' => array('dc:title'),\n ),\n 'created' => array(\n 'predicates' => array('dc:date', 'dc:created'),\n 'datatype' => 'xsd:dateTime',\n 'callback' => 'date_iso8601',\n ),\n 'changed' => array(\n 'predicates' => array('dc:modified'),\n 'datatype' => 'xsd:dateTime',\n 'callback' => 'date_iso8601',\n ),\n 'body' => array(\n 'predicates' => array('content:encoded'),\n ),\n 'uid' => array(\n 'predicates' => array('sioc:has_creator'),\n 'type' => 'rel',\n ),\n 'name' => array(\n 'predicates' => array('foaf:name'),\n ),\n 'comment_count' => array(\n 'predicates' => array('sioc:num_replies'),\n 'datatype' => 'xsd:integer',\n ),\n 'last_activity' => array(\n 'predicates' => array('sioc:last_activity_date'),\n 'datatype' => 'xsd:dateTime',\n 'callback' => 'date_iso8601',\n ),\n ),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0494c22ca2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_css/7.x", "instruction": "Implement `ajax_command_css($selector, $argument)` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'css' command.", "context": "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.\n\nThis command is implemented by Drupal.ajax.prototype.commands.css() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n- $argument: An array of key/value pairs to set in the CSS for the selector.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_css($selector, $argument) {\n return array(\n 'command' => 'css',\n 'selector' => $selector,\n 'argument' => $argument,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-04974522ca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_delete_menu_confirm/7.x", "instruction": "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.", "context": "File: modules/menu/menu.admin.inc", "response": "function menu_delete_menu_confirm($form, &$form_state, $menu) {\n $form['#menu'] = $menu;\n $caption = '';\n $num_links = db_query(\"SELECT COUNT(*) FROM {menu_links} WHERE menu_name = :menu\", array(':menu' => $menu['menu_name']))->fetchField();\n if ($num_links) {\n $caption .= '

' . format_plural($num_links, 'Warning: There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', 'Warning: There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $menu['title'])) . '

';\n }\n $caption .= '

' . t('This action cannot be undone.') . '

';\n return confirm_form($form, t('Are you sure you want to delete the custom menu %title?', array('%title' => $menu['title'])), 'admin/structure/menu/manage/' . $menu['menu_name'], $caption, t('Delete'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-049fa22d57", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_deliver/7.x", "instruction": "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.", "context": "This function is the equivalent of drupal_deliver_html_page(), but for Ajax\nrequests. Like that function, it:\n- Adds needed HTTP headers.\n- Prints rendered output.\n- Performs end-of-request tasks.\n\nParameters:\n- $page_callback_result: The result of a page callback. Can be one of: - NULL: to indicate no content. - An integer menu status constant: to indicate an error condition. - A string of HTML content. - A renderable array of content.\n\nFile: includes/ajax.inc", "response": "function ajax_deliver($page_callback_result) {\n // Browsers do not allow JavaScript to read the contents of a user's local\n // files. To work around that, the jQuery Form plugin submits forms containing\n // a file input element to an IFRAME, instead of using XHR. Browsers do not\n // normally expect JSON strings as content within an IFRAME, so the response\n // must be customized accordingly.\n // @see http://malsup.com/jquery/form/#file-upload\n // @see Drupal.ajax.prototype.beforeSend()\n $iframe_upload = !empty($_POST['ajax_iframe_upload']);\n\n // Emit a Content-Type HTTP header if none has been added by the page callback\n // or by a wrapping delivery callback.\n if (is_null(drupal_get_http_header('Content-Type'))) {\n if (!$iframe_upload) {\n // Standard JSON can be returned to a browser's XHR object, and to\n // non-browser user agents.\n // @see http://www.ietf.org/rfc/rfc4627.txt?number=4627\n drupal_add_http_header('Content-Type', 'application/json; charset=utf-8');\n }\n else {\n // Browser IFRAMEs expect HTML. With most other content types, Internet\n // Explorer presents the user with a download prompt.\n drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');\n }\n }\n\n // Let ajax.js know that this response is safe to process.\n ajax_set_verification_header();\n\n // Print the response.\n $commands = ajax_prepare_response($page_callback_result);\n $json = ajax_render($commands);\n if (!$iframe_upload) {\n // Standard JSON can be returned to a browser's XHR object, and to\n // non-browser user agents.\n print $json;\n }\n else {\n // Browser IFRAMEs expect HTML. Browser extensions, such as Linkification\n // and Skype's Browser Highlighter, convert URLs, phone numbers, etc. into\n // links. This corrupts the JSON response. Protect the integrity of the\n // JSON data by making it the value of a textarea.\n // @see http://malsup.com/jquery/form/#file-upload\n // @see http://drupal.org/node/1009382\n print '';\n }\n\n // Perform end-of-request tasks.\n ajax_footer();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-04d6d23c80", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_desaturate/7.x", "instruction": "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.", "context": "Note that transparent GIFs loose transparency when desaturated.\n\nParameters:\n- $image: An image object. The $image->resource value will be modified by this call.\n\nReturns: TRUE or FALSE, based on success.\n\nFile: modules/system/image.gd.inc", "response": "function image_gd_desaturate(stdClass $image) {\n // PHP installations using non-bundled GD do not have imagefilter.\n if (!function_exists('imagefilter')) {\n watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $image->source));\n return FALSE;\n }\n\n return imagefilter($image->resource, IMG_FILTER_GRAYSCALE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-04dafff6db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_formatter_prepare_view/7.x", "instruction": "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().", "context": "This preloads all taxonomy terms for multiple loaded objects at once and unsets values for invalid terms that do not exist.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) {\n $tids = array();\n\n // Collect every possible term attached to any of the fieldable entities.\n foreach ($entities as $id => $entity) {\n foreach ($items[$id] as $delta => $item) {\n // Force the array key to prevent duplicates.\n if ($item['tid'] !== 'autocreate') {\n $tids[$item['tid']] = $item['tid'];\n }\n }\n }\n if ($tids) {\n $terms = taxonomy_term_load_multiple(array_filter($tids));\n\n // Iterate through the fieldable entities again to attach the loaded term data.\n foreach ($entities as $id => $entity) {\n $rekey = FALSE;\n\n foreach ($items[$id] as $delta => $item) {\n // Check whether the taxonomy term field instance value could be loaded.\n if (isset($terms[$item['tid']])) {\n // Replace the instance value with the term data.\n $items[$id][$delta]['taxonomy_term'] = $terms[$item['tid']];\n }\n // Terms to be created are not in $terms, but are still legitimate.\n elseif ($item['tid'] === 'autocreate') {\n // Leave the item in place.\n }\n // Otherwise, unset the instance value, since the term does not exist.\n else {\n unset($items[$id][$delta]);\n $rekey = TRUE;\n }\n }\n\n if ($rekey) {\n // Rekey the items array.\n $items[$id] = array_values($items[$id]);\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-04f661437e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_user_view/7.x", "instruction": "Implement `blog_user_view($account)` in PHP for Drupal 7. Required behavior: Implements hook_user_view().", "context": "File: modules/blog/blog.module", "response": "function blog_user_view($account) {\n if (user_access('create blog content', $account)) {\n $account->content['summary']['blog'] = array(\n '#type' => 'user_profile_item',\n '#title' => t('Blog'),\n // l() escapes the attributes, so we should not escape !username here.\n '#markup' => l(t('View recent blog entries'), \"blog/$account->uid\", array('attributes' => array('title' => t(\"Read !username's latest blog entries.\", array('!username' => format_username($account)))))),\n '#attributes' => array('class' => array('blog')),\n );\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-04f8d5d4bf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_attributes/7.x", "instruction": "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.", "context": "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).\n\nAttribute values are sanitized by running them through check_plain(). Attribute names are not automatically sanitized. When using user-supplied attribute names, it is strongly recommended to allow only white-listed names, since certain attributes carry security risks and can be abused.\n\nExamples of security aspects when using drupal_attributes:\n\nParameters:\n- $attributes: An associative array of key-value pairs to be converted to attributes.\n\nReturns: A string ready for insertion in a tag (starts with a space).\n\nFile: includes/common.inc", "response": "function drupal_attributes(array $attributes = array()) {\n foreach ($attributes as $attribute => &$data) {\n $data = implode(' ', (array) $data);\n $data = $attribute . '=\"' . check_plain($data) . '\"';\n }\n return $attributes ? ' ' . implode(' ', $attributes) : '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0500051ad4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.install/function/filter_update_7003/7.x", "instruction": "Implement `filter_update_7003()` in PHP for Drupal 7. Required behavior: Upgrade the {filter} table for core filters.", "context": "File: modules/filter/filter.install", "response": "function filter_update_7003() {\n // Duplicates the {filters} table since core cannot take care of the potential\n // contributed module filters.\n db_rename_table('filters', 'd6_upgrade_filter');\n // Creates the Drupal 7 filter table.\n $filter_table = array(\n 'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',\n 'fields' => array(\n 'format' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',\n ),\n 'module' => array(\n 'type' => 'varchar',\n 'length' => 64,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The origin module of the filter.',\n ),\n 'name' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Name of the filter being referenced.',\n ),\n 'weight' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Weight of filter within format.',\n ),\n 'status' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Filter enabled status. (1 = enabled, 0 = disabled)',\n ),\n 'settings' => array(\n 'type' => 'blob',\n 'not null' => FALSE,\n 'size' => 'big',\n 'serialize' => TRUE,\n 'description' => 'A serialized array of name value pairs that store the filter settings for the specific format.',\n ),\n ),\n 'primary key' => array('format', 'name'),\n 'indexes' => array(\n 'list' => array('weight', 'module', 'name'),\n ),\n );\n db_create_table('filter', $filter_table);\n\n // Get an array of the renamed filter deltas, organized by module.\n $renamed_deltas = array(\n 'filter' => array(\n '0' => 'filter_html',\n '1' => 'filter_autop',\n '2' => 'filter_url',\n '3' => 'filter_htmlcorrector',\n '4' => 'filter_html_escape',\n ),\n 'php' => array(\n '0' => 'php_code',\n ),\n );\n\n // Loop through each filter and make changes to the core filter table by\n // each record from the old to the new table.\n foreach ($renamed_deltas as $module => $deltas) {\n foreach ($deltas as $old_delta => $new_name) {\n $query = db_select('d6_upgrade_filter')\n ->fields('d6_upgrade_filter', array('format', 'weight'))\n ->condition('module', $module)\n ->condition('delta', $old_delta)\n ->distinct();\n\n foreach ($query->execute() as $record) {\n // Port the filter settings.\n $settings = array();\n if ($new_name == 'filter_html') {\n if ($setting = variable_get(\"allowed_html_{$record->format}\", NULL)) {\n $settings['allowed_html'] = $setting;\n variable_del(\"allowed_html_{$record->format}\");\n }\n if ($setting = variable_get(\"filter_html_help_{$record->format}\", NULL)) {\n $settings['filter_html_help'] = $setting;\n variable_del(\"filter_html_help_{$record->format}\");\n }\n if ($setting = variable_get(\"filter_html_nofollow_{$record->format}\", NULL)) {\n $settings['filter_html_nofollow'] = $setting;\n variable_del(\"filter_html_nofollow_{$record->format}\");\n }\n }\n elseif ($new_name == 'filter_url') {\n if ($setting = variable_get(\"filter_url_length_{$record->format}\", NULL)) {\n $settings['filter_url_length'] = $setting;\n variable_del(\"filter_url_length_{$record->format}\");\n }\n }\n\n db_insert('filter')\n ->fields(array(\n 'format' => $record->format,\n 'module' => $module,\n 'name' => $new_name,\n 'weight' => $record->weight,\n 'settings' => serialize($settings),\n 'status' => 1,\n ))\n ->execute();\n }\n db_delete('d6_upgrade_filter')\n ->condition('module', $module)\n ->condition('delta', $old_delta)\n ->execute();\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-051bb95452", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_hook_info/7.x", "instruction": "I need the code for `system_hook_info()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_hook_info().", "context": "File: modules/system/system.module", "response": "function system_hook_info() {\n $hooks['token_info'] = array(\n 'group' => 'tokens',\n );\n $hooks['token_info_alter'] = array(\n 'group' => 'tokens',\n );\n $hooks['tokens'] = array(\n 'group' => 'tokens',\n );\n $hooks['tokens_alter'] = array(\n 'group' => 'tokens',\n );\n\n return $hooks;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0520c8f124", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_install_system/7.x", "instruction": "In Drupal 7, write the function `drupal_install_system()` (file includes/install.inc) so that it does the following: Installs the system module.", "context": "Separated from the installation of other modules so core system functions can be made available while other modules are installed.\n\nFile: includes/install.inc", "response": "function drupal_install_system() {\n $system_path = drupal_get_path('module', 'system');\n require_once DRUPAL_ROOT . '/' . $system_path . '/system.install';\n module_invoke('system', 'install');\n\n $system_versions = drupal_get_schema_versions('system');\n $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED;\n db_insert('system')\n ->fields(array('filename', 'name', 'type', 'owner', 'status', 'schema_version', 'bootstrap'))\n ->values(array(\n 'filename' => $system_path . '/system.module',\n 'name' => 'system',\n 'type' => 'module',\n 'owner' => '',\n 'status' => 1,\n 'schema_version' => $system_version,\n 'bootstrap' => 0,\n ))\n ->execute();\n system_rebuild_module_data();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-05262ce4b3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.api.php/function/hook_field_formatter_settings_form/7.x", "instruction": "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.", "context": "This hook is only invoked if hook_field_formatter_settings_summary() returns a non-empty value.\n\nParameters:\n- $field: The field structure being configured.\n- $instance: The instance structure being configured.\n- $view_mode: The view mode being configured.\n- $form: The (entire) configuration form array, which will usually have no use here.\n- $form_state: The form state of the (entire) configuration form.\n\nReturns: The form elements for the formatter settings.\n\nFile: modules/field_ui/field_ui.api.php", "response": "function hook_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {\n $display = $instance['display'][$view_mode];\n $settings = $display['settings'];\n\n $element = array();\n\n if ($display['type'] == 'text_trimmed' || $display['type'] == 'text_summary_or_trimmed') {\n $element['trim_length'] = array(\n '#title' => t('Length'),\n '#type' => 'textfield',\n '#size' => 20,\n '#default_value' => $settings['trim_length'],\n '#element_validate' => array('element_validate_integer_positive'),\n '#required' => TRUE,\n );\n }\n\n return $element;\n\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0529b9ae92", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_load/7.x", "instruction": "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.", "context": "This prevents including a theme, engine, module, etc., more than once.\n\nParameters:\n- $type: The type of item to load (i.e. theme, theme_engine, module).\n- $name: The name of the item to load.\n\nReturns: TRUE if the item is loaded or has already been loaded.\n\nFile: includes/bootstrap.inc", "response": "function drupal_load($type, $name) {\n // Once a file is included this can't be reversed during a request so do not\n // use drupal_static() here.\n static $files = array();\n\n if (isset($files[$type][$name])) {\n return TRUE;\n }\n\n $filename = drupal_get_filename($type, $name);\n\n if ($filename) {\n include_once DRUPAL_ROOT . '/' . $filename;\n $files[$type][$name] = TRUE;\n\n return TRUE;\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0567c250ca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7012/7.x", "instruction": "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.", "context": "File: modules/user/user.install", "response": "function user_update_7012(&$sandbox) {\n\n $picture_field = array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => \"Foreign key: {file_managed}.fid of user's picture.\",\n );\n\n if (!isset($sandbox['progress'])) {\n // Check that the field hasn't been updated in an aborted run of this\n // update.\n if (!db_field_exists('users', 'picture_fid')) {\n // Add a new field for the fid.\n db_add_field('users', 'picture_fid', $picture_field);\n }\n\n // Initialize batch update information.\n $sandbox['progress'] = 0;\n $sandbox['last_user_processed'] = -1;\n $sandbox['max'] = db_query(\"SELECT COUNT(*) FROM {users} WHERE picture <> ''\")->fetchField();\n }\n\n // As a batch operation move the photos into the {file_managed} table and\n // update the {users} records.\n $limit = 500;\n $result = db_query_range(\"SELECT uid, picture FROM {users} WHERE picture <> '' AND uid > :uid ORDER BY uid\", 0, $limit, array(':uid' => $sandbox['last_user_processed']));\n foreach ($result as $user) {\n // Don't bother adding files that don't exist.\n if (file_exists($user->picture)) {\n\n // Check if the file already exists.\n $files = file_load_multiple(array(), array('uri' => $user->picture));\n if (count($files)) {\n $file = reset($files);\n }\n else {\n // Create a file object.\n $file = new stdClass();\n $file->uri = $user->picture;\n $file->filename = drupal_basename($file->uri);\n $file->filemime = file_get_mimetype($file->uri);\n $file->uid = $user->uid;\n $file->status = FILE_STATUS_PERMANENT;\n $file = file_save($file);\n }\n\n db_update('users')\n ->fields(array('picture_fid' => $file->fid))\n ->condition('uid', $user->uid)\n ->execute();\n }\n\n // Update our progress information for the batch update.\n $sandbox['progress']++;\n $sandbox['last_user_processed'] = $user->uid;\n }\n\n // Indicate our current progress to the batch update system. If there's no\n // max value then there's nothing to update and we're finished.\n $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);\n\n // When we're finished, drop the old picture field and rename the new one to\n // replace it.\n if (isset($sandbox['#finished']) && $sandbox['#finished'] == 1) {\n db_drop_field('users', 'picture');\n db_change_field('users', 'picture_fid', 'picture', $picture_field);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-057889df3a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_expand_cjk/7.x", "instruction": "Implement `search_expand_cjk($matches)` in PHP for Drupal 7. Required behavior: Splits CJK (Chinese, Japanese, Korean) text into tokens.", "context": "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, overlapping sequences of characters whose length is equal to the 'minimum_word_size' variable. This tokenizing is only done if the 'overlap_cjk' variable is TRUE.\n\nParameters:\n- $matches: This function is a callback for preg_replace_callback(), which is called from search_simplify(). So, $matches is an array of regular expression matches, which means that $matches[0] contains the matched text -- a string of CJK characters to tokenize.\n\nReturns: Tokenized text, starting and ending with a space character.\n\nFile: modules/search/search.module", "response": "function search_expand_cjk($matches) {\n $min = variable_get('minimum_word_size', 3);\n $str = $matches[0];\n $length = drupal_strlen($str);\n // If the text is shorter than the minimum word size, don't tokenize it.\n if ($length <= $min) {\n return ' ' . $str . ' ';\n }\n $tokens = ' ';\n // Build a FIFO queue of characters.\n $chars = array();\n for ($i = 0; $i < $length; $i++) {\n // Add the next character off the beginning of the string to the queue.\n $current = drupal_substr($str, 0, 1);\n $str = substr($str, strlen($current));\n $chars[] = $current;\n if ($i >= $min - 1) {\n // Make a token of $min characters, and add it to the token string.\n $tokens .= implode('', $chars) . ' ';\n // Shift out the first character in the queue.\n array_shift($chars);\n }\n }\n return $tokens;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-05845550a9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_get_project_name/7.x", "instruction": "Implement `update_get_project_name($file)` in PHP for Drupal 7. Required behavior: Determines what project a given file object belongs to.", "context": "Parameters:\n- $file: A file object as returned by system_get_files_database().\n\nReturns: The canonical project short name.\n\nFile: modules/update/update.compare.inc", "response": "function update_get_project_name($file) {\n $project_name = '';\n if (isset($file->info['project'])) {\n $project_name = $file->info['project'];\n }\n elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core') === 0)) {\n $project_name = 'drupal';\n }\n return $project_name;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-059e5d5699", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_explode_tags/7.x", "instruction": "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.", "context": "File: includes/common.inc", "response": "function drupal_explode_tags($tags) {\n // This regexp allows the following types of user input:\n // this, \"somecompany, llc\", \"and \"\"this\"\" w,o.rks\", foo bar\n $regexp = '%(?:^|,\\ *)(\"(?>[^\"]*)(?>\"\"[^\"]* )*\"|(?: [^\",]*))%x';\n preg_match_all($regexp, $tags, $matches);\n $typed_tags = array_unique($matches[1]);\n\n $tags = array();\n foreach ($typed_tags as $tag) {\n // If a user has escaped a term (to demonstrate that it is a group,\n // or includes a comma or quote character), we remove the escape\n // formatting so to save the term into the database as the user intends.\n $tag = trim(str_replace('\"\"', '\"', preg_replace('/^\"(.*)\"$/', '\\1', $tag)));\n if ($tag != \"\") {\n $tags[] = $tag;\n }\n }\n\n return $tags;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-059e5f4f53", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_cron_queue_info_alter/7.x", "instruction": "Give me the example code for `hook_cron_queue_info_alter(&$queues)` in Drupal 7. Hook description: Alter cron queue information before cron runs.", "context": "Called by drupal_cron_run() to allow modules to alter cron queue settings before any jobs are processesed.\n\nParameters:\n- $queues (array): An array of cron queue information.\n\nFile: modules/system/system.api.php", "response": "function hook_cron_queue_info_alter(&$queues) {\n // This site has many feeds so let's spend 90 seconds on each cron run\n // updating feeds instead of the default 60.\n $queues['aggregator_feeds']['time'] = 90;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-05d8e65ff5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.admin.inc/function/search_admin_settings/7.x", "instruction": "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.", "context": "File: modules/search/search.admin.inc", "response": "function search_admin_settings($form) {\n // Collect some stats\n $remaining = 0;\n $total = 0;\n foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {\n if ($status = module_invoke($module, 'search_status')) {\n $remaining += $status['remaining'];\n $total += $status['total'];\n }\n }\n\n $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');\n $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%';\n $status = '

' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '

';\n $form['status'] = array('#type' => 'fieldset', '#title' => t('Indexing status'));\n $form['status']['status'] = array('#markup' => $status);\n $form['status']['wipe'] = array('#type' => 'submit', '#value' => t('Re-index site'), '#submit' => array('search_admin_reindex_submit'));\n\n $items = drupal_map_assoc(array(10, 20, 50, 100, 200, 500));\n\n // Indexing throttle:\n $form['indexing_throttle'] = array(\n '#type' => 'fieldset',\n '#title' => t('Indexing throttle')\n );\n $form['indexing_throttle']['search_cron_limit'] = array(\n '#type' => 'select',\n '#title' => t('Number of items to index per cron run'),\n '#default_value' => variable_get('search_cron_limit', 100),\n '#options' => $items,\n '#description' => t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status')))\n );\n // Indexing settings:\n $form['indexing_settings'] = array(\n '#type' => 'fieldset',\n '#title' => t('Indexing settings')\n );\n $form['indexing_settings']['info'] = array(\n '#markup' => t('

Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\\'t be indexed until all existing content has been re-indexed.

The default settings should be appropriate for the majority of sites.

')\n );\n $form['indexing_settings']['minimum_word_size'] = array(\n '#type' => 'textfield',\n '#title' => t('Minimum word length to index'),\n '#default_value' => variable_get('minimum_word_size', 3),\n '#size' => 5,\n '#maxlength' => 3,\n '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).'),\n '#element_validate' => array('element_validate_integer_positive'),\n );\n $form['indexing_settings']['overlap_cjk'] = array(\n '#type' => 'checkbox',\n '#title' => t('Simple CJK handling'),\n '#default_value' => variable_get('overlap_cjk', TRUE),\n '#description' => t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.')\n );\n\n $form['active'] = array(\n '#type' => 'fieldset',\n '#title' => t('Active search modules')\n );\n $module_options = _search_get_module_names();\n $form['active']['search_active_modules'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Active modules'),\n '#title_display' => 'invisible',\n '#default_value' => variable_get('search_active_modules', array('node', 'user')),\n '#options' => $module_options,\n '#description' => t('Choose which search modules are active from the available modules.')\n );\n $form['active']['search_default_module'] = array(\n '#title' => t('Default search module'),\n '#type' => 'radios',\n '#default_value' => variable_get('search_default_module', 'node'),\n '#options' => $module_options,\n '#description' => t('Choose which search module is the default.')\n );\n $form['logging'] = array(\n '#type' => 'fieldset',\n '#title' => t('Logging')\n );\n $form['logging']['search_logging'] = array(\n '#type' => 'checkbox',\n '#title' => t('Log searches'),\n '#default_value' => variable_get('search_logging', 1),\n '#description' => t('If checked, all searches will be logged. Uncheck to skip logging. Logging may affect performance.'),\n );\n $form['#validate'][] = 'search_admin_settings_validate';\n $form['#submit'][] = 'search_admin_settings_submit';\n\n // Per module settings\n foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {\n $added_form = module_invoke($module, 'search_admin');\n if (is_array($added_form)) {\n $form = array_merge($form, $added_form);\n }\n }\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-05f028997d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_local_tasks_alter/7.x", "instruction": "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.", "context": "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.\n\nEach tab or action is an associative array containing:\n- #theme: The theme function to use to render.\n- #link: An associative array containing:\n - title: The localized title of the link.\n - href: The system path to link to.\n - localized_options: An array of options to pass to l().\n- #active: Whether the link should be marked as 'active'.\n\nParameters:\n- $data: An associative array containing: - actions: An associative array containing: - count: The amount of actions determined by the menu system, which can be ignored. - output: A list of of actions, each one being an associative array as described above. - tabs: An indexed array (list) of tab levels (up to 2 levels), each containing an associative array: - count: The amount of tabs determined by the menu system. This value does not need to be altered if there is more than one tab. - output: A list of of tabs, each one being an associative array as described above.\n- $router_item: The menu system router item of the page.\n- $root_path: The path to the root item for this set of tabs.\n\nFile: modules/system/system.api.php", "response": "function hook_menu_local_tasks_alter(&$data, $router_item, $root_path) {\n // Add an action linking to node/add to all pages.\n $data['actions']['output'][] = array(\n '#theme' => 'menu_local_task',\n '#link' => array(\n 'title' => t('Add new content'),\n 'href' => 'node/add',\n 'localized_options' => array(\n 'attributes' => array(\n 'title' => t('Add new content'),\n ),\n ),\n ),\n );\n\n // Add a tab linking to node/add to all pages.\n $data['tabs'][0]['output'][] = array(\n '#theme' => 'menu_local_task',\n '#link' => array(\n 'title' => t('Example tab'),\n 'href' => 'node/add',\n 'localized_options' => array(\n 'attributes' => array(\n 'title' => t('Add new content'),\n ),\n ),\n ),\n // Define whether this link is active. This can be omitted for\n // implementations that add links to pages outside of the current page\n // context.\n '#active' => ($router_item['path'] == $root_path),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0601fb205a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_insert/7.x", "instruction": "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().", "context": "File: modules/file/file.field.inc", "response": "function file_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n // Add a new usage of each uploaded file.\n foreach ($items as $item) {\n $file = (object) $item;\n file_usage_add($file, 'file', $entity_type, $id);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-060853deb3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_update/7.x", "instruction": "Implement `dashboard_update()` in PHP for Drupal 7. Required behavior: Sets the new weight of each region according to the drag-and-drop order.", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_update() {\n drupal_theme_initialize();\n global $theme_key;\n // Check the form token to make sure we have a valid request.\n if (!empty($_REQUEST['form_token']) && drupal_valid_token($_REQUEST['form_token'], 'dashboard-update')) {\n parse_str($_REQUEST['regions'], $regions);\n foreach ($regions as $region_name => $blocks) {\n if ($region_name == 'disabled_blocks') {\n $region_name = 'dashboard_inactive';\n }\n foreach ($blocks as $weight => $block_string) {\n // Parse the query string to determine the block's module and delta.\n preg_match('/block-([^-]+)-(.+)/', $block_string, $matches);\n $block = new stdClass();\n $block->module = $matches[1];\n $block->delta = $matches[2];\n\n $block->region = $region_name;\n $block->weight = $weight;\n $block->status = 1;\n\n db_merge('block')\n ->key(array(\n 'module' => $block->module,\n 'delta' => $block->delta,\n 'theme' => $theme_key,\n ))\n ->fields(array(\n 'status' => $block->status,\n 'weight' => $block->weight,\n 'region' => $block->region,\n 'pages' => '',\n ))\n ->execute();\n }\n }\n drupal_set_message(t('The configuration options have been saved.'), 'status', FALSE);\n }\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-060978aa1e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7015/7.x", "instruction": "I need the code for `system_update_7015()` in Drupal 7 (modules/system/system.install). It must do this: Change the user logout path.", "context": "File: modules/system/system.install", "response": "function system_update_7015() {\n db_update('menu_links')\n ->fields(array('link_path' => 'user/logout'))\n ->condition('link_path', 'logout')\n ->execute();\n db_update('menu_links')\n ->fields(array('router_path' => 'user/logout'))\n ->condition('router_path', 'logout')\n ->execute();\n\n db_update('menu_links')\n ->fields(array(\n 'menu_name' => 'user-menu',\n 'plid' => 0,\n ))\n ->condition(db_or()\n ->condition('link_path', 'user/logout')\n ->condition('router_path', 'user/logout')\n )\n ->condition('module', 'system')\n ->condition('customized', 0)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0630af2457", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_insert/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_user_insert(&$edit, $account, $category)` (modules/user/user.api.php): A user account was created.", "context": "The module should save its custom additions to the user object into the database.\n\nParameters:\n- $edit: The array of form values submitted by the user.\n- $account: The user object on which the operation is being performed.\n- $category: The active category of user information being edited.\n\nFile: modules/user/user.api.php", "response": "function hook_user_insert(&$edit, $account, $category) {\n db_insert('mytable')\n ->fields(array(\n 'myfield' => $edit['myfield'],\n 'uid' => $account->uid,\n ))\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-063c76e4d4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/update.php/function/update_script_selection_form/7.x", "instruction": "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.", "context": "File: update.php", "response": "function update_script_selection_form($form, &$form_state) {\n $count = 0;\n $incompatible_count = 0;\n $form['start'] = array(\n '#tree' => TRUE,\n '#type' => 'fieldset',\n '#collapsed' => TRUE,\n '#collapsible' => TRUE,\n );\n\n // Ensure system.module's updates appear first.\n $form['start']['system'] = array();\n\n $updates = update_get_update_list();\n $starting_updates = array();\n $incompatible_updates_exist = FALSE;\n foreach ($updates as $module => $update) {\n if (!isset($update['start'])) {\n $form['start'][$module] = array(\n '#type' => 'item',\n '#title' => $module . ' module',\n '#markup' => $update['warning'],\n '#prefix' => '
',\n '#suffix' => '
',\n );\n $incompatible_updates_exist = TRUE;\n continue;\n }\n if (!empty($update['pending'])) {\n $starting_updates[$module] = $update['start'];\n $form['start'][$module] = array(\n '#type' => 'hidden',\n '#value' => $update['start'],\n );\n $form['start'][$module . '_updates'] = array(\n '#theme' => 'item_list',\n '#items' => $update['pending'],\n '#title' => $module . ' module',\n );\n }\n if (isset($update['pending'])) {\n $count = $count + count($update['pending']);\n }\n }\n\n // Find and label any incompatible updates.\n foreach (update_resolve_dependencies($starting_updates) as $function => $data) {\n if (!$data['allowed']) {\n $incompatible_updates_exist = TRUE;\n $incompatible_count++;\n $module_update_key = $data['module'] . '_updates';\n if (isset($form['start'][$module_update_key]['#items'][$data['number']])) {\n $text = $data['missing_dependencies'] ? 'This update will been skipped due to the following missing dependencies: ' . implode(', ', $data['missing_dependencies']) . '' : \"This update will be skipped due to an error in the module's code.\";\n $form['start'][$module_update_key]['#items'][$data['number']] .= '
' . $text . '
';\n }\n // Move the module containing this update to the top of the list.\n $form['start'] = array($module_update_key => $form['start'][$module_update_key]) + $form['start'];\n }\n }\n\n // Warn the user if any updates were incompatible.\n if ($incompatible_updates_exist) {\n drupal_set_message('Some of the pending updates cannot be applied because their dependencies were not met.', 'warning');\n }\n\n if (empty($count)) {\n drupal_set_message(t('No pending updates.'));\n unset($form);\n $form['links'] = array(\n '#markup' => theme('item_list', array('items' => update_helpful_links())),\n );\n\n // No updates to run, so caches won't get flushed later. Clear them now.\n drupal_flush_all_caches();\n }\n else {\n $form['help'] = array(\n '#markup' => '

The version of Drupal you are updating from has been automatically detected.

',\n '#weight' => -5,\n );\n if ($incompatible_count) {\n $form['start']['#title'] = format_plural(\n $count,\n '1 pending update (@number_applied to be applied, @number_incompatible skipped)',\n '@count pending updates (@number_applied to be applied, @number_incompatible skipped)',\n array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count)\n );\n }\n else {\n $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates');\n }\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => 'Apply pending updates',\n );\n }\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-064128b484", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_help/7.x", "instruction": "Implement `text_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/field/modules/text/text.module", "response": "function text_help($path, $arg) {\n switch ($path) {\n case 'admin/help#text':\n $output = '';\n $output .= '

' . t('About') . '

';\n $output .= '

' . 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's text filters to securely manage HTML output. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, the field can be validated, so that it is limited to a set of allowed values. See the Field module help page for more information about fields.\", array('@field-help' => url('admin/help/field'), '@filter-help' => url('admin/help/filter'))) . '

';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-068565f655", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21errors.inc/function/_drupal_error_handler_real/7.x", "instruction": "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.", "context": "Parameters:\n- $error_level: The level of the error raised.\n- $message: The error message.\n- $filename: The filename that the error was raised in.\n- $line: The line number the error was raised at.\n\nFile: includes/errors.inc", "response": "function _drupal_error_handler_real($error_level, $message, $filename, $line) {\n if ($error_level & error_reporting()) {\n $types = drupal_error_levels();\n list($severity_msg, $severity_level) = $types[$error_level];\n $caller = _drupal_get_last_caller(debug_backtrace());\n\n if (!function_exists('filter_xss_admin')) {\n require_once DRUPAL_ROOT . '/includes/common.inc';\n }\n\n // We treat recoverable errors as fatal, and also allow fatal errors to be\n // explicitly triggered by drupal_trigger_fatal_error().\n _drupal_log_error(array(\n '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error',\n // The standard PHP error handler considers that the error messages\n // are HTML. We mimic this behavior here.\n '!message' => filter_xss_admin($message),\n '%function' => $caller['function'],\n '%file' => $caller['file'],\n '%line' => $caller['line'],\n 'severity_level' => $severity_level,\n ), $error_level == E_RECOVERABLE_ERROR || drupal_static('drupal_trigger_fatal_error'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-068abc2538", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/template_preprocess_poll_vote/7.x", "instruction": "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.", "context": "Inputs: $form\n\nFile: modules/poll/poll.module", "response": "function template_preprocess_poll_vote(&$variables) {\n $form = $variables['form'];\n $variables['choice'] = drupal_render($form['choice']);\n $variables['title'] = check_plain($form['#node']->title);\n $variables['vote'] = drupal_render($form['vote']);\n $variables['rest'] = drupal_render_children($form);\n $variables['block'] = $form['#block'];\n if ($variables['block']) {\n $variables['theme_hook_suggestions'][] = 'poll_vote__block';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-069521f212", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/theme_aggregator_categorize_items/7.x", "instruction": "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.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/aggregator/aggregator.pages.inc", "response": "function theme_aggregator_categorize_items($variables) {\n $form = $variables['form'];\n\n $output = drupal_render($form['feed_source']);\n $rows = array();\n if (!empty($form['items'])) {\n foreach (element_children($form['items']) as $key) {\n $rows[] = array(\n drupal_render($form['items'][$key]),\n array('data' => drupal_render($form['categories'][$key]), 'class' => array('categorize-item')),\n );\n }\n }\n $output .= theme('table', array('header' => array('', t('Categorize')), 'rows' => $rows));\n $output .= drupal_render($form['submit']);\n $output .= drupal_render_children($form);\n\n return theme('aggregator_wrapper', array('content' => $output));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-06ece89526", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.install/function/menu_update_7003/7.x", "instruction": "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.", "context": "File: modules/menu/menu.install", "response": "function menu_update_7003(&$sandbox) {\n // Make sure all custom menus are present in the active menus variable so that\n // their items may appear in the active trail.\n // @see menu_set_active_menu_names()\n $active_menus = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus()));\n $update_variable = FALSE;\n foreach (menu_get_names() as $menu_name) {\n if (!in_array($menu_name, $active_menus) && (strpos($menu_name, 'menu-') === 0)) {\n $active_menus[] = $menu_name;\n $update_variable = TRUE;\n }\n }\n if ($update_variable) {\n variable_set('menu_default_active_menus', $active_menus);\n }\n // Clear the menu cache.\n cache_clear_all(NULL, 'cache_menu');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-06f0243c43", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_date_formats/7.x", "instruction": "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.", "context": "Parameters:\n- $type: (optional) The date type name.\n\nReturns: 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 format string. - type: The machine-readable name of the date type. - locales: An array of language codes. This can include both 2 character language codes like 'en and 'fr' and 5 character language codes like 'en-gb' and 'en-us'. - locked: A boolean indicating whether or not this date type should be configurable from the user interface. - module: The name of the module that defined this date format in its hook_date_formats(). An empty string if the format was user-defined. - is_new: A boolean indicating whether or not this date type is as of yet unsaved in the database. If $type was defined, only the date formats associated with the given date type are returned, in a single associative array keyed by format string.\n\nFile: modules/system/system.module", "response": "function system_get_date_formats($type = NULL) {\n $date_formats = &drupal_static(__FUNCTION__);\n\n if (!isset($date_formats)) {\n $date_formats = _system_date_formats_build();\n }\n\n return $type ? (isset($date_formats[$type]) ? $date_formats[$type] : FALSE) : $date_formats;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0711a37df9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_cache_clear/7.x", "instruction": "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.", "context": "File: modules/field/field.module", "response": "function field_cache_clear() {\n cache_clear_all('*', 'cache_field', TRUE);\n field_info_cache_clear();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-07555f0f06", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_form_element_validate/7.x", "instruction": "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.", "context": "File: modules/path/path.module", "response": "function path_form_element_validate($element, &$form_state, $complete_form) {\n // Trim the submitted value.\n $alias = trim($form_state['values']['path']['alias']);\n if (!empty($alias)) {\n form_set_value($element['alias'], $alias, $form_state);\n // Node language (Locale module) needs special care. Since the language of\n // the URL alias depends on the node language, and the node language can be\n // switched right within the same form, we need to conditionally overload\n // the originally assigned URL alias language.\n // @todo Remove this after converting Path module to a field, and, after\n // stopping Locale module from abusing the content language system.\n if (isset($form_state['values']['language'])) {\n form_set_value($element['language'], $form_state['values']['language'], $form_state);\n }\n\n $path = $form_state['values']['path'];\n\n // Ensure that the submitted alias does not exist yet.\n $query = db_select('url_alias')\n ->condition('alias', $path['alias'])\n ->condition('language', $path['language']);\n if (!empty($path['source'])) {\n $query->condition('source', $path['source'], '<>');\n }\n $query->addExpression('1');\n $query->range(0, 1);\n if ($query->execute()->fetchField()) {\n form_error($element, t('The alias is already in use.'));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-076229816c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/filter_xss/7.x", "instruction": "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.", "context": "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.\n\nThis code does four things:\n- Removes characters and constructs that can trick browsers.\n- Makes sure all HTML entities are well-formed.\n- Makes sure all HTML tags and attributes are well-formed.\n- Makes sure no HTML tags contain URLs with a disallowed protocol (e.g.\n javascript:).\n\nParameters:\n- $string: The string with raw HTML in it. It will be stripped of everything that can cause an XSS attack.\n- $allowed_tags: An array of allowed tags.\n\nReturns: An XSS safe version of $string, or an empty string if $string is not valid UTF-8.\n\nFile: includes/common.inc", "response": "function filter_xss($string, $allowed_tags = array('a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd')) {\n // Only operate on valid UTF-8 strings. This is necessary to prevent cross\n // site scripting issues on Internet Explorer 6.\n if (!drupal_validate_utf8($string)) {\n return '';\n }\n // Store the text format.\n _filter_xss_split($allowed_tags, TRUE);\n // Remove NULL characters (ignored by some browsers).\n $string = str_replace(chr(0), '', (string) $string);\n // Remove Netscape 4 JS entities.\n $string = preg_replace('%&\\s*\\{[^}]*(\\}\\s*;?|$)%', '', $string);\n\n // Defuse all HTML entities.\n $string = str_replace('&', '&', $string);\n // Change back only well-formed entities in our whitelist:\n // Decimal numeric entities.\n $string = preg_replace('/&#([0-9]+;)/', '&#\\1', $string);\n // Hexadecimal numeric entities.\n $string = preg_replace('/&#[Xx]0*((?:[0-9A-Fa-f]{2})+;)/', '&#x\\1', $string);\n // Named entities.\n $string = preg_replace('/&([A-Za-z][A-Za-z0-9]*;)/', '&\\1', $string);\n\n return preg_replace_callback('%\n (\n <(?=[^a-zA-Z!/]) # a lone <\n | # or\n # a comment\n | # or\n <[^>]*(>|$) # a string that starts with a <, up until the > or the end of the string\n | # or\n > # just a >\n )%x', '_filter_xss_split', $string);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-076252b590", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_system_theme_engine_info/7.x", "instruction": "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.", "context": "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.\n\nReturns: An associative array. Each key is the system name of a theme engine and each value is the corresponding path to the theme engine's .engine file.\n\nFile: modules/system/system.api.php", "response": "function hook_system_theme_engine_info() {\n $theme_engines['izumi'] = drupal_get_path('module', 'mymodule') . '/izumi/izumi.engine';\n return $theme_engines;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-07805ccc32", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_block_denied/7.x", "instruction": "Implement `drupal_block_denied($ip)` in PHP for Drupal 7. Required behavior: Handles denied users.", "context": "Parameters:\n- $ip: IP address to check. Prints a message and exits if access is denied.\n\nFile: includes/bootstrap.inc", "response": "function drupal_block_denied($ip) {\n // Deny access to blocked IP addresses - t() is not yet available.\n if (drupal_is_denied($ip)) {\n header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');\n print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.';\n exit();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-078546b1ee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_math_div/7.x", "instruction": "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.", "context": "File: modules/openid/openid.inc", "response": "function _openid_math_div($x, $y) {\n $library = _openid_get_math_library();\n switch ($library) {\n case 'gmp':\n return gmp_div($x, $y);\n case 'bcmath':\n return bcdiv($x, $y);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-078ef4d1ab", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_validate_utf8/7.x", "instruction": "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.", "context": "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.\n\nWhen 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 subsequent bytes are HTML control characters such as quotes or angle brackets, parts of the text that were deemed safe by filters end up in locations that are potentially unsafe; An onerror attribute that is outside of a tag, and thus deemed safe by a filter, can be interpreted by the browser as if it were inside the tag.\n\nThe function does not return FALSE for strings containing character codes above U+10FFFF, even though these are prohibited by RFC 3629.\n\nParameters:\n- $text: The text to check.\n\nReturns: TRUE if the text is valid UTF-8, FALSE if not.\n\nFile: includes/bootstrap.inc", "response": "function drupal_validate_utf8($text) {\n if (strlen((string) $text) == 0) {\n return TRUE;\n }\n // With the PCRE_UTF8 modifier 'u', preg_match() fails silently on strings\n // containing invalid UTF-8 byte sequences. It does not reject character\n // codes above U+10FFFF (represented by 4 or more octets), though.\n return (preg_match('/^./us', $text) == 1);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-07b83f73c7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21bartik%21template.php/function/bartik_preprocess_block/7.x", "instruction": "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.", "context": "File: themes/bartik/template.php", "response": "function bartik_preprocess_block(&$variables) {\n // In the header region visually hide block titles.\n if ($variables['block']->region == 'header') {\n $variables['title_attributes_array']['class'][] = 'element-invisible';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-07bbf08e15", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/theme_field/7.x", "instruction": "Implement `theme_field($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a field.", "context": "This is the default theme implementation to display the value of a field.\nTheme developers who are comfortable with overriding theme functions may do\nso in order to customize this markup. This function can be overridden with\nvarying levels of specificity. For example, for a field named 'body'\ndisplayed on the 'article' content type, any of the following functions will\noverride this default implementation. The first of these functions that\nexists is used:\n- THEMENAME_field__body__article()\n- THEMENAME_field__article()\n- THEMENAME_field__body()\n- THEMENAME_field()\n\nTheme developers who prefer to customize templates instead of overriding\nfunctions may copy the \"field.tpl.php\" from the \"modules/field/theme\" folder\nof the Drupal installation to somewhere within the theme's folder and\ncustomize it, just like customizing other Drupal templates such as\npage.tpl.php or node.tpl.php. However, it takes longer for the server to\nprocess templates than to call a function, so for websites with many fields\ndisplayed on a page, this can result in a noticeable slowdown of the website.\nFor these websites, developers are discouraged from placing a field.tpl.php\nfile into the theme's folder, but may customize templates for specific\nfields. For example, for a field named 'body' displayed on the 'article'\ncontent type, any of the following templates will override this default\nimplementation. The first of these templates that exists is used:\n- field--body--article.tpl.php\n- field--article.tpl.php\n- field--body.tpl.php\n- field.tpl.php\nSo, if the body field on the article content type needs customization, a\nfield--body--article.tpl.php file can be added within the theme's folder.\nBecause it's a template, it will result in slightly more time needed to\ndisplay that field, but it will not impact other fields, and therefore,\nis unlikely to cause a noticeable change in website performance. A very rough\nguideline is that if a page is being displayed with more than 100 fields and\nthey are all themed with a template instead of a function, it can add up to\n5% to the time it takes to display that page. This is a guideline only and\nthe exact performance impact depends on the server configuration and the\ndetails of the website.\n\nParameters:\n- $variables: An associative array containing: - label_hidden: A boolean indicating to show or hide the field label. - title_attributes: A string containing the attributes for the title. - label: The label for the field. - content_attributes: A string containing the attributes for the content's div. - items: An array of field items. - item_attributes: An array of attributes for each item. - classes: A string containing the classes for the wrapping div. - attributes: A string containing the attributes for the wrapping div.\n\nFile: modules/field/field.module", "response": "function theme_field($variables) {\n $output = '';\n\n // Render the label, if it's not hidden.\n if (!$variables['label_hidden']) {\n $output .= '
' . $variables['label'] . ': 
';\n }\n\n // Render the items.\n $output .= '
';\n foreach ($variables['items'] as $delta => $item) {\n $classes = 'field-item ' . ($delta % 2 ? 'odd' : 'even');\n $output .= '
' . drupal_render($item) . '
';\n }\n $output .= '
';\n\n // Render the top-level DIV.\n $output = '
' . $output . '
';\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-07ca60b4ec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_actions/7.x", "instruction": "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.", "context": "Parameters:\n- $element: An associative array containing the properties and children of the form actions container.\n- $form_state: The $form_state array for the form this element belongs to.\n\nReturns: The processed element.\n\nFile: includes/form.inc", "response": "function form_process_actions($element, &$form_state) {\n $element['#attributes']['class'][] = 'form-actions';\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-07de549c21", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_normalization_method_info/7.x", "instruction": "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.", "context": "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.\n\nThe first normalization method that succeed (return a value that is not NULL) will stop the normalization process.\n\nReturns: An array with a set of function callbacks, that will be called in turn when normalizing an OpenID identifier. The normalization functions have to return a normalized identifier, or NULL if the identifier is not in a form they can handle.\n\nFile: modules/openid/openid.api.php", "response": "function hook_openid_normalization_method_info() {\n return array(\n 'new_normalization_idea' => '_my_normalization_method',\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0815af898d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_map_assoc/7.x", "instruction": "Implement `drupal_map_assoc($array, $function = NULL)` in PHP for Drupal 7. Required behavior: Forms an associative array from a linear array.", "context": "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.\n\nParameters:\n- $array: A linear array.\n- $function: A name of a function to apply to all values before output.\n\nReturns: An associative array.\n\nFile: includes/common.inc", "response": "function drupal_map_assoc($array, $function = NULL) {\n // array_combine() fails with empty arrays:\n // http://bugs.php.net/bug.php?id=34857.\n $array = !empty($array) ? array_combine($array, $array) : array();\n if (is_callable($function)) {\n $array = array_map($function, $array);\n }\n return $array;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-081eaaa966", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21update.inc/function/update_batch/7.x", "instruction": "In Drupal 7, write the function `update_batch($start, $redirect = NULL, $url = NULL, $batch = array(), $redirect_callback = 'drupal_goto')` (file includes/update.inc) so that it does the following: Starts the database update batch process.", "context": "Parameters:\n- $start: An array whose keys contain the names of modules to be updated during the current batch process, and whose values contain the number of the first requested update for that module. The actual updates that are run (and the order they are run in) will depend on the results of passing this data through the update dependency system.\n- $redirect: Path to redirect to when the batch has finished processing.\n- $url: URL of the batch processing page (should only be used for separate scripts like update.php).\n- $batch: Optional parameters to pass into the batch API.\n- $redirect_callback: (optional) Specify a function to be called to redirect to the progressive processing page.\n\nFile: includes/update.inc", "response": "function update_batch($start, $redirect = NULL, $url = NULL, $batch = array(), $redirect_callback = 'drupal_goto') {\n // During the update, bring the site offline so that schema changes do not\n // affect visiting users.\n $_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE);\n if ($_SESSION['maintenance_mode'] == FALSE) {\n variable_set('maintenance_mode', TRUE);\n }\n\n // Resolve any update dependencies to determine the actual updates that will\n // be run and the order they will be run in.\n $updates = update_resolve_dependencies($start);\n\n // Store the dependencies for each update function in an array which the\n // batch API can pass in to the batch operation each time it is called. (We\n // do not store the entire update dependency array here because it is\n // potentially very large.)\n $dependency_map = array();\n foreach ($updates as $function => $update) {\n $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();\n }\n\n $operations = array();\n foreach ($updates as $update) {\n if ($update['allowed']) {\n // Set the installed version of each module so updates will start at the\n // correct place. (The updates are already sorted, so we can simply base\n // this on the first one we come across in the above foreach loop.)\n if (isset($start[$update['module']])) {\n drupal_set_installed_schema_version($update['module'], $update['number'] - 1);\n unset($start[$update['module']]);\n }\n // Add this update function to the batch.\n $function = $update['module'] . '_update_' . $update['number'];\n $operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));\n }\n }\n $batch['operations'] = $operations;\n $batch += array(\n 'title' => 'Updating',\n 'init_message' => 'Starting updates',\n 'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.',\n 'finished' => 'update_finished',\n 'file' => 'includes/update.inc',\n );\n batch_set($batch);\n batch_process($redirect, $url, $redirect_callback);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0820c290f1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_widget_submit/7.x", "instruction": "In Drupal 7, write the function `file_field_widget_submit($form, &$form_state)` (file modules/file/file.field.inc) so that it does the following: Form submission handler for upload/remove button of file_field_widget_form().", "context": "This runs in addition to and after file_managed_file_submit().\n\nFile: modules/file/file.field.inc", "response": "function file_field_widget_submit($form, &$form_state) {\n // During the form rebuild, file_field_widget_form() will create field item\n // widget elements using re-indexed deltas, so clear out $form_state['input']\n // to avoid a mismatch between old and new deltas. The rebuilt elements will\n // have #default_value set appropriately for the current state of the field,\n // so nothing is lost in doing this.\n $parents = array_slice($form_state['triggering_element']['#parents'], 0, -2);\n drupal_array_set_nested_value($form_state['input'], $parents, NULL);\n\n $button = $form_state['triggering_element'];\n\n // Go one level up in the form, to the widgets container.\n $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -1));\n $field_name = $element['#field_name'];\n $langcode = $element['#language'];\n $parents = $element['#field_parents'];\n\n $submitted_values = drupal_array_get_nested_value($form_state['values'], array_slice($button['#parents'], 0, -2));\n foreach ($submitted_values as $delta => $submitted_value) {\n if (!$submitted_value['fid']) {\n unset($submitted_values[$delta]);\n }\n }\n\n // Re-index deltas after removing empty items.\n $submitted_values = array_values($submitted_values);\n\n // Update form_state values.\n drupal_array_set_nested_value($form_state['values'], array_slice($button['#parents'], 0, -2), $submitted_values);\n\n // Update items.\n $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state);\n $field_state['items'] = $submitted_values;\n field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0883638889", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_admin_form/7.x", "instruction": "I need the code for `aggregator_admin_form($form, $form_state)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Form constructor for the aggregator system settings.", "context": "File: modules/aggregator/aggregator.admin.inc", "response": "function aggregator_admin_form($form, $form_state) {\n // Global aggregator settings.\n $form['aggregator_allowed_html_tags'] = array(\n '#type' => 'textfield',\n '#title' => t('Allowed HTML tags'),\n '#size' => 80,\n '#maxlength' => 255,\n '#default_value' => variable_get('aggregator_allowed_html_tags', '
      • '),\n '#description' => t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'),\n );\n\n // Make sure configuration is sane.\n aggregator_sanitize_configuration();\n\n // Get all available fetchers.\n $fetchers = module_implements('aggregator_fetch');\n foreach ($fetchers as $k => $module) {\n if ($info = module_invoke($module, 'aggregator_fetch_info')) {\n $label = $info['title'] . ' ' . $info['description'] . '';\n }\n else {\n $label = $module;\n }\n unset($fetchers[$k]);\n $fetchers[$module] = $label;\n }\n\n // Get all available parsers.\n $parsers = module_implements('aggregator_parse');\n foreach ($parsers as $k => $module) {\n if ($info = module_invoke($module, 'aggregator_parse_info')) {\n $label = $info['title'] . ' ' . $info['description'] . '';\n }\n else {\n $label = $module;\n }\n unset($parsers[$k]);\n $parsers[$module] = $label;\n }\n\n // Get all available processors.\n $processors = module_implements('aggregator_process');\n foreach ($processors as $k => $module) {\n if ($info = module_invoke($module, 'aggregator_process_info')) {\n $label = $info['title'] . ' ' . $info['description'] . '';\n }\n else {\n $label = $module;\n }\n unset($processors[$k]);\n $processors[$module] = $label;\n }\n\n // Only show basic configuration if there are actually options.\n $basic_conf = array();\n if (count($fetchers) > 1) {\n $basic_conf['aggregator_fetcher'] = array(\n '#type' => 'radios',\n '#title' => t('Fetcher'),\n '#description' => t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'),\n '#options' => $fetchers,\n '#default_value' => variable_get('aggregator_fetcher', 'aggregator'),\n );\n }\n if (count($parsers) > 1) {\n $basic_conf['aggregator_parser'] = array(\n '#type' => 'radios',\n '#title' => t('Parser'),\n '#description' => t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'),\n '#options' => $parsers,\n '#default_value' => variable_get('aggregator_parser', 'aggregator'),\n );\n }\n if (count($processors) > 1) {\n $basic_conf['aggregator_processors'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Processors'),\n '#description' => t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'),\n '#options' => $processors,\n '#default_value' => variable_get('aggregator_processors', array('aggregator')),\n );\n }\n if (count($basic_conf)) {\n $form['basic_conf'] = array(\n '#type' => 'fieldset',\n '#title' => t('Basic configuration'),\n '#description' => t('For most aggregation tasks, the default settings are fine.'),\n '#collapsible' => TRUE,\n '#collapsed' => FALSE,\n );\n $form['basic_conf'] += $basic_conf;\n }\n\n // Implementing modules will expect an array at $form['modules'].\n $form['modules'] = array();\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save configuration'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0889daee9b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_uri/7.x", "instruction": "In Drupal 7, write the function `entity_uri($entity_type, $entity)` (file includes/common.inc) so that it does the following: Returns the URI elements of an entity.", "context": "Parameters:\n- $entity_type: The entity type; e.g. 'node' or 'user'.\n- $entity: The entity for which to generate a path.\n\nReturns: An array containing the 'path' and 'options' keys used to build the URI of the entity, and matching the signature of url(). NULL if the entity has no URI of its own.\n\nFile: includes/common.inc", "response": "function entity_uri($entity_type, $entity) {\n $info = entity_get_info($entity_type);\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n // A bundle-specific callback takes precedence over the generic one for the\n // entity type.\n if (isset($info['bundles'][$bundle]['uri callback'])) {\n $uri_callback = $info['bundles'][$bundle]['uri callback'];\n }\n elseif (isset($info['uri callback'])) {\n $uri_callback = $info['uri callback'];\n }\n else {\n return NULL;\n }\n\n // Invoke the callback to get the URI. If there is no callback, return NULL.\n if (isset($uri_callback) && function_exists($uri_callback)) {\n $uri = $uri_callback($entity);\n // Pass the entity data to url() so that alter functions do not need to\n // lookup this entity again.\n $uri['options']['entity_type'] = $entity_type;\n $uri['options']['entity'] = $entity;\n return $uri;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-08a79c7bcc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.parser.inc/function/aggregator_aggregator_parse_info/7.x", "instruction": "I need the code for `aggregator_aggregator_parse_info()` in Drupal 7 (modules/aggregator/aggregator.parser.inc). It must do this: Implements hook_aggregator_parse_info().", "context": "File: modules/aggregator/aggregator.parser.inc", "response": "function aggregator_aggregator_parse_info() {\n return array(\n 'title' => t('Default parser'),\n 'description' => t('Parses RSS, Atom and RDF feeds.'),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-08b2adb00b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.install/function/openid_update_7000/7.x", "instruction": "In Drupal 7, write the function `openid_update_7000()` (file modules/openid/openid.install) so that it does the following: Bind associations to their providers.", "context": "File: modules/openid/openid.install", "response": "function openid_update_7000() {\n db_drop_table('openid_association');\n\n $schema = array(\n 'description' => 'Stores temporary shared key association information for OpenID authentication.',\n 'fields' => array(\n 'idp_endpoint_uri' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'description' => 'Primary Key: URI of the OpenID Provider endpoint.',\n ),\n 'assoc_handle' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'description' => 'Used to refer to this association in subsequent messages.',\n ),\n 'assoc_type' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',\n ),\n 'session_type' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'description' => 'Valid association session types: \"no-encryption\", \"DH-SHA1\", and \"DH-SHA256\".',\n ),\n 'mac_key' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'description' => 'The MAC key (shared secret) for this association.',\n ),\n 'created' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'UNIX timestamp for when the association was created.',\n ),\n 'expires_in' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The lifetime, in seconds, of this association.',\n ),\n ),\n 'primary key' => array('idp_endpoint_uri'),\n 'unique keys' => array(\n 'assoc_handle' => array('assoc_handle'),\n ),\n );\n db_create_table('openid_association', $schema);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-08b47ceeea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_menu/7.x", "instruction": "I need the code for `shortcut_menu()` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Implements hook_menu().", "context": "File: modules/shortcut/shortcut.module", "response": "function shortcut_menu() {\n $items['admin/config/user-interface/shortcut'] = array(\n 'title' => 'Shortcuts',\n 'description' => 'Add and modify shortcut sets.',\n 'page callback' => 'shortcut_set_admin',\n 'access arguments' => array('administer shortcuts'),\n 'file' => 'shortcut.admin.inc',\n );\n $items['admin/config/user-interface/shortcut/add-set'] = array(\n 'title' => 'Add shortcut set',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_set_add_form'),\n 'access arguments' => array('administer shortcuts'),\n 'type' => MENU_LOCAL_ACTION,\n 'file' => 'shortcut.admin.inc',\n );\n $items['admin/config/user-interface/shortcut/%shortcut_set'] = array(\n 'title' => 'Edit shortcuts',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_set_customize', 4),\n 'title callback' => 'shortcut_set_title_callback',\n 'title arguments' => array(4),\n 'access callback' => 'shortcut_set_edit_access',\n 'access arguments' => array(4),\n 'file' => 'shortcut.admin.inc',\n );\n $items['admin/config/user-interface/shortcut/%shortcut_set/links'] = array(\n 'title' => 'List links',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n );\n $items['admin/config/user-interface/shortcut/%shortcut_set/edit'] = array(\n 'title' => 'Edit set name',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_set_edit_form', 4),\n 'access callback' => 'shortcut_set_edit_access',\n 'access arguments' => array(4),\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'shortcut.admin.inc',\n 'weight' => 10,\n );\n $items['admin/config/user-interface/shortcut/%shortcut_set/delete'] = array(\n 'title' => 'Delete shortcut set',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_set_delete_form', 4),\n 'access callback' => 'shortcut_set_delete_access',\n 'access arguments' => array(4),\n 'file' => 'shortcut.admin.inc',\n );\n $items['admin/config/user-interface/shortcut/%shortcut_set/add-link'] = array(\n 'title' => 'Add shortcut',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_link_add', 4),\n 'access callback' => 'shortcut_set_edit_access',\n 'access arguments' => array(4),\n 'type' => MENU_LOCAL_ACTION,\n 'file' => 'shortcut.admin.inc',\n );\n $items['admin/config/user-interface/shortcut/%shortcut_set/add-link-inline'] = array(\n 'title' => 'Add shortcut',\n 'page callback' => 'shortcut_link_add_inline',\n 'page arguments' => array(4),\n 'access callback' => 'shortcut_set_edit_access',\n 'access arguments' => array(4),\n 'type' => MENU_CALLBACK,\n 'file' => 'shortcut.admin.inc',\n );\n $items['admin/config/user-interface/shortcut/link/%menu_link'] = array(\n 'title' => 'Edit shortcut',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_link_edit', 5),\n 'access callback' => 'shortcut_link_access',\n 'access arguments' => array(5),\n 'file' => 'shortcut.admin.inc',\n );\n $items['admin/config/user-interface/shortcut/link/%menu_link/delete'] = array(\n 'title' => 'Delete shortcut',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_link_delete', 5),\n 'access callback' => 'shortcut_link_access',\n 'access arguments' => array(5),\n 'file' => 'shortcut.admin.inc',\n );\n $items['user/%user/shortcuts'] = array(\n 'title' => 'Shortcuts',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('shortcut_set_switch', 1),\n 'access callback' => 'shortcut_set_switch_access',\n 'access arguments' => array(1),\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'shortcut.admin.inc',\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-08c1b9a8ee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.settings.inc/function/update_settings_validate/7.x", "instruction": "Implement `update_settings_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for update_settings().", "context": "Validates the e-mail addresses and ensures the field is formatted correctly.\n\nFile: modules/update/update.settings.inc", "response": "function update_settings_validate($form, &$form_state) {\n if (!empty($form_state['values']['update_notify_emails'])) {\n $valid = array();\n $invalid = array();\n foreach (explode(\"\\n\", trim($form_state['values']['update_notify_emails'])) as $email) {\n $email = trim($email);\n if (!empty($email)) {\n if (valid_email_address($email)) {\n $valid[] = $email;\n }\n else {\n $invalid[] = $email;\n }\n }\n }\n if (empty($invalid)) {\n $form_state['notify_emails'] = $valid;\n }\n elseif (count($invalid) == 1) {\n form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));\n }\n else {\n form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-08c3ec6d4f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_prepare_thread/7.x", "instruction": "I need the code for `comment_prepare_thread(&$comments)` in Drupal 7 (modules/comment/comment.module). It must do this: Loop over comment thread, noting indentation level.", "context": "Parameters:\n- $comments (array): An array of comment objects, keyed by cid.\n\nReturns: The $comments argument is altered by reference with indentation information.\n\nFile: modules/comment/comment.module", "response": "function comment_prepare_thread(&$comments) {\n // A flag stating if we are still searching for first new comment on the thread.\n $first_new = TRUE;\n\n // A counter that helps track how indented we are.\n $divs = 0;\n\n foreach ($comments as $key => $comment) {\n if ($first_new && $comment->new != MARK_READ) {\n // Assign the anchor only for the first new comment. This avoids duplicate\n // id attributes on a page.\n $first_new = FALSE;\n $comment->first_new = TRUE;\n }\n\n // The $divs element instructs #prefix whether to add an indent div or\n // close existing divs (a negative value).\n $comment->depth = count(explode('.', $comment->thread)) - 1;\n if ($comment->depth > $divs) {\n $comment->divs = 1;\n $divs++;\n }\n else {\n $comment->divs = $comment->depth - $divs;\n while ($comment->depth < $divs) {\n $divs--;\n }\n }\n $comments[$key] = $comment;\n }\n\n // The final comment must close up some hanging divs\n $comments[$key]->divs_final = $divs;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-08db503810", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_acquire/7.x", "instruction": "In Drupal 7, write the function `lock_acquire($name, $timeout = 30.0)` (file includes/lock.inc) so that it does the following: Acquire (or renew) a lock, but do not block if it fails.", "context": "Parameters:\n- $name: The name of the lock. Limit of name's length is 255 characters.\n- $timeout: A number of seconds (float) before the lock expires (minimum of 0.001).\n\nReturns: TRUE if the lock was acquired, FALSE if it failed.\n\nFile: includes/lock.inc", "response": "function lock_acquire($name, $timeout = 30.0) {\n global $locks;\n\n // Insure that the timeout is at least 1 ms.\n $timeout = max($timeout, 0.001);\n $expire = microtime(TRUE) + $timeout;\n if (isset($locks[$name])) {\n // Try to extend the expiration of a lock we already acquired.\n $success = (bool) db_update('semaphore')\n ->fields(array('expire' => $expire))\n ->condition('name', $name)\n ->condition('value', _lock_id())\n ->execute();\n if (!$success) {\n // The lock was broken.\n unset($locks[$name]);\n }\n return $success;\n }\n else {\n // Optimistically try to acquire the lock, then retry once if it fails.\n // The first time through the loop cannot be a retry.\n $retry = FALSE;\n // We always want to do this code at least once.\n do {\n try {\n db_insert('semaphore')\n ->fields(array(\n 'name' => $name,\n 'value' => _lock_id(),\n 'expire' => $expire,\n ))\n ->execute();\n // We track all acquired locks in the global variable.\n $locks[$name] = TRUE;\n // We never need to try again.\n $retry = FALSE;\n }\n catch (PDOException $e) {\n // Suppress the error. If this is our first pass through the loop,\n // then $retry is FALSE. In this case, the insert must have failed\n // meaning some other request acquired the lock but did not release it.\n // We decide whether to retry by checking lock_may_be_available()\n // Since this will break the lock in case it is expired.\n $retry = $retry ? FALSE : lock_may_be_available($name);\n }\n // We only retry in case the first attempt failed, but we then broke\n // an expired lock.\n } while ($retry);\n }\n return isset($locks[$name]);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-08fbaa8b0b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21actions.inc/function/actions_function_lookup/7.x", "instruction": "I need the code for `actions_function_lookup($hash)` in Drupal 7 (includes/actions.inc). It must do this: Returns an action array key (function or ID), given its hash.", "context": "Faster than actions_actions_map() when you only need the function name or ID.\n\nParameters:\n- $hash: Hash of a function name or action ID array key. The array key is a key into the return value of actions_list() (array key is the action function name) or actions_get_all_actions() (array key is the action ID).\n\nReturns: The corresponding array key, or FALSE if no match is found.\n\nFile: includes/actions.inc", "response": "function actions_function_lookup($hash) {\n // Check for a function name match.\n $actions_list = actions_list();\n foreach ($actions_list as $function => $array) {\n if (drupal_hash_base64($function) == $hash) {\n return $function;\n }\n }\n $aid = FALSE;\n // Must be a configurable action; check database.\n $result = db_query(\"SELECT aid FROM {actions} WHERE parameters <> ''\")->fetchAll(PDO::FETCH_ASSOC);\n foreach ($result as $row) {\n if (drupal_hash_base64($row['aid']) == $hash) {\n $aid = $row['aid'];\n break;\n }\n }\n return $aid;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-092a82d686", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_touch_node/7.x", "instruction": "In Drupal 7, write the function `search_touch_node($nid)` (file modules/search/search.module) so that it does the following: Changes a node's changed timestamp to 'now' to force reindexing.", "context": "Parameters:\n- $nid: The node ID of the node that needs reindexing.\n\nFile: modules/search/search.module", "response": "function search_touch_node($nid) {\n db_update('search_dataset')\n ->fields(array('reindex' => REQUEST_TIME))\n ->condition('type', 'node')\n ->condition('sid', $nid)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0933fc91c8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_register_form/7.x", "instruction": "In Drupal 7, write the function `user_register_form($form, &$form_state)` (file modules/user/user.module) so that it does the following: Form builder; the user registration form.", "context": "File: modules/user/user.module", "response": "function user_register_form($form, &$form_state) {\n global $user;\n\n $admin = user_access('administer users');\n\n // Pass access information to the submit handler. Running an access check\n // inside the submit function interferes with form processing and breaks\n // hook_form_alter().\n $form['administer_users'] = array(\n '#type' => 'value',\n '#value' => $admin,\n );\n\n // If we aren't admin but already logged on, go to the user page instead.\n if (!$admin && $user->uid) {\n drupal_goto('user/' . $user->uid);\n }\n\n $form['#user'] = drupal_anonymous_user();\n $form['#user_category'] = 'register';\n\n $form['#attached']['library'][] = array('system', 'jquery.cookie');\n $form['#attributes']['class'][] = 'user-info-from-cookie';\n\n // Start with the default user account fields.\n user_account_form($form, $form_state);\n\n // Attach field widgets, and hide the ones where the 'user_register_form'\n // setting is not on.\n $langcode = entity_language('user', $form['#user']);\n field_attach_form('user', $form['#user'], $form, $form_state, $langcode);\n foreach (field_info_instances('user', 'user') as $field_name => $instance) {\n if (empty($instance['settings']['user_register_form'])) {\n $form[$field_name]['#access'] = FALSE;\n }\n }\n\n if ($admin) {\n // Redirect back to page which initiated the create request;\n // usually admin/people/create.\n $form_state['redirect'] = $_GET['q'];\n }\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Create new account'),\n );\n\n $form['#validate'][] = 'user_register_validate';\n // Add the final user registration form submit handler.\n $form['#submit'][] = 'user_register_submit';\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-093b72f536", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21php%21php.module/function/_php_filter_tips/7.x", "instruction": "In Drupal 7, write the function `_php_filter_tips($filter, $format, $long = FALSE)` (file modules/php/php.module) so that it does the following: Implements callback_filter_tips().", "context": "File: modules/php/php.module", "response": "function _php_filter_tips($filter, $format, $long = FALSE) {\n global $base_url;\n if ($long) {\n $output = '

        ' . t('Using custom PHP code') . '

        ';\n $output .= '

        ' . t('Custom PHP code may be embedded in some types of site content, including posts and blocks. While embedding PHP code inside a post or block is a powerful and flexible feature when used by a trusted user with PHP experience, it is a significant and dangerous security risk when used improperly. Even a small mistake when posting PHP code may accidentally compromise your site.') . '

        ';\n $output .= '

        ' . t('If you are unfamiliar with PHP, SQL, or Drupal, avoid using custom PHP code within posts. Experimenting with PHP may corrupt your database, render your site inoperable, or significantly compromise security.') . '

        ';\n $output .= '

        ' . t('Notes:') . '

        ';\n $output .= '
        ';\n $output .= '

        ' . t('A basic example: Creating a \"Welcome\" block that greets visitors with a simple message.') . '

        ';\n $output .= '
        • ' . t('

          Add a custom block to your site, named \"Welcome\" . With its text format set to \"PHP code\" (or another format supporting PHP input), add the following in the Block body:

          \n
          \nprint t(\\'Welcome visitor! Thank you for visiting.\\');\n
          ') . '
        • ';\n $output .= '
        • ' . t('

          To display the name of a registered user, use this instead:

          \n
          \nglobal $user;\nif ($user->uid) {\n  print t(\\'Welcome @name! Thank you for visiting.\\', array(\\'@name\\' => format_username($user)));\n}\nelse {\n  print t(\\'Welcome visitor! Thank you for visiting.\\');\n}\n
          ') . '
        ';\n $output .= '

        ' . t('Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.', array('@drupal' => url('http://drupal.org'), '@php-snippets' => url('http://drupal.org/documentation/customization/php-snippets'))) . '

        ';\n return $output;\n }\n else {\n return t('You may post PHP code. You should include <?php ?> tags.');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0940387f1d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/_user_cancel/7.x", "instruction": "I need the code for `_user_cancel($edit, $account, $method)` in Drupal 7 (modules/user/user.module). It must do this: Implements callback_batch_operation().", "context": "Last step for cancelling a user account.\n\nSince batch and session API require a valid user account, the actual cancellation of a user account needs to happen last.\n\nFile: modules/user/user.module", "response": "function _user_cancel($edit, $account, $method) {\n global $user;\n\n switch ($method) {\n case 'user_cancel_block':\n case 'user_cancel_block_unpublish':\n default:\n // Send account blocked notification if option was checked.\n if (!empty($edit['user_cancel_notify'])) {\n _user_mail_notify('status_blocked', $account);\n }\n user_save($account, array('status' => 0));\n drupal_set_message(t('%name has been disabled.', array('%name' => $account->name)));\n watchdog('user', 'Blocked user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);\n break;\n\n case 'user_cancel_reassign':\n case 'user_cancel_delete':\n // Send account canceled notification if option was checked.\n if (!empty($edit['user_cancel_notify'])) {\n _user_mail_notify('status_canceled', $account);\n }\n user_delete($account->uid);\n drupal_set_message(t('%name has been deleted.', array('%name' => $account->name)));\n watchdog('user', 'Deleted user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);\n break;\n }\n\n // After cancelling account, ensure that user is logged out. We can't destroy\n // their session though, as we might have information in it, and we can't\n // regenerate it because batch API uses the session ID, we will regenerate it\n // in _user_cancel_session_regenerate().\n if ($account->uid == $user->uid) {\n $user = drupal_anonymous_user();\n }\n\n // Clear the cache for anonymous users.\n cache_clear_all();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-095a88021e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_admin_remove_feed/7.x", "instruction": "In Drupal 7, write the function `aggregator_admin_remove_feed($form, $form_state, $feed)` (file modules/aggregator/aggregator.admin.inc) so that it does the following: Deletes a feed.", "context": "Parameters:\n- $feed: An associative array describing the feed to be cleared.\n\nFile: modules/aggregator/aggregator.admin.inc", "response": "function aggregator_admin_remove_feed($form, $form_state, $feed) {\n return confirm_form(\n array(\n 'feed' => array(\n '#type' => 'value',\n '#value' => $feed,\n ),\n ),\n t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $feed->title)),\n 'admin/config/services/aggregator',\n t('This action cannot be undone.'),\n t('Remove items'),\n t('Cancel')\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0972a5e5c2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/template_process_field/7.x", "instruction": "Implement `template_process_field(&$variables, $hook)` in PHP for Drupal 7. Required behavior: Theme process function for theme_field() and field.tpl.php.", "context": "File: modules/field/field.module", "response": "function template_process_field(&$variables, $hook) {\n // The default theme implementation is a function, so template_process() does\n // not automatically run, so we need to flatten the classes and attributes\n // here. For best performance, only call drupal_attributes() when needed, and\n // note that template_preprocess_field() does not initialize the\n // *_attributes_array variables.\n $variables['classes'] = implode(' ', $variables['classes_array']);\n $variables['attributes'] = empty($variables['attributes_array']) ? '' : drupal_attributes($variables['attributes_array']);\n $variables['title_attributes'] = empty($variables['title_attributes_array']) ? '' : drupal_attributes($variables['title_attributes_array']);\n $variables['content_attributes'] = empty($variables['content_attributes_array']) ? '' : drupal_attributes($variables['content_attributes_array']);\n foreach ($variables['items'] as $delta => $item) {\n $variables['item_attributes'][$delta] = empty($variables['item_attributes_array'][$delta]) ? '' : drupal_attributes($variables['item_attributes_array'][$delta]);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-09796f73d8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_edit_form_submit/7.x", "instruction": "Implement `locale_languages_edit_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process the language editing form submission.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_languages_edit_form_submit($form, &$form_state) {\n db_update('languages')\n ->fields(array(\n 'name' => $form_state['values']['name'],\n 'native' => $form_state['values']['native'],\n 'domain' => $form_state['values']['domain'],\n 'prefix' => $form_state['values']['prefix'],\n 'direction' => $form_state['values']['direction'],\n ))\n ->condition('language', $form_state['values']['langcode'])\n ->execute();\n $default = language_default();\n if ($default->language == $form_state['values']['langcode']) {\n $properties = array('name', 'native', 'direction', 'enabled', 'plurals', 'formula', 'domain', 'prefix', 'weight');\n foreach ($properties as $keyname) {\n if (isset($form_state['values'][$keyname])) {\n $default->$keyname = $form_state['values'][$keyname];\n }\n }\n variable_set('language_default', $default);\n }\n $form_state['redirect'] = 'admin/config/regional/language';\n return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-09c198dae4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_update_index/7.x", "instruction": "In Drupal 7, write the function `comment_update_index()` (file modules/comment/comment.module) so that it does the following: Implements hook_update_index().", "context": "File: modules/comment/comment.module", "response": "function comment_update_index() {\n // Store the maximum possible comments per thread (used for ranking by reply count)\n variable_set('node_cron_comments_scale', 1.0 / max(1, db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')->fetchField()));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-09db7f1863", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_preprocess_maintenance_page/7.x", "instruction": "I need the code for `seven_preprocess_maintenance_page(&$vars)` in Drupal 7 (themes/seven/template.php). It must do this: Override or insert variables into the maintenance page template.", "context": "File: themes/seven/template.php", "response": "function seven_preprocess_maintenance_page(&$vars) {\n // While markup for normal pages is split into page.tpl.php and html.tpl.php,\n // the markup for the maintenance page is all in the single\n // maintenance-page.tpl.php template. So, to have what's done in\n // seven_preprocess_html() also happen on the maintenance page, it has to be\n // called here.\n seven_preprocess_html($vars);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-09ef302cbf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_rdf_mapping/7.x", "instruction": "I need the code for `user_rdf_mapping()` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_rdf_mapping().", "context": "File: modules/user/user.module", "response": "function user_rdf_mapping() {\n return array(\n array(\n 'type' => 'user',\n 'bundle' => RDF_DEFAULT_BUNDLE,\n 'mapping' => array(\n 'rdftype' => array('sioc:UserAccount'),\n 'name' => array(\n 'predicates' => array('foaf:name'),\n ),\n 'homepage' => array(\n 'predicates' => array('foaf:page'),\n 'type' => 'rel',\n ),\n ),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-09f3be93fd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_field_widget_info_alter/7.x", "instruction": "Implement `list_field_widget_info_alter(&$info)` in PHP for Drupal 7. Required behavior: Implements hook_field_widget_info_alter().", "context": "The List module does not implement widgets of its own, but reuses the widgets defined in options.module.\n\nFile: modules/field/modules/list/list.module", "response": "function list_field_widget_info_alter(&$info) {\n $widgets = array(\n 'options_select' => array('list_integer', 'list_float', 'list_text'),\n 'options_buttons' => array('list_integer', 'list_float', 'list_text', 'list_boolean'),\n 'options_onoff' => array('list_boolean'),\n );\n\n foreach ($widgets as $widget => $field_types) {\n $info[$widget]['field types'] = array_merge($info[$widget]['field types'], $field_types);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-09ff88341a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_menu_alter/7.x", "instruction": "I need the code for `comment_menu_alter(&$items)` in Drupal 7 (modules/comment/comment.module). It must do this: Implements hook_menu_alter().", "context": "File: modules/comment/comment.module", "response": "function comment_menu_alter(&$items) {\n // Add comments to the description for admin/content.\n $items['admin/content']['description'] = 'Administer content and comments.';\n\n // Adjust the Field UI tabs on admin/structure/types/manage/[node-type].\n // See comment_entity_info().\n $items['admin/structure/types/manage/%comment_node_type/comment/fields']['title'] = 'Comment fields';\n $items['admin/structure/types/manage/%comment_node_type/comment/fields']['weight'] = 3;\n $items['admin/structure/types/manage/%comment_node_type/comment/display']['title'] = 'Comment display';\n $items['admin/structure/types/manage/%comment_node_type/comment/display']['weight'] = 4;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a03db5d1f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_widget_form/7.x", "instruction": "Implement `file_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)` in PHP for Drupal 7. Required behavior: Implements hook_field_widget_form().", "context": "File: modules/file/file.field.inc", "response": "function file_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {\n\n $defaults = array(\n 'fid' => 0,\n 'display' => !empty($field['settings']['display_default']),\n 'description' => '',\n );\n\n // Load the items for form rebuilds from the field state as they might not be\n // in $form_state['values'] because of validation limitations. Also, they are\n // only passed in as $items when editing existing entities.\n $field_state = field_form_get_state($element['#field_parents'], $field['field_name'], $langcode, $form_state);\n if (isset($field_state['items'])) {\n $items = $field_state['items'];\n }\n\n // Essentially we use the managed_file type, extended with some enhancements.\n $element_info = element_info('managed_file');\n $element += array(\n '#type' => 'managed_file',\n '#upload_location' => file_field_widget_uri($field, $instance),\n '#upload_validators' => file_field_widget_upload_validators($field, $instance),\n '#value_callback' => 'file_field_widget_value',\n '#process' => array_merge($element_info['#process'], array('file_field_widget_process')),\n '#progress_indicator' => $instance['widget']['settings']['progress_indicator'],\n // Allows this field to return an array instead of a single value.\n '#extended' => TRUE,\n );\n\n if ($field['cardinality'] == 1) {\n // Set the default value.\n $element['#default_value'] = !empty($items) ? $items[0] : $defaults;\n // If there's only one field, return it as delta 0.\n if (empty($element['#default_value']['fid'])) {\n $element['#description'] = theme('file_upload_help', array('description' => $element['#description'], 'upload_validators' => $element['#upload_validators']));\n }\n $elements = array($element);\n }\n else {\n // If there are multiple values, add an element for each existing one.\n foreach ($items as $item) {\n $elements[$delta] = $element;\n $elements[$delta]['#default_value'] = $item;\n $elements[$delta]['#weight'] = $delta;\n $delta++;\n }\n // And then add one more empty row for new uploads except when this is a\n // programmed form as it is not necessary.\n if (($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta < $field['cardinality']) && empty($form_state['programmed'])) {\n $elements[$delta] = $element;\n $elements[$delta]['#default_value'] = $defaults;\n $elements[$delta]['#weight'] = $delta;\n $elements[$delta]['#required'] = ($element['#required'] && $delta == 0);\n }\n // The group of elements all-together need some extra functionality\n // after building up the full list (like draggable table rows).\n $elements['#file_upload_delta'] = $delta;\n $elements['#theme'] = 'file_widget_multiple';\n $elements['#theme_wrappers'] = array('fieldset');\n $elements['#process'] = array('file_field_widget_process_multiple');\n $elements['#title'] = $element['#title'];\n $elements['#description'] = $element['#description'];\n $elements['#field_name'] = $element['#field_name'];\n $elements['#language'] = $element['#language'];\n $elements['#display_field'] = $field['settings']['display_field'];\n\n // Add some properties that will eventually be added to the file upload\n // field. These are added here so that they may be referenced easily through\n // a hook_form_alter().\n $elements['#file_upload_title'] = t('Add a new file');\n $elements['#file_upload_description'] = theme('file_upload_help', array('description' => '', 'upload_validators' => $elements[0]['#upload_validators']));\n }\n\n return $elements;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a10d409d9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_base64_encode/7.x", "instruction": "Implement `drupal_base64_encode($string)` in PHP for Drupal 7. Required behavior: Returns a URL-safe, base64 encoded version of the supplied string.", "context": "Parameters:\n- $string: The string to convert to base64.\n\nReturns (string)\n\nFile: includes/bootstrap.inc", "response": "function drupal_base64_encode($string) {\n $data = base64_encode($string);\n // Modify the output so it's safe to use in URLs.\n return strtr($data, array('+' => '-', '/' => '_', '=' => ''));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a1e5482f8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_register_submit/7.x", "instruction": "In Drupal 7, write the function `user_register_submit($form, &$form_state)` (file modules/user/user.module) so that it does the following: Submit handler for the user registration form.", "context": "This function is shared by the installation form and the normal registration form, which is why it can't be in the user.pages.inc file.\n\nFile: modules/user/user.module", "response": "function user_register_submit($form, &$form_state) {\n $admin = $form_state['values']['administer_users'];\n\n if (!variable_get('user_email_verification', TRUE) || $admin) {\n $pass = $form_state['values']['pass'];\n }\n else {\n $pass = user_password();\n }\n $notify = !empty($form_state['values']['notify']);\n\n // Remove unneeded values.\n form_state_values_clean($form_state);\n\n $form_state['values']['pass'] = $pass;\n $form_state['values']['init'] = $form_state['values']['mail'];\n\n $account = $form['#user'];\n\n entity_form_submit_build_entity('user', $account, $form, $form_state);\n\n // Populate $edit with the properties of $account, which have been edited on\n // this form by taking over all values, which appear in the form values too.\n $edit = array_intersect_key((array) $account, $form_state['values']);\n $account = user_save($account, $edit);\n\n // Terminate if an error occurred during user_save().\n if (!$account) {\n drupal_set_message(t(\"Error saving user account.\"), 'error');\n $form_state['redirect'] = '';\n return;\n }\n $form_state['user'] = $account;\n $form_state['values']['uid'] = $account->uid;\n\n watchdog('user', 'New user: %name (%email).', array('%name' => $form_state['values']['name'], '%email' => $form_state['values']['mail']), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));\n\n // Add plain text password into user account to generate mail tokens.\n $account->password = $pass;\n\n // New administrative account without notification.\n $uri = entity_uri('user', $account);\n if ($admin && !$notify) {\n drupal_set_message(t('Created a new user account for %name. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));\n }\n // No e-mail verification required; log in user immediately.\n elseif (!$admin && !variable_get('user_email_verification', TRUE) && $account->status) {\n _user_mail_notify('register_no_approval_required', $account);\n $form_state['uid'] = $account->uid;\n user_login_submit(array(), $form_state);\n drupal_set_message(t('Registration successful. You are now logged in.'));\n $form_state['redirect'] = '';\n }\n // No administrator approval required.\n elseif ($account->status || $notify) {\n $op = $notify ? 'register_admin_created' : 'register_no_approval_required';\n _user_mail_notify($op, $account);\n if ($notify) {\n drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user %name.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));\n }\n else {\n drupal_set_message(t('A welcome message with further instructions has been sent to your e-mail address.'));\n $form_state['redirect'] = '';\n }\n }\n // Administrator approval required.\n else {\n _user_mail_notify('register_pending_approval', $account);\n drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.
        In the meantime, a welcome message with further instructions has been sent to your e-mail address.'));\n $form_state['redirect'] = '';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a40e217b1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/_field_invoke_get_instances/7.x", "instruction": "I need the code for `_field_invoke_get_instances($entity_type, $bundle, $options)` in Drupal 7 (modules/field/field.attach.inc). It must do this: Helper for _field_invoke(): retrieves a list of instances to operate on.", "context": "Parameters:\n- $entity_type: The entity type.\n- $bundle: The bundle name.\n- $options: An associative array of options, as provided to _field_invoke(). Only the following keys are considered : - deleted - field_name - field_id See _field_invoke() for details.\n\nReturns: The array of selected instance definitions.\n\nFile: modules/field/field.attach.inc", "response": "function _field_invoke_get_instances($entity_type, $bundle, $options) {\n if ($options['deleted']) {\n // Deleted fields are not included in field_info_instances(), and need to\n // be fetched from the database with field_read_instances().\n $params = array('entity_type' => $entity_type, 'bundle' => $bundle);\n if (isset($options['field_id'])) {\n // Single-field mode by field id: field_read_instances() does the filtering.\n // Single-field mode by field name is not compatible with the 'deleted'\n // option.\n $params['field_id'] = $options['field_id'];\n }\n $instances = field_read_instances($params, array('include_deleted' => TRUE));\n }\n elseif (isset($options['field_name'])) {\n // Single-field mode by field name: field_info_instance() does the\n // filtering.\n $instances = array(field_info_instance($entity_type, $options['field_name'], $bundle));\n }\n else {\n $instances = field_info_instances($entity_type, $bundle);\n if (isset($options['field_id'])) {\n // Single-field mode by field id: we need to loop on each instance to\n // find the right one.\n foreach ($instances as $instance) {\n if ($instance['field_id'] == $options['field_id']) {\n $instances = array($instance);\n break;\n }\n }\n }\n }\n\n return $instances;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a42f5a869", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_status_messages/7.x", "instruction": "In Drupal 7, write the function `theme_status_messages($variables)` (file includes/theme.inc) so that it does the following: Returns HTML for status and/or error messages, grouped by type.", "context": "An invisible heading identifies the messages for assistive technology. Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html for info.\n\nParameters:\n- $variables: An associative array containing: - display: (optional) Set to 'status' or 'error' to display only messages of that type.\n\nFile: includes/theme.inc", "response": "function theme_status_messages($variables) {\n $display = $variables['display'];\n $output = '';\n\n $status_heading = array(\n 'status' => t('Status message'),\n 'error' => t('Error message'),\n 'warning' => t('Warning message'),\n );\n foreach (drupal_get_messages($display) as $type => $messages) {\n $output .= \"
        \\n\";\n if (!empty($status_heading[$type])) {\n $output .= '

        ' . $status_heading[$type] . \"

        \\n\";\n }\n if (count($messages) > 1) {\n $output .= \"
          \\n\";\n foreach ($messages as $message) {\n $output .= '
        • ' . $message . \"
        • \\n\";\n }\n $output .= \"
        \\n\";\n }\n else {\n $output .= reset($messages);\n }\n $output .= \"
        \\n\";\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a454da632", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21image.inc/function/image_get_info/7.x", "instruction": "In Drupal 7, write the function `image_get_info($filepath, $toolkit = FALSE)` (file includes/image.inc) so that it does the following: Gets details about an image.", "context": "Drupal supports GIF, JPG and PNG file formats when used with the GD toolkit, and may support others, depending on which toolkits are installed.\n\nParameters:\n- $filepath: String specifying the path of the image file.\n- $toolkit: An optional image toolkit name to override the default.\n\nReturns: FALSE, if the file could not be found or is not an image. Otherwise, a keyed array containing information about the image: - \"width\": Width, in pixels. - \"height\": Height, in pixels. - \"extension\": Commonly used file extension for the image. - \"mime_type\": MIME type ('image/jpeg', 'image/gif', 'image/png'). - \"file_size\": File size in bytes.\n\nFile: includes/image.inc", "response": "function image_get_info($filepath, $toolkit = FALSE) {\n $details = FALSE;\n if (!is_file($filepath) && !is_uploaded_file($filepath)) {\n return $details;\n }\n\n if (!$toolkit) {\n $toolkit = image_get_toolkit();\n }\n if ($toolkit) {\n $image = new stdClass();\n $image->source = $filepath;\n $image->toolkit = $toolkit;\n $details = image_toolkit_invoke('get_info', $image);\n if (isset($details) && is_array($details)) {\n $details['file_size'] = filesize($filepath);\n }\n }\n\n return $details;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a4c357fe6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.install/function/simpletest_schema/7.x", "instruction": "Implement `simpletest_schema()` in PHP for Drupal 7. Required behavior: Implements hook_schema().", "context": "File: modules/simpletest/simpletest.install", "response": "function simpletest_schema() {\n $schema['simpletest'] = array(\n 'description' => 'Stores simpletest messages',\n 'fields' => array(\n 'message_id' => array(\n 'type' => 'serial',\n 'not null' => TRUE,\n 'description' => 'Primary Key: Unique simpletest message ID.',\n ),\n 'test_id' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Test ID, messages belonging to the same ID are reported together',\n ),\n 'test_class' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The name of the class that created this message.',\n ),\n 'status' => array(\n 'type' => 'varchar',\n 'length' => 9,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Message status. Core understands pass, fail, exception.',\n ),\n 'message' => array(\n 'type' => 'text',\n 'not null' => TRUE,\n 'description' => 'The message itself.',\n ),\n 'message_group' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The message group this message belongs to. For example: warning, browser, user.',\n ),\n 'function' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Name of the assertion function or method that created this message.',\n ),\n 'line' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Line number on which the function is called.',\n ),\n 'file' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Name of the file where the function is called.',\n ),\n ),\n 'primary key' => array('message_id'),\n 'indexes' => array(\n 'reporter' => array('test_class', 'message_id'),\n ),\n );\n $schema['simpletest_test_id'] = array(\n 'description' => 'Stores simpletest test IDs, used to auto-incrament the test ID so that a fresh test ID is used.',\n 'fields' => array(\n 'test_id' => array(\n 'type' => 'serial',\n 'not null' => TRUE,\n 'description' => 'Primary Key: Unique simpletest ID used to group test results together. Each time a set of tests\n are run a new test ID is used.',\n ),\n 'last_prefix' => array(\n 'type' => 'varchar',\n 'length' => 60,\n 'not null' => FALSE,\n 'default' => '',\n 'description' => 'The last database prefix used during testing.',\n ),\n ),\n 'primary key' => array('test_id'),\n );\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a5fa6e267", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_get_filename_fallback_trigger_error/7.x", "instruction": "In Drupal 7, write the function `_drupal_get_filename_fallback_trigger_error($type, $name, $error_type)` (file includes/bootstrap.inc) so that it does the following: Triggers a user-level warning for missing or unexpectedly moved files.", "context": "Parameters:\n- $type: The type of the item (theme, theme_engine, module, profile).\n- $name: The name of the item for which the filename is requested.\n- $error_type: The type of the error ('missing' or 'moved').\n\nFile: includes/bootstrap.inc", "response": "function _drupal_get_filename_fallback_trigger_error($type, $name, $error_type) {\n // Hide messages due to known bugs that will appear on a lot of sites.\n // @todo Remove this in https://www.drupal.org/node/2383823\n if (empty($name)) {\n return;\n }\n\n // Make sure we only show any missing or moved file errors only once per\n // request.\n static $errors_triggered = array();\n if (empty($errors_triggered[$type][$name][$error_type])) {\n // Use _drupal_trigger_error_with_delayed_logging() here since these are\n // triggered during low-level operations that cannot necessarily be\n // interrupted by a watchdog() call.\n if ($error_type == 'missing') {\n _drupal_trigger_error_with_delayed_logging(format_string('The following @type is missing from the file system: %name. For information about how to fix this, see the documentation page.', array('@type' => $type, '%name' => $name, '@documentation' => 'https://www.drupal.org/node/2487215')), E_USER_WARNING);\n }\n elseif ($error_type == 'moved') {\n _drupal_trigger_error_with_delayed_logging(format_string('The following @type has moved within the file system: %name. In order to fix this, clear caches or put the @type back in its original location. For more information, see the documentation page.', array('@type' => $type, '%name' => $name, '@documentation' => 'https://www.drupal.org/node/2487215')), E_USER_WARNING);\n }\n $errors_triggered[$type][$name][$error_type] = TRUE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a6954bdc5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_block_view/7.x", "instruction": "In Drupal 7, write the function `aggregator_block_view($delta = '')` (file modules/aggregator/aggregator.module) so that it does the following: Implements hook_block_view().", "context": "Generates blocks for the latest news items in each category and feed.\n\nFile: modules/aggregator/aggregator.module", "response": "function aggregator_block_view($delta = '') {\n if (user_access('access news feeds')) {\n $block = array();\n list($type, $id) = explode('-', $delta);\n $result = FALSE;\n switch ($type) {\n case 'feed':\n if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {\n $block['subject'] = check_plain($feed->title);\n $result = db_query_range(\"SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC\", 0, $feed->block, array(':fid' => $id));\n $read_more = theme('more_link', array('url' => 'aggregator/sources/' . $feed->fid, 'title' => t(\"View this feed's recent news.\")));\n }\n break;\n\n case 'category':\n if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {\n $block['subject'] = check_plain($category->title);\n $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $category->block, array(':cid' => $category->cid));\n $read_more = theme('more_link', array('url' => 'aggregator/categories/' . $category->cid, 'title' => t(\"View this category's recent news.\")));\n }\n break;\n }\n\n $items = array();\n if (!empty($result)) {\n foreach ($result as $item) {\n $items[] = theme('aggregator_block_item', array('item' => $item));\n }\n }\n\n // Only display the block if there are items to show.\n if (count($items) > 0) {\n $block['content'] = theme('item_list', array('items' => $items)) . $read_more;\n }\n return $block;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0a98959f1a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.admin.inc/function/path_admin_overview/7.x", "instruction": "Implement `path_admin_overview()` in PHP for Drupal 7. Required behavior: Returns a listing of all defined URL aliases.", "context": "When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.\n\nFile: modules/path/path.admin.inc", "response": "function path_admin_overview() {\n // Get search keys.\n $args = func_get_args();\n $keys = implode('/', $args);\n\n // Add the filter form above the overview table.\n $build['path_admin_filter_form'] = drupal_get_form('path_admin_filter_form', $keys);\n // Enable language column if locale is enabled or if we have any alias with language\n $alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE language <> :language', 0, 1, array(':language' => LANGUAGE_NONE))->fetchField();\n $multilanguage = (module_exists('locale') || $alias_exists);\n\n $header = array();\n $header[] = array('data' => t('Alias'), 'field' => 'alias', 'sort' => 'asc');\n $header[] = array('data' => t('System'), 'field' => 'source');\n if ($multilanguage) {\n $header[] = array('data' => t('Language'), 'field' => 'language');\n }\n $header[] = array('data' => t('Operations'));\n\n $query = db_select('url_alias')->extend('PagerDefault')->extend('TableSort');\n if ($keys) {\n // Replace wildcards with PDO wildcards.\n $query->condition('alias', '%' . preg_replace('!\\*+!', '%', $keys) . '%', 'LIKE');\n }\n $result = $query\n ->fields('url_alias')\n ->orderByHeader($header)\n ->limit(50)\n ->execute();\n\n $rows = array();\n $destination = drupal_get_destination();\n foreach ($result as $data) {\n $row = array();\n $row['data']['alias'] = l($data->alias, $data->source);\n $row['data']['source'] = l($data->source, $data->source, array('alias' => TRUE));\n if ($multilanguage) {\n $row['data']['language'] = module_invoke('locale', 'language_name', $data->language);\n }\n\n $operations = array();\n $operations['edit'] = array(\n 'title' => t('edit'),\n 'href' => \"admin/config/search/path/edit/$data->pid\",\n 'query' => $destination,\n );\n $operations['delete'] = array(\n 'title' => t('delete'),\n 'href' => \"admin/config/search/path/delete/$data->pid\",\n 'query' => $destination,\n );\n $row['data']['operations'] = array(\n 'data' => array(\n '#theme' => 'links',\n '#links' => $operations,\n '#attributes' => array('class' => array('links', 'inline', 'nowrap')),\n ),\n );\n\n // If the system path maps to a different URL alias, highlight this table\n // row to let the user know of old aliases.\n if ($data->alias != drupal_get_path_alias($data->source, $data->language)) {\n $row['class'] = array('warning');\n }\n\n $rows[] = $row;\n }\n\n $build['path_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#empty' => t('No URL aliases available. Add URL alias.', array('@link' => url('admin/config/search/path/add'))),\n );\n $build['path_pager'] = array('#theme' => 'pager');\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0aa03662a0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/_book_toc_recurse/7.x", "instruction": "I need the code for `_book_toc_recurse($tree, $indent, &$toc, $exclude, $depth_limit)` in Drupal 7 (modules/book/book.module). It must do this: Recursively processes and formats menu items for book_toc().", "context": "This helper function recursively modifies the table of contents array for each item in the menu tree, ignoring items in the exclude array or at a depth greater than the limit. Truncates titles over thirty characters and appends an indentation string incremented by depth.\n\nParameters:\n- $tree: The data structure of the book's menu tree. Includes hidden links.\n- $indent: A string appended to each menu item title. Increments by '--' per depth level.\n- $toc: Reference to the table of contents array. This is modified in place, so the function does not have a return value.\n- $exclude: (optional) An array of menu link ID values. Any link whose menu link ID is in this array will be excluded (along with its children). Defaults to an empty array.\n- $depth_limit: Any link deeper than this value will be excluded (along with its children).\n\nFile: modules/book/book.module", "response": "function _book_toc_recurse($tree, $indent, &$toc, $exclude, $depth_limit) {\n foreach ($tree as $data) {\n if ($data['link']['depth'] > $depth_limit) {\n // Don't iterate through any links on this level.\n break;\n }\n\n if (!in_array($data['link']['mlid'], $exclude)) {\n $toc[$data['link']['mlid']] = $indent . ' ' . truncate_utf8($data['link']['title'], 30, TRUE, TRUE);\n if ($data['below']) {\n _book_toc_recurse($data['below'], $indent . '--', $toc, $exclude, $depth_limit);\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0aa5097955", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.install/function/simpletest_uninstall/7.x", "instruction": "In Drupal 7, write the function `simpletest_uninstall()` (file modules/simpletest/simpletest.install) so that it does the following: Implements hook_uninstall().", "context": "File: modules/simpletest/simpletest.install", "response": "function simpletest_uninstall() {\n drupal_load('module', 'simpletest');\n simpletest_clean_database();\n\n // Remove settings variables.\n variable_del('simpletest_httpauth_method');\n variable_del('simpletest_httpauth_username');\n variable_del('simpletest_httpauth_password');\n variable_del('simpletest_clear_results');\n variable_del('simpletest_verbose');\n\n // Remove generated files.\n file_unmanaged_delete_recursive('public://simpletest');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ac2c3d6cf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_tokenize_formula/7.x", "instruction": "Implement `_locale_import_tokenize_formula($formula)` in PHP for Drupal 7. Required behavior: Backward compatible implementation of token_get_all() for formula parsing", "context": "Parameters:\n- $string: A string containing the arithmetic formula.\n\nReturns: The PHP version of the formula.\n\nFile: includes/locale.inc", "response": "function _locale_import_tokenize_formula($formula) {\n $formula = str_replace(\" \", \"\", $formula);\n $tokens = array();\n for ($i = 0; $i < strlen($formula); $i++) {\n if (is_numeric($formula[$i])) {\n $num = $formula[$i];\n $j = $i + 1;\n while ($j < strlen($formula) && is_numeric($formula[$j])) {\n $num .= $formula[$j];\n $j++;\n }\n $i = $j - 1;\n $tokens[] = $num;\n }\n elseif ($pos = strpos(\" =<>!&|\", $formula[$i])) { // We won't have a space\n $next = $formula[$i + 1];\n switch ($pos) {\n case 1:\n case 2:\n case 3:\n case 4:\n if ($next == '=') {\n $tokens[] = $formula[$i] . '=';\n $i++;\n }\n else {\n $tokens[] = $formula[$i];\n }\n break;\n case 5:\n if ($next == '&') {\n $tokens[] = '&&';\n $i++;\n }\n else {\n $tokens[] = $formula[$i];\n }\n break;\n case 6:\n if ($next == '|') {\n $tokens[] = '||';\n $i++;\n }\n else {\n $tokens[] = $formula[$i];\n }\n break;\n }\n }\n else {\n $tokens[] = $formula[$i];\n }\n }\n return $tokens;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ae6bdec78", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_data/7.x", "instruction": "Implement `ajax_command_data($selector, $name, $value)` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'data' command.", "context": "The 'data' command instructs the client to attach the name=value pair of data to the selector via jQuery's data cache.\n\nThis command is implemented by Drupal.ajax.prototype.commands.data() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n- $name: The name or key (in the key value pair) of the data attached to this selector.\n- $value: The value of the data. Not just limited to strings can be any format.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_data($selector, $name, $value) {\n return array(\n 'command' => 'data',\n 'selector' => $selector,\n 'name' => $name,\n 'value' => $value,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b0e2663a8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_storage_delete_field/7.x", "instruction": "I need the code for `field_sql_storage_field_storage_delete_field($field)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_field_storage_delete_field().", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function field_sql_storage_field_storage_delete_field($field) {\n // Mark all data associated with the field for deletion.\n $field['deleted'] = 0;\n $table = _field_sql_storage_tablename($field);\n $revision_table = _field_sql_storage_revision_tablename($field);\n db_update($table)\n ->fields(array('deleted' => 1))\n ->execute();\n\n // Move the table to a unique name while the table contents are being deleted.\n $field['deleted'] = 1;\n $new_table = _field_sql_storage_tablename($field);\n $revision_new_table = _field_sql_storage_revision_tablename($field);\n db_rename_table($table, $new_table);\n db_rename_table($revision_table, $revision_new_table);\n drupal_get_schema(NULL, TRUE);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b17eb30e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/_theme_table_cell/7.x", "instruction": "I need the code for `_theme_table_cell($cell, $header = FALSE)` in Drupal 7 (includes/theme.inc). It must do this: Returns HTML output for a single table cell for theme_table().", "context": "Parameters:\n- $cell: Array of cell information, or string to display in cell.\n- $header (bool): TRUE if this cell is a table header cell, FALSE if it is an ordinary table cell. If $cell is an array with element 'header' set to TRUE, that will override the $header parameter.\n\nReturns: HTML for the cell.\n\nFile: includes/theme.inc", "response": "function _theme_table_cell($cell, $header = FALSE) {\n $attributes = '';\n\n if (is_array($cell)) {\n $data = isset($cell['data']) ? $cell['data'] : '';\n // Cell's data property can be a string or a renderable array.\n if (is_array($data)) {\n $data = drupal_render($data);\n }\n $header |= isset($cell['header']);\n unset($cell['data']);\n unset($cell['header']);\n $attributes = drupal_attributes($cell);\n }\n else {\n $data = $cell;\n }\n\n if ($header) {\n $output = \"$data\";\n }\n else {\n $output = \"$data\";\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b1cfbbe70", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_fallback_format_title/7.x", "instruction": "Implement `filter_fallback_format_title()` in PHP for Drupal 7. Required behavior: Returns the title of the fallback text format.", "context": "Returns (string): The title of the fallback text format.\n\nFile: modules/filter/filter.module", "response": "function filter_fallback_format_title() {\n $fallback_format = filter_format_load(filter_fallback_format());\n return filter_admin_format_title($fallback_format);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b30545b16", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.install/function/profile_update_7002/7.x", "instruction": "I need the code for `profile_update_7002()` in Drupal 7 (modules/profile/profile.install). It must do this: Change the weight column to normal int.", "context": "File: modules/profile/profile.install", "response": "function profile_update_7002() {\n db_change_field('profile_field', 'weight', 'weight', array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Weight of field in relation to other profile fields.',\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b435c3e05", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_form_term/7.x", "instruction": "Implement `taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL)` in PHP for Drupal 7. Required behavior: Form function for the term edit form.", "context": "File: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL) {\n // During initial form build, add the term entity to the form state for use\n // during form building and processing. During a rebuild, use what is in the\n // form state.\n if (!isset($form_state['term'])) {\n $term = is_object($edit) ? $edit : (object) $edit;\n if (!isset($vocabulary) && isset($term->vid)) {\n $vocabulary = taxonomy_vocabulary_load($term->vid);\n }\n $defaults = array(\n 'name' => '',\n 'description' => '',\n 'format' => NULL,\n 'vocabulary_machine_name' => isset($vocabulary) ? $vocabulary->machine_name : NULL,\n 'tid' => NULL,\n 'weight' => 0,\n );\n foreach ($defaults as $key => $value) {\n if (!isset($term->$key)) {\n $term->$key = $value;\n }\n }\n $form_state['term'] = $term;\n }\n else {\n $term = $form_state['term'];\n if (!isset($vocabulary) && isset($term->vid)) {\n $vocabulary = taxonomy_vocabulary_load($term->vid);\n }\n }\n\n $parent = array_keys(taxonomy_get_parents($term->tid));\n $form['#term'] = (array) $term;\n $form['#term']['parent'] = $parent;\n $form['#vocabulary'] = $vocabulary;\n\n // Check for confirmation forms.\n if (isset($form_state['confirm_delete'])) {\n return array_merge($form, taxonomy_term_confirm_delete($form, $form_state, $term->tid));\n }\n\n $form['name'] = array(\n '#type' => 'textfield',\n '#title' => t('Name'),\n '#default_value' => $term->name,\n '#maxlength' => 255,\n '#required' => TRUE,\n '#weight' => -5,\n );\n $form['description'] = array(\n '#type' => 'text_format',\n '#title' => t('Description'),\n '#default_value' => $term->description,\n '#format' => $term->format,\n '#weight' => 0,\n );\n\n $form['vocabulary_machine_name'] = array(\n '#type' => 'value',\n '#value' => isset($term->vocabulary_machine_name) ? $term->vocabulary_machine_name : $vocabulary->name,\n );\n\n $langcode = entity_language('taxonomy_term', $term);\n field_attach_form('taxonomy_term', $term, $form, $form_state, $langcode);\n\n $form['relations'] = array(\n '#type' => 'fieldset',\n '#title' => t('Relations'),\n '#collapsible' => TRUE,\n '#collapsed' => $vocabulary->hierarchy < 2,\n '#weight' => 10,\n );\n\n // taxonomy_get_tree and taxonomy_get_parents may contain large numbers of\n // items so we check for taxonomy_override_selector before loading the\n // full vocabulary. Contrib modules can then intercept before\n // hook_form_alter to provide scalable alternatives.\n if (!variable_get('taxonomy_override_selector', FALSE)) {\n $parent = array_keys(taxonomy_get_parents($term->tid));\n $children = taxonomy_get_tree($vocabulary->vid, $term->tid);\n\n // A term can't be the child of itself, nor of its children.\n foreach ($children as $child) {\n $exclude[] = $child->tid;\n }\n $exclude[] = $term->tid;\n\n $tree = taxonomy_get_tree($vocabulary->vid);\n $options = array('<' . t('root') . '>');\n if (empty($parent)) {\n $parent = array(0);\n }\n foreach ($tree as $item) {\n if (!in_array($item->tid, $exclude)) {\n $options[$item->tid] = str_repeat('-', $item->depth) . $item->name;\n }\n }\n $form['relations']['parent'] = array(\n '#type' => 'select',\n '#title' => t('Parent terms'),\n '#options' => $options,\n '#default_value' => $parent,\n '#multiple' => TRUE,\n );\n\n }\n $form['relations']['weight'] = array(\n '#type' => 'textfield',\n '#title' => t('Weight'),\n '#size' => 6,\n '#default_value' => $term->weight,\n '#description' => t('Terms are displayed in ascending order by weight.'),\n '#required' => TRUE,\n );\n $form['vid'] = array(\n '#type' => 'value',\n '#value' => $vocabulary->vid,\n );\n $form['tid'] = array(\n '#type' => 'value',\n '#value' => $term->tid,\n );\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save'),\n '#weight' => 5,\n );\n\n if ($term->tid) {\n $form['actions']['delete'] = array(\n '#type' => 'submit',\n '#value' => t('Delete'),\n '#access' => user_access(\"delete terms in $vocabulary->vid\") || user_access('administer taxonomy'),\n '#weight' => 10,\n );\n }\n else {\n $form_state['redirect'] = $_GET['q'];\n }\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b561c063f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess_region/7.x", "instruction": "In Drupal 7, write the function `template_preprocess_region(&$variables)` (file includes/theme.inc) so that it does the following: Preprocess variables for region.tpl.php", "context": "Prepares the values passed to the theme_region function to be passed into a pluggable template engine. Uses the region name to generate a template file suggestions. If none are found, the default region.tpl.php is used.\n\nFile: includes/theme.inc", "response": "function template_preprocess_region(&$variables) {\n // Create the $content variable that templates expect.\n $variables['content'] = $variables['elements']['#children'];\n $variables['region'] = $variables['elements']['#region'];\n\n $variables['classes_array'][] = drupal_region_class($variables['region']);\n $variables['theme_hook_suggestions'][] = 'region__' . $variables['region'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b83e09608", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_filter_form_submit/7.x", "instruction": "In Drupal 7, write the function `user_filter_form_submit($form, &$form_state)` (file modules/user/user.admin.inc) so that it does the following: Process result from user administration filter form.", "context": "File: modules/user/user.admin.inc", "response": "function user_filter_form_submit($form, &$form_state) {\n $op = $form_state['values']['op'];\n $filters = user_filters();\n switch ($op) {\n case t('Filter'):\n case t('Refine'):\n // Apply every filter that has a choice selected other than 'any'.\n foreach ($filters as $filter => $options) {\n if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {\n // Merge an array of arrays into one if necessary.\n $options = ($filter == 'permission') ? form_options_flatten($filters[$filter]['options']) : $filters[$filter]['options'];\n // Only accept valid selections offered on the dropdown, block bad input.\n if (isset($options[$form_state['values'][$filter]])) {\n $_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);\n }\n }\n }\n break;\n case t('Undo'):\n array_pop($_SESSION['user_overview_filter']);\n break;\n case t('Reset'):\n $_SESSION['user_overview_filter'] = array();\n break;\n case t('Update'):\n return;\n }\n\n $form_state['redirect'] = 'admin/people';\n return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0b922481ee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_block_user_action/7.x", "instruction": "I need the code for `user_block_user_action(&$entity, $context = array())` in Drupal 7 (modules/user/user.module). It must do this: Blocks a specific user or the current user, if one is not specified.", "context": "Parameters:\n- $entity: (optional) An entity object; if it is provided and it has a uid property, the user with that ID is blocked.\n- $context: (optional) An associative array; if no user ID is found in $entity, the 'uid' element of this array determines the user to block.\n\nFile: modules/user/user.module", "response": "function user_block_user_action(&$entity, $context = array()) {\n // First priority: If there is a $entity->uid, block that user.\n // This is most likely a user object or the author if a node or comment.\n if (isset($entity->uid)) {\n $uid = $entity->uid;\n }\n elseif (isset($context['uid'])) {\n $uid = $context['uid'];\n }\n // If neither of those are valid, then block the current user.\n else {\n $uid = $GLOBALS['user']->uid;\n }\n $account = user_load($uid);\n $account = user_save($account, array('status' => 0));\n watchdog('action', 'Blocked user %name.', array('%name' => $account->name));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0bc845967d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_revision_delete/7.x", "instruction": "I need the code for `node_revision_delete($revision_id)` in Drupal 7 (modules/node/node.module). It must do this: Deletes a node revision.", "context": "Parameters:\n- $revision_id: The revision ID to delete.\n\nFile: modules/node/node.module", "response": "function node_revision_delete($revision_id) {\n if ($revision = node_load(NULL, $revision_id)) {\n // Prevent deleting the current revision.\n $node = node_load($revision->nid);\n if ($revision_id == $node->vid) {\n return FALSE;\n }\n\n db_delete('node_revision')\n ->condition('nid', $revision->nid)\n ->condition('vid', $revision->vid)\n ->execute();\n module_invoke_all('node_revision_delete', $revision);\n field_attach_delete_revision('node', $revision);\n return TRUE;\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0bd4022d51", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_node_info/7.x", "instruction": "Implement `blog_node_info()` in PHP for Drupal 7. Required behavior: Implements hook_node_info().", "context": "File: modules/blog/blog.module", "response": "function blog_node_info() {\n return array(\n 'blog' => array(\n 'name' => t('Blog entry'),\n 'base' => 'blog',\n 'description' => t('Use for multi-user blogs. Every user gets a personal blog.'),\n )\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0bd7eafef4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_path_alias_whitelist_rebuild/7.x", "instruction": "Implement `drupal_path_alias_whitelist_rebuild($source = NULL)` in PHP for Drupal 7. Required behavior: Rebuild the path alias white list.", "context": "Parameters:\n- $source: An optional system path for which an alias is being inserted.\n\nReturns: An array containing a white list of path aliases.\n\nFile: includes/path.inc", "response": "function drupal_path_alias_whitelist_rebuild($source = NULL) {\n // When paths are inserted, only rebuild the whitelist if the system path\n // has a top level component which is not already in the whitelist.\n if (!empty($source)) {\n $whitelist = variable_get('path_alias_whitelist', NULL);\n if (isset($whitelist[strtok($source, '/')])) {\n return $whitelist;\n }\n }\n // For each alias in the database, get the top level component of the system\n // path it corresponds to. This is the portion of the path before the first\n // '/', if present, otherwise the whole path itself.\n $whitelist = array();\n $result = db_query(\"SELECT DISTINCT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias}\");\n foreach ($result as $row) {\n $whitelist[$row->path] = TRUE;\n }\n variable_set('path_alias_whitelist', $whitelist);\n return $whitelist;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0bd97df219", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21language.api.php/function/hook_language_init/7.x", "instruction": "Give me the example code for `hook_language_init()` in Drupal 7. Hook description: Allows modules to act after language initialization has been performed.", "context": "This is primarily needed to provide translation for configuration variables in the proper bootstrap phase. Variables are user-defined strings and therefore should not be translated via t(), since the source string can change without notice and any previous translation would be lost. Moreover, since variables can be used in the bootstrap phase, we need a bootstrap hook to provide a translation early enough to avoid misalignments between code using the original values and code using the translated values. However modules implementing hook_boot() should be aware that language initialization did not happen yet and thus they cannot rely on translated variables.\n\nFile: modules/system/language.api.php", "response": "function hook_language_init() {\n global $language, $conf;\n\n switch ($language->language) {\n case 'it':\n $conf['site_name'] = 'Il mio sito Drupal';\n break;\n\n case 'fr':\n $conf['site_name'] = 'Mon site Drupal';\n break;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0bf75dd641", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_effect_color_validate/7.x", "instruction": "In Drupal 7, write the function `image_effect_color_validate($element, &$form_state)` (file modules/image/image.admin.inc) so that it does the following: Element validate handler to ensure a hexadecimal color value.", "context": "File: modules/image/image.admin.inc", "response": "function image_effect_color_validate($element, &$form_state) {\n if ($element['#value'] != '') {\n $hex_value = preg_replace('/^#/', '', $element['#value']);\n if (!preg_match('/^#[0-9A-F]{3}([0-9A-F]{3})?$/', $element['#value'])) {\n form_error($element, t('!name must be a hexadecimal color value.', array('!name' => $element['#title'])));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c00570557", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_term_confirm_delete_submit/7.x", "instruction": "In Drupal 7, write the function `taxonomy_term_confirm_delete_submit($form, &$form_state)` (file modules/taxonomy/taxonomy.admin.inc) so that it does the following: Submit handler to delete a term after confirmation.", "context": "File: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_term_confirm_delete_submit($form, &$form_state) {\n taxonomy_term_delete($form_state['values']['tid']);\n taxonomy_check_vocabulary_hierarchy($form['#vocabulary'], $form_state['values']);\n drupal_set_message(t('Deleted term %name.', array('%name' => $form_state['values']['name'])));\n watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);\n $form_state['redirect'] = 'admin/structure/taxonomy';\n cache_clear_all();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c04067d5d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/_theme_load_registry/7.x", "instruction": "In Drupal 7, write the function `_theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL, $complete = TRUE)` (file includes/theme.inc) so that it does the following: Gets the theme_registry cache; if it doesn't exist, builds it.", "context": "Parameters:\n- $theme: The loaded $theme object as returned by list_themes().\n- $base_theme: An array of loaded $theme objects representing the ancestor themes in oldest first order.\n- $theme_engine: The name of the theme engine.\n- $complete: Whether to load the complete theme registry or an instance of the ThemeRegistry class.\n\nReturns: The theme registry array, or an instance of the ThemeRegistry class.\n\nFile: includes/theme.inc", "response": "function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL, $complete = TRUE) {\n if ($complete) {\n // Check the theme registry cache; if it exists, use it.\n $cached = cache_get(\"theme_registry:$theme->name\");\n if (isset($cached->data)) {\n $registry = $cached->data;\n }\n else {\n // If not, build one and cache it.\n $registry = _theme_build_registry($theme, $base_theme, $theme_engine);\n // Only persist this registry if all modules are loaded. This assures a\n // complete set of theme hooks.\n if (module_load_all(NULL)) {\n _theme_save_registry($theme, $registry);\n }\n }\n return $registry;\n }\n else {\n return new ThemeRegistry('theme_registry:runtime:' . $theme->name, 'cache');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c28972553", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_store_rendered_content/7.x", "instruction": "Implement `overlay_store_rendered_content($id = NULL, $content = NULL)` in PHP for Drupal 7. Required behavior: Stores strings representing rendered HTML content.", "context": "This function is used to keep a static cache of rendered content that can be referred to later in the page request.\n\nParameters:\n- $id: (Optional) An identifier for the content which is being stored, which will be used as an array key in the returned array. If omitted, no change will be made to the current stored data.\n- $content: (Optional) A string representing the rendered data to store. This only has an effect if $id is also provided.\n\nReturns: An array representing all data that is currently being stored, or an empty array if there is none.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_store_rendered_content($id = NULL, $content = NULL) {\n $rendered_content = &drupal_static(__FUNCTION__, array());\n if (isset($id)) {\n $rendered_content[$id] = $content;\n }\n return $rendered_content;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c41ef0e1a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_load_blocks/7.x", "instruction": "I need the code for `_block_load_blocks()` in Drupal 7 (modules/block/block.module). It must do this: Loads blocks' information from the database.", "context": "Returns: An array of blocks grouped by region.\n\nFile: modules/block/block.module", "response": "function _block_load_blocks() {\n global $theme_key;\n\n $query = db_select('block', 'b');\n $result = $query\n ->fields('b')\n ->condition('b.theme', $theme_key)\n ->condition('b.status', 1)\n ->orderBy('b.region')\n ->orderBy('b.weight')\n ->orderBy('b.module')\n ->addTag('block_load')\n ->addTag('translatable')\n ->execute();\n\n $block_info = $result->fetchAllAssoc('bid');\n // Allow modules to modify the block list.\n drupal_alter('block_list', $block_info);\n\n $blocks = array();\n foreach ($block_info as $block) {\n $blocks[$block->region][\"{$block->module}_{$block->delta}\"] = $block;\n }\n return $blocks;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c43efbbf7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_unpublish_by_keyword_action_form/7.x", "instruction": "In Drupal 7, write the function `comment_unpublish_by_keyword_action_form($context)` (file modules/comment/comment.module) so that it does the following: Form builder; Prepare a form for blacklisted keywords.", "context": "File: modules/comment/comment.module", "response": "function comment_unpublish_by_keyword_action_form($context) {\n $form['keywords'] = array(\n '#title' => t('Keywords'),\n '#type' => 'textarea',\n '#description' => t('The comment will be unpublished if it contains any of the phrases above. Use a case-sensitive, comma-separated list of phrases. Example: funny, bungee jumping, \"Company, Inc.\"'),\n '#default_value' => isset($context['keywords']) ? drupal_implode_tags($context['keywords']) : '',\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c44e582de", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_hash_base64/7.x", "instruction": "I need the code for `drupal_hash_base64($data)` in Drupal 7 (includes/bootstrap.inc). It must do this: Calculates a base-64 encoded, URL-safe sha-256 hash.", "context": "Parameters:\n- $data: String to be hashed.\n\nReturns: A base-64 encoded sha-256 hash, with + replaced with -, / with _ and any = padding characters removed.\n\nFile: includes/bootstrap.inc", "response": "function drupal_hash_base64($data) {\n $hash = base64_encode(hash('sha256', $data, TRUE));\n // Modify the hash so it's safe to use in URLs.\n return strtr($hash, array('+' => '-', '/' => '_', '=' => ''));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c51f5c354", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_block_view/7.x", "instruction": "In Drupal 7, write the function `comment_block_view($delta = '')` (file modules/comment/comment.module) so that it does the following: Implements hook_block_view().", "context": "Generates a block with the most recent comments.\n\nFile: modules/comment/comment.module", "response": "function comment_block_view($delta = '') {\n if (user_access('access comments')) {\n $block['subject'] = t('Recent comments');\n $block['content'] = theme('comment_block');\n\n return $block;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c5798df7f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_search_execute/7.x", "instruction": "Give me the example code for `hook_search_execute($keys = NULL, $conditions = NULL)` in Drupal 7. Hook description: Execute a search for a set of key words.", "context": "Use database API with the 'PagerDefault' query extension to perform your search.\n\nIf your module uses hook_update_index() and search_index() to index its items, use table 'search_index' aliased to 'i' as the main table in your query, with the 'SearchQuery' extension. You can join to your module's table using the 'i.sid' field, which will contain the $sid values you provided to search_index(). Add the main keywords to the query by using method searchExpression(). The functions search_expression_extract() and search_expression_insert() may also be helpful for adding custom search parameters to the search expression.\n\nSee node_search_execute() for an example of a module that uses the search index, and user_search_execute() for an example that doesn't use the search index.\n\nParameters:\n- $keys: The search keywords as entered by the user.\n- $conditions: An optional array of additional conditions, such as filters.\n\nReturns: An array of search results. To use the default search result display, each item should have the following keys': - 'link': Required. The URL of the found item. - 'type': The type of item (such as the content type). - 'title': Required. The name of the item. - 'user': The author of the item. - 'date': A timestamp when the item was last modified. - 'extra': An array of optional extra information items. - 'snippet': An excerpt or preview to show with the result (can be generated with search_excerpt()). - 'language': Language code for the item (usually two characters).\n\nFile: modules/search/search.api.php", "response": "function hook_search_execute($keys = NULL, $conditions = NULL) {\n // Build matching conditions\n $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');\n $query->join('node', 'n', 'n.nid = i.sid');\n $query\n ->condition('n.status', 1)\n ->addTag('node_access')\n ->searchExpression($keys, 'node');\n\n // Insert special keywords.\n $query->setOption('type', 'n.type');\n $query->setOption('language', 'n.language');\n if ($query->setOption('term', 'ti.tid')) {\n $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');\n }\n // Only continue if the first pass query matches.\n if (!$query->executeFirstPass()) {\n return array();\n }\n\n // Add the ranking expressions.\n _node_rankings($query);\n\n // Load results.\n $find = $query\n ->limit(10)\n ->execute();\n $results = array();\n foreach ($find as $item) {\n // Build the node body.\n $node = node_load($item->sid);\n node_build_content($node, 'search_result');\n $node->body = drupal_render($node->content);\n\n // Fetch comments for snippet.\n $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);\n // Fetch terms for snippet.\n $node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node);\n\n $extra = module_invoke_all('node_search_result', $node);\n\n $results[] = array(\n 'link' => url('node/' . $item->sid, array('absolute' => TRUE)),\n 'type' => check_plain(node_type_get_name($node)),\n 'title' => $node->title,\n 'user' => theme('username', array('account' => $node)),\n 'date' => $node->changed,\n 'node' => $node,\n 'extra' => $extra,\n 'score' => $item->calculated_score,\n 'snippet' => search_excerpt($keys, $node->body),\n );\n }\n return $results;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c6097b262", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_expression_extract/7.x", "instruction": "I need the code for `search_expression_extract($expression, $option)` in Drupal 7 (modules/search/search.module). It must do this: Extracts a module-specific search option from a search expression.", "context": "Search options are added using search_expression_insert(), and retrieved using search_expression_extract(). They take the form option:value, and are added to the ordinary keywords in the search expression.\n\nParameters:\n- $expression: The search expression to extract from.\n- $option: The name of the option to retrieve from the search expression.\n\nReturns: The value previously stored in the search expression for option $option, if any. Trailing spaces in values will not be included.\n\nFile: modules/search/search.module", "response": "function search_expression_extract($expression, $option) {\n if (preg_match('/(^| )' . $option . ':([^ ]*)( |$)/i', $expression, $matches)) {\n return $matches[2];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0c74d4edfc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_message_tag_open/7.x", "instruction": "Implement `xmlrpc_message_tag_open($parser, $tag, $attr)` in PHP for Drupal 7. Required behavior: Handles opening tags for XML parsing in xmlrpc_message_parse().", "context": "File: includes/xmlrpc.inc", "response": "function xmlrpc_message_tag_open($parser, $tag, $attr) {\n $xmlrpc_message = xmlrpc_message_get();\n $xmlrpc_message->current_tag_contents = '';\n $xmlrpc_message->last_open = $tag;\n switch ($tag) {\n case 'methodCall':\n case 'methodResponse':\n case 'fault':\n $xmlrpc_message->messagetype = $tag;\n break;\n\n // Deal with stacks of arrays and structs\n case 'data':\n $xmlrpc_message->array_structs_types[] = 'array';\n $xmlrpc_message->array_structs[] = array();\n break;\n\n case 'struct':\n $xmlrpc_message->array_structs_types[] = 'struct';\n $xmlrpc_message->array_structs[] = array();\n break;\n }\n xmlrpc_message_set($xmlrpc_message);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0cac16c077", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21pager.inc/function/pager_get_query_parameters/7.x", "instruction": "Implement `pager_get_query_parameters()` in PHP for Drupal 7. Required behavior: Compose a URL query parameter array for pager links.", "context": "Returns: A URL query parameter array that consists of all components of the current page request except for those pertaining to paging.\n\nFile: includes/pager.inc", "response": "function pager_get_query_parameters() {\n $query = &drupal_static(__FUNCTION__);\n if (!isset($query)) {\n $query = drupal_get_query_parameters($_GET, array('q', 'page'));\n }\n return $query;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0cd333c4e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/_form_options_flatten/7.x", "instruction": "I need the code for `_form_options_flatten($array)` in Drupal 7 (includes/form.inc). It must do this: Iterates over an array and returns a flat array with duplicate keys removed.", "context": "This function also handles cases where objects are passed as array values.\n\nFile: includes/form.inc", "response": "function _form_options_flatten($array) {\n $return = &drupal_static(__FUNCTION__);\n\n foreach ($array as $key => $value) {\n if (is_object($value)) {\n _form_options_flatten($value->option);\n }\n elseif (is_array($value)) {\n _form_options_flatten($value);\n }\n else {\n $return[$key] = 1;\n }\n }\n\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ceef0f655", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_url_escape_comments/7.x", "instruction": "I need the code for `_filter_url_escape_comments($match, $escape = NULL)` in Drupal 7 (modules/filter/filter.module). It must do this: Escapes the contents of HTML comments.", "context": "Callback for preg_replace_callback() within _filter_url().\n\nParameters:\n- $match: An array containing matches to replace from preg_replace_callback(), whereas $match[1] is expected to contain the content to be filtered.\n- $escape: (optional) A Boolean indicating whether to escape (TRUE) or unescape comments (FALSE). Defaults to NULL, indicating neither. If TRUE, statically cached $comments are reset.\n\nFile: modules/filter/filter.module", "response": "function _filter_url_escape_comments($match, $escape = NULL) {\n static $mode, $comments = array();\n\n if (isset($escape)) {\n $mode = $escape;\n if ($escape){\n $comments = array();\n }\n return;\n }\n\n // Replace all HTML coments with a '' placeholder.\n if ($mode) {\n $content = $match[1];\n $hash = hash('sha256', $content);\n $comments[$hash] = $content;\n return \"\";\n }\n // Or replace placeholders with actual comment contents.\n else {\n $hash = $match[1];\n $hash = trim($hash);\n $content = $comments[$hash];\n return \"\";\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d009924a0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_hook_info/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_hook_info()` (modules/system/system.api.php): Defines one or more hooks that are exposed by a module.", "context": "Normally hooks do not need to be explicitly defined. However, by declaring a hook explicitly, a module may define a \"group\" for it. Modules that implement a hook may then place their implementation in either $module.module or in $module.$group.inc. If the hook is located in $module.$group.inc, then that file will be automatically loaded when needed. In general, hooks that are rarely invoked and/or are very large should be placed in a separate include file, while hooks that are very short or very frequently called should be left in the main module file so that they are always available.\n\nReturns: An associative array whose keys are hook names and whose values are an associative array containing: - group: A string defining the group to which the hook belongs. The module system will determine whether a file with the name $module.$group.inc exists, and automatically load it when required. See system_hook_info() for all hook groups defined by Drupal core.\n\nFile: modules/system/system.api.php", "response": "function hook_hook_info() {\n $hooks['token_info'] = array(\n 'group' => 'tokens',\n );\n $hooks['tokens'] = array(\n 'group' => 'tokens',\n );\n return $hooks;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d159cf85d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_delete/7.x", "instruction": "In Drupal 7, write the function `comment_node_delete($node)` (file modules/comment/comment.module) so that it does the following: Implements hook_node_delete().", "context": "File: modules/comment/comment.module", "response": "function comment_node_delete($node) {\n $cids = db_query('SELECT cid FROM {comment} WHERE nid = :nid', array(':nid' => $node->nid))->fetchCol();\n comment_delete_multiple($cids);\n db_delete('node_comment_statistics')\n ->condition('nid', $node->nid)\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d19b0847d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.parser.inc/function/aggregator_parse_feed/7.x", "instruction": "I need the code for `aggregator_parse_feed(&$data, $feed)` in Drupal 7 (modules/aggregator/aggregator.parser.inc). It must do this: Parses a feed and stores its items.", "context": "Parameters:\n- $data: The feed data.\n- $feed: An object describing the feed to be parsed.\n\nReturns: FALSE on error, TRUE otherwise.\n\nFile: modules/aggregator/aggregator.parser.inc", "response": "function aggregator_parse_feed(&$data, $feed) {\n global $items, $image, $channel;\n\n // Unset the global variables before we use them.\n unset($GLOBALS['element'], $GLOBALS['item'], $GLOBALS['tag']);\n $items = array();\n $image = array();\n $channel = array();\n\n // Parse the data.\n $xml_parser = drupal_xml_parser_create($data);\n xml_set_element_handler($xml_parser, 'aggregator_element_start', 'aggregator_element_end');\n xml_set_character_data_handler($xml_parser, 'aggregator_element_data');\n\n if (!xml_parse($xml_parser, $data, 1)) {\n watchdog('aggregator', 'The feed from %site seems to be broken, due to an error \"%error\" on line %line.', array('%site' => $feed->title, '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser)), WATCHDOG_WARNING);\n drupal_set_message(t('The feed from %site seems to be broken, because of error \"%error\" on line %line.', array('%site' => $feed->title, '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), 'error');\n return FALSE;\n }\n xml_parser_free($xml_parser);\n\n // We reverse the array such that we store the first item last, and the last\n // item first. In the database, the newest item should be at the top.\n $items = array_reverse($items);\n\n // Initialize items array.\n $feed->items = array();\n foreach ($items as $item) {\n\n // Prepare the item:\n foreach ($item as $key => $value) {\n $item[$key] = trim($value);\n }\n\n // Resolve the item's title. If no title is found, we use up to 255\n // characters of the description ending at a word boundary.\n if (!empty($item['title'])) {\n $item['title'] = $item['title'];\n }\n elseif (!empty($item['description'])) {\n $clean_description = strip_tags(html_entity_decode($item['description'], ENT_QUOTES, 'UTF-8'));\n $item['title'] = truncate_utf8($clean_description, 255, TRUE, TRUE);\n }\n else {\n $item['title'] = '';\n }\n\n // Resolve the items link.\n if (!empty($item['link'])) {\n $item['link'] = $item['link'];\n }\n else {\n $item['link'] = $feed->link;\n }\n\n // Atom feeds have an ID tag instead of a GUID tag.\n if (!isset($item['guid'])) {\n $item['guid'] = isset($item['id']) ? $item['id'] : '';\n }\n\n // Atom feeds have a content and/or summary tag instead of a description tag.\n if (!empty($item['content:encoded'])) {\n $item['description'] = $item['content:encoded'];\n }\n elseif (!empty($item['summary'])) {\n $item['description'] = $item['summary'];\n }\n elseif (!empty($item['content'])) {\n $item['description'] = $item['content'];\n }\n\n // Try to resolve and parse the item's publication date.\n $date = '';\n foreach (array('pubdate', 'dc:date', 'dcterms:issued', 'dcterms:created', 'dcterms:modified', 'issued', 'created', 'modified', 'published', 'updated') as $key) {\n if (!empty($item[$key])) {\n $date = $item[$key];\n break;\n }\n }\n\n $item['timestamp'] = strtotime($date);\n\n if ($item['timestamp'] === FALSE) {\n $item['timestamp'] = aggregator_parse_w3cdtf($date); // Aggregator_parse_w3cdtf() returns FALSE on failure.\n }\n\n // Resolve dc:creator tag as the item author if author tag is not set.\n if (empty($item['author']) && !empty($item['dc:creator'])) {\n $item['author'] = $item['dc:creator'];\n }\n\n $item += array('author' => '', 'description' => '');\n\n // Store on $feed object. This is where processors will look for parsed items.\n $feed->items[] = $item;\n }\n\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d495f2491", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_primary_local_tasks/7.x", "instruction": "In Drupal 7, write the function `menu_primary_local_tasks()` (file includes/menu.inc) so that it does the following: Returns the rendered local tasks at the top level.", "context": "File: includes/menu.inc", "response": "function menu_primary_local_tasks() {\n $links = menu_local_tasks(0);\n // Do not display single tabs.\n return ($links['tabs']['count'] > 1 ? $links['tabs']['output'] : '');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d5072e447", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_no_data/7.x", "instruction": "In Drupal 7, write the function `_update_no_data()` (file modules/update/update.module) so that it does the following: Returns a warning message when there is no data about available updates.", "context": "File: modules/update/update.module", "response": "function _update_no_data() {\n $destination = drupal_get_destination();\n $cron_token = array('token' => drupal_get_token('run-cron'));\n return t('No update information available. Run cron or check manually.', array(\n '@run_cron' => url('admin/reports/status/run-cron', array('query' => $cron_token + $destination)),\n '@check_manually' => url('admin/reports/updates/check', array('query' => $destination)),\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d5dcb0d4a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_run_task/7.x", "instruction": "In Drupal 7, write the function `install_run_task($task, &$install_state)` (file includes/install.core.inc) so that it does the following: Runs an individual installation task.", "context": "Parameters:\n- $task: An array of information about the task to be run as returned by hook_install_tasks().\n- $install_state: An array of information about the current installation state. This is passed in by reference so that it can be modified by the task.\n\nReturns: The output of the task function, if there is any.\n\nFile: includes/install.core.inc", "response": "function install_run_task($task, &$install_state) {\n $function = $task['function'];\n\n if ($task['type'] == 'form') {\n require_once DRUPAL_ROOT . '/includes/form.inc';\n if ($install_state['interactive']) {\n // For interactive forms, build the form and ensure that it will not\n // redirect, since the installer handles its own redirection only after\n // marking the form submission task complete.\n $form_state = array(\n // We need to pass $install_state by reference in order for forms to\n // modify it, since the form API will use it in call_user_func_array(),\n // which requires that referenced variables be passed explicitly.\n 'build_info' => array('args' => array(&$install_state)),\n 'no_redirect' => TRUE,\n );\n $form = drupal_build_form($function, $form_state);\n // If a successful form submission did not occur, the form needs to be\n // rendered, which means the task is not complete yet.\n if (empty($form_state['executed'])) {\n $install_state['task_not_complete'] = TRUE;\n return drupal_render($form);\n }\n // Otherwise, return nothing so the next task will run in the same\n // request.\n return;\n }\n else {\n // For non-interactive forms, submit the form programmatically with the\n // values taken from the installation state. Throw an exception if any\n // errors were encountered.\n $form_state = array(\n 'values' => !empty($install_state['forms'][$function]) ? $install_state['forms'][$function] : array(),\n // We need to pass $install_state by reference in order for forms to\n // modify it, since the form API will use it in call_user_func_array(),\n // which requires that referenced variables be passed explicitly.\n 'build_info' => array('args' => array(&$install_state)),\n );\n drupal_form_submit($function, $form_state);\n $errors = form_get_errors();\n if (!empty($errors)) {\n throw new Exception(implode(\"\\n\", $errors));\n }\n }\n }\n\n elseif ($task['type'] == 'batch') {\n // Start a new batch based on the task function, if one is not running\n // already.\n $current_batch = variable_get('install_current_batch');\n if (!$install_state['interactive'] || !$current_batch) {\n $batch = $function($install_state);\n if (empty($batch)) {\n // If the task did some processing and decided no batch was necessary,\n // there is nothing more to do here.\n return;\n }\n batch_set($batch);\n // For interactive batches, we need to store the fact that this batch\n // task is currently running. Otherwise, we need to make sure the batch\n // will complete in one page request.\n if ($install_state['interactive']) {\n variable_set('install_current_batch', $function);\n }\n else {\n $batch =& batch_get();\n $batch['progressive'] = FALSE;\n }\n // Process the batch. For progressive batches, this will redirect.\n // Otherwise, the batch will complete.\n batch_process(install_redirect_url($install_state), install_full_redirect_url($install_state));\n }\n // If we are in the middle of processing this batch, keep sending back\n // any output from the batch process, until the task is complete.\n elseif ($current_batch == $function) {\n include_once DRUPAL_ROOT . '/includes/batch.inc';\n $output = _batch_page();\n // The task is complete when we try to access the batch page and receive\n // FALSE in return, since this means we are at a URL where we are no\n // longer requesting a batch ID.\n if ($output === FALSE) {\n // Return nothing so the next task will run in the same request.\n variable_del('install_current_batch');\n return;\n }\n else {\n // We need to force the page request to end if the task is not\n // complete, since the batch API sometimes prints JSON output\n // rather than returning a themed page.\n $install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE;\n return $output;\n }\n }\n }\n\n else {\n // For normal tasks, just return the function result, whatever it is.\n return $function($install_state);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d74a5f484", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_gd/7.x", "instruction": "Implement `_color_gd($img, $hex)` in PHP for Drupal 7. Required behavior: Converts a hex triplet into a GD color.", "context": "File: modules/color/color.module", "response": "function _color_gd($img, $hex) {\n $c = array_merge(array($img), _color_unpack($hex));\n return call_user_func_array('imagecolorallocate', $c);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d7d856e74", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/theme_locale_date_format_form/7.x", "instruction": "Implement `theme_locale_date_format_form($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a locale date format form.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/locale/locale.admin.inc", "response": "function theme_locale_date_format_form($variables) {\n $form = $variables['form'];\n $header = array(\n t('Date type'),\n t('Format'),\n );\n\n foreach (element_children($form['date_formats']) as $key) {\n $row = array();\n $row[] = $form['date_formats'][$key]['#title'];\n unset($form['date_formats'][$key]['#title']);\n $row[] = array('data' => drupal_render($form['date_formats'][$key]));\n $rows[] = $row;\n }\n\n $output = drupal_render($form['language']);\n $output .= theme('table', array('header' => $header, 'rows' => $rows));\n $output .= drupal_render_children($form);\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d81aed0f7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_flush_caches/7.x", "instruction": "Implement `update_flush_caches()` in PHP for Drupal 7. Required behavior: Implements hook_flush_caches().", "context": "Called from update.php (among others) to flush the caches. Since we're running update.php, we are likely to install a new version of something, in which case, we want to check for available update data again. However, because we have our own caching system, we need to directly clear the database table ourselves at this point and return nothing, for example, on sites that use memcache where cache_clear_all() won't know how to purge this data.\n\nHowever, we only want to do this from update.php, since otherwise, we'd lose all the available update data on every cron run. So, we specifically check if the site is in MAINTENANCE_MODE == 'update' (which indicates update.php is running, not update module... alas for overloaded names).\n\nFile: modules/update/update.module", "response": "function update_flush_caches() {\n if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {\n _update_cache_clear();\n }\n return array();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d93db6b2a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_format_allowcache/7.x", "instruction": "In Drupal 7, write the function `filter_format_allowcache($format_id)` (file modules/filter/filter.module) so that it does the following: Checks if the text in a certain text format is allowed to be cached.", "context": "This function can be used to check whether the result of the filtering process can be cached. A text format may allow caching depending on the filters enabled.\n\nParameters:\n- $format_id: The text format ID to check.\n\nReturns: TRUE if the given text format allows caching, FALSE otherwise.\n\nFile: modules/filter/filter.module", "response": "function filter_format_allowcache($format_id) {\n $format = filter_format_load($format_id);\n return !empty($format->cache);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d945d8bb0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_display_overview_multistep_submit/7.x", "instruction": "Implement `field_ui_display_overview_multistep_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for buttons in field_ui_display_overview_form().", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_display_overview_multistep_submit($form, &$form_state) {\n $trigger = $form_state['triggering_element'];\n $op = $trigger['#op'];\n\n switch ($op) {\n case 'edit':\n // Store the field whose settings are currently being edited.\n $field_name = $trigger['#field_name'];\n $form_state['formatter_settings_edit'] = $field_name;\n break;\n\n case 'update':\n // Store the saved settings, and set the field back to 'non edit' mode.\n $field_name = $trigger['#field_name'];\n $values = $form_state['values']['fields'][$field_name]['settings_edit_form']['settings'];\n $form_state['formatter_settings'][$field_name] = $values;\n unset($form_state['formatter_settings_edit']);\n break;\n\n case 'cancel':\n // Set the field back to 'non edit' mode.\n unset($form_state['formatter_settings_edit']);\n break;\n\n case 'refresh_table':\n // If the currently edited field is one of the rows to be refreshed, set\n // it back to 'non edit' mode.\n $updated_rows = explode(' ', $form_state['values']['refresh_rows']);\n if (isset($form_state['formatter_settings_edit']) && in_array($form_state['formatter_settings_edit'], $updated_rows)) {\n unset($form_state['formatter_settings_edit']);\n }\n break;\n }\n\n $form_state['rebuild'] = TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0d98dcea29", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/theme_trigger_display/7.x", "instruction": "Implement `theme_trigger_display($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the form showing actions assigned to a trigger.", "context": "Parameters:\n- $variables: An associative array containing: - element: The fieldset including all assigned actions.\n\nFile: modules/trigger/trigger.admin.inc", "response": "function theme_trigger_display($variables) {\n $element = $variables['element'];\n\n $header = array();\n $rows = array();\n if (isset($element['assigned']) && count($element['assigned']['#value'])) {\n $header = array(array('data' => t('Name')), array('data' => t('Operation')));\n $rows = array();\n foreach ($element['assigned']['#value'] as $aid => $info) {\n $rows[] = array(\n check_plain($info['label']),\n $info['link']\n );\n }\n }\n\n if (count($rows)) {\n $output = theme('table', array('header' => $header, 'rows' => $rows)) . drupal_render_children($element);\n }\n else {\n $output = drupal_render_children($element);\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0db33e3973", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/_list_values_in_use/7.x", "instruction": "I need the code for `_list_values_in_use($field, $values)` in Drupal 7 (modules/field/modules/list/list.module). It must do this: Checks if a list of values are being used in actual field values.", "context": "File: modules/field/modules/list/list.module", "response": "function _list_values_in_use($field, $values) {\n if ($values) {\n $query = new EntityFieldQuery();\n $found = $query\n ->fieldCondition($field['field_name'], 'value', $values)\n ->range(0, 1)\n ->execute();\n return !empty($found);\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0db38c8379", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/function/hook_filter_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_filter_info_alter(&$info)` (modules/filter/filter.api.php): Perform alterations on filter definitions.", "context": "Parameters:\n- $info: Array of information on filters exposed by hook_filter_info() implementations.\n\nFile: modules/filter/filter.api.php", "response": "function hook_filter_info_alter(&$info) {\n // Replace the PHP evaluator process callback with an improved\n // PHP evaluator provided by a module.\n $info['php_code']['process callback'] = 'my_module_php_evaluator';\n\n // Alter the default settings of the URL filter provided by core.\n $info['filter_url']['default settings'] = array(\n 'filter_url_length' => 100,\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0dbe5a6e1e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_presave/7.x", "instruction": "In Drupal 7, write the function `file_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items)` (file modules/file/file.field.inc) so that it does the following: Implements hook_field_presave().", "context": "File: modules/file/file.field.inc", "response": "function file_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {\n // Make sure that each file which will be saved with this object has a\n // permanent status, so that it will not be removed when temporary files are\n // cleaned up.\n foreach ($items as $delta => $item) {\n if (empty($item['fid'])) {\n unset($items[$delta]);\n continue;\n }\n $file = file_load($item['fid']);\n if (empty($file)) {\n unset($items[$delta]);\n continue;\n }\n if (!$file->status) {\n $file->status = FILE_STATUS_PERMANENT;\n file_save($file);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0dbeb71455", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.install/function/dashboard_disable/7.x", "instruction": "I need the code for `dashboard_disable()` in Drupal 7 (modules/dashboard/dashboard.install). It must do this: Implements hook_disable().", "context": "Stash a list of blocks enabled on the dashboard, so they can be re-enabled if the dashboard is re-enabled. Then disable those blocks, since the dashboard regions will no longer be defined.\n\nFile: modules/dashboard/dashboard.install", "response": "function dashboard_disable() {\n // Stash a list of currently enabled blocks.\n $stashed_blocks = array();\n\n $result = db_select('block', 'b')\n ->fields('b', array('module', 'delta', 'region'))\n ->condition('b.region', dashboard_regions(), 'IN')\n ->execute();\n\n foreach ($result as $block) {\n $stashed_blocks[] = array(\n 'module' => $block->module,\n 'delta' => $block->delta,\n 'region' => $block->region,\n );\n }\n variable_set('dashboard_stashed_blocks', $stashed_blocks);\n\n // Disable the dashboard blocks.\n db_update('block')\n ->fields(array(\n 'status' => 0,\n 'region' => BLOCK_REGION_NONE,\n ))\n ->condition('region', dashboard_regions(), 'IN')\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0dc2d31c33", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_save_feed/7.x", "instruction": "Implement `aggregator_save_feed($edit)` in PHP for Drupal 7. Required behavior: Add/edit/delete an aggregator feed.", "context": "Parameters:\n- $edit: An associative array describing the feed to be added/edited/deleted.\n\nFile: modules/aggregator/aggregator.module", "response": "function aggregator_save_feed($edit) {\n if (!empty($edit['fid'])) {\n // An existing feed is being modified, delete the category listings.\n db_delete('aggregator_category_feed')\n ->condition('fid', $edit['fid'])\n ->execute();\n }\n if (!empty($edit['fid']) && !empty($edit['title'])) {\n db_update('aggregator_feed')\n ->condition('fid', $edit['fid'])\n ->fields(array(\n 'title' => $edit['title'],\n 'url' => $edit['url'],\n 'refresh' => $edit['refresh'],\n 'block' => $edit['block'],\n ))\n ->execute();\n }\n elseif (!empty($edit['fid'])) {\n $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $edit['fid']))->fetchCol();\n if ($iids) {\n db_delete('aggregator_category_item')\n ->condition('iid', $iids, 'IN')\n ->execute();\n }\n db_delete('aggregator_feed')->\n condition('fid', $edit['fid'])\n ->execute();\n db_delete('aggregator_item')\n ->condition('fid', $edit['fid'])\n ->execute();\n // Make sure there is no active block for this feed.\n if (module_exists('block')) {\n db_delete('block')\n ->condition('module', 'aggregator')\n ->condition('delta', 'feed-' . $edit['fid'])\n ->execute();\n }\n }\n elseif (!empty($edit['title'])) {\n $edit['fid'] = db_insert('aggregator_feed')\n ->fields(array(\n 'title' => $edit['title'],\n 'url' => $edit['url'],\n 'refresh' => $edit['refresh'],\n 'block' => $edit['block'],\n 'link' => '',\n 'description' => '',\n 'image' => '',\n ))\n ->execute();\n\n }\n if (!empty($edit['title'])) {\n // The feed is being saved, save the categories as well.\n if (!empty($edit['category'])) {\n foreach ($edit['category'] as $cid => $value) {\n if ($value) {\n db_insert('aggregator_category_feed')\n ->fields(array(\n 'fid' => $edit['fid'],\n 'cid' => $cid,\n ))\n ->execute();\n }\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0dde58af8d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/theme_simpletest_result_summary/7.x", "instruction": "Implement `theme_simpletest_result_summary($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the summary status of a simpletest result.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/simpletest/simpletest.pages.inc", "response": "function theme_simpletest_result_summary($variables) {\n $form = $variables['form'];\n return '
        ' . _simpletest_format_summary_line($form) . '
        ';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0dea79f354", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_build_content/7.x", "instruction": "Implement `comment_build_content($comment, $node, $view_mode = 'full', $langcode = NULL)` in PHP for Drupal 7. Required behavior: Builds a structured array representing the comment's content.", "context": "The content built for the comment (field values, comments, file attachments or other comment components) will vary depending on the $view_mode parameter.\n\nParameters:\n- $comment: A comment object.\n- $node: The node the comment is attached to.\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nFile: modules/comment/comment.module", "response": "function comment_build_content($comment, $node, $view_mode = 'full', $langcode = NULL) {\n if (!isset($langcode)) {\n $langcode = $GLOBALS['language_content']->language;\n }\n\n // Remove previously built content, if exists.\n $comment->content = array();\n\n // Allow modules to change the view mode.\n $view_mode = key(entity_view_mode_prepare('comment', array($comment->cid => $comment), $view_mode, $langcode));\n\n // Build fields content.\n field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode);\n entity_prepare_view('comment', array($comment->cid => $comment), $langcode);\n $comment->content += field_attach_view('comment', $comment, $view_mode, $langcode);\n\n $comment->content['links'] = array(\n '#theme' => 'links__comment',\n '#pre_render' => array('drupal_pre_render_links'),\n '#attributes' => array('class' => array('links', 'inline')),\n );\n if (empty($comment->in_preview)) {\n $comment->content['links']['comment'] = array(\n '#theme' => 'links__comment__comment',\n '#links' => comment_links($comment, $node),\n '#attributes' => array('class' => array('links', 'inline')),\n );\n }\n\n // Allow modules to make their own additions to the comment.\n module_invoke_all('comment_view', $comment, $view_mode, $langcode);\n module_invoke_all('entity_view', $comment, 'comment', $view_mode, $langcode);\n\n // Make sure the current view mode is stored if no module has already\n // populated the related key.\n $comment->content += array('#view_mode' => $view_mode);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0dffece9ef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_more_choices_submit/7.x", "instruction": "I need the code for `poll_more_choices_submit($form, &$form_state)` in Drupal 7 (modules/poll/poll.module). It must do this: Submit handler to add more choices to a poll form.", "context": "This handler is run regardless of whether JS is enabled or not. It makes changes to the form state. If the button was clicked with JS disabled, then the page is reloaded with the complete rebuilt form. If the button was clicked with JS enabled, then ajax_form_callback() calls poll_choice_js() to return just the changed part of the form.\n\nFile: modules/poll/poll.module", "response": "function poll_more_choices_submit($form, &$form_state) {\n // If this is a Ajax POST, add 1, otherwise add 5 more choices to the form.\n if ($form_state['values']['poll_more']) {\n $n = $_GET['q'] == 'system/ajax' ? 1 : 5;\n $form_state['choice_count'] = count($form_state['values']['choice']) + $n;\n }\n // Renumber the choices. This invalidates the corresponding key/value\n // associations in $form_state['input'], so clear that out. This requires\n // poll_form() to rebuild the choices with the values in\n // $form_state['node']->choice, which it does.\n $form_state['node']->choice = array_values($form_state['values']['choice']);\n unset($form_state['input']['choice']);\n $form_state['rebuild'] = TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0e2295091c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpcs.inc/function/xmlrpc_server/7.x", "instruction": "I need the code for `xmlrpc_server($callbacks)` in Drupal 7 (includes/xmlrpcs.inc). It must do this: Invokes XML-RPC methods on this server.", "context": "Parameters:\n- $callbacks (array): Either an associative array of external XML-RPC method names as keys with the callbacks they map to as values, or a more complex structure describing XML-RPC callbacks as returned from hook_xmlrpc().\n\nFile: includes/xmlrpcs.inc", "response": "function xmlrpc_server($callbacks) {\n $xmlrpc_server = new stdClass();\n // Define built-in XML-RPC method names\n $defaults = array(\n 'system.multicall' => 'xmlrpc_server_multicall',\n array(\n 'system.methodSignature',\n 'xmlrpc_server_method_signature',\n array('array', 'string'),\n 'Returns an array describing the return type and required parameters of a method.',\n ),\n array(\n 'system.getCapabilities',\n 'xmlrpc_server_get_capabilities',\n array('struct'),\n 'Returns a struct describing the XML-RPC specifications supported by this server.',\n ),\n array(\n 'system.listMethods',\n 'xmlrpc_server_list_methods',\n array('array'),\n 'Returns an array of available methods on this server.',\n ),\n array(\n 'system.methodHelp',\n 'xmlrpc_server_method_help',\n array('string', 'string'),\n 'Returns a documentation string for the specified method.',\n ),\n );\n // We build an array of all method names by combining the built-ins\n // with those defined by modules implementing the _xmlrpc hook.\n // Built-in methods are overridable.\n $callbacks = array_merge($defaults, (array) $callbacks);\n drupal_alter('xmlrpc', $callbacks);\n foreach ($callbacks as $key => $callback) {\n // we could check for is_array($callback)\n if (is_int($key)) {\n $method = $callback[0];\n $xmlrpc_server->callbacks[$method] = $callback[1];\n $xmlrpc_server->signatures[$method] = $callback[2];\n $xmlrpc_server->help[$method] = $callback[3];\n }\n else {\n $xmlrpc_server->callbacks[$key] = $callback;\n $xmlrpc_server->signatures[$key] = '';\n $xmlrpc_server->help[$key] = '';\n }\n }\n\n $data = file_get_contents('php://input');\n if (!$data) {\n print 'XML-RPC server accepts POST requests only.';\n drupal_exit();\n }\n $xmlrpc_server->message = xmlrpc_message($data);\n if (!xmlrpc_message_parse($xmlrpc_server->message)) {\n xmlrpc_server_error(-32700, t('Parse error. Request not well formed.'));\n }\n if ($xmlrpc_server->message->messagetype != 'methodCall') {\n xmlrpc_server_error(-32600, t('Server error. Invalid XML-RPC. Request must be a methodCall.'));\n }\n if (!isset($xmlrpc_server->message->params)) {\n $xmlrpc_server->message->params = array();\n }\n xmlrpc_server_set($xmlrpc_server);\n $result = xmlrpc_server_call($xmlrpc_server, $xmlrpc_server->message->methodname, $xmlrpc_server->message->params);\n\n if (is_object($result) && !empty($result->is_error)) {\n xmlrpc_server_error($result);\n }\n // Encode the result\n $r = xmlrpc_value($result);\n // Create the XML\n $xml = '\n\n \n \n ' . xmlrpc_value_get_xml($r) . '\n \n \n\n\n';\n // Send it\n xmlrpc_server_output($xml);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0e53f750be", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_modules_installed/7.x", "instruction": "Give me the example code for `hook_modules_installed($modules)` in Drupal 7. Hook description: Perform necessary actions after modules are installed.", "context": "This function differs from hook_install() in that it gives all other modules a chance to perform actions when a module is installed, whereas hook_install() is only called on the module actually being installed. See module_enable() for a detailed description of the order in which install and enable hooks are invoked.\n\nThis hook should be implemented in a .module file, not in an .install file.\n\nParameters:\n- $modules: An array of the modules that were installed.\n\nFile: modules/system/system.api.php", "response": "function hook_modules_installed($modules) {\n if (in_array('lousy_module', $modules)) {\n variable_set('lousy_module_conflicting_variable', FALSE);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0e784f5690", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21unicode.inc/function/drupal_strlen/7.x", "instruction": "I need the code for `drupal_strlen($text)` in Drupal 7 (includes/unicode.inc). It must do this: Counts the number of characters in a UTF-8 string.", "context": "This is less than or equal to the byte count.\n\nParameters:\n- $text: The string to run the operation on.\n\nReturns (integer): The length of the string.\n\nFile: includes/unicode.inc", "response": "function drupal_strlen($text) {\n global $multibyte;\n if (is_null($text)) {\n return 0;\n }\n if ($multibyte == UNICODE_MULTIBYTE) {\n return mb_strlen($text);\n }\n else {\n // Do not count UTF-8 continuation bytes.\n return strlen(preg_replace(\"/[\\x80-\\xBF]/\", '', $text));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0e7b21be62", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_theme_registry_alter/7.x", "instruction": "Give me the example code for `hook_theme_registry_alter(&$theme_registry)` in Drupal 7. Hook description: Alter the theme registry information returned from hook_theme().", "context": "The theme registry stores information about all available theme hooks, including which callback functions those hooks will call when triggered, what template files are exposed by these hooks, and so on.\n\nNote that this hook is only executed as the theme cache is re-built. Changes here will not be visible until the next cache clear.\n\nThe $theme_registry array is keyed by theme hook name, and contains the information returned from hook_theme(), as well as additional properties added by _theme_process_registry().\n\nFor example:\n\nParameters:\n- $theme_registry: The entire cache of theme registry information, post-processing.\n\nFile: modules/system/system.api.php", "response": "function hook_theme_registry_alter(&$theme_registry) {\n // Kill the next/previous forum topic navigation links.\n foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) {\n if ($value == 'template_preprocess_forum_topic_navigation') {\n unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]);\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0e85f5fd93", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_select_nodes/7.x", "instruction": "I need the code for `taxonomy_select_nodes($tid, $pager = TRUE, $limit = FALSE, $order = array('t.sticky' => 'DESC', 't.created' => 'DESC'))` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Return nodes attached to a term across all field instances.", "context": "This function requires taxonomy module to be maintaining its own tables, and will return an empty array if it is not. If using other field storage methods alternatives methods for listing terms will need to be used.\n\nParameters:\n- $tid: The term ID.\n- $pager: Boolean to indicate whether a pager should be used.\n- $limit: Integer. The maximum number of nodes to find. Set to FALSE for no limit.\n- $order: An array of fields and directions.\n\nReturns: An array of nids matching the query.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_select_nodes($tid, $pager = TRUE, $limit = FALSE, $order = array('t.sticky' => 'DESC', 't.created' => 'DESC')) {\n if (!variable_get('taxonomy_maintain_index_table', TRUE)) {\n return array();\n }\n $query = db_select('taxonomy_index', 't');\n $query->addTag('node_access');\n $query->condition('t.tid', $tid);\n if ($pager) {\n $count_query = clone $query;\n $count_query->addExpression('COUNT(t.nid)');\n\n $query = $query->extend('PagerDefault');\n if ($limit !== FALSE) {\n $query = $query->limit($limit);\n }\n $query->setCountQuery($count_query);\n }\n else {\n if ($limit !== FALSE) {\n $query->range(0, $limit);\n }\n }\n $query->addField('t', 'nid');\n $query->addField('t', 'tid');\n foreach ($order as $field => $direction) {\n $query->orderBy($field, $direction);\n // ORDER BY fields need to be loaded too, assume they are in the form\n // table_alias.name\n list($table_alias, $name) = explode('.', $field);\n $query->addField($table_alias, $name);\n }\n return $query->execute()->fetchCol();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0e89bcdfaa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_initialize/7.x", "instruction": "In Drupal 7, write the function `lock_initialize()` (file includes/lock.inc) so that it does the following: Initialize the locking system.", "context": "File: includes/lock.inc", "response": "function lock_initialize() {\n global $locks;\n\n $locks = array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ea0940bf0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_field_language_fallback/7.x", "instruction": "Implement `locale_field_language_fallback(&$display_language, $entity, $langcode)` in PHP for Drupal 7. Required behavior: Applies language fallback rules to the fields attached to the given entity.", "context": "Core language fallback rules simply check if fields have a field translation for the requested language code. If so the requested language is returned, otherwise all the fallback candidates are inspected to see if there is a field translation available in another language. By default this is called by locale_field_language_alter(), but this behavior can be disabled by setting the 'locale_field_language_fallback' variable to FALSE.\n\nParameters:\n- $display_language: A reference to an array of language codes keyed by field name.\n- $entity: The entity to be displayed.\n- $langcode: The language code $entity has to be displayed in.\n\nFile: modules/locale/locale.module", "response": "function locale_field_language_fallback(&$display_language, $entity, $langcode) {\n // Lazily init fallback candidates to avoid unnecessary calls.\n $fallback_candidates = NULL;\n $field_languages = array();\n\n foreach ($display_language as $field_name => $field_language) {\n // If the requested language is defined for the current field use it,\n // otherwise search for a fallback value among the fallback candidates.\n if (isset($entity->{$field_name}[$langcode])) {\n $display_language[$field_name] = $langcode;\n }\n elseif (!empty($entity->{$field_name})) {\n if (!isset($fallback_candidates)) {\n require_once DRUPAL_ROOT . '/includes/language.inc';\n $fallback_candidates = language_fallback_get_candidates();\n }\n foreach ($fallback_candidates as $fallback_language) {\n if (isset($entity->{$field_name}[$fallback_language])) {\n $display_language[$field_name] = $fallback_language;\n break;\n }\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ea5c2be7f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_get_cookie_domain/7.x", "instruction": "Implement `_drupal_get_cookie_domain($host)` in PHP for Drupal 7. Required behavior: Derive the cookie domain to use for session cookies.", "context": "Parameters:\n- $host: The value of the HTTP host name.\n\nReturns: The string to use as a cookie domain.\n\nFile: includes/bootstrap.inc", "response": "function _drupal_get_cookie_domain($host) {\n $cookie_domain = $host;\n // Strip leading periods and port numbers from cookie domain.\n $cookie_domain = ltrim($cookie_domain, '.');\n $cookie_domain = explode(':', $cookie_domain);\n $cookie_domain = '.' . $cookie_domain[0];\n return $cookie_domain;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ea876c8bf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/_trigger_tab_information/7.x", "instruction": "I need the code for `_trigger_tab_information()` in Drupal 7 (modules/trigger/trigger.module). It must do this: Gathers information about tabs on the triggers administration screen.", "context": "Returns (Array): of modules that have triggers, with the keys being the machine-readable name of the module, and the values being the human-readable name of the module.\n\nFile: modules/trigger/trigger.module", "response": "function _trigger_tab_information() {\n // Gather information about all triggers and modules.\n $trigger_info = _trigger_get_all_info();\n $modules = system_get_info('module');\n $modules = array_intersect_key($modules, $trigger_info);\n\n $return_info = array();\n foreach ($modules as $name => $info) {\n $return_info[$name] = $info['name'];\n }\n\n return $return_info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0eaa88ca1c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_cron_queue_info/7.x", "instruction": "Implement `aggregator_cron_queue_info()` in PHP for Drupal 7. Required behavior: Implements hook_cron_queue_info().", "context": "File: modules/aggregator/aggregator.module", "response": "function aggregator_cron_queue_info() {\n $queues['aggregator_feeds'] = array(\n 'worker callback' => 'aggregator_refresh',\n 'time' => 60,\n );\n return $queues;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0eaf1bffa8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/openid_extract_namespace/7.x", "instruction": "I need the code for `openid_extract_namespace($response, $extension_namespace, $fallback_prefix = NULL, $only_signed = FALSE)` in Drupal 7 (modules/openid/openid.inc). It must do this: Extract all the parameters belonging to an extension in a response message.", "context": "OpenID 2.0 defines a simple extension mechanism, based on a namespace prefix.\n\nEach request or response can define a prefix using:\n\nParameters:\n- $response: The response array.\n- $extension_namespace: The namespace of the extension.\n- $fallback_prefix: An optional prefix that will be used in case no prefix is found for the target extension namespace.\n- $only_signed: Return only keys that are included in the message signature in openid.sig. Unsigned fields may have been modified or added by other parties than the OpenID Provider.\n\nReturns: An associative array containing all the parameters in the response message that belong to the extension. The keys are stripped from their namespace prefix.\n\nFile: modules/openid/openid.inc", "response": "function openid_extract_namespace($response, $extension_namespace, $fallback_prefix = NULL, $only_signed = FALSE) {\n $signed_keys = explode(',', $response['openid.signed']);\n\n // Find the namespace prefix.\n $prefix = $fallback_prefix;\n foreach ($response as $key => $value) {\n if ($value == $extension_namespace && preg_match('/^openid\\.ns\\.([^.]+)$/', $key, $matches)) {\n $prefix = $matches[1];\n if ($only_signed && !in_array('ns.' . $matches[1], $signed_keys)) {\n // The namespace was defined but was not signed as required. In this\n // case we do not fall back to $fallback_prefix.\n $prefix = NULL;\n }\n break;\n }\n }\n\n // Now extract the namespace keys from the response.\n $output = array();\n if (!isset($prefix)) {\n return $output;\n }\n foreach ($response as $key => $value) {\n if (preg_match('/^openid\\.' . $prefix . '\\.(.+)$/', $key, $matches)) {\n $local_key = $matches[1];\n if (!$only_signed || in_array($prefix . '.' . $local_key, $signed_keys)) {\n $output[$local_key] = $value;\n }\n }\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ed82f6e47", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_token_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_token_info_alter(&$data)` (modules/system/system.api.php): Alter the metadata about available placeholder tokens and token types.", "context": "Parameters:\n- $data: The associative array of token definitions from hook_token_info().\n\nFile: modules/system/system.api.php", "response": "function hook_token_info_alter(&$data) {\n // Modify description of node tokens for our site.\n $data['tokens']['node']['nid'] = array(\n 'name' => t(\"Node ID\"),\n 'description' => t(\"The unique ID of the article.\"),\n );\n $data['tokens']['node']['title'] = array(\n 'name' => t(\"Title\"),\n 'description' => t(\"The title of the article.\"),\n );\n\n // Chained tokens for nodes.\n $data['tokens']['node']['created'] = array(\n 'name' => t(\"Date created\"),\n 'description' => t(\"The date the article was posted.\"),\n 'type' => 'date',\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ee859b5c8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_themes_admin_form/7.x", "instruction": "Implement `system_themes_admin_form($form, &$form_state, $theme_options)` in PHP for Drupal 7. Required behavior: Form to select the administration theme.", "context": "File: modules/system/system.admin.inc", "response": "function system_themes_admin_form($form, &$form_state, $theme_options) {\n // Administration theme settings.\n $form['admin_theme'] = array(\n '#type' => 'fieldset',\n '#title' => t('Administration theme'),\n );\n $form['admin_theme']['admin_theme'] = array(\n '#type' => 'select',\n '#options' => array(0 => t('Default theme')) + $theme_options,\n '#title' => t('Administration theme'),\n '#description' => t('Choose \"Default theme\" to always use the same theme as the rest of the site.'),\n '#default_value' => variable_get('admin_theme', 0),\n );\n $form['admin_theme']['node_admin_theme'] = array(\n '#type' => 'checkbox',\n '#title' => t('Use the administration theme when editing or creating content'),\n '#default_value' => variable_get('node_admin_theme', '0'),\n );\n $form['admin_theme']['actions'] = array('#type' => 'actions');\n $form['admin_theme']['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save configuration'),\n );\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0eeea69b5c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.install/function/contact_update_7000/7.x", "instruction": "In Drupal 7, write the function `contact_update_7000()` (file modules/contact/contact.install) so that it does the following: Rename the threshold limit variable.", "context": "File: modules/contact/contact.install", "response": "function contact_update_7000() {\n variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));\n variable_del('contact_hourly_threshold');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ef17c29ef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_overview_page/7.x", "instruction": "I need the code for `menu_overview_page()` in Drupal 7 (modules/menu/menu.admin.inc). It must do this: Menu callback which shows an overview page of all the custom menus and their descriptions.", "context": "File: modules/menu/menu.admin.inc", "response": "function menu_overview_page() {\n $result = db_query(\"SELECT * FROM {menu_custom} ORDER BY title\", array(), array('fetch' => PDO::FETCH_ASSOC));\n $header = array(t('Title'), array('data' => t('Operations'), 'colspan' => '3'));\n $rows = array();\n foreach ($result as $menu) {\n $row = array(theme('menu_admin_overview', array('title' => $menu['title'], 'name' => $menu['menu_name'], 'description' => $menu['description'])));\n $row[] = array('data' => l(t('list links'), 'admin/structure/menu/manage/' . $menu['menu_name']));\n $row[] = array('data' => l(t('edit menu'), 'admin/structure/menu/manage/' . $menu['menu_name'] . '/edit'));\n $row[] = array('data' => l(t('add link'), 'admin/structure/menu/manage/' . $menu['menu_name'] . '/add'));\n $rows[] = $row;\n }\n\n return theme('table', array('header' => $header, 'rows' => $rows));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ef3cd28c9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_mail/7.x", "instruction": "I need the code for `update_mail($key, &$message, $params)` in Drupal 7 (modules/update/update.module). It must do this: Implements hook_mail().", "context": "Constructs the e-mail notification message when the site is out of date.\n\nParameters:\n- $key: Unique key to indicate what message to build, always 'status_notify'.\n- $message: Reference to the message array being built.\n- $params: Array of parameters to indicate what kind of text to include in the message body. This is a keyed array of message type ('core' or 'contrib') as the keys, and the status reason constant (UPDATE_NOT_SECURE, etc) for the values.\n\nFile: modules/update/update.module", "response": "function update_mail($key, &$message, $params) {\n $language = $message['language'];\n $langcode = $language->language;\n $message['subject'] .= t('New release(s) available for !site_name', array('!site_name' => variable_get('site_name', 'Drupal')), array('langcode' => $langcode));\n foreach ($params as $msg_type => $msg_reason) {\n $message['body'][] = _update_message_text($msg_type, $msg_reason, FALSE, $language);\n }\n $message['body'][] = t('See the available updates page for more information:', array(), array('langcode' => $langcode)) . \"\\n\" . url('admin/reports/updates', array('absolute' => TRUE, 'language' => $language));\n if (update_manager_access()) {\n $message['body'][] = t('You can automatically install your missing updates using the Update manager:', array(), array('langcode' => $langcode)) . \"\\n\" . url('admin/reports/updates/update', array('absolute' => TRUE, 'language' => $language));\n }\n $settings_url = url('admin/reports/updates/settings', array('absolute' => TRUE));\n if (variable_get('update_notification_threshold', 'all') == 'all') {\n $message['body'][] = t('Your site is currently configured to send these emails when any updates are available. To get notified only for security updates, !url.', array('!url' => $settings_url));\n }\n else {\n $message['body'][] = t('Your site is currently configured to send these emails only when security updates are available. To get notified for any available updates, !url.', array('!url' => $settings_url));\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0ef688d65a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_field_is_empty/7.x", "instruction": "In Drupal 7, write the function `list_field_is_empty($item, $field)` (file modules/field/modules/list/list.module) so that it does the following: Implements hook_field_is_empty().", "context": "File: modules/field/modules/list/list.module", "response": "function list_field_is_empty($item, $field) {\n if (empty($item['value']) && (string) $item['value'] !== '0') {\n return TRUE;\n }\n return FALSE;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0efa9298c3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_ensure_htaccess/7.x", "instruction": "Implement `file_ensure_htaccess()` in PHP for Drupal 7. Required behavior: Creates a .htaccess file in each Drupal files directory if it is missing.", "context": "File: includes/file.inc", "response": "function file_ensure_htaccess() {\n file_create_htaccess('public://', FALSE);\n if (variable_get('file_private_path', FALSE)) {\n file_create_htaccess('private://', TRUE);\n }\n file_create_htaccess('temporary://', TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0efadf6fc7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_format_form_submit/7.x", "instruction": "Implement `filter_admin_format_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for filter_admin_format_form().", "context": "File: modules/filter/filter.admin.inc", "response": "function filter_admin_format_form_submit($form, &$form_state) {\n // Remove unnecessary values.\n form_state_values_clean($form_state);\n\n // Add the submitted form values to the text format, and save it.\n $format = $form['#format'];\n foreach ($form_state['values'] as $key => $value) {\n $format->$key = $value;\n }\n $status = filter_format_save($format);\n\n // Save user permissions.\n if ($permission = filter_permission_name($format)) {\n foreach ($format->roles as $rid => $enabled) {\n user_role_change_permissions($rid, array($permission => $enabled));\n }\n }\n\n switch ($status) {\n case SAVED_NEW:\n drupal_set_message(t('Added text format %format.', array('%format' => $format->name)));\n break;\n\n case SAVED_UPDATED:\n drupal_set_message(t('The text format %format has been updated.', array('%format' => $format->name)));\n break;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f0ee11b76", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_link_access/7.x", "instruction": "I need the code for `shortcut_link_access($menu_link)` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Access callback for editing a link in a shortcut set.", "context": "File: modules/shortcut/shortcut.module", "response": "function shortcut_link_access($menu_link) {\n // The link must belong to a shortcut set that the current user has access\n // to edit.\n if ($shortcut_set = shortcut_set_load($menu_link['menu_name'])) {\n return shortcut_set_edit_access($shortcut_set);\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f19652f68", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_tablesort_indicator/7.x", "instruction": "Implement `theme_tablesort_indicator($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a sort icon.", "context": "Parameters:\n- $variables: An associative array containing: - style: Set to either 'asc' or 'desc', this determines which icon to show.\n\nFile: includes/theme.inc", "response": "function theme_tablesort_indicator($variables) {\n if ($variables['style'] == \"asc\") {\n return theme('image', array('path' => 'misc/arrow-asc.png', 'width' => 13, 'height' => 13, 'alt' => t('sort ascending'), 'title' => t('sort ascending')));\n }\n else {\n return theme('image', array('path' => 'misc/arrow-desc.png', 'width' => 13, 'height' => 13, 'alt' => t('sort descending'), 'title' => t('sort descending')));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f1ac72280", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/_drupal_mkdir_call/7.x", "instruction": "I need the code for `_drupal_mkdir_call($uri, $mode, $recursive, $context)` in Drupal 7 (includes/file.inc). It must do this: Helper function. Ensures we don't pass a NULL as a context resource to mkdir().", "context": "File: includes/file.inc", "response": "function _drupal_mkdir_call($uri, $mode, $recursive, $context) {\n if (is_null($context)) {\n return mkdir($uri, $mode, $recursive);\n }\n else {\n return mkdir($uri, $mode, $recursive, $context);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f2caf83e5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7057/7.x", "instruction": "In Drupal 7, write the function `system_update_7057()` (file modules/system/system.install) so that it does the following: Increase the size of session-ids.", "context": "File: modules/system/system.install", "response": "function system_update_7057() {\n $spec = array(\n 'description' => \"A session ID. The value is generated by PHP's Session API.\",\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n );\n db_change_field('sessions', 'sid', 'sid', $spec);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f37209f97", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_revision_revert_confirm/7.x", "instruction": "I need the code for `node_revision_revert_confirm($form, $form_state, $node_revision)` in Drupal 7 (modules/node/node.pages.inc). It must do this: Asks for confirmation of the reversion to prevent against CSRF attacks.", "context": "Parameters:\n- $node_revision (int): The node revision ID.\n\nReturns (array): An array as expected by drupal_render().\n\nFile: modules/node/node.pages.inc", "response": "function node_revision_revert_confirm($form, $form_state, $node_revision) {\n $form['#node_revision'] = $node_revision;\n return confirm_form($form, t('Are you sure you want to revert to the revision from %revision-date?', array('%revision-date' => format_date($node_revision->revision_timestamp))), 'node/' . $node_revision->nid . '/revisions', '', t('Revert'), t('Cancel'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f3acc69a3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_html_head/7.x", "instruction": "I need the code for `drupal_add_html_head($data = NULL, $key = NULL)` in Drupal 7 (includes/common.inc). It must do this: Adds output to the HEAD tag of the HTML page.", "context": "This function can be called as long as the headers aren't sent. Pass no arguments (or NULL for both) to retrieve the currently stored elements.\n\nParameters:\n- $data: A renderable array. If the '#type' key is not set then 'html_tag' will be added as the default '#type'.\n- $key: A unique string key to allow implementations of hook_html_head_alter() to identify the element in $data. Required if $data is not NULL.\n\nReturns: An array of all stored HEAD elements.\n\nFile: includes/common.inc", "response": "function drupal_add_html_head($data = NULL, $key = NULL) {\n $stored_head = &drupal_static(__FUNCTION__);\n\n if (!isset($stored_head)) {\n // Make sure the defaults, including Content-Type, come first.\n $stored_head = _drupal_default_html_head();\n }\n\n if (isset($data) && isset($key)) {\n if (!isset($data['#type'])) {\n $data['#type'] = 'html_tag';\n }\n $stored_head[$key] = $data;\n }\n return $stored_head;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f4e6b753c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21update.inc/function/update_finished/7.x", "instruction": "Implement `update_finished($success, $results, $operations)` in PHP for Drupal 7. Required behavior: Implements callback_batch_finished().", "context": "Finishes the update process and stores the results for eventual display.\n\nAfter the updates run, all caches are flushed. The update results are stored into the session (for example, to be displayed on the update results page in update.php). Additionally, if the site was off-line, now that the update process is completed, the site is set back online.\n\nParameters:\n- $success: Indicate that the batch API tasks were all completed successfully.\n- $results: An array of all the results that were updated in update_do_one().\n- $operations: A list of all the operations that had not been completed by the batch API.\n\nFile: includes/update.inc", "response": "function update_finished($success, $results, $operations) {\n // Remove the D6 upgrade flag variable so that subsequent update runs do not\n // get the wrong context.\n variable_del('update_d6');\n\n // Clear the caches in case the data has been updated.\n drupal_flush_all_caches();\n\n $_SESSION['update_results'] = $results;\n $_SESSION['update_success'] = $success;\n $_SESSION['updates_remaining'] = $operations;\n\n // Now that the update is done, we can put the site back online if it was\n // previously in maintenance mode.\n if (isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) {\n variable_set('maintenance_mode', FALSE);\n unset($_SESSION['maintenance_mode']);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f585e4a8b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_form_submit_build_comment/7.x", "instruction": "I need the code for `comment_form_submit_build_comment($form, &$form_state)` in Drupal 7 (modules/comment/comment.module). It must do this: Updates the form state's comment entity by processing this submission's values.", "context": "This is the default builder function for the comment form. It is called during the \"Save\" and \"Preview\" submit handlers to retrieve the entity to save or preview. This function can also be called by a \"Next\" button of a wizard to update the form state's entity with the current step's values before proceeding to the next step.\n\nFile: modules/comment/comment.module", "response": "function comment_form_submit_build_comment($form, &$form_state) {\n $comment = $form_state['comment'];\n entity_form_submit_build_entity('comment', $comment, $form, $form_state);\n comment_submit($comment);\n return $comment;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f7324b0e3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_filter_form/7.x", "instruction": "In Drupal 7, write the function `node_filter_form()` (file modules/node/node.admin.inc) so that it does the following: Returns the node administration filters form array to node_admin_content().", "context": "File: modules/node/node.admin.inc", "response": "function node_filter_form() {\n $session = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();\n $filters = node_filters();\n\n $i = 0;\n $form['filters'] = array(\n '#type' => 'fieldset',\n '#title' => t('Show only items where'),\n '#theme' => 'exposed_filters__node',\n );\n foreach ($session as $filter) {\n list($type, $value) = $filter;\n if ($type == 'language') {\n $value = $value == LANGUAGE_NONE ? t('Language neutral') : module_invoke('locale', 'language_name', $value);\n }\n else {\n $value = $filters[$type]['options'][$value];\n }\n $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);\n if ($i++) {\n $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));\n }\n else {\n $form['filters']['current'][] = array('#markup' => t('where %property is %value', $t_args));\n }\n if (in_array($type, array('type', 'language'))) {\n // Remove the option if it is already being filtered on.\n unset($filters[$type]);\n }\n }\n\n $form['filters']['status'] = array(\n '#type' => 'container',\n '#attributes' => array('class' => array('clearfix')),\n '#prefix' => ($i ? '
        ' . t('and where') . '
        ' : ''),\n );\n $form['filters']['status']['filters'] = array(\n '#type' => 'container',\n '#attributes' => array('class' => array('filters')),\n );\n foreach ($filters as $key => $filter) {\n $form['filters']['status']['filters'][$key] = array(\n '#type' => 'select',\n '#options' => $filter['options'],\n '#title' => $filter['title'],\n '#default_value' => '[any]',\n );\n }\n\n $form['filters']['status']['actions'] = array(\n '#type' => 'actions',\n '#attributes' => array('class' => array('container-inline')),\n );\n $form['filters']['status']['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => count($session) ? t('Refine') : t('Filter'),\n );\n if (count($session)) {\n $form['filters']['status']['actions']['undo'] = array('#type' => 'submit', '#value' => t('Undo'));\n $form['filters']['status']['actions']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));\n }\n\n drupal_add_js('misc/form.js');\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0f868f955c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_extra_fields/7.x", "instruction": "In Drupal 7, write the function `taxonomy_field_extra_fields()` (file modules/taxonomy/taxonomy.module) so that it does the following: Implements hook_field_extra_fields().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_field_extra_fields() {\n $return = array();\n $info = entity_get_info('taxonomy_term');\n foreach (array_keys($info['bundles']) as $bundle) {\n $return['taxonomy_term'][$bundle] = array(\n 'form' => array(\n 'name' => array(\n 'label' => t('Name'),\n 'description' => t('Term name textfield'),\n 'weight' => -5,\n ),\n 'description' => array(\n 'label' => t('Description'),\n 'description' => t('Term description textarea'),\n 'weight' => 0,\n ),\n ),\n 'display' => array(\n 'description' => array(\n 'label' => t('Description'),\n 'description' => t('Term description'),\n 'weight' => 0,\n ),\n ),\n );\n }\n\n return $return;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-0fa2a11c00", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_formatter_types/7.x", "instruction": "Implement `field_info_formatter_types($formatter_type = NULL)` in PHP for Drupal 7. Required behavior: Returns information about field formatters from hook_field_formatter_info().", "context": "Parameters:\n- $formatter_type: (optional) A formatter type name. If omitted, all formatter types will be returned.\n\nReturns: Either a single formatter type description, as provided by hook_field_formatter_info(), or an array of all existing formatter types, keyed by formatter type name.\n\nFile: modules/field/field.info.inc", "response": "function field_info_formatter_types($formatter_type = NULL) {\n $info = _field_info_collate_types();\n $formatter_types = $info['formatter types'];\n if ($formatter_type) {\n if (isset($formatter_types[$formatter_type])) {\n return $formatter_types[$formatter_type];\n }\n }\n else {\n return $formatter_types;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0fb3b51ade", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_extract_ids/7.x", "instruction": "In Drupal 7, write the function `entity_extract_ids($entity_type, $entity)` (file includes/common.inc) so that it does the following: Helper function to extract id, vid, and bundle name from an entity.", "context": "Parameters:\n- $entity_type: The entity type; e.g. 'node' or 'user'.\n- $entity: The entity from which to extract values.\n\nReturns: A numerically indexed array (not a hash table) containing these elements: - 0: Primary ID of the entity. - 1: Revision ID of the entity, or NULL if $entity_type is not versioned. - 2: Bundle name of the entity, or NULL if $entity_type has no bundles.\n\nFile: includes/common.inc", "response": "function entity_extract_ids($entity_type, $entity) {\n $info = entity_get_info($entity_type);\n\n // Objects being created might not have id/vid yet.\n if (!empty($info)) {\n $id = isset($entity->{$info['entity keys']['id']}) ? $entity->{$info['entity keys']['id']} : NULL;\n $vid = ($info['entity keys']['revision'] && isset($entity->{$info['entity keys']['revision']})) ? $entity->{$info['entity keys']['revision']} : NULL;\n }\n else {\n $id = NULL;\n $vid = NULL;\n }\n\n if (!empty($info['entity keys']['bundle'])) {\n // Explicitly fail for malformed entities missing the bundle property.\n if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {\n throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));\n }\n $bundle = $entity->{$info['entity keys']['bundle']};\n }\n else {\n // The entity type provides no bundle key: assume a single bundle, named\n // after the entity type.\n $bundle = $entity_type;\n }\n\n return array($id, $vid, $bundle);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0fca7e9725", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_begin_request/7.x", "instruction": "In Drupal 7, write the function `install_begin_request(&$install_state)` (file includes/install.core.inc) so that it does the following: Begins an installation request, modifying the installation state as needed.", "context": "This function performs commands that must run at the beginning of every page request. It throws an exception if the installation should not proceed.\n\nParameters:\n- $install_state: An array of information about the current installation state. This is modified with information gleaned from the beginning of the page request.\n\nFile: includes/install.core.inc", "response": "function install_begin_request(&$install_state) {\n // Add any installation parameters passed in via the URL.\n $install_state['parameters'] += $_GET;\n\n // Validate certain core settings that are used throughout the installation.\n if (!empty($install_state['parameters']['profile'])) {\n $install_state['parameters']['profile'] = preg_replace('/[^a-zA-Z_0-9]/', '', $install_state['parameters']['profile']);\n }\n if (!empty($install_state['parameters']['locale'])) {\n $install_state['parameters']['locale'] = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $install_state['parameters']['locale']);\n }\n\n // Allow command line scripts to override server variables used by Drupal.\n require_once DRUPAL_ROOT . '/includes/bootstrap.inc';\n if (!$install_state['interactive']) {\n drupal_override_server_variables($install_state['server']);\n }\n\n // The user agent header is used to pass a database prefix in the request when\n // running tests. However, for security reasons, it is imperative that no\n // installation be permitted using such a prefix.\n if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], \"simpletest\") !== FALSE) {\n header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');\n exit;\n }\n\n drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);\n\n // This must go after drupal_bootstrap(), which unsets globals!\n global $conf;\n\n require_once DRUPAL_ROOT . '/modules/system/system.install';\n require_once DRUPAL_ROOT . '/includes/common.inc';\n require_once DRUPAL_ROOT . '/includes/file.inc';\n require_once DRUPAL_ROOT . '/includes/install.inc';\n require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');\n\n // Load module basics (needed for hook invokes).\n include_once DRUPAL_ROOT . '/includes/module.inc';\n include_once DRUPAL_ROOT . '/includes/session.inc';\n\n // Set up $language, so t() caller functions will still work.\n drupal_language_initialize();\n\n include_once DRUPAL_ROOT . '/includes/entity.inc';\n require_once DRUPAL_ROOT . '/includes/ajax.inc';\n $module_list['system']['filename'] = 'modules/system/system.module';\n $module_list['user']['filename'] = 'modules/user/user.module';\n module_list(TRUE, FALSE, FALSE, $module_list);\n drupal_load('module', 'system');\n drupal_load('module', 'user');\n\n // Load the cache infrastructure using a \"fake\" cache implementation that\n // does not attempt to write to the database. We need this during the initial\n // part of the installer because the database is not available yet. We\n // continue to use it even when the database does become available, in order\n // to preserve consistency between interactive and command-line installations\n // (the latter complete in one page request and therefore are forced to\n // continue using the cache implementation they started with) and also\n // because any data put in the cache during the installer is inherently\n // suspect, due to the fact that Drupal is not fully set up yet.\n require_once DRUPAL_ROOT . '/includes/cache.inc';\n require_once DRUPAL_ROOT . '/includes/cache-install.inc';\n $conf['cache_default_class'] = 'DrupalFakeCache';\n\n // Prepare for themed output. We need to run this at the beginning of the\n // page request to avoid a different theme accidentally getting set. (We also\n // need to run it even in the case of command-line installations, to prevent\n // any code in the installer that happens to initialize the theme system from\n // accessing the database before it is set up yet.)\n drupal_maintenance_theme();\n\n // Check existing settings.php.\n $install_state['settings_verified'] = install_verify_settings();\n\n if ($install_state['settings_verified']) {\n // Initialize the database system. Note that the connection\n // won't be initialized until it is actually requested.\n require_once DRUPAL_ROOT . '/includes/database/database.inc';\n\n // Verify the last completed task in the database, if there is one.\n $task = install_verify_completed_task();\n }\n else {\n $task = NULL;\n\n // Do not install over a configured settings.php. Check the 'db_url'\n // variable in addition to 'databases', since previous versions of Drupal\n // used that (and we do not want to allow installations on an existing site\n // whose settings file has not yet been updated).\n if (!empty($GLOBALS['databases']) || !empty($GLOBALS['db_url'])) {\n throw new Exception(install_already_done_error());\n }\n }\n\n // Modify the installation state as appropriate.\n $install_state['completed_task'] = $task;\n $install_state['database_tables_exist'] = !empty($task);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0fdc77838a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_tips/7.x", "instruction": "I need the code for `_filter_tips($format_id, $long = FALSE)` in Drupal 7 (modules/filter/filter.module). It must do this: Retrieves the filter tips.", "context": "Parameters:\n- $format_id: The ID of the text format for which to retrieve tips, or -1 to return tips for all formats accessible to the current user.\n- $long: (optional) Boolean indicating whether the long form of tips should be returned. Defaults to FALSE.\n\nReturns: An associative array of filtering tips, keyed by filter name. Each filtering tip is an associative array with elements: - tip: Tip text. - id: Filter ID.\n\nFile: modules/filter/filter.module", "response": "function _filter_tips($format_id, $long = FALSE) {\n global $user;\n\n $formats = filter_formats($user);\n $filter_info = filter_get_filters();\n\n $tips = array();\n\n // If only listing one format, extract it from the $formats array.\n if ($format_id != -1) {\n $formats = array($formats[$format_id]);\n }\n\n foreach ($formats as $format) {\n $filters = filter_list_format($format->format);\n $tips[$format->name] = array();\n foreach ($filters as $name => $filter) {\n if ($filter->status && isset($filter_info[$name]['tips callback']) && function_exists($filter_info[$name]['tips callback'])) {\n $tip = $filter_info[$name]['tips callback']($filter, $format, $long);\n if (isset($tip)) {\n $tips[$format->name][$name] = array('tip' => $tip, 'id' => $name);\n }\n }\n }\n }\n\n return $tips;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0fdd6f2bac", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_wrap_mail/7.x", "instruction": "I need the code for `drupal_wrap_mail($text, $indent = '')` in Drupal 7 (includes/mail.inc). It must do this: Performs format=flowed soft wrapping for mail (RFC 3676).", "context": "We use delsp=yes wrapping, but only break non-spaced languages when absolutely necessary to avoid compatibility issues.\n\nWe deliberately use LF rather than CRLF, see drupal_mail().\n\nParameters:\n- $text (string): The plain text to process.\n- $indent (string): (optional) A string to indent the text with. Only '>' characters are repeated on subsequent wrapped lines. Others are replaced by spaces.\n\nReturns (string): The content of the email as a string with formatting applied.\n\nFile: includes/mail.inc", "response": "function drupal_wrap_mail($text, $indent = '') {\n // Convert CRLF into LF.\n $text = str_replace(\"\\r\", '', $text);\n // See if soft-wrapping is allowed.\n $clean_indent = _drupal_html_to_text_clean($indent);\n $soft = strpos($clean_indent, ' ') === FALSE;\n // Check if the string has line breaks.\n if (strpos($text, \"\\n\") !== FALSE) {\n // Remove trailing spaces to make existing breaks hard, but leave signature\n // marker untouched (RFC 3676, Section 4.3).\n $text = preg_replace('/(?(? $soft, 'length' => strlen($indent)));\n $text = implode(\"\\n\", $lines);\n }\n else {\n // Wrap this line.\n _drupal_wrap_mail_line($text, 0, array('soft' => $soft, 'length' => strlen($indent)));\n }\n // Empty lines with nothing but spaces.\n $text = preg_replace('/^ +\\n/m', \"\\n\", $text);\n // Space-stuff special lines.\n $text = preg_replace('/^(>| |From)/m', ' $1', $text);\n // Apply indentation. We only include non-'>' indentation on the first line.\n $text = $indent . substr(preg_replace('/^/m', $clean_indent, $text), strlen($indent));\n\n return $text;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-0fdf7d31a1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.api.php/function/hook_options_list/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_options_list($field, $instance, $entity_type, $entity)` (modules/field/modules/options/options.api.php): Returns the list of options to be displayed for a field.", "context": "Field types willing to enable one or several of the widgets defined in options.module (select, radios/checkboxes, on/off checkbox) need to implement this hook to specify the list of options to display in the widgets.\n\nParameters:\n- $field: The field definition.\n- $instance: (optional) The instance definition. The hook might be called without an $instance parameter in contexts where no specific instance can be targeted. It is recommended to only use instance level properties to filter out values from a list defined by field level properties.\n- $entity_type: The entity type the field is attached to.\n- $entity: The entity object the field is attached to, or NULL if no entity exists (e.g. in field settings page).\n\nReturns: The array of options for the field. Array keys are the values to be stored, and should be of the data type (string, number...) expected by the first 'column' for the field type. Array values are the labels to display within the widgets. The labels should NOT be sanitized, options.module takes care of sanitation according to the needs of each widget. The HTML tags defined in _field_filter_xss_allowed_tags() are allowed, other tags will be filtered.\n\nFile: modules/field/modules/options/options.api.php", "response": "function hook_options_list($field, $instance, $entity_type, $entity) {\n // Sample structure.\n $options = array(\n 0 => t('Zero'),\n 1 => t('One'),\n 2 => t('Two'),\n 3 => t('Three'),\n );\n\n // Sample structure with groups. Only one level of nesting is allowed. This\n // is only supported by the 'options_select' widget. Other widgets will\n // flatten the array.\n $options = array(\n t('First group') => array(\n 0 => t('Zero'),\n ),\n t('Second group') => array(\n 1 => t('One'),\n 2 => t('Two'),\n ),\n 3 => t('Three'),\n );\n\n // In actual implementations, the array of options will most probably depend\n // on properties of the field. Example from taxonomy.module:\n $options = array();\n foreach ($field['settings']['allowed_values'] as $tree) {\n $terms = taxonomy_get_tree($tree['vid'], $tree['parent']);\n if ($terms) {\n foreach ($terms as $term) {\n $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;\n }\n }\n }\n\n return $options;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-0fee0ac873", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_default_value/7.x", "instruction": "I need the code for `field_get_default_value($entity_type, $entity, $field, $instance, $langcode = NULL)` in Drupal 7 (modules/field/field.module). It must do this: Helper function to get the default value for a field on an entity.", "context": "Parameters:\n- $entity_type: The type of $entity; e.g., 'node' or 'user'.\n- $entity: The entity for the operation.\n- $field: The field structure.\n- $instance: The instance structure.\n- $langcode: The field language to fill-in with the default value.\n\nFile: modules/field/field.module", "response": "function field_get_default_value($entity_type, $entity, $field, $instance, $langcode = NULL) {\n $items = array();\n if (!empty($instance['default_value_function'])) {\n $function = $instance['default_value_function'];\n if (function_exists($function)) {\n $items = $function($entity_type, $entity, $field, $instance, $langcode);\n }\n }\n elseif (!empty($instance['default_value'])) {\n $items = $instance['default_value'];\n }\n return $items;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-10103df661", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_permission_get_modules/7.x", "instruction": "I need the code for `user_permission_get_modules()` in Drupal 7 (modules/user/user.module). It must do this: Determine the modules that permissions belong to.", "context": "Returns: An associative array in the format $permission => $module.\n\nFile: modules/user/user.module", "response": "function user_permission_get_modules() {\n $permissions = array();\n foreach (module_implements('permission') as $module) {\n $perms = module_invoke($module, 'permission');\n foreach ($perms as $key => $value) {\n $permissions[$key] = $module;\n }\n }\n return $permissions;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1022b39a8d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/function/callback_filter_tips/7.x", "instruction": "In Drupal 7, show an example implementation for `callback_filter_tips($filter, $format, $long)` (modules/filter/filter.api.php): Return help text for a filter.", "context": "Callback for hook_filter_info().\n\nA filter's tips should be informative and to the point. Short tips are preferably one-liners.\n\nParameters:\n- $filter: An object representing the filter.\n- $format: An object representing the text format the filter is contained in.\n- $long: Whether this callback should return a short tip to display in a form (FALSE), or whether a more elaborate filter tips should be returned for theme_filter_tips() (TRUE).\n\nReturns: Translated text to display as a tip.\n\nFile: modules/filter/filter.api.php", "response": "function callback_filter_tips($filter, $format, $long) {\n if ($long) {\n return t('Lines and paragraphs are automatically recognized. The <br /> line break, <p> paragraph and </p> close paragraph tags are inserted automatically. If paragraphs are not recognized simply add a couple blank lines.');\n }\n else {\n return t('Lines and paragraphs break automatically.');\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1052739fbd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_image_style_save/7.x", "instruction": "In Drupal 7, write the function `user_image_style_save($style)` (file modules/user/user.module) so that it does the following: Implements hook_image_style_save().", "context": "File: modules/user/user.module", "response": "function user_image_style_save($style) {\n // If a style is renamed, update the variables that use it.\n if (isset($style['old_name']) && $style['old_name'] == variable_get('user_picture_style', '')) {\n variable_set('user_picture_style', $style['name']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1070f29cac", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/simpletest_result_form/7.x", "instruction": "In Drupal 7, write the function `simpletest_result_form($form, &$form_state, $test_id)` (file modules/simpletest/simpletest.pages.inc) so that it does the following: Test results form for $test_id.", "context": "File: modules/simpletest/simpletest.pages.inc", "response": "function simpletest_result_form($form, &$form_state, $test_id) {\n // Make sure there are test results to display and a re-run is not being performed.\n $results = array();\n if (is_numeric($test_id) && !$results = simpletest_result_get($test_id)) {\n drupal_set_message(t('No test results to display.'), 'error');\n drupal_goto('admin/config/development/testing');\n return $form;\n }\n\n // Load all classes and include CSS.\n drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css');\n\n // Keep track of which test cases passed or failed.\n $filter = array(\n 'pass' => array(),\n 'fail' => array(),\n );\n\n // Summary result fieldset.\n $form['result'] = array(\n '#type' => 'fieldset',\n '#title' => t('Results'),\n );\n $form['result']['summary'] = $summary = array(\n '#theme' => 'simpletest_result_summary',\n '#pass' => 0,\n '#fail' => 0,\n '#exception' => 0,\n '#debug' => 0,\n );\n\n simpletest_classloader_register();\n\n // Cycle through each test group.\n $header = array(t('Message'), t('Group'), t('Filename'), t('Line'), t('Function'), array('colspan' => 2, 'data' => t('Status')));\n $form['result']['results'] = array();\n foreach ($results as $group => $assertions) {\n // Create group fieldset with summary information.\n $info = call_user_func(array($group, 'getInfo'));\n $form['result']['results'][$group] = array(\n '#type' => 'fieldset',\n '#title' => $info['name'],\n '#description' => $info['description'],\n '#collapsible' => TRUE,\n );\n $form['result']['results'][$group]['summary'] = $summary;\n $group_summary = &$form['result']['results'][$group]['summary'];\n\n // Create table of assertions for the group.\n $rows = array();\n foreach ($assertions as $assertion) {\n $row = array();\n $row[] = $assertion->message;\n $row[] = $assertion->message_group;\n $row[] = drupal_basename($assertion->file);\n $row[] = $assertion->line;\n $row[] = $assertion->function;\n $row[] = simpletest_result_status_image($assertion->status);\n\n $class = 'simpletest-' . $assertion->status;\n if ($assertion->message_group == 'Debug') {\n $class = 'simpletest-debug';\n }\n $rows[] = array('data' => $row, 'class' => array($class));\n\n $group_summary['#' . $assertion->status]++;\n $form['result']['summary']['#' . $assertion->status]++;\n }\n $form['result']['results'][$group]['table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n );\n\n // Set summary information.\n $group_summary['#ok'] = $group_summary['#fail'] + $group_summary['#exception'] == 0;\n $form['result']['results'][$group]['#collapsed'] = $group_summary['#ok'];\n\n // Store test group (class) as for use in filter.\n $filter[$group_summary['#ok'] ? 'pass' : 'fail'][] = $group;\n }\n\n // Overal summary status.\n $form['result']['summary']['#ok'] = $form['result']['summary']['#fail'] + $form['result']['summary']['#exception'] == 0;\n\n // Actions.\n $form['#action'] = url('admin/config/development/testing/results/re-run');\n $form['action'] = array(\n '#type' => 'fieldset',\n '#title' => t('Actions'),\n '#attributes' => array('class' => array('container-inline')),\n '#weight' => -11,\n );\n\n $form['action']['filter'] = array(\n '#type' => 'select',\n '#title' => 'Filter',\n '#options' => array(\n 'all' => t('All (@count)', array('@count' => count($filter['pass']) + count($filter['fail']))),\n 'pass' => t('Pass (@count)', array('@count' => count($filter['pass']))),\n 'fail' => t('Fail (@count)', array('@count' => count($filter['fail']))),\n ),\n );\n $form['action']['filter']['#default_value'] = ($filter['fail'] ? 'fail' : 'all');\n\n // Categorized test classes for to be used with selected filter value.\n $form['action']['filter_pass'] = array(\n '#type' => 'hidden',\n '#default_value' => implode(',', $filter['pass']),\n );\n $form['action']['filter_fail'] = array(\n '#type' => 'hidden',\n '#default_value' => implode(',', $filter['fail']),\n );\n\n $form['action']['op'] = array(\n '#type' => 'submit',\n '#value' => t('Run tests'),\n );\n\n $form['action']['return'] = array(\n '#type' => 'link',\n '#title' => t('Return to list'),\n '#href' => 'admin/config/development/testing',\n );\n\n if (is_numeric($test_id)) {\n simpletest_clean_results_table($test_id);\n }\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-10a002a840", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_field_display_node_alter/7.x", "instruction": "Implement `node_field_display_node_alter(&$display, $context)` in PHP for Drupal 7. Required behavior: Implements hook_field_display_ENTITY_TYPE_alter().", "context": "File: modules/node/node.module", "response": "function node_field_display_node_alter(&$display, $context) {\n // Hide field labels in search index.\n if ($context['view_mode'] == 'search_index') {\n $display['label'] = 'hidden';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-10a83b7d12", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_display_overview_form_submit/7.x", "instruction": "In Drupal 7, write the function `field_ui_display_overview_form_submit($form, &$form_state)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Form submission handler for field_ui_display_overview_form().", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_display_overview_form_submit($form, &$form_state) {\n $form_values = $form_state['values'];\n $entity_type = $form['#entity_type'];\n $bundle = $form['#bundle'];\n $view_mode = $form['#view_mode'];\n\n // Save data for 'regular' fields.\n foreach ($form['#fields'] as $field_name) {\n // Retrieve the stored instance settings to merge with the incoming values.\n $instance = field_read_instance($entity_type, $field_name, $bundle);\n $values = $form_values['fields'][$field_name];\n // Get formatter settings. They lie either directly in submitted form\n // values (if the whole form was submitted while some formatter\n // settings were being edited), or have been persisted in\n // $form_state.\n $settings = array();\n if (isset($values['settings_edit_form']['settings'])) {\n $settings = $values['settings_edit_form']['settings'];\n }\n elseif (isset($form_state['formatter_settings'][$field_name])) {\n $settings = $form_state['formatter_settings'][$field_name];\n }\n elseif (isset($instance['display'][$view_mode]['settings'])) {\n $settings = $instance['display'][$view_mode]['settings'];\n }\n\n // Only save settings actually used by the selected formatter.\n $default_settings = field_info_formatter_settings($values['type']);\n $settings = array_intersect_key($settings, $default_settings);\n\n $instance['display'][$view_mode] = array(\n 'label' => $values['label'],\n 'type' => $values['type'],\n 'weight' => $values['weight'],\n 'settings' => $settings,\n );\n field_update_instance($instance);\n }\n\n // Get current bundle settings.\n $bundle_settings = field_bundle_settings($entity_type, $bundle);\n\n // Save data for 'extra' fields.\n foreach ($form['#extra'] as $name) {\n $bundle_settings['extra_fields']['display'][$name][$view_mode] = array(\n 'weight' => $form_values['fields'][$name]['weight'],\n 'visible' => $form_values['fields'][$name]['type'] == 'visible',\n );\n }\n\n // Save view modes data.\n if ($view_mode == 'default') {\n $entity_info = entity_get_info($entity_type);\n foreach ($form_values['view_modes_custom'] as $view_mode_name => $value) {\n // Display a message for each view mode newly configured to use custom\n // settings.\n $view_mode_settings = field_view_mode_settings($entity_type, $bundle);\n if (!empty($value) && empty($view_mode_settings[$view_mode_name]['custom_settings'])) {\n $view_mode_label = $entity_info['view modes'][$view_mode_name]['label'];\n $path = _field_ui_bundle_admin_path($entity_type, $bundle) . \"/display/$view_mode_name\";\n drupal_set_message(t('The %view_mode mode now uses custom display settings. You might want to configure them.', array('%view_mode' => $view_mode_label, '@url' => url($path))));\n // Initialize the newly customized view mode with the display settings\n // from the default view mode.\n _field_ui_add_default_view_mode_settings($entity_type, $bundle, $view_mode_name, $bundle_settings);\n }\n $bundle_settings['view_modes'][$view_mode_name]['custom_settings'] = !empty($value);\n }\n }\n\n // Save updated bundle settings.\n field_bundle_settings($entity_type, $bundle, $bundle_settings);\n\n drupal_set_message(t('Your settings have been saved.'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-10cbac5acc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_load/7.x", "instruction": "I need the code for `field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $options = array())` in Drupal 7 (modules/field/field.attach.inc). It must do this: Loads fields for the current revisions of a group of entities.", "context": "Loads all fields for each entity object in a group of a single entity type. The loaded field values are added directly to the entity objects.\n\nfield_attach_load() is automatically called by the default entity controller class, and thus, in most cases, doesn't need to be explicitly called by the entity type module.\n\nParameters:\n- $entity_type: The type of $entity; e.g., 'node' or 'user'.\n- $entities: An array of entities for which to load fields, keyed by entity ID. Each entity needs to have its 'bundle', 'id' and (if applicable) 'revision' keys filled in. The function adds the loaded field data directly in the entity objects of the $entities array.\n- $age: FIELD_LOAD_CURRENT to load the most recent revision for all fields, or FIELD_LOAD_REVISION to load the version indicated by each entity. Defaults to FIELD_LOAD_CURRENT; use field_attach_load_revision() instead of passing FIELD_LOAD_REVISION.\n- $options: An associative array of additional options, with the following keys: - 'field_id': The field ID that should be loaded, instead of loading all fields, for each entity. Note that returned entities may contain data for other fields, for example if they are read from a cache. - 'deleted': If TRUE, the function will operate on deleted fields as well as non-deleted fields. If unset or FALSE, only non-deleted fields are operated on.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $options = array()) {\n $load_current = $age == FIELD_LOAD_CURRENT;\n\n // Merge default options.\n $default_options = array(\n 'deleted' => FALSE,\n );\n $options += $default_options;\n\n $info = entity_get_info($entity_type);\n // Only the most current revision of non-deleted fields for cacheable entity\n // types can be cached.\n $cache_read = $load_current && $info['field cache'] && empty($options['deleted']);\n // In addition, do not write to the cache when loading a single field.\n $cache_write = $cache_read && !isset($options['field_id']);\n\n if (empty($entities)) {\n return;\n }\n\n // Assume all entities will need to be queried. Entities found in the cache\n // will be removed from the list.\n $queried_entities = $entities;\n\n // Fetch available entities from cache, if applicable.\n if ($cache_read) {\n // Build the list of cache entries to retrieve.\n $cids = array();\n foreach ($entities as $id => $entity) {\n $cids[] = \"field:$entity_type:$id\";\n }\n $cache = cache_get_multiple($cids, 'cache_field');\n // Put the cached field values back into the entities and remove them from\n // the list of entities to query.\n foreach ($entities as $id => $entity) {\n $cid = \"field:$entity_type:$id\";\n if (isset($cache[$cid])) {\n unset($queried_entities[$id]);\n foreach ($cache[$cid]->data as $field_name => $values) {\n $entity->$field_name = $values;\n }\n }\n }\n }\n\n // Fetch other entities from their storage location.\n if ($queried_entities) {\n // The invoke order is:\n // - hook_field_storage_pre_load()\n // - storage backend's hook_field_storage_load()\n // - field-type module's hook_field_load()\n // - hook_field_attach_load()\n\n // Invoke hook_field_storage_pre_load(): let any module load field\n // data before the storage engine, accumulating along the way.\n $skip_fields = array();\n foreach (module_implements('field_storage_pre_load') as $module) {\n $function = $module . '_field_storage_pre_load';\n $function($entity_type, $queried_entities, $age, $skip_fields, $options);\n }\n\n $instances = array();\n\n // Collect the storage backends used by the remaining fields in the entities.\n $storages = array();\n foreach ($queried_entities as $entity) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n $instances = _field_invoke_get_instances($entity_type, $bundle, $options);\n\n foreach ($instances as $instance) {\n $field_name = $instance['field_name'];\n $field_id = $instance['field_id'];\n // Make sure all fields are present at least as empty arrays.\n if (!isset($queried_entities[$id]->{$field_name})) {\n $queried_entities[$id]->{$field_name} = array();\n }\n // Collect the storage backend if the field has not been loaded yet.\n if (!isset($skip_fields[$field_id])) {\n $field = field_info_field_by_id($field_id);\n $storages[$field['storage']['type']][$field_id][] = $load_current ? $id : $vid;\n }\n }\n }\n\n // Invoke hook_field_storage_load() on the relevant storage backends.\n foreach ($storages as $storage => $fields) {\n $storage_info = field_info_storage_types($storage);\n module_invoke($storage_info['module'], 'field_storage_load', $entity_type, $queried_entities, $age, $fields, $options);\n }\n\n // Invoke field-type module's hook_field_load().\n $null = NULL;\n _field_invoke_multiple('load', $entity_type, $queried_entities, $age, $null, $options);\n\n // Invoke hook_field_attach_load(): let other modules act on loading the\n // entity.\n module_invoke_all('field_attach_load', $entity_type, $queried_entities, $age, $options);\n\n // Build cache data.\n if ($cache_write) {\n foreach ($queried_entities as $id => $entity) {\n $data = array();\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n $instances = field_info_instances($entity_type, $bundle);\n foreach ($instances as $instance) {\n $data[$instance['field_name']] = $queried_entities[$id]->{$instance['field_name']};\n }\n $cid = \"field:$entity_type:$id\";\n cache_set($cid, $data, 'cache_field');\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-10da9b175e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate_is_image/7.x", "instruction": "I need the code for `file_validate_is_image(stdClass $file)` in Drupal 7 (includes/file.inc). It must do this: Checks that the file is recognized by image_get_info() as an image.", "context": "Parameters:\n- $file: A Drupal file object.\n\nReturns: An array. If the file is not an image, it will contain an error message.\n\nFile: includes/file.inc", "response": "function file_validate_is_image(stdClass $file) {\n $errors = array();\n\n $info = image_get_info($file->uri);\n if (!$info || empty($info['extension'])) {\n $errors[] = t('The image file is invalid or the image type is not allowed. Allowed types: %allowed_types', array('%allowed_types' => t('Only JPEG, PNG and GIF images are allowed.')));\n }\n\n return $errors;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-10f1179b89", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/_install_module_batch/7.x", "instruction": "I need the code for `_install_module_batch($module, $module_name, &$context)` in Drupal 7 (includes/install.core.inc). It must do this: Implements callback_batch_operation().", "context": "Performs batch installation of modules.\n\nFile: includes/install.core.inc", "response": "function _install_module_batch($module, $module_name, &$context) {\n // Install and enable the module right away, so that the module will be\n // loaded by drupal_bootstrap in subsequent batch requests, and other\n // modules possibly depending on it can safely perform their installation\n // steps.\n module_enable(array($module), FALSE);\n $context['results'][] = $module;\n $context['message'] = st('Installed %module module.', array('%module' => $module_name));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-10fd4c04ec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_insert/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_node_insert($node)` (modules/node/node.api.php): Respond to creation of a new node.", "context": "This hook is invoked from node_save() after the database query that will insert the node into the node table is scheduled for execution, after the type-specific hook_insert() is invoked, and after field_attach_insert() is called.\n\nNote that when this hook is invoked, the changes have not yet been written to the database, because a database transaction is still in progress. The transaction is not finalized until the save operation is entirely completed and node_save() goes out of scope. You should not rely on data in the database at this time as it is not updated yet. You should also note that any write/update database queries executed from this hook are also not committed immediately. Check node_save() and db_transaction() for more info.\n\nParameters:\n- $node: The node that is being created.\n\nFile: modules/node/node.api.php", "response": "function hook_node_insert($node) {\n db_insert('mytable')\n ->fields(array(\n 'nid' => $node->nid,\n 'extra' => $node->extra,\n ))\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-110d0618c7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_theme/7.x", "instruction": "In Drupal 7, write the function `trigger_theme()` (file modules/trigger/trigger.module) so that it does the following: Implements hook_theme().", "context": "File: modules/trigger/trigger.module", "response": "function trigger_theme() {\n return array(\n 'trigger_display' => array(\n 'render element' => 'element',\n 'file' => 'trigger.admin.inc',\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-111d0b6887", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_default_form_errors/7.x", "instruction": "I need the code for `field_default_form_errors($entity_type, $entity, $field, $instance, $langcode, $items, $form, &$form_state)` in Drupal 7 (modules/field/field.form.inc). It must do this: Transfer field-level validation errors to widgets.", "context": "File: modules/field/field.form.inc", "response": "function field_default_form_errors($entity_type, $entity, $field, $instance, $langcode, $items, $form, &$form_state) {\n $field_state = field_form_get_state($form['#parents'], $field['field_name'], $langcode, $form_state);\n\n if (!empty($field_state['errors'])) {\n // Locate the correct element in the form.\n $element = drupal_array_get_nested_value($form_state['complete form'], $field_state['array_parents']);\n // Only set errors if the element is accessible.\n if (!isset($element['#access']) || $element['#access']) {\n $function = $instance['widget']['module'] . '_field_widget_error';\n $function_exists = function_exists($function);\n\n $multiple_widget = field_behaviors_widget('multiple values', $instance) != FIELD_BEHAVIOR_DEFAULT;\n foreach ($field_state['errors'] as $delta => $delta_errors) {\n // For multiple single-value widgets, pass errors by delta.\n // For a multiple-value widget, pass all errors to the main widget.\n $error_element = $multiple_widget ? $element : $element[$delta];\n foreach ($delta_errors as $error) {\n if ($function_exists) {\n $function($error_element, $error, $form, $form_state);\n }\n else {\n // Make sure that errors are reported (even incorrectly flagged) if\n // the widget module fails to implement hook_field_widget_error().\n form_error($error_element, $error['message']);\n }\n }\n }\n // Reinitialize the errors list for the next submit.\n $field_state['errors'] = array();\n field_form_set_state($form['#parents'], $field['field_name'], $langcode, $form_state, $field_state);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1122125179", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.install/function/filter_update_7001/7.x", "instruction": "In Drupal 7, write the function `filter_update_7001()` (file modules/filter/filter.install) so that it does the following: Break out \"escape HTML filter\" option to its own filter.", "context": "File: modules/filter/filter.install", "response": "function filter_update_7001() {\n $result = db_query(\"SELECT format FROM {filter_format}\")->fetchCol();\n $insert = db_insert('filters')->fields(array('format', 'module', 'delta', 'weight'));\n\n foreach ($result as $format_id) {\n // Deprecated constants FILTER_HTML_STRIP = 1 and FILTER_HTML_ESCAPE = 2.\n if (variable_get('filter_html_' . $format_id, 1) == 2) {\n $insert->values(array(\n 'format' => $format_id,\n 'module' => 'filter',\n 'delta' => 4,\n 'weight' => 0,\n ));\n }\n variable_del('filter_html_' . $format_id);\n }\n\n $insert->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-11386ab91a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_theme/7.x", "instruction": "In Drupal 7, write the function `poll_theme()` (file modules/poll/poll.module) so that it does the following: Implements hook_theme().", "context": "File: modules/poll/poll.module", "response": "function poll_theme() {\n $theme_hooks = array(\n 'poll_vote' => array(\n 'template' => 'poll-vote',\n 'render element' => 'form',\n ),\n 'poll_choices' => array(\n 'render element' => 'form',\n ),\n 'poll_results' => array(\n 'template' => 'poll-results',\n 'variables' => array('raw_title' => NULL, 'results' => NULL, 'votes' => NULL, 'raw_links' => NULL, 'block' => NULL, 'nid' => NULL, 'vote' => NULL),\n ),\n 'poll_bar' => array(\n 'template' => 'poll-bar',\n 'variables' => array('title' => NULL, 'votes' => NULL, 'total_votes' => NULL, 'vote' => NULL, 'block' => NULL),\n ),\n );\n // The theme system automatically discovers the theme's functions and\n // templates that implement more targeted \"suggestions\" of generic theme\n // hooks. But suggestions implemented by a module must be explicitly\n // registered.\n $theme_hooks += array(\n 'poll_results__block' => array(\n 'template' => 'poll-results--block',\n 'variables' => $theme_hooks['poll_results']['variables'],\n ),\n 'poll_bar__block' => array(\n 'template' => 'poll-bar--block',\n 'variables' => $theme_hooks['poll_bar']['variables'],\n ),\n );\n return $theme_hooks;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-115c617cfc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_admin_index/7.x", "instruction": "Implement `system_admin_index()` in PHP for Drupal 7. Required behavior: Menu callback; prints a listing of admin tasks, organized by module.", "context": "File: modules/system/system.admin.inc", "response": "function system_admin_index() {\n $module_info = system_get_info('module');\n foreach ($module_info as $module => $info) {\n $module_info[$module] = new stdClass();\n $module_info[$module]->info = $info;\n }\n uasort($module_info, 'system_sort_modules_by_info_name');\n $menu_items = array();\n\n foreach ($module_info as $module => $info) {\n // Only display a section if there are any available tasks.\n if ($admin_tasks = system_get_module_admin_tasks($module, $info->info)) {\n // Sort links by title.\n uasort($admin_tasks, 'drupal_sort_title');\n // Move 'Configure permissions' links to the bottom of each section.\n $permission_key = \"admin/people/permissions#module-$module\";\n if (isset($admin_tasks[$permission_key])) {\n $permission_task = $admin_tasks[$permission_key];\n unset($admin_tasks[$permission_key]);\n $admin_tasks[$permission_key] = $permission_task;\n }\n\n $menu_items[$info->info['name']] = array($info->info['description'], $admin_tasks);\n }\n }\n return theme('system_admin_index', array('menu_items' => $menu_items));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1171dde0e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_permission/7.x", "instruction": "Implement `poll_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/poll/poll.module", "response": "function poll_permission() {\n $perms = array(\n 'vote on polls' => array(\n 'title' => t('Vote on polls'),\n ),\n 'cancel own vote' => array(\n 'title' => t('Cancel and change own votes'),\n ),\n 'inspect all votes' => array(\n 'title' => t('View details for all votes'),\n ),\n );\n\n return $perms;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-117541de64", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_save/7.x", "instruction": "In Drupal 7, write the function `shortcut_set_save(&$shortcut_set)` (file modules/shortcut/shortcut.module) so that it does the following: Saves a shortcut set.", "context": "Parameters:\n- $shortcut_set: An object containing the following properties: - 'title': The title of the shortcut set. - 'set_name': (optional) The internal name of the shortcut set. If omitted, a new shortcut set will be created, and the 'set_name' property will be added to the passed-in object. - 'links': (optional) An array of menu links to save for the shortcut set. Each link is an array containing at least the following keys (which will be expanded to fill in other default values after the shortcut set is saved): - 'link_path': The Drupal path or external path that the link points to. - 'link_title': The title of the link. Any other keys accepted by menu_link_save() may also be provided.\n\nReturns: A constant which is either SAVED_NEW or SAVED_UPDATED depending on whether a new set was created or an existing one was updated.\n\nFile: modules/shortcut/shortcut.module", "response": "function shortcut_set_save(&$shortcut_set) {\n // First save the shortcut set itself.\n if (isset($shortcut_set->set_name)) {\n $return = drupal_write_record('shortcut_set', $shortcut_set, 'set_name');\n }\n else {\n $shortcut_set->set_name = shortcut_set_get_unique_name();\n $return = drupal_write_record('shortcut_set', $shortcut_set);\n }\n // If links were provided for the set, save them.\n if (isset($shortcut_set->links)) {\n foreach ($shortcut_set->links as &$link) {\n // Do not specifically associate these links with the shortcut module,\n // since other modules may make them editable via the menu system.\n // However, we do need to specify the correct menu name.\n $link['menu_name'] = $shortcut_set->set_name;\n $link['plid'] = 0;\n menu_link_save($link);\n }\n // Make sure that we have a return value, since if the links were updated\n // but the shortcut set was not, the call to drupal_write_record() above\n // would not return an indication that anything had changed.\n if (empty($return)) {\n $return = SAVED_UPDATED;\n }\n }\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-11844c1239", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_load/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age)` (modules/field/field.api.php): Define custom load behavior for this module's field types.", "context": "Unlike most other field hooks, this hook operates on multiple entities. The $entities, $instances and $items parameters are arrays keyed by entity ID. For performance reasons, information for all available entity should be loaded in a single query where possible.\n\nNote that the changes made to the field values get cached by the field cache for subsequent loads. You should never use this hook to load fieldable entities, since this is likely to cause infinite recursions when hook_field_load() is run on those as well. Use hook_field_formatter_prepare_view() instead.\n\nMake changes or additions to field values by altering the $items parameter by reference. There is no return value.\n\nParameters:\n- $entity_type: The type of $entity.\n- $entities: Array of entities being loaded, keyed by entity ID.\n- $field: The field structure for the operation.\n- $instances: Array of instance structures for $field for each entity, keyed by entity ID.\n- $langcode: The language code associated with $items.\n- $items: Array of field values already loaded for the entities, keyed by entity ID. Store your changes in this parameter (passed by reference).\n- $age: FIELD_LOAD_CURRENT to load the most recent revision for all fields, or FIELD_LOAD_REVISION to load the version indicated by each entity.\n\nFile: modules/field/field.api.php", "response": "function hook_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {\n // Sample code from text.module: precompute sanitized strings so they are\n // stored in the field cache.\n foreach ($entities as $id => $entity) {\n foreach ($items[$id] as $delta => $item) {\n // Only process items with a cacheable format, the rest will be handled\n // by formatters if needed.\n if (empty($instances[$id]['settings']['text_processing']) || filter_format_allowcache($item['format'])) {\n $items[$id][$delta]['safe_value'] = isset($item['value']) ? _text_sanitize($instances[$id], $langcode, $item, 'value') : '';\n if ($field['type'] == 'text_with_summary') {\n $items[$id][$delta]['safe_summary'] = isset($item['summary']) ? _text_sanitize($instances[$id], $langcode, $item, 'summary') : '';\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-11949cf866", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_node_save/7.x", "instruction": "I need the code for `menu_node_save($node)` in Drupal 7 (modules/menu/menu.module). It must do this: Helper for hook_node_insert() and hook_node_update().", "context": "File: modules/menu/menu.module", "response": "function menu_node_save($node) {\n if (isset($node->menu)) {\n $link = &$node->menu;\n if (empty($link['enabled'])) {\n if (!empty($link['mlid'])) {\n menu_link_delete($link['mlid']);\n }\n }\n elseif (trim($link['link_title'])) {\n $link['link_title'] = trim($link['link_title']);\n $link['link_path'] = \"node/$node->nid\";\n if (trim($link['description'])) {\n $link['options']['attributes']['title'] = trim($link['description']);\n }\n else {\n // If the description field was left empty, remove the title attribute\n // from the menu link.\n unset($link['options']['attributes']['title']);\n }\n if (!menu_link_save($link)) {\n drupal_set_message(t('There was an error saving the menu link.'), 'error');\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-11a02c1583", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.tokens.inc/function/taxonomy_token_info/7.x", "instruction": "In Drupal 7, write the function `taxonomy_token_info()` (file modules/taxonomy/taxonomy.tokens.inc) so that it does the following: Implements hook_token_info().", "context": "File: modules/taxonomy/taxonomy.tokens.inc", "response": "function taxonomy_token_info() {\n $types['term'] = array(\n 'name' => t(\"Taxonomy terms\"),\n 'description' => t(\"Tokens related to taxonomy terms.\"),\n 'needs-data' => 'term',\n );\n $types['vocabulary'] = array(\n 'name' => t(\"Vocabularies\"),\n 'description' => t(\"Tokens related to taxonomy vocabularies.\"),\n 'needs-data' => 'vocabulary',\n );\n\n // Taxonomy term related variables.\n $term['tid'] = array(\n 'name' => t(\"Term ID\"),\n 'description' => t(\"The unique ID of the taxonomy term.\"),\n );\n $term['name'] = array(\n 'name' => t(\"Name\"),\n 'description' => t(\"The name of the taxonomy term.\"),\n );\n $term['description'] = array(\n 'name' => t(\"Description\"),\n 'description' => t(\"The optional description of the taxonomy term.\"),\n );\n $term['node-count'] = array(\n 'name' => t(\"Node count\"),\n 'description' => t(\"The number of nodes tagged with the taxonomy term.\"),\n );\n $term['url'] = array(\n 'name' => t(\"URL\"),\n 'description' => t(\"The URL of the taxonomy term.\"),\n );\n\n // Taxonomy vocabulary related variables.\n $vocabulary['vid'] = array(\n 'name' => t(\"Vocabulary ID\"),\n 'description' => t(\"The unique ID of the taxonomy vocabulary.\"),\n );\n $vocabulary['name'] = array(\n 'name' => t(\"Name\"),\n 'description' => t(\"The name of the taxonomy vocabulary.\"),\n );\n $vocabulary['description'] = array(\n 'name' => t(\"Description\"),\n 'description' => t(\"The optional description of the taxonomy vocabulary.\"),\n );\n $vocabulary['node-count'] = array(\n 'name' => t(\"Node count\"),\n 'description' => t(\"The number of nodes tagged with terms belonging to the taxonomy vocabulary.\"),\n );\n $vocabulary['term-count'] = array(\n 'name' => t(\"Term count\"),\n 'description' => t(\"The number of terms belonging to the taxonomy vocabulary.\"),\n );\n\n // Chained tokens for taxonomies\n $term['vocabulary'] = array(\n 'name' => t(\"Vocabulary\"),\n 'description' => t(\"The vocabulary the taxonomy term belongs to.\"),\n 'type' => 'vocabulary',\n );\n $term['parent'] = array(\n 'name' => t(\"Parent term\"),\n 'description' => t(\"The parent term of the taxonomy term, if one exists.\"),\n 'type' => 'term',\n );\n\n return array(\n 'types' => $types,\n 'tokens' => array(\n 'term' => $term,\n 'vocabulary' => $vocabulary,\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-11b71fb675", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_get_menu_tree/7.x", "instruction": "Implement `toolbar_get_menu_tree()` in PHP for Drupal 7. Required behavior: Gets only the top level items below the 'admin' path.", "context": "Returns: An array containing a menu tree of top level items below the 'admin' path.\n\nFile: modules/toolbar/toolbar.module", "response": "function toolbar_get_menu_tree() {\n $tree = array();\n $admin_link = db_query('SELECT * FROM {menu_links} WHERE menu_name = :menu_name AND module = :module AND link_path = :path', array(':menu_name' => 'management', ':module' => 'system', ':path' => 'admin'))->fetchAssoc();\n if ($admin_link) {\n $tree = menu_build_tree('management', array(\n 'expanded' => array($admin_link['mlid']),\n 'min_depth' => $admin_link['depth'] + 1,\n 'max_depth' => $admin_link['depth'] + 1,\n ));\n }\n\n return $tree;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-11c81a3d41", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_cookie_save/7.x", "instruction": "In Drupal 7, write the function `user_cookie_save(array $values)` (file modules/user/user.module) so that it does the following: Saves visitor information as a cookie so it can be reused.", "context": "Parameters:\n- $values: An array of key/value pairs to be saved into a cookie.\n\nFile: modules/user/user.module", "response": "function user_cookie_save(array $values) {\n foreach ($values as $field => $value) {\n // Set cookie for 365 days.\n setrawcookie('Drupal.visitor.' . $field, rawurlencode($value), REQUEST_TIME + 31536000, '/');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-11d4621dea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_cancel_confirm_form_submit/7.x", "instruction": "In Drupal 7, write the function `user_cancel_confirm_form_submit($form, &$form_state)` (file modules/user/user.pages.inc) so that it does the following: Submit handler for the account cancellation confirm form.", "context": "File: modules/user/user.pages.inc", "response": "function user_cancel_confirm_form_submit($form, &$form_state) {\n global $user;\n $account = $form_state['values']['_account'];\n\n // Cancel account immediately, if the current user has administrative\n // privileges, no confirmation mail shall be sent, and the user does not\n // attempt to cancel the own account.\n if (user_access('administer users') && empty($form_state['values']['user_cancel_confirm']) && $account->uid != $user->uid) {\n user_cancel($form_state['values'], $account->uid, $form_state['values']['user_cancel_method']);\n\n $form_state['redirect'] = 'admin/people';\n }\n else {\n // Store cancelling method and whether to notify the user in $account for\n // user_cancel_confirm().\n $edit = array(\n 'user_cancel_method' => $form_state['values']['user_cancel_method'],\n 'user_cancel_notify' => $form_state['values']['user_cancel_notify'],\n );\n $account = user_save($account, $edit);\n _user_mail_notify('cancel_confirm', $account);\n drupal_set_message(t('A confirmation request to cancel your account has been sent to your e-mail address.'));\n watchdog('user', 'Sent account cancellation request to %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);\n\n $form_state['redirect'] = \"user/$account->uid\";\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-12043cc227", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_file_move/7.x", "instruction": "I need the code for `image_file_move($file, $source)` in Drupal 7 (modules/image/image.module). It must do this: Implements hook_file_move().", "context": "File: modules/image/image.module", "response": "function image_file_move($file, $source) {\n // Delete any image derivatives at the original image path.\n image_path_flush($source->uri);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1205e12899", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_unpromote_action/7.x", "instruction": "I need the code for `node_unpromote_action($node, $context = array())` in Drupal 7 (modules/node/node.module). It must do this: Sets the promote property of a node to 0.", "context": "Parameters:\n- $node: A node object.\n- $context: (optional) Array of additional information about what triggered the action. Not used for this action.\n\nFile: modules/node/node.module", "response": "function node_unpromote_action($node, $context = array()) {\n $node->promote = NODE_NOT_PROMOTED;\n watchdog('action', 'Removed @type %title from front page.', array('@type' => node_type_get_name($node), '%title' => $node->title));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-12285a478d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate/7.x", "instruction": "Implement `file_validate(stdClass &$file, $validators = array())` in PHP for Drupal 7. Required behavior: Checks that a file meets the criteria specified by the validators.", "context": "After executing the validator callbacks specified hook_file_validate() will also be called to allow other modules to report errors about the file.\n\nParameters:\n- $file: A Drupal file object.\n- $validators: An optional, associative array of callback functions used to validate the file. The keys are function names and the values arrays of callback parameters which will be passed in after the file object. The functions should return an array of error messages; an empty array indicates that the file passed validation. The functions will be called in the order specified.\n\nReturns: An array containing validation error messages.\n\nFile: includes/file.inc", "response": "function file_validate(stdClass &$file, $validators = array()) {\n // Call the validation functions specified by this function's caller.\n $errors = array();\n foreach ($validators as $function => $args) {\n if (function_exists($function)) {\n array_unshift($args, $file);\n $errors = array_merge($errors, call_user_func_array($function, $args));\n }\n }\n\n // Let other modules perform validation on the new file.\n $errors = array_merge($errors, module_invoke_all('file_validate', $file));\n\n // Ensure the file does not contain a malicious extension. At this point\n // file_save_upload() will have munged the file so it does not contain a\n // malicious extension. Contributed and custom code that calls this method\n // needs to take similar steps if they need to permit files with malicious\n // extensions to be uploaded.\n if (empty($errors) && !variable_get('allow_insecure_uploads', 0) && preg_match('/\\.(' . FILE_INSECURE_EXTENSIONS . ')(\\.|$)/i', $file->filename)) {\n $errors[] = t('For security reasons, your upload has been rejected.');\n }\n\n return $errors;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-122b6394de", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_hue2rgb/7.x", "instruction": "I need the code for `_color_hue2rgb($m1, $m2, $h)` in Drupal 7 (modules/color/color.module). It must do this: Helper function for _color_hsl2rgb().", "context": "File: modules/color/color.module", "response": "function _color_hue2rgb($m1, $m2, $h) {\n $h = ($h < 0) ? $h + 1 : (($h > 1) ? $h - 1 : $h);\n if ($h * 6 < 1) return $m1 + ($m2 - $m1) * $h * 6;\n if ($h * 2 < 1) return $m2;\n if ($h * 3 < 2) return $m1 + ($m2 - $m1) * (0.66666 - $h) * 6;\n\n return $m1;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1239d3b7ba", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_signature/7.x", "instruction": "I need the code for `_openid_signature($association, $message_array, $keys_to_sign)` in Drupal 7 (modules/openid/openid.inc). It must do this: Sign certain keys in a message", "context": "Parameters:\n- $association: - object loaded from openid_association or openid_server_association table - important fields are ->assoc_type and ->mac_key\n- $message_array: - array of entire message about to be sent\n- $keys_to_sign: - keys in the message to include in signature (without 'openid.' appended)\n\nFile: modules/openid/openid.inc", "response": "function _openid_signature($association, $message_array, $keys_to_sign) {\n $signature = '';\n $sign_data = array();\n\n foreach ($keys_to_sign as $key) {\n if (isset($message_array['openid.' . $key])) {\n $sign_data[$key] = $message_array['openid.' . $key];\n }\n }\n\n $message = _openid_create_message($sign_data);\n $secret = base64_decode((string) $association->mac_key);\n $signature = _openid_hmac($secret, $message);\n\n return base64_encode($signature);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-123b976c20", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_form_node_delete_confirm_alter/7.x", "instruction": "I need the code for `book_form_node_delete_confirm_alter(&$form, $form_state)` in Drupal 7 (modules/book/book.module). It must do this: Implements hook_form_FORM_ID_alter() for node_delete_confirm().", "context": "Alters the confirm form for a single node deletion.\n\nFile: modules/book/book.module", "response": "function book_form_node_delete_confirm_alter(&$form, $form_state) {\n $node = node_load($form['nid']['#value']);\n\n if (isset($node->book) && $node->book['has_children']) {\n $form['book_warning'] = array(\n '#markup' => '

        ' . t('%title is part of a book outline, and has associated child pages. If you proceed with deletion, the child pages will be relocated automatically.', array('%title' => $node->title)) . '

        ',\n '#weight' => -10,\n );\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1247a00f89", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_update_7005/7.x", "instruction": "I need the code for `comment_update_7005()` in Drupal 7 (modules/comment/comment.install). It must do this: Create the comment_body field.", "context": "File: modules/comment/comment.install", "response": "function comment_update_7005() {\n // Create comment body field.\n $field = array(\n 'field_name' => 'comment_body',\n 'type' => 'text_long',\n 'module' => 'text',\n 'entity_types' => array(\n 'comment',\n ),\n 'settings' => array(),\n 'cardinality' => 1,\n );\n _update_7000_field_create_field($field);\n\n // Add the field to comments for all existing bundles.\n $generic_instance = array(\n 'entity_type' => 'comment',\n 'label' => t('Comment'),\n 'settings' => array(\n 'text_processing' => 1,\n ),\n 'required' => TRUE,\n 'display' => array(\n 'default' => array(\n 'label' => 'hidden',\n 'type' => 'text_default',\n 'weight' => 0,\n 'settings' => array(),\n 'module' => 'text',\n ),\n ),\n 'widget' => array(\n 'type' => 'text_textarea',\n 'settings' => array(\n 'rows' => 5,\n ),\n 'weight' => 0,\n 'module' => 'text',\n ),\n 'description' => '',\n );\n\n $types = _update_7000_node_get_types();\n foreach ($types as $type => $type_object) {\n $instance = $generic_instance;\n $instance['bundle'] = 'comment_node_' . $type;\n _update_7000_field_create_instance($field, $instance);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1284174995", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_add_form/7.x", "instruction": "Implement `shortcut_set_add_form($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form callback: builds the form for adding a shortcut set.", "context": "Parameters:\n- $form: An associative array containing the structure of the form.\n- $form_state: An associative array containing the current state of the form.\n\nReturns: An array representing the form definition.\n\nFile: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_set_add_form($form, &$form_state) {\n $form['new'] = array(\n '#type' => 'textfield',\n '#title' => t('Set name'),\n '#description' => t('The new set is created by copying items from your default shortcut set.'),\n '#required' => TRUE,\n );\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Create new set'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-12aca333a5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_permission/7.x", "instruction": "Implement `forum_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/forum/forum.module", "response": "function forum_permission() {\n $perms = array(\n 'administer forums' => array(\n 'title' => t('Administer forums'),\n ),\n );\n return $perms;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-12b375dae3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_manager_extract_directory/7.x", "instruction": "I need the code for `_update_manager_extract_directory($create = TRUE)` in Drupal 7 (modules/update/update.module). It must do this: Returns the directory where update archive files should be extracted.", "context": "Parameters:\n- $create: (optional) Whether to attempt to create the directory if it does not already exist. Defaults to TRUE.\n\nReturns: The full path to the temporary directory where update file archives should be extracted.\n\nFile: modules/update/update.module", "response": "function _update_manager_extract_directory($create = TRUE) {\n $directory = &drupal_static(__FUNCTION__, '');\n if (empty($directory)) {\n $directory = 'temporary://update-extraction-' . _update_manager_unique_identifier();\n if ($create && !file_exists($directory)) {\n mkdir($directory);\n }\n }\n return $directory;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-12c1eebb08", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_block_save/7.x", "instruction": "Implement `node_block_save($delta = '', $edit = array())` in PHP for Drupal 7. Required behavior: Implements hook_block_save().", "context": "File: modules/node/node.module", "response": "function node_block_save($delta = '', $edit = array()) {\n if ($delta == 'recent') {\n variable_set('node_recent_block_count', $edit['node_recent_block_count']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-12caa3dd5f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_block_save/7.x", "instruction": "In Drupal 7, write the function `user_block_save($delta = '', $edit = array())` (file modules/user/user.module) so that it does the following: Implements hook_block_save().", "context": "File: modules/user/user.module", "response": "function user_block_save($delta = '', $edit = array()) {\n global $user;\n\n switch ($delta) {\n case 'new':\n variable_set('user_block_whois_new_count', $edit['user_block_whois_new_count']);\n break;\n\n case 'online':\n variable_set('user_block_seconds_online', $edit['user_block_seconds_online']);\n variable_set('user_block_max_list_count', $edit['user_block_max_list_count']);\n break;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-12cd1c618b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translation_filter_form_submit/7.x", "instruction": "In Drupal 7, write the function `locale_translation_filter_form_submit($form, &$form_state)` (file modules/locale/locale.admin.inc) so that it does the following: Process result from locale translation filter form.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_translation_filter_form_submit($form, &$form_state) {\n $op = $form_state['values']['op'];\n $filters = locale_translation_filters();\n switch ($op) {\n case t('Filter'):\n foreach ($filters as $name => $filter) {\n if (isset($form_state['values'][$name])) {\n $_SESSION['locale_translation_filter'][$name] = $form_state['values'][$name];\n }\n }\n break;\n case t('Reset'):\n $_SESSION['locale_translation_filter'] = array();\n break;\n }\n\n $form_state['redirect'] = 'admin/config/regional/translate/translate';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-12dea37f2c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/_form_set_class/7.x", "instruction": "Implement `_form_set_class(&$element, $class = array())` in PHP for Drupal 7. Required behavior: Sets a form element's class attribute.", "context": "Adds 'required' and 'error' classes as needed.\n\nParameters:\n- $element: The form element.\n- $name: Array of new class names to be added.\n\nFile: includes/form.inc", "response": "function _form_set_class(&$element, $class = array()) {\n if (!empty($class)) {\n if (!isset($element['#attributes']['class'])) {\n $element['#attributes']['class'] = array();\n }\n $element['#attributes']['class'] = array_merge($element['#attributes']['class'], $class);\n }\n // This function is invoked from form element theme functions, but the\n // rendered form element may not necessarily have been processed by\n // form_builder().\n if (!empty($element['#required'])) {\n $element['#attributes']['class'][] = 'required';\n }\n if (isset($element['#parents']) && form_get_error($element) !== NULL && !empty($element['#validated'])) {\n $element['#attributes']['class'][] = 'error';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-12f91297a5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_instance_settings/7.x", "instruction": "I need the code for `field_info_instance_settings($type)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns a field type's default instance settings.", "context": "Parameters:\n- $type: A field type name.\n\nReturns: The field type's default instance settings, as provided by hook_field_info(), or an empty array if type or settings are not defined.\n\nFile: modules/field/field.info.inc", "response": "function field_info_instance_settings($type) {\n $info = field_info_field_types($type);\n return isset($info['instance_settings']) ? $info['instance_settings'] : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-13084f1e4b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/theme_locale_languages_overview_form/7.x", "instruction": "Implement `theme_locale_languages_overview_form($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the language overview form.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/locale/locale.admin.inc", "response": "function theme_locale_languages_overview_form($variables) {\n $form = $variables['form'];\n $default = language_default();\n foreach ($form['name'] as $key => $element) {\n // Do not take form control structures.\n if (is_array($element) && element_child($key)) {\n // Disable checkbox for the default language, because it cannot be disabled.\n if ($key == $default->language) {\n $form['enabled'][$key]['#attributes']['disabled'] = 'disabled';\n }\n\n // Add invisible labels for the checkboxes and radio buttons in the table\n // for accessibility. These changes are only required and valid when the\n // form is themed as a table, so it would be wrong to perform them in the\n // form constructor.\n $title = drupal_render($form['name'][$key]);\n $form['enabled'][$key]['#title'] = t('Enable !title', array('!title' => $title));\n $form['enabled'][$key]['#title_display'] = 'invisible';\n $form['site_default'][$key]['#title'] = t('Set !title as default', array('!title' => $title));\n $form['site_default'][$key]['#title_display'] = 'invisible';\n $rows[] = array(\n 'data' => array(\n '' . $title . '',\n drupal_render($form['native'][$key]),\n check_plain($key),\n drupal_render($form['direction'][$key]),\n array('data' => drupal_render($form['enabled'][$key]), 'align' => 'center'),\n drupal_render($form['site_default'][$key]),\n drupal_render($form['weight'][$key]),\n l(t('edit'), 'admin/config/regional/language/edit/' . $key) . (($key != 'en' && $key != $default->language) ? ' ' . l(t('delete'), 'admin/config/regional/language/delete/' . $key) : '')\n ),\n 'class' => array('draggable'),\n );\n }\n }\n $header = array(array('data' => t('English name')), array('data' => t('Native name')), array('data' => t('Code')), array('data' => t('Direction')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Weight')), array('data' => t('Operations')));\n $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'language-order')));\n $output .= drupal_render_children($form);\n\n drupal_add_tabledrag('language-order', 'order', 'sibling', 'language-order-weight');\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-130bec09bd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/theme_node_search_admin/7.x", "instruction": "Implement `theme_node_search_admin($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the content ranking part of the search settings admin page.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/node/node.module", "response": "function theme_node_search_admin($variables) {\n $form = $variables['form'];\n\n $output = drupal_render($form['info']);\n\n $header = array(t('Factor'), t('Influence'));\n foreach (element_children($form['factors']) as $key) {\n $row = array();\n $row[] = $form['factors'][$key]['#title'];\n $form['factors'][$key]['#title_display'] = 'invisible';\n $row[] = drupal_render($form['factors'][$key]);\n $rows[] = $row;\n }\n $output .= theme('table', array('header' => $header, 'rows' => $rows));\n\n $output .= drupal_render_children($form);\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-130e69584b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_permissions_get_configured_types/7.x", "instruction": "In Drupal 7, write the function `node_permissions_get_configured_types()` (file modules/node/node.module) so that it does the following: Returns an array of node types that should be managed by permissions.", "context": "By default, this will include all node types in the system. To exclude a specific node from getting permissions defined for it, set the node_permissions_$type variable to 0. Core does not provide an interface for doing so. However, contrib modules may exclude their own nodes in hook_install(). Alternatively, contrib modules may configure all node types at once, or decide to apply some other hook_node_access() implementation to some or all node types.\n\nReturns: An array of node types managed by this module.\n\nFile: modules/node/node.module", "response": "function node_permissions_get_configured_types() {\n\n $configured_types = array();\n\n foreach (node_type_get_types() as $type => $info) {\n if (variable_get('node_permissions_' . $type, 1)) {\n $configured_types[] = $type;\n }\n }\n\n return $configured_types;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-130f7f31a4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.install/function/aggregator_update_7003/7.x", "instruction": "Implement `aggregator_update_7003()` in PHP for Drupal 7. Required behavior: Increase the length of {aggregator_feed}.url.", "context": "File: modules/aggregator/aggregator.install", "response": "function aggregator_update_7003() {\n db_drop_unique_key('aggregator_feed', 'url');\n db_change_field('aggregator_feed', 'url', 'url', array('type' => 'text', 'not null' => TRUE, 'description' => 'URL to the feed.'));\n db_change_field('aggregator_feed', 'link', 'link', array('type' => 'text', 'not null' => TRUE, 'description' => 'The parent website of the feed; comes from the element in the feed.'));\n db_change_field('aggregator_item', 'link', 'link', array('type' => 'text', 'not null' => TRUE, 'description' => 'Link to the feed item.'));\n db_change_field('aggregator_item', 'guid', 'guid', array('type' => 'text', 'not null' => TRUE, 'description' => 'Unique identifier for the feed item.'));\n db_add_index('aggregator_feed', 'url', array(array('url', 255)));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1322e008c7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_transfer/7.x", "instruction": "In Drupal 7, write the function `file_transfer($uri, $headers)` (file includes/file.inc) so that it does the following: Transfers a file to the client using HTTP.", "context": "Pipes a file through Drupal to the client.\n\nParameters:\n- $uri: String specifying the file URI to transfer.\n- $headers: An array of HTTP headers to send along with file.\n\nFile: includes/file.inc", "response": "function file_transfer($uri, $headers) {\n if (ob_get_level()) {\n ob_end_clean();\n }\n\n foreach ($headers as $name => $value) {\n drupal_add_http_header($name, $value);\n }\n drupal_send_headers();\n $scheme = file_uri_scheme($uri);\n // Transfer file in 1024 byte chunks to save memory usage.\n if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) {\n while (!feof($fd)) {\n print fread($fd, 1024);\n }\n fclose($fd);\n }\n else {\n drupal_not_found();\n }\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-13454f02fa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_configure_date_formats_form/7.x", "instruction": "In Drupal 7, write the function `system_configure_date_formats_form($form, &$form_state, $dfid = 0)` (file modules/system/system.admin.inc) so that it does the following: Allow users to add additional date formats.", "context": "File: modules/system/system.admin.inc", "response": "function system_configure_date_formats_form($form, &$form_state, $dfid = 0) {\n $ajax_path = 'admin/config/regional/date-time/formats/lookup';\n $js_settings = array(\n 'type' => 'setting',\n 'data' => array(\n 'dateTime' => array(\n 'date-format' => array(\n 'text' => t('Displayed as'),\n 'lookup' => url($ajax_path, array('query' => array('token' => drupal_get_token($ajax_path)))),\n ),\n ),\n ),\n );\n\n if ($dfid) {\n $form['dfid'] = array(\n '#type' => 'value',\n '#value' => $dfid,\n );\n $format = system_get_date_format($dfid);\n }\n\n $now = ($dfid ? t('Displayed as %date', array('%date' => format_date(REQUEST_TIME, 'custom', $format->format))) : '');\n\n $form['date_format'] = array(\n '#type' => 'textfield',\n '#title' => t('Format string'),\n '#maxlength' => 100,\n '#description' => t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://php.net/manual/function.date.php')),\n '#default_value' => ($dfid ? $format->format : ''),\n '#field_suffix' => ' ' . $now . '',\n '#attached' => array(\n 'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),\n ),\n '#required' => TRUE,\n );\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['update'] = array(\n '#type' => 'submit',\n '#value' => ($dfid ? t('Save format') : t('Add format')),\n );\n\n $form['#validate'][] = 'system_add_date_formats_form_validate';\n $form['#submit'][] = 'system_add_date_formats_form_submit';\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-134a2eeeb2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/_toolbar_is_collapsed/7.x", "instruction": "In Drupal 7, write the function `_toolbar_is_collapsed()` (file modules/toolbar/toolbar.module) so that it does the following: Determines the current state of the toolbar drawer's visibility.", "context": "Returns: TRUE when drawer is collapsed, FALSE when it is expanded.\n\nFile: modules/toolbar/toolbar.module", "response": "function _toolbar_is_collapsed() {\n // PHP converts dots into underscores in cookie names to avoid problems with\n // its parser, so we use a converted cookie name.\n return isset($_COOKIE['Drupal_toolbar_collapsed']) ? $_COOKIE['Drupal_toolbar_collapsed'] : 0;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-134f7b885c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/_update_manager_check_backends/7.x", "instruction": "In Drupal 7, write the function `_update_manager_check_backends(&$form, $operation)` (file modules/update/update.manager.inc) so that it does the following: Checks for file transfer backends and prepares a form fragment about them.", "context": "Parameters:\n- $form (array): Reference to the form array we're building.\n- $operation (string): The update manager operation we're in the middle of. Can be either 'update' or 'install'. Use to provide operation-specific interface text.\n\nReturns: TRUE if the update manager should continue to the next step in the workflow, or FALSE if we've hit a fatal configuration and must halt the workflow.\n\nFile: modules/update/update.manager.inc", "response": "function _update_manager_check_backends(&$form, $operation) {\n // If file transfers will be performed locally, we do not need to display any\n // warnings or notices to the user and should automatically continue the\n // workflow, since we won't be using a FileTransfer backend that requires\n // user input or a specific server configuration.\n if (update_manager_local_transfers_allowed()) {\n return TRUE;\n }\n\n // Otherwise, show the available backends.\n $form['available_backends'] = array(\n '#prefix' => '

        ',\n '#suffix' => '

        ',\n );\n\n $available_backends = drupal_get_filetransfer_info();\n if (empty($available_backends)) {\n if ($operation == 'update') {\n $form['available_backends']['#markup'] = t('Your server does not support updating modules and themes from this interface. Instead, update modules and themes by uploading the new versions directly to the server, as described in the handbook.', array('@handbook_url' => 'http://drupal.org/getting-started/install-contrib'));\n }\n else {\n $form['available_backends']['#markup'] = t('Your server does not support installing modules and themes from this interface. Instead, install modules and themes by uploading them directly to the server, as described in the handbook.', array('@handbook_url' => 'http://drupal.org/getting-started/install-contrib'));\n }\n return FALSE;\n }\n\n $backend_names = array();\n foreach ($available_backends as $backend) {\n $backend_names[] = $backend['title'];\n }\n if ($operation == 'update') {\n $form['available_backends']['#markup'] = format_plural(\n count($available_backends),\n 'Updating modules and themes requires @backends access to your server. See the handbook for other update methods.',\n 'Updating modules and themes requires access to your server via one of the following methods: @backends. See the handbook for other update methods.',\n array(\n '@backends' => implode(', ', $backend_names),\n '@handbook_url' => 'http://drupal.org/getting-started/install-contrib',\n ));\n }\n else {\n $form['available_backends']['#markup'] = format_plural(\n count($available_backends),\n 'Installing modules and themes requires @backends access to your server. See the handbook for other installation methods.',\n 'Installing modules and themes requires access to your server via one of the following methods: @backends. See the handbook for other installation methods.',\n array(\n '@backends' => implode(', ', $backend_names),\n '@handbook_url' => 'http://drupal.org/getting-started/install-contrib',\n ));\n }\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1395db8baa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_reset_item_confirm_submit/7.x", "instruction": "Implement `menu_reset_item_confirm_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process menu reset item form submissions.", "context": "File: modules/menu/menu.admin.inc", "response": "function menu_reset_item_confirm_submit($form, &$form_state) {\n $item = $form_state['values']['item'];\n $new_item = menu_reset_item($item);\n drupal_set_message(t('The menu link was reset to its default settings.'));\n $form_state['redirect'] = 'admin/structure/menu/manage/' . $new_item['menu_name'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-13a5b838cd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_preview/7.x", "instruction": "In Drupal 7, write the function `comment_preview($comment)` (file modules/comment/comment.module) so that it does the following: Generate a comment preview.", "context": "File: modules/comment/comment.module", "response": "function comment_preview($comment) {\n global $user;\n\n drupal_set_title(t('Preview comment'), PASS_THROUGH);\n\n $node = node_load($comment->nid);\n\n if (!form_get_errors()) {\n $comment_body = field_get_items('comment', $comment, 'comment_body');\n $comment->format = $comment_body[0]['format'];\n // Attach the user and time information.\n if (!empty($comment->name)) {\n $account = user_load_by_name($comment->name);\n }\n elseif ($user->uid && empty($comment->is_anonymous)) {\n $account = $user;\n }\n\n if (!empty($account->uid)) {\n $comment->uid = $account->uid;\n $comment->name = check_plain($account->name);\n $comment->signature = $account->signature;\n $comment->signature_format = $account->signature_format;\n $comment->picture = $account->picture;\n }\n elseif (empty($comment->name)) {\n $comment->name = variable_get('anonymous', t('Anonymous'));\n }\n\n $comment->created = !empty($comment->created) ? $comment->created : REQUEST_TIME;\n $comment->changed = REQUEST_TIME;\n $comment->in_preview = TRUE;\n $comment_build = comment_view($comment, $node);\n $comment_build['#weight'] = -100;\n\n $form['comment_preview'] = $comment_build;\n }\n\n if ($comment->pid) {\n $build = array();\n if ($comments = comment_load_multiple(array($comment->pid), array('status' => COMMENT_PUBLISHED))) {\n $parent_comment = $comments[$comment->pid];\n $build = comment_view($parent_comment, $node);\n }\n }\n else {\n $build = node_view($node);\n }\n\n $form['comment_output_below'] = $build;\n $form['comment_output_below']['#weight'] = 100;\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-13d3c31d08", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_formatter_info/7.x", "instruction": "I need the code for `taxonomy_field_formatter_info()` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_field_formatter_info().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_field_formatter_info() {\n return array(\n 'taxonomy_term_reference_link' => array(\n 'label' => t('Link'),\n 'field types' => array('taxonomy_term_reference'),\n ),\n 'taxonomy_term_reference_plain' => array(\n 'label' => t('Plain text'),\n 'field types' => array('taxonomy_term_reference'),\n ),\n 'taxonomy_term_reference_rss_category' => array(\n 'label' => t('RSS category'),\n 'field types' => array('taxonomy_term_reference'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1401b80cf9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_update_bid/7.x", "instruction": "Implement `book_update_bid($book_link)` in PHP for Drupal 7. Required behavior: Updates the book ID of a page and its children when it moves to a new book.", "context": "Parameters:\n- $book_link: A fully loaded menu link that is part of the book hierarchy.\n\nFile: modules/book/book.module", "response": "function book_update_bid($book_link) {\n $query = db_select('menu_links');\n $query->addField('menu_links', 'mlid');\n for ($i = 1; $i <= MENU_MAX_DEPTH && $book_link[\"p$i\"]; $i++) {\n $query->condition(\"p$i\", $book_link[\"p$i\"]);\n }\n $mlids = $query->execute()->fetchCol();\n\n if ($mlids) {\n db_update('book')\n ->fields(array('bid' => $book_link['bid']))\n ->condition('mlid', $mlids, 'IN')\n ->execute();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-141bab8b69", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_link_load/7.x", "instruction": "Implement `book_link_load($mlid)` in PHP for Drupal 7. Required behavior: Gets a book menu link by its menu link ID.", "context": "Like menu_link_load(), but adds additional data from the {book} table.\n\nDo not call when loading a node, since this function may call node_load().\n\nParameters:\n- $mlid: The menu link ID of the menu item.\n\nReturns: A menu link, with the link translated for rendering and data added from the {book} table. FALSE if there is an error.\n\nFile: modules/book/book.module", "response": "function book_link_load($mlid) {\n if ($item = db_query(\"SELECT * FROM {menu_links} ml INNER JOIN {book} b ON b.mlid = ml.mlid LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid\", array(\n ':mlid' => $mlid,\n ))->fetchAssoc()) {\n _menu_link_translate($item);\n return $item;\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-142430f006", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_page_user_access/7.x", "instruction": "I need the code for `blog_page_user_access($account)` in Drupal 7 (modules/blog/blog.module). It must do this: Access callback for user blog pages.", "context": "File: modules/blog/blog.module", "response": "function blog_page_user_access($account) {\n // The visitor must be able to access the site's content.\n // For a blog to 'exist' the user must either be able to\n // create new blog entries, or it must have existing posts.\n return $account->uid && user_access('access content') && (user_access('create blog content', $account) || _blog_post_exists($account));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-142d653364", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_shift/7.x", "instruction": "Implement `_color_shift($given, $ref1, $ref2, $target)` in PHP for Drupal 7. Required behavior: Shifts a given color, using a reference pair and a target blend color.", "context": "Note: this function is significantly different from the JS version, as it is written to match the blended images perfectly.\n\nConstraint: if (ref2 == target + (ref1 - target) * delta) for some fraction delta then (return == target + (given - target) * delta).\n\nLoose constraint: Preserve relative positions in saturation and luminance space.\n\nFile: modules/color/color.module", "response": "function _color_shift($given, $ref1, $ref2, $target) {\n // We assume that ref2 is a blend of ref1 and target and find\n // delta based on the length of the difference vectors.\n\n // delta = 1 - |ref2 - ref1| / |white - ref1|\n $target = _color_unpack($target, TRUE);\n $ref1 = _color_unpack($ref1, TRUE);\n $ref2 = _color_unpack($ref2, TRUE);\n $numerator = 0;\n $denominator = 0;\n for ($i = 0; $i < 3; ++$i) {\n $numerator += ($ref2[$i] - $ref1[$i]) * ($ref2[$i] - $ref1[$i]);\n $denominator += ($target[$i] - $ref1[$i]) * ($target[$i] - $ref1[$i]);\n }\n $delta = ($denominator > 0) ? (1 - sqrt($numerator / $denominator)) : 0;\n\n // Calculate the color that ref2 would be if the assumption was true.\n for ($i = 0; $i < 3; ++$i) {\n $ref3[$i] = $target[$i] + ($ref1[$i] - $target[$i]) * $delta;\n }\n\n // If the assumption is not true, there is a difference between ref2 and ref3.\n // We measure this in HSL space. Notation: x' = hsl(x).\n $ref2 = _color_rgb2hsl($ref2);\n $ref3 = _color_rgb2hsl($ref3);\n for ($i = 0; $i < 3; ++$i) {\n $shift[$i] = $ref2[$i] - $ref3[$i];\n }\n\n // Take the given color, and blend it towards the target.\n $given = _color_unpack($given, TRUE);\n for ($i = 0; $i < 3; ++$i) {\n $result[$i] = $target[$i] + ($given[$i] - $target[$i]) * $delta;\n }\n\n // Finally, we apply the extra shift in HSL space.\n // Note: if ref2 is a pure blend of ref1 and target, then |shift| = 0.\n $result = _color_rgb2hsl($result);\n for ($i = 0; $i < 3; ++$i) {\n $result[$i] = min(1, max(0, $result[$i] + $shift[$i]));\n }\n $result = _color_hsl2rgb($result);\n\n // Return hex color.\n return _color_pack($result, TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-142fb8a55c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_page_opml/7.x", "instruction": "Implement `aggregator_page_opml($cid = NULL)` in PHP for Drupal 7. Required behavior: Page callback: Generates an OPML representation of all feeds.", "context": "Parameters:\n- $cid: (optional) If set, feeds are exported only from a category with this ID. Otherwise, all feeds are exported. Defaults to NULL.\n\nReturns: An OPML formatted string.\n\nFile: modules/aggregator/aggregator.pages.inc", "response": "function aggregator_page_opml($cid = NULL) {\n if ($cid) {\n $result = db_query('SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = :cid ORDER BY title', array(':cid' => $cid));\n }\n else {\n $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title');\n }\n\n $feeds = $result->fetchAll();\n return theme('aggregator_page_opml', array('feeds' => $feeds));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-143622373a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_overview_terms_submit/7.x", "instruction": "I need the code for `taxonomy_overview_terms_submit($form, &$form_state)` in Drupal 7 (modules/taxonomy/taxonomy.admin.inc). It must do this: Submit handler for terms overview form.", "context": "Rather than using a textfield or weight field, this form depends entirely upon the order of form elements on the page to determine new weights.\n\nBecause there might be hundreds or thousands of taxonomy terms that need to be ordered, terms are weighted from 0 to the number of terms in the vocabulary, rather than the standard -10 to 10 scale. Numbers are sorted lowest to highest, but are not necessarily sequential. Numbers may be skipped when a term has children so that reordering is minimal when a child is added or removed from a term.\n\nFile: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_overview_terms_submit($form, &$form_state) {\n if ($form_state['triggering_element']['#value'] == t('Reset to alphabetical')) {\n // Execute the reset action.\n if ($form_state['values']['reset_alphabetical'] === TRUE) {\n return taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, $form_state);\n }\n // Rebuild the form to confirm the reset action.\n $form_state['rebuild'] = TRUE;\n $form_state['confirm_reset_alphabetical'] = TRUE;\n return;\n }\n\n // Sort term order based on weight.\n uasort($form_state['values'], 'drupal_sort_weight');\n\n $vocabulary = $form['#vocabulary'];\n $hierarchy = 0; // Update the current hierarchy type as we go.\n\n $changed_terms = array();\n $tree = taxonomy_get_tree($vocabulary->vid);\n\n if (empty($tree)) {\n return;\n }\n\n // Build a list of all terms that need to be updated on previous pages.\n $weight = 0;\n $term = (array) $tree[0];\n while ($term['tid'] != $form['#first_tid']) {\n if ($term['parents'][0] == 0 && $term['weight'] != $weight) {\n $term['parent'] = $term['parents'][0];\n $term['weight'] = $weight;\n $changed_terms[$term['tid']] = $term;\n }\n $weight++;\n $hierarchy = $term['parents'][0] != 0 ? 1 : $hierarchy;\n $term = (array) $tree[$weight];\n }\n\n // Renumber the current page weights and assign any new parents.\n $level_weights = array();\n foreach ($form_state['values'] as $tid => $values) {\n if (isset($form[$tid]['#term'])) {\n $term = $form[$tid]['#term'];\n // Give terms at the root level a weight in sequence with terms on previous pages.\n if ($values['parent'] == 0 && $term['weight'] != $weight) {\n $term['weight'] = $weight;\n $changed_terms[$term['tid']] = $term;\n }\n // Terms not at the root level can safely start from 0 because they're all on this page.\n elseif ($values['parent'] > 0) {\n $level_weights[$values['parent']] = isset($level_weights[$values['parent']]) ? $level_weights[$values['parent']] + 1 : 0;\n if ($level_weights[$values['parent']] != $term['weight']) {\n $term['weight'] = $level_weights[$values['parent']];\n $changed_terms[$term['tid']] = $term;\n }\n }\n // Update any changed parents.\n if ($values['parent'] != $term['parent']) {\n $term['parent'] = $values['parent'];\n $changed_terms[$term['tid']] = $term;\n }\n $hierarchy = $term['parent'] != 0 ? 1 : $hierarchy;\n $weight++;\n }\n }\n\n // Build a list of all terms that need to be updated on following pages.\n for ($weight; $weight < count($tree); $weight++) {\n $term = (array) $tree[$weight];\n if ($term['parents'][0] == 0 && $term['weight'] != $weight) {\n $term['parent'] = $term['parents'][0];\n $term['weight'] = $weight;\n $changed_terms[$term['tid']] = $term;\n }\n $hierarchy = $term['parents'][0] != 0 ? 1 : $hierarchy;\n }\n\n // Save all updated terms.\n foreach ($changed_terms as $changed) {\n $term = (object) $changed;\n // Update term_hierachy and term_data directly since we don't have a\n // fully populated term object to save.\n db_update('taxonomy_term_hierarchy')\n ->fields(array('parent' => $term->parent))\n ->condition('tid', $term->tid, '=')\n ->execute();\n\n db_update('taxonomy_term_data')\n ->fields(array('weight' => $term->weight))\n ->condition('tid', $term->tid, '=')\n ->execute();\n }\n\n // Update the vocabulary hierarchy to flat or single hierarchy.\n if ($vocabulary->hierarchy != $hierarchy) {\n $vocabulary->hierarchy = $hierarchy;\n taxonomy_vocabulary_save($vocabulary);\n }\n drupal_set_message(t('The configuration options have been saved.'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-143d741c1e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7011/7.x", "instruction": "I need the code for `system_update_7011()` in Drupal 7 (modules/system/system.install). It must do this: Split the 'bypass node access' permission from 'administer nodes'.", "context": "File: modules/system/system.install", "response": "function system_update_7011() {\n // Get existing roles that can 'administer nodes'.\n $rids = array();\n $rids = db_query(\"SELECT rid FROM {role_permission} WHERE permission = :perm\", array(':perm' => 'administer nodes'))->fetchCol();\n // None found.\n if (empty($rids)) {\n return;\n }\n $insert = db_insert('role_permission')->fields(array('rid', 'permission'));\n foreach ($rids as $rid) {\n $insert->values(array(\n 'rid' => $rid,\n 'permission' => 'bypass node access',\n ));\n }\n $insert->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-145c74a706", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_system_info_alter/7.x", "instruction": "In Drupal 7, write the function `overlay_system_info_alter(&$info, $file, $type)` (file modules/overlay/overlay.module) so that it does the following: Implements hook_system_info_alter().", "context": "Add default regions for the overlay.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_system_info_alter(&$info, $file, $type) {\n if ($type == 'theme') {\n $info['overlay_regions'][] = 'content';\n $info['overlay_regions'][] = 'help';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-147ab3383c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_widget_properties_ENTITY_TYPE_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_widget_properties_ENTITY_TYPE_alter(&$widget, $context)` (modules/field/field.api.php): Alters the widget properties of a field instance on a given entity type before it gets displayed.", "context": "Modules can implement hook_field_widget_properties_ENTITY_TYPE_alter() to alter the widget properties for fields on a specific entity type, rather than implementing hook_field_widget_properties_alter().\n\nThis hook is called once per field per displayed widget entity. If the result of the hook involves reading from the database, it is highly recommended to statically cache the information.\n\nParameters:\n- $widget: The instance's widget properties.\n- $context: An associative array containing: - entity_type: The entity type; e.g., 'node' or 'user'. - entity: The entity object. - field: The field that the widget belongs to. - instance: The instance of the field.\n\nFile: modules/field/field.api.php", "response": "function hook_field_widget_properties_ENTITY_TYPE_alter(&$widget, $context) {\n // Change a widget's type according to the time of day.\n $field = $context['field'];\n if ($field['field_name'] == 'field_foo') {\n $time = date('H');\n $widget['type'] = $time < 12 ? 'widget_am' : 'widget_pm';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-14a02c5008", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_form_term_submit/7.x", "instruction": "In Drupal 7, write the function `taxonomy_form_term_submit($form, &$form_state)` (file modules/taxonomy/taxonomy.admin.inc) so that it does the following: Submit handler to insert or update a term.", "context": "File: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_form_term_submit($form, &$form_state) {\n if ($form_state['triggering_element']['#value'] == t('Delete')) {\n // Execute the term deletion.\n if ($form_state['values']['delete'] === TRUE) {\n return taxonomy_term_confirm_delete_submit($form, $form_state);\n }\n // Rebuild the form to confirm term deletion.\n $form_state['rebuild'] = TRUE;\n $form_state['confirm_delete'] = TRUE;\n return;\n }\n\n $term = taxonomy_form_term_submit_build_taxonomy_term($form, $form_state);\n\n $status = taxonomy_term_save($term);\n switch ($status) {\n case SAVED_NEW:\n drupal_set_message(t('Created new term %term.', array('%term' => $term->name)));\n watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->name), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));\n break;\n case SAVED_UPDATED:\n drupal_set_message(t('Updated term %term.', array('%term' => $term->name)));\n watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->name), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));\n // Clear the page and block caches to avoid stale data.\n cache_clear_all();\n break;\n }\n\n $current_parent_count = empty($form_state['values']['parent']) ? 0 : count((array) $form_state['values']['parent']);\n $previous_parent_count = empty($form['#term']['parent']) ? 0 : count((array) $form['#term']['parent']);\n // Root doesn't count if it's the only parent.\n if ($current_parent_count == 1 && isset($form_state['values']['parent'][0])) {\n $current_parent_count = 0;\n $form_state['values']['parent'] = array();\n }\n\n // If the number of parents has been reduced to one or none, do a check on the\n // parents of every term in the vocabulary value.\n if ($current_parent_count < $previous_parent_count && $current_parent_count < 2) {\n taxonomy_check_vocabulary_hierarchy($form['#vocabulary'], $form_state['values']);\n }\n // If we've increased the number of parents and this is a single or flat\n // hierarchy, update the vocabulary immediately.\n elseif ($current_parent_count > $previous_parent_count && $form['#vocabulary']->hierarchy < 2) {\n $form['#vocabulary']->hierarchy = $current_parent_count == 1 ? 1 : 2;\n taxonomy_vocabulary_save($form['#vocabulary']);\n }\n\n $form_state['values']['tid'] = $term->tid;\n $form_state['tid'] = $term->tid;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-14a3f128d6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_show_block_content/7.x", "instruction": "In Drupal 7, write the function `dashboard_show_block_content($module, $delta)` (file modules/dashboard/dashboard.module) so that it does the following: Ajax callback: Displays the rendered contents of a specific block.", "context": "Parameters:\n- $module: The block's module name.\n- $delta: The block's delta.\n\nFile: modules/dashboard/dashboard.module", "response": "function dashboard_show_block_content($module, $delta) {\n drupal_theme_initialize();\n global $theme_key;\n\n $blocks = array();\n $block_object = db_query(\"SELECT * FROM {block} WHERE theme = :theme AND module = :module AND delta = :delta\", array(\n \":theme\" => $theme_key,\n \":module\" => $module,\n \":delta\" => $delta,\n ))\n ->fetchObject();\n $block_object->enabled = $block_object->page_match = TRUE;\n $blocks[$module . \"_\" . $delta] = $block_object;\n $block_content = _block_render_blocks($blocks);\n $build = _block_get_renderable_array($block_content);\n $rendered_block = drupal_render($build);\n print $rendered_block;\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-14a7608afd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.pages.inc/function/openid_user_identities/7.x", "instruction": "I need the code for `openid_user_identities($account)` in Drupal 7 (modules/openid/openid.pages.inc). It must do this: Menu callback; Manage OpenID identities for the specified user.", "context": "File: modules/openid/openid.pages.inc", "response": "function openid_user_identities($account) {\n drupal_set_title(format_username($account));\n drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css');\n\n // Check to see if we got a response\n $result = openid_complete();\n if ($result['status'] == 'success') {\n $identity = $result['openid.claimed_id'];\n $query = db_insert('authmap')\n ->fields(array(\n 'uid' => $account->uid,\n 'authname' => $identity,\n 'module' => 'openid',\n ))\n ->execute();\n drupal_set_message(t('Successfully added %identity', array('%identity' => $identity)));\n }\n\n $header = array(t('OpenID'), t('Operations'));\n $rows = array();\n\n $result = db_query(\"SELECT * FROM {authmap} WHERE module='openid' AND uid=:uid\", array(':uid' => $account->uid));\n foreach ($result as $identity) {\n $rows[] = array(check_plain($identity->authname), l(t('Delete'), 'user/' . $account->uid . '/openid/delete/' . $identity->aid));\n }\n\n $build['openid_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#empty' => t('No OpenID identities available for this account.'),\n );\n $build['openid_user_add'] = drupal_get_form('openid_user_add');\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-14c13cd102", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21batch.inc/function/_batch_do/7.x", "instruction": "I need the code for `_batch_do()` in Drupal 7 (includes/batch.inc). It must do this: Does one execution pass with JavaScript and returns progress to the browser.", "context": "File: includes/batch.inc", "response": "function _batch_do() {\n\n // Perform actual processing.\n list($percentage, $message) = _batch_process();\n\n drupal_json_output(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-14c9103bbc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_admin_paths/7.x", "instruction": "I need the code for `overlay_admin_paths()` in Drupal 7 (modules/overlay/overlay.module). It must do this: Implements hook_admin_paths().", "context": "File: modules/overlay/overlay.module", "response": "function overlay_admin_paths() {\n $paths = array(\n // This is marked as an administrative path so that if it is visited from\n // within the overlay, the user will stay within the overlay while the\n // callback is being processed.\n 'overlay/dismiss-message' => TRUE,\n );\n return $paths;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-14d92fb8bc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_write_compare_filter/7.x", "instruction": "I need the code for `_field_sql_storage_write_compare_filter($field, $array)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Cleanup field values for later values comparison.", "context": "Parameters:\n- $field (array): Field info as returned by field_info_field_by_id().\n- $array (array): Field values to cleanup.\n\nReturns (array): Filtered values.\n\nFile: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function _field_sql_storage_write_compare_filter($field, $array) {\n foreach ($array as $language => $items) {\n if (empty($items)) {\n unset($array[$language]);\n }\n else {\n foreach ($items as $delta => $item) {\n // This should not happen but some modules provide invalid data to the\n // field API.\n if (!is_array($item)) {\n continue;\n }\n // Let's start by pruning empty values and non storable values.\n $array[$language][$delta] = array_filter(array_intersect_key($item, $field['columns']), '_field_sql_storage_write_compare_filter_callback');\n // Ordering is important because for widget elements and loaded columns\n // from database order might differ and give false positives on field\n // value change, especially with complex fields such as image fields.\n ksort($array[$language][$delta]);\n }\n }\n }\n return $array;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1539b58479", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_revision_delete/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_node_revision_delete($node)` (modules/node/node.api.php): Respond to deletion of a node revision.", "context": "This hook is invoked from node_revision_delete() after the revision has been removed from the node_revision table, and before field_attach_delete_revision() is called.\n\nParameters:\n- $node: The node revision (node object) that is being deleted.\n\nFile: modules/node/node.api.php", "response": "function hook_node_revision_delete($node) {\n db_delete('mytable')\n ->condition('vid', $node->vid)\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-153abb3694", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/template_preprocess_forum_icon/7.x", "instruction": "In Drupal 7, write the function `template_preprocess_forum_icon(&$variables)` (file modules/forum/forum.module) so that it does the following: Preprocesses variables for forum-icon.tpl.php.", "context": "Parameters:\n- $variables: An array containing the following elements: - new_posts: Indicates whether or not the topic contains new posts. - num_posts: The total number of posts in all topics. - comment_mode: An integer indicating whether comments are open, closed, or hidden. - sticky: Indicates whether the topic is sticky. - first_new: Indicates whether this is the first topic with new posts.\n\nFile: modules/forum/forum.module", "response": "function template_preprocess_forum_icon(&$variables) {\n $variables['hot_threshold'] = variable_get('forum_hot_topic', 15);\n if ($variables['num_posts'] > $variables['hot_threshold']) {\n $variables['icon_class'] = $variables['new_posts'] ? 'hot-new' : 'hot';\n $variables['icon_title'] = $variables['new_posts'] ? t('Hot topic, new comments') : t('Hot topic');\n }\n else {\n $variables['icon_class'] = $variables['new_posts'] ? 'new' : 'default';\n $variables['icon_title'] = $variables['new_posts'] ? t('New comments') : t('Normal topic');\n }\n\n if ($variables['comment_mode'] == COMMENT_NODE_CLOSED || $variables['comment_mode'] == COMMENT_NODE_HIDDEN) {\n $variables['icon_class'] = 'closed';\n $variables['icon_title'] = t('Closed topic');\n }\n\n if ($variables['sticky'] == 1) {\n $variables['icon_class'] = 'sticky';\n $variables['icon_title'] = t('Sticky topic');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-153ac71423", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_mimetype_mapping_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_file_mimetype_mapping_alter(&$mapping)` (modules/system/system.api.php): Alter MIME type mappings used to determine MIME type from a file extension.", "context": "This hook is run when file_mimetype_mapping() is called. It is used to allow modules to add to or modify the default mapping from file_default_mimetype_mapping().\n\nParameters:\n- $mapping: An array of mimetypes correlated to the extensions that relate to them. The array has 'mimetypes' and 'extensions' elements, each of which is an array.\n\nFile: modules/system/system.api.php", "response": "function hook_file_mimetype_mapping_alter(&$mapping) {\n // Add new MIME type 'drupal/info'.\n $mapping['mimetypes']['example_info'] = 'drupal/info';\n // Add new extension '.info' and map it to the 'drupal/info' MIME type.\n $mapping['extensions']['info'] = 'example_info';\n // Override existing extension mapping for '.ogg' files.\n $mapping['extensions']['ogg'] = 189;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-155aeb674b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_form_element_after_build/7.x", "instruction": "I need the code for `field_form_element_after_build($element, &$form_state)` in Drupal 7 (modules/field/field.form.inc). It must do this: #after_build callback for field elements in a form.", "context": "This stores the final location of the field within the form structure so that field_default_form_errors() can assign validation errors to the right form element.\n\nFile: modules/field/field.form.inc", "response": "function field_form_element_after_build($element, &$form_state) {\n $parents = $element['#field_parents'];\n $field_name = $element['#field_name'];\n $langcode = $element['#language'];\n\n $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state);\n $field_state['array_parents'] = $element['#array_parents'];\n field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state);\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1568c1037e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_access_records_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_node_access_records_alter(&$grants, $node)` (modules/node/node.api.php): Alter permissions for a node before it is written to the database.", "context": "Node access modules establish rules for user access to content. Node access records are stored in the {node_access} table and define which permissions are required to access a node. This hook is invoked after node access modules returned their requirements via hook_node_access_records(); doing so allows modules to modify the $grants array by reference before it is stored, so custom or advanced business logic can be applied.\n\nParameters:\n- $grants: The $grants array returned by hook_node_access_records().\n- $node: The node for which the grants were acquired. The preferred use of this hook is in a module that bridges multiple node access modules with a configurable behavior, as shown in the example with the 'is_preview' field.\n\nFile: modules/node/node.api.php", "response": "function hook_node_access_records_alter(&$grants, $node) {\n // Our module allows editors to mark specific articles with the 'is_preview'\n // field. If the node being saved has a TRUE value for that field, then only\n // our grants are retained, and other grants are removed. Doing so ensures\n // that our rules are enforced no matter what priority other grants are given.\n if ($node->is_preview) {\n // Our module grants are set in $grants['example'].\n $temp = $grants['example'];\n // Now remove all module grants but our own.\n $grants = array('example' => $temp);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-157166beac", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.pages.inc/function/blog_feed_user/7.x", "instruction": "In Drupal 7, write the function `blog_feed_user($account)` (file modules/blog/blog.pages.inc) so that it does the following: Menu callback; displays an RSS feed containing recent blog entries of a given user.", "context": "File: modules/blog/blog.pages.inc", "response": "function blog_feed_user($account) {\n\n $nids = db_select('node', 'n')\n ->fields('n', array('nid', 'created'))\n ->condition('type', 'blog')\n ->condition('uid', $account->uid)\n ->condition('status', 1)\n ->orderBy('created', 'DESC')\n ->range(0, variable_get('feed_default_items', 10))\n ->addTag('node_access')\n ->execute()\n ->fetchCol();\n\n $channel['title'] = t(\"!name's blog\", array('!name' => format_username($account)));\n $channel['link'] = url('blog/' . $account->uid, array('absolute' => TRUE));\n\n node_feed($nids, $channel);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-158d0ab056", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_settings_form/7.x", "instruction": "In Drupal 7, write the function `image_field_settings_form($field, $instance)` (file modules/image/image.field.inc) so that it does the following: Implements hook_field_settings_form().", "context": "File: modules/image/image.field.inc", "response": "function image_field_settings_form($field, $instance) {\n $defaults = field_info_field_settings($field['type']);\n $settings = array_merge($defaults, $field['settings']);\n\n $scheme_options = array();\n foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {\n $scheme_options[$scheme] = $stream_wrapper['name'];\n }\n $form['uri_scheme'] = array(\n '#type' => 'radios',\n '#title' => t('Upload destination'),\n '#options' => $scheme_options,\n '#default_value' => $settings['uri_scheme'],\n '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'),\n );\n\n // When the user sets the scheme on the UI, even for the first time, it's\n // updating a field because fields are created on the \"Manage fields\"\n // page. So image_field_update_field() can handle this change.\n $form['default_image'] = array(\n '#title' => t('Default image'),\n '#type' => 'managed_file',\n '#description' => t('If no image is uploaded, this image will be shown on display.'),\n '#default_value' => $field['settings']['default_image'],\n '#upload_location' => $settings['uri_scheme'] . '://default_images/',\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-15b66b6333", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_formatter_view/7.x", "instruction": "Implement `image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_view().", "context": "File: modules/image/image.field.inc", "response": "function image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {\n $element = array();\n\n // Check if the formatter involves a link.\n if ($display['settings']['image_link'] == 'content') {\n $uri = entity_uri($entity_type, $entity);\n }\n elseif ($display['settings']['image_link'] == 'file') {\n $link_file = TRUE;\n }\n\n foreach ($items as $delta => $item) {\n if (isset($link_file)) {\n $uri = array(\n 'path' => file_create_url($item['uri']),\n 'options' => array(),\n );\n }\n $element[$delta] = array(\n '#theme' => 'image_formatter',\n '#item' => $item,\n '#image_style' => $display['settings']['image_style'],\n '#path' => isset($uri) ? $uri : '',\n );\n }\n\n return $element;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-15df82f9a7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_form_search_form_alter/7.x", "instruction": "I need the code for `node_form_search_form_alter(&$form, $form_state)` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_form_FORM_ID_alter().", "context": "File: modules/node/node.module", "response": "function node_form_search_form_alter(&$form, $form_state) {\n if (isset($form['module']) && $form['module']['#value'] == 'node' && user_access('use advanced search')) {\n // Keyword boxes:\n $form['advanced'] = array(\n '#type' => 'fieldset',\n '#title' => t('Advanced search'),\n '#collapsible' => TRUE,\n '#collapsed' => TRUE,\n '#attributes' => array('class' => array('search-advanced')),\n );\n $form['advanced']['keywords'] = array(\n '#prefix' => '
        ',\n '#suffix' => '
        ',\n );\n $form['advanced']['keywords']['or'] = array(\n '#type' => 'textfield',\n '#title' => t('Containing any of the words'),\n '#size' => 30,\n '#maxlength' => 255,\n );\n $form['advanced']['keywords']['phrase'] = array(\n '#type' => 'textfield',\n '#title' => t('Containing the phrase'),\n '#size' => 30,\n '#maxlength' => 255,\n );\n $form['advanced']['keywords']['negative'] = array(\n '#type' => 'textfield',\n '#title' => t('Containing none of the words'),\n '#size' => 30,\n '#maxlength' => 255,\n );\n\n // Node types:\n $types = array_map('check_plain', node_type_get_names());\n $form['advanced']['type'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Only of the type(s)'),\n '#prefix' => '
        ',\n '#suffix' => '
        ',\n '#options' => $types,\n );\n $form['advanced']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Advanced search'),\n '#prefix' => '
        ',\n '#suffix' => '
        ',\n '#weight' => 100,\n );\n\n // Languages:\n $language_options = array();\n foreach (language_list('language') as $key => $entity) {\n if ($entity->enabled) {\n $language_options[$key] = $entity->name;\n }\n }\n if (count($language_options) > 1) {\n $form['advanced']['language'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Languages'),\n '#prefix' => '
        ',\n '#suffix' => '
        ',\n '#options' => $language_options,\n );\n }\n\n $form['#validate'][] = 'node_search_validate';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-15f4912a5d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_validate/7.x", "instruction": "I need the code for `number_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors)` in Drupal 7 (modules/field/modules/number/number.module). It must do this: Implements hook_field_validate().", "context": "Possible error codes:\n- 'number_min': The value is less than the allowed minimum value.\n- 'number_max': The value is greater than the allowed maximum value.\n\nFile: modules/field/modules/number/number.module", "response": "function number_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {\n foreach ($items as $delta => $item) {\n if ($item['value'] != '') {\n if (is_numeric($instance['settings']['min']) && $item['value'] < $instance['settings']['min']) {\n $errors[$field['field_name']][$langcode][$delta][] = array(\n 'error' => 'number_min',\n 'message' => t('%name: the value may be no less than %min.', array('%name' => $instance['label'], '%min' => $instance['settings']['min'])),\n );\n }\n if (is_numeric($instance['settings']['max']) && $item['value'] > $instance['settings']['max']) {\n $errors[$field['field_name']][$langcode][$delta][] = array(\n 'error' => 'number_max',\n 'message' => t('%name: the value may be no greater than %max.', array('%name' => $instance['label'], '%max' => $instance['settings']['max'])),\n );\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-16140fa440", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_get_default_module_info/7.x", "instruction": "Implement `search_get_default_module_info()` in PHP for Drupal 7. Required behavior: Returns information about the default search module.", "context": "Returns: The search_get_info() array element for the default search module, if any.\n\nFile: modules/search/search.module", "response": "function search_get_default_module_info() {\n $info = search_get_info();\n $default = variable_get('search_default_module', 'node');\n if (isset($info[$default])) {\n return $info[$default];\n }\n // The variable setting does not match any active module, so just return\n // the info for the first active module (if any).\n return reset($info);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1626708163", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/_rdf_get_default_mapping/7.x", "instruction": "Implement `_rdf_get_default_mapping($type)` in PHP for Drupal 7. Required behavior: Helper function to get the default RDF mapping for a given entity type.", "context": "Parameters:\n- $type: An entity type, e.g. 'node' or 'comment'.\n\nReturns: The RDF mapping or an empty array if no mapping is defined for this entity type.\n\nFile: modules/rdf/rdf.module", "response": "function _rdf_get_default_mapping($type) {\n $default_mappings = &drupal_static(__FUNCTION__);\n\n if (!isset($default_mappings)) {\n // Get all of the modules that implement hook_rdf_mapping().\n $modules = module_implements('rdf_mapping');\n\n // Only consider the default entity mapping definitions.\n foreach ($modules as $module) {\n $mappings = module_invoke($module, 'rdf_mapping');\n foreach ($mappings as $mapping) {\n if ($mapping['bundle'] === RDF_DEFAULT_BUNDLE) {\n $default_mappings[$mapping['type']] = $mapping['mapping'];\n }\n }\n }\n }\n\n return isset($default_mappings[$type]) ? $default_mappings[$type] : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-162b03b993", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.report.inc/function/update_status/7.x", "instruction": "I need the code for `update_status()` in Drupal 7 (modules/update/update.report.inc). It must do this: Page callback: Generates a page about the update status of projects.", "context": "File: modules/update/update.report.inc", "response": "function update_status() {\n if ($available = update_get_available(TRUE)) {\n module_load_include('inc', 'update', 'update.compare');\n $data = update_calculate_project_data($available);\n return theme('update_report', array('data' => $data));\n }\n else {\n return theme('update_report', array('data' => _update_no_data()));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-16426cc551", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_parse_info_format/7.x", "instruction": "In Drupal 7, write the function `drupal_parse_info_format($data)` (file includes/common.inc) so that it does the following: Parses data in Drupal's .info format.", "context": "Data should be in an .ini-like format to specify values. White-space generally doesn't matter, except inside values:\n\nParameters:\n- $data: A string to parse.\n\nReturns: The info array.\n\nFile: includes/common.inc", "response": "function drupal_parse_info_format($data) {\n $info = array();\n\n if (preg_match_all('\n @^\\s* # Start at the beginning of a line, ignoring leading whitespace\n ((?:\n [^=;\\[\\]]| # Key names cannot contain equal signs, semi-colons or square brackets,\n \\[[^\\[\\]]*\\] # unless they are balanced and not nested\n )+?)\n \\s*=\\s* # Key/value pairs are separated by equal signs (ignoring white-space)\n (?:\n (\"(?:[^\"]|(?<=\\\\\\\\)\")*\")| # Double-quoted string, which may contain slash-escaped quotes/slashes\n (\\'(?:[^\\']|(?<=\\\\\\\\)\\')*\\')| # Single-quoted string, which may contain slash-escaped quotes/slashes\n ([^\\r\\n]*?) # Non-quoted string\n )\\s*$ # Stop at the next end of a line, ignoring trailing whitespace\n @msx', $data, $matches, PREG_SET_ORDER)) {\n foreach ($matches as $match) {\n // Fetch the key and value string.\n $i = 0;\n foreach (array('key', 'value1', 'value2', 'value3') as $var) {\n $$var = isset($match[++$i]) ? $match[$i] : '';\n }\n $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;\n\n // Parse array syntax.\n $keys = preg_split('/\\]?\\[/', rtrim($key, ']'));\n $last = array_pop($keys);\n $parent = &$info;\n\n // Create nested arrays.\n foreach ($keys as $key) {\n if ($key == '') {\n $key = count($parent);\n }\n if (!isset($parent[$key]) || !is_array($parent[$key])) {\n $parent[$key] = array();\n }\n $parent = &$parent[$key];\n }\n\n // Handle PHP constants.\n if (preg_match('/^\\w+$/i', $value) && defined($value)) {\n $value = constant($value);\n }\n\n // Insert actual value.\n if ($last == '') {\n $last = count($parent);\n }\n $parent[$last] = $value;\n }\n }\n\n return $info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-16518d26ee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_setcookie/7.x", "instruction": "I need the code for `drupal_setcookie($name, $value, $options)` in Drupal 7 (includes/bootstrap.inc). It must do this: Drupal's wrapper around PHP's setcookie() function.", "context": "This allows the cookie's $value and $options to be altered.\n\nParameters:\n- $name: The name of the cookie.\n- $value: The value of the cookie.\n- $options: An associative array which may have any of the keys expires, path, domain, secure, httponly, samesite.\n\nFile: includes/bootstrap.inc", "response": "function drupal_setcookie($name, $value, $options) {\n $options = _drupal_cookie_params($options);\n if (\\PHP_VERSION_ID >= 70300) {\n setcookie($name, $value, $options);\n }\n else {\n $defaults = array(\n 'expires' => 0,\n 'path' => '',\n 'domain' => '',\n 'secure' => FALSE,\n 'httponly' => FALSE,\n );\n $options += $defaults;\n setcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1653c3f8cd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.install/function/tracker_uninstall/7.x", "instruction": "I need the code for `tracker_uninstall()` in Drupal 7 (modules/tracker/tracker.install). It must do this: Implements hook_uninstall().", "context": "File: modules/tracker/tracker.install", "response": "function tracker_uninstall() {\n variable_del('tracker_index_nid');\n variable_del('tracker_batch_size');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-16752de564", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_image_toolkit_settings/7.x", "instruction": "In Drupal 7, write the function `system_image_toolkit_settings()` (file modules/system/system.admin.inc) so that it does the following: Form builder; Configure site image toolkit usage.", "context": "File: modules/system/system.admin.inc", "response": "function system_image_toolkit_settings() {\n $toolkits_available = image_get_available_toolkits();\n $current_toolkit = image_get_toolkit();\n\n if (count($toolkits_available) == 0) {\n variable_del('image_toolkit');\n $form['image_toolkit_help'] = array(\n '#markup' => t(\"No image toolkits were detected. Drupal includes support for PHP's built-in image processing functions but they were not detected on this system. You should consult your system administrator to have them enabled, or try using a third party toolkit.\", array('!gd-link' => url('http://php.net/gd'))),\n );\n return $form;\n }\n\n if (count($toolkits_available) > 1) {\n $form['image_toolkit'] = array(\n '#type' => 'radios',\n '#title' => t('Select an image processing toolkit'),\n '#default_value' => variable_get('image_toolkit', $current_toolkit),\n '#options' => $toolkits_available\n );\n }\n else {\n variable_set('image_toolkit', key($toolkits_available));\n }\n\n // Get the toolkit's settings form.\n $function = 'image_' . $current_toolkit . '_settings';\n if (function_exists($function)) {\n $form['image_toolkit_settings'] = $function();\n }\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-167a254441", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_preview/7.x", "instruction": "Implement `node_preview($node)` in PHP for Drupal 7. Required behavior: Generates a node preview.", "context": "Parameters:\n- $node: The node to preview.\n\nReturns: An HTML-formatted string of a node preview.\n\nFile: modules/node/node.pages.inc", "response": "function node_preview($node) {\n // Clone the node before previewing it to prevent the node itself from being\n // modified.\n $cloned_node = clone $node;\n if (node_access('create', $cloned_node) || node_access('update', $cloned_node)) {\n _field_invoke_multiple('load', 'node', array($cloned_node->nid => $cloned_node));\n // Load the user's name when needed.\n if (isset($cloned_node->name)) {\n // The use of isset() is mandatory in the context of user IDs, because\n // user ID 0 denotes the anonymous user.\n if ($user = user_load_by_name($cloned_node->name)) {\n $cloned_node->uid = $user->uid;\n $cloned_node->picture = $user->picture;\n }\n else {\n $cloned_node->uid = 0; // anonymous user\n }\n }\n elseif ($cloned_node->uid) {\n $user = user_load($cloned_node->uid);\n $cloned_node->name = $user->name;\n $cloned_node->picture = $user->picture;\n }\n\n $cloned_node->changed = REQUEST_TIME;\n $nodes = array($cloned_node->nid => $cloned_node);\n\n // Display a preview of the node.\n if (!form_get_errors()) {\n $cloned_node->in_preview = TRUE;\n $output = theme('node_preview', array('node' => $cloned_node));\n unset($cloned_node->in_preview);\n }\n drupal_set_title(t('Preview'), PASS_THROUGH);\n\n return $output;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-168d1a6dc6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_parse_plural_forms/7.x", "instruction": "Implement `_locale_import_parse_plural_forms($pluralforms, $filepath)` in PHP for Drupal 7. Required behavior: Parses a Plural-Forms entry from a Gettext Portable Object file header", "context": "Parameters:\n- $pluralforms: A string containing the Plural-Forms entry.\n- $filepath: A string containing the filepath.\n\nReturns: An array containing the number of plurals and a formula in PHP for computing the plural form.\n\nFile: includes/locale.inc", "response": "function _locale_import_parse_plural_forms($pluralforms, $filepath) {\n // First, delete all whitespace\n $pluralforms = strtr($pluralforms, array(\" \" => \"\", \"\\t\" => \"\"));\n\n // Select the parts that define nplurals and plural\n $nplurals = strstr($pluralforms, \"nplurals=\");\n if (strpos($nplurals, \";\")) {\n $nplurals = substr($nplurals, 9, strpos($nplurals, \";\") - 9);\n }\n else {\n return FALSE;\n }\n $plural = strstr($pluralforms, \"plural=\");\n if (strpos($plural, \";\")) {\n $plural = substr($plural, 7, strpos($plural, \";\") - 7);\n }\n else {\n return FALSE;\n }\n\n // Get PHP version of the plural formula\n $plural = _locale_import_parse_arithmetic($plural);\n\n if ($plural !== FALSE) {\n return array($nplurals, $plural);\n }\n else {\n drupal_set_message(t('The translation file %filepath contains an error: the plural formula could not be parsed.', array('%filepath' => $filepath)), 'error');\n return FALSE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-168e039da4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_vocabulary_static_reset/7.x", "instruction": "Implement `taxonomy_vocabulary_static_reset($ids = NULL)` in PHP for Drupal 7. Required behavior: Clear all static cache variables for vocabularies.", "context": "Parameters:\n- $ids: An array of ids to reset in entity controller cache.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_vocabulary_static_reset($ids = NULL) {\n drupal_static_reset('taxonomy_vocabulary_get_names');\n entity_get_controller('taxonomy_vocabulary')->resetCache($ids);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-16c0224b8b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_reset_link_weights/7.x", "instruction": "Implement `shortcut_set_reset_link_weights(&$shortcut_set)` in PHP for Drupal 7. Required behavior: Resets the link weights in a shortcut set to match their current order.", "context": "This function can be used, for example, when a new shortcut link is added to the set. If the link is added to the end of the array and this function is called, it will force that link to display at the end of the list.\n\nParameters:\n- $shortcut_set (object): An object representing a shortcut set. The link weights of the passed-in object will be reset as described above.\n\nFile: modules/shortcut/shortcut.module", "response": "function shortcut_set_reset_link_weights(&$shortcut_set) {\n $weight = -50;\n foreach ($shortcut_set->links as &$link) {\n $link['weight'] = $weight;\n $weight++;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-17109eedc9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/theme_rdf_template_variable_wrapper/7.x", "instruction": "In Drupal 7, write the function `theme_rdf_template_variable_wrapper($variables)` (file modules/rdf/rdf.module) so that it does the following: Returns HTML for a template variable wrapped in an HTML element with the RDF attributes.", "context": "This is called by rdf_process() shortly before the theme system renders a template file. It is called once for each template variable for which additional attributes are needed. While template files are responsible for rendering the attributes for the template's primary object (via the $attributes variable), title (via the $title_attributes variable), and content (via the $content_attributes variable), additional template variables that need containing attributes are routed through this function, allowing the template file to receive properly wrapped variables.\n\nTip for themers: if you're already outputting a wrapper element around a particular template variable in your template file, and if you don't want an extra wrapper element, you can override this function to not wrap that variable and instead print the following inside your template file:\n\nParameters:\n- $variables: An associative array containing: - content: A string of content to be wrapped with attributes. - attributes: An array of attributes to be placed on the wrapping element. - context: An array of context information about the content to be wrapped: - hook: The theme hook that will use the wrapped content. This corresponds to the key within the theme registry for this template. For example, if this content is about to be used in node.tpl.php or node-[type].tpl.php, then the 'hook' is 'node'. - variable_name: The name of the variable by which the template will refer to this content. Each template file has documentation about the variables it uses. For example, if this function is called in preparing the $author variable for comment.tpl.php, then the 'variable_name' is 'author'. - variables: The full array of variables about to be passed to the template. - inline: TRUE if the content contains only inline HTML elements and therefore can be validly wrapped by a tag. FALSE if the content might contain block level HTML elements and therefore cannot be validly wrapped by a tag. Modules implementing preprocess functions that set 'rdf_template_variable_attributes_array' for a particular template variable that might contain block level HTML must also implement hook_preprocess_rdf_template_variable_wrapper() and set 'inline' to FALSE for that context. Themes that render normally inline content with block level HTML must similarly implement hook_preprocess_rdf_template_variable_wrapper() and set 'inline' accordingly.\n\nFile: modules/rdf/rdf.module", "response": "function theme_rdf_template_variable_wrapper($variables) {\n $output = $variables['content'];\n if (!empty($output) && !empty($variables['attributes'])) {\n $attributes = drupal_attributes($variables['attributes']);\n $output = $variables['inline'] ? \"$output\" : \"$output\";\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1724d6c5db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_switch_access/7.x", "instruction": "I need the code for `shortcut_set_switch_access($account = NULL)` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Access callback for switching the shortcut set assigned to a user account.", "context": "Parameters:\n- $account (object): (optional) The user account whose shortcuts will be switched. If not set, permissions will be checked for switching the logged-in user's own shortcut set.\n\nReturns: TRUE if the current user has access to switch the shortcut set of the provided account, FALSE otherwise.\n\nFile: modules/shortcut/shortcut.module", "response": "function shortcut_set_switch_access($account = NULL) {\n global $user;\n\n if (user_access('administer shortcuts')) {\n // Administrators can switch anyone's shortcut set.\n return TRUE;\n }\n\n if (!user_access('switch shortcut sets')) {\n // The user has no permission to switch anyone's shortcut set.\n return FALSE;\n }\n\n if (!isset($account) || $user->uid == $account->uid) {\n // Users with the 'switch shortcut sets' permission can switch their own\n // shortcuts sets.\n return TRUE;\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1727ff2deb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_valid_test_ua/7.x", "instruction": "I need the code for `drupal_valid_test_ua()` in Drupal 7 (includes/bootstrap.inc). It must do this: Returns the test prefix if this is an internal request from SimpleTest.", "context": "Returns: Either the simpletest prefix (the string \"simpletest\" followed by any number of digits) or FALSE if the user agent does not contain a valid HMAC and timestamp.\n\nFile: includes/bootstrap.inc", "response": "function drupal_valid_test_ua() {\n // No reason to reset this.\n static $test_prefix;\n\n if (isset($test_prefix)) {\n return $test_prefix;\n }\n\n if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match(\"/^(simpletest\\d+);(.+);(.+);(.+)$/\", $_SERVER['HTTP_USER_AGENT'], $matches)) {\n list(, $prefix, $time, $salt, $hmac) = $matches;\n $check_string = $prefix . ';' . $time . ';' . $salt;\n // We use the salt from settings.php to make the HMAC key, since\n // the database is not yet initialized and we can't access any Drupal variables.\n // The file properties add more entropy not easily accessible to others.\n $key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__);\n $time_diff = REQUEST_TIME - $time;\n // Since we are making a local request a 5 second time window is allowed,\n // and the HMAC must match.\n if ($time_diff >= 0 && $time_diff <= 5 && $hmac == drupal_hmac_base64($check_string, $key)) {\n $test_prefix = $prefix;\n return $test_prefix;\n }\n }\n\n $test_prefix = FALSE;\n return $test_prefix;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-17306ceacb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_load/7.x", "instruction": "I need the code for `profile_user_load($users)` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_user_load().", "context": "File: modules/profile/profile.module", "response": "function profile_user_load($users) {\n $result = db_query('SELECT f.name, f.type, v.uid, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid IN (:uids)', array(':uids' => array_keys($users)));\n foreach ($result as $record) {\n if (empty($users[$record->uid]->{$record->name})) {\n $users[$record->uid]->{$record->name} = _profile_field_serialize($record->type) ? unserialize($record->value) : $record->value;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-173631a85d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_scheme_form_validate/7.x", "instruction": "I need the code for `color_scheme_form_validate($form, &$form_state)` in Drupal 7 (modules/color/color.module). It must do this: Form validation handler for color_scheme_form().", "context": "File: modules/color/color.module", "response": "function color_scheme_form_validate($form, &$form_state) {\n // Only accept hexadecimal CSS color strings to avoid XSS upon use.\n foreach ($form_state['values']['palette'] as $key => $color) {\n if (!color_valid_hexadecimal_string($color)) {\n form_set_error('palette][' . $key, t('%name must be a valid hexadecimal CSS color value.', array('%name' => $form['color']['palette'][$key]['#title'])));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-17371c381f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_purge_field/7.x", "instruction": "I need the code for `field_purge_field($field)` in Drupal 7 (modules/field/field.crud.inc). It must do this: Purges a field record from the database.", "context": "This function assumes all instances for the field has already been purged, and should only be called by field_purge_batch().\n\nParameters:\n- $field: The field record to purge.\n\nFile: modules/field/field.crud.inc", "response": "function field_purge_field($field) {\n $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => 1));\n if (count($instances) > 0) {\n throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field['field_name'])));\n }\n\n db_delete('field_config')\n ->condition('id', $field['id'])\n ->execute();\n\n // Notify the storage engine.\n module_invoke($field['storage']['module'], 'field_storage_purge_field', $field);\n\n // Clear the cache.\n field_info_cache_clear();\n\n // Invoke external hooks after the cache is cleared for API consistency.\n module_invoke_all('field_purge_field', $field);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1754592880", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_hook_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_hook_info_alter(&$hooks)` (modules/system/system.api.php): Alter information from hook_hook_info().", "context": "Parameters:\n- $hooks: Information gathered by module_hook_info() from other modules' implementations of hook_hook_info(). Alter this array directly. See hook_hook_info() for information on what this may contain.\n\nFile: modules/system/system.api.php", "response": "function hook_hook_info_alter(&$hooks) {\n // Our module wants to completely override the core tokens, so make\n // sure the core token hooks are not found.\n $hooks['token_info']['group'] = 'mytokens';\n $hooks['tokens']['group'] = 'mytokens';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-175635d43f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_search_info/7.x", "instruction": "Implement `user_search_info()` in PHP for Drupal 7. Required behavior: Implements hook_search_info().", "context": "File: modules/user/user.module", "response": "function user_search_info() {\n return array(\n 'title' => 'Users',\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-175e36a13d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_login/7.x", "instruction": "Give me the example code for `hook_user_login(&$form_state, $account)` in Drupal 7. Hook description: The user just logged in.", "context": "Parameters:\n- $form_state: A keyed array containing the current state of the login form.\n- $account: The user object on which the operation was just performed.\n\nFile: modules/user/user.api.php", "response": "function hook_user_login(&$form_state, $account) {\n // If the user has a NULL time zone, notify them to set a time zone.\n if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {\n drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url(\"user/$account->uid/edit\", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-176301d31a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_update/7.x", "instruction": "I need the code for `book_node_update($node)` in Drupal 7 (modules/book/book.module). It must do this: Implements hook_node_update().", "context": "File: modules/book/book.module", "response": "function book_node_update($node) {\n if (!empty($node->book['bid'])) {\n if ($node->book['bid'] == 'new') {\n // New nodes that are their own book.\n $node->book['bid'] = $node->nid;\n }\n $node->book['nid'] = $node->nid;\n $node->book['menu_name'] = book_menu_name($node->book['bid']);\n _book_update_outline($node);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-177ee084ea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_overview/7.x", "instruction": "In Drupal 7, write the function `forum_overview($form, &$form_state)` (file modules/forum/forum.admin.inc) so that it does the following: Form constructor for the forum overview form.", "context": "Returns a form for controlling the hierarchy of existing forums and containers.\n\nFile: modules/forum/forum.admin.inc", "response": "function forum_overview($form, &$form_state) {\n module_load_include('inc', 'taxonomy', 'taxonomy.admin');\n\n $vid = variable_get('forum_nav_vocabulary', '');\n $vocabulary = taxonomy_vocabulary_load($vid);\n $form = taxonomy_overview_terms($form, $form_state, $vocabulary);\n\n foreach (element_children($form) as $key) {\n if (isset($form[$key]['#term'])) {\n $term = $form[$key]['#term'];\n $form[$key]['view']['#href'] = 'forum/' . $term['tid'];\n if (in_array($form[$key]['#term']['tid'], variable_get('forum_containers', array()))) {\n $form[$key]['edit']['#title'] = t('edit container');\n $form[$key]['edit']['#href'] = 'admin/structure/forum/edit/container/' . $term['tid'];\n }\n else {\n $form[$key]['edit']['#title'] = t('edit forum');\n $form[$key]['edit']['#href'] = 'admin/structure/forum/edit/forum/' . $term['tid'];\n }\n }\n }\n\n // Remove the alphabetical reset.\n unset($form['actions']['reset_alphabetical']);\n\n // The form needs to have submit and validate handlers set explicitly.\n $form['#theme'] = 'taxonomy_overview_terms';\n $form['#submit'] = array('taxonomy_overview_terms_submit'); // Use the existing taxonomy overview submit handler.\n $form['#empty_text'] = t('No containers or forums available. Add container or Add forum.', array('@container' => url('admin/structure/forum/add/container'), '@forum' => url('admin/structure/forum/add/forum')));\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1785202b02", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21language.inc/function/language_types_configurable/7.x", "instruction": "I need the code for `language_types_configurable($stored = TRUE)` in Drupal 7 (includes/language.inc). It must do this: Returns only the configurable language types.", "context": "A language type maybe configurable or fixed. A fixed language type is a type whose language negotiation providers are module-defined and not altered through the user interface.\n\nParameters:\n- $stored: Optional. By default retrieves values from the 'language_types' variable to avoid unnecessary hook invocations. If set to FALSE retrieves values from the actual language type definitions. This allows to react to alterations performed on the definitions by modules installed after the 'language_types' variable is set.\n\nReturns: An array of language type names.\n\nFile: includes/language.inc", "response": "function language_types_configurable($stored = TRUE) {\n $configurable = &drupal_static(__FUNCTION__);\n\n if ($stored && !isset($configurable)) {\n $types = variable_get('language_types', drupal_language_types());\n $configurable = array_keys(array_filter($types));\n }\n\n if (!$stored) {\n $result = array();\n foreach (language_types_info() as $type => $info) {\n if (!isset($info['fixed'])) {\n $result[] = $type;\n }\n }\n return $result;\n }\n\n return $configurable;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1799687e44", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_field_extra_fields/7.x", "instruction": "Implement `node_field_extra_fields()` in PHP for Drupal 7. Required behavior: Implements hook_field_extra_fields().", "context": "File: modules/node/node.module", "response": "function node_field_extra_fields() {\n $extra = array();\n\n foreach (node_type_get_types() as $type) {\n if ($type->has_title) {\n $extra['node'][$type->type] = array(\n 'form' => array(\n 'title' => array(\n 'label' => $type->title_label,\n 'description' => t('Node module element'),\n 'weight' => -5,\n ),\n ),\n );\n }\n }\n\n return $extra;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-179a780333", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_export_traverse/7.x", "instruction": "In Drupal 7, write the function `book_export_traverse($tree, $visit_func)` (file modules/book/book.module) so that it does the following: Traverses the book tree to build printable or exportable output.", "context": "During the traversal, the $visit_func() callback is applied to each node and is called recursively for each child of the node (in weight, title order).\n\nParameters:\n- $tree: A subtree of the book menu hierarchy, rooted at the current page.\n- $visit_func: A function callback to be called upon visiting a node in the tree.\n\nReturns: The output generated in visiting each node.\n\nFile: modules/book/book.module", "response": "function book_export_traverse($tree, $visit_func) {\n $output = '';\n\n foreach ($tree as $data) {\n // Note- access checking is already performed when building the tree.\n if ($node = node_load($data['link']['nid'], FALSE)) {\n $children = '';\n\n if ($data['below']) {\n $children = book_export_traverse($data['below'], $visit_func);\n }\n\n if (function_exists($visit_func)) {\n $output .= call_user_func($visit_func, $node, $children);\n }\n else {\n // Use the default function.\n $output .= book_node_export($node, $children);\n }\n }\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-179ba0dec4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21image.inc/function/image_dimensions_scale/7.x", "instruction": "Implement `image_dimensions_scale(array &$dimensions, $width = NULL, $height = NULL, $upscale = FALSE)` in PHP for Drupal 7. Required behavior: Scales image dimensions while maintaining aspect ratio.", "context": "The resulting dimensions can be smaller for one or both target dimensions.\n\nParameters:\n- $dimensions: Dimensions to be modified - an array with components width and height, in pixels.\n- $width: The target width, in pixels. If this value is NULL then the scaling will be based only on the height value.\n- $height: The target height, in pixels. If this value is NULL then the scaling will be based only on the width value.\n- $upscale: Boolean indicating that images smaller than the target dimensions will be scaled up. This generally results in a low quality image.\n\nReturns: TRUE if $dimensions was modified, FALSE otherwise.\n\nFile: includes/image.inc", "response": "function image_dimensions_scale(array &$dimensions, $width = NULL, $height = NULL, $upscale = FALSE) {\n $aspect = $dimensions['height'] / $dimensions['width'];\n\n // Calculate one of the dimensions from the other target dimension,\n // ensuring the same aspect ratio as the source dimensions. If one of the\n // target dimensions is missing, that is the one that is calculated. If both\n // are specified then the dimension calculated is the one that would not be\n // calculated to be bigger than its target.\n if (($width && !$height) || ($width && $height && $aspect < $height / $width)) {\n $height = (int) round($width * $aspect);\n }\n else {\n $width = (int) round($height / $aspect);\n }\n\n // Don't upscale if the option isn't enabled.\n if (!$upscale && ($width >= $dimensions['width'] || $height >= $dimensions['height'])) {\n return FALSE;\n }\n\n $dimensions['width'] = $width;\n $dimensions['height'] = $height;\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-17c0564274", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_schema_alter/7.x", "instruction": "Give me the example code for `hook_schema_alter(&$schema)` in Drupal 7. Hook description: Perform alterations to existing database schemas.", "context": "When a module modifies the database structure of another module (by changing, adding or removing fields, keys or indexes), it should implement hook_schema_alter() to update the default $schema to take its changes into account.\n\nSee hook_schema() for details on the schema definition structure.\n\nParameters:\n- $schema: Nested array describing the schemas for all modules.\n\nFile: modules/system/system.api.php", "response": "function hook_schema_alter(&$schema) {\n // Add field to existing schema.\n $schema['users']['fields']['timezone_id'] = array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Per-user timezone configuration.',\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-17df751a6e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.admin.inc/function/comment_multiple_delete_confirm/7.x", "instruction": "I need the code for `comment_multiple_delete_confirm($form, &$form_state)` in Drupal 7 (modules/comment/comment.admin.inc). It must do this: List the selected comments and verify that the admin wants to delete them.", "context": "Parameters:\n- $form_state: An associative array containing the current state of the form.\n\nReturns: TRUE if the comments should be deleted, FALSE otherwise.\n\nFile: modules/comment/comment.admin.inc", "response": "function comment_multiple_delete_confirm($form, &$form_state) {\n $edit = $form_state['input'];\n\n $form['comments'] = array(\n '#prefix' => '
          ',\n '#suffix' => '
        ',\n '#tree' => TRUE,\n );\n // array_filter() returns only elements with actual values.\n $comment_counter = 0;\n foreach (array_filter($edit['comments']) as $cid => $value) {\n $comment = comment_load($cid);\n if (is_object($comment) && is_numeric($comment->cid)) {\n $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();\n $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '
      • ', '#suffix' => check_plain($subject) . '
      • ');\n $comment_counter++;\n }\n }\n $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');\n\n if (!$comment_counter) {\n drupal_set_message(t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.'));\n drupal_goto('admin/content/comment');\n }\n else {\n return confirm_form($form,\n t('Are you sure you want to delete these comments and all their children?'),\n 'admin/content/comment', t('This action cannot be undone.'),\n t('Delete comments'), t('Cancel'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-17fb7acbd4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_formatter_settings_summary/7.x", "instruction": "Implement `text_field_formatter_settings_summary($field, $instance, $view_mode)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_settings_summary().", "context": "File: modules/field/modules/text/text.module", "response": "function text_field_formatter_settings_summary($field, $instance, $view_mode) {\n $display = $instance['display'][$view_mode];\n $settings = $display['settings'];\n\n $summary = '';\n\n if (strpos($display['type'], '_trimmed') !== FALSE) {\n $summary = t('Trimmed limit: @trim_length characters', array('@trim_length' => $settings['trim_length']));\n }\n\n return $summary;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-180ef85060", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/_batch_queue/7.x", "instruction": "I need the code for `_batch_queue($batch_set)` in Drupal 7 (includes/form.inc). It must do this: Returns a queue object for a batch set.", "context": "Parameters:\n- $batch_set: The batch set.\n\nReturns: The queue object.\n\nFile: includes/form.inc", "response": "function _batch_queue($batch_set) {\n static $queues;\n\n // The class autoloader is not available when running update.php, so make\n // sure the files are manually included.\n if (!isset($queues)) {\n $queues = array();\n require_once DRUPAL_ROOT . '/modules/system/system.queue.inc';\n require_once DRUPAL_ROOT . '/includes/batch.queue.inc';\n }\n\n if (isset($batch_set['queue'])) {\n $name = $batch_set['queue']['name'];\n $class = $batch_set['queue']['class'];\n\n if (!isset($queues[$class][$name])) {\n $queues[$class][$name] = new $class($name);\n }\n return $queues[$class][$name];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-182bd89ae1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_widget_field/7.x", "instruction": "Implement `field_widget_field($element, $form_state)` in PHP for Drupal 7. Required behavior: Retrieves the field definition for a widget's helper callbacks.", "context": "Widgets helper element callbacks (such as #process, #element_validate, #value_callback, ...) should use field_widget_field() and field_widget_instance() instead of field_info_field() and field_info_instance() when they need to access field or instance properties. See hook_field_widget_form() for more details.\n\nParameters:\n- $element: The structured array for the widget.\n- $form_state: The form state.\n\nReturns: The $field definition array for the current widget.\n\nFile: modules/field/field.form.inc", "response": "function field_widget_field($element, $form_state) {\n $field_state = field_form_get_state($element['#field_parents'], $element['#field_name'], $element['#language'], $form_state);\n return $field_state['field'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1831f946a8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_field_extra_fields/7.x", "instruction": "I need the code for `poll_field_extra_fields()` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_field_extra_fields().", "context": "File: modules/poll/poll.module", "response": "function poll_field_extra_fields() {\n $extra['node']['poll'] = array(\n 'form' => array(\n 'choice_wrapper' => array(\n 'label' => t('Poll choices'),\n 'description' => t('Poll choices'),\n 'weight' => -4,\n ),\n 'settings' => array(\n 'label' => t('Poll settings'),\n 'description' => t('Poll module settings'),\n 'weight' => -3,\n ),\n ),\n 'display' => array(\n 'poll_view_voting' => array(\n 'label' => t('Poll vote'),\n 'description' => t('Poll vote'),\n 'weight' => 0,\n ),\n 'poll_view_results' => array(\n 'label' => t('Poll results'),\n 'description' => t('Poll results'),\n 'weight' => 0,\n ),\n )\n );\n\n return $extra;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1832cf1062", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/function/hook_filter_info/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_filter_info()` (modules/filter/filter.api.php): Define content filters.", "context": "User submitted content is passed through a group of filters before it is output in HTML, in order to remove insecure or unwanted parts, correct or enhance the formatting, transform special keywords, etc. A group of filters is referred to as a \"text format\". Administrators can create as many text formats as needed. Individual filters can be enabled and configured differently for each text format.\n\nThis hook is invoked by filter_get_filters() and allows modules to register input filters they provide.\n\nFiltering is a two-step process. First, the content is 'prepared' by calling the 'prepare callback' function for every filter. The purpose of the 'prepare callback' is to escape HTML-like structures. For example, imagine a filter which allows the user to paste entire chunks of programming code without requiring manual escaping of special HTML characters like < or &. If the programming code were left untouched, then other filters could think it was HTML and change it. For many filters, the prepare step is not necessary.\n\nThe second step is the actual processing step. The result from passing the text through all the filters' prepare steps gets passed to all the filters again, this time with the 'process callback' function. The process callbacks should then actually change the content: transform URLs into hyperlinks, convert smileys into images, etc.\n\nFor performance reasons content is only filtered once; the result is stored in the cache table and retrieved from the cache the next time the same piece of content is displayed. If a filter's output is dynamic, it can override the cache mechanism, but obviously this should be used with caution: having one filter that does not support caching in a particular text format disables caching for the entire format, not just for one filter.\n\nBeware of the filter cache when developing your module: it is advised to set your filter to 'cache' => FALSE while developing, but be sure to remove that setting if it's not needed, when you are no longer in development mode.\n\nReturns: An associative array of filters, whose keys are internal filter names, which should be unique and therefore prefixed with the name of the module. Each value is an associative array describing the filter, with the following elements (all are optional except as noted): - title: (required) An administrative summary of what the filter does. - description: Additional administrative information about the filter's behavior, if needed for clarification. - settings callback: The name of a function that returns configuration form elements for the filter. See callback_filter_settings() for details. - default settings: An associative array containing default settings for the filter, to be applied when the filter has not been configured yet. - prepare callback: The name of a function that escapes the content before the actual filtering happens. See callback_filter_prepare() for details. - process callback: (required) The name the function that performs the actual filtering. See callback_filter_process() for details. - cache (default TRUE): Specifies whether the filtered text can be cached. Note that setting this to FALSE makes the entire text format not cacheable, which may have an impact on the site's overall performance. See filter_format_allowcache() for details. - tips callback: The name of a function that returns end-user-facing filter usage guidelines for the filter. See callback_filter_tips() for details. - weight: A default weight for the filter in new text formats.\n\nFile: modules/filter/filter.api.php", "response": "function hook_filter_info() {\n $filters['filter_html'] = array(\n 'title' => t('Limit allowed HTML tags'),\n 'description' => t('Allows you to restrict the HTML tags the user can use. It will also remove harmful content such as JavaScript events, JavaScript URLs and CSS styles from those tags that are not removed.'),\n 'process callback' => '_filter_html',\n 'settings callback' => '_filter_html_settings',\n 'default settings' => array(\n 'allowed_html' => '
          1. ',\n 'filter_html_help' => 1,\n 'filter_html_nofollow' => 0,\n ),\n 'tips callback' => '_filter_html_tips',\n );\n $filters['filter_autop'] = array(\n 'title' => t('Convert line breaks'),\n 'description' => t('Converts line breaks into HTML (i.e. <br> and <p>) tags.'),\n 'process callback' => '_filter_autop',\n 'tips callback' => '_filter_autop_tips',\n );\n return $filters;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-183f151ba5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_prepare_instance/7.x", "instruction": "In Drupal 7, write the function `_field_info_prepare_instance($instance, $field)` (file modules/field/field.info.inc) so that it does the following: Prepares an instance definition for the current run-time context.", "context": "The functionality has moved to the FieldInfo class. This function is kept as a backwards-compatibility layer. See http://drupal.org/node/1915646.\n\nFile: modules/field/field.info.inc", "response": "function _field_info_prepare_instance($instance, $field) {\n $cache = _field_info_field_cache();\n return $cache->prepareInstance($instance, $field['type']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-187389a884", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_edit_submit/7.x", "instruction": "I need the code for `shortcut_link_edit_submit($form, &$form_state)` in Drupal 7 (modules/shortcut/shortcut.admin.inc). It must do this: Submit handler for shortcut_link_edit().", "context": "File: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_link_edit_submit($form, &$form_state) {\n // Normalize the path in case it is an alias.\n $shortcut_path = drupal_get_normal_path($form_state['values']['shortcut_link']['link_path']);\n if (empty($shortcut_path)) {\n $shortcut_path = '';\n }\n $form_state['values']['shortcut_link']['link_path'] = $shortcut_path;\n\n $shortcut_link = array_merge($form_state['values']['original_shortcut_link'], $form_state['values']['shortcut_link']);\n\n menu_link_save($shortcut_link);\n $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $shortcut_link['menu_name'];\n drupal_set_message(t('The shortcut %link has been updated.', array('%link' => $shortcut_link['link_title'])));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1876ae7981", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7081/7.x", "instruction": "In Drupal 7, write the function `system_update_7081()` (file modules/system/system.install) so that it does the following: Remove the Drupal 6 default install profile if it is still in the database.", "context": "File: modules/system/system.install", "response": "function system_update_7081() {\n // Sites which used the default install profile in Drupal 6 and then updated\n // to Drupal 7.44 or earlier will still have a record of this install profile\n // in the database that needs to be deleted.\n db_delete('system')\n ->condition('filename', 'profiles/default/default.profile')\n ->condition('type', 'module')\n ->condition('status', 0)\n ->condition('schema_version', 0)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-188cf7bc15", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_date/7.x", "instruction": "In Drupal 7, write the function `xmlrpc_date($time)` (file includes/xmlrpc.inc) so that it does the following: Converts a PHP or ISO date/time to an XML-RPC object.", "context": "Parameters:\n- $time: A PHP timestamp or an ISO date-time string.\n\nReturns (object): An XML-RPC time/date object.\n\nFile: includes/xmlrpc.inc", "response": "function xmlrpc_date($time) {\n $xmlrpc_date = new stdClass();\n $xmlrpc_date->is_date = TRUE;\n // $time can be a PHP timestamp or an ISO one\n if (is_numeric($time)) {\n $xmlrpc_date->year = gmdate('Y', $time);\n $xmlrpc_date->month = gmdate('m', $time);\n $xmlrpc_date->day = gmdate('d', $time);\n $xmlrpc_date->hour = gmdate('H', $time);\n $xmlrpc_date->minute = gmdate('i', $time);\n $xmlrpc_date->second = gmdate('s', $time);\n $xmlrpc_date->iso8601 = gmdate('Ymd\\TH:i:s', $time);\n }\n else {\n $xmlrpc_date->iso8601 = $time;\n $time = str_replace(array('-', ':'), '', $time);\n $xmlrpc_date->year = substr($time, 0, 4);\n $xmlrpc_date->month = substr($time, 4, 2);\n $xmlrpc_date->day = substr($time, 6, 2);\n $xmlrpc_date->hour = substr($time, 9, 2);\n $xmlrpc_date->minute = substr($time, 11, 2);\n $xmlrpc_date->second = substr($time, 13, 2);\n }\n return $xmlrpc_date;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-18bd2ae644", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.authorize.inc/function/update_authorize_run_install/7.x", "instruction": "I need the code for `update_authorize_run_install($filetransfer, $project, $updater_name, $local_url)` in Drupal 7 (modules/update/update.authorize.inc). It must do this: Installs a new project when invoked by authorize.php.", "context": "Callback for system_authorized_init() in update_manager_install_form_submit().\n\nParameters:\n- $filetransfer (FileTransfer): The FileTransfer object created by authorize.php for use during this operation.\n- $project (string): The canonical project short name (e.g., {system}.name).\n- $updater_name (string): The name of the Updater class to use for installing this project.\n- $local_url (string): The URL to the locally installed temp directory where the project has already been downloaded and extracted into.\n\nFile: modules/update/update.authorize.inc", "response": "function update_authorize_run_install($filetransfer, $project, $updater_name, $local_url) {\n $operations[] = array(\n 'update_authorize_batch_copy_project',\n array(\n $project,\n $updater_name,\n $local_url,\n $filetransfer,\n ),\n );\n\n // @todo Instantiate our Updater to set the human-readable title?\n $batch = array(\n 'title' => t('Installing %project', array('%project' => $project)),\n 'init_message' => t('Preparing to install'),\n 'operations' => $operations,\n // @todo Use a different finished callback for different messages?\n 'finished' => 'update_authorize_install_batch_finished',\n 'file' => drupal_get_path('module', 'update') . '/update.authorize.inc',\n );\n batch_set($batch);\n\n // Invoke the batch via authorize.php.\n system_authorized_batch_process();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-18bfbac78c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_form_build_preview/7.x", "instruction": "I need the code for `comment_form_build_preview($form, &$form_state)` in Drupal 7 (modules/comment/comment.module). It must do this: Build a preview from submitted form values.", "context": "File: modules/comment/comment.module", "response": "function comment_form_build_preview($form, &$form_state) {\n $comment = comment_form_submit_build_comment($form, $form_state);\n $form_state['comment_preview'] = comment_preview($comment);\n $form_state['rebuild'] = TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-18d25bf394", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_install_tasks_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_install_tasks_alter(&$tasks, $install_state)` (modules/system/system.api.php): Alter the full list of installation tasks.", "context": "This hook is invoked on the install profile in install_tasks().\n\nParameters:\n- $tasks: An array of all available installation tasks, including those provided by Drupal core. You can modify this array to change or replace any part of the Drupal installation process that occurs after the installation profile is selected.\n- $install_state: An array of information about the current installation state.\n\nFile: modules/system/system.api.php", "response": "function hook_install_tasks_alter(&$tasks, $install_state) {\n // Replace the \"Choose language\" installation task provided by Drupal core\n // with a custom callback function defined by this installation profile.\n $tasks['install_select_locale']['function'] = 'myprofile_locale_selection';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-18d890c4e6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_tableselect_value/7.x", "instruction": "I need the code for `form_type_tableselect_value($element, $input = FALSE)` in Drupal 7 (includes/form.inc). It must do this: Determines the value for a tableselect form element.", "context": "Parameters:\n- $element: The form element whose value is being populated.\n- $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.\n\nReturns: The data that will appear in $form_state['values'] for this element, or nothing to use the default.\n\nFile: includes/form.inc", "response": "function form_type_tableselect_value($element, $input = FALSE) {\n // If $element['#multiple'] == FALSE, then radio buttons are displayed and\n // the default value handling is used.\n if (isset($element['#multiple']) && $element['#multiple']) {\n // Checkboxes are being displayed with the default value coming from the\n // keys of the #default_value property. This differs from the checkboxes\n // element which uses the array values.\n if ($input === FALSE) {\n $value = array();\n $element += array('#default_value' => array());\n foreach ($element['#default_value'] as $key => $flag) {\n if ($flag) {\n $value[$key] = $key;\n }\n }\n return $value;\n }\n else {\n return is_array($input) ? drupal_map_assoc($input) : array();\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-18db3e3441", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_form_user_profile_form_alter/7.x", "instruction": "Implement `contact_form_user_profile_form_alter(&$form, &$form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter().", "context": "Add the enable personal contact form to an individual user's account page.\n\nFile: modules/contact/contact.module", "response": "function contact_form_user_profile_form_alter(&$form, &$form_state) {\n if ($form['#user_category'] == 'account') {\n $account = $form['#user'];\n $form['contact'] = array(\n '#type' => 'fieldset',\n '#title' => t('Contact settings'),\n '#weight' => 5,\n '#collapsible' => TRUE,\n );\n $form['contact']['contact'] = array(\n '#type' => 'checkbox',\n '#title' => t('Personal contact form'),\n '#default_value' => !empty($account->data['contact']) ? $account->data['contact'] : FALSE,\n '#description' => t('Allow other users to contact you via a personal contact form which keeps your e-mail address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.', array('@url' => url(\"user/$account->uid/contact\"))),\n );\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-18ddab7b7d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_preprocess_block/7.x", "instruction": "In Drupal 7, write the function `system_preprocess_block(&$variables)` (file modules/system/system.module) so that it does the following: Implements hook_preprocess_block().", "context": "File: modules/system/system.module", "response": "function system_preprocess_block(&$variables) {\n // System menu blocks should get the same class as menu module blocks.\n if ($variables['block']->module == 'system' && in_array($variables['block']->delta, array_keys(menu_list_system_menus()))) {\n $variables['classes_array'][] = 'block-menu';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-18e27bc844", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_entity_info/7.x", "instruction": "In Drupal 7, write the function `comment_entity_info()` (file modules/comment/comment.module) so that it does the following: Implements hook_entity_info().", "context": "File: modules/comment/comment.module", "response": "function comment_entity_info() {\n $return = array(\n 'comment' => array(\n 'label' => t('Comment'),\n 'base table' => 'comment',\n 'uri callback' => 'comment_uri',\n 'fieldable' => TRUE,\n 'controller class' => 'CommentController',\n 'entity keys' => array(\n 'id' => 'cid',\n 'bundle' => 'node_type',\n 'label' => 'subject',\n 'language' => 'language',\n ),\n 'bundles' => array(),\n 'view modes' => array(\n 'full' => array(\n 'label' => t('Full comment'),\n 'custom settings' => FALSE,\n ),\n ),\n 'static cache' => FALSE,\n ),\n );\n\n foreach (node_type_get_names() as $type => $name) {\n $return['comment']['bundles']['comment_node_' . $type] = array(\n 'label' => t('@node_type comment', array('@node_type' => $name)),\n // Provide the node type/bundle name for other modules, so it does not\n // have to be extracted manually from the bundle name.\n 'node bundle' => $type,\n 'admin' => array(\n // Place the Field UI paths for comments one level below the\n // corresponding paths for nodes, so that they appear in the same set\n // of local tasks. Note that the paths use a different placeholder name\n // and thus a different menu loader callback, so that Field UI page\n // callbacks get a comment bundle name from the node type in the URL.\n // See comment_node_type_load() and comment_menu_alter().\n 'path' => 'admin/structure/types/manage/%comment_node_type/comment',\n 'bundle argument' => 4,\n 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type) . '/comment',\n 'access arguments' => array('administer content types'),\n ),\n );\n }\n\n return $return;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-18ff7ce2c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_format_form_validate/7.x", "instruction": "Implement `filter_admin_format_form_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for filter_admin_format_form().", "context": "File: modules/filter/filter.admin.inc", "response": "function filter_admin_format_form_validate($form, &$form_state) {\n $format_format = trim($form_state['values']['format']);\n $format_name = trim($form_state['values']['name']);\n\n // Ensure that the values to be saved later are exactly the ones validated.\n form_set_value($form['format'], $format_format, $form_state);\n form_set_value($form['name'], $format_name, $form_state);\n\n $result = db_query(\"SELECT format FROM {filter_format} WHERE name = :name AND format <> :format\", array(':name' => $format_name, ':format' => $format_format))->fetchField();\n if ($result) {\n form_set_error('name', t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19052011e1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_block_configure/7.x", "instruction": "Implement `book_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().", "context": "File: modules/book/book.module", "response": "function book_block_configure($delta = '') {\n $block = array();\n $options = array(\n 'all pages' => t('Show block on all pages'),\n 'book pages' => t('Show block only on book pages'),\n );\n $form['book_block_mode'] = array(\n '#type' => 'radios',\n '#title' => t('Book navigation block display'),\n '#options' => $options,\n '#default_value' => variable_get('book_block_mode', 'all pages'),\n '#description' => t(\"If Show block on all pages is selected, the block will contain the automatically generated menus for all of the site's books. If Show block only on book pages is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The Page specific visibility settings or other visibility settings can be used in addition to selectively display this block.\"),\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-19101bb763", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_theme_enable/7.x", "instruction": "Implement `system_theme_enable()` in PHP for Drupal 7. Required behavior: Menu callback; Enables a theme.", "context": "File: modules/system/system.admin.inc", "response": "function system_theme_enable() {\n if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'system-theme-operation-link')) {\n $theme = $_REQUEST['theme'];\n // Get current list of themes.\n $themes = list_themes();\n\n // Check if the specified theme is one recognized by the system.\n if (!empty($themes[$theme])) {\n theme_enable(array($theme));\n drupal_set_message(t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name'])));\n }\n else {\n drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');\n }\n drupal_goto('admin/appearance');\n }\n return MENU_ACCESS_DENIED;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1915008171", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_presave/7.x", "instruction": "In Drupal 7, write the function `field_attach_presave($entity_type, $entity)` (file modules/field/field.attach.inc) so that it does the following: Perform necessary operations just before fields data get saved.", "context": "We take no specific action here, we just give other modules the opportunity to act.\n\nParameters:\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entity: The entity with fields to process.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_presave($entity_type, $entity) {\n _field_invoke('presave', $entity_type, $entity);\n\n // Let other modules act on presaving the entity.\n module_invoke_all('field_attach_presave', $entity_type, $entity);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-193fc83197", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_strip_dangerous_protocols/7.x", "instruction": "I need the code for `drupal_strip_dangerous_protocols($uri)` in Drupal 7 (includes/common.inc). It must do this: Strips dangerous protocols (e.g. 'javascript:') from a URI.", "context": "This function must be called for all URIs within user-entered input prior to being output to an HTML attribute value. It is often called as part of check_url() or filter_xss(), but those functions return an HTML-encoded string, so this function can be called independently when the output needs to be a plain-text string for passing to t(), l(), drupal_attributes(), or another function that will call check_plain() separately.\n\nParameters:\n- $uri: A plain-text URI that might contain dangerous protocols.\n\nReturns: A plain-text URI stripped of dangerous protocols. As with all plain-text strings, this return value must not be output to an HTML page without check_plain() being called on it. However, it can be passed to functions expecting plain-text strings.\n\nFile: includes/common.inc", "response": "function drupal_strip_dangerous_protocols($uri) {\n static $allowed_protocols;\n\n if (!isset($allowed_protocols)) {\n $allowed_protocols = array_flip(variable_get('filter_allowed_protocols', array('ftp', 'http', 'https', 'irc', 'mailto', 'news', 'nntp', 'rtsp', 'sftp', 'ssh', 'tel', 'telnet', 'webcal')));\n }\n\n // Iteratively remove any invalid protocol found.\n do {\n $before = $uri;\n $colonpos = strpos($uri, ':');\n if ($colonpos > 0) {\n // We found a colon, possibly a protocol. Verify.\n $protocol = substr($uri, 0, $colonpos);\n // If a colon is preceded by a slash, question mark or hash, it cannot\n // possibly be part of the URL scheme. This must be a relative URL, which\n // inherits the (safe) protocol of the base document.\n if (preg_match('![/?#]!', $protocol)) {\n break;\n }\n // Check if this is a disallowed protocol. Per RFC2616, section 3.2.3\n // (URI Comparison) scheme comparison must be case-insensitive.\n if (!isset($allowed_protocols[strtolower($protocol)])) {\n $uri = substr($uri, $colonpos + 1);\n }\n }\n } while ($before != $uri);\n\n return $uri;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-194ec2e05d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_rename_bundle/7.x", "instruction": "Give me the example code for `hook_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new)` in Drupal 7. Hook description: Act on field_attach_rename_bundle().", "context": "This hook is invoked after the field module has performed the operation.\n\nSee field_attach_rename_bundle() for details and arguments.\n\nFile: modules/field/field.api.php", "response": "function hook_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {\n // Update the extra weights variable with new information.\n if ($bundle_old !== $bundle_new) {\n $extra_weights = variable_get('field_extra_weights', array());\n if (isset($info[$entity_type][$bundle_old])) {\n $extra_weights[$entity_type][$bundle_new] = $extra_weights[$entity_type][$bundle_old];\n unset($extra_weights[$entity_type][$bundle_old]);\n variable_set('field_extra_weights', $extra_weights);\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-19514bfa9a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_library_alter/7.x", "instruction": "I need the code for `locale_library_alter(&$libraries, $module)` in Drupal 7 (modules/locale/locale.module). It must do this: Implement hook_library_alter().", "context": "Provides the language support for the jQuery UI Date Picker.\n\nFile: modules/locale/locale.module", "response": "function locale_library_alter(&$libraries, $module) {\n if ($module == 'system' && isset($libraries['ui.datepicker'])) {\n global $language;\n // locale.datepicker.js should be added in the JS_LIBRARY group, so that\n // this attach behavior will execute early. JS_LIBRARY is the default for\n // hook_library_info_alter(), thus does not have to be specified explicitly.\n $datepicker = drupal_get_path('module', 'locale') . '/locale.datepicker.js';\n $libraries['ui.datepicker']['js'][$datepicker] = array();\n $libraries['ui.datepicker']['js'][] = array(\n 'data' => array(\n 'jquery' => array(\n 'ui' => array(\n 'datepicker' => array(\n 'isRTL' => $language->direction == LANGUAGE_RTL,\n 'firstDay' => variable_get('date_first_day', 0),\n ),\n ),\n ),\n ),\n 'type' => 'setting',\n );\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19546df251", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_storage_delete/7.x", "instruction": "I need the code for `field_sql_storage_field_storage_delete($entity_type, $entity, $fields)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_field_storage_delete().", "context": "This function deletes data for all fields for an entity from the database.\n\nFile: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function field_sql_storage_field_storage_delete($entity_type, $entity, $fields) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n foreach (field_info_instances($entity_type, $bundle) as $instance) {\n if (isset($fields[$instance['field_id']])) {\n $field = field_info_field_by_id($instance['field_id']);\n field_sql_storage_field_storage_purge($entity_type, $entity, $field, $instance);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1961450a13", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_category/7.x", "instruction": "In Drupal 7, write the function `aggregator_form_category($form, &$form_state, $edit = array('title' => '', 'description' => '', 'cid' => NULL))` (file modules/aggregator/aggregator.admin.inc) so that it does the following: Form constructor to add/edit/delete aggregator categories.", "context": "Parameters:\n- $edit: An associative array containing: - title: A string to use for the category title. - description: A string to use for the category description. - cid: The category ID.\n\nFile: modules/aggregator/aggregator.admin.inc", "response": "function aggregator_form_category($form, &$form_state, $edit = array('title' => '', 'description' => '', 'cid' => NULL)) {\n $form['title'] = array('#type' => 'textfield',\n '#title' => t('Title'),\n '#default_value' => $edit['title'],\n '#maxlength' => 64,\n '#required' => TRUE,\n );\n $form['description'] = array('#type' => 'textarea',\n '#title' => t('Description'),\n '#default_value' => $edit['description'],\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));\n if ($edit['cid']) {\n $form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));\n $form['cid'] = array('#type' => 'hidden', '#value' => $edit['cid']);\n }\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19725d8f21", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.multilingual.inc/function/_field_language_suggestion/7.x", "instruction": "I need the code for `_field_language_suggestion($available_languages, $language_suggestion, $field_name)` in Drupal 7 (modules/field/field.multilingual.inc). It must do this: Process the given language suggestion based on the available languages.", "context": "If a non-empty language suggestion is provided it must appear among the available languages, otherwise it will be ignored.\n\nParameters:\n- $available_languages: An array of valid language codes.\n- $language_suggestion: A language code or an array of language codes keyed by field name.\n- $field_name: The name of the field being processed.\n\nReturns: An array of valid language codes.\n\nFile: modules/field/field.multilingual.inc", "response": "function _field_language_suggestion($available_languages, $language_suggestion, $field_name) {\n // Handle possible language suggestions.\n if (!empty($language_suggestion)) {\n // We might have an array of language suggestions keyed by field name.\n if (is_array($language_suggestion) && isset($language_suggestion[$field_name])) {\n $language_suggestion = $language_suggestion[$field_name];\n }\n\n // If we have a language suggestion and the suggested language is available,\n // we return only it.\n if (in_array($language_suggestion, $available_languages)) {\n $available_languages = array($language_suggestion);\n }\n }\n\n return $available_languages;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1974f8d251", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_unpack/7.x", "instruction": "Implement `drupal_unpack($obj, $field = 'data')` in PHP for Drupal 7. Required behavior: Unserializes and appends elements from a serialized string.", "context": "Parameters:\n- $obj: The object to which the elements are appended.\n- $field: The attribute of $obj whose value should be unserialized.\n\nFile: includes/bootstrap.inc", "response": "function drupal_unpack($obj, $field = 'data') {\n if ($obj->$field && $data = unserialize($obj->$field)) {\n foreach ($data as $key => $value) {\n if (!empty($key) && !isset($obj->$key)) {\n $obj->$key = $value;\n }\n }\n }\n return $obj;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-197999f2a9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_remove/7.x", "instruction": "In Drupal 7, write the function `aggregator_remove($feed)` (file modules/aggregator/aggregator.module) so that it does the following: Removes all items from a feed.", "context": "Parameters:\n- $feed: An object describing the feed to be cleared.\n\nFile: modules/aggregator/aggregator.module", "response": "function aggregator_remove($feed) {\n _aggregator_get_variables();\n // Call hook_aggregator_remove() on all modules.\n module_invoke_all('aggregator_remove', $feed);\n // Reset feed.\n db_update('aggregator_feed')\n ->condition('fid', $feed->fid)\n ->fields(array(\n 'checked' => 0,\n 'hash' => '',\n 'etag' => '',\n 'modified' => 0,\n ))\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1980f72ad9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_clear_update_disk_cache/7.x", "instruction": "Implement `update_clear_update_disk_cache()` in PHP for Drupal 7. Required behavior: Clears the temporary files and directories based on file age from disk.", "context": "File: modules/update/update.module", "response": "function update_clear_update_disk_cache() {\n // List of update module cache directories. Do not create the directories if\n // they do not exist.\n $directories = array(\n _update_manager_cache_directory(FALSE),\n _update_manager_extract_directory(FALSE),\n );\n\n // Search for files and directories in base folder only without recursion.\n foreach ($directories as $directory) {\n file_scan_directory($directory, '/.*/', array('callback' => 'update_delete_file_if_stale', 'recurse' => FALSE));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-198c20c6bf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_block_view/7.x", "instruction": "In Drupal 7, write the function `forum_block_view($delta = '')` (file modules/forum/forum.module) so that it does the following: Implements hook_block_view().", "context": "Generates a block containing the currently active forum topics and the most recently added forum topics.\n\nFile: modules/forum/forum.module", "response": "function forum_block_view($delta = '') {\n $query = db_select('forum_index', 'f')\n ->fields('f')\n ->addTag('node_access');\n switch ($delta) {\n case 'active':\n $title = t('Active forum topics');\n $query\n ->orderBy('f.last_comment_timestamp', 'DESC')\n ->range(0, variable_get('forum_block_num_active', '5'));\n break;\n\n case 'new':\n $title = t('New forum topics');\n $query\n ->orderBy('f.created', 'DESC')\n ->range(0, variable_get('forum_block_num_new', '5'));\n break;\n }\n\n $block['subject'] = $title;\n // Cache based on the altered query. Enables us to cache with node access enabled.\n $block['content'] = drupal_render_cache_by_query($query, 'forum_block_view');\n $block['content']['#access'] = user_access('access content');\n return $block;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-198c7f9861", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/template_preprocess_profile_listing/7.x", "instruction": "Implement `template_preprocess_profile_listing(&$variables)` in PHP for Drupal 7. Required behavior: Process variables for profile-listing.tpl.php.", "context": "The $variables array contains the following arguments:\n- $account\n- $fields\n\nFile: modules/profile/profile.module", "response": "function template_preprocess_profile_listing(&$variables) {\n\n $variables['user_picture'] = theme('user_picture', array('account' => $variables['account']));\n $variables['name'] = theme('username', array('account' => $variables['account']));\n $variables['profile'] = array();\n // Supply filtered version of $fields that have values.\n foreach ($variables['fields'] as $field) {\n if ($field->value) {\n $variables['profile'][$field->name] = new stdClass();\n $variables['profile'][$field->name]->title = $field->title;\n $variables['profile'][$field->name]->value = $field->value;\n $variables['profile'][$field->name]->type = $field->type;\n }\n }\n\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19930b15ef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_get_options/7.x", "instruction": "Implement `form_get_options($element, $key)` in PHP for Drupal 7. Required behavior: Returns the indexes of a select element's options matching a given key.", "context": "This function is useful if you need to modify the options that are already in a form element; for example, to remove choices which are not valid because of additional filters imposed by another module. One example might be altering the choices in a taxonomy selector. To correctly handle the case of a multiple hierarchy taxonomy, #options arrays can now hold an array of objects, instead of a direct mapping of keys to labels, so that multiple choices in the selector can have the same key (and label). This makes it difficult to manipulate directly, which is why this helper function exists.\n\nThis function does not support optgroups (when the elements of the #options array are themselves arrays), and will return FALSE if arrays are found. The caller must either flatten/restore or manually do their manipulations in this case, since returning the index is not sufficient, and supporting this would make the \"helper\" too complicated and cumbersome to be of any help.\n\nAs usual with functions that can return array() or FALSE, do not forget to use === and !== if needed.\n\nParameters:\n- $element: The select element to search.\n- $key: The key to look for.\n\nReturns: An array of indexes that match the given $key. Array will be empty if no elements were found. FALSE if optgroups were found.\n\nFile: includes/form.inc", "response": "function form_get_options($element, $key) {\n $keys = array();\n foreach ($element['#options'] as $index => $choice) {\n if (is_array($choice)) {\n return FALSE;\n }\n elseif (is_object($choice)) {\n if (isset($choice->option[$key])) {\n $keys[] = $index;\n }\n }\n elseif ($index == $key) {\n $keys[] = $index;\n }\n }\n return $keys;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19956108bd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_toolbar_pre_render_alter/7.x", "instruction": "Implement `announcements_feed_toolbar_pre_render_alter($toolbar)` in PHP for Drupal 7. Required behavior: Pre-render function for adding default class to announcement link.", "context": "File: modules/announcements_feed/announcements_feed.module", "response": "function announcements_feed_toolbar_pre_render_alter($toolbar) {\n $path = drupal_get_path('module', 'announcements_feed');\n $toolbar['#attached']['css'][] = $path . '/announcements_feed-toolbar.css';\n module_load_include('inc', 'announcements_feed');\n foreach ($toolbar['toolbar_menu']['#links'] as &$link) {\n if ($link['href'] === 'admin/announcements_feed') {\n $link['attributes']['class'][] = 'announcement-default';\n }\n }\n\n return $toolbar;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19a1dc492d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/template_preprocess_node/7.x", "instruction": "Implement `template_preprocess_node(&$variables)` in PHP for Drupal 7. Required behavior: Processes variables for node.tpl.php", "context": "Most themes utilize their own copy of node.tpl.php. The default is located inside \"modules/node/node.tpl.php\". Look in there for the full list of variables.\n\nThe $variables array contains the following arguments:\n- $node\n- $view_mode\n- $page\n\nFile: modules/node/node.module", "response": "function template_preprocess_node(&$variables) {\n $variables['view_mode'] = $variables['elements']['#view_mode'];\n // Provide a distinct $teaser boolean.\n $variables['teaser'] = $variables['view_mode'] == 'teaser';\n $variables['node'] = $variables['elements']['#node'];\n $node = $variables['node'];\n\n $variables['date'] = format_date($node->created);\n $variables['name'] = theme('username', array('account' => $node));\n\n $uri = entity_uri('node', $node);\n $variables['node_url'] = url($uri['path'], $uri['options']);\n $variables['title'] = check_plain($node->title);\n $variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);\n\n // Flatten the node object's member fields.\n $variables = array_merge((array) $node, $variables);\n\n // Helpful $content variable for templates.\n $variables += array('content' => array());\n foreach (element_children($variables['elements']) as $key) {\n $variables['content'][$key] = $variables['elements'][$key];\n }\n\n // Make the field variables available with the appropriate language.\n field_attach_preprocess('node', $node, $variables['content'], $variables);\n\n // Display post information only on certain node types.\n if (variable_get('node_submitted_' . $node->type, TRUE)) {\n $variables['display_submitted'] = TRUE;\n $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));\n $variables['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : '';\n }\n else {\n $variables['display_submitted'] = FALSE;\n $variables['submitted'] = '';\n $variables['user_picture'] = '';\n }\n\n // Gather node classes.\n $variables['classes_array'][] = drupal_html_class('node-' . $node->type);\n if ($variables['promote']) {\n $variables['classes_array'][] = 'node-promoted';\n }\n if ($variables['sticky']) {\n $variables['classes_array'][] = 'node-sticky';\n }\n if (!$variables['status']) {\n $variables['classes_array'][] = 'node-unpublished';\n }\n if ($variables['teaser']) {\n $variables['classes_array'][] = 'node-teaser';\n }\n if (isset($variables['preview'])) {\n $variables['classes_array'][] = 'node-preview';\n }\n\n // Clean up name so there are no underscores.\n $variables['theme_hook_suggestions'][] = 'node__' . $node->type;\n $variables['theme_hook_suggestions'][] = 'node__' . $node->nid;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19b314ce93", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_fetch/7.x", "instruction": "Implement `announcements_feed_fetch($force = FALSE)` in PHP for Drupal 7. Required behavior: Fetches the feed either from a local cache or fresh remotely.", "context": "The feed follows the \"JSON Feed\" format:\n- https://www.jsonfeed.org/version/1.1/\n\nThe structure of an announcement item in the feed is:\n - id: Id.\n - title: Title of the announcement.\n - content_html: Announcement teaser.\n - url: URL\n - date_modified: Last updated timestamp.\n - date_published: Created timestamp.\n - _drupalorg.featured: 1 if featured, 0 if not featured.\n - _drupalorg.version: Target version of Drupal, as a Composer version.\n\nParameters:\n- $force (bool): (optional) Whether to always fetch new items or not. Defaults to FALSE.\n\nReturns (array): An array of announcements from the feed relevant to the Drupal version. The array is empty if there were no matching announcements. If an error occurred while fetching/decoding the feed, it is thrown as an exception.\n\nFile: modules/announcements_feed/announcements_feed.inc", "response": "function announcements_feed_fetch($force = FALSE) {\n $announcements = cache_get('announcements_feed');\n if ($force || empty($announcements)) {\n $announcements_feed_json_url = variable_get('announcements_feed_json_url', ANNOUNCEMENTS_FEED_DEFAULT_JSON_URL);\n $response = drupal_http_request($announcements_feed_json_url);\n if ($response->code == 200) {\n $feeds = json_decode($response->data, TRUE);\n if (!isset($feeds['items'])) {\n watchdog('announcements_feed', 'The feed format is not valid.', NULL, WATCHDOG_ERROR);\n throw new Exception('Announcements feed JSON format is invalid');\n }\n $announcements = array();\n if ($feeds['items']) {\n $announcements = $feeds['items'];\n }\n $announcements = array_filter($announcements, 'announcements_feed_filter_announcements');\n cache_set('announcements_feed', $announcements, 'cache', REQUEST_TIME + variable_get('announcements_feed_max_age', ANNOUNCEMENTS_FEED_DEFAULT_MAX_AGE));\n }\n else {\n watchdog(\n 'announcements_feed',\n 'The feed failed to fetch with an error code: @code, error message: @message.',\n array('@code' => $response->code, '@message' => $response->error),\n WATCHDOG_ERROR\n );\n throw new Exception($response->error, $response->code);\n }\n }\n else {\n $announcements = $announcements->data;\n }\n // The drupal.org endpoint is sorted by created date in descending order.\n // We will limit the announcements based on the configuration limit.\n $announcements_feed_limit = variable_get('announcements_feed_limit', ANNOUNCEMENTS_FEED_DEFAULT_LIMIT);\n $announcements = array_slice($announcements, 0, $announcements_feed_limit);\n // For the remaining announcements, put all the featured announcements\n // before the rest.\n uasort($announcements, 'announcements_feed_sort_featured');\n\n return $announcements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19c8f42cda", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_form_main/7.x", "instruction": "In Drupal 7, write the function `forum_form_main($type, $edit = array())` (file modules/forum/forum.admin.inc) so that it does the following: Page callback: Returns a form for creating a new forum or container.", "context": "Parameters:\n- $type: What is being added. Possible values are 'forum' and 'container'.\n- $edit: (optional) Associative array containing a forum term to be edited. Defaults to an empty array.\n\nReturns: A form for creating a new forum or container.\n\nFile: modules/forum/forum.admin.inc", "response": "function forum_form_main($type, $edit = array()) {\n $edit = (array) $edit;\n if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) {\n return drupal_get_form('forum_confirm_delete', $edit['tid']);\n }\n switch ($type) {\n case 'forum':\n return drupal_get_form('forum_form_forum', $edit);\n break;\n case 'container':\n return drupal_get_form('forum_form_container', $edit);\n break;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-19dabe34be", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_system_info_alter/7.x", "instruction": "In Drupal 7, write the function `dashboard_system_info_alter(&$info, $file, $type)` (file modules/dashboard/dashboard.module) so that it does the following: Implements hook_system_info_alter().", "context": "Add regions to each theme to store the dashboard blocks.\n\nFile: modules/dashboard/dashboard.module", "response": "function dashboard_system_info_alter(&$info, $file, $type) {\n if ($type == 'theme') {\n // Add the dashboard regions (the \"inactive\" region should always appear\n // last in the list, for usability reasons).\n $dashboard_regions = dashboard_region_descriptions();\n if (isset($dashboard_regions['dashboard_inactive'])) {\n $inactive_region = $dashboard_regions['dashboard_inactive'];\n unset($dashboard_regions['dashboard_inactive']);\n $dashboard_regions['dashboard_inactive'] = $inactive_region;\n }\n $info['regions'] += $dashboard_regions;\n // Indicate that these regions are intended to be displayed whenever the\n // dashboard is displayed in an overlay. This information is provided for\n // any module that might need to use it, not just the core Overlay module.\n $info['overlay_regions'] = !empty($info['overlay_regions']) ? array_merge($info['overlay_regions'], dashboard_regions()) : dashboard_regions();\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-19ebad5fe1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpcs.inc/function/xmlrpc_server_call/7.x", "instruction": "In Drupal 7, write the function `xmlrpc_server_call($xmlrpc_server, $methodname, $args)` (file includes/xmlrpcs.inc) so that it does the following: Dispatches an XML-RPC request and any parameters to the appropriate handler.", "context": "Parameters:\n- $xmlrpc_server (object): Object containing information about this XML-RPC server, the methods it provides, their signatures, etc.\n- $methodname (string): The external XML-RPC method name; e.g., 'system.methodHelp'.\n- $args (array): Array containing any parameters that are to be sent along with the request.\n\nReturns: The results of the call.\n\nFile: includes/xmlrpcs.inc", "response": "function xmlrpc_server_call($xmlrpc_server, $methodname, $args) {\n // Make sure parameters are in an array\n if ($args && !is_array($args)) {\n $args = array($args);\n }\n // Has this method been mapped to a Drupal function by us or by modules?\n if (!isset($xmlrpc_server->callbacks[$methodname])) {\n return xmlrpc_error(-32601, t('Server error. Requested method @methodname not specified.', array(\"@methodname\" => $xmlrpc_server->message->methodname)));\n }\n $method = $xmlrpc_server->callbacks[$methodname];\n $signature = $xmlrpc_server->signatures[$methodname];\n\n // If the method has a signature, validate the request against the signature\n if (is_array($signature)) {\n $ok = TRUE;\n $return_type = array_shift($signature);\n // Check the number of arguments\n if (count($args) != count($signature)) {\n return xmlrpc_error(-32602, t('Server error. Wrong number of method parameters.'));\n }\n // Check the argument types\n foreach ($signature as $key => $type) {\n $arg = $args[$key];\n switch ($type) {\n case 'int':\n case 'i4':\n if (is_array($arg) || !is_int($arg)) {\n $ok = FALSE;\n }\n break;\n\n case 'base64':\n case 'string':\n if (!is_string($arg)) {\n $ok = FALSE;\n }\n break;\n\n case 'boolean':\n if ($arg !== FALSE && $arg !== TRUE) {\n $ok = FALSE;\n }\n break;\n\n case 'float':\n case 'double':\n if (!is_float($arg)) {\n $ok = FALSE;\n }\n break;\n\n case 'date':\n case 'dateTime.iso8601':\n if (!$arg->is_date) {\n $ok = FALSE;\n }\n break;\n }\n if (!$ok) {\n return xmlrpc_error(-32602, t('Server error. Invalid method parameters.'));\n }\n }\n }\n\n if (!function_exists($method)) {\n return xmlrpc_error(-32601, t('Server error. Requested function @method does not exist.', array(\"@method\" => $method)));\n }\n // Call the mapped function\n return call_user_func_array($method, $args);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a067026fd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.install/function/list_update_7001/7.x", "instruction": "Implement `list_update_7001()` in PHP for Drupal 7. Required behavior: Rename the list field types and change 'allowed_values' format.", "context": "File: modules/field/modules/list/list.install", "response": "function list_update_7001() {\n $fields = _update_7000_field_read_fields(array('module' => 'list'));\n foreach ($fields as $field) {\n $update = array();\n\n // Translate the old string format into the new array format.\n $allowed_values = $field['settings']['allowed_values'];\n if (is_string($allowed_values)) {\n $position_keys = ($field['type'] == 'list');\n $allowed_values = _list_update_7001_extract_allowed_values($allowed_values, $position_keys);\n\n // Additionally, float keys need to be disambiguated ('.5' is '0.5').\n if ($field['type'] == 'list_number' && !empty($allowed_values)) {\n $keys = array_map('_list_update_7001_float_string_cast', array_keys($allowed_values));\n $allowed_values = array_combine($keys, array_values($allowed_values));\n }\n\n // Place the new setting in the existing serialized 'data' column.\n $data = db_query(\"SELECT data FROM {field_config} WHERE id = :id\", array(':id' => $field['id']))->fetchField();\n $data = unserialize($data);\n $data['settings']['allowed_values'] = $allowed_values;\n $update['data'] = serialize($data);\n }\n\n // Rename field types.\n $types = array('list' => 'list_integer', 'list_number' => 'list_float');\n if (isset($types[$field['type']])) {\n $update['type'] = $types[$field['type']];\n }\n\n // Save the new data.\n if ($update) {\n $query = db_update('field_config')\n ->condition('id', $field['id'])\n ->fields($update)\n ->execute();\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a187f7eda", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_delete/7.x", "instruction": "Implement `file_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items)` in PHP for Drupal 7. Required behavior: Implements hook_field_delete().", "context": "File: modules/file/file.field.inc", "response": "function file_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n // Delete all file usages within this entity.\n foreach ($items as $delta => $item) {\n file_field_delete_file($item, $field, $entity_type, $id, 0);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a2747dec5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_get_projects/7.x", "instruction": "I need the code for `update_get_projects()` in Drupal 7 (modules/update/update.compare.inc). It must do this: Fetches an array of installed and enabled projects.", "context": "This is only responsible for generating an array of projects (taking into account projects that include more than one module or theme). Other information like the specific version and install type (official release, dev snapshot, etc) is handled later in update_process_project_info() since that logic is only required when preparing the status report, not for fetching the available release data.\n\nThis array is fairly expensive to construct, since it involves a lot of disk I/O, so we cache the results into the {cache_update} table using the 'update_project_projects' cache ID. However, since this is not the data about available updates fetched from the network, it is acceptable to invalidate it somewhat quickly. If we keep this data for very long, site administrators are more likely to see incorrect results if they upgrade to a newer version of a module or theme but do not visit certain pages that automatically clear this cache.\n\nReturns: An associative array of currently enabled projects keyed by the machine-readable project short name. Each project contains: - name: The machine-readable project short name. - info: An array with values from the main .info file for this project. - name: The human-readable name of the project. - package: The package that the project is grouped under. - version: The version of the project. - project: The Drupal.org project name. - datestamp: The date stamp of the project's main .info file. - _info_file_ctime: The maximum file change time for all of the .info files included in this project. - datestamp: The date stamp when the project was released, if known. - includes: An associative array containing all projects included with this project, keyed by the machine-readable short name with the human-readable name as value. - project_type: The type of project. Allowed values are 'module' and 'theme'. - project_status: This indicates if the project is enabled and will always be TRUE, as the function only returns enabled projects. - sub_themes: If the project is a theme it contains an associative array of all sub-themes. - base_themes: If the project is a theme it contains an associative array of all base-themes.\n\nFile: modules/update/update.compare.inc", "response": "function update_get_projects() {\n $projects = &drupal_static(__FUNCTION__, array());\n if (empty($projects)) {\n // Retrieve the projects from cache, if present.\n $projects = update_project_cache('update_project_projects');\n if (empty($projects)) {\n // Still empty, so we have to rebuild the cache.\n $module_data = system_rebuild_module_data();\n $theme_data = system_rebuild_theme_data();\n _update_process_info_list($projects, $module_data, 'module', TRUE);\n _update_process_info_list($projects, $theme_data, 'theme', TRUE);\n if (variable_get('update_check_disabled', FALSE)) {\n _update_process_info_list($projects, $module_data, 'module', FALSE);\n _update_process_info_list($projects, $theme_data, 'theme', FALSE);\n }\n // Allow other modules to alter projects before fetching and comparing.\n drupal_alter('update_projects', $projects);\n // Cache the site's project data for at most 1 hour.\n _update_cache_set('update_project_projects', $projects, REQUEST_TIME + 3600);\n }\n }\n return $projects;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a28d5d36f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/simpletest_test_form/7.x", "instruction": "I need the code for `simpletest_test_form($form)` in Drupal 7 (modules/simpletest/simpletest.pages.inc). It must do this: List tests arranged in groups that can be selected and run.", "context": "File: modules/simpletest/simpletest.pages.inc", "response": "function simpletest_test_form($form) {\n $form['tests'] = array(\n '#type' => 'fieldset',\n '#title' => t('Tests'),\n '#description' => t('Select the test(s) or test group(s) you would like to run, and click Run tests.'),\n );\n\n $form['tests']['table'] = array(\n '#theme' => 'simpletest_test_table',\n );\n\n // Generate the list of tests arranged by group.\n $groups = simpletest_test_get_all();\n foreach ($groups as $group => $tests) {\n $form['tests']['table'][$group] = array(\n '#collapsed' => TRUE,\n );\n\n foreach ($tests as $class => $info) {\n $form['tests']['table'][$group][$class] = array(\n '#type' => 'checkbox',\n '#title' => $info['name'],\n '#description' => $info['description'],\n );\n }\n }\n\n // Operation buttons.\n $form['tests']['op'] = array(\n '#type' => 'submit',\n '#value' => t('Run tests'),\n );\n $form['clean'] = array(\n '#type' => 'fieldset',\n '#collapsible' => FALSE,\n '#collapsed' => FALSE,\n '#title' => t('Clean test environment'),\n '#description' => t('Remove tables with the prefix \"simpletest\" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),\n );\n $form['clean']['op'] = array(\n '#type' => 'submit',\n '#value' => t('Clean environment'),\n '#submit' => array('simpletest_clean_environment'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a4b290ef8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_switcher_session/7.x", "instruction": "Implement `locale_language_switcher_session($type, $path)` in PHP for Drupal 7. Required behavior: Return the session language switcher block.", "context": "File: includes/locale.inc", "response": "function locale_language_switcher_session($type, $path) {\n drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');\n\n $param = variable_get('locale_language_negotiation_session_param', 'language');\n $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $GLOBALS[$type]->language;\n\n $languages = language_list('enabled');\n $links = array();\n\n $query = $_GET;\n unset($query['q']);\n\n foreach ($languages[1] as $language) {\n $langcode = $language->language;\n $links[$langcode] = array(\n 'href' => $path,\n 'title' => $language->native,\n 'attributes' => array('class' => array('language-link')),\n 'query' => $query,\n );\n if ($language_query != $langcode) {\n $links[$langcode]['query'][$param] = $langcode;\n }\n else {\n $links[$langcode]['attributes']['class'][] = 'session-active';\n }\n }\n\n return $links;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a5a077636", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_insert/7.x", "instruction": "Implement `poll_insert($node)` in PHP for Drupal 7. Required behavior: Implements hook_insert().", "context": "File: modules/poll/poll.module", "response": "function poll_insert($node) {\n if (!user_access('administer nodes')) {\n // Make sure all votes are 0 initially\n foreach ($node->choice as $i => $choice) {\n $node->choice[$i]['chvotes'] = 0;\n }\n $node->active = 1;\n }\n\n db_insert('poll')\n ->fields(array(\n 'nid' => $node->nid,\n 'runtime' => $node->runtime,\n 'active' => $node->active,\n ))\n ->execute();\n\n foreach ($node->choice as $choice) {\n if ($choice['chtext'] != '') {\n db_insert('poll_choice')\n ->fields(array(\n 'nid' => $node->nid,\n 'chtext' => $choice['chtext'],\n 'chvotes' => $choice['chvotes'],\n 'weight' => $choice['weight'],\n ))\n ->execute();\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a717d726a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_http_build_query/7.x", "instruction": "In Drupal 7, write the function `drupal_http_build_query(array $query, $parent = '')` (file includes/common.inc) so that it does the following: Parses an array into a valid, rawurlencoded query string.", "context": "This differs from http_build_query() as we need to rawurlencode() (instead of urlencode()) all query parameters.\n\nParameters:\n- $query: The query parameter array to be processed, e.g. $_GET.\n- $parent: Internal use only. Used to build the $query array key for nested items.\n\nReturns: A rawurlencoded string which can be used as or appended to the URL query string.\n\nFile: includes/common.inc", "response": "function drupal_http_build_query(array $query, $parent = '') {\n $params = array();\n\n foreach ($query as $key => $value) {\n $key = $parent ? $parent . rawurlencode('[' . $key . ']') : rawurlencode($key);\n\n // Recurse into children.\n if (is_array($value)) {\n $params[] = drupal_http_build_query($value, $key);\n }\n // If a query parameter value is NULL, only append its key.\n elseif (!isset($value)) {\n $params[] = $key;\n }\n else {\n // For better readability of paths in query strings, we decode slashes.\n $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value));\n }\n }\n\n return implode('&', $params);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a756c8b34", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/theme_filter_admin_overview/7.x", "instruction": "Implement `theme_filter_admin_overview($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the text format administration overview form.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/filter/filter.admin.inc", "response": "function theme_filter_admin_overview($variables) {\n $form = $variables['form'];\n\n $rows = array();\n foreach (element_children($form['formats']) as $id) {\n $form['formats'][$id]['weight']['#attributes']['class'] = array('text-format-order-weight');\n $rows[] = array(\n 'data' => array(\n drupal_render($form['formats'][$id]['name']),\n drupal_render($form['formats'][$id]['roles']),\n drupal_render($form['formats'][$id]['weight']),\n drupal_render($form['formats'][$id]['configure']),\n drupal_render($form['formats'][$id]['disable']),\n ),\n 'class' => array('draggable'),\n );\n }\n $header = array(t('Name'), t('Roles'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));\n $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'text-format-order')));\n $output .= drupal_render_children($form);\n\n drupal_add_tabledrag('text-format-order', 'order', 'sibling', 'text-format-order-weight');\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a89c84ada", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_preprocess_block/7.x", "instruction": "I need the code for `garland_preprocess_block(&$variables)` in Drupal 7 (themes/garland/template.php). It must do this: Override or insert variables into the block template.", "context": "File: themes/garland/template.php", "response": "function garland_preprocess_block(&$variables) {\n $variables['title_attributes_array']['class'][] = 'title';\n $variables['classes_array'][] = 'clearfix';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1a97d75113", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/theme_overlay_disable_message/7.x", "instruction": "Implement `theme_overlay_disable_message($variables)` in PHP for Drupal 7. Required behavior: Returns the HTML for the message about how to disable the overlay.", "context": "Parameters:\n- $variables: An associative array with an 'element' element, which itself is an associative array containing: - profile_link: The link to this user's account. - dismiss_message_link: The link to dismiss the overlay.\n\nFile: modules/overlay/overlay.module", "response": "function theme_overlay_disable_message($variables) {\n $element = $variables['element'];\n\n // Add CSS classes to hide the links from most sighted users, while keeping\n // them accessible to screen-reader users and keyboard-only users. To assist\n // screen-reader users, this message appears in both the parent and child\n // documents, but only the one in the child document is part of the tab order.\n foreach (array('profile_link', 'dismiss_message_link') as $key) {\n $element[$key]['#options']['attributes']['class'][] = 'element-invisible';\n if (overlay_get_mode() == 'child') {\n $element[$key]['#options']['attributes']['class'][] = 'element-focusable';\n }\n }\n\n // Render the links.\n $output = drupal_render($element['profile_link']) . ' ' . drupal_render($element['dismiss_message_link']);\n\n // Add a heading for screen-reader users. The heading doesn't need to be seen\n // by sighted users.\n $output = '

            ' . t('Options for the administrative overlay') . '

            ' . $output;\n\n // Wrap in a container for styling.\n $output = '
            ' . $output . '
            ';\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1aa3559eea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_custom_theme/7.x", "instruction": "In Drupal 7, write the function `system_custom_theme()` (file modules/system/system.module) so that it does the following: Implements hook_custom_theme().", "context": "File: modules/system/system.module", "response": "function system_custom_theme() {\n if (user_access('view the administration theme') && path_is_admin(current_path())) {\n return variable_get('admin_theme');\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ab6665f94", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_access_view_all_nodes/7.x", "instruction": "In Drupal 7, write the function `node_access_view_all_nodes($account = NULL)` (file modules/node/node.module) so that it does the following: Determines whether the user has a global viewing grant for all nodes.", "context": "Checks to see whether any module grants global 'view' access to a user account; global 'view' access is encoded in the {node_access} table as a grant with nid=0. If no node access modules are enabled, node.module defines such a global 'view' access grant.\n\nThis function is called when a node listing query is tagged with 'node_access'; when this function returns TRUE, no node access joins are added to the query.\n\nParameters:\n- $account: The user object for the user whose access is being checked. If omitted, the current user is used.\n\nReturns: TRUE if 'view' access to all nodes is granted, FALSE otherwise.\n\nFile: modules/node/node.module", "response": "function node_access_view_all_nodes($account = NULL) {\n global $user;\n if (!$account) {\n $account = $user;\n }\n\n // Statically cache results in an array keyed by $account->uid.\n $access = &drupal_static(__FUNCTION__);\n if (isset($access[$account->uid])) {\n return $access[$account->uid];\n }\n\n // If no modules implement the node access system, access is always TRUE.\n if (!module_implements('node_grants')) {\n $access[$account->uid] = TRUE;\n }\n else {\n $query = db_select('node_access');\n $query->addExpression('COUNT(*)');\n $query\n ->condition('nid', 0)\n ->condition('grant_view', 1, '>=');\n\n $grants = node_add_node_grants_to_query(node_access_grants('view', $account));\n\n if (count($grants) > 0 ) {\n $query->condition($grants);\n }\n $access[$account->uid] = $query\n ->execute()\n ->fetchField();\n }\n\n return $access[$account->uid];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1abbcfce3b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.admin.inc/function/statistics_top_visitors/7.x", "instruction": "Implement `statistics_top_visitors()` in PHP for Drupal 7. Required behavior: Page callback: Displays the \"top visitors\" page.", "context": "This displays the pages with the top number of visitors in a given time interval that haven't been flushed yet. The flush interval is set on the statistics settings form, but is dependent on cron running.\n\nReturns: A render array containing the top visitors information.\n\nFile: modules/statistics/statistics.admin.inc", "response": "function statistics_top_visitors() {\n\n $header = array(\n array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),\n array('data' => t('Visitor'), 'field' => 'u.name'),\n array('data' => t('Total page generation time'), 'field' => 'total'),\n array('data' => user_access('block IP addresses') ? t('Operations') : '', 'colspan' => 2),\n );\n $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');\n $query->leftJoin('blocked_ips', 'bl', 'a.hostname = bl.ip');\n $query->leftJoin('users', 'u', 'a.uid = u.uid');\n\n $query->addExpression('COUNT(a.uid)', 'hits');\n $query->addExpression('SUM(a.timer)', 'total');\n $query\n ->fields('a', array('uid', 'hostname'))\n ->fields('u', array('name'))\n ->fields('bl', array('iid'))\n ->groupBy('a.hostname')\n ->groupBy('a.uid')\n ->groupBy('u.name')\n ->groupBy('bl.iid')\n ->limit(30)\n ->orderByHeader($header)\n ->orderBy('a.hostname');\n\n $uniques_query = db_select('accesslog')->distinct();\n $uniques_query->fields('accesslog', array('uid', 'hostname'));\n $count_query = db_select($uniques_query);\n $count_query->addExpression('COUNT(*)');\n $query->setCountQuery($count_query);\n\n $result = $query->execute();\n $rows = array();\n $destination = drupal_get_destination();\n foreach ($result as $account) {\n $ban_link = $account->iid ? l(t('unblock IP address'), \"admin/config/people/ip-blocking/delete/$account->iid\", array('query' => $destination)) : l(t('block IP address'), \"admin/config/people/ip-blocking/$account->hostname\", array('query' => $destination));\n $rows[] = array($account->hits, ($account->uid ? theme('username', array('account' => $account)) : $account->hostname), format_interval(round($account->total / 1000)), (user_access('block IP addresses') && !$account->uid) ? $ban_link : '');\n }\n\n drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH);\n $build['statistics_top_visitors_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#empty' => t('No statistics available.'),\n );\n $build['statistics_top_visitors_pager'] = array('#theme' => 'pager');\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1abde71718", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_icon_path/7.x", "instruction": "Implement `file_icon_path($file, $icon_directory = NULL)` in PHP for Drupal 7. Required behavior: Creates a path to the icon for a file object.", "context": "Parameters:\n- $file: A file object.\n- $icon_directory: (optional) A path to a directory of icons to be used for files. Defaults to the value of the \"file_icon_directory\" variable.\n\nReturns: A string to the icon as a local path, or FALSE if an appropriate icon could not be found.\n\nFile: modules/file/file.module", "response": "function file_icon_path($file, $icon_directory = NULL) {\n // Use the default set of icons if none specified.\n if (!isset($icon_directory)) {\n $icon_directory = variable_get('file_icon_directory', drupal_get_path('module', 'file') . '/icons');\n }\n\n // If there's an icon matching the exact mimetype, go for it.\n $dashed_mime = strtr($file->filemime, array('/' => '-'));\n $icon_path = $icon_directory . '/' . $dashed_mime . '.png';\n if (file_exists($icon_path)) {\n return $icon_path;\n }\n\n // For a few mimetypes, we can \"manually\" map to a generic icon.\n $generic_mime = (string) file_icon_map($file);\n $icon_path = $icon_directory . '/' . $generic_mime . '.png';\n if ($generic_mime && file_exists($icon_path)) {\n return $icon_path;\n }\n\n // Use generic icons for each category that provides such icons.\n foreach (array('audio', 'image', 'text', 'video') as $category) {\n if (strpos($file->filemime, $category . '/') === 0) {\n $icon_path = $icon_directory . '/' . $category . '-x-generic.png';\n if (file_exists($icon_path)) {\n return $icon_path;\n }\n }\n }\n\n // Try application-octet-stream as last fallback.\n $icon_path = $icon_directory . '/application-octet-stream.png';\n if (file_exists($icon_path)) {\n return $icon_path;\n }\n\n // No icon can be found.\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ac53d6751", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_access/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_access($op, $field, $entity_type, $entity, $account)` (modules/field/field.api.php): Determine whether the user has access to a given field.", "context": "This hook is invoked from field_access() to let modules block access to operations on fields. If no module returns FALSE, the operation is allowed.\n\nParameters:\n- $op: The operation to be performed. Possible values: 'edit', 'view'.\n- $field: The field on which the operation is to be performed.\n- $entity_type: The type of $entity; for example, 'node' or 'user'.\n- $entity: (optional) The entity for the operation.\n- $account: (optional) The account to check; if not given use currently logged in user.\n\nReturns: TRUE if the operation is allowed, and FALSE if the operation is denied.\n\nFile: modules/field/field.api.php", "response": "function hook_field_access($op, $field, $entity_type, $entity, $account) {\n if ($field['field_name'] == 'field_of_interest' && $op == 'edit') {\n return user_access('edit field of interest', $account);\n }\n return TRUE;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ad889a590", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_search_preprocess/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_search_preprocess($text)` (modules/search/search.api.php): Preprocess text for search.", "context": "This hook is called to preprocess both the text added to the search index and the keywords users have submitted for searching.\n\nPossible uses:\n- Adding spaces between words of Chinese or Japanese text.\n- Stemming words down to their root words to allow matches between, for\n instance, walk, walked, walking, and walks in searching.\n- Expanding abbreviations and acronymns that occur in text.\n\nParameters:\n- $text: The text to preprocess. This is a single piece of plain text extracted from between two HTML tags or from the search query. It will not contain any HTML entities or HTML tags.\n\nReturns: The text after preprocessing. Note that if your module decides not to alter the text, it should return the original text. Also, after preprocessing, words in the text should be separated by a space.\n\nFile: modules/search/search.api.php", "response": "function hook_search_preprocess($text) {\n // Do processing on $text\n return $text;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ad924f2bf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_state_defaults/7.x", "instruction": "I need the code for `install_state_defaults()` in Drupal 7 (includes/install.core.inc). It must do this: Returns an array of default settings for the global installation state.", "context": "The installation state is initialized with these settings at the beginning of each page request. They may evolve during the page request, but they are initialized again once the next request begins.\n\nNon-interactive Drupal installations can override some of these default settings by passing in an array to the installation script, most notably 'parameters' (which contains one-time parameters such as 'profile' and 'locale' that are normally passed in via the URL) and 'forms' (which can be used to programmatically submit forms during the installation; the keys of each element indicate the name of the installation task that the form submission is for, and the values are used as the $form_state['values'] array that is passed on to the form submission via drupal_form_submit()).\n\nFile: includes/install.core.inc", "response": "function install_state_defaults() {\n $defaults = array(\n // The current task being processed.\n 'active_task' => NULL,\n // The last task that was completed during the previous installation\n // request.\n 'completed_task' => NULL,\n // This becomes TRUE only when Drupal's system module is installed.\n 'database_tables_exist' => FALSE,\n // An array of forms to be programmatically submitted during the\n // installation. The keys of each element indicate the name of the\n // installation task that the form submission is for, and the values are\n // used as the $form_state['values'] array that is passed on to the form\n // submission via drupal_form_submit().\n 'forms' => array(),\n // This becomes TRUE only at the end of the installation process, after\n // all available tasks have been completed and Drupal is fully installed.\n // It is used by the installer to store correct information in the database\n // about the completed installation, as well as to inform theme functions\n // that all tasks are finished (so that the task list can be displayed\n // correctly).\n 'installation_finished' => FALSE,\n // Whether or not this installation is interactive. By default this will\n // be set to FALSE if settings are passed in to install_drupal().\n 'interactive' => TRUE,\n // An array of available languages for the installation.\n 'locales' => array(),\n // An array of parameters for the installation, pre-populated by the URL\n // or by the settings passed in to install_drupal(). This is primarily\n // used to store 'profile' (the name of the chosen installation profile)\n // and 'locale' (the name of the chosen installation language), since\n // these settings need to persist from page request to page request before\n // the database is available for storage.\n 'parameters' => array(),\n // Whether or not the parameters have changed during the current page\n // request. For interactive installations, this will trigger a page\n // redirect.\n 'parameters_changed' => FALSE,\n // An array of information about the chosen installation profile. This will\n // be filled in based on the profile's .info file.\n 'profile_info' => array(),\n // An array of available installation profiles.\n 'profiles' => array(),\n // An array of server variables that will be substituted into the global\n // $_SERVER array via drupal_override_server_variables(). Used by\n // non-interactive installations only.\n 'server' => array(),\n // This becomes TRUE only when a valid database connection can be\n // established.\n 'settings_verified' => FALSE,\n // Installation tasks can set this to TRUE to force the page request to\n // end (even if there is no themable output), in the case of an interactive\n // installation. This is needed only rarely; for example, it would be used\n // by an installation task that prints JSON output rather than returning a\n // themed page. The most common example of this is during batch processing,\n // but the Drupal installer automatically takes care of setting this\n // parameter properly in that case, so that individual installation tasks\n // which implement the batch API do not need to set it themselves.\n 'stop_page_request' => FALSE,\n // Installation tasks can set this to TRUE to indicate that the task should\n // be run again, even if it normally wouldn't be. This can be used, for\n // example, if a single task needs to be spread out over multiple page\n // requests, or if it needs to perform some validation before allowing\n // itself to be marked complete. The most common examples of this are batch\n // processing and form submissions, but the Drupal installer automatically\n // takes care of setting this parameter properly in those cases, so that\n // individual installation tasks which implement the batch API or form API\n // do not need to set it themselves.\n 'task_not_complete' => FALSE,\n // A list of installation tasks which have already been performed during\n // the current page request.\n 'tasks_performed' => array(),\n );\n return $defaults;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b01f163b7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_boot/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_boot()` (modules/system/system.api.php): Perform setup tasks for all page requests.", "context": "This hook is run at the beginning of the page request. It is typically used to set up global parameters that are needed later in the request.\n\nOnly use this hook if your code must run even for cached page views. This hook is called before the theme, modules, or most include files are loaded into memory. It happens while Drupal is still in bootstrap mode.\n\nFile: modules/system/system.api.php", "response": "function hook_boot() {\n // We need user_access() in the shutdown function. Make sure it gets loaded.\n drupal_load('module', 'user');\n drupal_register_shutdown_function('devel_shutdown');\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b15b16631", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contextual%21contextual.module/function/contextual_permission/7.x", "instruction": "Implement `contextual_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/contextual/contextual.module", "response": "function contextual_permission() {\n return array(\n 'access contextual links' => array(\n 'title' => t('Use contextual links'),\n 'description' => t('Use contextual links to perform actions related to elements on a page.'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b1972dcb4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_library/7.x", "instruction": "In Drupal 7, write the function `drupal_get_library($module, $name = NULL)` (file includes/common.inc) so that it does the following: Retrieves information for a JavaScript/CSS library.", "context": "Library information is statically cached. Libraries are keyed by module for\nseveral reasons:\n- Libraries are not unique. Multiple modules might ship with the same library\n in a different version or variant. This registry cannot (and does not\n attempt to) prevent library conflicts.\n- Modules implementing and thereby depending on a library that is registered\n by another module can only rely on that module's library.\n- Two (or more) modules can still register the same library and use it\n without conflicts in case the libraries are loaded on certain pages only.\n\nParameters:\n- $module: The name of a module that registered a library.\n- $name: (optional) The name of a registered library to retrieve. By default, all libraries registered by $module are returned.\n\nReturns: The definition of the requested library, if $name was passed and it exists, or FALSE if it does not exist. If no $name was passed, an associative array of libraries registered by $module is returned (which may be empty).\n\nFile: includes/common.inc", "response": "function drupal_get_library($module, $name = NULL) {\n $libraries = &drupal_static(__FUNCTION__, array());\n\n if (!isset($libraries[$module])) {\n // Retrieve all libraries associated with the module.\n $module_libraries = module_invoke($module, 'library');\n if (empty($module_libraries)) {\n $module_libraries = array();\n }\n // Allow modules to alter the module's registered libraries.\n drupal_alter('library', $module_libraries, $module);\n\n foreach ($module_libraries as $key => $data) {\n if (is_array($data)) {\n // Add default elements to allow for easier processing.\n $module_libraries[$key] += array('dependencies' => array(), 'js' => array(), 'css' => array());\n foreach ($module_libraries[$key]['js'] as $file => $options) {\n $module_libraries[$key]['js'][$file]['version'] = $module_libraries[$key]['version'];\n }\n }\n }\n $libraries[$module] = $module_libraries;\n }\n if (isset($name)) {\n if (!isset($libraries[$module][$name])) {\n $libraries[$module][$name] = FALSE;\n }\n return $libraries[$module][$name];\n }\n return $libraries[$module];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b3aeef176", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_permissions_submit/7.x", "instruction": "In Drupal 7, write the function `user_admin_permissions_submit($form, &$form_state)` (file modules/user/user.admin.inc) so that it does the following: Save permissions selected on the administer permissions page.", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_permissions_submit($form, &$form_state) {\n foreach ($form_state['values']['role_names'] as $rid => $name) {\n user_role_change_permissions($rid, $form_state['values'][$rid]);\n }\n\n drupal_set_message(t('The changes have been saved.'));\n\n // Clear the cached pages and blocks.\n cache_clear_all();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b59703342", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_widget_info/7.x", "instruction": "Give me the example code for `hook_field_widget_info()` in Drupal 7. Hook description: Expose Field API widget types.", "context": "Returns: An array describing the widget types implemented by the module. The keys are widget type names. To avoid name clashes, widget type names should be prefixed with the name of the module that exposes them. The values are arrays describing the widget type, with the following key/value pairs: - label: The human-readable name of the widget type. - description: A short description for the widget type. - field types: An array of field types the widget supports. - settings: An array whose keys are the names of the settings available for the widget type, and whose values are the default values for those settings. - behaviors: (optional) An array describing behaviors of the widget, with the following elements: - multiple values: One of the following constants: - FIELD_BEHAVIOR_DEFAULT: (default) If the widget allows the input of one single field value (most common case). The widget will be repeated for each value input. - FIELD_BEHAVIOR_CUSTOM: If one single copy of the widget can receive several field values. Examples: checkboxes, multiple select, comma-separated textfield. - default value: One of the following constants: - FIELD_BEHAVIOR_DEFAULT: (default) If the widget accepts default values. - FIELD_BEHAVIOR_NONE: if the widget does not support default values. - weight: (optional) An integer to determine the weight of this widget relative to other widgets in the Field UI when selecting a widget for a given field instance.\n\nFile: modules/field/field.api.php", "response": "function hook_field_widget_info() {\n return array(\n 'text_textfield' => array(\n 'label' => t('Text field'),\n 'field types' => array('text'),\n 'settings' => array('size' => 60),\n 'behaviors' => array(\n 'multiple values' => FIELD_BEHAVIOR_DEFAULT,\n 'default value' => FIELD_BEHAVIOR_DEFAULT,\n ),\n ),\n 'text_textarea' => array(\n 'label' => t('Text area (multiple rows)'),\n 'field types' => array('text_long'),\n 'settings' => array('rows' => 5),\n 'behaviors' => array(\n 'multiple values' => FIELD_BEHAVIOR_DEFAULT,\n 'default value' => FIELD_BEHAVIOR_DEFAULT,\n ),\n ),\n 'text_textarea_with_summary' => array(\n 'label' => t('Text area with a summary'),\n 'field types' => array('text_with_summary'),\n 'settings' => array('rows' => 20, 'summary_rows' => 5),\n 'behaviors' => array(\n 'multiple values' => FIELD_BEHAVIOR_DEFAULT,\n 'default value' => FIELD_BEHAVIOR_DEFAULT,\n ),\n // As an advanced widget, force it to sink to the bottom of the choices.\n 'weight' => 2,\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b66f5b3e7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_presave/7.x", "instruction": "In Drupal 7, write the function `book_node_presave($node)` (file modules/book/book.module) so that it does the following: Implements hook_node_presave().", "context": "File: modules/book/book.module", "response": "function book_node_presave($node) {\n // Always save a revision for non-administrators.\n if (!empty($node->book['bid']) && !user_access('administer nodes')) {\n $node->revision = 1;\n // The database schema requires a log message for every revision.\n if (!isset($node->log)) {\n $node->log = '';\n }\n }\n // Make sure a new node gets a new menu link.\n if (empty($node->nid)) {\n $node->book['mlid'] = NULL;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b67df0151", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_export_wrap/7.x", "instruction": "In Drupal 7, write the function `_locale_export_wrap($str, $len)` (file includes/locale.inc) so that it does the following: Custom word wrapping for Portable Object (Template) files.", "context": "File: includes/locale.inc", "response": "function _locale_export_wrap($str, $len) {\n $words = explode(' ', $str);\n $return = array();\n\n $cur = \"\";\n $nstr = 1;\n while (count($words)) {\n $word = array_shift($words);\n if ($nstr) {\n $cur = $word;\n $nstr = 0;\n }\n elseif (strlen(\"$cur $word\") > $len) {\n $return[] = $cur . \" \";\n $cur = $word;\n }\n else {\n $cur = \"$cur $word\";\n }\n }\n $return[] = $cur;\n\n return implode(\"\\n\", $return);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b76cbf430", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess_page/7.x", "instruction": "Implement `template_preprocess_page(&$variables)` in PHP for Drupal 7. Required behavior: Preprocess variables for page.tpl.php", "context": "Most themes utilize their own copy of page.tpl.php. The default is located inside \"modules/system/page.tpl.php\". Look in there for the full list of variables.\n\nUses the arg() function to generate a series of page template suggestions based on the current path.\n\nAny changes to variables in this preprocessor should also be changed inside template_preprocess_maintenance_page() to keep all of them consistent.\n\nFile: includes/theme.inc", "response": "function template_preprocess_page(&$variables) {\n // Move some variables to the top level for themer convenience and template cleanliness.\n $variables['show_messages'] = $variables['page']['#show_messages'];\n\n foreach (system_region_list($GLOBALS['theme'], REGIONS_ALL, FALSE) as $region_key) {\n if (!isset($variables['page'][$region_key])) {\n $variables['page'][$region_key] = array();\n }\n if ($region_content = drupal_get_region_content($region_key)) {\n $variables['page'][$region_key][]['#markup'] = $region_content;\n }\n }\n\n // Set up layout variable.\n $variables['layout'] = 'none';\n if (!empty($variables['page']['sidebar_first'])) {\n $variables['layout'] = 'first';\n }\n if (!empty($variables['page']['sidebar_second'])) {\n $variables['layout'] = ($variables['layout'] == 'first') ? 'both' : 'second';\n }\n\n $variables['base_path'] = base_path();\n $variables['front_page'] = url();\n $variables['feed_icons'] = drupal_get_feeds();\n $variables['language'] = $GLOBALS['language'];\n $variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';\n $variables['logo'] = theme_get_setting('logo');\n $variables['main_menu'] = theme_get_setting('toggle_main_menu') ? menu_main_menu() : array();\n $variables['secondary_menu'] = theme_get_setting('toggle_secondary_menu') ? menu_secondary_menu() : array();\n $variables['action_links'] = menu_local_actions();\n $variables['site_name'] = (theme_get_setting('toggle_name') ? filter_xss_admin(variable_get('site_name', 'Drupal')) : '');\n $variables['site_slogan'] = (theme_get_setting('toggle_slogan') ? filter_xss_admin(variable_get('site_slogan', '')) : '');\n $variables['tabs'] = menu_local_tabs();\n\n if ($node = menu_get_object()) {\n $variables['node'] = $node;\n }\n\n // Populate the page template suggestions.\n if ($suggestions = theme_get_suggestions(arg(), 'page')) {\n $variables['theme_hook_suggestions'] = $suggestions;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b80b7e331", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7019/7.x", "instruction": "Implement `user_update_7019()` in PHP for Drupal 7. Required behavior: Ensure there is a combined index on {authmap}.uid and {authmap}.module.", "context": "File: modules/user/user.install", "response": "function user_update_7019() {\n // Check first in case it was already added manually.\n if (!db_index_exists('authmap', 'uid_module')) {\n db_add_index('authmap', 'uid_module', array('uid', 'module'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1b8cfa2c75", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_database_errors/7.x", "instruction": "In Drupal 7, write the function `install_database_errors($database, $settings_file)` (file includes/install.core.inc) so that it does the following: Checks a database connection and returns any errors.", "context": "File: includes/install.core.inc", "response": "function install_database_errors($database, $settings_file) {\n global $databases;\n $errors = array();\n\n // Check database type.\n $database_types = drupal_get_database_types();\n $driver = $database['driver'];\n if (!isset($database_types[$driver])) {\n $errors['driver'] = st(\"In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.\", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_distribution_name(), '%driver' => $driver));\n }\n else {\n // Run driver specific validation\n $errors += $database_types[$driver]->validateDatabaseSettings($database);\n\n // Run tasks associated with the database type. Any errors are caught in the\n // calling function.\n $databases['default']['default'] = $database;\n // Just changing the global doesn't get the new information processed.\n // We tell tell the Database class to re-parse $databases.\n Database::parseConnectionInfo();\n\n try {\n db_run_tasks($driver);\n }\n catch (DatabaseTaskException $e) {\n // These are generic errors, so we do not have any specific key of the\n // database connection array to attach them to; therefore, we just put\n // them in the error array with standard numeric keys.\n $errors[$driver . '][0'] = $e->getMessage();\n }\n }\n return $errors;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ba1c92ca8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/theme_status_report/7.x", "instruction": "I need the code for `theme_status_report($variables)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Returns HTML for the status report.", "context": "This theme function is dependent on install.inc being loaded, because that's where the constants are defined.\n\nParameters:\n- $variables: An associative array containing: - requirements: An array of requirements/status items. Each requirement is an associative array containing the following elements: - title: The name of the requirement. - value: (optional) The current value (version, time, level, etc). - description: (optional) The description of the requirement. - severity: (optional) The requirement's result/severity level, one of: - REQUIREMENT_INFO: Status information. - REQUIREMENT_OK: The requirement is satisfied. - REQUIREMENT_WARNING: The requirement failed with a warning. - REQUIREMENT_ERROR: The requirement failed with an error.\n\nFile: modules/system/system.admin.inc", "response": "function theme_status_report($variables) {\n $requirements = $variables['requirements'];\n $severities = array(\n REQUIREMENT_INFO => array(\n 'title' => t('Info'),\n 'class' => 'info',\n ),\n REQUIREMENT_OK => array(\n 'title' => t('OK'),\n 'class' => 'ok',\n ),\n REQUIREMENT_WARNING => array(\n 'title' => t('Warning'),\n 'class' => 'warning',\n ),\n REQUIREMENT_ERROR => array(\n 'title' => t('Error'),\n 'class' => 'error',\n ),\n );\n $output = '';\n\n foreach ($requirements as $requirement) {\n if (empty($requirement['#type'])) {\n $severity = $severities[isset($requirement['severity']) ? (int) $requirement['severity'] : REQUIREMENT_OK];\n $severity['icon'] = '
            ' . $severity['title'] . '
            ';\n // The requirement's 'value' key is optional, provide a default value.\n $requirement['value'] = isset($requirement['value']) ? $requirement['value'] : '';\n\n // Output table row(s)\n if (!empty($requirement['description'])) {\n $output .= '';\n $output .= '';\n }\n else {\n $output .= '';\n }\n }\n }\n\n $output .= '
            ' . $severity['icon'] . '' . $requirement['title'] . '' . $requirement['value'] . '
            ' . $requirement['description'] . '
            ' . $severity['icon'] . '' . $requirement['title'] . '' . $requirement['value'] . '
            ';\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ba7bebd0a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_user_delete/7.x", "instruction": "In Drupal 7, write the function `poll_user_delete($account)` (file modules/poll/poll.module) so that it does the following: Implements hook_user_delete().", "context": "File: modules/poll/poll.module", "response": "function poll_user_delete($account) {\n db_delete('poll_vote')\n ->condition('uid', $account->uid)\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1baab824b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_load/7.x", "instruction": "Implement `forum_node_load($nodes)` in PHP for Drupal 7. Required behavior: Implements hook_node_load().", "context": "File: modules/forum/forum.module", "response": "function forum_node_load($nodes) {\n $node_vids = array();\n foreach ($nodes as $node) {\n if (_forum_node_check_node_type($node)) {\n $node_vids[] = $node->vid;\n }\n }\n if (!empty($node_vids)) {\n $query = db_select('forum', 'f');\n $query\n ->fields('f', array('nid', 'tid'))\n ->condition('f.vid', $node_vids);\n $result = $query->execute();\n foreach ($result as $record) {\n $nodes[$record->nid]->forum_tid = $record->tid;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bb14806a1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_vocabulary_confirm_reset_alphabetical/7.x", "instruction": "In Drupal 7, write the function `taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vid)` (file modules/taxonomy/taxonomy.admin.inc) so that it does the following: Form builder to confirm resetting a vocabulary to alphabetical order.", "context": "File: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vid) {\n $vocabulary = taxonomy_vocabulary_load($vid);\n\n $form['type'] = array('#type' => 'value', '#value' => 'vocabulary');\n $form['vid'] = array('#type' => 'value', '#value' => $vid);\n $form['machine_name'] = array('#type' => 'value', '#value' => $vocabulary->machine_name);\n $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name);\n $form['reset_alphabetical'] = array('#type' => 'value', '#value' => TRUE);\n return confirm_form($form,\n t('Are you sure you want to reset the vocabulary %title to alphabetical order?',\n array('%title' => $vocabulary->name)),\n 'admin/structure/taxonomy/' . $vocabulary->machine_name,\n t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'),\n t('Reset to alphabetical'),\n t('Cancel'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bbb69edfb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_display_ENTITY_TYPE_alter/7.x", "instruction": "Give me the example code for `hook_field_display_ENTITY_TYPE_alter(&$display, $context)` in Drupal 7. Hook description: Alters the display settings of a field on a given entity type before it gets displayed.", "context": "Modules can implement hook_field_display_ENTITY_TYPE_alter() to alter display settings for fields on a specific entity type, rather than implementing hook_field_display_alter().\n\nThis hook is called once per field per displayed entity. If the result of the hook involves reading from the database, it is highly recommended to statically cache the information.\n\nParameters:\n- $display: The display settings that will be used to display the field values, as found in the 'display' key of $instance definitions.\n- $context: An associative array containing: - entity_type: The entity type; e.g., 'node' or 'user'. - field: The field being rendered. - instance: The instance being rendered. - entity: The entity being rendered. - view_mode: The view mode, e.g. 'full', 'teaser'...\n\nFile: modules/field/field.api.php", "response": "function hook_field_display_ENTITY_TYPE_alter(&$display, $context) {\n // Leave field labels out of the search index.\n if ($context['view_mode'] == 'search_index') {\n $display['label'] = 'hidden';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bbf86635f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_language_types/7.x", "instruction": "In Drupal 7, write the function `drupal_language_types()` (file includes/bootstrap.inc) so that it does the following: Returns a list of the built-in language types.", "context": "Returns: An array of key-values pairs where the key is the language type and the value is its configurability.\n\nFile: includes/bootstrap.inc", "response": "function drupal_language_types() {\n return array(\n LANGUAGE_TYPE_INTERFACE => TRUE,\n LANGUAGE_TYPE_CONTENT => FALSE,\n LANGUAGE_TYPE_URL => FALSE,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bc1dad456", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_replace/7.x", "instruction": "In Drupal 7, write the function `ajax_command_replace($selector, $html, $settings = NULL)` (file includes/ajax.inc) so that it does the following: Creates a Drupal Ajax 'insert/replaceWith' command.", "context": "The 'insert/replaceWith' command instructs the client to use jQuery's replaceWith() method to replace each element matched matched by the given selector with the given HTML.\n\nThis command is implemented by Drupal.ajax.prototype.commands.insert() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n- $html: The data to use with the jQuery replaceWith() method.\n- $settings: An optional array of settings that will be used for this command only.\n\nReturns: An array suitable for use with the ajax_render() function. See\n\nFile: includes/ajax.inc", "response": "function ajax_command_replace($selector, $html, $settings = NULL) {\n return array(\n 'command' => 'insert',\n 'method' => 'replaceWith',\n 'selector' => $selector,\n 'data' => $html,\n 'settings' => $settings,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bcbfb8542", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_deliver_page/7.x", "instruction": "I need the code for `drupal_deliver_page($page_callback_result, $default_delivery_callback = NULL)` in Drupal 7 (includes/common.inc). It must do this: Delivers a page callback result to the browser in the appropriate format.", "context": "This function is most commonly called by menu_execute_active_handler(), but can also be called by error conditions such as drupal_not_found(), drupal_access_denied(), and drupal_site_offline().\n\nWhen a user requests a page, index.php calls menu_execute_active_handler(),\nwhich calls the 'page callback' function registered in hook_menu(). The page\ncallback function can return one of:\n- NULL: to indicate no content.\n- An integer menu status constant: to indicate an error condition.\n- A string of HTML content.\n- A renderable array of content.\nReturning a renderable array rather than a string of HTML is preferred,\nbecause that provides modules with more flexibility in customizing the final\nresult.\n\nWhen the page callback returns its constructed content to menu_execute_active_handler(), this function gets called. The purpose of this function is to determine the most appropriate 'delivery callback' function to route the content to. The delivery callback function then sends the content to the browser in the needed format. The default delivery callback is drupal_deliver_html_page(), which delivers the content as an HTML page, complete with blocks in addition to the content. This default can be overridden on a per menu router item basis by setting 'delivery callback' in hook_menu() or hook_menu_alter(), and can also be overridden on a per request basis in hook_page_delivery_callback_alter().\n\nFor example, the same page callback function can be used for an HTML version of the page and an Ajax version of the page. The page callback function just needs to decide what content is to be returned and the delivery callback function will send it as an HTML page or an Ajax response, as appropriate.\n\nIn order for page callbacks to be reusable in different delivery formats, they should not issue any \"print\" or \"echo\" statements, but instead just return content.\n\nAlso note that this function does not perform access checks. The delivery callback function specified in hook_menu(), hook_menu_alter(), or hook_page_delivery_callback_alter() will be called even if the router item access checks fail. This is intentional (it is needed for JSON and other purposes), but it has security implications. Do not call this function directly unless you understand the security implications, and be careful in writing delivery callbacks, so that they do not violate security. See drupal_deliver_html_page() for an example of a delivery callback that respects security.\n\nParameters:\n- $page_callback_result: The result of a page callback. Can be one of: - NULL: to indicate no content. - An integer menu status constant: to indicate an error condition. - A string of HTML content. - A renderable array of content.\n- $default_delivery_callback: (Optional) If given, it is the name of a delivery function most likely to be appropriate for the page request as determined by the calling function (e.g., menu_execute_active_handler()). If not given, it is determined from the menu router information of the current page.\n\nFile: includes/common.inc", "response": "function drupal_deliver_page($page_callback_result, $default_delivery_callback = NULL) {\n if (!isset($default_delivery_callback) && ($router_item = menu_get_item())) {\n $default_delivery_callback = $router_item['delivery_callback'];\n }\n $delivery_callback = !empty($default_delivery_callback) ? $default_delivery_callback : 'drupal_deliver_html_page';\n // Give modules a chance to alter the delivery callback used, based on\n // request-time context (e.g., HTTP request headers).\n drupal_alter('page_delivery_callback', $delivery_callback);\n if (function_exists($delivery_callback)) {\n $delivery_callback($page_callback_result);\n }\n else {\n // If a delivery callback is specified, but doesn't exist as a function,\n // something is wrong, but don't print anything, since it's not known\n // what format the response needs to be in.\n watchdog('delivery callback not found', 'callback %callback not found: %q.', array('%callback' => $delivery_callback, '%q' => $_GET['q']), WATCHDOG_ERROR);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bd039a97e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_token_value/7.x", "instruction": "I need the code for `form_type_token_value($element, $input = FALSE)` in Drupal 7 (includes/form.inc). It must do this: Determines the value for form's token value.", "context": "Parameters:\n- $element: The form element whose value is being populated.\n- $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.\n\nReturns: The data that will appear in $form_state['values'] for this element, or nothing to use the default.\n\nFile: includes/form.inc", "response": "function form_type_token_value($element, $input = FALSE) {\n if ($input !== FALSE) {\n return (string) $input;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bd6da8fe6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_maintenance_theme/7.x", "instruction": "I need the code for `drupal_maintenance_theme()` in Drupal 7 (includes/bootstrap.inc). It must do this: Enables use of the theme system without requiring database access.", "context": "Loads and initializes the theme system for site installs, updates and when the site is in maintenance mode. This also applies when the database fails.\n\nFile: includes/bootstrap.inc", "response": "function drupal_maintenance_theme() {\n require_once DRUPAL_ROOT . '/includes/theme.maintenance.inc';\n _drupal_maintenance_theme();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1bf2eade31", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_cancel_methods_alter/7.x", "instruction": "Give me the example code for `hook_user_cancel_methods_alter(&$methods)` in Drupal 7. Hook description: Modify account cancellation methods.", "context": "By implementing this hook, modules are able to add, customize, or remove\naccount cancellation methods. All defined methods are turned into radio\nbutton form elements by user_cancel_methods() after this hook is invoked.\nThe following properties can be defined for each method:\n- title: The radio button's title.\n- description: (optional) A description to display on the confirmation form\n if the user is not allowed to select the account cancellation method. The\n description is NOT used for the radio button, but instead should provide\n additional explanation to the user seeking to cancel their account.\n- access: (optional) A boolean value indicating whether the user can access\n a method. If access is defined, the method cannot be configured as the\n default method.\n\nParameters:\n- $methods: An array containing user account cancellation methods, keyed by method id.\n\nFile: modules/user/user.api.php", "response": "function hook_user_cancel_methods_alter(&$methods) {\n // Limit access to disable account and unpublish content method.\n $methods['user_cancel_block_unpublish']['access'] = user_access('administer site configuration');\n\n // Remove the content re-assigning method.\n unset($methods['user_cancel_reassign']);\n\n // Add a custom zero-out method.\n $methods['mymodule_zero_out'] = array(\n 'title' => t('Delete the account and remove all content.'),\n 'description' => t('All your content will be replaced by empty strings.'),\n // access should be used for administrative methods only.\n 'access' => user_access('access zero-out account cancellation method'),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1c147ef308", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_node_delete/7.x", "instruction": "In Drupal 7, write the function `statistics_node_delete($node)` (file modules/statistics/statistics.module) so that it does the following: Implements hook_node_delete().", "context": "File: modules/statistics/statistics.module", "response": "function statistics_node_delete($node) {\n // clean up statistics table when node is deleted\n db_delete('node_counter')\n ->condition('nid', $node->nid)\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1c2478f61c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/_tracker_myrecent_access/7.x", "instruction": "In Drupal 7, write the function `_tracker_myrecent_access($account)` (file modules/tracker/tracker.module) so that it does the following: Access callback for tracker/%user_uid_optional.", "context": "File: modules/tracker/tracker.module", "response": "function _tracker_myrecent_access($account) {\n // This path is only allowed for authenticated users looking at their own content.\n return $account->uid && ($GLOBALS['user']->uid == $account->uid) && user_access('access content');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1c4a23b0fd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_revision_tablename/7.x", "instruction": "In Drupal 7, write the function `_field_sql_storage_revision_tablename($field)` (file modules/field/modules/field_sql_storage/field_sql_storage.module) so that it does the following: Generate a table name for a field revision archive table.", "context": "Parameters:\n- $name: The field structure.\n\nReturns: A string containing the generated name for the database table\n\nFile: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function _field_sql_storage_revision_tablename($field) {\n if ($field['deleted']) {\n return \"field_deleted_revision_{$field['id']}\";\n }\n else {\n return \"field_revision_{$field['field_name']}\";\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1c5922a1b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_get_cache_multiple/7.x", "instruction": "In Drupal 7, write the function `_update_get_cache_multiple($cid_prefix)` (file modules/update/update.module) so that it does the following: Returns an array of cache items with a given cache ID prefix.", "context": "Parameters:\n- $cid_prefix (string): The cache ID prefix.\n\nReturns: Associative array of cache items, keyed by cache ID.\n\nFile: modules/update/update.module", "response": "function _update_get_cache_multiple($cid_prefix) {\n $data = array();\n $result = db_select('cache_update')\n ->fields('cache_update', array('cid', 'data', 'created', 'expire', 'serialized'))\n ->condition('cache_update.cid', $cid_prefix . '::%', 'LIKE')\n ->execute();\n foreach ($result as $cache) {\n if ($cache) {\n if ($cache->serialized) {\n $cache->data = unserialize($cache->data);\n }\n $data[$cache->cid] = $cache;\n }\n }\n return $data;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1c74f80493", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.settings.inc/function/update_settings/7.x", "instruction": "I need the code for `update_settings($form)` in Drupal 7 (modules/update/update.settings.inc). It must do this: Form constructor for the update settings form.", "context": "File: modules/update/update.settings.inc", "response": "function update_settings($form) {\n $form['update_check_frequency'] = array(\n '#type' => 'radios',\n '#title' => t('Check for updates'),\n '#default_value' => variable_get('update_check_frequency', 1),\n '#options' => array(\n '1' => t('Daily'),\n '7' => t('Weekly'),\n ),\n '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),\n );\n\n $form['update_check_disabled'] = array(\n '#type' => 'checkbox',\n '#title' => t('Check for updates of disabled and uninstalled modules and themes'),\n '#default_value' => variable_get('update_check_disabled', FALSE),\n );\n\n $notify_emails = variable_get('update_notify_emails', array());\n $form['update_notify_emails'] = array(\n '#type' => 'textarea',\n '#title' => t('E-mail addresses to notify when updates are available'),\n '#rows' => 4,\n '#default_value' => implode(\"\\n\", $notify_emails),\n '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'),\n );\n\n $form['update_notification_threshold'] = array(\n '#type' => 'radios',\n '#title' => t('E-mail notification threshold'),\n '#default_value' => variable_get('update_notification_threshold', 'all'),\n '#options' => array(\n 'all' => t('All newer versions'),\n 'security' => t('Only security updates'),\n ),\n '#description' => t('You can choose to send e-mail only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the status report page, and will also display an error message on administration pages if there is a security update.', array('@status_report' => url('admin/reports/status')))\n );\n\n $form = system_settings_form($form);\n // Custom validation callback for the email notification setting.\n $form['#validate'][] = 'update_settings_validate';\n // We need to call our own submit callback first, not the one from\n // system_settings_form(), so that we can process and save the emails.\n unset($form['#submit']);\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1c906a6603", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.api.php/function/hook_dashboard_regions_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_dashboard_regions_alter(&$regions)` (modules/dashboard/dashboard.api.php): Alter dashboard regions provided by modules.", "context": "Parameters:\n- $regions: An array containing all dashboard regions, in the format provided by hook_dashboard_regions().\n\nFile: modules/dashboard/dashboard.api.php", "response": "function hook_dashboard_regions_alter(&$regions) {\n // Remove the sidebar region defined by the core dashboard module.\n unset($regions['dashboard_sidebar']);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ccbf9dff8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_format_is_cacheable/7.x", "instruction": "In Drupal 7, write the function `_filter_format_is_cacheable($format)` (file modules/filter/filter.module) so that it does the following: Helper function to determine whether the output of a given text format can be cached.", "context": "The output of a given text format can be cached when all enabled filters in the text format allow caching.\n\nParameters:\n- $format: The text format object to check.\n\nReturns: TRUE if all the filters enabled in the given text format allow caching, FALSE otherwise.\n\nFile: modules/filter/filter.module", "response": "function _filter_format_is_cacheable($format) {\n if (empty($format->filters)) {\n return TRUE;\n }\n $filter_info = filter_get_filters();\n foreach ($format->filters as $name => $filter) {\n // By default, 'cache' is TRUE for all filters unless specified otherwise.\n if (!empty($filter['status']) && isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {\n return FALSE;\n }\n }\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1cf71e2080", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/theme_user_signature/7.x", "instruction": "Implement `theme_user_signature($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a user signature.", "context": "Parameters:\n- $variables: An associative array containing: - signature: The user's signature.\n\nFile: modules/user/user.module", "response": "function theme_user_signature($variables) {\n $signature = $variables['signature'];\n $output = '';\n\n if ($signature) {\n $output .= '
            ';\n $output .= '
            —
            ';\n $output .= $signature;\n $output .= '
            ';\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d083fa8c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_actions_remove_orphans/7.x", "instruction": "Implement `system_actions_remove_orphans()` in PHP for Drupal 7. Required behavior: Remove actions that are in the database but not supported by any enabled module.", "context": "File: modules/system/system.admin.inc", "response": "function system_actions_remove_orphans() {\n actions_synchronize(TRUE);\n drupal_goto('admin/config/system/actions/manage');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d0cc9dbb6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.maintenance.inc/function/theme_update_page/7.x", "instruction": "Implement `theme_update_page($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the update page.", "context": "Note: this function is not themeable.\n\nParameters:\n- $variables: An associative array containing: - content: The page content to show. - show_messages: Whether to output status and error messages. FALSE can be useful to postpone the messages to a subsequent page.\n\nFile: includes/theme.maintenance.inc", "response": "function theme_update_page($variables) {\n drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');\n return theme('maintenance_page', $variables);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d10151a44", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_delete_item/7.x", "instruction": "In Drupal 7, write the function `_menu_delete_item($item, $force = FALSE)` (file includes/menu.inc) so that it does the following: Deletes a single menu link.", "context": "Parameters:\n- $item: Item to be deleted.\n- $force: Forces deletion. Internal use only, setting to TRUE is discouraged.\n\nFile: includes/menu.inc", "response": "function _menu_delete_item($item, $force = FALSE) {\n $item = is_object($item) ? get_object_vars($item) : $item;\n if ($item && ($item['module'] != 'system' || $item['updated'] || $force)) {\n // Children get re-attached to the item's parent.\n if ($item['has_children']) {\n $result = db_query(\"SELECT mlid FROM {menu_links} WHERE plid = :plid\", array(':plid' => $item['mlid']));\n foreach ($result as $m) {\n $child = menu_link_load($m->mlid);\n $child['plid'] = $item['plid'];\n menu_link_save($child);\n }\n }\n\n // Notify modules we are deleting the item.\n module_invoke_all('menu_link_delete', $item);\n\n db_delete('menu_links')->condition('mlid', $item['mlid'])->execute();\n\n // Update the has_children status of the parent.\n _menu_update_parental_status($item);\n menu_cache_clear($item['menu_name']);\n _menu_clear_page_cache();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d13d43689", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_view_voting/7.x", "instruction": "Implement `poll_view_voting($form, &$form_state, $node, $block = FALSE)` in PHP for Drupal 7. Required behavior: Generates the voting form for a poll.", "context": "File: modules/poll/poll.module", "response": "function poll_view_voting($form, &$form_state, $node, $block = FALSE) {\n if ($node->choice) {\n $list = array();\n foreach ($node->choice as $i => $choice) {\n $list[$i] = check_plain($choice['chtext']);\n }\n $form['choice'] = array(\n '#type' => 'radios',\n '#title' => t('Choices'),\n '#title_display' => 'invisible',\n '#options' => $list,\n );\n }\n\n $form['vote'] = array(\n '#type' => 'submit',\n '#value' => t('Vote'),\n '#submit' => array('poll_vote'),\n );\n\n // Store the node so we can get to it in submit functions.\n $form['#node'] = $node;\n $form['#block'] = $block;\n\n // Set form caching because we could have multiple of these forms on\n // the same page, and we want to ensure the right one gets picked.\n $form_state['cache'] = TRUE;\n\n // Provide a more cleanly named voting form theme.\n $form['#theme'] = 'poll_vote';\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d18e76de7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_rebuild_theme_data/7.x", "instruction": "I need the code for `system_rebuild_theme_data()` in Drupal 7 (modules/system/system.module). It must do this: Rebuild, save, and return data about all currently available themes.", "context": "Returns (Array): of all available themes and their data.\n\nFile: modules/system/system.module", "response": "function system_rebuild_theme_data() {\n $themes = _system_rebuild_theme_data();\n ksort($themes);\n system_get_files_database($themes, 'theme');\n system_update_files_database($themes, 'theme');\n return $themes;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d1a4472e1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_add_form_submit/7.x", "instruction": "Implement `shortcut_set_add_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Submit handler for shortcut_set_add_form().", "context": "File: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_set_add_form_submit($form, &$form_state) {\n // Save a new shortcut set with links copied from the user's default set.\n $default_set = shortcut_default_set();\n $set = (object) array(\n 'title' => $form_state['values']['new'],\n 'links' => menu_links_clone($default_set->links),\n );\n shortcut_set_save($set);\n drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', array('%set_name' => $set->title)));\n $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $set->set_name;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d1de282e0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_form_node_type_form_alter/7.x", "instruction": "I need the code for `translation_form_node_type_form_alter(&$form, &$form_state)` in Drupal 7 (modules/translation/translation.module). It must do this: Implements hook_form_FORM_ID_alter() for node_type_form().", "context": "File: modules/translation/translation.module", "response": "function translation_form_node_type_form_alter(&$form, &$form_state) {\n // Add translation option to content type form.\n $form['workflow']['language_content_type']['#options'][TRANSLATION_ENABLED] = t('Enabled, with translation');\n // Description based on text from locale.module.\n $form['workflow']['language_content_type']['#description'] = t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the enabled languages. You can also turn on translation for this content type, which lets you have content translated to any of the installed languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language')));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d24cb4b66", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_uninstall/7.x", "instruction": "In Drupal 7, write the function `forum_uninstall()` (file modules/forum/forum.install) so that it does the following: Implements hook_uninstall().", "context": "File: modules/forum/forum.install", "response": "function forum_uninstall() {\n // Load the dependent Taxonomy module, in case it has been disabled.\n drupal_load('module', 'taxonomy');\n\n variable_del('forum_containers');\n variable_del('forum_hot_topic');\n variable_del('forum_per_page');\n variable_del('forum_order');\n variable_del('forum_block_num_active');\n variable_del('forum_block_num_new');\n variable_del('node_options_forum');\n\n field_delete_field('taxonomy_forums');\n // Purge field data now to allow taxonomy module to be uninstalled\n // if this is the only field remaining.\n field_purge_batch(10);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d46f719af", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_get_books/7.x", "instruction": "I need the code for `book_get_books()` in Drupal 7 (modules/book/book.module). It must do this: Returns an array of all books.", "context": "This list may be used for generating a list of all the books, or for building the options for a form select.\n\nReturns: An array of all books.\n\nFile: modules/book/book.module", "response": "function book_get_books() {\n $all_books = &drupal_static(__FUNCTION__);\n\n if (!isset($all_books)) {\n $all_books = array();\n $nids = db_query(\"SELECT DISTINCT(bid) FROM {book}\")->fetchCol();\n\n if ($nids) {\n $query = db_select('book', 'b', array('fetch' => PDO::FETCH_ASSOC));\n $query->join('node', 'n', 'b.nid = n.nid');\n $query->join('menu_links', 'ml', 'b.mlid = ml.mlid');\n $query->addField('n', 'type', 'type');\n $query->addField('n', 'title', 'title');\n $query->fields('b');\n $query->fields('ml');\n $query->condition('n.nid', $nids, 'IN');\n $query->condition('n.status', 1);\n $query->orderBy('ml.weight');\n $query->orderBy('ml.link_title');\n $query->addTag('node_access');\n $result2 = $query->execute();\n foreach ($result2 as $link) {\n $link['href'] = $link['link_path'];\n $link['options'] = unserialize($link['options']);\n $all_books[$link['bid']] = $link;\n }\n }\n }\n\n return $all_books;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d4ae2b491", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_help/7.x", "instruction": "In Drupal 7, write the function `comment_help($path, $arg)` (file modules/comment/comment.module) so that it does the following: Implements hook_help().", "context": "File: modules/comment/comment.module", "response": "function comment_help($path, $arg) {\n switch ($path) {\n case 'admin/help#comment':\n $output = '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the online handbook entry for Comment module.', array('@comment' => 'http://drupal.org/documentation/modules/comment/')) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Default and custom settings') . '
            ';\n $output .= '
            ' . t(\"Each content type can have its own default comment settings configured as: Open to allow new comments, Hidden to hide existing comments and prevent new comments, or Closed to view existing comments, but prevent new comments. These defaults will apply to all new content created (changes to the settings on existing content must be done manually). Other comment settings can also be customized per content type, and can be overridden for any given item of content. When a comment has no replies, it remains editable by its author, as long as the author has a user account and is logged in.\", array('@content-type' => url('admin/structure/types'))) . '
            ';\n $output .= '
            ' . t('Comment approval') . '
            ';\n $output .= '
            ' . t(\"Comments from users who have the Skip comment approval permission are published immediately. All other comments are placed in the Unapproved comments queue, until a user who has permission to Administer comments publishes or deletes them. Published comments can be bulk managed on the Published comments administration page.\", array('@comment-approval' => url('admin/content/comment/approval'), '@admin-comment' => url('admin/content/comment'))) . '
            ';\n $output .= '
            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d663423cd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_dirname/7.x", "instruction": "I need the code for `drupal_dirname($uri)` in Drupal 7 (includes/file.inc). It must do this: Gets the name of the directory from a given path.", "context": "PHP's dirname() does not properly pass streams, so this function fills that gap. It is backwards compatible with normal paths and will use PHP's dirname() as a fallback.\n\nCompatibility: normal paths and stream wrappers.\n\nParameters:\n- $uri: A URI or path.\n\nReturns: A string containing the directory name.\n\nFile: includes/file.inc", "response": "function drupal_dirname($uri) {\n $scheme = file_uri_scheme($uri);\n\n if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {\n return file_stream_wrapper_get_instance_by_scheme($scheme)->dirname($uri);\n }\n else {\n return dirname($uri);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d6ab21bc7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_themes_enabled/7.x", "instruction": "I need the code for `update_themes_enabled($themes)` in Drupal 7 (modules/update/update.module). It must do this: Implements hook_themes_enabled().", "context": "If themes are enabled, we invalidate the cache of available updates.\n\nFile: modules/update/update.module", "response": "function update_themes_enabled($themes) {\n // Clear all update module caches.\n _update_cache_clear();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d6e46b597", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_categories/7.x", "instruction": "I need the code for `profile_user_categories()` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_user_categories().", "context": "File: modules/profile/profile.module", "response": "function profile_user_categories() {\n $result = db_query(\"SELECT DISTINCT(category) FROM {profile_field}\");\n $data = array();\n foreach ($result as $category) {\n $data[] = array(\n 'name' => $category->category,\n 'title' => $category->category,\n 'weight' => 3,\n 'access callback' => 'profile_category_access',\n 'access arguments' => array(1, $category->category)\n );\n }\n return $data;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d86402aab", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_check_access/7.x", "instruction": "Implement `menu_tree_check_access(&$tree, $node_links = array())` in PHP for Drupal 7. Required behavior: Checks access and performs dynamic operations for each link in the tree.", "context": "Parameters:\n- $tree: The menu tree you wish to operate on.\n- $node_links: A collection of node link references generated from $tree by menu_tree_collect_node_links().\n\nFile: includes/menu.inc", "response": "function menu_tree_check_access(&$tree, $node_links = array()) {\n if ($node_links && (user_access('access content') || user_access('bypass node access'))) {\n $nids = array_keys($node_links);\n $select = db_select('node', 'n');\n $select->addField('n', 'nid');\n // When a menu administrator who we know has permission to see unpublished\n // nodes is administering the menu, included the unpublished nodes in the\n // tree, with a special flag so that the Menu module can label them.\n // Otherwise, exclude these nodes from the tree.\n if (!empty($GLOBALS['menu_admin']) && user_access('bypass node access')) {\n $select->addField('n', 'status');\n }\n else {\n $select->condition('n.status', 1);\n }\n $select->condition('n.nid', $nids, 'IN');\n $select->addTag('node_access');\n $node_objects = $select->execute()->fetchAll();\n foreach ($node_objects as $node_object) {\n foreach ($node_links[$node_object->nid] as $mlid => $link) {\n $node_links[$node_object->nid][$mlid]['access'] = TRUE;\n if (isset($node_object->status)) {\n $node_links[$node_object->nid][$mlid]['node_unpublished'] = !$node_object->status;\n }\n }\n }\n }\n _menu_tree_check_access($tree);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d8e6c2302", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_edit_cancel_submit/7.x", "instruction": "Implement `user_edit_cancel_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Submit function for the 'Cancel account' button on the user edit form.", "context": "File: modules/user/user.pages.inc", "response": "function user_edit_cancel_submit($form, &$form_state) {\n $destination = array();\n if (isset($_GET['destination'])) {\n $destination = drupal_get_destination();\n unset($_GET['destination']);\n }\n // Note: We redirect from user/uid/edit to user/uid/cancel to make the tabs disappear.\n $form_state['redirect'] = array(\"user/\" . $form['#user']->uid . \"/cancel\", array('query' => $destination));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1d9596ee99", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_admin_compact_page/7.x", "instruction": "Implement `system_admin_compact_page($mode = 'off')` in PHP for Drupal 7. Required behavior: Menu callback; Sets whether the admin menu is in compact mode or not.", "context": "Parameters:\n- $mode: Valid values are 'on' and 'off'.\n\nFile: modules/system/system.module", "response": "function system_admin_compact_page($mode = 'off') {\n user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));\n drupal_goto();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1da6de6851", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/_system_update_bootstrap_status/7.x", "instruction": "Implement `_system_update_bootstrap_status()` in PHP for Drupal 7. Required behavior: Refresh bootstrap column in the system table.", "context": "This is called internally by module_enable/disable() to flag modules that implement hooks used during bootstrap, such as hook_boot(). These modules are loaded earlier to invoke the hooks.\n\nFile: modules/system/system.module", "response": "function _system_update_bootstrap_status() {\n $bootstrap_modules = array();\n foreach (bootstrap_hooks() as $hook) {\n foreach (module_implements($hook) as $module) {\n $bootstrap_modules[] = $module;\n }\n }\n $query = db_update('system')->fields(array('bootstrap' => 0));\n if ($bootstrap_modules) {\n db_update('system')\n ->fields(array('bootstrap' => 1))\n ->condition('name', $bootstrap_modules, 'IN')\n ->execute();\n $query->condition('name', $bootstrap_modules, 'NOT IN');\n }\n $query->execute();\n // Reset the cached list of bootstrap modules.\n system_list_reset();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1db2f1e3a7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_get_flat_menu/7.x", "instruction": "Implement `book_get_flat_menu($book_link)` in PHP for Drupal 7. Required behavior: Gets the book menu tree for a page and returns it as a linear array.", "context": "Parameters:\n- $book_link: A fully loaded menu link that is part of the book hierarchy.\n\nReturns: A linear array of menu links in the order that the links are shown in the menu, so the previous and next pages are the elements before and after the element corresponding to the current node. The children of the current node (if any) will come immediately after it in the array, and links will only be fetched as deep as one level deeper than $book_link.\n\nFile: modules/book/book.module", "response": "function book_get_flat_menu($book_link) {\n $flat = &drupal_static(__FUNCTION__, array());\n\n if (!isset($flat[$book_link['mlid']])) {\n // Call menu_tree_all_data() to take advantage of the menu system's caching.\n $tree = menu_tree_all_data($book_link['menu_name'], $book_link, $book_link['depth'] + 1);\n $flat[$book_link['mlid']] = array();\n _book_flatten_menu($tree, $flat[$book_link['mlid']]);\n }\n\n return $flat[$book_link['mlid']];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1db77180ad", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_category_load/7.x", "instruction": "I need the code for `aggregator_category_load($cid)` in Drupal 7 (modules/aggregator/aggregator.module). It must do this: Loads an aggregator category.", "context": "Parameters:\n- $cid: The category id.\n\nReturns: An associative array describing the category.\n\nFile: modules/aggregator/aggregator.module", "response": "function aggregator_category_load($cid) {\n $categories = &drupal_static(__FUNCTION__);\n if (!isset($categories[$cid])) {\n $categories[$cid] = db_query('SELECT * FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $cid))->fetchAssoc();\n }\n\n return $categories[$cid];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1dbbf76664", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_load/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_file_load($files)` (modules/system/system.api.php): Load additional information into file objects.", "context": "file_load_multiple() calls this hook to allow modules to load additional information into each file.\n\nParameters:\n- $files: An array of file objects, indexed by fid.\n\nFile: modules/system/system.api.php", "response": "function hook_file_load($files) {\n // Add the upload specific data into the file object.\n $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC);\n foreach ($result as $record) {\n foreach ($record as $key => $value) {\n $files[$record['fid']]->$key = $value;\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1dc035ff9e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_collect_node_links/7.x", "instruction": "In Drupal 7, write the function `menu_tree_collect_node_links(&$tree, &$node_links)` (file includes/menu.inc) so that it does the following: Collects node links from a given menu tree recursively.", "context": "Parameters:\n- $tree: The menu tree you wish to collect node links from.\n- $node_links: An array in which to store the collected node links.\n\nFile: includes/menu.inc", "response": "function menu_tree_collect_node_links(&$tree, &$node_links) {\n foreach ($tree as $key => $v) {\n if ($tree[$key]['link']['router_path'] == 'node/%') {\n $nid = substr($tree[$key]['link']['link_path'], 5);\n if (is_numeric($nid)) {\n $node_links[$nid][$tree[$key]['link']['mlid']] = &$tree[$key]['link'];\n $tree[$key]['link']['access'] = FALSE;\n }\n }\n if ($tree[$key]['below']) {\n menu_tree_collect_node_links($tree[$key]['below'], $node_links);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1de8df3d97", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_before/7.x", "instruction": "I need the code for `ajax_command_before($selector, $html, $settings = NULL)` in Drupal 7 (includes/ajax.inc). It must do this: Creates a Drupal Ajax 'insert/before' command.", "context": "The 'insert/before' command instructs the client to use jQuery's before() method to insert the given HTML content before each of elements matched by the given selector.\n\nThis command is implemented by Drupal.ajax.prototype.commands.insert() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n- $html: The data to use with the jQuery before() method.\n- $settings: An optional array of settings that will be used for this command only.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_before($selector, $html, $settings = NULL) {\n return array(\n 'command' => 'insert',\n 'method' => 'before',\n 'selector' => $selector,\n 'data' => $html,\n 'settings' => $settings,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1dec973b0a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7055/7.x", "instruction": "Implement `system_update_7055()` in PHP for Drupal 7. Required behavior: Converts fields that store serialized variables from text to blob.", "context": "File: modules/system/system.install", "response": "function system_update_7055() {\n $spec = array(\n 'description' => 'The value of the variable.',\n 'type' => 'blob',\n 'not null' => TRUE,\n 'size' => 'big',\n 'translatable' => TRUE,\n );\n db_change_field('variable', 'value', 'value', $spec);\n\n $spec = array(\n 'description' => 'Parameters to be passed to the callback function.',\n 'type' => 'blob',\n 'not null' => TRUE,\n 'size' => 'big',\n );\n db_change_field('actions', 'parameters', 'parameters', $spec);\n\n $spec = array(\n 'description' => 'A serialized array containing the processing data for the batch.',\n 'type' => 'blob',\n 'not null' => FALSE,\n 'size' => 'big',\n );\n db_change_field('batch', 'batch', 'batch', $spec);\n\n $spec = array(\n 'description' => 'A serialized array of function names (like node_load) to be called to load an object corresponding to a part of the current path.',\n 'type' => 'blob',\n 'not null' => TRUE,\n );\n db_change_field('menu_router', 'load_functions', 'load_functions', $spec);\n\n $spec = array(\n 'description' => 'A serialized array of function names (like user_uid_optional_to_arg) to be called to replace a part of the router path with another string.',\n 'type' => 'blob',\n 'not null' => TRUE,\n );\n db_change_field('menu_router', 'to_arg_functions', 'to_arg_functions', $spec);\n\n $spec = array(\n 'description' => 'A serialized array of arguments for the access callback.',\n 'type' => 'blob',\n 'not null' => FALSE,\n );\n db_change_field('menu_router', 'access_arguments', 'access_arguments', $spec);\n\n $spec = array(\n 'description' => 'A serialized array of arguments for the page callback.',\n 'type' => 'blob',\n 'not null' => FALSE,\n );\n db_change_field('menu_router', 'page_arguments', 'page_arguments', $spec);\n\n $spec = array(\n 'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.',\n 'type' => 'blob',\n 'not null' => FALSE,\n 'translatable' => TRUE,\n );\n db_change_field('menu_links', 'options', 'options', $spec);\n\n $spec = array(\n 'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.',\n 'type' => 'blob',\n 'not null' => FALSE,\n 'size' => 'big',\n );\n db_change_field('sessions', 'session', 'session', $spec);\n\n $spec = array(\n 'description' => \"A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.\",\n 'type' => 'blob',\n 'not null' => FALSE,\n );\n db_change_field('system', 'info', 'info', $spec);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1df0c533ef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_trigger_info/7.x", "instruction": "In Drupal 7, write the function `trigger_trigger_info()` (file modules/trigger/trigger.module) so that it does the following: Implements hook_trigger_info().", "context": "Defines all the triggers that this module implements triggers for.\n\nFile: modules/trigger/trigger.module", "response": "function trigger_trigger_info() {\n return array(\n 'node' => array(\n 'node_presave' => array(\n 'label' => t('When either saving new content or updating existing content'),\n ),\n 'node_insert' => array(\n 'label' => t('After saving new content'),\n ),\n 'node_update' => array(\n 'label' => t('After saving updated content'),\n ),\n 'node_delete' => array(\n 'label' => t('After deleting content'),\n ),\n 'node_view' => array(\n 'label' => t('When content is viewed by an authenticated user'),\n ),\n ),\n 'comment' => array(\n 'comment_presave' => array(\n 'label' => t('When either saving a new comment or updating an existing comment'),\n ),\n 'comment_insert' => array(\n 'label' => t('After saving a new comment'),\n ),\n 'comment_update' => array(\n 'label' => t('After saving an updated comment'),\n ),\n 'comment_delete' => array(\n 'label' => t('After deleting a comment'),\n ),\n 'comment_view' => array(\n 'label' => t('When a comment is being viewed by an authenticated user'),\n ),\n ),\n 'taxonomy' => array(\n 'taxonomy_term_insert' => array(\n 'label' => t('After saving a new term to the database'),\n ),\n 'taxonomy_term_update' => array(\n 'label' => t('After saving an updated term to the database'),\n ),\n 'taxonomy_term_delete' => array(\n 'label' => t('After deleting a term'),\n ),\n ),\n 'system' => array(\n 'cron' => array(\n 'label' => t('When cron runs'),\n ),\n ),\n 'user' => array(\n 'user_insert' => array(\n 'label' => t('After creating a new user account'),\n ),\n 'user_update' => array(\n 'label' => t('After updating a user account'),\n ),\n 'user_delete' => array(\n 'label' => t('After a user has been deleted'),\n ),\n 'user_login' => array(\n 'label' => t('After a user has logged in'),\n ),\n 'user_logout' => array(\n 'label' => t('After a user has logged out'),\n ),\n 'user_view' => array(\n 'label' => t(\"When a user's profile is being viewed\"),\n ),\n ),\n );\n }", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e041cbba9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_date_formats/7.x", "instruction": "Give me the example code for `hook_date_formats()` in Drupal 7. Hook description: Define additional date formats.", "context": "This hook is used to define the PHP date format strings that can be assigned to date types in the administrative interface. A module can provide date format strings for the core-provided date types ('long', 'medium', and 'short'), or for date types defined in hook_date_format_types() by itself or another module.\n\nSince date formats can be locale-specific, you can specify the locales that each date format string applies to. There may be more than one locale for a format. There may also be more than one format for the same locale. For example d/m/Y and Y/m/d work equally well in some locales. You may wish to define some additional date formats that aren't specific to any one locale, for example, \"Y m\". For these cases, the 'locales' component of the return value should be omitted.\n\nProviding a date format here does not normally assign the format to be used with the associated date type -- a user has to choose a format for each date type in the administrative interface. There is one exception: locale initialization chooses a locale-specific format for the three core-provided types (see locale_get_localized_date_format() for details). If your module needs to ensure that a date type it defines has a format associated with it, call @code variable_set('date_format_' . $type, $format); @endcode where $type is the machine-readable name defined in hook_date_format_types(), and $format is a PHP date format string.\n\nReturns: A list of date formats to offer as choices in the administrative interface. Each date format is a keyed array consisting of three elements: - 'type': The date type name that this format can be used with, as declared in an implementation of hook_date_format_types(). - 'format': A PHP date format string to use when formatting dates. It can contain any of the formatting options described at http://php.net/manual/function.date.php - 'locales': (optional) An array of 2 and 5 character locale codes, defining which locales this format applies to (for example, 'en', 'en-us', etc.). If your date format is not language-specific, leave this array empty.\n\nFile: modules/system/system.api.php", "response": "function hook_date_formats() {\n return array(\n array(\n 'type' => 'mymodule_extra_long',\n 'format' => 'l jS F Y H:i:s e',\n 'locales' => array('en-ie'),\n ),\n array(\n 'type' => 'mymodule_extra_long',\n 'format' => 'l jS F Y h:i:sa',\n 'locales' => array('en', 'en-us'),\n ),\n array(\n 'type' => 'short',\n 'format' => 'F Y',\n 'locales' => array(),\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e1964125e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_authorized_init/7.x", "instruction": "Implement `system_authorized_init($callback, $file, $arguments = array(), $page_title = NULL)` in PHP for Drupal 7. Required behavior: Setup a given callback to run via authorize.php with elevated privileges.", "context": "To use authorize.php, certain variables must be stashed into $_SESSION. This function sets up all the necessary $_SESSION variables. The calling function should then redirect to authorize.php, using the full path returned by system_authorized_get_url(). That initiates the workflow that will eventually lead to the callback being invoked. The callback will be invoked at a low bootstrap level, without all modules being invoked, so it needs to be careful not to assume any code exists. Example (system_authorized_run()):\n\nParameters:\n- $callback: The name of the function to invoke once the user authorizes the operation.\n- $file: The full path to the file where the callback function is implemented.\n- $arguments: Optional array of arguments to pass into the callback when it is invoked. Note that the first argument to the callback is always the FileTransfer object created by authorize.php when the user authorizes the operation.\n- $page_title: Optional string to use as the page title once redirected to authorize.php.\n\nReturns: Nothing, this function just initializes variables in the user's session.\n\nFile: modules/system/system.module", "response": "function system_authorized_init($callback, $file, $arguments = array(), $page_title = NULL) {\n // First, figure out what file transfer backends the site supports, and put\n // all of those in the SESSION so that authorize.php has access to all of\n // them via the class autoloader, even without a full bootstrap.\n $_SESSION['authorize_filetransfer_info'] = drupal_get_filetransfer_info();\n\n // Now, define the callback to invoke.\n $_SESSION['authorize_operation'] = array(\n 'callback' => $callback,\n 'file' => $file,\n 'arguments' => $arguments,\n );\n\n if (isset($page_title)) {\n $_SESSION['authorize_operation']['page_title'] = $page_title;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e263851d7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_get_normal_path/7.x", "instruction": "In Drupal 7, write the function `drupal_get_normal_path($path, $path_language = NULL)` (file includes/path.inc) so that it does the following: Given a path alias, return the internal path it represents.", "context": "Parameters:\n- $path: A Drupal path alias.\n- $path_language: An optional language code to look up the path in.\n\nReturns: The internal path represented by the alias, or the original alias if no internal path was found.\n\nFile: includes/path.inc", "response": "function drupal_get_normal_path($path, $path_language = NULL) {\n $original_path = $path;\n\n // Lookup the path alias first.\n if ($source = drupal_lookup_path('source', $path, $path_language)) {\n $path = $source;\n }\n\n // Allow other modules to alter the inbound URL. We cannot use drupal_alter()\n // here because we need to run hook_url_inbound_alter() in the reverse order\n // of hook_url_outbound_alter().\n foreach (array_reverse(module_implements('url_inbound_alter')) as $module) {\n $function = $module . '_url_inbound_alter';\n $function($path, $original_path, $path_language);\n }\n\n return $path;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e32051ea7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_settings_initialize/7.x", "instruction": "Implement `drupal_settings_initialize()` in PHP for Drupal 7. Required behavior: Sets the base URL, cookie domain, and session name from configuration.", "context": "File: includes/bootstrap.inc", "response": "function drupal_settings_initialize() {\n global $base_url, $base_path, $base_root;\n\n // Export these settings.php variables to the global namespace.\n global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url;\n $conf = array();\n\n if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) {\n include_once DRUPAL_ROOT . '/' . conf_path() . '/settings.php';\n }\n $is_https = drupal_is_https();\n\n if (isset($base_url)) {\n // Parse fixed base URL from settings.php.\n $parts = parse_url($base_url);\n if (!isset($parts['path'])) {\n $parts['path'] = '';\n }\n $base_path = $parts['path'] . '/';\n // Build $base_root (everything until first slash after \"scheme://\").\n $base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));\n }\n else {\n // Create base URL.\n $http_protocol = $is_https ? 'https' : 'http';\n $base_root = $http_protocol . '://' . $_SERVER['HTTP_HOST'];\n\n $base_url = $base_root;\n\n // $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not\n // be modified by a visitor.\n if ($dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/')) {\n $base_path = $dir;\n $base_url .= $base_path;\n $base_path .= '/';\n }\n else {\n $base_path = '/';\n }\n }\n $base_secure_url = str_replace('http://', 'https://', $base_url);\n $base_insecure_url = str_replace('https://', 'http://', $base_url);\n\n if ($cookie_domain) {\n // If the user specifies the cookie domain, also use it for session name.\n $session_name = $cookie_domain;\n }\n else {\n // Otherwise use $base_url as session name, without the protocol\n // to use the same session identifiers across HTTP and HTTPS.\n list( , $session_name) = explode('://', $base_url, 2);\n // HTTP_HOST can be modified by a visitor, but we already sanitized it in\n // drupal_environment_initialize().\n if (!empty($_SERVER['HTTP_HOST'])) {\n $cookie_domain = _drupal_get_cookie_domain($_SERVER['HTTP_HOST']);\n }\n\n // Drupal 7.83 included a security improvement whereby www. is no longer\n // stripped from the cookie domain. However, this can cause problems with\n // existing session cookies where some users are left unable to login. In\n // order to avoid that, prepend a leading dot to the session_name that was\n // derived from the base_url when a www. subdomain is in use.\n // @see https://www.drupal.org/project/drupal/issues/2522002\n if (strpos($session_name, 'www.') === 0) {\n $session_name = '.' . $session_name;\n }\n }\n // Per RFC 2109, cookie domains must contain at least one dot other than the\n // first. For hosts such as 'localhost' or IP Addresses we don't set a cookie domain.\n if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {\n ini_set('session.cookie_domain', $cookie_domain);\n }\n // To prevent session cookies from being hijacked, a user can configure the\n // SSL version of their website to only transfer session cookies via SSL by\n // using PHP's session.cookie_secure setting. The browser will then use two\n // separate session cookies for the HTTPS and HTTP versions of the site. So we\n // must use different session identifiers for HTTPS and HTTP to prevent a\n // cookie collision.\n if ($is_https) {\n ini_set('session.cookie_secure', TRUE);\n }\n $prefix = ini_get('session.cookie_secure') ? 'SSESS' : 'SESS';\n session_name($prefix . substr(hash('sha256', $session_name), 0, 32));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e5ae50b13", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_widget_form/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)` (modules/field/field.api.php): Return the form for a single field widget.", "context": "Field widget form elements should be based on the passed-in $element, which contains the base form element properties derived from the field configuration.\n\nField API will set the weight, field name and delta values for each form element. If there are multiple values for this field, the Field API will invoke this hook as many times as needed.\n\nNote that, depending on the context in which the widget is being included (regular entity form, field configuration form, advanced search form...), the values for $field and $instance might be different from the \"official\" definitions returned by field_info_field() and field_info_instance(). Examples: mono-value widget even if the field is multi-valued, non-required widget even if the field is 'required'...\n\nTherefore, the FAPI element callbacks (such as #process, #element_validate, #value_callback...) used by the widget cannot use the field_info_field() or field_info_instance() functions to retrieve the $field or $instance definitions they should operate on. The field_widget_field() and field_widget_instance() functions should be used instead to fetch the current working definitions from $form_state, where Field API stores them.\n\nAlternatively, hook_field_widget_form() can extract the needed specific properties from $field and $instance and set them as ad-hoc $element['#custom'] properties, for later use by its element callbacks.\n\nOther modules may alter the form element provided by this function using hook_field_widget_form_alter().\n\nParameters:\n- $form: The form structure where widgets are being attached to. This might be a full form structure, or a sub-element of a larger form.\n- $form_state: An associative array containing the current state of the form.\n- $field: The field structure.\n- $instance: The field instance.\n- $langcode: The language associated with $items.\n- $items: Array of default values for this field.\n- $delta: The order of this item in the array of subelements (0, 1, 2, etc).\n- $element: A form element array containing basic properties for the widget: - #entity_type: The name of the entity the field is attached to. - #bundle: The name of the field bundle the field is contained in. - #field_name: The name of the field. - #language: The language the field is being edited in. - #field_parents: The 'parents' space for the field in the form. Most widgets can simply overlook this property. This identifies the location where the field values are placed within $form_state['values'], and is used to access processing information for the field through the field_form_get_state() and field_form_set_state() functions. - #columns: A list of field storage columns of the field. - #title: The sanitized element label for the field instance, ready for output. - #description: The sanitized element description for the field instance, ready for output. - #required: A Boolean indicating whether the element value is required; for required multiple value fields, only the first widget's values are required. - #delta: The order of this item in the array of subelements; see $delta above.\n\nReturns: The form elements for a single widget for this field.\n\nFile: modules/field/field.api.php", "response": "function hook_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {\n $element += array(\n '#type' => $instance['widget']['type'],\n '#default_value' => isset($items[$delta]) ? $items[$delta] : '',\n );\n return array('value' => $element);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e6cda33ce", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21content_types.inc/function/node_type_form/7.x", "instruction": "In Drupal 7, write the function `node_type_form($form, &$form_state, $type = NULL)` (file modules/node/content_types.inc) so that it does the following: Form constructor for the node type editing form.", "context": "Parameters:\n- $type: (optional) An object representing the node type, when editing an existing node type.\n\nFile: modules/node/content_types.inc", "response": "function node_type_form($form, &$form_state, $type = NULL) {\n if (!isset($type->type)) {\n // This is a new type. Node module managed types are custom and unlocked.\n $type = node_type_set_defaults(array('custom' => 1, 'locked' => 0));\n }\n\n // Make the type object available to implementations of hook_form_alter.\n $form['#node_type'] = $type;\n\n $form['name'] = array(\n '#title' => t('Name'),\n '#type' => 'textfield',\n '#default_value' => $type->name,\n '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the Add new content page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),\n '#required' => TRUE,\n '#size' => 30,\n );\n\n $form['type'] = array(\n '#type' => 'machine_name',\n '#default_value' => $type->type,\n '#maxlength' => 32,\n '#disabled' => $type->locked,\n '#machine_name' => array(\n 'exists' => 'node_type_load',\n ),\n '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array(\n '%node-add' => t('Add new content'),\n )),\n );\n\n $form['description'] = array(\n '#title' => t('Description'),\n '#type' => 'textarea',\n '#default_value' => $type->description,\n '#description' => t('Describe this content type. The text will be displayed on the Add new content page.'),\n );\n\n $form['additional_settings'] = array(\n '#type' => 'vertical_tabs',\n '#attached' => array(\n 'js' => array(drupal_get_path('module', 'node') . '/content_types.js'),\n ),\n );\n\n $form['submission'] = array(\n '#type' => 'fieldset',\n '#title' => t('Submission form settings'),\n '#collapsible' => TRUE,\n '#group' => 'additional_settings',\n );\n $form['submission']['title_label'] = array(\n '#title' => t('Title field label'),\n '#type' => 'textfield',\n '#default_value' => $type->title_label,\n '#required' => TRUE,\n );\n if (!$type->has_title) {\n // Avoid overwriting a content type that intentionally does not have a\n // title field.\n $form['submission']['title_label']['#attributes'] = array('disabled' => 'disabled');\n $form['submission']['title_label']['#description'] = t('This content type does not have a title field.');\n $form['submission']['title_label']['#required'] = FALSE;\n }\n $form['submission']['node_preview'] = array(\n '#type' => 'radios',\n '#title' => t('Preview before submitting'),\n '#default_value' => variable_get('node_preview_' . $type->type, DRUPAL_OPTIONAL),\n '#options' => array(\n DRUPAL_DISABLED => t('Disabled'),\n DRUPAL_OPTIONAL => t('Optional'),\n DRUPAL_REQUIRED => t('Required'),\n ),\n );\n $form['submission']['help'] = array(\n '#type' => 'textarea',\n '#title' => t('Explanation or submission guidelines'),\n '#default_value' => $type->help,\n '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'),\n );\n $form['workflow'] = array(\n '#type' => 'fieldset',\n '#title' => t('Publishing options'),\n '#collapsible' => TRUE,\n '#collapsed' => TRUE,\n '#group' => 'additional_settings',\n );\n $form['workflow']['node_options'] = array('#type' => 'checkboxes',\n '#title' => t('Default options'),\n '#default_value' => variable_get('node_options_' . $type->type, array('status', 'promote')),\n '#options' => array(\n 'status' => t('Published'),\n 'promote' => t('Promoted to front page'),\n 'sticky' => t('Sticky at top of lists'),\n 'revision' => t('Create new revision'),\n ),\n '#description' => t('Users with the Administer content permission will be able to override these options.'),\n );\n $form['display'] = array(\n '#type' => 'fieldset',\n '#title' => t('Display settings'),\n '#collapsible' => TRUE,\n '#collapsed' => TRUE,\n '#group' => 'additional_settings',\n );\n $form['display']['node_submitted'] = array(\n '#type' => 'checkbox',\n '#title' => t('Display author and date information.'),\n '#default_value' => variable_get('node_submitted_' . $type->type, TRUE),\n '#description' => t('Author username and publish date will be displayed.'),\n );\n $form['old_type'] = array(\n '#type' => 'value',\n '#value' => $type->type,\n );\n $form['orig_type'] = array(\n '#type' => 'value',\n '#value' => isset($type->orig_type) ? $type->orig_type : '',\n );\n $form['base'] = array(\n '#type' => 'value',\n '#value' => $type->base,\n );\n $form['custom'] = array(\n '#type' => 'value',\n '#value' => $type->custom,\n );\n $form['modified'] = array(\n '#type' => 'value',\n '#value' => $type->modified,\n );\n $form['locked'] = array(\n '#type' => 'value',\n '#value' => $type->locked,\n );\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save content type'),\n '#weight' => 40,\n );\n\n if ($type->custom) {\n if (!empty($type->type)) {\n $form['actions']['delete'] = array(\n '#type' => 'submit',\n '#value' => t('Delete content type'),\n '#weight' => 45,\n );\n }\n }\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e7d64aadc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/template_preprocess_aggregator_feed_source/7.x", "instruction": "In Drupal 7, write the function `template_preprocess_aggregator_feed_source(&$variables)` (file modules/aggregator/aggregator.pages.inc) so that it does the following: Processes variables for aggregator-feed-source.tpl.php.", "context": "File: modules/aggregator/aggregator.pages.inc", "response": "function template_preprocess_aggregator_feed_source(&$variables) {\n $feed = $variables['feed'];\n\n $variables['source_icon'] = theme('feed_icon', array('url' => $feed->url, 'title' => t('!title feed', array('!title' => $feed->title))));\n\n if (!empty($feed->image) && !empty($feed->title) && !empty($feed->link)) {\n $variables['source_image'] = l(theme('image', array('path' => $feed->image, 'alt' => $feed->title)), $feed->link, array('html' => TRUE, 'attributes' => array('class' => 'feed-image')));\n }\n else {\n $variables['source_image'] = '';\n }\n\n $variables['source_description'] = aggregator_filter_xss($feed->description);\n $variables['source_url'] = check_url(url($feed->link, array('absolute' => TRUE)));\n\n if ($feed->checked) {\n $variables['last_checked'] = t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->checked)));\n }\n else {\n $variables['last_checked'] = t('never');\n }\n\n if (user_access('administer news feeds')) {\n $variables['last_checked'] = l($variables['last_checked'], 'admin/config/services/aggregator');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e7e8766f4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_search_execute/7.x", "instruction": "I need the code for `node_search_execute($keys = NULL, $conditions = NULL)` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_search_execute().", "context": "File: modules/node/node.module", "response": "function node_search_execute($keys = NULL, $conditions = NULL) {\n // Build matching conditions\n $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');\n $query->join('node', 'n', 'n.nid = i.sid');\n $query\n ->condition('n.status', 1)\n ->addTag('node_access')\n ->searchExpression($keys, 'node');\n\n // Insert special keywords.\n $query->setOption('type', 'n.type');\n $query->setOption('language', 'n.language');\n if ($query->setOption('term', 'ti.tid')) {\n $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');\n }\n // Only continue if the first pass query matches.\n if (!$query->executeFirstPass()) {\n return array();\n }\n\n // Add the ranking expressions.\n _node_rankings($query);\n\n // Load results.\n $find = $query\n ->limit(10)\n ->execute();\n $results = array();\n foreach ($find as $item) {\n // Render the node.\n $node = node_load($item->sid);\n $build = node_view($node, 'search_result');\n unset($build['#theme']);\n $node->rendered = drupal_render($build);\n\n // Fetch comments for snippet.\n $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);\n\n $extra = module_invoke_all('node_search_result', $node);\n\n $uri = entity_uri('node', $node);\n $results[] = array(\n 'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE))),\n 'type' => check_plain(node_type_get_name($node)),\n 'title' => $node->title,\n 'user' => theme('username', array('account' => $node)),\n 'date' => $node->changed,\n 'node' => $node,\n 'extra' => $extra,\n 'score' => $item->calculated_score,\n 'snippet' => search_excerpt($keys, $node->rendered),\n 'language' => entity_language('node', $node),\n );\n }\n return $results;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1e8842c279", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21php%21php.module/function/php_filter_info/7.x", "instruction": "In Drupal 7, write the function `php_filter_info()` (file modules/php/php.module) so that it does the following: Implements hook_filter_info().", "context": "Provide PHP code filter. Use with care.\n\nFile: modules/php/php.module", "response": "function php_filter_info() {\n $filters['php_code'] = array(\n 'title' => t('PHP evaluator'),\n 'description' => t('Executes a piece of PHP code. The usage of this filter should be restricted to administrators only!'),\n 'process callback' => 'php_eval',\n 'tips callback' => '_php_filter_tips',\n 'cache' => FALSE,\n );\n return $filters;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ead6603c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/openid_redirect_http/7.x", "instruction": "In Drupal 7, write the function `openid_redirect_http($url, $message)` (file modules/openid/openid.inc) so that it does the following: Performs an HTTP 302 redirect (for the 1.x protocol).", "context": "File: modules/openid/openid.inc", "response": "function openid_redirect_http($url, $message) {\n $query = array();\n foreach ($message as $key => $val) {\n $query[] = $key . '=' . urlencode($val);\n }\n\n $sep = (strpos($url, '?') === FALSE) ? '?' : '&';\n header('Location: ' . $url . $sep . implode('&', $query), TRUE, 302);\n\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1edeb8e327", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_list/7.x", "instruction": "Implement `image_style_list()` in PHP for Drupal 7. Required behavior: Menu callback; Listing of all current image styles.", "context": "File: modules/image/image.admin.inc", "response": "function image_style_list() {\n $page = array();\n\n $styles = image_styles();\n $page['image_style_list'] = array(\n '#markup' => theme('image_style_list', array('styles' => $styles)),\n '#attached' => array(\n 'css' => array(drupal_get_path('module', 'image') . '/image.admin.css' => array()),\n ),\n );\n\n return $page;\n\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ef0b5e478", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_get_controller/7.x", "instruction": "Implement `entity_get_controller($entity_type)` in PHP for Drupal 7. Required behavior: Gets the entity controller for an entity type.", "context": "Returns: DrupalEntityControllerInterface The entity controller object for the specified entity type.\n\nFile: includes/common.inc", "response": "function entity_get_controller($entity_type) {\n $controllers = &drupal_static(__FUNCTION__, array());\n if (!isset($controllers[$entity_type])) {\n $type_info = entity_get_info($entity_type);\n // Explicitly fail for malformed entities missing a valid controller class.\n if (!isset($type_info['controller class']) || !class_exists($class = $type_info['controller class'])) {\n throw new EntityMalformedException(t('Missing or non-existent controller class on entity of type @entity_type.', array('@entity_type' => $entity_type)));\n }\n $controllers[$entity_type] = new $class($entity_type);\n }\n return $controllers[$entity_type];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1f17bff3c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_admin_content/7.x", "instruction": "Implement `node_admin_content($form, $form_state)` in PHP for Drupal 7. Required behavior: Page callback: Form constructor for the content administration form.", "context": "File: modules/node/node.admin.inc", "response": "function node_admin_content($form, $form_state) {\n if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {\n return node_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['nodes']));\n }\n $form['filter'] = node_filter_form();\n $form['#submit'][] = 'node_filter_form_submit';\n $form['admin'] = node_admin_nodes();\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1f183c0a95", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_cache_clear_all/7.x", "instruction": "I need the code for `menu_cache_clear_all()` in Drupal 7 (includes/menu.inc). It must do this: Clears all cached menu data.", "context": "This should be called any time broad changes might have been made to the router items or menu links.\n\nFile: includes/menu.inc", "response": "function menu_cache_clear_all() {\n cache_clear_all('*', 'cache_menu', TRUE);\n menu_reset_static_cache();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1f4c865681", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_multilingual/7.x", "instruction": "In Drupal 7, write the function `drupal_multilingual()` (file includes/bootstrap.inc) so that it does the following: Returns TRUE if there is more than one language enabled.", "context": "Returns: TRUE if more than one language is enabled.\n\nFile: includes/bootstrap.inc", "response": "function drupal_multilingual() {\n // The \"language_count\" variable stores the number of enabled languages to\n // avoid unnecessarily querying the database when building the list of\n // enabled languages on monolingual sites.\n return variable_get('language_count', 1) > 1;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1f844d4a68", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_form_field_ui_field_edit_form_submit/7.x", "instruction": "In Drupal 7, write the function `user_form_field_ui_field_edit_form_submit($form, &$form_state)` (file modules/user/user.module) so that it does the following: Additional submit handler for the 'Edit field instance' form.", "context": "Make sure the 'user_register_form' setting is set for required fields.\n\nFile: modules/user/user.module", "response": "function user_form_field_ui_field_edit_form_submit($form, &$form_state) {\n $instance = $form_state['values']['instance'];\n\n if (!empty($instance['required'])) {\n form_set_value($form['instance']['settings']['user_register_form'], 1, $form_state);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1f988ee2aa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_settings_form_submit/7.x", "instruction": "In Drupal 7, write the function `install_settings_form_submit($form, &$form_state)` (file includes/install.core.inc) so that it does the following: Form submission handler for install_settings_form().", "context": "File: includes/install.core.inc", "response": "function install_settings_form_submit($form, &$form_state) {\n global $install_state;\n\n // Update global settings array and save.\n $settings['databases'] = array(\n 'value' => array('default' => array('default' => $form_state['storage']['database'])),\n 'required' => TRUE,\n );\n $settings['drupal_hash_salt'] = array(\n 'value' => drupal_random_key(),\n 'required' => TRUE,\n );\n drupal_rewrite_settings($settings);\n // Indicate that the settings file has been verified, and check the database\n // for the last completed task, now that we have a valid connection. This\n // last step is important since we want to trigger an error if the new\n // database already has Drupal installed.\n $install_state['settings_verified'] = TRUE;\n $install_state['completed_task'] = install_verify_completed_task();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1fae97e3d3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_multiple_delete_confirm/7.x", "instruction": "I need the code for `node_multiple_delete_confirm($form, &$form_state, $nodes)` in Drupal 7 (modules/node/node.admin.inc). It must do this: Multiple node deletion confirmation form for node_admin_content().", "context": "File: modules/node/node.admin.inc", "response": "function node_multiple_delete_confirm($form, &$form_state, $nodes) {\n $form['nodes'] = array('#prefix' => '
              ', '#suffix' => '
            ', '#tree' => TRUE);\n // array_filter returns only elements with TRUE values\n foreach ($nodes as $nid => $value) {\n $title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();\n $form['nodes'][$nid] = array(\n '#type' => 'hidden',\n '#value' => $nid,\n '#prefix' => '
          2. ',\n '#suffix' => check_plain($title) . \"
          3. \\n\",\n );\n }\n $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');\n $form['#submit'][] = 'node_multiple_delete_confirm_submit';\n $confirm_question = format_plural(count($nodes),\n 'Are you sure you want to delete this item?',\n 'Are you sure you want to delete these items?');\n return confirm_form($form,\n $confirm_question,\n 'admin/content', t('This action cannot be undone.'),\n t('Delete'), t('Cancel'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1faf9be98f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_edit_form/7.x", "instruction": "I need the code for `locale_languages_edit_form($form, &$form_state, $langcode)` in Drupal 7 (modules/locale/locale.admin.inc). It must do this: Editing screen for a particular language.", "context": "Parameters:\n- $langcode: Language code of the language to edit.\n\nFile: modules/locale/locale.admin.inc", "response": "function locale_languages_edit_form($form, &$form_state, $langcode) {\n if ($language = db_query(\"SELECT * FROM {languages} WHERE language = :language\", array(':language' => $langcode))->fetchObject()) {\n _locale_languages_common_controls($form, $language);\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save language')\n );\n $form['#submit'][] = 'locale_languages_edit_form_submit';\n $form['#validate'][] = 'locale_languages_edit_form_validate';\n return $form;\n }\n else {\n drupal_not_found();\n drupal_exit();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1fe399f35b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/template_preprocess_overlay/7.x", "instruction": "Implement `template_preprocess_overlay(&$variables)` in PHP for Drupal 7. Required behavior: Implements template_preprocess_HOOK() for overlay.tpl.php", "context": "If the current page request is inside the overlay, add appropriate classes to the element, and simplify the page title.\n\nFile: modules/overlay/overlay.module", "response": "function template_preprocess_overlay(&$variables) {\n $variables['tabs'] = menu_primary_local_tasks();\n $variables['title'] = drupal_get_title();\n $variables['disable_overlay'] = overlay_disable_message();\n $variables['content_attributes_array']['class'][] = 'clearfix';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1fe5bea880", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/theme_system_date_time_settings/7.x", "instruction": "I need the code for `theme_system_date_time_settings($variables)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Returns HTML for the date settings form.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/system/system.admin.inc", "response": "function theme_system_date_time_settings($variables) {\n $form = $variables['form'];\n $header = array(\n t('Date type'),\n t('Format'),\n t('Operations'),\n );\n\n foreach (element_children($form['format']) as $key) {\n $delete_key = $key . '_delete';\n $row = array();\n $row[] = $form['format'][$key]['#title'];\n $form['format'][$key]['#title_display'] = 'invisible';\n $row[] = array('data' => drupal_render($form['format'][$key]));\n $row[] = array('data' => drupal_render($form['delete'][$delete_key]));\n $rows[] = $row;\n }\n\n $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'system-date-types')));\n $output .= drupal_render_children($form);\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ff1ac976e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_configure_form/7.x", "instruction": "In Drupal 7, write the function `locale_languages_configure_form()` (file modules/locale/locale.admin.inc) so that it does the following: Setting for language negotiation options", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_languages_configure_form() {\n include_once DRUPAL_ROOT . '/includes/language.inc';\n\n $form = array(\n '#submit' => array('locale_languages_configure_form_submit'),\n '#theme' => 'locale_languages_configure_form',\n '#language_types' => language_types_configurable(FALSE),\n '#language_types_info' => language_types_info(),\n '#language_providers' => language_negotiation_info(),\n );\n\n foreach ($form['#language_types'] as $type) {\n _locale_languages_configure_form_language_table($form, $type);\n }\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save settings'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-1ff3c8039b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/_system_date_format_types_build/7.x", "instruction": "I need the code for `_system_date_format_types_build()` in Drupal 7 (modules/system/system.module). It must do this: Builds and returns information about available date types.", "context": "Returns: An associative array of date type information keyed by name. Each date type information array has the following elements: - type: The machine-readable name of the date type. - title: The human-readable name of the date type. - locked: A boolean indicating whether or not this date type should be configurable from the user interface. - module: The name of the module that defined this format in its hook_date_format_types(). An empty string if the format was user-defined. - is_new: A boolean indicating whether or not this date type is as of yet unsaved in the database.\n\nFile: modules/system/system.module", "response": "function _system_date_format_types_build() {\n $types = array();\n\n // Get list of modules that implement hook_date_format_types().\n $modules = module_implements('date_format_types');\n\n foreach ($modules as $module) {\n $module_types = module_invoke($module, 'date_format_types');\n foreach ($module_types as $module_type => $type_title) {\n $type = array();\n $type['module'] = $module;\n $type['type'] = $module_type;\n $type['title'] = $type_title;\n $type['locked'] = 1;\n // Will be over-ridden later if in the db.\n $type['is_new'] = TRUE;\n $types[$module_type] = $type;\n }\n }\n\n // Get custom formats added to the database by the end user.\n $result = db_query('SELECT dft.type, dft.title, dft.locked FROM {date_format_type} dft ORDER BY dft.title');\n foreach ($result as $record) {\n if (!isset($types[$record->type])) {\n $type = array();\n $type['is_new'] = FALSE;\n $type['module'] = '';\n $type['type'] = $record->type;\n $type['title'] = $record->title;\n $type['locked'] = $record->locked;\n $types[$record->type] = $type;\n }\n else {\n $type = array();\n $type['is_new'] = FALSE; // Over-riding previous setting.\n $types[$record->type] = array_merge($types[$record->type], $type);\n }\n }\n\n // Allow other modules to modify these date types.\n drupal_alter('date_format_types', $types);\n\n return $types;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-201f9f18c4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_theme/7.x", "instruction": "Implement `aggregator_theme()` in PHP for Drupal 7. Required behavior: Implements hook_theme().", "context": "File: modules/aggregator/aggregator.module", "response": "function aggregator_theme() {\n return array(\n 'aggregator_wrapper' => array(\n 'variables' => array('content' => NULL),\n 'file' => 'aggregator.pages.inc',\n 'template' => 'aggregator-wrapper',\n ),\n 'aggregator_categorize_items' => array(\n 'render element' => 'form',\n 'file' => 'aggregator.pages.inc',\n ),\n 'aggregator_feed_source' => array(\n 'variables' => array('feed' => NULL),\n 'file' => 'aggregator.pages.inc',\n 'template' => 'aggregator-feed-source',\n ),\n 'aggregator_block_item' => array(\n 'variables' => array('item' => NULL, 'feed' => 0),\n ),\n 'aggregator_summary_items' => array(\n 'variables' => array('summary_items' => NULL, 'source' => NULL),\n 'file' => 'aggregator.pages.inc',\n 'template' => 'aggregator-summary-items',\n ),\n 'aggregator_summary_item' => array(\n 'variables' => array('item' => NULL),\n 'file' => 'aggregator.pages.inc',\n 'template' => 'aggregator-summary-item',\n ),\n 'aggregator_item' => array(\n 'variables' => array('item' => NULL),\n 'file' => 'aggregator.pages.inc',\n 'template' => 'aggregator-item',\n ),\n 'aggregator_page_opml' => array(\n 'variables' => array('feeds' => NULL),\n 'file' => 'aggregator.pages.inc',\n ),\n 'aggregator_page_rss' => array(\n 'variables' => array('feeds' => NULL, 'category' => NULL),\n 'file' => 'aggregator.pages.inc',\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-203c93ced0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_storage_settings/7.x", "instruction": "In Drupal 7, write the function `field_info_storage_settings($type)` (file modules/field/field.info.inc) so that it does the following: Returns a field storage type's default settings.", "context": "Parameters:\n- $type: A field storage type name.\n\nReturns: The storage type's default settings, as provided by hook_field_storage_info(), or an empty array if type or settings are undefined.\n\nFile: modules/field/field.info.inc", "response": "function field_info_storage_settings($type) {\n $info = field_info_storage_types($type);\n return isset($info['settings']) ? $info['settings'] : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-203d869885", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_delete/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items)` (modules/field/field.api.php): Define custom delete behavior for this module's field data.", "context": "This hook is invoked from field_attach_delete() on the module that defines a field, during the process of deleting an entity object (node, taxonomy term, etc.). It is invoked just before the data for this field on the particular entity object is deleted from field storage. Only field modules that are storing or tracking information outside the standard field storage mechanism need to implement this hook.\n\nParameters:\n- $entity_type: The type of $entity.\n- $entity: The entity for the operation.\n- $field: The field structure for the operation.\n- $instance: The instance structure for $field on $entity's bundle.\n- $langcode: The language associated with $items.\n- $entity ($items): ->{$field['field_name']}[$langcode], or an empty array if unset.\n\nFile: modules/field/field.api.php", "response": "function hook_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n foreach ($items as $delta => $item) {\n // For hook_file_references(), remember that this is being deleted.\n $item['file_field_name'] = $field['field_name'];\n // Pass in the ID of the object that is being removed so all references can\n // be counted in hook_file_references().\n $item['file_field_type'] = $entity_type;\n $item['file_field_id'] = $id;\n file_field_delete_file($item, $field, $entity_type, $id);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-20634b279c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/template_preprocess_poll_results/7.x", "instruction": "In Drupal 7, write the function `template_preprocess_poll_results(&$variables)` (file modules/poll/poll.module) so that it does the following: Preprocess the poll_results theme hook.", "context": "Inputs: $raw_title, $results, $votes, $raw_links, $block, $nid, $vote. The $raw_* inputs to this are naturally unsafe; often safe versions are made to simply overwrite the raw version, but in this case it seems likely that the title and the links may be overridden by the theme layer, so they are left in with a different name for that purpose.\n\nFile: modules/poll/poll.module", "response": "function template_preprocess_poll_results(&$variables) {\n $variables['links'] = theme('links__poll_results', array('links' => $variables['raw_links']));\n if (isset($variables['vote']) && $variables['vote'] > -1 && user_access('cancel own vote')) {\n $elements = drupal_get_form('poll_cancel_form', $variables['nid']);\n $variables['cancel_form'] = drupal_render($elements);\n }\n $variables['title'] = check_plain($variables['raw_title']);\n\n if ($variables['block']) {\n $variables['theme_hook_suggestions'][] = 'poll_results__block';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-208a56bc62", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_help/7.x", "instruction": "Implement `number_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/field/modules/number/number.module", "response": "function number_help($path, $arg) {\n switch ($path) {\n case 'admin/help#number':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Number module defines various numeric field types for the Field module. Numbers can be in integer, decimal, or floating-point form, and they can be formatted when displayed. Number fields can be limited to a specific set of input values or to a range of values. See the Field module help page for more information about fields.', array('@field-help' => url('admin/help/field'))) . '

            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-209b66eecc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_confirm_delete/7.x", "instruction": "Implement `forum_confirm_delete($form, &$form_state, $tid)` in PHP for Drupal 7. Required behavior: Form constructor for confirming deletion of a forum taxonomy term.", "context": "Parameters:\n- $tid: ID of the term to be deleted.\n\nFile: modules/forum/forum.admin.inc", "response": "function forum_confirm_delete($form, &$form_state, $tid) {\n $term = taxonomy_term_load($tid);\n\n $form['tid'] = array('#type' => 'value', '#value' => $tid);\n $form['name'] = array('#type' => 'value', '#value' => $term->name);\n\n return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/structure/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit content administration first. This action cannot be undone.', array('@content' => url('admin/content'))), t('Delete'), t('Cancel'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-209ea162f2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_7001/7.x", "instruction": "I need the code for `forum_update_7001()` in Drupal 7 (modules/forum/forum.install). It must do this: Create new {forum_index} table.", "context": "File: modules/forum/forum.install", "response": "function forum_update_7001() {\n $forum_index = array(\n 'description' => 'Maintains denormalized information about node/term relationships.',\n 'fields' => array(\n 'nid' => array(\n 'description' => 'The {node}.nid this record tracks.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'title' => array(\n 'description' => 'The title of this node, always treated as non-markup plain text.',\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n ),\n 'tid' => array(\n 'description' => 'The term ID.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'sticky' => array(\n 'description' => 'Boolean indicating whether the node is sticky.',\n 'type' => 'int',\n 'not null' => FALSE,\n 'default' => 0,\n 'size' => 'tiny',\n ),\n 'created' => array(\n 'description' => 'The Unix timestamp when the node was created.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default'=> 0,\n ),\n 'last_comment_timestamp' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',\n ),\n 'comment_count' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The total number of comments on this node.',\n ),\n ),\n 'indexes' => array(\n 'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),\n ),\n 'foreign keys' => array(\n 'tracked_node' => array(\n 'table' => 'node',\n 'columns' => array('nid' => 'nid'),\n ),\n 'term' => array(\n 'table' => 'taxonomy_term_data',\n 'columns' => array(\n 'tid' => 'tid',\n ),\n ),\n ),\n );\n db_create_table('forum_index', $forum_index);\n\n $select = db_select('node', 'n');\n $forum_alias = $select->join('forum', 'f', 'n.vid = f.vid');\n $ncs_alias = $select->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');\n $select\n ->fields('n', array('nid', 'title', 'sticky', 'created'))\n ->fields($forum_alias, array('tid'))\n ->fields($ncs_alias, array('last_comment_timestamp', 'comment_count'));\n\n db_insert('forum_index')\n ->fields(array('nid', 'title', 'sticky', 'created', 'tid', 'last_comment_timestamp', 'comment_count'))\n ->from($select)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-210004b873", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_transform_dimensions/7.x", "instruction": "I need the code for `image_style_transform_dimensions($style_name, array &$dimensions)` in Drupal 7 (modules/image/image.module). It must do this: Determines the dimensions of the styled image.", "context": "Applies all of an image style's effects to $dimensions.\n\nParameters:\n- $style_name: The name of the style to be applied.\n- $dimensions: Dimensions to be modified - an array with components width and height, in pixels.\n\nFile: modules/image/image.module", "response": "function image_style_transform_dimensions($style_name, array &$dimensions) {\n module_load_include('inc', 'image', 'image.effects');\n $style = image_style_load($style_name);\n\n if (!is_array($style)) {\n return;\n }\n\n foreach ($style['effects'] as $effect) {\n if (isset($effect['dimensions passthrough'])) {\n continue;\n }\n\n if (isset($effect['dimensions callback'])) {\n $effect['dimensions callback']($dimensions, $effect['data']);\n }\n else {\n $dimensions['width'] = $dimensions['height'] = NULL;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-211599db60", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_create_bundle/7.x", "instruction": "Give me the example code for `hook_field_attach_create_bundle($entity_type, $bundle)` in Drupal 7. Hook description: Act on field_attach_create_bundle().", "context": "This hook is invoked after the field module has performed the operation.\n\nSee field_attach_create_bundle() for details and arguments.\n\nFile: modules/field/field.api.php", "response": "function hook_field_attach_create_bundle($entity_type, $bundle) {\n // When a new bundle is created, the menu needs to be rebuilt to add the\n // Field UI menu item tabs.\n variable_set('menu_rebuild_needed', TRUE);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-21166ab29b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_page_header/7.x", "instruction": "I need the code for `drupal_page_header()` in Drupal 7 (includes/bootstrap.inc). It must do this: Sets HTTP headers in preparation for a page response.", "context": "Authenticated users are always given a 'no-cache' header, and will fetch a fresh page on every request. This prevents authenticated users from seeing locally cached pages.\n\nETag and Last-Modified headers are not set per default for authenticated users so that browsers do not send If-Modified-Since headers from authenticated user pages. drupal_serve_page_from_cache() will set appropriate ETag and Last-Modified headers for cached pages.\n\nFile: includes/bootstrap.inc", "response": "function drupal_page_header() {\n $headers_sent = &drupal_static(__FUNCTION__, FALSE);\n if ($headers_sent) {\n return TRUE;\n }\n $headers_sent = TRUE;\n\n $default_headers = array(\n 'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT',\n 'Cache-Control' => 'no-cache, must-revalidate',\n // Prevent browsers from sniffing a response and picking a MIME type\n // different from the declared content-type, since that can lead to\n // XSS and other vulnerabilities.\n 'X-Content-Type-Options' => 'nosniff',\n );\n drupal_send_headers($default_headers);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-213fb5f65b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.admin.inc/function/path_admin_form_delete_submit/7.x", "instruction": "I need the code for `path_admin_form_delete_submit($form, &$form_state)` in Drupal 7 (modules/path/path.admin.inc). It must do this: Form submission handler for the 'Delete' button on path_admin_form().", "context": "File: modules/path/path.admin.inc", "response": "function path_admin_form_delete_submit($form, &$form_state) {\n $destination = array();\n if (isset($_GET['destination'])) {\n $destination = drupal_get_destination();\n unset($_GET['destination']);\n }\n $form_state['redirect'] = array('admin/config/search/path/delete/' . $form_state['values']['pid'], array('query' => $destination));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2160d10809", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/batch_get/7.x", "instruction": "Implement `&batch_get()` in PHP for Drupal 7. Required behavior: Retrieves the current batch.", "context": "File: includes/form.inc", "response": "function &batch_get() {\n // Not drupal_static(), because Batch API operates at a lower level than most\n // use-cases for resetting static variables, and we specifically do not want a\n // global drupal_static_reset() resetting the batch information. Functions\n // that are part of the Batch API and need to reset the batch information may\n // call batch_get() and manipulate the result by reference. Functions that are\n // not part of the Batch API can also do this, but shouldn't.\n static $batch = array();\n return $batch;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2168ef670d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_widget_value/7.x", "instruction": "I need the code for `file_field_widget_value($element, $input = FALSE, $form_state = array())` in Drupal 7 (modules/file/file.field.inc). It must do this: The #value_callback for the file_generic field element.", "context": "File: modules/file/file.field.inc", "response": "function file_field_widget_value($element, $input = FALSE, $form_state = array()) {\n if ($input) {\n // Checkboxes lose their value when empty.\n // If the display field is present make sure its unchecked value is saved.\n $field = field_widget_field($element, $form_state);\n if (empty($input['display'])) {\n $input['display'] = !empty($field['settings']['display_field']) ? 0 : 1;\n }\n }\n\n // We depend on the managed file element to handle uploads.\n $return = file_managed_file_value($element, $input, $form_state);\n\n // Ensure that all the required properties are returned even if empty.\n $return += array(\n 'fid' => 0,\n 'display' => 1,\n 'description' => '',\n );\n\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-218a34a835", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_custom_form/7.x", "instruction": "Implement `locale_languages_custom_form($form)` in PHP for Drupal 7. Required behavior: Custom language addition form.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_languages_custom_form($form) {\n $form['custom language'] = array('#type' => 'fieldset',\n '#title' => t('Custom language'),\n '#collapsible' => TRUE,\n '#collapsed' => TRUE,\n );\n _locale_languages_common_controls($form['custom language']);\n $form['custom language']['actions'] = array('#type' => 'actions');\n $form['custom language']['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Add custom language')\n );\n // Reuse the validation and submit functions of the predefined language setup form.\n $form['#submit'][] = 'locale_languages_predefined_form_submit';\n $form['#validate'][] = 'locale_languages_predefined_form_validate';\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21a012a6a6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_get_complete_schema/7.x", "instruction": "In Drupal 7, write the function `drupal_get_complete_schema($rebuild = FALSE)` (file includes/bootstrap.inc) so that it does the following: Gets the whole database schema.", "context": "The returned schema will include any modifications made by any module that implements hook_schema_alter().\n\nParameters:\n- $rebuild: If true, the schema will be rebuilt instead of retrieved from the cache.\n\nFile: includes/bootstrap.inc", "response": "function drupal_get_complete_schema($rebuild = FALSE) {\n static $schema = array();\n\n if (empty($schema) || $rebuild) {\n // Try to load the schema from cache.\n if (!$rebuild && $cached = cache_get('schema')) {\n $schema = $cached->data;\n }\n // Otherwise, rebuild the schema cache.\n else {\n $schema = array();\n // Load the .install files to get hook_schema.\n // On some databases this function may be called before bootstrap has\n // been completed, so we force the functions we need to load just in case.\n if (function_exists('module_load_all_includes')) {\n // This function can be called very early in the bootstrap process, so\n // we force the module_list() cache to be refreshed to ensure that it\n // contains the complete list of modules before we go on to call\n // module_load_all_includes().\n module_list(TRUE);\n module_load_all_includes('install');\n }\n\n require_once DRUPAL_ROOT . '/includes/common.inc';\n // Invoke hook_schema for all modules.\n foreach (module_implements('schema') as $module) {\n // Cast the result of hook_schema() to an array, as a NULL return value\n // would cause array_merge() to set the $schema variable to NULL as well.\n // That would break modules which use $schema further down the line.\n $current = (array) module_invoke($module, 'schema');\n // Set 'module' and 'name' keys for each table, and remove descriptions,\n // as they needlessly slow down cache_get() for every single request.\n _drupal_schema_initialize($current, $module);\n $schema = array_merge($schema, $current);\n }\n\n drupal_alter('schema', $schema);\n // If the schema is empty, avoid saving it: some database engines require\n // the schema to perform queries, and this could lead to infinite loops.\n if (!empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) {\n cache_set('schema', $schema);\n }\n if ($rebuild) {\n cache_clear_all('schema:', 'cache', TRUE);\n }\n }\n }\n\n return $schema;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21a0c55848", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_translated_menu_link_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_translated_menu_link_alter(&$item, $map)` (modules/system/system.api.php): Alter a menu link after it has been translated and before it is rendered.", "context": "This hook is invoked from _menu_link_translate() after a menu link has been translated; i.e., after dynamic path argument placeholders (%) have been replaced with actual values, the user access to the link's target page has been checked, and the link has been localized. It is only invoked if $item['options']['alter'] has been set to a non-empty value (e.g., TRUE). This flag should be set using hook_menu_link_alter().\n\nImplementations of this hook are able to alter any property of the menu link. For example, this hook may be used to add a page-specific query string to all menu links, or hide a certain link by setting:\n\nParameters:\n- $item: Associative array defining a menu link after _menu_link_translate()\n- $map: Associative array containing the menu $map (path parts and/or objects).\n\nFile: modules/system/system.api.php", "response": "function hook_translated_menu_link_alter(&$item, $map) {\n if ($item['href'] == 'devel/cache/clear') {\n $item['localized_options']['query'] = drupal_get_destination();\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-21a19b217d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_save/7.x", "instruction": "In Drupal 7, write the function `node_save($node)` (file modules/node/node.module) so that it does the following: Saves changes to a node or adds a new node.", "context": "Parameters:\n- $node: The $node object to be saved. If $node->nid is omitted (or $node->is_new is TRUE), a new node will be added.\n\nFile: modules/node/node.module", "response": "function node_save($node) {\n $transaction = db_transaction();\n\n try {\n // Load the stored entity, if any.\n if (!empty($node->nid) && !isset($node->original)) {\n $node->original = entity_load_unchanged('node', $node->nid);\n }\n\n field_attach_presave('node', $node);\n global $user;\n\n // Determine if we will be inserting a new node.\n if (!isset($node->is_new)) {\n $node->is_new = empty($node->nid);\n }\n\n // Set the timestamp fields.\n if (empty($node->created)) {\n $node->created = REQUEST_TIME;\n }\n // The changed timestamp is always updated for bookkeeping purposes,\n // for example: revisions, searching, etc.\n $node->changed = REQUEST_TIME;\n\n $node->timestamp = REQUEST_TIME;\n $update_node = TRUE;\n\n // Let modules modify the node before it is saved to the database.\n module_invoke_all('node_presave', $node);\n module_invoke_all('entity_presave', $node, 'node');\n\n if ($node->is_new || !empty($node->revision)) {\n // When inserting either a new node or a new node revision, $node->log\n // must be set because {node_revision}.log is a text column and therefore\n // cannot have a default value. However, it might not be set at this\n // point (for example, if the user submitting a node form does not have\n // permission to create revisions), so we ensure that it is at least an\n // empty string in that case.\n // @todo: Make the {node_revision}.log column nullable so that we can\n // remove this check.\n if (!isset($node->log)) {\n $node->log = '';\n }\n }\n elseif (!isset($node->log) || $node->log === '') {\n // If we are updating an existing node without adding a new revision, we\n // need to make sure $node->log is unset whenever it is empty. As long as\n // $node->log is unset, drupal_write_record() will not attempt to update\n // the existing database column when re-saving the revision; therefore,\n // this code allows us to avoid clobbering an existing log entry with an\n // empty one.\n unset($node->log);\n }\n\n // When saving a new node revision, unset any existing $node->vid so as to\n // ensure that a new revision will actually be created, then store the old\n // revision ID in a separate property for use by node hook implementations.\n if (!$node->is_new && !empty($node->revision) && $node->vid) {\n $node->old_vid = $node->vid;\n unset($node->vid);\n }\n\n // Save the node and node revision.\n if ($node->is_new) {\n // For new nodes, save new records for both the node itself and the node\n // revision.\n drupal_write_record('node', $node);\n _node_save_revision($node, $user->uid);\n $op = 'insert';\n }\n else {\n // For existing nodes, update the node record which matches the value of\n // $node->nid.\n drupal_write_record('node', $node, 'nid');\n // Then, if a new node revision was requested, save a new record for\n // that; otherwise, update the node revision record which matches the\n // value of $node->vid.\n if (!empty($node->revision)) {\n _node_save_revision($node, $user->uid);\n }\n else {\n _node_save_revision($node, $user->uid, 'vid');\n $update_node = FALSE;\n }\n $op = 'update';\n }\n if ($update_node) {\n db_update('node')\n ->fields(array('vid' => $node->vid))\n ->condition('nid', $node->nid)\n ->execute();\n }\n\n // Call the node specific callback (if any). This can be\n // node_invoke($node, 'insert') or\n // node_invoke($node, 'update').\n node_invoke($node, $op);\n\n // Save fields.\n $function = \"field_attach_$op\";\n $function('node', $node);\n\n module_invoke_all('node_' . $op, $node);\n module_invoke_all('entity_' . $op, $node, 'node');\n\n // Update the node access table for this node.\n node_access_acquire_grants($node);\n\n // Clear internal properties.\n unset($node->is_new);\n unset($node->original);\n // Clear the static loading cache.\n entity_get_controller('node')->resetCache(array($node->nid));\n\n // Ignore slave server temporarily to give time for the\n // saved node to be propagated to the slave.\n db_ignore_slave();\n }\n catch (Exception $e) {\n $transaction->rollback();\n watchdog_exception('node', $e);\n throw $e;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21ac0762b1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/_user_mail_text/7.x", "instruction": "In Drupal 7, write the function `_user_mail_text($key, $language = NULL, $variables = array(), $replace = TRUE)` (file modules/user/user.module) so that it does the following: Returns a mail string for a variable name.", "context": "Used by user_mail() and the settings forms to retrieve strings.\n\nFile: modules/user/user.module", "response": "function _user_mail_text($key, $language = NULL, $variables = array(), $replace = TRUE) {\n $langcode = isset($language) ? $language->language : NULL;\n\n if ($admin_setting = variable_get('user_mail_' . $key, FALSE)) {\n // An admin setting overrides the default string.\n $text = $admin_setting;\n }\n else {\n // No override, return default string.\n switch ($key) {\n case 'register_no_approval_required_subject':\n $text = t('Account details for [user:name] at [site:name]', array(), array('langcode' => $langcode));\n break;\n case 'register_no_approval_required_body':\n $text = t(\"[user:name],\n\nThank you for registering at [site:name]. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n\n case 'register_admin_created_subject':\n $text = t('An administrator created an account for you at [site:name]', array(), array('langcode' => $langcode));\n break;\n case 'register_admin_created_body':\n $text = t(\"[user:name],\n\nA site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n\n case 'register_pending_approval_subject':\n case 'register_pending_approval_admin_subject':\n $text = t('Account details for [user:name] at [site:name] (pending admin approval)', array(), array('langcode' => $langcode));\n break;\n case 'register_pending_approval_body':\n $text = t(\"[user:name],\n\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another e-mail containing information about how to log in, set your password, and other details.\n\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n case 'register_pending_approval_admin_body':\n $text = t(\"[user:name] has applied for an account.\n\n[user:edit-url]\", array(), array('langcode' => $langcode));\n break;\n\n case 'password_reset_subject':\n $text = t('Replacement login information for [user:name] at [site:name]', array(), array('langcode' => $langcode));\n break;\n case 'password_reset_body':\n $text = t(\"[user:name],\n\nA request to reset the password for your account has been made at [site:name].\n\nYou may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password. It expires after one day and nothing will happen if it's not used.\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n\n case 'status_activated_subject':\n $text = t('Account details for [user:name] at [site:name] (approved)', array(), array('langcode' => $langcode));\n break;\n case 'status_activated_body':\n $text = t(\"[user:name],\n\nYour account at [site:name] has been activated.\n\nYou may now log in by clicking this link or copying and pasting it into your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n\n case 'status_blocked_subject':\n $text = t('Account details for [user:name] at [site:name] (blocked)', array(), array('langcode' => $langcode));\n break;\n case 'status_blocked_body':\n $text = t(\"[user:name],\n\nYour account on [site:name] has been blocked.\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n\n case 'cancel_confirm_subject':\n $text = t('Account cancellation request for [user:name] at [site:name]', array(), array('langcode' => $langcode));\n break;\n case 'cancel_confirm_body':\n $text = t(\"[user:name],\n\nA request to cancel your account has been made at [site:name].\n\nYou may now cancel your account on [site:url-brief] by clicking this link or copying and pasting it into your browser:\n\n[user:cancel-url]\n\nNOTE: The cancellation of your account is not reversible.\n\nThis link expires in one day and nothing will happen if it is not used.\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n\n case 'status_canceled_subject':\n $text = t('Account details for [user:name] at [site:name] (canceled)', array(), array('langcode' => $langcode));\n break;\n case 'status_canceled_body':\n $text = t(\"[user:name],\n\nYour account on [site:name] has been canceled.\n\n-- [site:name] team\", array(), array('langcode' => $langcode));\n break;\n }\n }\n\n if ($replace) {\n // We do not sanitize the token replacement, since the output of this\n // replacement is intended for an e-mail message, not a web browser.\n return token_replace($text, $variables, array('language' => $language, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE));\n }\n\n return $text;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21b8213f4f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_admin_menu_block/7.x", "instruction": "In Drupal 7, write the function `system_admin_menu_block($item)` (file modules/system/system.module) so that it does the following: Provide a single block on the administration overview page.", "context": "Parameters:\n- $item: The menu item to be displayed.\n\nFile: modules/system/system.module", "response": "function system_admin_menu_block($item) {\n $cache = &drupal_static(__FUNCTION__, array());\n // If we are calling this function for a menu item that corresponds to a\n // local task (for example, admin/tasks), then we want to retrieve the\n // parent item's child links, not this item's (since this item won't have\n // any).\n if ($item['tab_root'] != $item['path']) {\n $item = menu_get_item($item['tab_root_href']);\n }\n\n if (!isset($item['mlid'])) {\n $item += db_query(\"SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'\", array(':path' => $item['path']))->fetchAssoc();\n }\n\n if (isset($cache[$item['mlid']])) {\n return $cache[$item['mlid']];\n }\n\n $content = array();\n $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));\n $query->join('menu_router', 'm', 'm.path = ml.router_path');\n $query\n ->fields('ml')\n // Weight should be taken from {menu_links}, not {menu_router}.\n ->fields('m', array_diff(drupal_schema_fields_sql('menu_router'), array('weight')))\n ->condition('ml.plid', $item['mlid'])\n ->condition('ml.menu_name', $item['menu_name'])\n ->condition('ml.hidden', 0);\n\n foreach ($query->execute() as $link) {\n _menu_link_translate($link);\n if ($link['access']) {\n // The link description, either derived from 'description' in\n // hook_menu() or customized via menu module is used as title attribute.\n if (!empty($link['localized_options']['attributes']['title'])) {\n $link['description'] = $link['localized_options']['attributes']['title'];\n unset($link['localized_options']['attributes']['title']);\n }\n // Prepare for sorting as in function _menu_tree_check_access().\n // The weight is offset so it is always positive, with a uniform 5-digits.\n $key = (50000 + $link['weight']) . ' ' . drupal_strtolower($link['title']) . ' ' . $link['mlid'];\n $content[$key] = $link;\n }\n }\n ksort($content);\n $cache[$item['mlid']] = $content;\n return $content;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21bae22e3d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_edit_form_validate/7.x", "instruction": "In Drupal 7, write the function `locale_languages_edit_form_validate($form, &$form_state)` (file modules/locale/locale.admin.inc) so that it does the following: Validate the language editing form. Reused for custom language addition too.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_languages_edit_form_validate($form, &$form_state) {\n // Ensure sane field values for langcode, name, and native.\n if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state['values']['langcode'])) {\n form_set_error('langcode', t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => $form['langcode']['#title'])));\n }\n if ($form_state['values']['name'] != check_plain($form_state['values']['name'])) {\n form_set_error('name', t('%field cannot contain any markup.', array('%field' => $form['name']['#title'])));\n }\n if ($form_state['values']['native'] != check_plain($form_state['values']['native'])) {\n form_set_error('native', t('%field cannot contain any markup.', array('%field' => $form['native']['#title'])));\n }\n\n if (!empty($form_state['values']['domain']) && !empty($form_state['values']['prefix'])) {\n form_set_error('prefix', t('Domain and path prefix values should not be set at the same time.'));\n }\n if (!empty($form_state['values']['domain']) && $duplicate = db_query(\"SELECT language FROM {languages} WHERE domain = :domain AND language <> :language\", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchField()) {\n form_set_error('domain', t('The domain (%domain) is already tied to a language (%language).', array('%domain' => $form_state['values']['domain'], '%language' => $duplicate)));\n }\n if (empty($form_state['values']['prefix']) && language_default('language') != $form_state['values']['langcode'] && empty($form_state['values']['domain'])) {\n form_set_error('prefix', t('Only the default language can have both the domain and prefix empty.'));\n }\n if (!empty($form_state['values']['prefix']) && $duplicate = db_query(\"SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language\", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchField()) {\n form_set_error('prefix', t('The prefix (%prefix) is already tied to a language (%language).', array('%prefix' => $form_state['values']['prefix'], '%language' => $duplicate)));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21bc3d3491", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_rdf_namespaces/7.x", "instruction": "In Drupal 7, write the function `rdf_rdf_namespaces()` (file modules/rdf/rdf.module) so that it does the following: Implements hook_rdf_namespaces().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_rdf_namespaces() {\n return array(\n 'content' => 'http://purl.org/rss/1.0/modules/content/',\n 'dc' => 'http://purl.org/dc/terms/',\n 'foaf' => 'http://xmlns.com/foaf/0.1/',\n 'og' => 'http://ogp.me/ns#',\n 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',\n 'sioc' => 'http://rdfs.org/sioc/ns#',\n 'sioct' => 'http://rdfs.org/sioc/types#',\n 'skos' => 'http://www.w3.org/2004/02/skos/core#',\n 'xsd' => 'http://www.w3.org/2001/XMLSchema#',\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-21c3478472", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_file_delete/7.x", "instruction": "I need the code for `image_file_delete($file)` in Drupal 7 (modules/image/image.module). It must do this: Implements hook_file_delete().", "context": "File: modules/image/image.module", "response": "function image_file_delete($file) {\n // Delete any image derivatives of this image.\n image_path_flush($file->uri);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-21c453658f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/_field_invoke/7.x", "instruction": "In Drupal 7, write the function `_field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $options = array())` (file modules/field/field.attach.inc) so that it does the following: Invoke a field hook.", "context": "Parameters:\n- $op: Possible operations include: - form - validate - presave - insert - update - delete - delete revision - view - prepare translation\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entity: The fully formed $entity_type entity.\n- $a: - The $form in the 'form' operation. - The value of $view_mode in the 'view' operation. - Otherwise NULL.\n- $b: - The $form_state in the 'submit' operation. - Otherwise NULL.\n- $options: An associative array of additional options, with the following keys: - 'field_name': The name of the field whose operation should be invoked. By default, the operation is invoked on all the fields in the entity's bundle. NOTE: This option is not compatible with the 'deleted' option; the 'field_id' option should be used instead. - 'field_id': The id of the field whose operation should be invoked. By default, the operation is invoked on all the fields in the entity's' bundles. - 'default': A boolean value, specifying which implementation of the operation should be invoked. - if FALSE (default), the field types implementation of the operation will be invoked (hook_field_[op]) - If TRUE, the default field implementation of the field operation will be invoked (field_default_[op]) Internal use only. Do not explicitely set to TRUE, but use _field_invoke_default() instead. - 'deleted': If TRUE, the function will operate on deleted fields as well as non-deleted fields. If unset or FALSE, only non-deleted fields are operated on. - 'language': A language code or an array of language codes keyed by field name. It will be used to narrow down to a single value the available languages to act on.\n\nFile: modules/field/field.attach.inc", "response": "function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $options = array()) {\n // Merge default options.\n $default_options = array(\n 'default' => FALSE,\n 'deleted' => FALSE,\n 'language' => NULL,\n );\n $options += $default_options;\n\n // Determine the list of instances to iterate on.\n list(, , $bundle) = entity_extract_ids($entity_type, $entity);\n $instances = _field_invoke_get_instances($entity_type, $bundle, $options);\n\n // Iterate through the instances and collect results.\n $return = array();\n foreach ($instances as $instance) {\n // field_info_field() is not available for deleted fields, so use\n // field_info_field_by_id().\n $field = field_info_field_by_id($instance['field_id']);\n $field_name = $field['field_name'];\n $function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op;\n if (function_exists($function)) {\n // Determine the list of languages to iterate on.\n $available_languages = field_available_languages($entity_type, $field);\n $languages = _field_language_suggestion($available_languages, $options['language'], $field_name);\n\n foreach ($languages as $langcode) {\n $items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();\n $result = $function($entity_type, $entity, $field, $instance, $langcode, $items, $a, $b);\n if (isset($result)) {\n // For hooks with array results, we merge results together.\n // For hooks with scalar results, we collect results in an array.\n if (is_array($result)) {\n $return = array_merge($return, $result);\n }\n else {\n $return[] = $result;\n }\n }\n\n // Populate $items back in the field values, but avoid replacing missing\n // fields with an empty array (those are not equivalent on update).\n if ($items !== array() || isset($entity->{$field_name}[$langcode])) {\n $entity->{$field_name}[$langcode] = $items;\n }\n }\n }\n }\n\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21cd1c9337", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_FORM_ID_alter/7.x", "instruction": "Give me the example code for `hook_form_FORM_ID_alter(&$form, &$form_state, $form_id)` in Drupal 7. Hook description: Provide a form-specific alteration instead of the global hook_form_alter().", "context": "Modules can implement hook_form_FORM_ID_alter() to modify a specific form, rather than implementing hook_form_alter() and checking the form ID, or using long switch statements to alter multiple forms.\n\nForm alter hooks are called in the following order: hook_form_alter(), hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter(). See hook_form_alter() for more details.\n\nParameters:\n- $form: Nested array of form elements that comprise the form.\n- $form_state: A keyed array containing the current state of the form. The arguments that drupal_get_form() was originally called with are available in the array $form_state['build_info']['args'].\n- $form_id: String representing the name of the form itself. Typically this is the name of the function that generated the form.\n\nFile: modules/system/system.api.php", "response": "function hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) {\n // Modification for the form with the given form ID goes here. For example, if\n // FORM_ID is \"user_register_form\" this code would run only on the user\n // registration form.\n\n // Add a checkbox to registration form about agreeing to terms of use.\n $form['terms_of_use'] = array(\n '#type' => 'checkbox',\n '#title' => t(\"I agree with the website's terms and conditions.\"),\n '#required' => TRUE,\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-21cf117ef3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_updater_info/7.x", "instruction": "I need the code for `system_updater_info()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_updater_info().", "context": "File: modules/system/system.module", "response": "function system_updater_info() {\n return array(\n 'module' => array(\n 'class' => 'ModuleUpdater',\n 'name' => t('Update modules'),\n 'weight' => 0,\n ),\n 'theme' => array(\n 'class' => 'ThemeUpdater',\n 'name' => t('Update themes'),\n 'weight' => 0,\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-21d74515dd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_parse_url/7.x", "instruction": "I need the code for `drupal_parse_url($url)` in Drupal 7 (includes/common.inc). It must do this: Parses a URL string into its path, query, and fragment components.", "context": "This function splits both internal paths like @code node?b=c#d @endcode and external URLs like @code https://example.com/a?b=c#d @endcode into their component parts. See\n\nParameters:\n- $url (string): The internal path or external URL string to parse.\n\nReturns (array): An associative array containing: - path: The path component of $url. If $url is an external URL, this includes the scheme, authority, and path. - query: An array of query parameters from $url, if they exist. - fragment: The fragment component from $url, if it exists.\n\nFile: includes/common.inc", "response": "function drupal_parse_url($url) {\n $options = array(\n 'path' => NULL,\n 'query' => array(),\n 'fragment' => '',\n );\n\n // External URLs: not using parse_url() here, so we do not have to rebuild\n // the scheme, host, and path without having any use for it.\n if (strpos($url, '://') !== FALSE) {\n // Split off everything before the query string into 'path'.\n $parts = explode('?', $url);\n $options['path'] = $parts[0];\n // If there is a query string, transform it into keyed query parameters.\n if (isset($parts[1])) {\n $query_parts = explode('#', $parts[1]);\n parse_str($query_parts[0], $options['query']);\n // Take over the fragment, if there is any.\n if (isset($query_parts[1])) {\n $options['fragment'] = $query_parts[1];\n }\n }\n }\n // Internal URLs.\n else {\n // parse_url() does not support relative URLs, so make it absolute. E.g. the\n // relative URL \"foo/bar:1\" isn't properly parsed.\n $parts = parse_url('http://example.com/' . $url);\n // Strip the leading slash that was just added.\n $options['path'] = substr($parts['path'], 1);\n if (isset($parts['query'])) {\n parse_str($parts['query'], $options['query']);\n }\n if (isset($parts['fragment'])) {\n $options['fragment'] = $parts['fragment'];\n }\n }\n // The 'q' parameter contains the path of the current page if clean URLs are\n // disabled. It overrides the 'path' of the URL when present, even if clean\n // URLs are enabled, due to how Apache rewriting rules work. The path\n // parameter must be a string.\n if (isset($options['query']['q']) && is_string($options['query']['q'])) {\n $options['path'] = $options['query']['q'];\n unset($options['query']['q']);\n }\n\n return $options;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21dc197b86", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_space_used/7.x", "instruction": "Implement `file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT)` in PHP for Drupal 7. Required behavior: Determines total disk space used by a single user or the whole filesystem.", "context": "Parameters:\n- $uid: Optional. A user id, specifying NULL returns the total space used by all non-temporary files.\n- $status: Optional. The file status to consider. The default is to only consider files in status FILE_STATUS_PERMANENT.\n\nReturns: An integer containing the number of bytes used.\n\nFile: includes/file.inc", "response": "function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) {\n $query = db_select('file_managed', 'f');\n $query->condition('f.status', $status);\n $query->addExpression('SUM(f.filesize)', 'filesize');\n if (isset($uid)) {\n $query->condition('f.uid', $uid);\n }\n return $query->execute()->fetchField();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21e6985413", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_tablesort_indicator/7.x", "instruction": "Implement `seven_tablesort_indicator($variables)` in PHP for Drupal 7. Required behavior: Override of theme_tablesort_indicator().", "context": "Use our own image versions, so they show up as black and not gray on gray.\n\nFile: themes/seven/template.php", "response": "function seven_tablesort_indicator($variables) {\n $style = $variables['style'];\n $theme_path = drupal_get_path('theme', 'seven');\n if ($style == 'asc') {\n return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));\n }\n else {\n return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21e70549ce", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_update_forbid/7.x", "instruction": "Give me the example code for `hook_field_update_forbid($field, $prior_field, $has_data)` in Drupal 7. Hook description: Forbid a field update from occurring.", "context": "Any module may forbid any update for any reason. For example, the field's storage module might forbid an update if it would change the storage schema while data for the field exists. A field type module might forbid an update if it would change existing data's semantics, or if there are external dependencies on field settings that cannot be updated.\n\nTo forbid the update from occurring, throw a FieldUpdateForbiddenException.\n\nParameters:\n- $field: The field as it will be post-update.\n- $prior_field: The field as it is pre-update.\n- $has_data: Whether any data already exists for this field.\n\nFile: modules/field/field.api.php", "response": "function hook_field_update_forbid($field, $prior_field, $has_data) {\n // A 'list' field stores integer keys mapped to display values. If\n // the new field will have fewer values, and any data exists for the\n // abandoned keys, the field will have no way to display them. So,\n // forbid such an update.\n if ($has_data && count($field['settings']['allowed_values']) < count($prior_field['settings']['allowed_values'])) {\n // Identify the keys that will be lost.\n $lost_keys = array_diff(array_keys($field['settings']['allowed_values']), array_keys($prior_field['settings']['allowed_values']));\n // If any data exist for those keys, forbid the update.\n $query = new EntityFieldQuery();\n $found = $query\n ->fieldCondition($prior_field['field_name'], 'value', $lost_keys)\n ->range(0, 1)\n ->execute();\n if ($found) {\n throw new FieldUpdateForbiddenException(\"Cannot update a list field not to include keys with existing data\");\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-21e7128c8a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_rgb2hsl/7.x", "instruction": "In Drupal 7, write the function `_color_rgb2hsl($rgb)` (file modules/color/color.module) so that it does the following: Converts an RGB triplet to HSL.", "context": "File: modules/color/color.module", "response": "function _color_rgb2hsl($rgb) {\n $r = $rgb[0];\n $g = $rgb[1];\n $b = $rgb[2];\n $min = min($r, min($g, $b));\n $max = max($r, max($g, $b));\n $delta = $max - $min;\n $l = ($min + $max) / 2;\n $s = 0;\n\n if ($l > 0 && $l < 1) {\n $s = $delta / ($l < 0.5 ? (2 * $l) : (2 - 2 * $l));\n }\n\n $h = 0;\n if ($delta > 0) {\n if ($max == $r && $max != $g) $h += ($g - $b) / $delta;\n if ($max == $g && $max != $b) $h += (2 + ($b - $r) / $delta);\n if ($max == $b && $max != $r) $h += (4 + ($r - $g) / $delta);\n $h /= 6;\n }\n\n return array($h, $s, $l);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21e96707af", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_view/7.x", "instruction": "Implement `comment_view($comment, $node, $view_mode = 'full', $langcode = NULL)` in PHP for Drupal 7. Required behavior: Generate an array for rendering the given comment.", "context": "Parameters:\n- $comment: A comment object.\n- $node: The node the comment is attached to.\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nReturns: An array as expected by drupal_render().\n\nFile: modules/comment/comment.module", "response": "function comment_view($comment, $node, $view_mode = 'full', $langcode = NULL) {\n if (!isset($langcode)) {\n $langcode = $GLOBALS['language_content']->language;\n }\n\n // Populate $comment->content with a render() array.\n comment_build_content($comment, $node, $view_mode, $langcode);\n\n $build = $comment->content;\n // We don't need duplicate rendering info in comment->content.\n unset($comment->content);\n\n $build += array(\n '#theme' => 'comment__node_' . $node->type,\n '#comment' => $comment,\n '#node' => $node,\n '#view_mode' => $view_mode,\n '#language' => $langcode,\n );\n\n if (empty($comment->in_preview)) {\n $prefix = '';\n $is_threaded = isset($comment->divs) && variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED) == COMMENT_MODE_THREADED;\n\n // Add 'new' anchor if needed.\n if (!empty($comment->first_new)) {\n $prefix .= \"\\n\";\n }\n\n // Add indentation div or close open divs as needed.\n if ($is_threaded) {\n $prefix .= $comment->divs <= 0 ? str_repeat('', abs($comment->divs)) : \"\\n\" . '
            ';\n }\n\n // Add anchor for each comment.\n $prefix .= \"cid\\\">\\n\";\n $build['#prefix'] = $prefix;\n\n // Close all open divs.\n if ($is_threaded && !empty($comment->divs_final)) {\n $build['#suffix'] = str_repeat('
            ', $comment->divs_final);\n }\n }\n\n // Allow modules to modify the structured comment.\n $type = 'comment';\n drupal_alter(array('comment_view', 'entity_view'), $build, $type);\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21edcc60b5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_index_split/7.x", "instruction": "Implement `search_index_split($text)` in PHP for Drupal 7. Required behavior: Simplifies and splits a string into tokens for indexing.", "context": "File: modules/search/search.module", "response": "function search_index_split($text) {\n $last = &drupal_static(__FUNCTION__);\n $lastsplit = &drupal_static(__FUNCTION__ . ':lastsplit');\n\n if ($last == $text) {\n return $lastsplit;\n }\n // Process words\n $text = search_simplify($text);\n $words = explode(' ', $text);\n\n // Save last keyword result\n $last = $text;\n $lastsplit = $words;\n\n return $words;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-21fb4e93c3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/archiver_get_info/7.x", "instruction": "In Drupal 7, write the function `archiver_get_info()` (file includes/common.inc) so that it does the following: Retrieves a list of all available archivers.", "context": "File: includes/common.inc", "response": "function archiver_get_info() {\n $archiver_info = &drupal_static(__FUNCTION__, array());\n\n if (empty($archiver_info)) {\n $cache = cache_get('archiver_info');\n if ($cache === FALSE) {\n // Rebuild the cache and save it.\n $archiver_info = module_invoke_all('archiver_info');\n drupal_alter('archiver_info', $archiver_info);\n uasort($archiver_info, 'drupal_sort_weight');\n cache_set('archiver_info', $archiver_info);\n }\n else {\n $archiver_info = $cache->data;\n }\n }\n\n return $archiver_info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-220d16d6a5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_edit_item/7.x", "instruction": "In Drupal 7, write the function `menu_edit_item($form, &$form_state, $type, $item, $menu)` (file modules/menu/menu.admin.inc) so that it does the following: Menu callback; Build the menu link editing form.", "context": "File: modules/menu/menu.admin.inc", "response": "function menu_edit_item($form, &$form_state, $type, $item, $menu) {\n if ($type == 'add' || empty($item)) {\n // This is an add form, initialize the menu link.\n $item = array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu['menu_name'], 'weight' => 0, 'link_path' => '', 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0);\n }\n else {\n // Get the human-readable menu title from the given menu name.\n $titles = menu_get_menus();\n $current_title = $titles[$item['menu_name']];\n\n // Get the current breadcrumb and add a link to that menu's overview page.\n $breadcrumb = menu_get_active_breadcrumb();\n $breadcrumb[] = l($current_title, 'admin/structure/menu/manage/' . $item['menu_name']);\n drupal_set_breadcrumb($breadcrumb);\n }\n $form['actions'] = array('#type' => 'actions');\n $form['link_title'] = array(\n '#type' => 'textfield',\n '#title' => t('Menu link title'),\n '#maxlength' => 255,\n '#default_value' => $item['link_title'],\n '#description' => t('The text to be used for this link in the menu.'),\n '#required' => TRUE,\n );\n foreach (array('link_path', 'mlid', 'module', 'has_children', 'options') as $key) {\n $form[$key] = array('#type' => 'value', '#value' => $item[$key]);\n }\n // Any item created or edited via this interface is considered \"customized\".\n $form['customized'] = array('#type' => 'value', '#value' => 1);\n $form['original_item'] = array('#type' => 'value', '#value' => $item);\n\n $path = $item['link_path'];\n if (isset($item['options']['query'])) {\n $path .= '?' . drupal_http_build_query($item['options']['query']);\n }\n if (isset($item['options']['fragment'])) {\n $path .= '#' . $item['options']['fragment'];\n }\n if ($item['module'] == 'menu') {\n $form['link_path'] = array(\n '#type' => 'textfield',\n '#title' => t('Path'),\n '#maxlength' => 255,\n '#default_value' => $path,\n '#description' => t('The path for this menu link. This can be an internal path such as %add-node or an external URL such as %example. Enter %front to link to the front page.', array('%front' => '', '%add-node' => 'node/add', '%example' => 'http://example.com')),\n '#required' => TRUE,\n );\n $form['actions']['delete'] = array(\n '#type' => 'submit',\n '#value' => t('Delete'),\n '#access' => $item['mlid'],\n '#submit' => array('menu_item_delete_submit'),\n '#weight' => 10,\n );\n }\n else {\n $form['_path'] = array(\n '#type' => 'item',\n '#title' => t('Path'),\n '#description' => l($item['link_title'], $item['href'], $item['options']),\n );\n }\n $form['description'] = array(\n '#type' => 'textarea',\n '#title' => t('Description'),\n '#default_value' => isset($item['options']['attributes']['title']) ? $item['options']['attributes']['title'] : '',\n '#rows' => 1,\n '#description' => t('Shown when hovering over the menu link.'),\n );\n $form['enabled'] = array(\n '#type' => 'checkbox',\n '#title' => t('Enabled'),\n '#default_value' => !$item['hidden'],\n '#description' => t('Menu links that are not enabled will not be listed in any menu.'),\n );\n $form['expanded'] = array(\n '#type' => 'checkbox',\n '#title' => t('Show as expanded'),\n '#default_value' => $item['expanded'],\n '#description' => t('If selected and this menu link has children, the menu will always appear expanded.'),\n );\n\n // Generate a list of possible parents (not including this link or descendants).\n if ($type == 'add') {\n $options = menu_parent_options(array($menu['menu_name'] => t($menu['title'])), $item);\n }\n else {\n $options = menu_parent_options(menu_get_menus(), $item);\n }\n $default = $item['menu_name'] . ':' . $item['plid'];\n if (!isset($options[$default])) {\n $default = $item['menu_name'] . ':0';\n }\n $form['parent'] = array(\n '#type' => 'select',\n '#title' => t('Parent link'),\n '#default_value' => $default,\n '#options' => $options,\n '#description' => t('The maximum depth for a link and all its children is fixed at !maxdepth. Some menu links may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),\n '#attributes' => array('class' => array('menu-title-select')),\n );\n // Get number of items in all possible parent menus so the weight selector is\n // sized appropriately.\n $menu_names = array_keys(menu_get_menus());\n $menu_options = array();\n foreach ($menu_names as $menu_name) {\n if (isset($options[$menu_name . ':0'])) {\n $menu_options[] = $menu_name;\n }\n }\n // Make sure that we always have values in menu_options.\n $menu_options = !empty($menu_options) ? $menu_options : $menu_names;\n\n $form['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight'),\n '#delta' => _menu_get_menu_weight_delta($menu_options),\n '#default_value' => $item['weight'],\n '#description' => t('Optional. In the menu, the heavier links will sink and the lighter links will be positioned nearer the top.'),\n );\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-221372dfd5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/update_manual_status/7.x", "instruction": "Implement `update_manual_status()` in PHP for Drupal 7. Required behavior: Page callback: Checks for updates and displays the update status report.", "context": "Manually checks the update status without the use of cron.\n\nFile: modules/update/update.fetch.inc", "response": "function update_manual_status() {\n _update_refresh();\n $batch = array(\n 'operations' => array(\n array('update_fetch_data_batch', array()),\n ),\n 'finished' => 'update_fetch_data_finished',\n 'title' => t('Checking available update data'),\n 'progress_message' => t('Trying to check available update data ...'),\n 'error_message' => t('Error checking available update data.'),\n 'file' => drupal_get_path('module', 'update') . '/update.fetch.inc',\n );\n batch_set($batch);\n batch_process('admin/reports/updates');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2215969b43", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_form_node_type_form_alter/7.x", "instruction": "I need the code for `locale_form_node_type_form_alter(&$form, &$form_state)` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_form_FORM_ID_alter().", "context": "File: modules/locale/locale.module", "response": "function locale_form_node_type_form_alter(&$form, &$form_state) {\n if (isset($form['type'])) {\n $form['workflow']['language_content_type'] = array(\n '#type' => 'radios',\n '#title' => t('Multilingual support'),\n '#default_value' => variable_get('language_content_type_' . $form['#node_type']->type, 0),\n '#options' => array(t('Disabled'), t('Enabled')),\n '#description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the enabled languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language'))),\n );\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-221735feca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_delete_revision/7.x", "instruction": "Implement `file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items)` in PHP for Drupal 7. Required behavior: Implements hook_field_delete_revision().", "context": "File: modules/file/file.field.inc", "response": "function file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n foreach ($items as $delta => $item) {\n // Decrement the file usage count by 1 and delete the file if possible.\n if (file_field_delete_file($item, $field, $entity_type, $id)) {\n $items[$delta] = NULL;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2221257087", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21unicode.inc/function/drupal_ucfirst/7.x", "instruction": "I need the code for `drupal_ucfirst($text)` in Drupal 7 (includes/unicode.inc). It must do this: Capitalizes the first letter of a UTF-8 string.", "context": "Parameters:\n- $text: The string to convert.\n\nReturns: The string with the first letter as uppercase.\n\nFile: includes/unicode.inc", "response": "function drupal_ucfirst($text) {\n // Note: no mbstring equivalent!\n return drupal_strtoupper(drupal_substr($text, 0, 1)) . drupal_substr($text, 1);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-222cca40ed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_create_bundle/7.x", "instruction": "I need the code for `field_attach_create_bundle($entity_type, $bundle)` in Drupal 7 (modules/field/field.attach.inc). It must do this: Notify field.module that a new bundle was created.", "context": "The default SQL-based storage doesn't need to do anything about it, but others might.\n\nParameters:\n- $entity_type: The entity type to which the bundle is bound.\n- $bundle: The name of the newly created bundle.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_create_bundle($entity_type, $bundle) {\n // Clear the cache.\n field_cache_clear();\n\n // Let other modules act on creating the bundle.\n module_invoke_all('field_attach_create_bundle', $entity_type, $bundle);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2232eadc63", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_revision_delete_confirm/7.x", "instruction": "I need the code for `node_revision_delete_confirm($form, $form_state, $node_revision)` in Drupal 7 (modules/node/node.pages.inc). It must do this: Form constructor for the revision deletion confirmation form.", "context": "This form prevents against CSRF attacks.\n\nParameters:\n- $node_revision: The node revision ID.\n\nReturns: An array as expected by drupal_render().\n\nFile: modules/node/node.pages.inc", "response": "function node_revision_delete_confirm($form, $form_state, $node_revision) {\n $form['#node_revision'] = $node_revision;\n return confirm_form($form, t('Are you sure you want to delete the revision from %revision-date?', array('%revision-date' => format_date($node_revision->revision_timestamp))), 'node/' . $node_revision->nid . '/revisions', t('This action cannot be undone.'), t('Delete'), t('Cancel'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-226de1df7a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_configure_form_submit/7.x", "instruction": "I need the code for `locale_languages_configure_form_submit($form, &$form_state)` in Drupal 7 (modules/locale/locale.admin.inc). It must do this: Submit handler for language negotiation settings.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_languages_configure_form_submit($form, &$form_state) {\n $configurable_types = $form['#language_types'];\n\n foreach ($configurable_types as $type) {\n $negotiation = array();\n $enabled_providers = $form_state['values'][$type]['enabled'];\n $enabled_providers[LANGUAGE_NEGOTIATION_DEFAULT] = TRUE;\n $providers_weight = $form_state['values'][$type]['weight'];\n\n foreach ($providers_weight as $id => $weight) {\n if ($enabled_providers[$id]) {\n $provider = $form[$type]['#language_providers'][$id];\n $provider['weight'] = $weight;\n $negotiation[$id] = $provider;\n }\n }\n\n language_negotiation_set($type, $negotiation);\n variable_set(\"locale_language_providers_weight_$type\", $providers_weight);\n }\n\n // Update non-configurable language types and the related language negotiation\n // configuration.\n language_types_set();\n\n $form_state['redirect'] = 'admin/config/regional/language/configure';\n drupal_set_message(t('Language negotiation configuration saved.'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2276f35af4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_enable/7.x", "instruction": "I need the code for `theme_enable($theme_list)` in Drupal 7 (includes/theme.inc). It must do this: Enables a given list of themes.", "context": "Parameters:\n- $theme_list: An array of theme names.\n\nFile: includes/theme.inc", "response": "function theme_enable($theme_list) {\n drupal_clear_css_cache();\n\n foreach ($theme_list as $key) {\n db_update('system')\n ->fields(array('status' => 1))\n ->condition('type', 'theme')\n ->condition('name', $key)\n ->execute();\n }\n\n list_themes(TRUE);\n menu_rebuild();\n drupal_theme_rebuild();\n\n // Invoke hook_themes_enabled() after the themes have been enabled.\n module_invoke_all('themes_enabled', $theme_list);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-22c29ebc8f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_url_normalize/7.x", "instruction": "I need the code for `_openid_url_normalize($url)` in Drupal 7 (modules/openid/openid.inc). It must do this: OpenID normalization method: normalize URL identifiers.", "context": "File: modules/openid/openid.inc", "response": "function _openid_url_normalize($url) {\n $normalized_url = $url;\n\n if (stristr($url, '://') === FALSE) {\n $normalized_url = 'http://' . $url;\n }\n\n // Strip the fragment and fragment delimiter if present.\n $normalized_url = strtok($normalized_url, '#');\n\n if (substr_count($normalized_url, '/') < 3) {\n $normalized_url .= '/';\n }\n\n return $normalized_url;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-22ceed1488", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_form_node_form_alter/7.x", "instruction": "I need the code for `comment_form_node_form_alter(&$form, $form_state)` in Drupal 7 (modules/comment/comment.module). It must do this: Implements hook_form_BASE_FORM_ID_alter().", "context": "File: modules/comment/comment.module", "response": "function comment_form_node_form_alter(&$form, $form_state) {\n $node = $form['#node'];\n $form['comment_settings'] = array(\n '#type' => 'fieldset',\n '#access' => user_access('administer comments'),\n '#title' => t('Comment settings'),\n '#collapsible' => TRUE,\n '#collapsed' => TRUE,\n '#group' => 'additional_settings',\n '#attributes' => array(\n 'class' => array('comment-node-settings-form'),\n ),\n '#attached' => array(\n 'js' => array(drupal_get_path('module', 'comment') . '/comment-node-form.js'),\n ),\n '#weight' => 30,\n );\n $comment_count = isset($node->nid) ? db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() : 0;\n $comment_settings = ($node->comment == COMMENT_NODE_HIDDEN && empty($comment_count)) ? COMMENT_NODE_CLOSED : $node->comment;\n $form['comment_settings']['comment'] = array(\n '#type' => 'radios',\n '#title' => t('Comments'),\n '#title_display' => 'invisible',\n '#parents' => array('comment'),\n '#default_value' => $comment_settings,\n '#options' => array(\n COMMENT_NODE_OPEN => t('Open'),\n COMMENT_NODE_CLOSED => t('Closed'),\n COMMENT_NODE_HIDDEN => t('Hidden'),\n ),\n COMMENT_NODE_OPEN => array(\n '#description' => t('Users with the \"Post comments\" permission can post comments.'),\n ),\n COMMENT_NODE_CLOSED => array(\n '#description' => t('Users cannot post comments, but existing comments will be displayed.'),\n ),\n COMMENT_NODE_HIDDEN => array(\n '#description' => t('Comments are hidden from view.'),\n ),\n );\n // If the node doesn't have any comments, the \"hidden\" option makes no\n // sense, so don't even bother presenting it to the user.\n if (empty($comment_count)) {\n $form['comment_settings']['comment'][COMMENT_NODE_HIDDEN]['#access'] = FALSE;\n // Also adjust the description of the \"closed\" option.\n $form['comment_settings']['comment'][COMMENT_NODE_CLOSED]['#description'] = t('Users cannot post comments.');\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-22ea88cd24", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_sort_themes/7.x", "instruction": "I need the code for `system_sort_themes($a, $b)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Sorts themes by their names, with the default theme listed first.", "context": "Callback for uasort() within system_themes_page().\n\nFile: modules/system/system.admin.inc", "response": "function system_sort_themes($a, $b) {\n if ($a->is_default) {\n return -1;\n }\n if ($b->is_default) {\n return 1;\n }\n return strcasecmp($a->info['name'], $b->info['name']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-22ffbbb8c7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_widget_settings_form/7.x", "instruction": "In Drupal 7, write the function `file_field_widget_settings_form($field, $instance)` (file modules/file/file.field.inc) so that it does the following: Implements hook_field_widget_settings_form().", "context": "File: modules/file/file.field.inc", "response": "function file_field_widget_settings_form($field, $instance) {\n $widget = $instance['widget'];\n $settings = $widget['settings'];\n\n $form['progress_indicator'] = array(\n '#type' => 'radios',\n '#title' => t('Progress indicator'),\n '#options' => array(\n 'throbber' => t('Throbber'),\n 'bar' => t('Bar with progress meter'),\n ),\n '#default_value' => $settings['progress_indicator'],\n '#description' => t('The throbber display does not show the status of uploads but takes up less space. The progress bar is helpful for monitoring progress on large uploads.'),\n '#weight' => 16,\n '#access' => file_progress_implementation(),\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2312df52bb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_insert/7.x", "instruction": "Give me the example code for `hook_entity_insert($entity, $type)` in Drupal 7. Hook description: Act on entities when inserted.", "context": "Parameters:\n- $entity: The entity object.\n- $type: The type of entity being inserted (i.e. node, user, comment).\n\nFile: modules/system/system.api.php", "response": "function hook_entity_insert($entity, $type) {\n // Insert the new entity into a fictional table of all entities.\n $info = entity_get_info($type);\n list($id) = entity_extract_ids($type, $entity);\n db_insert('example_entity')\n ->fields(array(\n 'type' => $type,\n 'id' => $id,\n 'created' => REQUEST_TIME,\n 'updated' => REQUEST_TIME,\n ))\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-233c02d38b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_form_submit_build_entity/7.x", "instruction": "Implement `entity_form_submit_build_entity($entity_type, $entity, $form, &$form_state)` in PHP for Drupal 7. Required behavior: Copies submitted values to entity properties for simple entity forms.", "context": "During the submission handling of an entity form's \"Save\", \"Preview\", and possibly other buttons, the form state's entity needs to be updated with the submitted form values. Each entity form implements its own builder function for doing this, appropriate for the particular entity and form, whereas modules may specify additional builder functions in $form['#entity_builders'] for copying the form values of added form elements to entity properties. Many of the main entity builder functions can call this helper function to re-use its logic of copying $form_state['values'][PROPERTY] values to $entity->PROPERTY for all entries in $form_state['values'] that are not field data, and calling field_attach_submit() to copy field data. Apart from that this helper invokes any additional builder functions that have been specified in $form['#entity_builders'].\n\nFor some entity forms (e.g., forms with complex non-field data and forms that simultaneously edit multiple entities), this behavior may be inappropriate, so the builder function for such forms needs to implement the required functionality instead of calling this function.\n\nFile: includes/common.inc", "response": "function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_state) {\n $info = entity_get_info($entity_type);\n list(, , $bundle) = entity_extract_ids($entity_type, $entity);\n\n // Copy top-level form values that are not for fields to entity properties,\n // without changing existing entity properties that are not being edited by\n // this form. Copying field values must be done using field_attach_submit().\n $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $bundle)) : $form_state['values'];\n foreach ($values_excluding_fields as $key => $value) {\n $entity->$key = $value;\n }\n\n // Invoke all specified builders for copying form values to entity properties.\n if (isset($form['#entity_builders'])) {\n foreach ($form['#entity_builders'] as $function) {\n $function($entity_type, $entity, $form, $form_state);\n }\n }\n\n // Copy field values to the entity.\n if ($info['fieldable']) {\n field_attach_submit($entity_type, $entity, $form, $form_state);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-234496cc98", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_menu/7.x", "instruction": "Implement `forum_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu().", "context": "File: modules/forum/forum.module", "response": "function forum_menu() {\n $items['forum'] = array(\n 'title' => 'Forums',\n 'page callback' => 'forum_page',\n 'access arguments' => array('access content'),\n 'file' => 'forum.pages.inc',\n );\n $items['forum/%forum_forum'] = array(\n 'title' => 'Forums',\n 'page callback' => 'forum_page',\n 'page arguments' => array(1),\n 'access arguments' => array('access content'),\n 'file' => 'forum.pages.inc',\n );\n $items['admin/structure/forum'] = array(\n 'title' => 'Forums',\n 'description' => 'Control forum hierarchy settings.',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('forum_overview'),\n 'access arguments' => array('administer forums'),\n 'file' => 'forum.admin.inc',\n );\n $items['admin/structure/forum/list'] = array(\n 'title' => 'List',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n 'weight' => -10,\n );\n $items['admin/structure/forum/add/container'] = array(\n 'title' => 'Add container',\n 'page callback' => 'forum_form_main',\n 'page arguments' => array('container'),\n 'access arguments' => array('administer forums'),\n 'type' => MENU_LOCAL_ACTION,\n 'parent' => 'admin/structure/forum',\n 'file' => 'forum.admin.inc',\n );\n $items['admin/structure/forum/add/forum'] = array(\n 'title' => 'Add forum',\n 'page callback' => 'forum_form_main',\n 'page arguments' => array('forum'),\n 'access arguments' => array('administer forums'),\n 'type' => MENU_LOCAL_ACTION,\n 'parent' => 'admin/structure/forum',\n 'file' => 'forum.admin.inc',\n );\n $items['admin/structure/forum/settings'] = array(\n 'title' => 'Settings',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('forum_admin_settings'),\n 'access arguments' => array('administer forums'),\n 'weight' => 5,\n 'type' => MENU_LOCAL_TASK,\n 'parent' => 'admin/structure/forum',\n 'file' => 'forum.admin.inc',\n );\n $items['admin/structure/forum/edit/container/%taxonomy_term'] = array(\n 'title' => 'Edit container',\n 'page callback' => 'forum_form_main',\n 'page arguments' => array('container', 5),\n 'access arguments' => array('administer forums'),\n 'file' => 'forum.admin.inc',\n );\n $items['admin/structure/forum/edit/forum/%taxonomy_term'] = array(\n 'title' => 'Edit forum',\n 'page callback' => 'forum_form_main',\n 'page arguments' => array('forum', 5),\n 'access arguments' => array('administer forums'),\n 'file' => 'forum.admin.inc',\n );\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2372937c65", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_stream_wrappers_alter/7.x", "instruction": "Give me the example code for `hook_stream_wrappers_alter(&$wrappers)` in Drupal 7. Hook description: Alters the list of PHP stream wrapper implementations.", "context": "File: modules/system/system.api.php", "response": "function hook_stream_wrappers_alter(&$wrappers) {\n // Change the name of private files to reflect the performance.\n $wrappers['private']['name'] = t('Slow files');\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-23d756fd7a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_modules_enabled/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_modules_enabled($modules)` (modules/system/system.api.php): Perform necessary actions after modules are enabled.", "context": "This function differs from hook_enable() in that it gives all other modules a chance to perform actions when modules are enabled, whereas hook_enable() is only called on the module actually being enabled. See module_enable() for a detailed description of the order in which install and enable hooks are invoked.\n\nParameters:\n- $modules: An array of the modules that were enabled.\n\nFile: modules/system/system.api.php", "response": "function hook_modules_enabled($modules) {\n if (in_array('lousy_module', $modules)) {\n drupal_set_message(t('mymodule is not compatible with lousy_module'), 'error');\n mymodule_disable_functionality();\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-23df2c4ef0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_schema/7.x", "instruction": "I need the code for `taxonomy_schema()` in Drupal 7 (modules/taxonomy/taxonomy.install). It must do this: Implements hook_schema().", "context": "File: modules/taxonomy/taxonomy.install", "response": "function taxonomy_schema() {\n $schema['taxonomy_term_data'] = array(\n 'description' => 'Stores term information.',\n 'fields' => array(\n 'tid' => array(\n 'type' => 'serial',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'description' => 'Primary Key: Unique term ID.',\n ),\n 'vid' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',\n ),\n 'name' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The term name.',\n 'translatable' => TRUE,\n ),\n 'description' => array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'size' => 'big',\n 'description' => 'A description of the term.',\n 'translatable' => TRUE,\n ),\n 'format' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n 'description' => 'The {filter_format}.format of the description.',\n ),\n 'weight' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The weight of this term in relation to other terms.',\n ),\n ),\n 'primary key' => array('tid'),\n 'foreign keys' => array(\n 'vocabulary' => array(\n 'table' => 'taxonomy_vocabulary',\n 'columns' => array('vid' => 'vid'),\n ),\n ),\n 'indexes' => array(\n 'taxonomy_tree' => array('vid', 'weight', 'name'),\n 'vid_name' => array('vid', 'name'),\n 'name' => array('name'),\n ),\n );\n\n $schema['taxonomy_term_hierarchy'] = array(\n 'description' => 'Stores the hierarchical relationship between terms.',\n 'fields' => array(\n 'tid' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',\n ),\n 'parent' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => \"Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.\",\n ),\n ),\n 'indexes' => array(\n 'parent' => array('parent'),\n ),\n 'foreign keys' => array(\n 'taxonomy_term_data' => array(\n 'table' => 'taxonomy_term_data',\n 'columns' => array('tid' => 'tid'),\n ),\n ),\n 'primary key' => array('tid', 'parent'),\n );\n\n $schema['taxonomy_vocabulary'] = array(\n 'description' => 'Stores vocabulary information.',\n 'fields' => array(\n 'vid' => array(\n 'type' => 'serial',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'description' => 'Primary Key: Unique vocabulary ID.',\n ),\n 'name' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Name of the vocabulary.',\n 'translatable' => TRUE,\n ),\n 'machine_name' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The vocabulary machine name.',\n ),\n 'description' => array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'size' => 'big',\n 'description' => 'Description of the vocabulary.',\n 'translatable' => TRUE,\n ),\n 'hierarchy' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'tiny',\n 'description' => 'The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)',\n ),\n 'module' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The module which created the vocabulary.',\n ),\n 'weight' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The weight of this vocabulary in relation to other vocabularies.',\n ),\n ),\n 'primary key' => array('vid'),\n 'indexes' => array(\n 'list' => array('weight', 'name'),\n ),\n 'unique keys' => array(\n 'machine_name' => array('machine_name'),\n ),\n );\n\n $schema['taxonomy_index'] = array(\n 'description' => 'Maintains denormalized information about node/term relationships.',\n 'fields' => array(\n 'nid' => array(\n 'description' => 'The {node}.nid this record tracks.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'tid' => array(\n 'description' => 'The term ID.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'sticky' => array(\n 'description' => 'Boolean indicating whether the node is sticky.',\n 'type' => 'int',\n 'not null' => FALSE,\n 'default' => 0,\n 'size' => 'tiny',\n ),\n 'created' => array(\n 'description' => 'The Unix timestamp when the node was created.',\n 'type' => 'int',\n 'not null' => TRUE,\n 'default'=> 0,\n ),\n ),\n 'indexes' => array(\n 'term_node' => array('tid', 'sticky', 'created'),\n 'nid' => array('nid'),\n ),\n 'foreign keys' => array(\n 'tracked_node' => array(\n 'table' => 'node',\n 'columns' => array('nid' => 'nid'),\n ),\n 'term' => array(\n 'table' => 'taxonomy_term_data',\n 'columns' => array('tid' => 'tid'),\n ),\n ),\n );\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-23dfa349fa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_requirements_url/7.x", "instruction": "Implement `drupal_requirements_url($severity)` in PHP for Drupal 7. Required behavior: Returns a URL for proceeding to the next page after a requirements problem.", "context": "This function can be called by low-level scripts (such as install.php and update.php) and returns a URL that can be used to attempt to proceed to the next step of the script.\n\nParameters:\n- $severity: The severity of the requirements problem, as returned by drupal_requirements_severity().\n\nReturns: A URL for attempting to proceed to the next step of the script. The URL is not sanitized, so it still needs to be run through check_url() if it will be used as an HTML attribute value.\n\nFile: includes/install.inc", "response": "function drupal_requirements_url($severity) {\n $query = array();\n // If there are no errors, only warnings, append 'continue=1' to the URL so\n // the user can bypass this screen on the next page load.\n if ($severity == REQUIREMENT_WARNING) {\n $query['continue'] = 1;\n }\n return drupal_current_script_url($query);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-23e6e1dd15", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_rdf_mapping/7.x", "instruction": "Implement `comment_rdf_mapping()` in PHP for Drupal 7. Required behavior: Implements hook_rdf_mapping().", "context": "File: modules/comment/comment.module", "response": "function comment_rdf_mapping() {\n return array(\n array(\n 'type' => 'comment',\n 'bundle' => RDF_DEFAULT_BUNDLE,\n 'mapping' => array(\n 'rdftype' => array('sioc:Post', 'sioct:Comment'),\n 'title' => array(\n 'predicates' => array('dc:title'),\n ),\n 'created' => array(\n 'predicates' => array('dc:date', 'dc:created'),\n 'datatype' => 'xsd:dateTime',\n 'callback' => 'date_iso8601',\n ),\n 'changed' => array(\n 'predicates' => array('dc:modified'),\n 'datatype' => 'xsd:dateTime',\n 'callback' => 'date_iso8601',\n ),\n 'comment_body' => array(\n 'predicates' => array('content:encoded'),\n ),\n 'pid' => array(\n 'predicates' => array('sioc:reply_of'),\n 'type' => 'rel',\n ),\n 'uid' => array(\n 'predicates' => array('sioc:has_creator'),\n 'type' => 'rel',\n ),\n 'name' => array(\n 'predicates' => array('foaf:name'),\n ),\n ),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-23fa1e58cc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_scheme_form_submit/7.x", "instruction": "I need the code for `color_scheme_form_submit($form, &$form_state)` in Drupal 7 (modules/color/color.module). It must do this: Form submission handler for color_scheme_form().", "context": "File: modules/color/color.module", "response": "function color_scheme_form_submit($form, &$form_state) {\n // Get theme coloring info.\n if (!isset($form_state['values']['info'])) {\n return;\n }\n $theme = $form_state['values']['theme'];\n $info = $form_state['values']['info'];\n\n // Resolve palette.\n $palette = $form_state['values']['palette'];\n if ($form_state['values']['scheme'] != '') {\n foreach ($palette as $key => $color) {\n if (isset($info['schemes'][$form_state['values']['scheme']]['colors'][$key])) {\n $palette[$key] = $info['schemes'][$form_state['values']['scheme']]['colors'][$key];\n }\n }\n $palette += $info['schemes']['default']['colors'];\n }\n\n // Make sure enough memory is available, if PHP's memory limit is compiled in.\n if (function_exists('memory_get_usage')) {\n // Fetch source image dimensions.\n $source = drupal_get_path('theme', $theme) . '/' . $info['base_image'];\n list($width, $height) = getimagesize($source);\n\n // We need at least a copy of the source and a target buffer of the same\n // size (both at 32bpp).\n $required = $width * $height * 8;\n // We intend to prevent color scheme changes if there isn't enough memory\n // available. memory_get_usage(TRUE) returns a more accurate number than\n // memory_get_usage(), therefore we won't inadvertently reject a color\n // scheme change based on a faulty memory calculation.\n $usage = memory_get_usage(TRUE);\n $memory_limit = ini_get('memory_limit');\n $size = parse_size($memory_limit);\n if (!drupal_check_memory_limit($usage + $required, $memory_limit)) {\n drupal_set_message(t('There is not enough memory available to PHP to change this theme\\'s color scheme. You need at least %size more. Check the PHP documentation for more information.', array('%size' => format_size($usage + $required - $size), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error');\n return;\n }\n }\n\n // Delete old files.\n foreach (variable_get('color_' . $theme . '_files', array()) as $file) {\n @drupal_unlink($file);\n }\n if (isset($file) && $file = dirname($file)) {\n @drupal_rmdir($file);\n }\n\n // Don't render the default colorscheme, use the standard theme instead.\n if (implode(',', color_get_palette($theme, TRUE)) == implode(',', $palette)) {\n variable_del('color_' . $theme . '_palette');\n variable_del('color_' . $theme . '_stylesheets');\n variable_del('color_' . $theme . '_logo');\n variable_del('color_' . $theme . '_files');\n variable_del('color_' . $theme . '_screenshot');\n return;\n }\n\n // Prepare target locations for generated files.\n $id = $theme . '-' . substr(hash('sha256', serialize($palette) . microtime()), 0, 8);\n $paths['color'] = 'public://color';\n $paths['target'] = $paths['color'] . '/' . $id;\n foreach ($paths as $path) {\n file_prepare_directory($path, FILE_CREATE_DIRECTORY);\n }\n $paths['target'] = $paths['target'] . '/';\n $paths['id'] = $id;\n $paths['source'] = drupal_get_path('theme', $theme) . '/';\n $paths['files'] = $paths['map'] = array();\n\n // Save palette and logo location.\n variable_set('color_' . $theme . '_palette', $palette);\n variable_set('color_' . $theme . '_logo', $paths['target'] . 'logo.png');\n\n // Copy over neutral images.\n foreach ($info['copy'] as $file) {\n $base = drupal_basename($file);\n $source = $paths['source'] . $file;\n $filepath = file_unmanaged_copy($source, $paths['target'] . $base);\n $paths['map'][$file] = $base;\n $paths['files'][] = $filepath;\n }\n\n // Render new images, if image has been provided.\n if ($info['base_image']) {\n _color_render_images($theme, $info, $paths, $palette);\n }\n\n // Rewrite theme stylesheets.\n $css = array();\n foreach ($info['css'] as $stylesheet) {\n // Build a temporary array with LTR and RTL files.\n $files = array();\n if (file_exists($paths['source'] . $stylesheet)) {\n $files[] = $stylesheet;\n\n $rtl_file = str_replace('.css', '-rtl.css', $stylesheet);\n if (file_exists($paths['source'] . $rtl_file)) {\n $files[] = $rtl_file;\n }\n }\n\n foreach ($files as $file) {\n // Aggregate @imports recursively for each configured top level CSS file\n // without optimization. Aggregation and optimization will be\n // handled by drupal_build_css_cache() only.\n $style = drupal_load_stylesheet($paths['source'] . $file, FALSE);\n\n // Return the path to where this CSS file originated from, stripping\n // off the name of the file at the end of the path.\n $base = base_path() . dirname($paths['source'] . $file) . '/';\n _drupal_build_css_path(NULL, $base);\n\n // Prefix all paths within this CSS file, ignoring absolute paths.\n $style = preg_replace_callback('/url\\([\\'\"]?(?![a-z]+:|\\/+)([^\\'\")]+)[\\'\"]?\\)/i', '_drupal_build_css_path', $style);\n\n // Rewrite stylesheet with new colors.\n $style = _color_rewrite_stylesheet($theme, $info, $paths, $palette, $style);\n $base_file = drupal_basename($file);\n $css[] = $paths['target'] . $base_file;\n _color_save_stylesheet($paths['target'] . $base_file, $style, $paths);\n }\n }\n\n // Maintain list of files.\n variable_set('color_' . $theme . '_stylesheets', $css);\n variable_set('color_' . $theme . '_files', $paths['files']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-242c4c1051", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_prepare_directory/7.x", "instruction": "I need the code for `file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)` in Drupal 7 (includes/file.inc). It must do this: Checks that the directory exists and is writable.", "context": "Directories need to have execute permissions to be considered a directory by FTP servers, etc.\n\nParameters:\n- $directory: A string reference containing the name of a directory path or URI. A trailing slash will be trimmed from a path.\n- $options: A bitmask to indicate if the directory should be created if it does not exist (FILE_CREATE_DIRECTORY) or made writable if it is read-only (FILE_MODIFY_PERMISSIONS).\n\nReturns: TRUE if the directory exists (or was created) and is writable. FALSE otherwise.\n\nFile: includes/file.inc", "response": "function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) {\n if (!file_stream_wrapper_valid_scheme(file_uri_scheme($directory))) {\n // Only trim if we're not dealing with a stream.\n $directory = rtrim($directory, '/\\\\');\n }\n\n // Check if directory exists.\n if (!is_dir($directory)) {\n // Let drupal_mkdir() recursively create directories and use the default\n // directory permissions.\n if ($options & FILE_CREATE_DIRECTORY) {\n return @drupal_mkdir($directory, NULL, TRUE);\n }\n return FALSE;\n }\n // The directory exists, so check to see if it is writable.\n $writable = is_writable($directory);\n if (!$writable && ($options & FILE_MODIFY_PERMISSIONS)) {\n return drupal_chmod($directory);\n }\n\n return $writable;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-242f92e06f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21php%21php.module/function/php_permission/7.x", "instruction": "In Drupal 7, write the function `php_permission()` (file modules/php/php.module) so that it does the following: Implements hook_permission().", "context": "File: modules/php/php.module", "response": "function php_permission() {\n return array(\n 'use PHP for settings' => array(\n 'title' => t('Use PHP for settings'),\n 'restrict access' => TRUE,\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-243d30e3ed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7005/7.x", "instruction": "I need the code for `node_update_7005()` in Drupal 7 (modules/node/node.install). It must do this: Add status/comment/promote and sticky columns to the {node_revision} table.", "context": "File: modules/node/node.install", "response": "function node_update_7005() {\n foreach (array('status', 'comment', 'promote', 'sticky') as $column) {\n db_add_field('node_revision', $column, array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n ));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-247a666175", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_goto/7.x", "instruction": "I need the code for `drupal_goto($path = '', array $options = array(), $http_response_code = 302)` in Drupal 7 (includes/common.inc). It must do this: Sends the user to a different page.", "context": "This issues an on-site HTTP redirect. The function makes sure the redirected URL is formatted correctly.\n\nUsually the redirected URL is constructed from this function's input parameters. However you may override that behavior by setting a destination in either the $_REQUEST-array (i.e. by using the query string of an URI) This is used to direct the user back to the proper page after completing a form. For example, after editing a post on the 'admin/content'-page or after having logged on using the 'user login'-block in a sidebar. The function drupal_get_destination() can be used to help set the destination URL.\n\nDrupal will ensure that messages set by drupal_set_message() and other session data are written to the database before the user is redirected.\n\nThis function ends the request; use it instead of a return in your menu callback.\n\nParameters:\n- $path: (optional) A Drupal path or a full URL, which will be passed to url() to compute the redirect for the URL.\n- $options: (optional) An associative array of additional URL options to pass to url().\n- $http_response_code: (optional) The HTTP status code to use for the redirection, defaults to 302. The valid values for 3xx redirection status codes are defined in @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3 RFC 2616 @endlink and the @link http://tools.ietf.org/html/draft-reschke-http-status-308-07 draft for the new HTTP status codes: @endlink - 301: Moved Permanently (the recommended value for most redirects). - 302: Found (default in Drupal and PHP, sometimes used for spamming search engines). - 303: See Other. - 304: Not Modified. - 305: Use Proxy. - 307: Temporary Redirect.\n\nFile: includes/common.inc", "response": "function drupal_goto($path = '', array $options = array(), $http_response_code = 302) {\n // A destination in $_GET always overrides the function arguments.\n // We do not allow absolute URLs to be passed via $_GET, as this can be an attack vector.\n if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {\n $destination = drupal_parse_url($_GET['destination']);\n // Double check the path derived by drupal_parse_url() is not external.\n if (!url_is_external($destination['path'])) {\n $path = $destination['path'];\n }\n $options['query'] = $destination['query'];\n $options['fragment'] = $destination['fragment'];\n }\n\n // In some cases modules call drupal_goto(current_path()). We need to ensure\n // that such a redirect is not to an external URL.\n if ($path === current_path() && empty($options['external']) && url_is_external($path)) {\n // Force url() to generate a non-external URL.\n $options['external'] = FALSE;\n }\n\n drupal_alter('drupal_goto', $path, $options, $http_response_code);\n\n // The 'Location' HTTP header must be absolute.\n $options['absolute'] = TRUE;\n\n $url = url($path, $options);\n\n header('Location: ' . $url, TRUE, $http_response_code);\n\n // The \"Location\" header sends a redirect status code to the HTTP daemon. In\n // some cases this can be wrong, so we make sure none of the code below the\n // drupal_goto() call gets executed upon redirection.\n drupal_exit($url);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2485e664bf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.api.php/function/hook_rdf_namespaces/7.x", "instruction": "Give me the example code for `hook_rdf_namespaces()` in Drupal 7. Hook description: Allow modules to define namespaces for RDF mappings.", "context": "Many common namespace prefixes are defined in rdf_rdf_namespaces(). However, if a module implements hook_rdf_mapping() and uses a prefix that is not defined in rdf_rdf_namespaces(), this hook should be used to define the new namespace prefix.\n\nReturns: An associative array of namespaces where the key is the namespace prefix and the value is the namespace URI.\n\nFile: modules/rdf/rdf.api.php", "response": "function hook_rdf_namespaces() {\n return array(\n 'content' => 'http://purl.org/rss/1.0/modules/content/',\n 'dc' => 'http://purl.org/dc/terms/',\n 'foaf' => 'http://xmlns.com/foaf/0.1/',\n 'og' => 'http://ogp.me/ns#',\n 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',\n 'sioc' => 'http://rdfs.org/sioc/ns#',\n 'sioct' => 'http://rdfs.org/sioc/types#',\n 'skos' => 'http://www.w3.org/2004/02/skos/core#',\n 'xsd' => 'http://www.w3.org/2001/XMLSchema#',\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-24961b818b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/element_validate_number/7.x", "instruction": "In Drupal 7, write the function `element_validate_number($element, &$form_state)` (file includes/form.inc) so that it does the following: Form element validation handler for number elements.", "context": "File: includes/form.inc", "response": "function element_validate_number($element, &$form_state) {\n $value = $element['#value'];\n if ($value != '' && !is_numeric($value)) {\n form_error($element, t('%name must be a number.', array('%name' => $element['#title'])));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-24a24ccfb7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_save/7.x", "instruction": "Give me the example code for `hook_block_save($delta = '', $edit = array())` in Drupal 7. Hook description: Save the configuration options from hook_block_configure().", "context": "This hook allows you to save the block-specific configuration settings defined within your hook_block_configure().\n\nParameters:\n- $delta: Which block is being configured. This is a unique identifier for the block within the module, defined in hook_block_info().\n- $edit: The submitted form data from the configuration form. For a detailed usage example, see block_example.module.\n\nFile: modules/block/block.api.php", "response": "function hook_block_save($delta = '', $edit = array()) {\n // This example comes from node.module.\n if ($delta == 'recent') {\n variable_set('node_recent_block_count', $edit['node_recent_block_count']);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-24a2a24884", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_delete_file_if_stale/7.x", "instruction": "In Drupal 7, write the function `drupal_delete_file_if_stale($uri)` (file includes/common.inc) so that it does the following: Callback to delete files modified more than a set time ago.", "context": "File: includes/common.inc", "response": "function drupal_delete_file_if_stale($uri) {\n // Default stale file threshold is 30 days.\n if (REQUEST_TIME - filemtime($uri) > variable_get('drupal_stale_file_threshold', 2592000)) {\n file_unmanaged_delete($uri);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-24bde54be0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_menu/7.x", "instruction": "In Drupal 7, write the function `contact_menu()` (file modules/contact/contact.module) so that it does the following: Implements hook_menu().", "context": "File: modules/contact/contact.module", "response": "function contact_menu() {\n $items['admin/structure/contact'] = array(\n 'title' => 'Contact form',\n 'description' => 'Create a system contact form and set up categories for the form to use.',\n 'page callback' => 'contact_category_list',\n 'access arguments' => array('administer contact forms'),\n 'file' => 'contact.admin.inc',\n );\n $items['admin/structure/contact/add'] = array(\n 'title' => 'Add category',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('contact_category_edit_form'),\n 'access arguments' => array('administer contact forms'),\n 'type' => MENU_LOCAL_ACTION,\n 'weight' => 1,\n 'file' => 'contact.admin.inc',\n );\n $items['admin/structure/contact/edit/%contact'] = array(\n 'title' => 'Edit contact category',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('contact_category_edit_form', 4),\n 'access arguments' => array('administer contact forms'),\n 'file' => 'contact.admin.inc',\n );\n $items['admin/structure/contact/delete/%contact'] = array(\n 'title' => 'Delete contact',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('contact_category_delete_form', 4),\n 'access arguments' => array('administer contact forms'),\n 'file' => 'contact.admin.inc',\n );\n $items['contact'] = array(\n 'title' => 'Contact',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('contact_site_form'),\n 'access arguments' => array('access site-wide contact form'),\n 'type' => MENU_SUGGESTED_ITEM,\n 'file' => 'contact.pages.inc',\n );\n $items['user/%user/contact'] = array(\n 'title' => 'Contact',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('contact_personal_form', 1),\n 'type' => MENU_LOCAL_TASK,\n 'access callback' => '_contact_personal_tab_access',\n 'access arguments' => array(1),\n 'weight' => 2,\n 'file' => 'contact.pages.inc',\n );\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-24c33aaf3b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_rebuild_module_data/7.x", "instruction": "Implement `system_rebuild_module_data()` in PHP for Drupal 7. Required behavior: Rebuild, save, and return data about all currently available modules.", "context": "Returns (Array): of all available modules and their data.\n\nFile: modules/system/system.module", "response": "function system_rebuild_module_data() {\n $modules_cache = &drupal_static(__FUNCTION__);\n // Only rebuild once per request. $modules and $modules_cache cannot be\n // combined into one variable, because the $modules_cache variable is reset by\n // reference from system_list_reset() during the rebuild.\n if (!isset($modules_cache)) {\n $modules = _system_rebuild_module_data();\n ksort($modules);\n system_get_files_database($modules, 'module');\n system_update_files_database($modules, 'module');\n $modules = _module_build_dependencies($modules);\n $modules_cache = $modules;\n }\n return $modules_cache;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-24d1b00bd7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_overview/7.x", "instruction": "In Drupal 7, write the function `filter_admin_overview($form)` (file modules/filter/filter.admin.inc) so that it does the following: Page callback: Form constructor for a form to list and reorder text formats.", "context": "File: modules/filter/filter.admin.inc", "response": "function filter_admin_overview($form) {\n // Overview of all formats.\n $formats = filter_formats();\n $fallback_format = filter_fallback_format();\n\n $form['#tree'] = TRUE;\n foreach ($formats as $id => $format) {\n // Check whether this is the fallback text format. This format is available\n // to all roles and cannot be disabled via the admin interface.\n $form['formats'][$id]['#is_fallback'] = ($id == $fallback_format);\n if ($form['formats'][$id]['#is_fallback']) {\n $form['formats'][$id]['name'] = array('#markup' => drupal_placeholder($format->name));\n $roles_markup = drupal_placeholder(t('All roles may use this format'));\n }\n else {\n $form['formats'][$id]['name'] = array('#markup' => check_plain($format->name));\n $roles = array_map('check_plain', filter_get_roles_by_format($format));\n $roles_markup = $roles ? implode(', ', $roles) : t('No roles may use this format');\n }\n $form['formats'][$id]['roles'] = array('#markup' => $roles_markup);\n $form['formats'][$id]['configure'] = array('#type' => 'link', '#title' => t('configure'), '#href' => 'admin/config/content/formats/' . $id);\n $form['formats'][$id]['disable'] = array('#type' => 'link', '#title' => t('disable'), '#href' => 'admin/config/content/formats/' . $id . '/disable', '#access' => !$form['formats'][$id]['#is_fallback']);\n $form['formats'][$id]['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight for @title', array('@title' => $format->name)),\n '#title_display' => 'invisible',\n '#default_value' => $format->weight,\n );\n }\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-24dce85df5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_get_filters/7.x", "instruction": "I need the code for `filter_get_filters()` in Drupal 7 (modules/filter/filter.module). It must do this: Returns a list of all filters provided by modules.", "context": "Returns (array): An array of filter formats.\n\nFile: modules/filter/filter.module", "response": "function filter_get_filters() {\n $filters = &drupal_static(__FUNCTION__, array());\n\n if (empty($filters)) {\n foreach (module_implements('filter_info') as $module) {\n $info = module_invoke($module, 'filter_info');\n if (isset($info) && is_array($info)) {\n // Assign the name of the module implementing the filters and ensure\n // default values.\n foreach (array_keys($info) as $name) {\n $info[$name]['module'] = $module;\n $info[$name] += array(\n 'description' => '',\n 'weight' => 0,\n );\n }\n $filters = array_merge($filters, $info);\n }\n }\n // Allow modules to alter filter definitions.\n drupal_alter('filter_info', $filters);\n\n uasort($filters, '_filter_list_cmp');\n }\n\n return $filters;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-24df0b4179", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.pages.inc/function/book_outline_form_submit/7.x", "instruction": "Implement `book_outline_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for book_outline_form().", "context": "File: modules/book/book.pages.inc", "response": "function book_outline_form_submit($form, &$form_state) {\n $node = $form['#node'];\n $form_state['redirect'] = \"node/\" . $node->nid;\n $book_link = $form_state['values']['book'];\n if (!$book_link['bid']) {\n drupal_set_message(t('No changes were made'));\n\n return;\n }\n\n $book_link['menu_name'] = book_menu_name($book_link['bid']);\n $node->book = $book_link;\n if (_book_update_outline($node)) {\n if ($node->book['parent_mismatch']) {\n // This will usually only happen when JS is disabled.\n drupal_set_message(t('The post has been added to the selected book. You may now position it relative to other pages.'));\n $form_state['redirect'] = \"node/\" . $node->nid . \"/outline\";\n }\n else {\n drupal_set_message(t('The book outline has been updated.'));\n }\n }\n else {\n drupal_set_message(t('There was an error adding the post to the book.'), 'error');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2503c8f7c2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_style_delete/7.x", "instruction": "Give me the example code for `hook_image_style_delete($style)` in Drupal 7. Hook description: Respond to image style deletion.", "context": "This hook enables modules to update settings when a image style is being deleted. If a style is deleted, a replacement name may be specified in $style['name'] and the style being deleted will be specified in $style['old_name'].\n\nParameters:\n- $style: The image style array that being deleted.\n\nFile: modules/image/image.api.php", "response": "function hook_image_style_delete($style) {\n // Administrators can choose an optional replacement style when deleting.\n // Update the modules style variable accordingly.\n if (isset($style['old_name']) && $style['old_name'] == variable_get('mymodule_image_style', '')) {\n variable_set('mymodule_image_style', $style['name']);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-250e95db29", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/timer_read/7.x", "instruction": "Implement `timer_read($name)` in PHP for Drupal 7. Required behavior: Reads the current timer value without stopping the timer.", "context": "Parameters:\n- $name: The name of the timer.\n\nReturns: The current timer value in ms.\n\nFile: includes/bootstrap.inc", "response": "function timer_read($name) {\n global $timers;\n\n if (isset($timers[$name]['start'])) {\n $stop = microtime(TRUE);\n $diff = round(($stop - $timers[$name]['start']) * 1000, 2);\n\n if (isset($timers[$name]['time'])) {\n $diff += $timers[$name]['time'];\n }\n return $diff;\n }\n return $timers[$name]['time'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2511b8b645", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_hidden/7.x", "instruction": "In Drupal 7, write the function `theme_hidden($variables)` (file includes/form.inc) so that it does the following: Returns HTML for a hidden form element.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #name, #value, #attributes.\n\nFile: includes/form.inc", "response": "function theme_hidden($variables) {\n $element = $variables['element'];\n $element['#attributes']['type'] = 'hidden';\n element_set_attributes($element, array('name', 'value'));\n return '\\n\";\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-251659f50e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_assign_form_submit/7.x", "instruction": "Implement `trigger_assign_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for trigger_assign_form().", "context": "File: modules/trigger/trigger.admin.inc", "response": "function trigger_assign_form_submit($form, &$form_state) {\n if (!empty($form_state['values']['aid'])) {\n $aid = actions_function_lookup($form_state['values']['aid']);\n $weight = db_query(\"SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook\", array(':hook' => $form_state['values']['hook']))->fetchField();\n\n // Insert the new action.\n db_insert('trigger_assignments')\n ->fields(array(\n 'hook' => $form_state['values']['hook'],\n 'aid' => $aid,\n 'weight' => $weight + 1,\n ))\n ->execute();\n\n // If we are not configuring an action for a \"presave\" hook and this action\n // changes an object property, then we need to save the object, so the\n // property change will persist.\n $actions = actions_list();\n if (strpos($form_state['values']['hook'], 'presave') === FALSE && isset($actions[$aid]['behavior']) && in_array('changes_property', $actions[$aid]['behavior'])) {\n // Determine the corresponding save action name for this action.\n $save_action = strtok($aid, '_') . '_save_action';\n // If no corresponding save action exists, we need to bail out.\n if (!isset($actions[$save_action])) {\n throw new Exception(t('Missing/undefined save action (%save_aid) for %aid action.', array('%save_aid' => $aid, '%aid' => $aid)));\n }\n // Delete previous save action if it exists, and re-add it using a higher\n // weight.\n $save_action_assigned = db_query(\"SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid\", array(':hook' => $form_state['values']['hook'], ':aid' => $save_action))->fetchField();\n\n if ($save_action_assigned) {\n db_delete('trigger_assignments')\n ->condition('hook', $form_state['values']['hook'])\n ->condition('aid', $save_action)\n ->execute();\n }\n db_insert('trigger_assignments')\n ->fields(array(\n 'hook' => $form_state['values']['hook'],\n 'aid' => $save_action,\n 'weight' => $weight + 2,\n ))\n ->execute();\n\n // If no save action existed before, inform the user about it.\n if (!$save_action_assigned) {\n drupal_set_message(t('The %label action has been appended, which is required to save the property change.', array('%label' => $actions[$save_action]['label'])));\n }\n // Otherwise, just inform about the new weight.\n else {\n drupal_set_message(t('The %label action was moved to save the property change.', array('%label' => $actions[$save_action]['label'])));\n }\n }\n }\n drupal_static_reset('trigger_get_assigned_actions');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-253eb08c9e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_date_types/7.x", "instruction": "In Drupal 7, write the function `system_get_date_types($type = NULL)` (file modules/system/system.module) so that it does the following: Gets the list of available date types and attributes.", "context": "Parameters:\n- $type: (optional) The date type name.\n\nReturns: An associative array of date type information keyed by the date type name. Each date type information array has the following elements: - type: The machine-readable name of the date type. - title: The human-readable name of the date type. - locked: A boolean indicating whether or not this date type should be configurable from the user interface. - module: The name of the module that defined this date type in its hook_date_format_types(). An empty string if the date type was user-defined. - is_new: A boolean indicating whether or not this date type is as of yet unsaved in the database. If $type was defined, only a single associative array with the above elements is returned.\n\nFile: modules/system/system.module", "response": "function system_get_date_types($type = NULL) {\n $types = &drupal_static(__FUNCTION__);\n\n if (!isset($types)) {\n $types = _system_date_format_types_build();\n }\n\n return $type ? (isset($types[$type]) ? $types[$type] : FALSE) : $types;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2551842946", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_url_alter/7.x", "instruction": "Give me the example code for `hook_file_url_alter(&$uri)` in Drupal 7. Hook description: Alter the URL to a file.", "context": "This hook is called from file_create_url(), and is called fairly frequently (10+ times per page), depending on how many files there are in a given page. If CSS and JS aggregation are disabled, this can become very frequently (50+ times per page) so performance is critical.\n\nThis function should alter the URI, if it wants to rewrite the file URL.\n\nParameters:\n- $uri: The URI to a file for which we need an external URL, or the path to a shipped file.\n\nFile: modules/system/system.api.php", "response": "function hook_file_url_alter(&$uri) {\n global $user;\n\n // User 1 will always see the local file in this example.\n if ($user->uid == 1) {\n return;\n }\n\n $cdn1 = 'http://cdn1.example.com';\n $cdn2 = 'http://cdn2.example.com';\n $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');\n\n // Most CDNs don't support private file transfers without a lot of hassle,\n // so don't support this in the common case.\n $schemes = array('public');\n\n $scheme = file_uri_scheme($uri);\n\n // Only serve shipped files and public created files from the CDN.\n if (!$scheme || in_array($scheme, $schemes)) {\n // Shipped files.\n if (!$scheme) {\n $path = $uri;\n }\n // Public created files.\n else {\n $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);\n $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);\n }\n\n // Clean up Windows paths.\n $path = str_replace('\\\\', '/', $path);\n\n // Serve files with one of the CDN extensions from CDN 1, all others from\n // CDN 2.\n $pathinfo = pathinfo($path);\n if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], $cdn_extensions)) {\n $uri = $cdn1 . '/' . $path;\n }\n else {\n $uri = $cdn2 . '/' . $path;\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-256bfe3ab8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_build_tree/7.x", "instruction": "In Drupal 7, write the function `menu_build_tree($menu_name, array $parameters = array())` (file includes/menu.inc) so that it does the following: Builds a menu tree, translates links, and checks access.", "context": "Parameters:\n- $menu_name: The name of the menu.\n- $parameters: (optional) An associative array of build parameters. Possible keys: - expanded: An array of parent link ids to return only menu links that are children of one of the plids in this list. If empty, the whole menu tree is built, unless 'only_active_trail' is TRUE. - active_trail: An array of mlids, representing the coordinates of the currently active menu link. - only_active_trail: Whether to only return links that are in the active trail. This option is ignored, if 'expanded' is non-empty. Internally used for breadcrumbs. - min_depth: The minimum depth of menu links in the resulting tree. Defaults to 1, which is the default to build a whole tree for a menu (excluding menu container itself). - max_depth: The maximum depth of menu links in the resulting tree. - conditions: An associative array of custom database select query condition key/value pairs; see _menu_build_tree() for the actual query.\n\nReturns: A fully built menu tree.\n\nFile: includes/menu.inc", "response": "function menu_build_tree($menu_name, array $parameters = array()) {\n // Build the menu tree.\n $data = _menu_build_tree($menu_name, $parameters);\n // Check access for the current user to each item in the tree.\n menu_tree_check_access($data['tree'], $data['node_links']);\n return $data['tree'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-257e4c5296", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/_update_refresh/7.x", "instruction": "I need the code for `_update_refresh()` in Drupal 7 (modules/update/update.fetch.inc). It must do this: Clears out all the cached available update data and initiates re-fetching.", "context": "File: modules/update/update.fetch.inc", "response": "function _update_refresh() {\n module_load_include('inc', 'update', 'update.compare');\n\n // Since we're fetching new available update data, we want to clear\n // our cache of both the projects we care about, and the current update\n // status of the site. We do *not* want to clear the cache of available\n // releases just yet, since that data (even if it's stale) can be useful\n // during update_get_projects(); for example, to modules that implement\n // hook_system_info_alter() such as cvs_deploy.\n _update_cache_clear('update_project_projects');\n _update_cache_clear('update_project_data');\n\n $projects = update_get_projects();\n\n // Now that we have the list of projects, we should also clear our cache of\n // available release data, since even if we fail to fetch new data, we need\n // to clear out the stale data at this point.\n _update_cache_clear('available_releases::', TRUE);\n\n foreach ($projects as $key => $project) {\n update_create_fetch_task($project);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-258f1cd352", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_set_regions_to_render/7.x", "instruction": "In Drupal 7, write the function `overlay_set_regions_to_render($regions = NULL)` (file modules/overlay/overlay.module) so that it does the following: Sets the regions of the page that rendering will be limited to.", "context": "Parameters:\n- $regions: (Optional) An array containing the names of the regions that should be rendered when drupal_render_page() is called. Pass in an empty array to remove all limits and cause drupal_render_page() to render all page regions (the default behavior). If this parameter is omitted, no change will be made to the current list of regions to render.\n\nReturns: The current list of regions to render, or an empty array if the regions are not being limited.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_set_regions_to_render($regions = NULL) {\n $regions_to_render = &drupal_static(__FUNCTION__, array());\n if (isset($regions)) {\n $regions_to_render = $regions;\n }\n return $regions_to_render;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-259586e372", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_filters/7.x", "instruction": "Implement `dblog_filters()` in PHP for Drupal 7. Required behavior: Creates a list of database log administration filters that can be applied.", "context": "Returns (array): Associative array of filters. The top-level keys are used as the form element names for the filters, and the values are arrays with the following elements: - title: Title of the filter. - where: The filter condition. - options: Array of options for the select list for the filter.\n\nFile: modules/dblog/dblog.admin.inc", "response": "function dblog_filters() {\n $filters = array();\n\n foreach (_dblog_get_message_types() as $type) {\n $types[$type] = t($type);\n }\n\n if (!empty($types)) {\n $filters['type'] = array(\n 'title' => t('Type'),\n 'where' => \"w.type = ?\",\n 'options' => $types,\n );\n }\n\n $filters['severity'] = array(\n 'title' => t('Severity'),\n 'where' => 'w.severity = ?',\n 'options' => watchdog_severity_levels(),\n );\n\n return $filters;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-259c772c06", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.install/function/aggregator_uninstall/7.x", "instruction": "In Drupal 7, write the function `aggregator_uninstall()` (file modules/aggregator/aggregator.install) so that it does the following: Implements hook_uninstall().", "context": "File: modules/aggregator/aggregator.install", "response": "function aggregator_uninstall() {\n variable_del('aggregator_allowed_html_tags');\n variable_del('aggregator_summary_items');\n variable_del('aggregator_clear');\n variable_del('aggregator_category_selector');\n variable_del('aggregator_fetcher');\n variable_del('aggregator_parser');\n variable_del('aggregator_processors');\n variable_del('aggregator_teaser_length');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-259e5935d7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21help%21help.admin.inc/function/help_main/7.x", "instruction": "I need the code for `help_main()` in Drupal 7 (modules/help/help.admin.inc). It must do this: Menu callback; prints a page listing a glossary of Drupal terminology.", "context": "File: modules/help/help.admin.inc", "response": "function help_main() {\n // Add CSS\n drupal_add_css(drupal_get_path('module', 'help') . '/help.css');\n $output = '

            ' . t('Help topics') . '

            ' . t('Help is available on the following items:') . '

            ' . help_links_as_list();\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-25ca9f1a44", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_ip_blocking_form/7.x", "instruction": "I need the code for `system_ip_blocking_form($form, $form_state, $default_ip)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Define the form for blocking IP addresses.", "context": "File: modules/system/system.admin.inc", "response": "function system_ip_blocking_form($form, $form_state, $default_ip) {\n $form['ip'] = array(\n '#title' => t('IP address'),\n '#type' => 'textfield',\n '#size' => 48,\n '#maxlength' => 40,\n '#default_value' => $default_ip,\n '#description' => t('Enter a valid IP address.'),\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Add'),\n );\n $form['#submit'][] = 'system_ip_blocking_form_submit';\n $form['#validate'][] = 'system_ip_blocking_form_validate';\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-25d6898809", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_effect_delete_form/7.x", "instruction": "I need the code for `image_effect_delete_form($form, &$form_state, $style, $effect)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Form builder; Form for deleting an image effect.", "context": "Parameters:\n- $style: Name of the image style from which the image effect will be removed.\n- $effect: Name of the image effect to remove.\n\nFile: modules/image/image.admin.inc", "response": "function image_effect_delete_form($form, &$form_state, $style, $effect) {\n $form_state['image_style'] = $style;\n $form_state['image_effect'] = $effect;\n\n $question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style['label'], '@effect' => $effect['label']));\n return confirm_form($form, $question, 'admin/config/media/image-styles/edit/' . $style['name'], '', t('Delete'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-25e00e6727", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_rss_feeds_settings/7.x", "instruction": "Implement `system_rss_feeds_settings()` in PHP for Drupal 7. Required behavior: Form builder; Configure how the site handles RSS feeds.", "context": "File: modules/system/system.admin.inc", "response": "function system_rss_feeds_settings() {\n $form['feed_description'] = array(\n '#type' => 'textarea',\n '#title' => t('Feed description'),\n '#default_value' => variable_get('feed_description', ''),\n '#description' => t('Description of your site, included in each feed.')\n );\n $form['feed_default_items'] = array(\n '#type' => 'select',\n '#title' => t('Number of items in each feed'),\n '#default_value' => variable_get('feed_default_items', 10),\n '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),\n '#description' => t('Default number of items to include in each feed.')\n );\n $form['feed_item_length'] = array(\n '#type' => 'select',\n '#title' => t('Feed content'),\n '#default_value' => variable_get('feed_item_length', 'fulltext'),\n '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),\n '#description' => t('Global setting for the default display of content items in each feed.')\n );\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-25f4161852", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_render_blocks/7.x", "instruction": "In Drupal 7, write the function `_block_render_blocks($region_blocks)` (file modules/block/block.module) so that it does the following: Render the content and subject for a set of blocks.", "context": "Parameters:\n- $region_blocks: An array of block objects such as returned for one region by _block_load_blocks().\n\nReturns: An array of visible blocks as expected by drupal_render().\n\nFile: modules/block/block.module", "response": "function _block_render_blocks($region_blocks) {\n $cacheable = TRUE;\n\n // We preserve the submission of forms in blocks, by fetching from cache only\n // if the request method is 'GET' (or 'HEAD').\n if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != 'HEAD') {\n $cacheable = FALSE;\n }\n // Block caching is not usually compatible with node access modules, so by\n // default it is disabled when node access modules exist. However, it can be\n // allowed by using the variable 'block_cache_bypass_node_grants'.\n elseif (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants'))) {\n $cacheable = FALSE;\n }\n\n // Proceed to loop over all blocks in order to compute their respective cache\n // identifiers; this allows us to do one single cache_get_multiple() call\n // instead of doing one cache_get() call per block.\n $cached_blocks = array();\n $cids = array();\n\n if ($cacheable) {\n foreach ($region_blocks as $key => $block) {\n if (!isset($block->content)) {\n if (($cid = _block_get_cache_id($block))) {\n $cids[$key] = $cid;\n }\n }\n }\n\n if ($cids) {\n // We cannot pass $cids in directly because cache_get_multiple() will\n // modify it, and we need to use it later on in this function.\n $cid_values = array_values($cids);\n $cached_blocks = cache_get_multiple($cid_values, 'cache_block');\n }\n }\n\n foreach ($region_blocks as $key => $block) {\n // Render the block content if it has not been created already.\n if (!isset($block->content)) {\n // Erase the block from the static array - we'll put it back if it has\n // content.\n unset($region_blocks[$key]);\n\n $cid = empty($cids[$key]) ? NULL : $cids[$key];\n\n // Try fetching the block from the previously loaded cache entries.\n if (isset($cached_blocks[$cid])) {\n $array = $cached_blocks[$cid]->data;\n }\n else {\n $array = module_invoke($block->module, 'block_view', $block->delta);\n\n // Valid PHP function names cannot contain hyphens.\n $delta = str_replace('-', '_', $block->delta);\n // Allow modules to modify the block before it is viewed, via either\n // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().\n drupal_alter(array('block_view', \"block_view_{$block->module}_{$delta}\"), $array, $block);\n\n if (isset($cid)) {\n cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);\n }\n }\n\n if (isset($array) && is_array($array)) {\n foreach ($array as $k => $v) {\n $block->$k = $v;\n }\n }\n if (isset($block->content) && $block->content) {\n // Normalize to the drupal_render() structure.\n if (is_string($block->content)) {\n $block->content = array('#markup' => $block->content);\n }\n // Override default block title if a custom display title is present.\n if ($block->title) {\n // Check plain here to allow module generated titles to keep any\n // markup.\n $block->subject = $block->title == '' ? '' : check_plain($block->title);\n }\n if (!isset($block->subject)) {\n $block->subject = '';\n }\n $region_blocks[\"{$block->module}_{$block->delta}\"] = $block;\n }\n }\n }\n return $region_blocks;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-25ffd13eb8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_cron/7.x", "instruction": "In Drupal 7, write the function `update_cron()` (file modules/update/update.module) so that it does the following: Implements hook_cron().", "context": "File: modules/update/update.module", "response": "function update_cron() {\n $frequency = variable_get('update_check_frequency', 1);\n $interval = 60 * 60 * 24 * $frequency;\n if ((REQUEST_TIME - variable_get('update_last_check', 0)) > $interval) {\n // If the configured update interval has elapsed, we want to invalidate\n // the cached data for all projects, attempt to re-fetch, and trigger any\n // configured notifications about the new status.\n update_refresh();\n update_fetch_data();\n }\n else {\n // Otherwise, see if any individual projects are now stale or still\n // missing data, and if so, try to fetch the data.\n update_get_available(TRUE);\n }\n if ((REQUEST_TIME - variable_get('update_last_email_notification', 0)) > $interval) {\n // If configured time between notifications elapsed, send email about\n // updates possibly available.\n module_load_include('inc', 'update', 'update.fetch');\n _update_cron_notify();\n }\n\n // Clear garbage from disk.\n update_clear_update_disk_cache();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-26211ddd3f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_directory_temp/7.x", "instruction": "I need the code for `file_directory_temp()` in Drupal 7 (includes/file.inc). It must do this: Gets the path of system-appropriate temporary directory.", "context": "File: includes/file.inc", "response": "function file_directory_temp() {\n $temporary_directory = variable_get('file_temporary_path', NULL);\n\n if (empty($temporary_directory)) {\n $directories = array();\n\n // Has PHP been set with an upload_tmp_dir?\n if (ini_get('upload_tmp_dir')) {\n $directories[] = ini_get('upload_tmp_dir');\n }\n\n // Operating system specific dirs.\n if (substr(PHP_OS, 0, 3) == 'WIN') {\n $directories[] = 'c:\\\\windows\\\\temp';\n $directories[] = 'c:\\\\winnt\\\\temp';\n }\n else {\n $directories[] = '/tmp';\n }\n // PHP may be able to find an alternative tmp directory.\n // This function exists in PHP 5 >= 5.2.1, but Drupal\n // requires PHP 5 >= 5.2.0, so we check for it.\n if (function_exists('sys_get_temp_dir')) {\n $directories[] = sys_get_temp_dir();\n }\n\n foreach ($directories as $directory) {\n if (is_dir($directory) && is_writable($directory)) {\n $temporary_directory = $directory;\n break;\n }\n }\n\n if (empty($temporary_directory)) {\n // If no directory has been found default to 'files/tmp'.\n $temporary_directory = variable_get('file_public_path', conf_path() . '/files') . '/tmp';\n\n // Windows accepts paths with either slash (/) or backslash (\\), but will\n // not accept a path which contains both a slash and a backslash. Since\n // the 'file_public_path' variable may have either format, we sanitize\n // everything to use slash which is supported on all platforms.\n $temporary_directory = str_replace('\\\\', '/', $temporary_directory);\n }\n // Save the path of the discovered directory.\n variable_set('file_temporary_path', $temporary_directory);\n }\n\n return $temporary_directory;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-26453b8421", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_create_fetch_task/7.x", "instruction": "I need the code for `update_create_fetch_task($project)` in Drupal 7 (modules/update/update.module). It must do this: Creates a new fetch task after loading the necessary include file.", "context": "Parameters:\n- $project: Associative array of information about a project. See update_get_projects() for the keys used.\n\nFile: modules/update/update.module", "response": "function update_create_fetch_task($project) {\n module_load_include('inc', 'update', 'update.fetch');\n return _update_create_fetch_task($project);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2651d14dbe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/_field_extra_fields_pre_render/7.x", "instruction": "In Drupal 7, write the function `_field_extra_fields_pre_render($elements)` (file modules/field/field.module) so that it does the following: Pre-render callback to adjust weights and visibility of non-field elements.", "context": "File: modules/field/field.module", "response": "function _field_extra_fields_pre_render($elements) {\n $entity_type = $elements['#entity_type'];\n $bundle = $elements['#bundle'];\n\n if (isset($elements['#type']) && $elements['#type'] == 'form') {\n $extra_fields = field_info_extra_fields($entity_type, $bundle, 'form');\n foreach ($extra_fields as $name => $settings) {\n if (isset($elements[$name])) {\n $elements[$name]['#weight'] = $settings['weight'];\n }\n }\n }\n elseif (isset($elements['#view_mode'])) {\n $view_mode = $elements['#view_mode'];\n $extra_fields = field_extra_fields_get_display($entity_type, $bundle, $view_mode);\n foreach ($extra_fields as $name => $settings) {\n if (isset($elements[$name])) {\n $elements[$name]['#weight'] = $settings['weight'];\n // Visibility: make sure we do not accidentally show a hidden element.\n $elements[$name]['#access'] = isset($elements[$name]['#access']) ? ($elements[$name]['#access'] && $settings['visible']) : $settings['visible'];\n }\n }\n }\n\n return $elements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-26539e814c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.api.php/function/hook_overlay_parent_initialize/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_overlay_parent_initialize()` (modules/overlay/overlay.api.php): Allow modules to act when an overlay parent window is initialized.", "context": "The parent window is initialized when a page is displayed in which the overlay might be required to be displayed, so modules can act here if they need to take action to accommodate the possibility of the overlay appearing within a Drupal page.\n\nFile: modules/overlay/overlay.api.php", "response": "function hook_overlay_parent_initialize() {\n // Add our custom JavaScript.\n drupal_add_js(drupal_get_path('module', 'hook') . '/hook-overlay.js');\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-265d27fa0f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_region_list/7.x", "instruction": "In Drupal 7, write the function `system_region_list($theme_key, $show = REGIONS_ALL, $labels = TRUE)` (file modules/system/system.module) so that it does the following: Get a list of available regions from a specified theme.", "context": "Parameters:\n- $theme_key: The name of a theme.\n- $show: Possible values: REGIONS_ALL or REGIONS_VISIBLE. Visible excludes hidden regions.\n- $labels (bool): (optional) Boolean to specify whether the human readable machine names should be returned or not. Defaults to TRUE, but calling code can set this to FALSE for better performance, if it only needs machine names.\n\nReturns (array): An associative array of regions in the form $region['name'] = 'description' if $labels is set to TRUE, or $region['name'] = 'name', if $labels is set to FALSE.\n\nFile: modules/system/system.module", "response": "function system_region_list($theme_key, $show = REGIONS_ALL, $labels = TRUE) {\n $themes = list_themes();\n if (!isset($themes[$theme_key])) {\n return array();\n }\n\n $list = array();\n $info = $themes[$theme_key]->info;\n // If requested, suppress hidden regions. See block_admin_display_form().\n foreach ($info['regions'] as $name => $label) {\n if ($show == REGIONS_ALL || !isset($info['regions_hidden']) || !in_array($name, $info['regions_hidden'])) {\n if ($labels) {\n $list[$name] = t($label);\n }\n else {\n $list[$name] = $name;\n }\n }\n }\n return $list;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-265e145dd3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/_update_fetch_data/7.x", "instruction": "Implement `_update_fetch_data()` in PHP for Drupal 7. Required behavior: Attempts to drain the queue of tasks for release history data to fetch.", "context": "File: modules/update/update.fetch.inc", "response": "function _update_fetch_data() {\n $queue = DrupalQueue::get('update_fetch_tasks');\n $end = time() + variable_get('update_max_fetch_time', UPDATE_MAX_FETCH_TIME);\n while (time() < $end && ($item = $queue->claimItem())) {\n _update_process_fetch_task($item->data);\n $queue->deleteItem($item);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-266c11f344", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_radios_value/7.x", "instruction": "In Drupal 7, write the function `form_type_radios_value(&$element, $input = FALSE)` (file includes/form.inc) so that it does the following: Form value callback: Determines the value for a #type radios form element.", "context": "Parameters:\n- $element: The form element whose value is being populated.\n- $input: (optional) The incoming input to populate the form element. If FALSE, the element's default value is returned. Defaults to FALSE.\n\nReturns: The data that will appear in $form_state['values'] for this element, or nothing to use the default.\n\nFile: includes/form.inc", "response": "function form_type_radios_value(&$element, $input = FALSE) {\n if ($input !== FALSE) {\n // When there's user input (including NULL), return it as the value.\n // However, if NULL is submitted, _form_builder_handle_input_element() will\n // apply the default value, and we want that validated against #options\n // unless it's empty. (An empty #default_value, such as NULL or FALSE, can\n // be used to indicate that no radio button is selected by default.)\n if (!isset($input) && !empty($element['#default_value'])) {\n $element['#needs_validation'] = TRUE;\n }\n return $input;\n }\n else {\n // For default value handling, simply return #default_value. Additionally,\n // for a NULL default value, set #has_garbage_value to prevent\n // _form_builder_handle_input_element() converting the NULL to an empty\n // string, so that code can distinguish between nothing selected and the\n // selection of a radio button whose value is an empty string.\n $value = isset($element['#default_value']) ? $element['#default_value'] : NULL;\n if (!isset($value)) {\n $element['#has_garbage_value'] = TRUE;\n }\n return $value;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-26b2d3ad9b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_rehash/7.x", "instruction": "I need the code for `_block_rehash($theme = NULL)` in Drupal 7 (modules/block/block.module). It must do this: Updates the 'block' DB table with the blocks currently exported by modules.", "context": "Parameters:\n- $theme: The theme to rehash blocks for. If not provided, defaults to the currently used theme.\n\nReturns: Blocks currently exported by modules.\n\nFile: modules/block/block.module", "response": "function _block_rehash($theme = NULL) {\n global $theme_key;\n\n drupal_theme_initialize();\n if (!isset($theme)) {\n // If theme is not specifically set, rehash for the current theme.\n $theme = $theme_key;\n }\n $regions = system_region_list($theme);\n\n // These are the blocks the function will return.\n $blocks = array();\n // These are the blocks defined by code and modified by the database.\n $current_blocks = array();\n // These are {block}.bid values to be kept.\n $bids = array();\n $or = db_or();\n // Gather the blocks defined by modules.\n foreach (module_implements('block_info') as $module) {\n $module_blocks = module_invoke($module, 'block_info');\n $delta_list = array();\n foreach ($module_blocks as $delta => $block) {\n // Compile a condition to retrieve this block from the database.\n // Add identifiers.\n $delta_list[] = $delta;\n $block['module'] = $module;\n $block['delta'] = $delta;\n $block['theme'] = $theme;\n $current_blocks[$module][$delta] = $block;\n }\n if (!empty($delta_list)) {\n $condition = db_and()->condition('module', $module)->condition('delta', $delta_list);\n $or->condition($condition);\n }\n }\n // Save the blocks defined in code for alter context.\n $code_blocks = $current_blocks;\n $database_blocks = db_select('block', 'b', array('fetch' => PDO::FETCH_ASSOC))\n ->fields('b')\n ->condition($or)\n ->condition('theme', $theme)\n ->execute();\n $original_database_blocks = array();\n foreach ($database_blocks as $block) {\n $module = $block['module'];\n $delta = $block['delta'];\n $original_database_blocks[$module][$delta] = $block;\n // The cache mode can only by set from hook_block_info(), so that has\n // precedence over the database's value.\n if (isset($current_blocks[$module][$delta]['cache'])) {\n $block['cache'] = $current_blocks[$module][$delta]['cache'];\n }\n // Preserve info which is not in the database.\n $block['info'] = $current_blocks[$module][$delta]['info'];\n // Blocks stored in the database override the blocks defined in code.\n $current_blocks[$module][$delta] = $block;\n // Preserve this block.\n $bids[$block['bid']] = $block['bid'];\n }\n drupal_alter('block_info', $current_blocks, $theme, $code_blocks);\n foreach ($current_blocks as $module => $module_blocks) {\n foreach ($module_blocks as $delta => $block) {\n // Make sure certain attributes are set.\n $block += array(\n 'pages' => '',\n 'weight' => 0,\n 'status' => 0,\n );\n // Check for active blocks in regions that are not available.\n if (!empty($block['region']) && $block['region'] != BLOCK_REGION_NONE && !isset($regions[$block['region']]) && $block['status'] == 1) {\n drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block['info'], '%region' => $block['region'])), 'warning');\n // Disabled modules are moved into the BLOCK_REGION_NONE later so no\n // need to move the block to another region.\n $block['status'] = 0;\n }\n // Set region to none if not enabled.\n if (empty($block['status'])) {\n $block['status'] = 0;\n $block['region'] = BLOCK_REGION_NONE;\n }\n // There is no point saving disabled blocks. Still, we need to save them\n // because the 'title' attribute is saved to the {blocks} table.\n if (isset($block['bid'])) {\n // If the block has a bid property, it comes from the database and\n // the record needs to be updated, so set the primary key to 'bid'\n // before passing to drupal_write_record().\n $primary_keys = array('bid');\n // Remove a block from the list of blocks to keep if it became disabled.\n unset($bids[$block['bid']]);\n }\n else {\n $primary_keys = array();\n }\n // If the block is new or differs from the original database block, save\n // it. To determine whether there was a change it is enough to examine\n // the values for the keys in the original database record as that\n // contained every database field.\n if (!$primary_keys || array_diff_assoc($original_database_blocks[$module][$delta], $block)) {\n drupal_write_record('block', $block, $primary_keys);\n // Make it possible to test this.\n $block['saved'] = TRUE;\n }\n // Add to the list of blocks we return.\n $blocks[] = $block;\n }\n }\n if ($bids) {\n // Remove disabled that are no longer defined by the code from the\n // database.\n db_delete('block')\n ->condition('bid', $bids, 'NOT IN')\n ->condition('theme', $theme)\n ->execute();\n }\n return $blocks;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-26c39e1406", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contextual%21contextual.module/function/contextual_library/7.x", "instruction": "Implement `contextual_library()` in PHP for Drupal 7. Required behavior: Implements hook_library().", "context": "File: modules/contextual/contextual.module", "response": "function contextual_library() {\n $path = drupal_get_path('module', 'contextual');\n $libraries['contextual-links'] = array(\n 'title' => 'Contextual links',\n 'website' => 'http://drupal.org/node/473268',\n 'version' => '1.0',\n 'js' => array(\n $path . '/contextual.js' => array(),\n ),\n 'css' => array(\n $path . '/contextual.css' => array(),\n ),\n );\n return $libraries;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-26cd268fbe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_vocabulary_get_names/7.x", "instruction": "I need the code for `taxonomy_vocabulary_get_names()` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Get names for all taxonomy vocabularies.", "context": "Returns: An associative array of objects keyed by vocabulary machine name with information about taxonomy vocabularies. Each object has properties: - name: The vocabulary name. - machine_name: The machine name. - vid: The vocabulary ID.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_vocabulary_get_names() {\n $names = &drupal_static(__FUNCTION__);\n\n if (!isset($names)) {\n $names = db_query('SELECT name, machine_name, vid FROM {taxonomy_vocabulary}')->fetchAllAssoc('machine_name');\n }\n\n return $names;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-26dfaa4b68", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21engines%21phptemplate%21phptemplate.engine/function/phptemplate_theme/7.x", "instruction": "I need the code for `phptemplate_theme($existing, $type, $theme, $path)` in Drupal 7 (themes/engines/phptemplate/phptemplate.engine). It must do this: Implements hook_theme().", "context": "File: themes/engines/phptemplate/phptemplate.engine", "response": "function phptemplate_theme($existing, $type, $theme, $path) {\n $templates = drupal_find_theme_functions($existing, array($theme));\n $templates += drupal_find_theme_templates($existing, '.tpl.php', $path);\n return $templates;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-26f3d304bc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_field_entity_form_submit/7.x", "instruction": "I need the code for `locale_field_entity_form_submit($entity_type, $form, &$form_state )` in Drupal 7 (modules/locale/locale.module). It must do this: Handles field language on submit for the given entity type.", "context": "Checks if Locale is registered as a translation handler and handle possible language changes.\n\nFile: modules/locale/locale.module", "response": "function locale_field_entity_form_submit($entity_type, $form, &$form_state ) {\n if (field_has_translation_handler($entity_type, 'locale')) {\n $entity = (object) $form_state['values'];\n $current_language = entity_language($entity_type, $entity);\n list(, , $bundle) = entity_extract_ids($entity_type, $entity);\n\n foreach (field_info_instances($entity_type, $bundle) as $instance) {\n $field_name = $instance['field_name'];\n $field = field_info_field($field_name);\n $previous_language = $form[$field_name]['#language'];\n\n // Handle a possible language change: new language values are inserted,\n // previous ones are deleted.\n if ($field['translatable'] && $previous_language != $current_language) {\n $form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];\n $form_state['values'][$field_name][$previous_language] = array();\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-27057c8737", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_form_submit/7.x", "instruction": "I need the code for `comment_form_submit($form, &$form_state)` in Drupal 7 (modules/comment/comment.module). It must do this: Process comment form submissions; prepare the comment, store it, and set a redirection target.", "context": "File: modules/comment/comment.module", "response": "function comment_form_submit($form, &$form_state) {\n $node = node_load($form_state['values']['nid']);\n $comment = comment_form_submit_build_comment($form, $form_state);\n if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) {\n // Save the anonymous user information to a cookie for reuse.\n if (user_is_anonymous()) {\n user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage'))));\n }\n\n comment_save($comment);\n $form_state['values']['cid'] = $comment->cid;\n\n // Add an entry to the watchdog log.\n watchdog('content', 'Comment posted: %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)));\n\n // Explain the approval queue if necessary.\n if ($comment->status == COMMENT_NOT_PUBLISHED) {\n if (!user_access('administer comments')) {\n drupal_set_message(t('Your comment has been queued for review by site administrators and will be published after approval.'));\n }\n }\n else {\n drupal_set_message(t('Your comment has been posted.'));\n }\n $query = array();\n // Find the current display page for this comment.\n $page = comment_get_display_page($comment->cid, $node->type);\n if ($page > 0) {\n $query['page'] = $page;\n }\n // Redirect to the newly posted comment.\n $redirect = array('node/' . $node->nid, array('query' => $query, 'fragment' => 'comment-' . $comment->cid));\n }\n else {\n watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject), WATCHDOG_WARNING);\n drupal_set_message(t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject)), 'error');\n // Redirect the user to the node they are commenting on.\n $redirect = 'node/' . $node->nid;\n }\n $form_state['redirect'] = $redirect;\n // Clear the block and page caches so that anonymous users see the comment\n // they have posted.\n cache_clear_all();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-271b23e46e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_feed/7.x", "instruction": "In Drupal 7, write the function `drupal_add_feed($url = NULL, $title = '')` (file includes/common.inc) so that it does the following: Adds a feed URL for the current page.", "context": "This function can be called as long the HTML header hasn't been sent.\n\nParameters:\n- $url: An internal system path or a fully qualified external URL of the feed.\n- $title: The title of the feed.\n\nFile: includes/common.inc", "response": "function drupal_add_feed($url = NULL, $title = '') {\n $stored_feed_links = &drupal_static(__FUNCTION__, array());\n\n if (isset($url)) {\n $stored_feed_links[$url] = theme('feed_icon', array('url' => $url, 'title' => $title));\n\n drupal_add_html_head_link(array(\n 'rel' => 'alternate',\n 'type' => 'application/rss+xml',\n 'title' => $title,\n // Force the URL to be absolute, for consistency with other tags\n // output by Drupal.\n 'href' => url($url, array('absolute' => TRUE)),\n ));\n }\n return $stored_feed_links;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-27371c40f0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_block_view/7.x", "instruction": "In Drupal 7, write the function `node_block_view($delta = '')` (file modules/node/node.module) so that it does the following: Implements hook_block_view().", "context": "File: modules/node/node.module", "response": "function node_block_view($delta = '') {\n $block = array();\n\n switch ($delta) {\n case 'syndicate':\n $block['subject'] = t('Syndicate');\n $block['content'] = theme('feed_icon', array('url' => 'rss.xml', 'title' => t('Syndicate')));\n break;\n\n case 'recent':\n if (user_access('access content')) {\n $block['subject'] = t('Recent content');\n if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) {\n $block['content'] = theme('node_recent_block', array(\n 'nodes' => $nodes,\n ));\n } else {\n $block['content'] = t('No content available.');\n }\n }\n break;\n }\n return $block;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-275cebf966", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_role_submit/7.x", "instruction": "Implement `user_admin_role_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submit handler for the user_admin_role() form.", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_role_submit($form, &$form_state) {\n $role = (object) $form_state['values'];\n if ($form_state['values']['op'] == t('Save role')) {\n user_role_save($role);\n drupal_set_message(t('The role has been renamed.'));\n }\n elseif ($form_state['values']['op'] == t('Add role')) {\n user_role_save($role);\n drupal_set_message(t('The role has been added.'));\n }\n $form_state['redirect'] = 'admin/people/permissions/roles';\n return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2772ec648f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/theme_color_scheme_form/7.x", "instruction": "Implement `theme_color_scheme_form($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a theme's color form.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/color/color.module", "response": "function theme_color_scheme_form($variables) {\n $form = $variables['form'];\n\n $theme = $form['theme']['#value'];\n $info = $form['info']['#value'];\n $path = drupal_get_path('theme', $theme) . '/';\n drupal_add_css($path . $info['preview_css']);\n\n $preview_js_path = isset($info['preview_js']) ? $path . $info['preview_js'] : drupal_get_path('module', 'color') . '/' . 'preview.js';\n // Add the JS at a weight below color.js.\n drupal_add_js($preview_js_path, array('weight' => -1));\n\n $output = '';\n $output .= '
            ';\n // Color schemes\n $output .= drupal_render($form['scheme']);\n // Palette\n $output .= '
            ';\n foreach (element_children($form['palette']) as $name) {\n $output .= drupal_render($form['palette'][$name]);\n }\n $output .= '
            ';\n // Preview\n $output .= drupal_render_children($form);\n $output .= '

            ' . t('Preview') . '

            ';\n // Attempt to load preview HTML if the theme provides it.\n $preview_html_path = DRUPAL_ROOT . '/' . (isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html');\n $output .= file_get_contents($preview_html_path);\n // Close the wrapper div.\n $output .= '
            ';\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-277e1c9da4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_settings_form_submit/7.x", "instruction": "In Drupal 7, write the function `field_ui_field_settings_form_submit($form, &$form_state)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Form submission handler for field_ui_field_settings_form().", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_field_settings_form_submit($form, &$form_state) {\n $form_values = $form_state['values'];\n $field_values = $form_values['field'];\n\n // Merge incoming form values into the existing field.\n $field = field_info_field($field_values['field_name']);\n\n $entity_type = $form['#entity_type'];\n $bundle = $form['#bundle'];\n $instance = field_info_instance($entity_type, $field['field_name'], $bundle);\n\n // Update the field.\n $field = array_merge($field, $field_values);\n\n try {\n field_update_field($field);\n drupal_set_message(t('Updated field %label field settings.', array('%label' => $instance['label'])));\n $form_state['redirect'] = field_ui_next_destination($entity_type, $bundle);\n }\n catch (Exception $e) {\n drupal_set_message(t('Attempt to update field %label failed: %message.', array('%label' => $instance['label'], '%message' => $e->getMessage())), 'error');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-27814c7a38", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_edit_submit/7.x", "instruction": "In Drupal 7, write the function `book_admin_edit_submit($form, &$form_state)` (file modules/book/book.admin.inc) so that it does the following: Form submission handler for book_admin_edit().", "context": "This function takes care to save parent menu items before their children. Saving menu items in the incorrect order can break the menu tree.\n\nFile: modules/book/book.admin.inc", "response": "function book_admin_edit_submit($form, &$form_state) {\n // Save elements in the same order as defined in post rather than the form.\n // This ensures parents are updated before their children, preventing orphans.\n $order = array_flip(array_keys($form_state['input']['table']));\n $form['table'] = array_merge($order, $form['table']);\n\n foreach (element_children($form['table']) as $key) {\n if ($form['table'][$key]['#item']) {\n $row = $form['table'][$key];\n $values = $form_state['values']['table'][$key];\n\n // Update menu item if moved.\n if ($row['plid']['#default_value'] != $values['plid'] || $row['weight']['#default_value'] != $values['weight']) {\n $row['#item']['plid'] = $values['plid'];\n $row['#item']['weight'] = $values['weight'];\n menu_link_save($row['#item']);\n }\n\n // Update the title if changed.\n if ($row['title']['#default_value'] != $values['title']) {\n $node = node_load($values['nid']);\n $langcode = LANGUAGE_NONE;\n $node->title = $values['title'];\n $node->book['link_title'] = $values['title'];\n $node->revision = 1;\n $node->log = t('Title changed from %original to %current.', array('%original' => $node->title, '%current' => $values['title']));\n\n node_save($node);\n watchdog('content', 'book: updated %title.', array('%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), 'node/' . $node->nid));\n }\n }\n }\n\n drupal_set_message(t('Updated book %title.', array('%title' => $form['#node']->title)));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-278d34f7db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.processor.inc/function/aggregator_form_aggregator_admin_form_alter/7.x", "instruction": "I need the code for `aggregator_form_aggregator_admin_form_alter(&$form, $form_state)` in Drupal 7 (modules/aggregator/aggregator.processor.inc). It must do this: Implements hook_form_aggregator_admin_form_alter().", "context": "Form alter aggregator module's own form to keep processor functionality separate from aggregator API functionality.\n\nFile: modules/aggregator/aggregator.processor.inc", "response": "function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) {\n if (in_array('aggregator', variable_get('aggregator_processors', array('aggregator')))) {\n $info = module_invoke('aggregator', 'aggregator_process_info');\n $items = drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items');\n $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');\n $period[AGGREGATOR_CLEAR_NEVER] = t('Never');\n\n // Only wrap into a collapsible fieldset if there is a basic configuration.\n if (isset($form['basic_conf'])) {\n $form['modules']['aggregator'] = array(\n '#type' => 'fieldset',\n '#title' => t('Default processor settings'),\n '#description' => $info['description'],\n '#collapsible' => TRUE,\n '#collapsed' => !in_array('aggregator', variable_get('aggregator_processors', array('aggregator'))),\n );\n }\n else {\n $form['modules']['aggregator'] = array();\n }\n\n $form['modules']['aggregator']['aggregator_summary_items'] = array(\n '#type' => 'select',\n '#title' => t('Number of items shown in listing pages'),\n '#default_value' => variable_get('aggregator_summary_items', 3),\n '#empty_value' => 0,\n '#options' => $items,\n );\n\n $form['modules']['aggregator']['aggregator_clear'] = array(\n '#type' => 'select',\n '#title' => t('Discard items older than'),\n '#default_value' => variable_get('aggregator_clear', 9676800),\n '#options' => $period,\n '#description' => t('Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status'))),\n );\n\n $form['modules']['aggregator']['aggregator_category_selector'] = array(\n '#type' => 'radios',\n '#title' => t('Select categories using'),\n '#default_value' => variable_get('aggregator_category_selector', 'checkboxes'),\n '#options' => array('checkboxes' => t('checkboxes'),\n 'select' => t('multiple selector')),\n '#description' => t('For a small number of categories, checkboxes are easier to use, while a multiple selector works well with large numbers of categories.'),\n );\n $form['modules']['aggregator']['aggregator_teaser_length'] = array(\n '#type' => 'select',\n '#title' => t('Length of trimmed description'),\n '#default_value' => variable_get('aggregator_teaser_length', 600),\n '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_aggregator_characters'),\n '#description' => t(\"The maximum number of characters used in the trimmed version of content.\")\n );\n\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-27934f9611", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.api.php/function/hook_locale/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_locale($op = 'groups')` (modules/locale/locale.api.php): Allows modules to define their own text groups that can be translated.", "context": "Parameters:\n- $op: Type of operation. Currently, only supports 'groups'.\n\nFile: modules/locale/locale.api.php", "response": "function hook_locale($op = 'groups') {\n switch ($op) {\n case 'groups':\n return array('custom' => t('Custom'));\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-27956094fe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_process/7.x", "instruction": "Give me the example code for `hook_process(&$variables, $hook)` in Drupal 7. Hook description: Process theme variables for templates.", "context": "This hook allows modules to process theme variables for theme templates. It is called for all theme hooks implemented as templates, but not for theme hooks implemented as functions. hook_process_HOOK() can be used to process variables for a specific theme hook, whether implemented as a template or function.\n\nFor more detailed information, see theme().\n\nParameters:\n- $variables: The variables array (modify in place).\n- $hook: The name of the theme hook.\n\nFile: modules/system/theme.api.php", "response": "function hook_process(&$variables, $hook) {\n // Wraps variables in RDF wrappers.\n if (!empty($variables['rdf_template_variable_attributes_array'])) {\n foreach ($variables['rdf_template_variable_attributes_array'] as $variable_name => $attributes) {\n $context = array(\n 'hook' => $hook,\n 'variable_name' => $variable_name,\n 'variables' => $variables,\n );\n $variables[$variable_name] = theme('rdf_template_variable_wrapper', array('content' => $variables[$variable_name], 'attributes' => $attributes, 'context' => $context));\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-27969512be", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_export_string/7.x", "instruction": "I need the code for `_locale_export_string($str)` in Drupal 7 (includes/locale.inc). It must do this: Print out a string on multiple lines", "context": "File: includes/locale.inc", "response": "function _locale_export_string($str) {\n $stri = addcslashes($str, \"\\0..\\37\\\\\\\"\");\n $parts = array();\n\n // Cut text into several lines\n while ($stri != \"\") {\n $i = strpos($stri, \"\\\\n\");\n if ($i === FALSE) {\n $curstr = $stri;\n $stri = \"\";\n }\n else {\n $curstr = substr($stri, 0, $i + 2);\n $stri = substr($stri, $i + 2);\n }\n $curparts = explode(\"\\n\", _locale_export_wrap($curstr, 70));\n $parts = array_merge($parts, $curparts);\n }\n\n // Multiline string\n if (count($parts) > 1) {\n return \"\\\"\\\"\\n\\\"\" . implode(\"\\\"\\n\\\"\", $parts) . \"\\\"\\n\";\n }\n // Single line string\n elseif (count($parts) == 1) {\n return \"\\\"$parts[0]\\\"\\n\";\n }\n // No translation\n else {\n return \"\\\"\\\"\\n\";\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-27b901a342", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/element_children/7.x", "instruction": "In Drupal 7, write the function `element_children(&$elements, $sort = FALSE)` (file includes/common.inc) so that it does the following: Identifies the children of an element array, optionally sorted by weight.", "context": "The children of a element array are those key/value pairs whose key does not start with a '#'. See drupal_render() for details.\n\nParameters:\n- $elements: The element array whose children are to be identified.\n- $sort: Boolean to indicate whether the children should be sorted by weight.\n\nReturns: The array keys of the element's children.\n\nFile: includes/common.inc", "response": "function element_children(&$elements, $sort = FALSE) {\n // Do not attempt to sort elements which have already been sorted.\n $sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;\n\n // Filter out properties from the element, leaving only children.\n $count = count($elements);\n $child_weights = array();\n $i = 0;\n $sortable = FALSE;\n foreach ($elements as $key => $value) {\n if (is_int($key) || $key === '' || $key[0] !== '#') {\n if (is_array($value) && isset($value['#weight'])) {\n $weight = $value['#weight'];\n $sortable = TRUE;\n }\n else {\n $weight = 0;\n }\n // Support weights with up to three digit precision and conserve the\n // insertion order.\n $child_weights[$key] = floor($weight * 1000) + $i / $count;\n }\n $i++;\n }\n\n // Sort the children if necessary.\n if ($sort && $sortable) {\n asort($child_weights);\n // Put the sorted children back into $elements in the correct order, to\n // preserve sorting if the same element is passed through\n // element_children() twice.\n foreach ($child_weights as $key => $weight) {\n $value = $elements[$key];\n unset($elements[$key]);\n $elements[$key] = $value;\n }\n $elements['#sorted'] = TRUE;\n }\n\n return array_keys($child_weights);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-27d63671ec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_user_delete/7.x", "instruction": "In Drupal 7, write the function `trigger_user_delete($account)` (file modules/trigger/trigger.module) so that it does the following: Implements hook_user_delete().", "context": "File: modules/trigger/trigger.module", "response": "function trigger_user_delete($account) {\n $edit = array();\n _trigger_user('user_delete', $edit, $account, NULL);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-27d8285c37", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_extract_bundle/7.x", "instruction": "Implement `field_extract_bundle($entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Helper function to extract the bundle name of from a bundle object.", "context": "Parameters:\n- $entity_type: The type of $entity; e.g., 'node' or 'user'.\n- $bundle: The bundle object (or string if bundles for this entity type do not exist as standalone objects).\n\nReturns: The bundle name.\n\nFile: modules/field/field.module", "response": "function field_extract_bundle($entity_type, $bundle) {\n if (is_string($bundle)) {\n return $bundle;\n }\n\n $info = entity_get_info($entity_type);\n if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) {\n return $bundle->{$info['bundle keys']['bundle']};\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-27eb36ccd7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_multiple_delete_confirm_submit/7.x", "instruction": "I need the code for `node_multiple_delete_confirm_submit($form, &$form_state)` in Drupal 7 (modules/node/node.admin.inc). It must do this: Form submission handler for node_multiple_delete_confirm().", "context": "File: modules/node/node.admin.inc", "response": "function node_multiple_delete_confirm_submit($form, &$form_state) {\n if ($form_state['values']['confirm']) {\n node_delete_multiple(array_keys($form_state['values']['nodes']));\n cache_clear_all();\n $count = count($form_state['values']['nodes']);\n watchdog('content', 'Deleted @count posts.', array('@count' => $count));\n drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));\n }\n $form_state['redirect'] = 'admin/content';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-27ff1de5fc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_entity_query_alter/7.x", "instruction": "Implement `taxonomy_entity_query_alter($query)` in PHP for Drupal 7. Required behavior: Implements hook_entity_query_alter().", "context": "Converts EntityFieldQuery instances on taxonomy terms that have an entity condition on term bundles (vocabulary machine names). Since the vocabulary machine name is not present in the {taxonomy_term_data} table itself, we have to convert the bundle condition into a property condition of vocabulary IDs to match against {taxonomy_term_data}.vid.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_entity_query_alter($query) {\n $conditions = &$query->entityConditions;\n\n // Alter only taxonomy term queries with bundle conditions.\n if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) {\n // Convert vocabulary machine names to vocabulary IDs.\n $vocabulary_data = taxonomy_vocabulary_get_names();\n $vids = array();\n if (is_array($conditions['bundle']['value'])) {\n foreach ($conditions['bundle']['value'] as $vocabulary_machine_name) {\n $vids[] = $vocabulary_data[$vocabulary_machine_name]->vid;\n }\n }\n else {\n $vocabulary_machine_name = $conditions['bundle']['value'];\n $vids = $vocabulary_data[$vocabulary_machine_name]->vid;\n }\n\n $query->propertyCondition('vid', $vids, $conditions['bundle']['operator']);\n unset($conditions['bundle']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-280861364b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_menu/7.x", "instruction": "I need the code for `search_menu()` in Drupal 7 (modules/search/search.module). It must do this: Implements hook_menu().", "context": "File: modules/search/search.module", "response": "function search_menu() {\n $items['search'] = array(\n 'title' => 'Search',\n 'page callback' => 'search_view',\n 'access callback' => 'search_is_active',\n 'type' => MENU_SUGGESTED_ITEM,\n 'file' => 'search.pages.inc',\n );\n $items['admin/config/search/settings'] = array(\n 'title' => 'Search settings',\n 'description' => 'Configure relevance settings for search and other indexing options.',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('search_admin_settings'),\n 'access arguments' => array('administer search'),\n 'weight' => -10,\n 'file' => 'search.admin.inc',\n );\n $items['admin/config/search/settings/reindex'] = array(\n 'title' => 'Clear index',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('search_reindex_confirm'),\n 'access arguments' => array('administer search'),\n 'type' => MENU_VISIBLE_IN_BREADCRUMB,\n 'file' => 'search.admin.inc',\n );\n\n // Add paths for searching. We add each module search path twice: once without\n // and once with %menu_tail appended. The reason for this is that we want to\n // preserve keywords when switching tabs, and also to have search tabs\n // highlighted properly. The only way to do that within the Drupal menu\n // system appears to be having two sets of tabs. See discussion on issue\n // http://drupal.org/node/245103 for details.\n\n drupal_static_reset('search_get_info');\n $default_info = search_get_default_module_info();\n if ($default_info) {\n foreach (search_get_info() as $module => $search_info) {\n $path = 'search/' . $search_info['path'];\n $items[$path] = array(\n 'title' => $search_info['title'],\n 'page callback' => 'search_view',\n 'page arguments' => array($module, ''),\n 'access callback' => '_search_menu_access',\n 'access arguments' => array($module),\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'search.pages.inc',\n 'weight' => $module == $default_info['module'] ? -10 : 0,\n );\n $items[\"$path/%menu_tail\"] = array(\n 'title' => $search_info['title'],\n 'load arguments' => array('%map', '%index'),\n 'page callback' => 'search_view',\n 'page arguments' => array($module, 2),\n 'access callback' => '_search_menu_access',\n 'access arguments' => array($module),\n // The default local task points to its parent, but this item points to\n // where it should so it should not be changed.\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'search.pages.inc',\n 'weight' => 0,\n // These tabs are not subtabs.\n 'tab_root' => 'search/' . $default_info['path'] . '/%',\n // These tabs need to display at the same level.\n 'tab_parent' => 'search/' . $default_info['path'],\n );\n }\n }\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-281f0f46f1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_new_page_count/7.x", "instruction": "Implement `comment_new_page_count($num_comments, $new_replies, $node)` in PHP for Drupal 7. Required behavior: Calculate page number for first new comment.", "context": "Parameters:\n- $num_comments: Number of comments.\n- $new_replies: Number of new replies.\n- $node: The first new comment node.\n\nReturns: \"page=X\" if the page number is greater than zero; empty string otherwise.\n\nFile: modules/comment/comment.module", "response": "function comment_new_page_count($num_comments, $new_replies, $node) {\n $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);\n $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);\n $pagenum = NULL;\n $flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE;\n if ($num_comments <= $comments_per_page) {\n // Only one page of comments.\n $pageno = 0;\n }\n elseif ($flat) {\n // Flat comments.\n $count = $num_comments - $new_replies;\n $pageno = $count / $comments_per_page;\n }\n else {\n // Threaded comments: we build a query with a subquery to find the first\n // thread with a new comment.\n\n // 1. Find all the threads with a new comment.\n $unread_threads_query = db_select('comment')\n ->fields('comment', array('thread'))\n ->condition('nid', $node->nid)\n ->condition('status', COMMENT_PUBLISHED)\n ->orderBy('created', 'DESC')\n ->orderBy('cid', 'DESC')\n ->range(0, $new_replies);\n\n // 2. Find the first thread.\n $first_thread = db_select($unread_threads_query, 'thread')\n ->fields('thread', array('thread'))\n ->orderBy('SUBSTRING(thread, 1, (LENGTH(thread) - 1))')\n ->range(0, 1)\n ->execute()\n ->fetchField();\n\n // Remove the final '/'.\n $first_thread = substr($first_thread, 0, -1);\n\n // Find the number of the first comment of the first unread thread.\n $count = db_query('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array(\n ':status' => COMMENT_PUBLISHED,\n ':nid' => $node->nid,\n ':thread' => $first_thread,\n ))->fetchField();\n\n $pageno = $count / $comments_per_page;\n }\n\n if ($pageno >= 1) {\n $pagenum = array('page' => intval($pageno));\n }\n\n return $pagenum;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-28315ee4ce", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_system_theme_info/7.x", "instruction": "Give me the example code for `hook_system_theme_info()` in Drupal 7. Hook description: Return additional themes provided by modules.", "context": "Only use this hook for testing purposes. Use a hidden MYMODULE_test.module to implement this hook. Testing themes should be hidden, too.\n\nThis hook is invoked from _system_rebuild_theme_data() and allows modules to register additional themes outside of the regular 'themes' directories of a Drupal installation.\n\nReturns: An associative array. Each key is the system name of a theme and each value is the corresponding path to the theme's .info file.\n\nFile: modules/system/system.api.php", "response": "function hook_system_theme_info() {\n $themes['mymodule_test_theme'] = drupal_get_path('module', 'mymodule') . '/mymodule_test_theme/mymodule_test_theme.info';\n return $themes;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-283c1dcddf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_formatter_info_alter/7.x", "instruction": "Give me the example code for `hook_field_formatter_info_alter(&$info)` in Drupal 7. Hook description: Perform alterations on Field API formatter types.", "context": "Parameters:\n- $info: An array of information on formatter types exposed by hook_field_formatter_info() implementations.\n\nFile: modules/field/field.api.php", "response": "function hook_field_formatter_info_alter(&$info) {\n // Add a setting to a formatter type.\n $info['text_default']['settings'] += array(\n 'mymodule_additional_setting' => 'default value',\n );\n\n // Let a new field type re-use an existing formatter.\n $info['text_default']['field types'][] = 'my_field_type';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-284e04ca51", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7087/7.x", "instruction": "In Drupal 7, write the function `system_update_7087()` (file modules/system/system.install) so that it does the following: Enable the Announcements module; see 7.100 Release Notes for opt-out details.", "context": "File: modules/system/system.install", "response": "function system_update_7087() {\n if (!variable_get('announcements_feed_enable_by_default_opt_out', FALSE)) {\n module_enable(array('announcements_feed'), FALSE);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-284f1d0180", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_get_info/7.x", "instruction": "I need the code for `color_get_info($theme)` in Drupal 7 (modules/color/color.module). It must do this: Retrieves the Color module information for a particular theme.", "context": "File: modules/color/color.module", "response": "function color_get_info($theme) {\n static $theme_info = array();\n\n if (isset($theme_info[$theme])) {\n return $theme_info[$theme];\n }\n\n $path = drupal_get_path('theme', $theme);\n $file = DRUPAL_ROOT . '/' . $path . '/color/color.inc';\n if ($path && file_exists($file)) {\n include $file;\n $theme_info[$theme] = $info;\n return $info;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2856048576", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_help/7.x", "instruction": "I need the code for `field_sql_storage_help($path, $arg)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_help().", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function field_sql_storage_help($path, $arg) {\n switch ($path) {\n case 'admin/help#field_sql_storage':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Field SQL storage module stores field data in the database. It is the default field storage module; other field storage mechanisms may be available as contributed modules. See the Field module help page for more information about fields.', array('@field-help' => url('admin/help/field'))) . '

            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-285b645922", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/show/7.x", "instruction": "In Drupal 7, write the function `show(&$element)` (file includes/common.inc) so that it does the following: Shows a hidden element for later rendering.", "context": "You can also use render($element), which shows the element while rendering it.\n\nThe first time render() or drupal_render() is called on an element tree, as each element in the tree is rendered, it is marked with a #printed flag and the rendered children of the element are cached. Subsequent calls to render() or drupal_render() will not traverse the child tree of this element again: they will just use the cached children. So if you want to show an element, be sure to call show() on the element before its parent tree is rendered for the first time, as it will have no effect on subsequent renderings of the parent tree.\n\nParameters:\n- $element: The element to be shown.\n\nReturns: The element.\n\nFile: includes/common.inc", "response": "function show(&$element) {\n $element['#printed'] = FALSE;\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-28850e730c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_sort_title/7.x", "instruction": "I need the code for `drupal_sort_title($a, $b)` in Drupal 7 (includes/common.inc). It must do this: Array sorting callback; sorts elements by 'title' key.", "context": "File: includes/common.inc", "response": "function drupal_sort_title($a, $b) {\n if (!isset($b['title'])) {\n return -1;\n }\n if (!isset($a['title'])) {\n return 1;\n }\n return strcasecmp($a['title'], $b['title']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-288cdf72a5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_entity_info_alter/7.x", "instruction": "In Drupal 7, write the function `locale_entity_info_alter(&$entity_info)` (file modules/locale/locale.module) so that it does the following: Implements hook_entity_info_alter().", "context": "File: modules/locale/locale.module", "response": "function locale_entity_info_alter(&$entity_info) {\n $entity_info['node']['translation']['locale'] = TRUE;\n if (isset($entity_info['comment'])) {\n $entity_info['comment']['translation']['locale'] = TRUE;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2897a4852b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7054/7.x", "instruction": "I need the code for `system_update_7054()` in Drupal 7 (modules/system/system.install). It must do this: Remove {cache_*}.headers columns.", "context": "File: modules/system/system.install", "response": "function system_update_7054() {\n // Update: update_fix_d7_requirements() installs this version for cache_path\n // already, so we don't include it in this particular update. It should be\n // included in later updates though.\n $cache_tables = array(\n 'cache' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',\n 'cache_form' => 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.',\n 'cache_page' => 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.',\n 'cache_menu' => 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.',\n );\n $schema = system_schema_cache_7054();\n foreach ($cache_tables as $table => $description) {\n $schema['description'] = $description;\n db_drop_table($table);\n db_create_table($table, $schema);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-28abb398eb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/valid_url/7.x", "instruction": "I need the code for `valid_url($url, $absolute = FALSE)` in Drupal 7 (includes/common.inc). It must do this: Verifies the syntax of the given URL.", "context": "This function should only be used on actual URLs. It should not be used for Drupal menu paths, which can contain arbitrary characters. Valid values per RFC 3986.\n\nParameters:\n- $url: The URL to verify.\n- $absolute: Whether the URL is absolute (beginning with a scheme such as \"http:\").\n\nReturns: TRUE if the URL is in a valid format.\n\nFile: includes/common.inc", "response": "function valid_url($url, $absolute = FALSE) {\n if ($absolute) {\n return (bool)preg_match(\"\n /^ # Start at the beginning of the text\n (?:ftp|https?|feed):\\/\\/ # Look for ftp, http, https or feed schemes\n (?: # Userinfo (optional) which is typically\n (?:(?:[\\w\\.\\-\\+!$&'\\(\\)*\\+,;=]|%[0-9a-f]{2})+:)* # a username or a username and password\n (?:[\\w\\.\\-\\+%!$&'\\(\\)*\\+,;=]|%[0-9a-f]{2})+@ # combination\n )?\n (?:\n (?:[a-z0-9\\-\\.]|%[0-9a-f]{2})+ # A domain name or a IPv4 address\n |(?:\\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\\]) # or a well formed IPv6 address\n )\n (?::[0-9]+)? # Server port number (optional)\n (?:[\\/|\\?]\n (?:[\\w#!:\\.\\?\\+=&@$'~*,;\\/\\(\\)\\[\\]\\-]|%[0-9a-f]{2}) # The path and query (optional)\n *)?\n $/xi\", $url);\n }\n else {\n return (bool)preg_match(\"/^(?:[\\w#!:\\.\\?\\+=&@$'~*,;\\/\\(\\)\\[\\]\\-]|%[0-9a-f]{2})+$/i\", $url);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-28ae856e17", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_update_nodes/7.x", "instruction": "I need the code for `node_type_update_nodes($old_type, $type)` in Drupal 7 (modules/node/node.module). It must do this: Updates all nodes of one type to be of another type.", "context": "Parameters:\n- $old_type: The current node type of the nodes.\n- $type: The new node type of the nodes.\n\nReturns: The number of nodes whose node type field was modified.\n\nFile: modules/node/node.module", "response": "function node_type_update_nodes($old_type, $type) {\n return db_update('node')\n ->fields(array('type' => $type))\n ->condition('type', $old_type)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-28cd36e33d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_permission/7.x", "instruction": "I need the code for `book_permission()` in Drupal 7 (modules/book/book.module). It must do this: Implements hook_permission().", "context": "File: modules/book/book.module", "response": "function book_permission() {\n return array(\n 'administer book outlines' => array(\n 'title' => t('Administer book outlines'),\n ),\n 'create new books' => array(\n 'title' => t('Create new books'),\n ),\n 'add content to books' => array(\n 'title' => t('Add content and child pages to books'),\n ),\n 'access printer-friendly version' => array(\n 'title' => t('View printer-friendly books'),\n 'description' => t('View a book page and all of its sub-pages as a single document for ease of printing. Can be performance heavy.'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-28d040cc91", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail_system/7.x", "instruction": "In Drupal 7, write the function `drupal_mail_system($module, $key)` (file includes/mail.inc) so that it does the following: Returns an object that implements the MailSystemInterface interface.", "context": "Allows for one or more custom mail backends to format and send mail messages composed using drupal_mail().\n\nAn implementation needs to implement the following methods:\n- format: Allows to preprocess, format, and postprocess a mail\n message before it is passed to the sending system. By default, all messages\n may contain HTML and are converted to plain-text by the DefaultMailSystem\n implementation. For example, an alternative implementation could override\n the default implementation and additionally sanitize the HTML for usage in\n a MIME-encoded e-mail, but still invoking the DefaultMailSystem\n implementation to generate an alternate plain-text version for sending.\n- mail: Sends a message through a custom mail sending engine.\n By default, all messages are sent via PHP's mail() function by the\n DefaultMailSystem implementation.\n\nThe selection of a particular implementation is controlled via the variable 'mail_system', which is a keyed array. The default implementation is the class whose name is the value of 'default-system' key. A more specific match first to key and then to module will be used in preference to the default. To specify a different class for all mail sent by one module, set the class name as the value for the key corresponding to the module name. To specify a class for a particular message sent by one module, set the class name as the value for the array key that is the message id, which is \"${module}_${key}\".\n\nFor example to debug all mail sent by the user module by logging it to a file, you might set the variable as something like:\n\nParameters:\n- $module: The module name which was used by drupal_mail() to invoke hook_mail().\n- $key: A key to identify the e-mail sent. The final e-mail ID for the e-mail alter hook in drupal_mail() would have been {$module}_{$key}.\n\nReturns: MailSystemInterface\n\nFile: includes/mail.inc", "response": "function drupal_mail_system($module, $key) {\n $instances = &drupal_static(__FUNCTION__, array());\n\n $id = $module . '_' . $key;\n\n $configuration = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));\n\n // Look for overrides for the default class, starting from the most specific\n // id, and falling back to the module name.\n if (isset($configuration[$id])) {\n $class = $configuration[$id];\n }\n elseif (isset($configuration[$module])) {\n $class = $configuration[$module];\n }\n else {\n $class = $configuration['default-system'];\n }\n\n if (empty($instances[$class])) {\n $interfaces = class_implements($class);\n if (isset($interfaces['MailSystemInterface'])) {\n $instances[$class] = new $class();\n }\n else {\n throw new Exception(t('Class %class does not implement interface %interface', array('%class' => $class, '%interface' => 'MailSystemInterface')));\n }\n }\n return $instances[$class];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2903e3936d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contextual%21contextual.module/function/contextual_element_info/7.x", "instruction": "I need the code for `contextual_element_info()` in Drupal 7 (modules/contextual/contextual.module). It must do this: Implements hook_element_info().", "context": "File: modules/contextual/contextual.module", "response": "function contextual_element_info() {\n $types['contextual_links'] = array(\n '#pre_render' => array('contextual_pre_render_links'),\n '#theme' => 'links__contextual',\n '#links' => array(),\n '#prefix' => '',\n '#attributes' => array(\n 'class' => array('contextual-links'),\n ),\n '#attached' => array(\n 'library' => array(\n array('contextual', 'contextual-links'),\n ),\n ),\n );\n return $types;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-290762c573", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_form_system_performance_settings_alter/7.x", "instruction": "I need the code for `block_form_system_performance_settings_alter(&$form, &$form_state)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_form_FORM_ID_alter().", "context": "File: modules/block/block.module", "response": "function block_form_system_performance_settings_alter(&$form, &$form_state) {\n $disabled = (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants')));\n $form['caching']['block_cache'] = array(\n '#type' => 'checkbox',\n '#title' => t('Cache blocks'),\n '#default_value' => variable_get('block_cache', FALSE),\n '#disabled' => $disabled,\n '#description' => $disabled ? t('Block caching is inactive because you have enabled modules defining content access restrictions.') : NULL,\n '#weight' => -1,\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-290b8ddc0f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_assign_form/7.x", "instruction": "Implement `trigger_assign_form($form, $form_state, $module, $hook, $label)` in PHP for Drupal 7. Required behavior: Returns the form for assigning an action to a trigger.", "context": "Parameters:\n- $module: The name of the trigger group, e.g., 'node'.\n- $hook: The name of the trigger hook, e.g., 'node_insert'.\n- $label: A plain English description of what this trigger does.\n\nFile: modules/trigger/trigger.admin.inc", "response": "function trigger_assign_form($form, $form_state, $module, $hook, $label) {\n $form['module'] = array(\n '#type' => 'hidden',\n '#value' => $module,\n );\n $form['hook'] = array(\n '#type' => 'hidden',\n '#value' => $hook,\n );\n // All of these forms use the same validate and submit functions.\n $form['#validate'][] = 'trigger_assign_form_validate';\n $form['#submit'][] = 'trigger_assign_form_submit';\n\n $options = array();\n $functions = array();\n // Restrict the options list to actions that declare support for this hook.\n foreach (actions_list() as $func => $metadata) {\n if (isset($metadata['triggers']) && array_intersect(array($hook, 'any'), $metadata['triggers'])) {\n $functions[] = $func;\n }\n }\n foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) {\n if (in_array($action['callback'], $functions)) {\n $options[$action['type']][$aid] = $action['label'];\n }\n }\n\n $form[$hook] = array(\n '#type' => 'fieldset',\n // !description is correct, since these labels are passed through t() in\n // hook_trigger_info().\n '#title' => t('Trigger: !description', array('!description' => $label)),\n '#theme' => 'trigger_display',\n );\n\n // Retrieve actions that are already assigned to this hook combination.\n $actions = trigger_get_assigned_actions($hook);\n $form[$hook]['assigned']['#type'] = 'value';\n $form[$hook]['assigned']['#value'] = array();\n foreach ($actions as $aid => $info) {\n // If action is defined unassign it, otherwise offer to delete all orphaned\n // actions.\n $hash = drupal_hash_base64($aid, TRUE);\n if (actions_function_lookup($hash)) {\n $form[$hook]['assigned']['#value'][$aid] = array(\n 'label' => $info['label'],\n 'link' => l(t('unassign'), \"admin/structure/trigger/unassign/$module/$hook/$hash\"),\n );\n }\n else {\n // Link to system_actions_remove_orphans() to do the clean up.\n $form[$hook]['assigned']['#value'][$aid] = array(\n 'label' => $info['label'],\n 'link' => l(t('Remove orphaned actions'), \"admin/config/system/actions/orphan\"),\n );\n }\n }\n\n $form[$hook]['parent'] = array(\n '#type' => 'container',\n '#attributes' => array('class' => array('container-inline')),\n );\n // List possible actions that may be assigned.\n if (count($options) != 0) {\n $form[$hook]['parent']['aid'] = array(\n '#type' => 'select',\n '#title' => t('List of trigger actions when !description', array('!description' => $label)),\n '#title_display' => 'invisible',\n '#options' => $options,\n '#empty_option' => t('Choose an action'),\n );\n $form[$hook]['parent']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Assign')\n );\n }\n else {\n $form[$hook]['none'] = array(\n '#markup' => t('No actions available for this trigger. Add action.', array('@link' => url('admin/config/system/actions/manage')))\n );\n }\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-290d79d5d7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/_filter_xss_attributes/7.x", "instruction": "I need the code for `_filter_xss_attributes($attr)` in Drupal 7 (includes/common.inc). It must do this: Processes a string of HTML attributes.", "context": "Returns: Cleaned up version of the HTML attributes.\n\nFile: includes/common.inc", "response": "function _filter_xss_attributes($attr) {\n $attrarr = array();\n $mode = 0;\n $attrname = '';\n\n while (strlen($attr) != 0) {\n // Was the last operation successful?\n $working = 0;\n\n switch ($mode) {\n case 0:\n // Attribute name, href for instance.\n if (preg_match('/^([-a-zA-Z][-a-zA-Z0-9]*)/', $attr, $match)) {\n $attrname = strtolower($match[1]);\n $skip = (\n $attrname == 'style' ||\n substr($attrname, 0, 2) == 'on' ||\n substr($attrname, 0, 1) == '-' ||\n // Ignore long attributes to avoid unnecessary processing overhead.\n strlen($attrname) > 96\n );\n $working = $mode = 1;\n $attr = preg_replace('/^[-a-zA-Z][-a-zA-Z0-9]*/', '', $attr);\n }\n break;\n\n case 1:\n // Equals sign or valueless (\"selected\").\n if (preg_match('/^\\s*=\\s*/', $attr)) {\n $working = 1; $mode = 2;\n $attr = preg_replace('/^\\s*=\\s*/', '', $attr);\n break;\n }\n\n if (preg_match('/^\\s+/', $attr)) {\n $working = 1; $mode = 0;\n if (!$skip) {\n $attrarr[] = $attrname;\n }\n $attr = preg_replace('/^\\s+/', '', $attr);\n }\n break;\n\n case 2:\n // Attribute value, a URL after href= for instance.\n if (preg_match('/^\"([^\"]*)\"(\\s+|$)/', $attr, $match)) {\n $thisval = filter_xss_bad_protocol($match[1]);\n\n if (!$skip) {\n $attrarr[] = \"$attrname=\\\"$thisval\\\"\";\n }\n $working = 1;\n $mode = 0;\n $attr = preg_replace('/^\"[^\"]*\"(\\s+|$)/', '', $attr);\n break;\n }\n\n if (preg_match(\"/^'([^']*)'(\\s+|$)/\", $attr, $match)) {\n $thisval = filter_xss_bad_protocol($match[1]);\n\n if (!$skip) {\n $attrarr[] = \"$attrname='$thisval'\";\n }\n $working = 1; $mode = 0;\n $attr = preg_replace(\"/^'[^']*'(\\s+|$)/\", '', $attr);\n break;\n }\n\n if (preg_match(\"%^([^\\s\\\"']+)(\\s+|$)%\", $attr, $match)) {\n $thisval = filter_xss_bad_protocol($match[1]);\n\n if (!$skip) {\n $attrarr[] = \"$attrname=\\\"$thisval\\\"\";\n }\n $working = 1; $mode = 0;\n $attr = preg_replace(\"%^[^\\s\\\"']+(\\s+|$)%\", '', $attr);\n }\n break;\n }\n\n if ($working == 0) {\n // Not well formed; remove and try again.\n $attr = preg_replace('/\n ^\n (\n \"[^\"]*(\"|$) # - a string that starts with a double quote, up until the next double quote or the end of the string\n | # or\n \\'[^\\']*(\\'|$)| # - a string that starts with a quote, up until the next quote or the end of the string\n | # or\n \\S # - a non-whitespace character\n )* # any number of the above three\n \\s* # any number of whitespaces\n /x', '', $attr);\n $mode = 0;\n }\n }\n\n // The attribute list ends with a valueless attribute like \"selected\".\n if ($mode == 1 && !$skip) {\n $attrarr[] = $attrname;\n }\n return $attrarr;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-292fae120d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_insert/7.x", "instruction": "Implement `book_node_insert($node)` in PHP for Drupal 7. Required behavior: Implements hook_node_insert().", "context": "File: modules/book/book.module", "response": "function book_node_insert($node) {\n if (!empty($node->book['bid'])) {\n if ($node->book['bid'] == 'new') {\n // New nodes that are their own book.\n $node->book['bid'] = $node->nid;\n }\n $node->book['nid'] = $node->nid;\n $node->book['menu_name'] = book_menu_name($node->book['bid']);\n _book_update_outline($node);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-295d7a351e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_tablename/7.x", "instruction": "I need the code for `_field_sql_storage_tablename($field)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Generate a table name for a field data table.", "context": "Parameters:\n- $field: The field structure.\n\nReturns: A string containing the generated name for the database table\n\nFile: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function _field_sql_storage_tablename($field) {\n if ($field['deleted']) {\n return \"field_deleted_data_{$field['id']}\";\n }\n else {\n return \"field_data_{$field['field_name']}\";\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-29685b1184", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7000/7.x", "instruction": "In Drupal 7, write the function `node_update_7000()` (file modules/node/node.install) so that it does the following: Upgrade the node type table and fix node type 'module' attribute to avoid name-space conflicts.", "context": "File: modules/node/node.install", "response": "function node_update_7000() {\n // Rename the module column to base.\n db_change_field('node_type', 'module', 'base', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));\n\n db_add_field('node_type', 'module', array(\n 'description' => 'The module defining this node type.',\n 'type' => 'varchar',\n 'default' => '',\n 'length' => 255,\n 'not null' => TRUE,\n ));\n\n db_add_field('node_type', 'disabled', array(\n 'description' => 'A boolean indicating whether the node type is disabled.',\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'tiny'\n ));\n\n $modules = db_select('system', 's')\n ->fields('s', array('name'))\n ->condition('type', 'module');\n db_update('node_type')\n ->expression('module', 'base')\n ->condition('base', $modules, 'IN')\n ->execute();\n\n db_update('node_type')\n ->fields(array('base' => 'node_content'))\n ->condition('base', 'node')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-297f4f6b54", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21pager.inc/function/pager_load_array/7.x", "instruction": "In Drupal 7, write the function `pager_load_array($value, $element, $old_array)` (file includes/pager.inc) so that it does the following: Helper function", "context": "Copies $old_array to $new_array and sets $new_array[$element] = $value Fills in $new_array[0 .. $element - 1] = 0\n\nFile: includes/pager.inc", "response": "function pager_load_array($value, $element, $old_array) {\n $new_array = $old_array;\n // Look for empty elements.\n for ($i = 0; $i < $element; $i++) {\n if (empty($new_array[$i])) {\n // Load found empty element with 0.\n $new_array[$i] = 0;\n }\n }\n // Update the changed element.\n $new_array[$element] = (int) $value;\n return $new_array;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-29acf54c66", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21json-encode.inc/function/drupal_json_encode_helper/7.x", "instruction": "Implement `drupal_json_encode_helper($var)` in PHP for Drupal 7. Required behavior: Encodes a PHP variable to HTML-safe JSON for PHP versions below 5.3.0.", "context": "File: includes/json-encode.inc", "response": "function drupal_json_encode_helper($var) {\n switch (gettype($var)) {\n case 'boolean':\n return $var ? 'true' : 'false'; // Lowercase necessary!\n\n case 'integer':\n case 'double':\n return $var;\n\n case 'resource':\n case 'string':\n // Always use Unicode escape sequences (\\u0022) over JSON escape\n // sequences (\\\") to prevent browsers interpreting these as\n // special characters.\n $replace_pairs = array(\n // \", \\ and U+0000 - U+001F must be escaped according to RFC 4627.\n '\\\\' => '\\u005C',\n '\"' => '\\u0022',\n \"\\x00\" => '\\u0000',\n \"\\x01\" => '\\u0001',\n \"\\x02\" => '\\u0002',\n \"\\x03\" => '\\u0003',\n \"\\x04\" => '\\u0004',\n \"\\x05\" => '\\u0005',\n \"\\x06\" => '\\u0006',\n \"\\x07\" => '\\u0007',\n \"\\x08\" => '\\u0008',\n \"\\x09\" => '\\u0009',\n \"\\x0a\" => '\\u000A',\n \"\\x0b\" => '\\u000B',\n \"\\x0c\" => '\\u000C',\n \"\\x0d\" => '\\u000D',\n \"\\x0e\" => '\\u000E',\n \"\\x0f\" => '\\u000F',\n \"\\x10\" => '\\u0010',\n \"\\x11\" => '\\u0011',\n \"\\x12\" => '\\u0012',\n \"\\x13\" => '\\u0013',\n \"\\x14\" => '\\u0014',\n \"\\x15\" => '\\u0015',\n \"\\x16\" => '\\u0016',\n \"\\x17\" => '\\u0017',\n \"\\x18\" => '\\u0018',\n \"\\x19\" => '\\u0019',\n \"\\x1a\" => '\\u001A',\n \"\\x1b\" => '\\u001B',\n \"\\x1c\" => '\\u001C',\n \"\\x1d\" => '\\u001D',\n \"\\x1e\" => '\\u001E',\n \"\\x1f\" => '\\u001F',\n // Prevent browsers from interpreting these as as special.\n \"'\" => '\\u0027',\n '<' => '\\u003C',\n '>' => '\\u003E',\n '&' => '\\u0026',\n // Prevent browsers from interpreting the solidus as special and\n // non-compliant JSON parsers from interpreting // as a comment.\n '/' => '\\u002F',\n // While these are allowed unescaped according to ECMA-262, section\n // 15.12.2, they cause problems in some JSON parsers.\n \"\\xe2\\x80\\xa8\" => '\\u2028', // U+2028, Line Separator.\n \"\\xe2\\x80\\xa9\" => '\\u2029', // U+2029, Paragraph Separator.\n );\n\n return '\"' . strtr($var, $replace_pairs) . '\"';\n\n case 'array':\n // Arrays in JSON can't be associative. If the array is empty or if it\n // has sequential whole number keys starting with 0, it's not associative\n // so we can go ahead and convert it as an array.\n if (empty($var) || array_keys($var) === range(0, sizeof($var) - 1)) {\n $output = array();\n foreach ($var as $v) {\n $output[] = drupal_json_encode_helper($v);\n }\n return '[ ' . implode(', ', $output) . ' ]';\n }\n // Otherwise, fall through to convert the array as an object.\n\n case 'object':\n $output = array();\n foreach ($var as $k => $v) {\n $output[] = drupal_json_encode_helper(strval($k)) . ':' . drupal_json_encode_helper($v);\n }\n return '{' . implode(', ', $output) . '}';\n\n default:\n return 'null';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-29b182f788", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_revert_form/7.x", "instruction": "I need the code for `image_style_revert_form($form, &$form_state, $style)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Confirmation form to revert a database style to its default.", "context": "File: modules/image/image.admin.inc", "response": "function image_style_revert_form($form, &$form_state, $style) {\n $form_state['image_style'] = $style;\n\n return confirm_form(\n $form,\n t('Revert the %style style?', array('%style' => $style['label'])),\n 'admin/config/media/image-styles',\n t('Reverting this style will delete the customized settings and restore the defaults provided by the @module module.', array('@module' => $style['module'])),\n t('Revert'), t('Cancel')\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-29fbd9b202", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21help%21help.admin.inc/function/help_links_as_list/7.x", "instruction": "In Drupal 7, write the function `help_links_as_list()` (file modules/help/help.admin.inc) so that it does the following: Provides a formatted list of available help topics.", "context": "Returns: A string containing the formatted list.\n\nFile: modules/help/help.admin.inc", "response": "function help_links_as_list() {\n $empty_arg = drupal_help_arg();\n $module_info = system_rebuild_module_data();\n\n $modules = array();\n foreach (module_implements('help', TRUE) as $module) {\n if (module_invoke($module, 'help', \"admin/help#$module\", $empty_arg)) {\n $modules[$module] = $module_info[$module]->info['name'];\n }\n }\n asort($modules);\n\n // Output pretty four-column list.\n $count = count($modules);\n $break = ceil($count / 4);\n $output = '
              ';\n $i = 0;\n foreach ($modules as $module => $name) {\n $output .= '
            • ' . l($name, 'admin/help/' . $module) . '
            • ';\n if (($i + 1) % $break == 0 && ($i + 1) != $count) {\n $output .= '
              ';\n }\n $i++;\n }\n $output .= '
            ';\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-29ff6f0712", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_batch_build/7.x", "instruction": "Implement `_locale_batch_build($files, $finished = NULL, $components = array())` in PHP for Drupal 7. Required behavior: Build a locale batch from an array of files.", "context": "Parameters:\n- $files: Array of files to import.\n- $finished: Optional finished callback for the batch.\n- $components: Optional list of component names the batch covers. Used in the installer.\n\nReturns: A batch structure.\n\nFile: includes/locale.inc", "response": "function _locale_batch_build($files, $finished = NULL, $components = array()) {\n $t = get_t();\n if (count($files)) {\n $operations = array();\n foreach ($files as $file) {\n // We call _locale_batch_import for every batch operation.\n $operations[] = array('_locale_batch_import', array($file->uri));\n }\n $batch = array(\n 'operations' => $operations,\n 'title' => $t('Importing interface translations'),\n 'init_message' => $t('Starting import'),\n 'error_message' => $t('Error importing interface translations'),\n 'file' => 'includes/locale.inc',\n // This is not a batch API construct, but data passed along to the\n // installer, so we know what did we import already.\n '#components' => $components,\n );\n if (isset($finished)) {\n $batch['finished'] = $finished;\n }\n return $batch;\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2a063c1f96", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7013/7.x", "instruction": "Implement `system_update_7013()` in PHP for Drupal 7. Required behavior: Convert default time zone offset to default time zone name.", "context": "File: modules/system/system.install", "response": "function system_update_7013() {\n $timezone = NULL;\n $timezones = system_time_zones();\n // If the contributed Date module set a default time zone name, use this\n // setting as the default time zone.\n if (($timezone_name = variable_get('date_default_timezone_name')) && isset($timezones[$timezone_name])) {\n $timezone = $timezone_name;\n }\n // If the contributed Event module has set a default site time zone, look up\n // the time zone name and use it as the default time zone.\n if (!$timezone && ($timezone_id = variable_get('date_default_timezone_id', 0))) {\n try {\n $timezone_name = db_query('SELECT name FROM {event_timezones} WHERE timezone = :timezone_id', array(':timezone_id' => $timezone_id))->fetchField();\n if (($timezone_name = str_replace(' ', '_', $timezone_name)) && isset($timezones[$timezone_name])) {\n $timezone = $timezone_name;\n }\n }\n catch (PDOException $e) {\n // Ignore error if event_timezones table does not exist or unexpected\n // schema found.\n }\n }\n\n // Check to see if timezone was overriden in update_prepare_d7_bootstrap().\n $offset = variable_get('date_temporary_timezone');\n // If not, use the default.\n if (!isset($offset)) {\n $offset = variable_get('date_default_timezone', 0);\n }\n\n // If the previous default time zone was a non-zero offset, guess the site's\n // intended time zone based on that offset and the server's daylight saving\n // time status.\n if (!$timezone && $offset) {\n $timezone_name = timezone_name_from_abbr('', intval($offset), date('I'));\n if ($timezone_name && isset($timezones[$timezone_name])) {\n $timezone = $timezone_name;\n }\n }\n // Otherwise, the default time zone offset was zero, which is UTC.\n if (!$timezone) {\n $timezone = 'UTC';\n }\n variable_set('date_default_timezone', $timezone);\n drupal_set_message(format_string('The default time zone has been set to %timezone. Check the date and time configuration page to configure it correctly.', array('%timezone' => $timezone, '@config-url' => url('admin/config/regional/settings'))), 'warning');\n // Remove temporary override.\n variable_del('date_temporary_timezone');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2a1eb11fce", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_role_load/7.x", "instruction": "In Drupal 7, write the function `user_role_load($rid)` (file modules/user/user.module) so that it does the following: Fetches a user role by role ID.", "context": "Parameters:\n- $rid: An integer representing the role ID.\n\nReturns: A fully-loaded role object if a role with the given ID exists, or FALSE otherwise.\n\nFile: modules/user/user.module", "response": "function user_role_load($rid) {\n return db_select('role', 'r')\n ->fields('r')\n ->condition('rid', $rid)\n ->execute()\n ->fetchObject();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2a2114d7a9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_uri/7.x", "instruction": "I need the code for `comment_uri($comment)` in Drupal 7 (modules/comment/comment.module). It must do this: Implements callback_entity_info_uri().", "context": "File: modules/comment/comment.module", "response": "function comment_uri($comment) {\n return array(\n 'path' => 'comment/' . $comment->cid,\n 'options' => array('fragment' => 'comment-' . $comment->cid),\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2a26cf1371", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_path/7.x", "instruction": "I need the code for `image_style_path($style_name, $uri)` in Drupal 7 (modules/image/image.module). It must do this: Returns the URI of an image when using a style.", "context": "The path returned by this function may not exist. The default generation method only creates images when they are requested by a user's browser.\n\nParameters:\n- $style_name: The name of the style to be used with this image.\n- $uri: The URI or path to the image.\n\nReturns: The URI to an image style image.\n\nFile: modules/image/image.module", "response": "function image_style_path($style_name, $uri) {\n $scheme = file_uri_scheme($uri);\n if ($scheme) {\n $path = file_uri_target($uri);\n }\n else {\n $path = $uri;\n $scheme = file_default_scheme();\n }\n return $scheme . '://styles/' . $style_name . '/' . $scheme . '/' . $path;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2a6752a724", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/_trigger_comment/7.x", "instruction": "I need the code for `_trigger_comment($a1, $hook)` in Drupal 7 (modules/trigger/trigger.module). It must do this: Calls action functions for comment triggers.", "context": "Parameters:\n- $a1: Comment object or array of form values.\n- $hook: Hook to trigger.\n\nFile: modules/trigger/trigger.module", "response": "function _trigger_comment($a1, $hook) {\n // Keep objects for reuse so that changes actions make to objects can persist.\n static $objects;\n $aids = trigger_get_assigned_actions($hook);\n $context = array(\n 'group' => 'comment',\n 'hook' => $hook,\n );\n // We need to get the expected object if the action's type is not 'comment'.\n // We keep the object in $objects so we can reuse it if we have multiple\n // actions that make changes to an object.\n foreach ($aids as $aid => $info) {\n $type = $info['type'];\n if ($type != 'comment') {\n if (!isset($objects[$type])) {\n $objects[$type] = _trigger_normalize_comment_context($type, $a1);\n }\n // Since we know about the comment, we pass it along to the action\n // in case it wants to peek at it.\n $context['comment'] = (object) $a1;\n actions_do($aid, $objects[$type], $context);\n }\n else {\n actions_do($aid, $a1, $context);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2a839b4825", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_styles_alter/7.x", "instruction": "Give me the example code for `hook_image_styles_alter(&$styles)` in Drupal 7. Hook description: Modify any image styles provided by other modules or the user.", "context": "This hook allows modules to modify, add, or remove image styles. This may be useful to modify default styles provided by other modules or enforce that a specific effect is always enabled on a style. Note that modifications to these styles may negatively affect the user experience, such as if an effect is added to a style through this hook, the user may attempt to remove the effect but it will be immediately be re-added.\n\nThe best use of this hook is usually to modify default styles, which are not editable by the user until they are overridden, so such interface contradictions will not occur. This hook can target default (or user) styles by checking the $style['storage'] property.\n\nIf your module needs to provide a new style (rather than modify an existing one) use hook_image_default_styles() instead.\n\nFile: modules/image/image.api.php", "response": "function hook_image_styles_alter(&$styles) {\n // Check that we only affect a default style.\n if ($styles['thumbnail']['storage'] == IMAGE_STORAGE_DEFAULT) {\n // Add an additional effect to the thumbnail style.\n $styles['thumbnail']['effects'][] = array(\n 'name' => 'image_desaturate',\n 'data' => array(),\n 'weight' => 1,\n 'effect callback' => 'image_desaturate_effect',\n );\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-2aa57580fe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/template_preprocess_poll_bar/7.x", "instruction": "Implement `template_preprocess_poll_bar(&$variables)` in PHP for Drupal 7. Required behavior: Preprocess the poll_bar theme hook.", "context": "Inputs: $title, $votes, $total_votes, $voted, $block\n\nFile: modules/poll/poll.module", "response": "function template_preprocess_poll_bar(&$variables) {\n if ($variables['block']) {\n $variables['theme_hook_suggestions'][] = 'poll_bar__block';\n }\n $variables['title'] = check_plain($variables['title']);\n $variables['percentage'] = round($variables['votes'] * 100 / max($variables['total_votes'], 1));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2aad595375", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21password.inc/function/_password_crypt/7.x", "instruction": "I need the code for `_password_crypt($algo, $password, $setting)` in Drupal 7 (includes/password.inc). It must do this: Hash a password using a secure stretched hash.", "context": "By using a salt and repeated hashing the password is \"stretched\". Its security is increased because it becomes much more computationally costly for an attacker to try to break the hash by brute-force computation of the hashes of a large number of plain-text words or strings to find a match.\n\nParameters:\n- $algo: The string name of a hashing algorithm usable by hash(), like 'sha256'.\n- $password: Plain-text password up to 512 bytes (128 to 512 UTF-8 characters) to hash.\n- $setting: An existing hash or the output of _password_generate_salt(). Must be at least 12 characters (the settings and salt).\n\nReturns: A string containing the hashed password (and salt) or FALSE on failure. The return string will be truncated at DRUPAL_HASH_LENGTH characters max.\n\nFile: includes/password.inc", "response": "function _password_crypt($algo, $password, $setting) {\n // Prevent DoS attacks by refusing to hash large passwords.\n if (strlen($password) > 512) {\n return FALSE;\n }\n // The first 12 characters of an existing hash are its setting string.\n $setting = substr($setting, 0, 12);\n\n if ($setting[0] != '$' || $setting[2] != '$') {\n return FALSE;\n }\n $count_log2 = _password_get_count_log2($setting);\n // Hashes may be imported from elsewhere, so we allow != DRUPAL_HASH_COUNT\n if ($count_log2 < DRUPAL_MIN_HASH_COUNT || $count_log2 > DRUPAL_MAX_HASH_COUNT) {\n return FALSE;\n }\n $salt = substr($setting, 4, 8);\n // Hashes must have an 8 character salt.\n if (strlen($salt) != 8) {\n return FALSE;\n }\n\n // Convert the base 2 logarithm into an integer.\n $count = 1 << $count_log2;\n\n // We rely on the hash() function being available in PHP 5.2+.\n $hash = hash($algo, $salt . $password, TRUE);\n do {\n $hash = hash($algo, $hash . $password, TRUE);\n } while (--$count);\n\n $len = strlen($hash);\n $output = $setting . _password_base64_encode($hash, $len);\n // _password_base64_encode() of a 16 byte MD5 will always be 22 characters.\n // _password_base64_encode() of a 64 byte sha512 will always be 86 characters.\n $expected = 12 + ceil((8 * $len) / 6);\n return (strlen($output) == $expected) ? substr($output, 0, DRUPAL_HASH_LENGTH) : FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ac84fd9a1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_logout/7.x", "instruction": "Implement `user_logout()` in PHP for Drupal 7. Required behavior: Menu callback; logs the current user out, and redirects to the home page.", "context": "File: modules/user/user.pages.inc", "response": "function user_logout() {\n user_logout_current_user();\n drupal_goto();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ad926d0fb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_field_cache/7.x", "instruction": "I need the code for `_field_info_field_cache()` in Drupal 7 (modules/field/field.info.inc). It must do this: Retrieves the FieldInfo object for the current request.", "context": "Returns: FieldInfo An instance of the FieldInfo class.\n\nFile: modules/field/field.info.inc", "response": "function _field_info_field_cache() {\n // Use the advanced drupal_static() pattern, since this is called very often.\n static $drupal_static_fast;\n\n if (!isset($drupal_static_fast)) {\n $drupal_static_fast['field_info_field_cache'] = &drupal_static(__FUNCTION__);\n }\n $field_info = &$drupal_static_fast['field_info_field_cache'];\n\n if (!isset($field_info)) {\n // @todo The registry should save the need for an explicit include, but not\n // a couple upgrade tests (DisabledNodeTypeTestCase,\n // FilterFormatUpgradePathTestCase...) break in a strange way without it.\n include_once dirname(__FILE__) . '/field.info.class.inc';\n $field_info = new FieldInfo();\n }\n\n return $field_info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2afd84b007", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_exit/7.x", "instruction": "I need the code for `drupal_exit($destination = NULL)` in Drupal 7 (includes/common.inc). It must do this: Performs end-of-request tasks.", "context": "In some cases page requests need to end without calling drupal_page_footer(). In these cases, call drupal_exit() instead. There should rarely be a reason to call exit instead of drupal_exit();\n\nParameters:\n- $destination: If this function is called from drupal_goto(), then this argument will be a fully-qualified URL that is the destination of the redirect. This should be passed along to hook_exit() implementations.\n\nFile: includes/common.inc", "response": "function drupal_exit($destination = NULL) {\n if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) {\n if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') {\n module_invoke_all('exit', $destination);\n }\n drupal_session_commit();\n }\n exit;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2afe329ab7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21image.inc/function/image_resize/7.x", "instruction": "In Drupal 7, write the function `image_resize(stdClass $image, $width, $height)` (file includes/image.inc) so that it does the following: Resizes an image to the given dimensions (ignoring aspect ratio).", "context": "Parameters:\n- $image: An image object returned by image_load().\n- $width: The target width, in pixels.\n- $height: The target height, in pixels.\n\nReturns: TRUE on success, FALSE on failure.\n\nFile: includes/image.inc", "response": "function image_resize(stdClass $image, $width, $height) {\n $width = (int) round($width);\n $height = (int) round($height);\n\n return image_toolkit_invoke('resize', $image, array($width, $height));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2afea4f6c3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_edit_menu/7.x", "instruction": "Implement `menu_edit_menu($form, &$form_state, $type, $menu = array())` in PHP for Drupal 7. Required behavior: Menu callback; Build the form that handles the adding/editing of a custom menu.", "context": "File: modules/menu/menu.admin.inc", "response": "function menu_edit_menu($form, &$form_state, $type, $menu = array()) {\n $system_menus = menu_list_system_menus();\n $menu += array(\n 'menu_name' => '',\n 'old_name' => !empty($menu['menu_name']) ? $menu['menu_name'] : '',\n 'title' => '',\n 'description' => '',\n );\n // Allow menu_edit_menu_submit() and other form submit handlers to determine\n // whether the menu already exists.\n $form['#insert'] = empty($menu['old_name']);\n $form['old_name'] = array(\n '#type' => 'value',\n '#value' => $menu['old_name'],\n );\n\n $form['title'] = array(\n '#type' => 'textfield',\n '#title' => t('Title'),\n '#default_value' => $menu['title'],\n '#required' => TRUE,\n // The title of a system menu cannot be altered.\n '#access' => !isset($system_menus[$menu['menu_name']]),\n );\n\n $form['menu_name'] = array(\n '#type' => 'machine_name',\n '#title' => t('Menu name'),\n '#default_value' => $menu['menu_name'],\n '#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI,\n '#description' => t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'),\n '#field_prefix' => empty($menu['old_name']) ? 'menu-' : '',\n '#machine_name' => array(\n 'exists' => 'menu_edit_menu_name_exists',\n 'source' => array('title'),\n 'replace_pattern' => '[^a-z0-9-]+',\n 'replace' => '-',\n ),\n // A menu's machine name cannot be changed.\n '#disabled' => !empty($menu['old_name']) || isset($system_menus[$menu['menu_name']]),\n );\n\n $form['description'] = array(\n '#type' => 'textarea',\n '#title' => t('Description'),\n '#default_value' => $menu['description'],\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save'),\n );\n // Only custom menus may be deleted.\n $form['actions']['delete'] = array(\n '#type' => 'submit',\n '#value' => t('Delete'),\n '#access' => $type == 'edit' && !isset($system_menus[$menu['menu_name']]),\n '#submit' => array('menu_custom_delete_submit'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2b0095f9e3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_edit_form_validate/7.x", "instruction": "In Drupal 7, write the function `locale_translate_edit_form_validate($form, &$form_state)` (file modules/locale/locale.admin.inc) so that it does the following: Validate string editing form submissions.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_translate_edit_form_validate($form, &$form_state) {\n // Locale string check is needed for default textgroup only.\n $safe_check_needed = $form_state['values']['textgroup'] == 'default';\n foreach ($form_state['values']['translations'] as $key => $value) {\n if ($safe_check_needed && !locale_string_is_safe($value)) {\n form_set_error('translations', t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));\n watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2b012c6b1d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_form_get_state/7.x", "instruction": "I need the code for `field_form_get_state($parents, $field_name, $langcode, &$form_state)` in Drupal 7 (modules/field/field.form.inc). It must do this: Retrieves processing information about a field from $form_state.", "context": "Parameters:\n- $parents: The array of #parents where the field lives in the form.\n- $field_name: The field name.\n- $langcode: The language in which the field values are entered.\n- $form_state: The form state.\n\nReturns: An array with the following key/data pairs: - field: the field definition array, - instance: the field instance definition array, - items_count: the number of widgets to display for the field, - array_parents: the location of the field's widgets within the $form structure. This entry is populated at '#after_build' time. - errors: the array of field validation errors reported on the field. This entry is populated at field_attach_form_validate() time.\n\nFile: modules/field/field.form.inc", "response": "function field_form_get_state($parents, $field_name, $langcode, &$form_state) {\n $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode);\n return drupal_array_get_nested_value($form_state, $form_state_parents);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2b2bd10460", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_update_7000/7.x", "instruction": "In Drupal 7, write the function `locale_update_7000()` (file modules/locale/locale.install) so that it does the following: Add context field index and allow longer location.", "context": "File: modules/locale/locale.install", "response": "function locale_update_7000() {\n db_drop_index('locales_source', 'source');\n db_add_index('locales_source', 'source_context', array(array('source', 30), 'context'));\n\n // Also drop the 'textgroup_location' index added by the i18nstrings module\n // of the i18n project, which prevents the below schema update from running.\n if (db_index_exists('locales_source', 'textgroup_location')) {\n db_drop_index('locales_source', 'textgroup_location');\n }\n\n db_change_field('locales_source', 'location', 'location', array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'size' => 'big',\n 'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.',\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2b489ab446", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/_node_mass_update_batch_process/7.x", "instruction": "Implement `_node_mass_update_batch_process($nodes, $updates, &$context)` in PHP for Drupal 7. Required behavior: Implements callback_batch_operation().", "context": "Executes a batch operation for node_mass_update().\n\nParameters:\n- $nodes (array): An array of node IDs.\n- $updates (array): Associative array of updates.\n- $context (array): An array of contextual key/values.\n\nFile: modules/node/node.admin.inc", "response": "function _node_mass_update_batch_process($nodes, $updates, &$context) {\n if (!isset($context['sandbox']['progress'])) {\n $context['sandbox']['progress'] = 0;\n $context['sandbox']['max'] = count($nodes);\n $context['sandbox']['nodes'] = $nodes;\n }\n\n // Process nodes by groups of 5.\n $count = min(5, count($context['sandbox']['nodes']));\n for ($i = 1; $i <= $count; $i++) {\n // For each nid, load the node, reset the values, and save it.\n $nid = array_shift($context['sandbox']['nodes']);\n $node = _node_mass_update_helper($nid, $updates);\n\n // Store result for post-processing in the finished callback.\n $context['results'][] = l($node->title, 'node/' . $node->nid);\n\n // Update our progress information.\n $context['sandbox']['progress']++;\n }\n\n // Inform the batch engine that we are not finished,\n // and provide an estimation of the completion level we reached.\n if ($context['sandbox']['progress'] != $context['sandbox']['max']) {\n $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2b6f5a8525", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_parse_message/7.x", "instruction": "In Drupal 7, write the function `_openid_parse_message($message)` (file modules/openid/openid.inc) so that it does the following: Convert a direct communication message into an associative array.", "context": "File: modules/openid/openid.inc", "response": "function _openid_parse_message($message) {\n $parsed_message = array();\n\n $items = explode(\"\\n\", $message);\n foreach ($items as $item) {\n $parts = explode(':', $item, 2);\n\n if (count($parts) == 2) {\n $parsed_message[$parts[0]] = $parts[1];\n }\n }\n\n return $parsed_message;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2b8c39ca11", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21mail.inc/function/_drupal_html_to_mail_urls/7.x", "instruction": "I need the code for `_drupal_html_to_mail_urls($match = NULL, $reset = FALSE)` in Drupal 7 (includes/mail.inc). It must do this: Keeps track of URLs and replaces them with placeholder tokens.", "context": "Callback for preg_replace_callback() within drupal_html_to_text().\n\nFile: includes/mail.inc", "response": "function _drupal_html_to_mail_urls($match = NULL, $reset = FALSE) {\n global $base_url, $base_path;\n static $urls = array(), $regexp;\n\n if ($reset) {\n // Reset internal URL list.\n $urls = array();\n }\n else {\n if (empty($regexp)) {\n $regexp = '@^' . preg_quote($base_path, '@') . '@';\n }\n if ($match) {\n list(, , $url, $label) = $match;\n // Ensure all URLs are absolute.\n $urls[] = strpos($url, '://') ? $url : preg_replace($regexp, $base_url . '/', $url);\n return $label . ' [' . count($urls) . ']';\n }\n }\n return $urls;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2bcbf5ac97", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_parse_header/7.x", "instruction": "I need the code for `_locale_import_parse_header($header)` in Drupal 7 (includes/locale.inc). It must do this: Parses a Gettext Portable Object file header", "context": "Parameters:\n- $header: A string containing the complete header.\n\nReturns: An associative array of key-value pairs.\n\nFile: includes/locale.inc", "response": "function _locale_import_parse_header($header) {\n $header_parsed = array();\n $lines = array_map('trim', explode(\"\\n\", $header));\n foreach ($lines as $line) {\n if ($line) {\n list($tag, $contents) = explode(\":\", $line, 2);\n $header_parsed[trim($tag)] = trim($contents);\n }\n }\n return $header_parsed;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c09a6f5e6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_help/7.x", "instruction": "I need the code for `block_help($path, $arg)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_help().", "context": "File: modules/block/block.module", "response": "function block_help($path, $arg) {\n switch ($path) {\n case 'admin/help#block':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Block module allows you to create boxes of content, which are rendered into an area, or region, of one or more pages of a website. The core Seven administration theme, for example, implements the regions \"Content\", \"Help\", \"Dashboard main\", and \"Dashboard sidebar\", and a block may appear in any one of these regions. The Blocks administration page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. For more information, see the online handbook entry for Block module.', array('@block' => 'http://drupal.org/documentation/modules/block/', '@blocks' => url('admin/structure/block'))) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Positioning content') . '
            ';\n $output .= '
            ' . t('When working with blocks, remember that all themes do not implement the same regions, or display regions in the same way. Blocks are positioned on a per-theme basis. Users with the Administer blocks permission can disable blocks. Disabled blocks are listed on the Blocks administration page, but are not displayed in any region.', array('@block' => 'http://drupal.org/documentation/modules/block/', '@blocks' => url('admin/structure/block'))) . '
            ';\n $output .= '
            ' . t('Controlling visibility') . '
            ';\n $output .= '
            ' . t('Blocks can be configured to be visible only on certain pages, only to users of certain roles, or only on pages displaying certain content types. Administrators can also allow specific blocks to be enabled or disabled by users when they edit their My account page. Some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.', array('@content-type' => url('admin/structure/types'), '@user' => url('user'))) . '
            ';\n $output .= '
            ' . t('Creating custom blocks') . '
            ';\n $output .= '
            ' . t('Users with the Administer blocks permission can add custom blocks, which are then listed on the Blocks administration page. Once created, custom blocks behave just like default and module-generated blocks.', array('@blocks' => url('admin/structure/block'), '@block-add' => url('admin/structure/block/add'))) . '
            ';\n $output .= '
            ';\n return $output;\n\n case 'admin/structure/block/add':\n return '

            ' . t('Use this page to create a new custom block.') . '

            ';\n }\n if ($arg[0] == 'admin' && $arg[1] == 'structure' && $arg['2'] == 'block' && (empty($arg[3]) || $arg[3] == 'list')) {\n $demo_theme = !empty($arg[4]) ? $arg[4] : variable_get('theme_default', 'bartik');\n $themes = list_themes();\n $output = '

            ' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the Save blocks button at the bottom of the page. Click the configure link next to each block to configure its specific title and visibility settings.') . '

            ';\n $output .= '

            ' . l(t('Demonstrate block regions (!theme)', array('!theme' => $themes[$demo_theme]->info['name'])), 'admin/structure/block/demo/' . $demo_theme) . '

            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c2ddb7868", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/template_preprocess_comment/7.x", "instruction": "I need the code for `template_preprocess_comment(&$variables)` in Drupal 7 (modules/comment/comment.module). It must do this: Process variables for comment.tpl.php.", "context": "File: modules/comment/comment.module", "response": "function template_preprocess_comment(&$variables) {\n $comment = $variables['elements']['#comment'];\n $node = $variables['elements']['#node'];\n $variables['comment'] = $comment;\n $variables['node'] = $node;\n $variables['author'] = theme('username', array('account' => $comment));\n\n $variables['created'] = format_date($comment->created);\n\n // Avoid calling format_date() twice on the same timestamp.\n if ($comment->changed == $comment->created) {\n $variables['changed'] = $variables['created'];\n }\n else {\n $variables['changed'] = format_date($comment->changed);\n }\n\n $variables['new'] = !empty($comment->new) ? t('new') : '';\n $variables['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : '';\n $variables['signature'] = $comment->signature;\n\n $uri = entity_uri('comment', $comment);\n $uri['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark'));\n\n $variables['title'] = l($comment->subject, $uri['path'], $uri['options']);\n $variables['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);\n $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created']));\n\n // Preprocess fields.\n field_attach_preprocess('comment', $comment, $variables['elements'], $variables);\n\n // Helpful $content variable for templates.\n foreach (element_children($variables['elements']) as $key) {\n $variables['content'][$key] = $variables['elements'][$key];\n }\n\n // Set status to a string representation of comment->status.\n if (isset($comment->in_preview)) {\n $variables['status'] = 'comment-preview';\n }\n else {\n $variables['status'] = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published';\n }\n\n // Gather comment classes.\n // 'comment-published' class is not needed, it is either 'comment-preview' or\n // 'comment-unpublished'.\n if ($variables['status'] != 'comment-published') {\n $variables['classes_array'][] = $variables['status'];\n }\n if ($variables['new']) {\n $variables['classes_array'][] = 'comment-new';\n }\n if (!$comment->uid) {\n $variables['classes_array'][] = 'comment-by-anonymous';\n }\n else {\n if ($comment->uid == $variables['node']->uid) {\n $variables['classes_array'][] = 'comment-by-node-author';\n }\n if ($comment->uid == $variables['user']->uid) {\n $variables['classes_array'][] = 'comment-by-viewer';\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c385351d7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_get_roles_by_format/7.x", "instruction": "I need the code for `filter_get_roles_by_format($format)` in Drupal 7 (modules/filter/filter.module). It must do this: Retrieves a list of roles that are allowed to use a given text format.", "context": "Parameters:\n- $format: An object representing the text format.\n\nReturns: An array of role names, keyed by role ID.\n\nFile: modules/filter/filter.module", "response": "function filter_get_roles_by_format($format) {\n // Handle the fallback format upfront (all roles have access to this format).\n if ($format->format == filter_fallback_format()) {\n return user_roles();\n }\n // Do not list any roles if the permission does not exist.\n $permission = filter_permission_name($format);\n return !empty($permission) ? user_roles(FALSE, $permission) : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c5842955b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_may_be_available/7.x", "instruction": "Implement `lock_may_be_available($name)` in PHP for Drupal 7. Required behavior: Check if lock acquired by a different process may be available.", "context": "If an existing lock has expired, it is removed.\n\nParameters:\n- $name: The name of the lock.\n\nReturns: TRUE if there is no lock or it was removed, FALSE otherwise.\n\nFile: includes/lock.inc", "response": "function lock_may_be_available($name) {\n $lock = db_query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc();\n if (!$lock) {\n return TRUE;\n }\n $expire = (float) $lock['expire'];\n $now = microtime(TRUE);\n if ($now > $expire) {\n // We check two conditions to prevent a race condition where another\n // request acquired the lock and set a new expire time. We add a small\n // number to $expire to avoid errors with float to string conversion.\n return (bool) db_delete('semaphore')\n ->condition('name', $name)\n ->condition('value', $lock['value'])\n ->condition('expire', 0.0001 + $expire, '<=')\n ->execute();\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c58f5247c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.maintenance.inc/function/theme_authorize_report/7.x", "instruction": "Implement `theme_authorize_report($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a results report of an operation run by authorize.php.", "context": "Parameters:\n- $variables: An associative array containing: - messages: An array of result messages.\n\nFile: includes/theme.maintenance.inc", "response": "function theme_authorize_report($variables) {\n $messages = $variables['messages'];\n $output = '';\n if (!empty($messages)) {\n $output .= '
            ';\n foreach ($messages as $heading => $logs) {\n $items = array();\n foreach ($logs as $number => $log_message) {\n if ($number === '#abort') {\n continue;\n }\n $items[] = theme('authorize_message', array('message' => $log_message['message'], 'success' => $log_message['success']));\n }\n $output .= theme('item_list', array('items' => $items, 'title' => $heading));\n }\n $output .= '
            ';\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c89fe44a8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.pages.inc/function/comment_approve/7.x", "instruction": "Implement `comment_approve($cid)` in PHP for Drupal 7. Required behavior: Menu callback; publish specified comment.", "context": "Parameters:\n- $cid: A comment identifier.\n\nFile: modules/comment/comment.pages.inc", "response": "function comment_approve($cid) {\n if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], \"comment/$cid/approve\")) {\n return MENU_ACCESS_DENIED;\n }\n if ($comment = comment_load($cid)) {\n $comment->status = COMMENT_PUBLISHED;\n comment_save($comment);\n\n drupal_set_message(t('Comment approved.'));\n drupal_goto('node/' . $comment->nid);\n }\n return MENU_NOT_FOUND;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c9099285d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_page_set_cache/7.x", "instruction": "In Drupal 7, write the function `drupal_page_set_cache()` (file includes/common.inc) so that it does the following: Stores the current page in the cache.", "context": "If page_compression is enabled, a gzipped version of the page is stored in the cache to avoid compressing the output on each request. The cache entry is unzipped in the relatively rare event that the page is requested by a client without gzip support.\n\nPage compression requires the PHP zlib extension (http://php.net/manual/ref.zlib.php).\n\nFile: includes/common.inc", "response": "function drupal_page_set_cache() {\n global $base_root;\n\n if (drupal_page_is_cacheable()) {\n\n // Check whether the current page might be compressed.\n $page_compressed = variable_get('page_compression', TRUE) && extension_loaded('zlib');\n\n $cache = (object) array(\n 'cid' => $base_root . request_uri(),\n 'data' => array(\n 'path' => $_GET['q'],\n 'body' => ob_get_clean(),\n 'title' => drupal_get_title(),\n 'headers' => array(),\n // We need to store whether page was compressed or not,\n // because by the time it is read, the configuration might change.\n 'page_compressed' => $page_compressed,\n ),\n 'expire' => CACHE_TEMPORARY,\n 'created' => REQUEST_TIME,\n );\n\n // Restore preferred header names based on the lower-case names returned\n // by drupal_get_http_header().\n $header_names = _drupal_set_preferred_header_name();\n foreach (drupal_get_http_header() as $name_lower => $value) {\n $cache->data['headers'][$header_names[$name_lower]] = $value;\n if ($name_lower == 'expires') {\n // Use the actual timestamp from an Expires header if available.\n $cache->expire = strtotime($value);\n }\n }\n\n if ($cache->data['body']) {\n if ($page_compressed) {\n $cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP);\n }\n cache_set($cache->cid, $cache->data, 'cache_page', $cache->expire);\n }\n return $cache;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c96570bba", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_get_filename_perform_file_scan/7.x", "instruction": "Implement `_drupal_get_filename_perform_file_scan($type, $name)` in PHP for Drupal 7. Required behavior: Performs a file system scan to search for a system resource.", "context": "Parameters:\n- $type: The type of the item (theme, theme_engine, module, profile).\n- $name: The name of the item for which the filename is requested.\n\nReturns: The filename of the requested item or FALSE if the item is not found.\n\nFile: includes/bootstrap.inc", "response": "function _drupal_get_filename_perform_file_scan($type, $name) {\n // The location of files will not change during the request, so do not use\n // drupal_static().\n static $dirs = array(), $files = array();\n\n // We have a consistent directory naming: modules, themes...\n $dir = $type . 's';\n if ($type == 'theme_engine') {\n $dir = 'themes/engines';\n $extension = 'engine';\n }\n elseif ($type == 'theme') {\n $extension = 'info';\n }\n else {\n $extension = $type;\n }\n\n // Check if we had already scanned this directory/extension combination.\n if (!isset($dirs[$dir][$extension])) {\n // Log that we have now scanned this directory/extension combination\n // into a static variable so as to prevent unnecessary file scans.\n $dirs[$dir][$extension] = TRUE;\n if (!function_exists('drupal_system_listing')) {\n require_once DRUPAL_ROOT . '/includes/common.inc';\n }\n // Scan the appropriate directories for all files with the requested\n // extension, not just the file we are currently looking for. This\n // prevents unnecessary scans from being repeated when this function is\n // called more than once in the same page request.\n $matches = drupal_system_listing(\"/^\" . DRUPAL_PHP_FUNCTION_PATTERN . \"\\.$extension$/\", $dir, 'name', 0);\n foreach ($matches as $matched_name => $file) {\n // Log the locations found in the file scan into a static variable.\n $files[$type][$matched_name] = $file->uri;\n }\n }\n\n // Return the results of the file system scan, or FALSE to indicate the file\n // was not found.\n return isset($files[$type][$name]) ? $files[$type][$name] : FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c96d74247", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21language.api.php/function/hook_language_negotiation_info/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_language_negotiation_info()` (modules/system/language.api.php): Define language negotiation providers.", "context": "Returns: An associative array of language negotiation provider definitions. The keys are provider identifiers, and the values are associative arrays defining each provider, with the following elements: - types: An array of allowed language types. If a language negotiation provider does not specify which language types it should be used with, it will be available for all the configurable language types. - callbacks: An associative array of functions that will be called to perform various tasks. Possible elements are: - language: (required) Name of the callback function that determines the language value. - switcher: (optional) Name of the callback function that determines links for a language switcher block associated with this provider. See language_switcher_url() for an example. - url_rewrite: (optional) Name of the callback function that provides URL rewriting, if needed by this provider. - file: The file where callback functions are defined (this file will be included before the callbacks are invoked). - weight: The default weight of the provider. - name: The translated human-readable name for the provider. - description: A translated longer description of the provider. - config: An internal path pointing to the provider's configuration page. - cache: The value Drupal's page cache should be set to for the current provider to be invoked.\n\nFile: modules/system/language.api.php", "response": "function hook_language_negotiation_info() {\n return array(\n 'custom_language_provider' => array(\n 'callbacks' => array(\n 'language' => 'custom_language_provider_callback',\n 'switcher' => 'custom_language_switcher_callback',\n 'url_rewrite' => 'custom_language_url_rewrite_callback',\n ),\n 'file' => drupal_get_path('module', 'custom') . '/custom.module',\n 'weight' => -4,\n 'types' => array('custom_language_type'),\n 'name' => t('Custom language negotiation provider'),\n 'description' => t('This is a custom language negotiation provider.'),\n 'cache' => 0,\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c98c4c7f7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.admin.inc/function/profile_admin_settings_autocomplete/7.x", "instruction": "In Drupal 7, write the function `profile_admin_settings_autocomplete($string)` (file modules/profile/profile.admin.inc) so that it does the following: Retrieve a pipe delimited string of autocomplete suggestions for profile categories", "context": "File: modules/profile/profile.admin.inc", "response": "function profile_admin_settings_autocomplete($string) {\n $matches = array();\n $result = db_select('profile_field')\n ->fields('profile_field', array('category'))\n ->condition('category', db_like($string) . '%', 'LIKE')\n ->range(0, 10)\n ->execute();\n\n foreach ($result as $data) {\n $matches[$data->category] = check_plain($data->category);\n }\n drupal_json_output($matches);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2c9bda2b32", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_node_get_translations/7.x", "instruction": "Implement `translation_node_get_translations($tnid)` in PHP for Drupal 7. Required behavior: Gets all nodes in a given translation set.", "context": "Parameters:\n- $tnid: The translation source nid of the translation set, the identifier of the node used to derive all translations in the set.\n\nReturns (Array): of partial node objects (nid, title, language) representing all nodes in the translation set, in effect all translations of node $tnid, including node $tnid itself. Because these are partial nodes, you need to node_load() the full node, if you need more properties. The array is indexed by language code.\n\nFile: modules/translation/translation.module", "response": "function translation_node_get_translations($tnid) {\n if (is_numeric($tnid) && $tnid) {\n $translations = &drupal_static(__FUNCTION__, array());\n\n if (!isset($translations[$tnid])) {\n $translations[$tnid] = array();\n $result = db_select('node', 'n')\n ->fields('n', array('nid', 'type', 'uid', 'status', 'title', 'language'))\n ->condition('n.tnid', $tnid)\n ->addTag('node_access')\n ->execute();\n\n foreach ($result as $node) {\n $langcode = entity_language('node', $node);\n $translations[$tnid][$langcode] = $node;\n }\n }\n return $translations[$tnid];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2caca1ec89", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_actions_delete_form/7.x", "instruction": "I need the code for `system_actions_delete_form($form, &$form_state, $action)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Create the form for confirmation of deleting an action.", "context": "File: modules/system/system.admin.inc", "response": "function system_actions_delete_form($form, &$form_state, $action) {\n $form['aid'] = array(\n '#type' => 'hidden',\n '#value' => $action->aid,\n );\n return confirm_form($form,\n t('Are you sure you want to delete the action %action?', array('%action' => $action->label)),\n 'admin/config/system/actions/manage',\n t('This cannot be undone.'),\n t('Delete'),\n t('Cancel')\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2cbdc955ed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21registry.inc/function/_registry_parse_files/7.x", "instruction": "I need the code for `_registry_parse_files($files)` in Drupal 7 (includes/registry.inc). It must do this: Parse all changed files and save their interface and class listings.", "context": "Parse all files that have changed since the registry was last built, and save their interface and class listings.\n\nParameters:\n- $files: The list of files to check and parse.\n\nFile: includes/registry.inc", "response": "function _registry_parse_files($files) {\n $parsed_files = array();\n foreach ($files as $filename => $file) {\n if (file_exists($filename)) {\n $hash = hash_file('sha256', $filename);\n if (empty($file['hash']) || $file['hash'] != $hash) {\n $file['hash'] = $hash;\n $parsed_files[$filename] = $file;\n }\n }\n }\n foreach ($parsed_files as $filename => $file) {\n _registry_parse_file($filename, file_get_contents($filename), $file['module'], $file['weight']);\n db_merge('registry_file')\n ->key(array('filename' => $filename))\n ->fields(array(\n 'hash' => $file['hash'],\n ))\n ->execute();\n }\n return array_keys($parsed_files);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2cc6369868", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_get_parents_all/7.x", "instruction": "I need the code for `taxonomy_get_parents_all($tid)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Find all ancestors of a given term ID.", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_get_parents_all($tid) {\n $cache = &drupal_static(__FUNCTION__, array());\n\n if (isset($cache[$tid])) {\n return $cache[$tid];\n }\n\n $parents = array();\n if ($term = taxonomy_term_load($tid)) {\n $parents[] = $term;\n $n = 0;\n while ($parent = taxonomy_get_parents($parents[$n]->tid)) {\n $parents = array_merge($parents, $parent);\n $n++;\n }\n }\n\n $cache[$tid] = $parents;\n\n return $parents;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ccccf7912", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/drupal_find_theme_templates/7.x", "instruction": "I need the code for `drupal_find_theme_templates($cache, $extension, $path)` in Drupal 7 (includes/theme.inc). It must do this: Allows themes and/or theme engines to easily discover overridden templates.", "context": "Parameters:\n- $cache: The existing cache of theme hooks to test against.\n- $extension: The extension that these templates will have.\n- $path: The path to search.\n\nFile: includes/theme.inc", "response": "function drupal_find_theme_templates($cache, $extension, $path) {\n $implementations = array();\n\n // Collect paths to all sub-themes grouped by base themes. These will be\n // used for filtering. This allows base themes to have sub-themes in its\n // folder hierarchy without affecting the base themes template discovery.\n $theme_paths = array();\n foreach (list_themes() as $theme_info) {\n if (!empty($theme_info->base_theme)) {\n $theme_paths[$theme_info->base_theme][$theme_info->name] = dirname($theme_info->filename);\n }\n }\n foreach ($theme_paths as $basetheme => $subthemes) {\n foreach ($subthemes as $subtheme => $subtheme_path) {\n if (isset($theme_paths[$subtheme])) {\n $theme_paths[$basetheme] = array_merge($theme_paths[$basetheme], $theme_paths[$subtheme]);\n }\n }\n }\n global $theme;\n $subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : array();\n\n // Escape the periods in the extension.\n $regex = '/' . str_replace('.', '\\.', $extension) . '$/';\n // Get a listing of all template files in the path to search.\n $files = drupal_system_listing($regex, $path, 'name', 0);\n\n // Find templates that implement registered theme hooks and include that in\n // what is returned so that the registry knows that the theme has this\n // implementation.\n foreach ($files as $template => $file) {\n // Ignore sub-theme templates for the current theme.\n if (strpos($file->uri, str_replace($subtheme_paths, '', $file->uri)) !== 0) {\n continue;\n }\n // Chop off the remaining extensions if there are any. $template already\n // has the rightmost extension removed, but there might still be more,\n // such as with .tpl.php, which still has .tpl in $template at this point.\n if (($pos = strpos($template, '.')) !== FALSE) {\n $template = substr($template, 0, $pos);\n }\n // Transform - in filenames to _ to match function naming scheme\n // for the purposes of searching.\n $hook = strtr($template, '-', '_');\n if (isset($cache[$hook])) {\n $implementations[$hook] = array(\n 'template' => $template,\n 'path' => dirname($file->uri),\n );\n }\n }\n\n // Find templates that implement possible \"suggestion\" variants of registered\n // theme hooks and add those as new registered theme hooks. See\n // drupal_find_theme_functions() for more information about suggestions and\n // the use of 'pattern' and 'base hook'.\n $patterns = array_keys($files);\n foreach ($cache as $hook => $info) {\n $pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');\n if (!isset($info['base hook']) && !empty($pattern)) {\n // Transform _ in pattern to - to match file naming scheme\n // for the purposes of searching.\n $pattern = strtr($pattern, '_', '-');\n\n $matches = preg_grep('/^' . $pattern . '/', $patterns);\n if ($matches) {\n foreach ($matches as $match) {\n $file = substr($match, 0, strpos($match, '.'));\n // Put the underscores back in for the hook name and register this\n // pattern.\n $arg_name = isset($info['variables']) ? 'variables' : 'render element';\n $implementations[strtr($file, '-', '_')] = array(\n 'template' => $file,\n 'path' => dirname($files[$match]->uri),\n $arg_name => $info[$arg_name],\n 'base hook' => $hook,\n );\n }\n }\n }\n }\n return $implementations;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ce222d3ea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_export_screen/7.x", "instruction": "Implement `locale_translate_export_screen()` in PHP for Drupal 7. Required behavior: User interface for the translation export screen.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_translate_export_screen() {\n // Get all languages, except English\n drupal_static_reset('language_list');\n $names = locale_language_list('name');\n unset($names['en']);\n $output = '';\n // Offer translation export if any language is set up.\n if (count($names)) {\n $elements = drupal_get_form('locale_translate_export_po_form', $names);\n $output = drupal_render($elements);\n }\n $elements = drupal_get_form('locale_translate_export_pot_form');\n $output .= drupal_render($elements);\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ce98b9041", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_theme/7.x", "instruction": "I need the code for `options_theme()` in Drupal 7 (modules/field/modules/options/options.module). It must do this: Implements hook_theme().", "context": "File: modules/field/modules/options/options.module", "response": "function options_theme() {\n return array(\n 'options_none' => array(\n 'variables' => array('instance' => NULL, 'option' => NULL),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d0ac726c2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_vertical_tabs/7.x", "instruction": "In Drupal 7, write the function `theme_vertical_tabs($variables)` (file includes/form.inc) so that it does the following: Returns HTML for an element's children fieldsets as vertical tabs.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties and children of the fieldset. Properties used: #children.\n\nFile: includes/form.inc", "response": "function theme_vertical_tabs($variables) {\n $element = $variables['element'];\n // Add required JavaScript and Stylesheet.\n drupal_add_library('system', 'drupal.vertical-tabs');\n\n $output = '

            ' . t('Vertical Tabs') . '

            ';\n $output .= '
            ' . $element['#children'] . '
            ';\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d0c6af0d3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_uri_normalize_dot_segments/7.x", "instruction": "Implement `file_uri_normalize_dot_segments($uri)` in PHP for Drupal 7. Required behavior: Normalize dot segments in a URI.", "context": "Parameters:\n- $uri: A stream, referenced as \"scheme://target\".\n\nReturns (string): The URI with dot segments removed and slashes as directory separator.\n\nFile: includes/file.inc", "response": "function file_uri_normalize_dot_segments($uri) {\n $scheme = file_uri_scheme($uri);\n\n if (file_stream_wrapper_valid_scheme($scheme)) {\n $target = file_uri_target($uri);\n\n if ($target !== FALSE) {\n if (!in_array($scheme, variable_get('file_sa_core_2023_005_schemes', array()))) {\n $class = file_stream_wrapper_get_class($scheme);\n $is_local = is_subclass_of($class, 'DrupalLocalStreamWrapper');\n if ($is_local) {\n $target = str_replace(DIRECTORY_SEPARATOR, '/', $target);\n }\n\n $parts = explode('/', $target);\n $normalized_parts = array();\n while ($parts) {\n $part = array_shift($parts);\n if ($part === '' || $part === '.') {\n continue;\n }\n elseif ($part === '..' && $is_local && $normalized_parts === array()) {\n $normalized_parts[] = $part;\n break;\n }\n elseif ($part === '..') {\n array_pop($normalized_parts);\n }\n else {\n $normalized_parts[] = $part;\n }\n }\n\n $target = implode('/', array_merge($normalized_parts, $parts));\n }\n\n $uri = $scheme . '://' . $target;\n }\n }\n\n return $uri;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d0e48a8c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_7002/7.x", "instruction": "In Drupal 7, write the function `forum_update_7002()` (file modules/forum/forum.install) so that it does the following: Add new index to forum_index table.", "context": "File: modules/forum/forum.install", "response": "function forum_update_7002() {\n db_drop_index('forum_index', 'forum_topics');\n db_add_index('forum_index', 'forum_topics', array('nid', 'tid', 'sticky', 'last_comment_timestamp'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d2167715d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/dblog_watchdog/7.x", "instruction": "Implement `dblog_watchdog(array $log_entry)` in PHP for Drupal 7. Required behavior: Implements hook_watchdog().", "context": "Note: Some values may be truncated to meet database column size restrictions.\n\nFile: modules/dblog/dblog.module", "response": "function dblog_watchdog(array $log_entry) {\n if (!function_exists('drupal_substr')) {\n require_once DRUPAL_ROOT . '/includes/unicode.inc';\n }\n try {\n Database::getConnection('default', 'default')->insert('watchdog')\n ->fields(array(\n 'uid' => $log_entry['uid'],\n 'type' => drupal_substr($log_entry['type'], 0, 64),\n 'message' => $log_entry['message'],\n 'variables' => serialize($log_entry['variables']),\n 'severity' => $log_entry['severity'],\n 'link' => drupal_substr($log_entry['link'], 0, 255),\n 'location' => $log_entry['request_uri'],\n 'referer' => $log_entry['referer'],\n 'hostname' => drupal_substr($log_entry['ip'], 0, 128),\n 'timestamp' => $log_entry['timestamp'],\n ))\n ->execute();\n }\n catch (Exception $e) {\n // Exception is ignored so that watchdog does not break pages during the\n // installation process or is not able to create the watchdog table during\n // installation.\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d274e28a9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_admin_paths/7.x", "instruction": "In Drupal 7, write the function `node_admin_paths()` (file modules/node/node.module) so that it does the following: Implements hook_admin_paths().", "context": "File: modules/node/node.module", "response": "function node_admin_paths() {\n if (variable_get('node_admin_theme')) {\n $paths = array(\n 'node/*/edit' => TRUE,\n 'node/*/delete' => TRUE,\n 'node/*/revisions' => TRUE,\n 'node/*/revisions/*/revert' => TRUE,\n 'node/*/revisions/*/delete' => TRUE,\n 'node/add' => TRUE,\n 'node/add/*' => TRUE,\n );\n return $paths;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d324e6b6e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_storage_info/7.x", "instruction": "Implement `field_sql_storage_field_storage_info()` in PHP for Drupal 7. Required behavior: Implements hook_field_storage_info().", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function field_sql_storage_field_storage_info() {\n return array(\n 'field_sql_storage' => array(\n 'label' => t('Default SQL storage'),\n 'description' => t('Stores fields in the local SQL database, using per-field tables.'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d4bad5dec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.api.php/function/hook_taxonomy_term_load/7.x", "instruction": "Give me the example code for `hook_taxonomy_term_load($terms)` in Drupal 7. Hook description: Act on taxonomy terms when loaded.", "context": "Modules implementing this hook can act on the term objects returned by taxonomy_term_load_multiple().\n\nFor performance reasons, information to be added to term objects should be loaded in a single query for all terms where possible.\n\nSince terms are stored and retrieved from cache during a page request, avoid altering properties provided by the {taxonomy_term_data} table, since this may affect the way results are loaded from cache in subsequent calls.\n\nParameters:\n- $terms: An array of term objects, indexed by tid.\n\nFile: modules/taxonomy/taxonomy.api.php", "response": "function hook_taxonomy_term_load($terms) {\n $result = db_select('mytable', 'm')\n ->fields('m', array('tid', 'foo'))\n ->condition('m.tid', array_keys($terms), 'IN')\n ->execute();\n foreach ($result as $record) {\n $terms[$record->tid]->foo = $record->foo;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d4e6284e4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_site_information_settings/7.x", "instruction": "I need the code for `system_site_information_settings()` in Drupal 7 (modules/system/system.admin.inc). It must do this: Form builder; The general site information form.", "context": "File: modules/system/system.admin.inc", "response": "function system_site_information_settings() {\n $form['site_information'] = array(\n '#type' => 'fieldset',\n '#title' => t('Site details'),\n );\n $form['site_information']['site_name'] = array(\n '#type' => 'textfield',\n '#title' => t('Site name'),\n '#default_value' => variable_get('site_name', 'Drupal'),\n '#required' => TRUE\n );\n $form['site_information']['site_slogan'] = array(\n '#type' => 'textfield',\n '#title' => t('Slogan'),\n '#default_value' => variable_get('site_slogan', ''),\n '#description' => t(\"How this is used depends on your site's theme.\"),\n );\n $form['site_information']['site_mail'] = array(\n '#type' => 'textfield',\n '#title' => t('E-mail address'),\n '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),\n '#description' => t(\"The From address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)\"),\n '#required' => TRUE,\n );\n $form['front_page'] = array(\n '#type' => 'fieldset',\n '#title' => t('Front page'),\n );\n $form['front_page']['default_nodes_main'] = array(\n '#type' => 'select', '#title' => t('Number of posts on front page'),\n '#default_value' => variable_get('default_nodes_main', 10),\n '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),\n '#description' => t('The maximum number of posts displayed on overview pages such as the front page.')\n );\n $form['front_page']['site_frontpage'] = array(\n '#type' => 'textfield',\n '#title' => t('Default front page'),\n '#default_value' => (variable_get('site_frontpage')!='node'?drupal_get_path_alias(variable_get('site_frontpage', 'node')):''),\n '#size' => 40,\n '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default content feed.'),\n '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),\n );\n $form['error_page'] = array(\n '#type' => 'fieldset',\n '#title' => t('Error pages'),\n );\n $form['error_page']['site_403'] = array(\n '#type' => 'textfield',\n '#title' => t('Default 403 (access denied) page'),\n '#default_value' => variable_get('site_403', ''),\n '#size' => 40,\n '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic \"access denied\" page.'),\n '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')\n );\n $form['error_page']['site_404'] = array(\n '#type' => 'textfield',\n '#title' => t('Default 404 (not found) page'),\n '#default_value' => variable_get('site_404', ''),\n '#size' => 40,\n '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic \"page not found\" page.'),\n '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')\n );\n\n $form['#validate'][] = 'system_site_information_settings_validate';\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d551730f9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.pages.inc/function/book_export_html/7.x", "instruction": "In Drupal 7, write the function `book_export_html($nid)` (file modules/book/book.pages.inc) so that it does the following: Generates HTML for export when invoked by book_export().", "context": "The given node is embedded to its absolute depth in a top level section. For example, a child node with depth 2 in the hierarchy is contained in (otherwise empty)
            elements corresponding to depth 0 and depth 1. This is intended to support WYSIWYG output - e.g., level 3 sections always look like level 3 sections, no matter their depth relative to the node selected to be exported as printer-friendly HTML.\n\nParameters:\n- $nid: An integer representing the node id (nid) of the node to export.\n\nReturns: A string containing HTML representing the node and its children in the book hierarchy.\n\nFile: modules/book/book.pages.inc", "response": "function book_export_html($nid) {\n if (user_access('access printer-friendly version')) {\n $node = node_load($nid);\n if (isset($node->book)) {\n $tree = book_menu_subtree_data($node->book);\n $contents = book_export_traverse($tree, 'book_node_export');\n return theme('book_export_html', array('title' => $node->title, 'contents' => $contents, 'depth' => $node->book['depth']));\n }\n else {\n drupal_not_found();\n }\n }\n else {\n drupal_access_denied();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d7039bea4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/_contact_personal_tab_access/7.x", "instruction": "Implement `_contact_personal_tab_access($account)` in PHP for Drupal 7. Required behavior: Menu access callback for a user's personal contact form.", "context": "Parameters:\n- $account: The user object of the user whose contact form is being requested.\n\nFile: modules/contact/contact.module", "response": "function _contact_personal_tab_access($account) {\n global $user;\n\n // Anonymous users cannot have contact forms.\n if (!$account->uid) {\n return FALSE;\n }\n\n // User administrators should always have access to personal contact forms.\n if (user_access('administer users')) {\n return TRUE;\n }\n\n // Users may not contact themselves.\n if ($user->uid == $account->uid) {\n return FALSE;\n }\n\n // If the requested user has disabled their contact form, or this preference\n // has not yet been saved, do not allow users to contact them.\n if (empty($account->data['contact'])) {\n return FALSE;\n }\n\n // If requested user has been blocked, do not allow users to contact them.\n if (empty($account->status)) {\n return FALSE;\n }\n\n return user_access('access user contact forms');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d779fd188", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_help/7.x", "instruction": "Implement `field_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/field/field.module", "response": "function field_help($path, $arg) {\n switch ($path) {\n case 'admin/help#field':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Field module allows custom data fields to be defined for entity types (entities include content items, comments, user accounts, and taxonomy terms). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the Field UI module user interface. Module developers can use the Field API to make new entity types \"fieldable\" and thus allow fields to be attached to them. For more information, see the online handbook entry for Field module.', array('@field-ui-help' => url('admin/help/field_ui'), '@field' => 'http://drupal.org/documentation/modules/field')) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Enabling field types') . '
            ';\n $output .= '
            ' . t('The Field module provides the infrastructure for fields and field attachment; the field types and input widgets themselves are provided by additional modules. Some of the modules are required; the optional modules can be enabled from the Modules administration page. Drupal core includes the following field type modules: Number (required), Text (required), List (required), Taxonomy (optional), Image (optional), and File (optional); the required Options module provides input widgets for other field modules. Additional fields and widgets may be provided by contributed modules, which you can find in the contributed module section of Drupal.org. Currently enabled field and input widget modules:', array('@modules' => url('admin/modules'), '@contrib' => 'http://drupal.org/project/modules', '@options' => url('admin/help/options')));\n\n // Make a list of all widget and field modules currently enabled, in\n // order by displayed module name (module names are not translated).\n $items = array();\n $info = system_get_info('module');\n $modules = array_merge(module_implements('field_info'), module_implements('field_widget_info'));\n $modules = array_unique($modules);\n sort($modules);\n foreach ($modules as $module) {\n $display = $info[$module]['name'];\n if (module_hook($module, 'help')) {\n $items['items'][] = l($display, 'admin/help/' . $module);\n }\n else {\n $items['items'][] = $display;\n }\n }\n $output .= theme('item_list', $items) . '
            ';\n $output .= '
            ' . t('Managing field data storage') . '
            ';\n $output .= '
            ' . t('Developers of field modules can either use the default Field SQL storage module to store data for their fields, or a contributed or custom module developed using the field storage API.', array('@storage-api' => 'http://api.drupal.org/api/group/field_storage/7', '@sql-store' => url('admin/help/field_sql_storage'))) . '
            ';\n $output .= '
            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d8df769ea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/theme_filter_admin_format_filter_order/7.x", "instruction": "I need the code for `theme_filter_admin_format_filter_order($variables)` in Drupal 7 (modules/filter/filter.admin.inc). It must do this: Returns HTML for a text format's filter order form.", "context": "Parameters:\n- $variables: An associative array containing: - element: A render element representing the form.\n\nFile: modules/filter/filter.admin.inc", "response": "function theme_filter_admin_format_filter_order($variables) {\n $element = $variables['element'];\n\n // Filter order (tabledrag).\n $rows = array();\n foreach (element_children($element, TRUE) as $name) {\n $element[$name]['weight']['#attributes']['class'][] = 'filter-order-weight';\n $rows[] = array(\n 'data' => array(\n drupal_render($element[$name]['filter']),\n drupal_render($element[$name]['weight']),\n ),\n 'class' => array('draggable'),\n );\n }\n $output = drupal_render_children($element);\n $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'filter-order')));\n drupal_add_tabledrag('filter-order', 'order', 'sibling', 'filter-order-weight', NULL, NULL, TRUE);\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2d9bb82c33", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_role_update/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_user_role_update($role)` (modules/user/user.api.php): Respond to updates to a user role.", "context": "Modules implementing this hook can act on the user role object when updated. 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.\n\nParameters:\n- $role: A user role object.\n\nFile: modules/user/user.api.php", "response": "function hook_user_role_update($role) {\n // Save extra fields provided by the module to user roles.\n db_merge('my_module_table')\n ->key(array('rid' => $role->rid))\n ->fields(array(\n 'role_description' => $role->description\n ))\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-2da03bdb2a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load_by_mail/7.x", "instruction": "In Drupal 7, write the function `user_load_by_mail($mail)` (file modules/user/user.module) so that it does the following: Fetch a user object by email address.", "context": "Parameters:\n- $mail: String with the account's e-mail address.\n\nReturns: A fully-loaded $user object upon successful user load or FALSE if user cannot be loaded.\n\nFile: modules/user/user.module", "response": "function user_load_by_mail($mail) {\n $users = user_load_multiple(array(), array('mail' => $mail));\n return reset($users);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2db23f3c25", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_update/7.x", "instruction": "Implement `file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items)` in PHP for Drupal 7. Required behavior: Implements hook_field_update().", "context": "Checks for files that have been removed from the object.\n\nFile: modules/file/file.field.inc", "response": "function file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {\n // Check whether the field is defined on the object.\n if (!isset($entity->{$field['field_name']})) {\n // We cannot check for removed files if the field is not defined.\n return;\n }\n\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n // On new revisions, all files are considered to be a new usage and no\n // deletion of previous file usages are necessary.\n if (!empty($entity->revision)) {\n foreach ($items as $item) {\n $file = (object) $item;\n file_usage_add($file, 'file', $entity_type, $id);\n }\n return;\n }\n\n // Build a display of the current FIDs.\n $current_fids = array();\n foreach ($items as $item) {\n $current_fids[] = $item['fid'];\n }\n\n // Compare the original field values with the ones that are being saved. Use\n // $entity->original to check this when possible, but if it isn't available,\n // create a bare-bones entity and load its previous values instead.\n if (isset($entity->original)) {\n $original = $entity->original;\n }\n else {\n $original = entity_create_stub_entity($entity_type, array($id, $vid, $bundle));\n field_attach_load($entity_type, array($id => $original), FIELD_LOAD_CURRENT, array('field_id' => $field['id']));\n }\n $original_fids = array();\n if (!empty($original->{$field['field_name']}[$langcode])) {\n foreach ($original->{$field['field_name']}[$langcode] as $original_item) {\n $original_fids[] = $original_item['fid'];\n if (isset($original_item['fid']) && !in_array($original_item['fid'], $current_fids)) {\n // Decrement the file usage count by 1 and delete the file if possible.\n file_field_delete_file($original_item, $field, $entity_type, $id);\n }\n }\n }\n\n // Add new usage entries for newly added files.\n foreach ($items as $item) {\n if (!in_array($item['fid'], $original_fids)) {\n $file = (object) $item;\n file_usage_add($file, 'file', $entity_type, $id);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ddb3028fc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_page_last/7.x", "instruction": "In Drupal 7, write the function `aggregator_page_last()` (file modules/aggregator/aggregator.pages.inc) so that it does the following: Page callback: Displays the most recent items gathered from any feed.", "context": "Returns: The rendered list of items for the feed.\n\nFile: modules/aggregator/aggregator.pages.inc", "response": "function aggregator_page_last() {\n drupal_add_feed('aggregator/rss', variable_get('site_name', 'Drupal') . ' ' . t('aggregator'));\n\n $items = aggregator_feed_items_load('sum');\n\n return _aggregator_page_list($items, arg(1));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2defe6517e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_retrieve_form/7.x", "instruction": "In Drupal 7, write the function `drupal_retrieve_form($form_id, &$form_state)` (file includes/form.inc) so that it does the following: Retrieves the structured array that defines a given form.", "context": "Parameters:\n- $form_id: The unique string identifying the desired form. If a function with that name exists, it is called to build the form array. Modules that need to generate the same form (or very similar forms) using different $form_ids can implement hook_forms(), which maps different $form_id values to the proper form constructor function.\n- $form_state: A keyed array containing the current state of the form, including the additional arguments to drupal_get_form() or drupal_form_submit() in the 'args' component of the array.\n\nFile: includes/form.inc", "response": "function drupal_retrieve_form($form_id, &$form_state) {\n $forms = &drupal_static(__FUNCTION__);\n\n // Record the $form_id.\n $form_state['build_info']['form_id'] = $form_id;\n\n // Record the filepath of the include file containing the original form, so\n // the form builder callbacks can be loaded when the form is being rebuilt\n // from cache on a different path (such as 'system/ajax'). See\n // form_get_cache(). Don't do this in maintenance mode as Drupal may not be\n // fully bootstrapped (i.e. during installation) in which case\n // menu_get_item() is not available.\n if (!isset($form_state['build_info']['files']['menu']) && !defined('MAINTENANCE_MODE')) {\n $item = menu_get_item();\n if (!empty($item['include_file'])) {\n // Do not use form_load_include() here, as the file is already loaded.\n // Anyway, form_get_cache() is able to handle filepaths too.\n $form_state['build_info']['files']['menu'] = $item['include_file'];\n }\n }\n\n // We save two copies of the incoming arguments: one for modules to use\n // when mapping form ids to constructor functions, and another to pass to\n // the constructor function itself.\n $args = $form_state['build_info']['args'];\n\n // We first check to see if there's a function named after the $form_id.\n // If there is, we simply pass the arguments on to it to get the form.\n if (!function_exists($form_id)) {\n // In cases where many form_ids need to share a central constructor function,\n // such as the node editing form, modules can implement hook_forms(). It\n // maps one or more form_ids to the correct constructor functions.\n //\n // We cache the results of that hook to save time, but that only works\n // for modules that know all their form_ids in advance. (A module that\n // adds a small 'rate this comment' form to each comment in a list\n // would need a unique form_id for each one, for example.)\n //\n // So, we call the hook if $forms isn't yet populated, OR if it doesn't\n // yet have an entry for the requested form_id.\n if (!isset($forms) || !isset($forms[$form_id])) {\n $forms = module_invoke_all('forms', $form_id, $args);\n }\n $form_definition = $forms[$form_id];\n if (isset($form_definition['callback arguments'])) {\n $args = array_merge($form_definition['callback arguments'], $args);\n }\n if (isset($form_definition['callback'])) {\n $callback = $form_definition['callback'];\n $form_state['build_info']['base_form_id'] = isset($form_definition['base_form_id']) ? $form_definition['base_form_id'] : $callback;\n }\n // In case $form_state['wrapper_callback'] is not defined already, we also\n // allow hook_forms() to define one.\n if (!isset($form_state['wrapper_callback']) && isset($form_definition['wrapper_callback'])) {\n $form_state['wrapper_callback'] = $form_definition['wrapper_callback'];\n }\n }\n\n $form = array();\n // We need to pass $form_state by reference in order for forms to modify it,\n // since call_user_func_array() requires that referenced variables are passed\n // explicitly.\n $args = array_merge(array($form, &$form_state), $args);\n\n // When the passed $form_state (not using drupal_get_form()) defines a\n // 'wrapper_callback', then it requests to invoke a separate (wrapping) form\n // builder function to pre-populate the $form array with form elements, which\n // the actual form builder function ($callback) expects. This allows for\n // pre-populating a form with common elements for certain forms, such as\n // back/next/save buttons in multi-step form wizards. See drupal_build_form().\n if (isset($form_state['wrapper_callback']) && is_callable($form_state['wrapper_callback'])) {\n $form = call_user_func_array($form_state['wrapper_callback'], $args);\n // Put the prepopulated $form into $args.\n $args[0] = $form;\n }\n\n // If $callback was returned by a hook_forms() implementation, call it.\n // Otherwise, call the function named after the form id.\n $form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);\n $form['#form_id'] = $form_id;\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e00f0816c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/_field_sort_items_value_helper/7.x", "instruction": "In Drupal 7, write the function `_field_sort_items_value_helper($a, $b)` (file modules/field/field.module) so that it does the following: Same as above, using ['_weight']['#value']", "context": "File: modules/field/field.module", "response": "function _field_sort_items_value_helper($a, $b) {\n $a_weight = (is_array($a) && isset($a['_weight']['#value']) ? $a['_weight']['#value'] : 0);\n $b_weight = (is_array($b) && isset($b['_weight']['#value']) ? $b['_weight']['#value'] : 0);\n return $a_weight - $b_weight;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e107a1ab5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_delete_date_format_type_form_submit/7.x", "instruction": "In Drupal 7, write the function `system_delete_date_format_type_form_submit($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Delete a configured date type.", "context": "File: modules/system/system.admin.inc", "response": "function system_delete_date_format_type_form_submit($form, &$form_state) {\n if ($form_state['values']['confirm']) {\n $type_info = system_get_date_types($form_state['values']['format_type']);\n system_date_format_type_delete($form_state['values']['format_type']);\n drupal_set_message(t('Removed date type %type.', array('%type' => $type_info['title'])));\n $form_state['redirect'] = 'admin/config/regional/date-time';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e349c1023", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_install_tasks/7.x", "instruction": "Give me the example code for `hook_install_tasks(&$install_state)` in Drupal 7. Hook description: Return an array of tasks to be performed by an installation profile.", "context": "Any tasks you define here will be run, in order, after the installer has finished the site configuration step but before it has moved on to the final import of languages and the end of the installation. This is invoked by install_tasks(). You can have any number of custom tasks to perform during this phase.\n\nEach task you define here corresponds to a callback function which you must separately define and which is called when your task is run. This function will receive the global installation state variable, $install_state, as input, and has the opportunity to access or modify any of its settings. See the install_state_defaults() function in the installer for the list of $install_state settings used by Drupal core.\n\nAt the end of your task function, you can indicate that you want the installer to pause and display a page to the user by returning any themed output that should be displayed on that page (but see below for tasks that use the form API or batch API; the return values of these task functions are handled differently). You should also use drupal_set_title() within the task callback function to set a custom page title. For some tasks, however, you may want to simply do some processing and pass control to the next task without ending the page request; to indicate this, simply do not send back a return value from your task function at all. This can be used, for example, by installation profiles that need to configure certain site settings in the database without obtaining any input from the user.\n\nThe task function is treated specially if it defines a form or requires batch processing; in that case, you should return either the form API definition or batch API array, as appropriate. See below for more information on the 'type' key that you must define in the task definition to inform the installer that your task falls into one of those two categories. It is important to use these APIs directly, since the installer may be run non-interactively (for example, via a command line script), all in one page request; in that case, the installer will automatically take care of submitting forms and processing batches correctly for both types of installations. You can inspect the $install_state['interactive'] boolean to see whether or not the current installation is interactive, if you need access to this information.\n\nRemember that a user installing Drupal interactively will be able to reload an installation page multiple times, so you should use variable_set() and variable_get() if you are collecting any data that you need to store and inspect later. It is important to remove any temporary variables using variable_del() before your last task has completed and control is handed back to the installer.\n\nParameters:\n- $install_state (array): An array of information about the current installation state.\n\nReturns (array): A keyed array of tasks the profile will perform during the final stage of the installation. Each key represents the name of a function (usually a function defined by this profile, although that is not strictly required) that is called when that task is run. The values are associative arrays containing the following key-value pairs (all of which are optional): - display_name: The human-readable name of the task. This will be displayed to the user while the installer is running, along with a list of other tasks that are being run. Leave this unset to prevent the task from appearing in the list. - display: This is a boolean which can be used to provide finer-grained control over whether or not the task will display. This is mostly useful for tasks that are intended to display only under certain conditions; for these tasks, you can set 'display_name' to the name that you want to display, but then use this boolean to hide the task only when certain conditions apply. - type: A string representing the type of task. This parameter has three possible values: - normal: (default) This indicates that the task will be treated as a regular callback function, which does its processing and optionally returns HTML output. - batch: This indicates that the task function will return a batch API definition suitable for batch_set(). The installer will then take care of automatically running the task via batch processing. - form: This indicates that the task function will return a standard form API definition (and separately define validation and submit handlers, as appropriate). The installer will then take care of automatically directing the user through the form submission process. - run: A constant representing the manner in which the task will be run. This parameter has three possible values: - INSTALL_TASK_RUN_IF_NOT_COMPLETED: (default) This indicates that the task will run once during the installation of the profile. - INSTALL_TASK_SKIP: This indicates that the task will not run during the current installation page request. It can be used to skip running an installation task when certain conditions are met, even though the task may still show on the list of installation tasks presented to the user. - INSTALL_TASK_RUN_IF_REACHED: This indicates that the task will run on each installation page request that reaches it. This is rarely necessary for an installation profile to use; it is primarily used by the Drupal installer for bootstrap-related tasks. - function: Normally this does not need to be set, but it can be used to force the installer to call a different function when the task is run (rather than the function whose name is given by the array key). This could be used, for example, to allow the same function to be called by two different tasks.\n\nFile: modules/system/system.api.php", "response": "function hook_install_tasks(&$install_state) {\n // Here, we define a variable to allow tasks to indicate that a particular,\n // processor-intensive batch process needs to be triggered later on in the\n // installation.\n $myprofile_needs_batch_processing = variable_get('myprofile_needs_batch_processing', FALSE);\n $tasks = array(\n // This is an example of a task that defines a form which the user who is\n // installing the site will be asked to fill out. To implement this task,\n // your profile would define a function named myprofile_data_import_form()\n // as a normal form API callback function, with associated validation and\n // submit handlers. In the submit handler, in addition to saving whatever\n // other data you have collected from the user, you might also call\n // variable_set('myprofile_needs_batch_processing', TRUE) if the user has\n // entered data which requires that batch processing will need to occur\n // later on.\n 'myprofile_data_import_form' => array(\n 'display_name' => st('Data import options'),\n 'type' => 'form',\n ),\n // Similarly, to implement this task, your profile would define a function\n // named myprofile_settings_form() with associated validation and submit\n // handlers. This form might be used to collect and save additional\n // information from the user that your profile needs. There are no extra\n // steps required for your profile to act as an \"installation wizard\"; you\n // can simply define as many tasks of type 'form' as you wish to execute,\n // and the forms will be presented to the user, one after another.\n 'myprofile_settings_form' => array(\n 'display_name' => st('Additional options'),\n 'type' => 'form',\n ),\n // This is an example of a task that performs batch operations. To\n // implement this task, your profile would define a function named\n // myprofile_batch_processing() which returns a batch API array definition\n // that the installer will use to execute your batch operations. Due to the\n // 'myprofile_needs_batch_processing' variable used here, this task will be\n // hidden and skipped unless your profile set it to TRUE in one of the\n // previous tasks.\n 'myprofile_batch_processing' => array(\n 'display_name' => st('Import additional data'),\n 'display' => $myprofile_needs_batch_processing,\n 'type' => 'batch',\n 'run' => $myprofile_needs_batch_processing ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,\n ),\n // This is an example of a task that will not be displayed in the list that\n // the user sees. To implement this task, your profile would define a\n // function named myprofile_final_site_setup(), in which additional,\n // automated site setup operations would be performed. Since this is the\n // last task defined by your profile, you should also use this function to\n // call variable_del('myprofile_needs_batch_processing') and clean up the\n // variable that was used above. If you want the user to pass to the final\n // Drupal installation tasks uninterrupted, return no output from this\n // function. Otherwise, return themed output that the user will see (for\n // example, a confirmation page explaining that your profile's tasks are\n // complete, with a link to reload the current page and therefore pass on\n // to the final Drupal installation tasks when the user is ready to do so).\n 'myprofile_final_site_setup' => array(\n ),\n );\n return $tasks;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e3c662c27", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_inactive_message/7.x", "instruction": "Implement `field_ui_inactive_message($entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Displays a message listing the inactive fields of a given bundle.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_inactive_message($entity_type, $bundle) {\n $inactive_instances = field_ui_inactive_instances($entity_type, $bundle);\n if (!empty($inactive_instances)) {\n $field_types = field_info_field_types();\n $widget_types = field_info_widget_types();\n\n foreach ($inactive_instances as $field_name => $instance) {\n $list[] = t('%field (@field_name) field requires the %widget_type widget provided by %widget_module module', array(\n '%field' => $instance['label'],\n '@field_name' => $instance['field_name'],\n '%widget_type' => isset($widget_types[$instance['widget']['type']]) ? $widget_types[$instance['widget']['type']]['label'] : $instance['widget']['type'],\n '%widget_module' => $instance['widget']['module'],\n ));\n }\n drupal_set_message(t('Inactive fields are not shown unless their providing modules are enabled. The following fields are not enabled: !list', array('!list' => theme('item_list', array('items' => $list)))), 'error');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e62f27d42", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_select_options/7.x", "instruction": "In Drupal 7, write the function `form_select_options($element, $choices = NULL)` (file includes/form.inc) so that it does the following: Converts an array of options into HTML, for use in select list form elements.", "context": "This function calls itself recursively to obtain the values for each optgroup within the list of options and when the function encounters an object with an 'options' property inside $element['#options'].\n\nParameters:\n- $element (array): An associative array containing the following key-value pairs: - #multiple: Optional Boolean indicating if the user may select more than one item. - #options: An associative array of options to render as HTML. Each array value can be a string, an array, or an object with an 'option' property: - A string or integer key whose value is a translated string is interpreted as a single HTML option element. Do not use placeholders that sanitize data: doing so will lead to double-escaping. Note that the key will be visible in the HTML and could be modified by malicious users, so don't put sensitive information in it. - A translated string key whose value is an array indicates a group of options. The translated string is used as the label attribute for the optgroup. Do not use placeholders to sanitize data: doing so will lead to double-escaping. The array should contain the options you wish to group and should follow the syntax of $element['#options']. - If the function encounters a string or integer key whose value is an object with an 'option' property, the key is ignored, the contents of the option property are interpreted as $element['#options'], and the resulting HTML is added to the output. - #value: Optional integer, string, or array representing which option(s) to pre-select when the list is first displayed. The integer or string must match the key of an option in the '#options' list. If '#multiple' is TRUE, this can be an array of integers or strings.\n- $choices (array|null): (optional) Either an associative array of options in the same format as $element['#options'] above, or NULL. This parameter is only used internally and is not intended to be passed in to the initial function call.\n\nReturns (string): An HTML string of options and optgroups for use in a select form element.\n\nFile: includes/form.inc", "response": "function form_select_options($element, $choices = NULL) {\n if (!isset($choices)) {\n $choices = $element['#options'];\n }\n // array_key_exists() accommodates the rare event where $element['#value'] is NULL.\n // isset() fails in this situation.\n $value_valid = isset($element['#value']) || array_key_exists('#value', $element);\n $value_is_array = $value_valid && is_array($element['#value']);\n $options = '';\n foreach ($choices as $key => $choice) {\n if (is_array($choice)) {\n $options .= '';\n $options .= form_select_options($element, $choice);\n $options .= '';\n }\n elseif (is_object($choice)) {\n $options .= form_select_options($element, $choice->option);\n }\n else {\n $key = (string) $key;\n if ($value_valid && (!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) {\n $selected = ' selected=\"selected\"';\n }\n else {\n $selected = '';\n }\n $options .= '';\n }\n }\n return $options;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e770ea267", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_uninstall/7.x", "instruction": "I need the code for `locale_uninstall()` in Drupal 7 (modules/locale/locale.install). It must do this: Implements hook_uninstall().", "context": "File: modules/locale/locale.install", "response": "function locale_uninstall() {\n // Delete all JavaScript translation files.\n $locale_js_directory = 'public://' . variable_get('locale_js_directory', 'languages');\n\n if (is_dir($locale_js_directory)) {\n $files = db_query('SELECT language, javascript FROM {languages}');\n foreach ($files as $file) {\n if (!empty($file->javascript)) {\n file_unmanaged_delete($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js');\n }\n }\n // Delete the JavaScript translations directory if empty.\n if (!file_scan_directory($locale_js_directory, '/.*/')) {\n drupal_rmdir($locale_js_directory);\n }\n }\n\n // Clear variables.\n variable_del('language_default');\n variable_del('language_count');\n variable_del('language_types');\n variable_del('locale_language_negotiation_url_part');\n variable_del('locale_language_negotiation_session_param');\n variable_del('language_content_type_default');\n variable_del('language_content_type_negotiation');\n variable_del('locale_cache_strings');\n variable_del('locale_js_directory');\n variable_del('javascript_parsed');\n variable_del('locale_field_language_fallback');\n variable_del('locale_cache_length');\n\n foreach (language_types() as $type) {\n variable_del(\"language_negotiation_$type\");\n variable_del(\"locale_language_providers_weight_$type\");\n }\n\n foreach (node_type_get_types() as $type => $content_type) {\n $setting = variable_del(\"language_content_type_$type\");\n }\n\n // Switch back to English: with a $language->language value different from 'en'\n // successive calls of t() might result in calling locale(), which in turn might\n // try to query the unexisting {locales_source} and {locales_target} tables.\n drupal_language_initialize();\n\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e7c80d54c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_effect_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_image_effect_info_alter(&$effects)` (modules/image/image.api.php): Alter the information provided in hook_image_effect_info().", "context": "Parameters:\n- $effects: The array of image effects, keyed on the machine-readable effect name.\n\nFile: modules/image/image.api.php", "response": "function hook_image_effect_info_alter(&$effects) {\n // Override the Image module's crop effect with more options.\n $effects['image_crop']['effect callback'] = 'mymodule_crop_effect';\n $effects['image_crop']['dimensions callback'] = 'mymodule_crop_dimensions';\n $effects['image_crop']['form callback'] = 'mymodule_crop_form';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e7ea00e92", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_get_path_alias/7.x", "instruction": "Implement `drupal_get_path_alias($path = NULL, $path_language = NULL)` in PHP for Drupal 7. Required behavior: Given an internal Drupal path, return the alias set by the administrator.", "context": "If no path is provided, the function will return the alias of the current page.\n\nParameters:\n- $path: An internal Drupal path.\n- $path_language: An optional language code to look up the path in.\n\nReturns: An aliased path if one was found, or the original path if no alias was found.\n\nFile: includes/path.inc", "response": "function drupal_get_path_alias($path = NULL, $path_language = NULL) {\n // If no path is specified, use the current page's path.\n if ($path == NULL) {\n $path = $_GET['q'];\n }\n $result = $path;\n if ($alias = drupal_lookup_path('alias', $path, $path_language)) {\n $result = $alias;\n }\n return $result;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e7ed801eb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/drupal_session_initialize/7.x", "instruction": "In Drupal 7, write the function `drupal_session_initialize()` (file includes/session.inc) so that it does the following: Initializes the session handler, starting a session if needed.", "context": "File: includes/session.inc", "response": "function drupal_session_initialize() {\n global $user, $is_https;\n\n session_set_save_handler('_drupal_session_open', '_drupal_session_close', '_drupal_session_read', '_drupal_session_write', '_drupal_session_destroy', '_drupal_session_garbage_collection');\n\n // We use !empty() in the following check to ensure that blank session IDs\n // are not valid.\n if (!empty($_COOKIE[session_name()]) || ($is_https && variable_get('https', FALSE) && !empty($_COOKIE[substr(session_name(), 1)]))) {\n // If a session cookie exists, initialize the session. Otherwise the\n // session is only started on demand in drupal_session_commit(), making\n // anonymous users not use a session cookie unless something is stored in\n // $_SESSION. This allows HTTP proxies to cache anonymous pageviews.\n drupal_session_start();\n if (!empty($user->uid) || !empty($_SESSION)) {\n drupal_page_is_cacheable(FALSE);\n }\n }\n else {\n // Set a session identifier for this request. This is necessary because\n // we lazily start sessions at the end of this request, and some\n // processes (like drupal_get_token()) needs to know the future\n // session ID in advance.\n $GLOBALS['lazy_session'] = TRUE;\n $user = drupal_anonymous_user();\n // Less random sessions (which are much faster to generate) are used for\n // anonymous users than are generated in drupal_session_regenerate() when\n // a user becomes authenticated.\n session_id(drupal_random_key());\n if ($is_https && variable_get('https', FALSE)) {\n $insecure_session_name = substr(session_name(), 1);\n $session_id = drupal_random_key();\n $_COOKIE[$insecure_session_name] = $session_id;\n }\n }\n date_default_timezone_set(drupal_get_user_timezone());\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e8072d289", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21image.inc/function/image_get_toolkit/7.x", "instruction": "I need the code for `image_get_toolkit()` in Drupal 7 (includes/image.inc). It must do this: Gets the name of the currently used toolkit.", "context": "Returns (String): containing the name of the selected toolkit, or FALSE on error.\n\nFile: includes/image.inc", "response": "function image_get_toolkit() {\n static $toolkit;\n\n if (!isset($toolkit)) {\n $toolkits = image_get_available_toolkits();\n $toolkit = variable_get('image_toolkit', 'gd');\n if (!isset($toolkits[$toolkit]) || !function_exists('image_' . $toolkit . '_load')) {\n // The selected toolkit isn't available so return the first one found. If\n // none are available this will return FALSE.\n reset($toolkits);\n $toolkit = key($toolkits);\n }\n }\n\n return $toolkit;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e89c64284", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/theme_comment_post_forbidden/7.x", "instruction": "Implement `theme_comment_post_forbidden($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a \"you can't post comments\" notice.", "context": "Parameters:\n- $variables: An associative array containing: - node: The comment node.\n\nFile: modules/comment/comment.module", "response": "function theme_comment_post_forbidden($variables) {\n $node = $variables['node'];\n global $user;\n\n // Since this is expensive to compute, we cache it so that a page with many\n // comments only has to query the database once for all the links.\n $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);\n\n if (!$user->uid) {\n if (!isset($authenticated_post_comments)) {\n // We only output a link if we are certain that users will get permission\n // to post comments by logging in.\n $comment_roles = user_roles(TRUE, 'post comments');\n $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);\n }\n\n if ($authenticated_post_comments) {\n // We cannot use drupal_get_destination() because these links\n // sometimes appear on /node and taxonomy listing pages.\n if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {\n $destination = array('destination' => \"comment/reply/$node->nid#comment-form\");\n }\n else {\n $destination = array('destination' => \"node/$node->nid#comment-form\");\n }\n\n if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {\n // Users can register themselves.\n return t('Log in or register to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));\n }\n else {\n // Only admins can add new users, no public registration.\n return t('Log in to post comments', array('@login' => url('user/login', array('query' => $destination))));\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2e931de923", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail_format_display_name/7.x", "instruction": "Implement `drupal_mail_format_display_name($string)` in PHP for Drupal 7. Required behavior: Return a RFC-2822 compliant \"display-name\" component.", "context": "The \"display-name\" component is used in mail header \"Originator\" fields (From, Sender, Reply-to) to give a human-friendly description of the address, i.e. From: My Display Name . RFC-822 and RFC-2822 define its syntax and rules. This method gets as input a string to be used as \"display-name\" and formats it to be RFC compliant.\n\nParameters:\n- $string (string): A string to be used as \"display-name\".\n\nReturns (string): A RFC compliant version of the string, ready to be used as \"display-name\" in mail originator header fields.\n\nFile: includes/mail.inc", "response": "function drupal_mail_format_display_name($string) {\n // Make sure we don't process html-encoded characters. They may create\n // unneeded trouble if left encoded, besides they will be correctly\n // processed if decoded.\n $string = decode_entities($string);\n\n // If string contains non-ASCII characters it must be (short) encoded\n // according to RFC-2047. The output of a \"B\" (Base64) encoded-word is\n // always safe to be used as display-name.\n $safe_display_name = mime_header_encode($string, TRUE);\n\n // Encoded-words are always safe to be used as display-name because don't\n // contain any RFC 2822 \"specials\" characters. However\n // mimeHeaderEncode() encodes a string only if it contains any\n // non-ASCII characters, and leaves its value untouched (un-encoded) if\n // ASCII only. For this reason in order to produce a valid display-name we\n // still need to make sure there are no \"specials\" characters left.\n if (preg_match('/[' . preg_quote(MAIL_RFC_2822_SPECIALS) . ']/', $safe_display_name)) {\n\n // If string is already quoted, it may or may not be escaped properly, so\n // don't trust it and reset.\n if (preg_match('/^\"(.+)\"$/', $safe_display_name, $matches)) {\n $safe_display_name = str_replace(array('\\\\\\\\', '\\\\\"'), array('\\\\', '\"'), $matches[1]);\n }\n\n // Transform the string in a RFC-2822 \"quoted-string\" by wrapping it in\n // double-quotes. Also make sure '\"' and '\\' occurrences are escaped.\n $safe_display_name = '\"' . str_replace(array('\\\\', '\"'), array('\\\\\\\\', '\\\\\"'), $safe_display_name) . '\"';\n }\n\n return $safe_display_name;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ea86c4c8a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_css_alter/7.x", "instruction": "Implement `seven_css_alter(&$css)` in PHP for Drupal 7. Required behavior: Implements hook_css_alter().", "context": "File: themes/seven/template.php", "response": "function seven_css_alter(&$css) {\n // Use Seven's vertical tabs style instead of the default one.\n if (isset($css['misc/vertical-tabs.css'])) {\n $css['misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'seven') . '/vertical-tabs.css';\n $css['misc/vertical-tabs.css']['type'] = 'file';\n }\n if (isset($css['misc/vertical-tabs-rtl.css'])) {\n $css['misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'seven') . '/vertical-tabs-rtl.css';\n $css['misc/vertical-tabs-rtl.css']['type'] = 'file';\n }\n // Use Seven's jQuery UI theme style instead of the default one.\n if (isset($css['misc/ui/jquery.ui.theme.css'])) {\n $css['misc/ui/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'seven') . '/jquery.ui.theme.css';\n $css['misc/ui/jquery.ui.theme.css']['type'] = 'file';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2eafaab565", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_block_latest_poll_view/7.x", "instruction": "I need the code for `poll_block_latest_poll_view($node)` in Drupal 7 (modules/poll/poll.module). It must do this: Return content for 'latest poll' block.", "context": "Parameters:\n- $node: The node object to load.\n\nFile: modules/poll/poll.module", "response": "function poll_block_latest_poll_view($node) {\n // This is necessary for shared objects because PHP doesn't copy objects, but\n // passes them by reference. So when the objects are cached it can result in\n // the wrong output being displayed on subsequent calls. The cloning and\n // unsetting of $node->content prevents the block output from being the same\n // as the node output.\n $node = clone $node;\n unset($node->content);\n\n // No 'read more' link.\n $node->readmore = FALSE;\n $node->teaser = '';\n\n $links = array();\n $links[] = array('title' => t('Older polls'), 'href' => 'poll', 'attributes' => array('title' => t('View the list of polls on this site.')));\n if ($node->allowvotes) {\n $links[] = array('title' => t('Results'), 'href' => 'node/' . $node->nid . '/results', 'attributes' => array('title' => t('View the current poll results.')));\n }\n\n $node->links = $links;\n\n if (!empty($node->allowvotes)) {\n $node->content['poll_view_voting'] = drupal_get_form('poll_view_voting', $node, TRUE);\n $node->content['links'] = array(\n '#theme' => 'links',\n '#links' => $node->links,\n '#weight' => 5,\n );\n }\n else {\n $node->content['poll_view_results'] = array('#markup' => poll_view_results($node, TRUE, TRUE));\n }\n\n return $node;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2eb9f913fb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21pager.inc/function/pager_find_page/7.x", "instruction": "I need the code for `pager_find_page($element = 0)` in Drupal 7 (includes/pager.inc). It must do this: Returns the current page being requested for display within a pager.", "context": "Parameters:\n- $element: An optional integer to distinguish between multiple pagers on one page.\n\nReturns: The number of the current requested page, within the pager represented by $element. This is determined from the URL query parameter $_GET['page'], or 0 by default. Note that this number may differ from the actual page being displayed. For example, if a search for \"example text\" brings up three pages of results, but a users visits search/node/example+text?page=10, this function will return 10, even though the default pager implementation adjusts for this and still displays the third page of search results at that URL.\n\nFile: includes/pager.inc", "response": "function pager_find_page($element = 0) {\n $page = isset($_GET['page']) ? $_GET['page'] : '';\n $page_array = explode(',', $page);\n if (!isset($page_array[$element])) {\n $page_array[$element] = 0;\n }\n return (int) $page_array[$element];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ebc4934d8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21authorize.inc/function/authorize_filetransfer_form_validate/7.x", "instruction": "I need the code for `authorize_filetransfer_form_validate($form, &$form_state)` in Drupal 7 (includes/authorize.inc). It must do this: Form validation handler for authorize_filetransfer_form().", "context": "File: includes/authorize.inc", "response": "function authorize_filetransfer_form_validate($form, &$form_state) {\n // Only validate the form if we have collected all of the user input and are\n // ready to proceed with updating or installing.\n if ($form_state['triggering_element']['#name'] != 'process_updates') {\n return;\n }\n\n if (isset($form_state['values']['connection_settings'])) {\n $backend = $form_state['values']['connection_settings']['authorize_filetransfer_default'];\n $filetransfer = authorize_get_filetransfer($backend, $form_state['values']['connection_settings'][$backend]);\n try {\n if (!$filetransfer) {\n throw new Exception(t('Error, this type of connection protocol (%backend) does not exist.', array('%backend' => $backend)));\n }\n $filetransfer->connect();\n }\n catch (Exception $e) {\n // The format of this error message is similar to that used on the\n // database connection form in the installer.\n form_set_error('connection_settings', t('Failed to connect to the server. The server reports the following message: !message For more help installing or updating code on your server, see the handbook.', array(\n '!message' => '

            ' . $e->getMessage() . '

            ',\n '@handbook_url' => 'http://drupal.org/documentation/install/modules-themes',\n )));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ece66a96a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_existing_field_options/7.x", "instruction": "Implement `field_ui_existing_field_options($entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Returns an array of existing fields to be added to a bundle.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_existing_field_options($entity_type, $bundle) {\n $info = array();\n $field_types = field_info_field_types();\n\n foreach (field_info_instances() as $existing_entity_type => $bundles) {\n foreach ($bundles as $existing_bundle => $instances) {\n // No need to look in the current bundle.\n if (!($existing_bundle == $bundle && $existing_entity_type == $entity_type)) {\n foreach ($instances as $instance) {\n $field = field_info_field($instance['field_name']);\n // Don't show\n // - locked fields,\n // - fields already in the current bundle,\n // - fields that cannot be added to the entity type,\n // - fields that should not be added via user interface.\n\n if (empty($field['locked'])\n && !field_info_instance($entity_type, $field['field_name'], $bundle)\n && (empty($field['entity_types']) || in_array($entity_type, $field['entity_types']))\n && empty($field_types[$field['type']]['no_ui'])) {\n $info[$instance['field_name']] = array(\n 'type' => $field['type'],\n 'type_label' => $field_types[$field['type']]['label'],\n 'field' => $field['field_name'],\n 'label' => $instance['label'],\n 'widget_type' => $instance['widget']['type'],\n );\n }\n }\n }\n }\n }\n return $info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ecfc7f4b9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/format_rss_item/7.x", "instruction": "Implement `format_rss_item($title, $link, $description, $args = array())` in PHP for Drupal 7. Required behavior: Formats a single RSS item.", "context": "Arbitrary elements may be added using the $args associative array.\n\nFile: includes/common.inc", "response": "function format_rss_item($title, $link, $description, $args = array()) {\n $output = \"\\n\";\n $output .= ' ' . check_plain($title) . \"\\n\";\n $output .= ' ' . check_url($link) . \"\\n\";\n $output .= ' ' . check_plain($description) . \"\\n\";\n $output .= format_xml_elements($args);\n $output .= \"\\n\";\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ed7397b5a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_theme_settings_validate/7.x", "instruction": "In Drupal 7, write the function `system_theme_settings_validate($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Validator for the system_theme_settings() form.", "context": "File: modules/system/system.admin.inc", "response": "function system_theme_settings_validate($form, &$form_state) {\n // Handle file uploads.\n $validators = array('file_validate_is_image' => array());\n\n // Check for a new uploaded logo.\n $file = file_save_upload('logo_upload', $validators);\n if (isset($file)) {\n // File upload was attempted.\n if ($file) {\n // Put the temporary file in form_values so we can save it on submit.\n $form_state['values']['logo_upload'] = $file;\n }\n else {\n // File upload failed.\n form_set_error('logo_upload', t('The logo could not be uploaded.'));\n }\n }\n\n $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));\n\n // Check for a new uploaded favicon.\n $file = file_save_upload('favicon_upload', $validators);\n if (isset($file)) {\n // File upload was attempted.\n if ($file) {\n // Put the temporary file in form_values so we can save it on submit.\n $form_state['values']['favicon_upload'] = $file;\n }\n else {\n // File upload failed.\n form_set_error('favicon_upload', t('The favicon could not be uploaded.'));\n }\n }\n\n // If the user provided a path for a logo or favicon file, make sure a file\n // exists at that path.\n if (!empty($form_state['values']['logo_path'])) {\n $path = _system_theme_settings_validate_path($form_state['values']['logo_path']);\n if (!$path) {\n form_set_error('logo_path', t('The custom logo path is invalid.'));\n }\n }\n if (!empty($form_state['values']['favicon_path'])) {\n $path = _system_theme_settings_validate_path($form_state['values']['favicon_path']);\n if (!$path) {\n form_set_error('favicon_path', t('The custom favicon path is invalid.'));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ef2f888d5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.install/function/dblog_update_7003/7.x", "instruction": "Implement `dblog_update_7003()` in PHP for Drupal 7. Required behavior: Account for possible legacy systems where dblog was not installed.", "context": "File: modules/dblog/dblog.install", "response": "function dblog_update_7003() {\n if (!db_table_exists('watchdog')) {\n db_create_table('watchdog', drupal_get_schema_unprocessed('dblog', 'watchdog'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f2bc0eaf6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_teaser/7.x", "instruction": "In Drupal 7, write the function `poll_teaser($node)` (file modules/poll/poll.module) so that it does the following: Creates a simple teaser that lists all the choices.", "context": "This is primarily used for RSS.\n\nFile: modules/poll/poll.module", "response": "function poll_teaser($node) {\n $teaser = NULL;\n if (is_array($node->choice)) {\n foreach ($node->choice as $choice) {\n if ($choice['chtext'] != '') {\n $teaser .= '* ' . check_plain($choice['chtext']) . \"\\n\";\n }\n }\n }\n return $teaser;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f3a3a7830", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/theme_image_widget/7.x", "instruction": "In Drupal 7, write the function `theme_image_widget($variables)` (file modules/image/image.field.inc) so that it does the following: Returns HTML for an image field widget.", "context": "Parameters:\n- $variables: An associative array containing: - element: A render element representing the image field widget.\n\nFile: modules/image/image.field.inc", "response": "function theme_image_widget($variables) {\n $element = $variables['element'];\n $output = '';\n $output .= '
            ';\n\n if (isset($element['preview'])) {\n $output .= '
            ';\n $output .= drupal_render($element['preview']);\n $output .= '
            ';\n }\n\n $output .= '
            ';\n if ($element['fid']['#value'] != 0) {\n $element['filename']['#markup'] .= ' (' . format_size($element['#file']->filesize) . ') ';\n }\n $output .= drupal_render_children($element);\n $output .= '
            ';\n $output .= '
            ';\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f44ab99a9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_override_server_variables/7.x", "instruction": "I need the code for `drupal_override_server_variables($variables = array())` in Drupal 7 (includes/bootstrap.inc). It must do this: Sets appropriate server variables needed for command line scripts to work.", "context": "This function can be called by command line scripts before bootstrapping Drupal, to ensure that the page loads with the desired server parameters. This is because many parts of Drupal assume that they are running in a web browser and therefore use information from the global PHP $_SERVER variable that does not get set when Drupal is run from the command line.\n\nIn many cases, the default way in which this function populates the $_SERVER variable is sufficient, and it can therefore be called without passing in any input. However, command line scripts running on a multisite installation (or on any installation that has settings.php stored somewhere other than the sites/default folder) need to pass in the URL of the site to allow Drupal to detect the correct location of the settings.php file. Passing in the 'url' parameter is also required for functions like request_uri() to return the expected values.\n\nMost other parameters do not need to be passed in, but may be necessary in some cases; for example, if Drupal's ip_address() function needs to return anything but the standard localhost value ('127.0.0.1'), the command line script should pass in the desired value via the 'REMOTE_ADDR' key.\n\nParameters:\n- $variables: (optional) An associative array of variables within $_SERVER that should be replaced. If the special element 'url' is provided in this array, it will be used to populate some of the server defaults; it should be set to the URL of the current page request, excluding any $_GET request but including the script name (e.g., http://www.example.com/mysite/index.php).\n\nFile: includes/bootstrap.inc", "response": "function drupal_override_server_variables($variables = array()) {\n // Allow the provided URL to override any existing values in $_SERVER.\n if (isset($variables['url'])) {\n $url = parse_url($variables['url']);\n if (isset($url['host'])) {\n $_SERVER['HTTP_HOST'] = $url['host'];\n }\n if (isset($url['path'])) {\n $_SERVER['SCRIPT_NAME'] = $url['path'];\n }\n unset($variables['url']);\n }\n // Define default values for $_SERVER keys. These will be used if $_SERVER\n // does not already define them and no other values are passed in to this\n // function.\n $defaults = array(\n 'HTTP_HOST' => 'localhost',\n 'SCRIPT_NAME' => NULL,\n 'REMOTE_ADDR' => '127.0.0.1',\n 'REQUEST_METHOD' => 'GET',\n 'SERVER_NAME' => NULL,\n 'SERVER_SOFTWARE' => NULL,\n 'HTTP_USER_AGENT' => NULL,\n );\n // Replace elements of the $_SERVER array, as appropriate.\n $_SERVER = $variables + $_SERVER + $defaults;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f4c2e45d9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.install/function/filter_update_7008/7.x", "instruction": "I need the code for `filter_update_7008()` in Drupal 7 (modules/filter/filter.install). It must do this: Grant usage of all text formats to user roles having the 'administer filters' permission.", "context": "File: modules/filter/filter.install", "response": "function filter_update_7008() {\n // Build the list of permissions to grant.\n $permissions = array();\n foreach (db_query('SELECT format FROM {filter_format}')->fetchCol() as $format_id) {\n if ($format_id != variable_get('filter_fallback_format')) {\n $permissions[] = 'use text format ' . $format_id;\n }\n }\n // Grant text format permissions to all roles that can 'administer filters'.\n // Albeit anonymous users *should not* have the permission, we cannot presume\n // that they do not or must not.\n if ($roles = user_roles(FALSE, 'administer filters')) {\n foreach ($roles as $rid => $name) {\n _update_7000_user_role_grant_permissions($rid, $permissions, 'filter');\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f65949b90", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/_menu_get_menu_weight_delta/7.x", "instruction": "In Drupal 7, write the function `_menu_get_menu_weight_delta($menu_names, $max_delta = NULL)` (file modules/menu/menu.module) so that it does the following: Calculate the delta for the weight element for a given set of menus.", "context": "Parameters:\n- $menu_names (string|array): Menu name or an array of menu names.\n- $max_delta (int): Optional maximum value.\n\nReturns (int): Delta value.\n\nFile: modules/menu/menu.module", "response": "function _menu_get_menu_weight_delta($menu_names, $max_delta = NULL) {\n\n if (is_string($menu_names)) {\n $menu_names = array($menu_names);\n }\n\n $weight_info = db_query(\"SELECT MAX(weight) AS max_weight, MIN(weight) as min_weight FROM {menu_links} WHERE menu_name IN (:menu_names)\", array(':menu_names' => $menu_names))->fetchObject();\n\n $delta = max(abs((int) $weight_info->min_weight), abs((int) $weight_info->max_weight)) + 1;\n\n // Honor max param, if given.\n if (!is_null($max_delta) && $delta > $max_delta) {\n $delta = $max_delta;\n }\n\n // Provide a minimum.\n if ($delta < 50) {\n $delta = 50;\n }\n return $delta;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f6b2ca4ae", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_date/7.x", "instruction": "I need the code for `form_process_date($element)` in Drupal 7 (includes/form.inc). It must do this: Expands a date element into year, month, and day select elements.", "context": "File: includes/form.inc", "response": "function form_process_date($element) {\n // Default to current date\n if (empty($element['#value'])) {\n $element['#value'] = array(\n 'day' => format_date(REQUEST_TIME, 'custom', 'j'),\n 'month' => format_date(REQUEST_TIME, 'custom', 'n'),\n 'year' => format_date(REQUEST_TIME, 'custom', 'Y'),\n );\n }\n\n $element['#tree'] = TRUE;\n\n // Determine the order of day, month, year in the site's chosen date format.\n $format = variable_get('date_format_short', 'm/d/Y - H:i');\n $sort = array();\n $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));\n $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));\n $sort['year'] = strpos($format, 'Y');\n asort($sort);\n $order = array_keys($sort);\n\n // Output multi-selector for date.\n foreach ($order as $type) {\n switch ($type) {\n case 'day':\n $options = drupal_map_assoc(range(1, 31));\n $title = t('Day');\n break;\n\n case 'month':\n $options = drupal_map_assoc(range(1, 12), 'map_month');\n $title = t('Month');\n break;\n\n case 'year':\n $options = drupal_map_assoc(range(1900, 2050));\n $title = t('Year');\n break;\n }\n\n $element[$type] = array(\n '#type' => 'select',\n '#title' => $title,\n '#title_display' => 'invisible',\n '#value' => $element['#value'][$type],\n '#attributes' => $element['#attributes'],\n '#options' => $options,\n );\n }\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f9096e730", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_load/7.x", "instruction": "Implement `menu_load($menu_name)` in PHP for Drupal 7. Required behavior: Load the data for a single custom menu.", "context": "Parameters:\n- $menu_name: The unique name of a custom menu to load.\n\nReturns (Array): defining the custom menu, or FALSE if the menu doesn't exist.\n\nFile: modules/menu/menu.module", "response": "function menu_load($menu_name) {\n $all_menus = menu_load_all();\n return isset($all_menus[$menu_name]) ? $all_menus[$menu_name] : FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2f919259d1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_changed/7.x", "instruction": "Implement `ajax_command_changed($selector, $asterisk = '')` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'changed' command.", "context": "This command instructs the client to mark each of the elements matched by the given selector as 'ajax-changed'.\n\nThis command is implemented by Drupal.ajax.prototype.commands.changed() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n- $asterisk: An optional CSS selector which must be inside $selector. If specified, an asterisk will be appended to the HTML inside the $asterisk selector.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_changed($selector, $asterisk = '') {\n return array(\n 'command' => 'changed',\n 'selector' => $selector,\n 'asterisk' => $asterisk,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fa1607ae0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_multiple_value_form/7.x", "instruction": "Implement `field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state)` in PHP for Drupal 7. Required behavior: Special handling to create form elements for multiple values.", "context": "Handles generic features for multiple fields:\n- number of widgets\n- AHAH-'add more' button\n- drag-n-drop value reordering\n\nFile: modules/field/field.form.inc", "response": "function field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state) {\n $field_name = $field['field_name'];\n $parents = $form['#parents'];\n\n // Determine the number of widgets to display.\n switch ($field['cardinality']) {\n case FIELD_CARDINALITY_UNLIMITED:\n $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state);\n $max = $field_state['items_count'];\n break;\n\n default:\n $max = $field['cardinality'] - 1;\n break;\n }\n\n $title = check_plain($instance['label']);\n $description = field_filter_xss($instance['description']);\n\n $id_prefix = implode('-', array_merge($parents, array($field_name)));\n $wrapper_id = drupal_html_id($id_prefix . '-add-more-wrapper');\n\n $field_elements = array();\n\n $function = $instance['widget']['module'] . '_field_widget_form';\n if (function_exists($function)) {\n for ($delta = 0; $delta <= $max; $delta++) {\n $multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;\n $element = array(\n '#entity_type' => $instance['entity_type'],\n '#entity' => $form['#entity'],\n '#bundle' => $instance['bundle'],\n '#field_name' => $field_name,\n '#language' => $langcode,\n '#field_parents' => $parents,\n '#columns' => array_keys($field['columns']),\n '#title' => $title,\n '#description' => $description,\n // Only the first widget should be required.\n '#required' => $delta == 0 && $instance['required'],\n '#delta' => $delta,\n '#weight' => $delta,\n );\n // For multiple fields, title and description are handled by the wrapping\n // table.\n if ($multiple) {\n if ($delta == 0) {\n $element['#title'] = $title;\n }\n else {\n $element['#title'] = t('!title (value @number)', array('@number' => $delta + 1, '!title' => $title));\n }\n $element['#title_display'] = 'invisible';\n $element['#description'] = '';\n }\n if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta, $element)) {\n // Input field for the delta (drag-n-drop reordering).\n if ($multiple) {\n // We name the element '_weight' to avoid clashing with elements\n // defined by widget.\n $element['_weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight for row @number', array('@number' => $delta + 1)),\n '#title_display' => 'invisible',\n // Note: this 'delta' is the FAPI 'weight' element's property.\n '#delta' => $max,\n '#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta,\n '#weight' => 100,\n );\n }\n\n // Allow modules to alter the field widget form element.\n $context = array(\n 'form' => $form,\n 'field' => $field,\n 'instance' => $instance,\n 'langcode' => $langcode,\n 'items' => $items,\n 'delta' => $delta,\n );\n drupal_alter(array('field_widget_form', 'field_widget_' . $instance['widget']['type'] . '_form'), $element, $form_state, $context);\n\n $field_elements[$delta] = $element;\n }\n }\n\n if ($field_elements) {\n $field_elements += array(\n '#theme' => 'field_multiple_value_form',\n '#field_name' => $field['field_name'],\n '#cardinality' => $field['cardinality'],\n '#title' => $title,\n '#required' => $instance['required'],\n '#description' => $description,\n '#prefix' => '
            ',\n '#suffix' => '
            ',\n '#max_delta' => $max,\n );\n // Add 'add more' button, if not working with a programmed form.\n if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED && empty($form_state['programmed'])) {\n $field_elements['add_more'] = array(\n '#type' => 'submit',\n '#name' => strtr($id_prefix, '-', '_') . '_add_more',\n '#value' => t('Add another item'),\n '#attributes' => array('class' => array('field-add-more-submit')),\n '#limit_validation_errors' => array(array_merge($parents, array($field_name, $langcode))),\n '#submit' => array('field_add_more_submit'),\n '#ajax' => array(\n 'callback' => 'field_add_more_js',\n 'wrapper' => $wrapper_id,\n 'effect' => 'fade',\n ),\n );\n }\n }\n }\n\n return $field_elements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fa439cc9e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_admin/7.x", "instruction": "I need the code for `shortcut_set_admin()` in Drupal 7 (modules/shortcut/shortcut.admin.inc). It must do this: Menu page callback: builds the page for administering shortcut sets.", "context": "File: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_set_admin() {\n $shortcut_sets = shortcut_sets();\n $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 4));\n\n $rows = array();\n foreach ($shortcut_sets as $set) {\n $row = array(\n check_plain($set->title),\n l(t('list links'), \"admin/config/user-interface/shortcut/$set->set_name\"),\n l(t('edit set name'), \"admin/config/user-interface/shortcut/$set->set_name/edit\"),\n );\n if (shortcut_set_delete_access($set)) {\n $row[] = l(t('delete set'), \"admin/config/user-interface/shortcut/$set->set_name/delete\");\n }\n else {\n $row[] = '';\n }\n\n $rows[] = $row;\n }\n\n return theme('table', array('header' => $header, 'rows' => $rows));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fa8a5a453", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_process_states/7.x", "instruction": "I need the code for `drupal_process_states(&$elements)` in Drupal 7 (includes/common.inc). It must do this: Adds JavaScript to change the state of an element based on another element.", "context": "A \"state\" means a certain property on a DOM element, such as \"visible\" or \"checked\". A state can be applied to an element, depending on the state of another element on the page. In general, states depend on HTML attributes and DOM element properties, which change due to user interaction.\n\nSince states are driven by JavaScript only, it is important to understand that all states are applied on presentation only, none of the states force any server-side logic, and that they will not be applied for site visitors without JavaScript support. All modules implementing states have to make sure that the intended logic also works without JavaScript being enabled.\n\n#states is an associative array in the form of:\n\nParameters:\n- $elements: A renderable array element having a #states property as described above.\n\nFile: includes/common.inc", "response": "function drupal_process_states(&$elements) {\n $elements['#attached']['library'][] = array('system', 'drupal.states');\n $elements['#attached']['js'][] = array(\n 'type' => 'setting',\n 'data' => array('states' => array('#' . $elements['#id'] => $elements['#states'])),\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fae25f851", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_get_assigned_actions/7.x", "instruction": "I need the code for `trigger_get_assigned_actions($hook)` in Drupal 7 (modules/trigger/trigger.module). It must do this: Gets the action IDs of actions to be executed for a hook.", "context": "Parameters:\n- $hook: The name of the hook being fired.\n\nReturns: An array whose keys are action IDs that the user has associated with this trigger, and whose values are arrays containing the action type and label.\n\nFile: modules/trigger/trigger.module", "response": "function trigger_get_assigned_actions($hook) {\n $actions = &drupal_static(__FUNCTION__, array());\n if (!isset($actions[$hook])) {\n $actions[$hook] = db_query(\"SELECT ta.aid, a.type, a.label FROM {trigger_assignments} ta LEFT JOIN {actions} a ON ta.aid = a.aid WHERE ta.hook = :hook ORDER BY ta.weight\", array(\n ':hook' => $hook,\n ))->fetchAllAssoc('aid', PDO::FETCH_ASSOC);\n }\n return $actions[$hook];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2faeb79bd2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_view_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_block_view_alter(&$data, $block)` (modules/block/block.api.php): Perform alterations to the content of a block.", "context": "This hook allows you to modify any data returned by hook_block_view().\n\nNote that instead of hook_block_view_alter(), which is called for all blocks, you can also use hook_block_view_MODULE_DELTA_alter() to alter a specific block.\n\nParameters:\n- $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 empty) or an array containing: - subject: The default localized title of the block. - content: Either a string or a renderable array representing the content of the block. You should check that the content is an array before trying to modify parts of the renderable structure.\n- $block: The block object, as loaded from the database, having the main properties: - module: The name of the module that defined the block. - delta: The unique identifier for the block within that module, as defined in hook_block_info().\n\nFile: modules/block/block.api.php", "response": "function hook_block_view_alter(&$data, $block) {\n // Remove the contextual links on all blocks that provide them.\n if (is_array($data['content']) && isset($data['content']['#contextual_links'])) {\n unset($data['content']['#contextual_links']);\n }\n // Add a theme wrapper function defined by the current module to all blocks\n // provided by the \"somemodule\" module.\n if (is_array($data['content']) && $block->module == 'somemodule') {\n $data['content']['#theme_wrappers'][] = 'mymodule_special_block';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fb7a614e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_resize/7.x", "instruction": "I need the code for `image_gd_resize(stdClass $image, $width, $height)` in Drupal 7 (modules/system/image.gd.inc). It must do this: Scale an image to the specified size using GD.", "context": "Parameters:\n- $image: An image object. The $image->resource, $image->info['width'], and $image->info['height'] values will be modified by this call.\n- $width: The new width of the resized image, in pixels.\n- $height: The new height of the resized image, in pixels.\n\nReturns: TRUE or FALSE, based on success.\n\nFile: modules/system/image.gd.inc", "response": "function image_gd_resize(stdClass $image, $width, $height) {\n $res = image_gd_create_tmp($image, $width, $height);\n\n if (!imagecopyresampled($res, $image->resource, 0, 0, 0, 0, $width, $height, $image->info['width'], $image->info['height'])) {\n return FALSE;\n }\n\n imagedestroy($image->resource);\n // Update image object.\n $image->resource = $res;\n $image->info['width'] = $width;\n $image->info['height'] = $height;\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fbb4fc6e4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_pre_render_markup/7.x", "instruction": "Implement `drupal_pre_render_markup($elements)` in PHP for Drupal 7. Required behavior: #pre_render callback to append contents in #markup to #children.", "context": "This needs to be a #pre_render callback, because eventually assigned #theme_wrappers will expect the element's rendered content in #children. Note that if also a #theme is defined for the element, then the result of the theme callback will override #children.\n\nParameters:\n- $elements: A structured array using the #markup key.\n\nReturns: The passed-in elements, but #markup appended to #children.\n\nFile: includes/common.inc", "response": "function drupal_pre_render_markup($elements) {\n $elements['#children'] = $elements['#markup'];\n return $elements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fc26fe147", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_instances/7.x", "instruction": "Implement `field_info_instances($entity_type = NULL, $bundle_name = NULL)` in PHP for Drupal 7. Required behavior: Retrieves information about field instances.", "context": "Use of this function to retrieve instances across separate bundles (i.e. when the $bundle parameter is NULL) should be avoided when possible, since it loads and statically caches a potentially large array of information. Use field_info_field_map() instead.\n\nWhen retrieving the instances of a specific bundle (i.e. when both $entity_type and $bundle_name are provided), the function also populates a static cache with the corresponding field definitions, allowing fast retrieval of field_info_field() later in the request.\n\nParameters:\n- $entity_type: (optional) The entity type for which to return instances.\n- $bundle_name: (optional) The bundle name for which to return instances. If $entity_type is NULL, the $bundle_name parameter is ignored.\n\nReturns: If $entity_type is not set, return all instances keyed by entity type and bundle name. If $entity_type is set, return all instances for that entity type, keyed by bundle name. If $entity_type and $bundle_name are set, return all instances for that bundle.\n\nFile: modules/field/field.info.inc", "response": "function field_info_instances($entity_type = NULL, $bundle_name = NULL) {\n $cache = _field_info_field_cache();\n\n if (!isset($entity_type)) {\n return $cache->getInstances();\n }\n if (!isset($bundle_name)) {\n return $cache->getInstances($entity_type);\n }\n\n return $cache->getBundleInstances($entity_type, $bundle_name);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fccb5ed06", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_encode_message/7.x", "instruction": "I need the code for `_openid_encode_message($message)` in Drupal 7 (modules/openid/openid.inc). It must do this: Encode a message from _openid_create_message for HTTP Post", "context": "File: modules/openid/openid.inc", "response": "function _openid_encode_message($message) {\n $encoded_message = '';\n\n $items = explode(\"\\n\", $message);\n foreach ($items as $item) {\n $parts = explode(':', $item, 2);\n\n if (count($parts) == 2) {\n if ($encoded_message != '') {\n $encoded_message .= '&';\n }\n $encoded_message .= rawurlencode(trim($parts[0])) . '=' . rawurlencode(trim($parts[1]));\n }\n }\n\n return $encoded_message;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fd643421e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_filetransfer_info/7.x", "instruction": "Implement `system_filetransfer_info()` in PHP for Drupal 7. Required behavior: Implements hook_filetransfer_info().", "context": "File: modules/system/system.module", "response": "function system_filetransfer_info() {\n $backends = array();\n\n // This is the default, will be available on most systems.\n if (function_exists('ftp_connect')) {\n $backends['ftp'] = array(\n 'title' => t('FTP'),\n 'class' => 'FileTransferFTP',\n 'file' => 'ftp.inc',\n 'file path' => 'includes/filetransfer',\n 'weight' => 0,\n );\n }\n\n // SSH2 lib connection is only available if the proper PHP extension is\n // installed.\n if (function_exists('ssh2_connect')) {\n $backends['ssh'] = array(\n 'title' => t('SSH'),\n 'class' => 'FileTransferSSH',\n 'file' => 'ssh.inc',\n 'file path' => 'includes/filetransfer',\n 'weight' => 20,\n );\n }\n return $backends;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-2fe60ed96e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_admin_demo/7.x", "instruction": "Implement `block_admin_demo($theme = NULL)` in PHP for Drupal 7. Required behavior: Menu callback for admin/structure/block/demo.", "context": "File: modules/block/block.admin.inc", "response": "function block_admin_demo($theme = NULL) {\n drupal_add_css(drupal_get_path('module', 'block') . '/block.css');\n return '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-2ff1e6584b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_get_any/7.x", "instruction": "Implement `language_negotiation_get_any($provider_id)` in PHP for Drupal 7. Required behavior: Checks if the language negotiation provider is enabled for any language type.", "context": "Parameters:\n- $provider_id: The language negotiation provider ID.\n\nReturns: TRUE if there is at least one language type for which the given language provider is enabled, FALSE otherwise.\n\nFile: includes/language.inc", "response": "function language_negotiation_get_any($provider_id) {\n foreach (language_types_configurable() as $type) {\n if (language_negotiation_get($type, $provider_id)) {\n return TRUE;\n }\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-30119df06f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_get_plural/7.x", "instruction": "Implement `locale_get_plural($count, $langcode = NULL)` in PHP for Drupal 7. Required behavior: Returns plural form index for a specific number.", "context": "The index is computed from the formula of this language.\n\nParameters:\n- $count: Number to return plural for.\n- $langcode: Optional language code to translate to a language other than what is used to display the page.\n\nReturns: The numeric index of the plural variant to use for this $langcode and $count combination or -1 if the language was not found or does not have a plural formula.\n\nFile: modules/locale/locale.module", "response": "function locale_get_plural($count, $langcode = NULL) {\n global $language;\n\n // Used to locally cache the plural formulas for all languages.\n $plural_formulas = &drupal_static(__FUNCTION__, array());\n\n // Used to store precomputed plural indexes corresponding to numbers\n // individually for each language.\n $plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', array());\n\n $langcode = $langcode ? $langcode : $language->language;\n\n if (!isset($plural_indexes[$langcode][$count])) {\n // Retrieve and statically cache the plural formulas for all languages.\n if (empty($plural_formulas)) {\n foreach (language_list() as $installed_language) {\n $plural_formulas[$installed_language->language] = $installed_language->formula;\n }\n }\n // If there is a plural formula for the language, evaluate it for the given\n // $count and statically cache the result for the combination of language\n // and count, since the result will always be identical.\n if (!empty($plural_formulas[$langcode])) {\n // $n is used inside the expression in the eval().\n $n = $count;\n $plural_indexes[$langcode][$count] = @eval('return intval(' . $plural_formulas[$langcode] . ');');\n }\n // In case there is no plural formula for English (no imported translation\n // for English), use a default formula.\n elseif ($langcode == 'en') {\n $plural_indexes[$langcode][$count] = (int) ($count != 1);\n }\n // Otherwise, return -1 (unknown).\n else {\n $plural_indexes[$langcode][$count] = -1;\n }\n }\n return $plural_indexes[$langcode][$count];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-301920ec6f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_update_index/7.x", "instruction": "Give me the example code for `hook_update_index()` in Drupal 7. Hook description: Update the search index for this module.", "context": "This hook is called every cron run if search.module is enabled, your module has implemented hook_search_info(), and your module has been set as an active search module on the Search settings page (admin/config/search/settings). It allows your module to add items to the built-in search index using search_index(), or to add them to your module's own indexing mechanism.\n\nWhen implementing this hook, your module should index content items that were modified or added since the last run. PHP has a time limit for cron, though, so it is advisable to limit how many items you index per run using variable_get('search_cron_limit') (see example below). Also, since the cron run could time out and abort in the middle of your run, you should update your module's internal bookkeeping on when items have last been indexed as you go rather than waiting to the end of indexing.\n\nFile: modules/search/search.api.php", "response": "function hook_update_index() {\n $limit = (int)variable_get('search_cron_limit', 100);\n\n $result = db_query_range(\"SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC\", 0, $limit);\n\n foreach ($result as $node) {\n $node = node_load($node->nid);\n\n // Save the changed time of the most recent indexed node, for the search\n // results half-life calculation.\n variable_set('node_cron_last', $node->changed);\n\n // Render the node.\n node_build_content($node, 'search_index');\n $node->rendered = drupal_render($node->content);\n\n $text = '

            ' . check_plain($node->title) . '

            ' . $node->rendered;\n\n // Fetch extra data normally not visible\n $extra = module_invoke_all('node_update_index', $node);\n foreach ($extra as $t) {\n $text .= $t;\n }\n\n // Update index\n search_index($node->nid, 'node', $text);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3025d540ab", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.api.php/function/hook_field_instance_settings_form/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_instance_settings_form($field, $instance)` (modules/field_ui/field_ui.api.php): Add settings to an instance field settings form.", "context": "Invoked from field_ui_field_edit_form() to allow the module defining the field to add settings for a field instance.\n\nParameters:\n- $field: The field structure being configured.\n- $instance: The instance structure being configured.\n\nReturns: The form definition for the field instance settings.\n\nFile: modules/field_ui/field_ui.api.php", "response": "function hook_field_instance_settings_form($field, $instance) {\n $settings = $instance['settings'];\n\n $form['text_processing'] = array(\n '#type' => 'radios',\n '#title' => t('Text processing'),\n '#default_value' => $settings['text_processing'],\n '#options' => array(\n t('Plain text'),\n t('Filtered text (user selects text format)'),\n ),\n );\n if ($field['type'] == 'text_with_summary') {\n $form['display_summary'] = array(\n '#type' => 'select',\n '#title' => t('Display summary'),\n '#options' => array(\n t('No'),\n t('Yes'),\n ),\n '#description' => t('Display the summary to allow the user to input a summary value. Hide the summary to automatically fill it with a trimmed portion from the main post.'),\n '#default_value' => !empty($settings['display_summary']) ? $settings['display_summary'] : 0,\n );\n }\n\n return $form;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-306c96bf95", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_release_all/7.x", "instruction": "In Drupal 7, write the function `lock_release_all($lock_id = NULL)` (file includes/lock.inc) so that it does the following: Release all previously acquired locks.", "context": "File: includes/lock.inc", "response": "function lock_release_all($lock_id = NULL) {\n global $locks;\n\n $locks = array();\n if (empty($lock_id)) {\n $lock_id = _lock_id();\n }\n db_delete('semaphore')\n ->condition('value', $lock_id)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3089b2351c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/template_preprocess_menu_tree/7.x", "instruction": "I need the code for `template_preprocess_menu_tree(&$variables)` in Drupal 7 (includes/menu.inc). It must do this: Implements template_preprocess_HOOK() for theme_menu_tree().", "context": "File: includes/menu.inc", "response": "function template_preprocess_menu_tree(&$variables) {\n $variables['#tree'] = $variables['tree'];\n $variables['tree'] = $variables['tree']['#children'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-309122a7bd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_uid_optional_load/7.x", "instruction": "In Drupal 7, write the function `user_uid_optional_load($uid = NULL)` (file modules/user/user.module) so that it does the following: Load either a specified or the current user account.", "context": "Parameters:\n- $uid: An optional user ID of the user to load. If not provided, the current user's ID will be used.\n\nReturns: A fully-loaded $user object upon successful user load, FALSE if user cannot be loaded.\n\nFile: modules/user/user.module", "response": "function user_uid_optional_load($uid = NULL) {\n if (!isset($uid)) {\n $uid = $GLOBALS['user']->uid;\n }\n return user_load($uid);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-30ba83f360", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_set_expanded_menus/7.x", "instruction": "Implement `_menu_set_expanded_menus()` in PHP for Drupal 7. Required behavior: Updates a list of menus with expanded items.", "context": "File: includes/menu.inc", "response": "function _menu_set_expanded_menus() {\n $names = db_query(\"SELECT menu_name FROM {menu_links} WHERE expanded <> 0 GROUP BY menu_name\")->fetchCol();\n variable_set('menu_expanded', $names);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-30c0745357", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_retrieve_file/7.x", "instruction": "In Drupal 7, write the function `system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME)` (file modules/system/system.module) so that it does the following: Attempts to get a file using drupal_http_request and to store it locally.", "context": "Parameters:\n- $url (string): The URL of the file to grab.\n- $destination (string): Stream wrapper URI specifying where the file should be placed. If a directory path is provided, the file is saved into that directory under its original name. If the path contains a filename as well, that one will be used instead. If this value is omitted, the site's default files scheme will be used, usually \"public://\".\n- $managed (bool): If this is set to TRUE, the file API hooks will be invoked and the file is registered in the database.\n- $replace (int): Replace behavior when the destination file already exists: - FILE_EXISTS_REPLACE: Replace the existing file. - FILE_EXISTS_RENAME: Append _{incrementing number} until the filename is unique. - FILE_EXISTS_ERROR: Do nothing and return FALSE.\n\nReturns (mixed): One of these possibilities: - If it succeeds and $managed is FALSE, the location where the file was saved. - If it succeeds and $managed is TRUE, a \\Drupal\\file\\FileInterface object which describes the file. - If it fails, FALSE.\n\nFile: modules/system/system.module", "response": "function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $replace = FILE_EXISTS_RENAME) {\n $parsed_url = parse_url($url);\n if (!isset($destination)) {\n $path = file_build_uri(drupal_basename($parsed_url['path']));\n }\n else {\n if (is_dir(drupal_realpath($destination))) {\n // Prevent URIs with triple slashes when glueing parts together.\n $path = str_replace('///', '//', \"$destination/\") . drupal_basename($parsed_url['path']);\n }\n else {\n $path = $destination;\n }\n }\n $result = drupal_http_request($url);\n if ($result->code != 200) {\n drupal_set_message(t('HTTP error @errorcode occurred when trying to fetch @remote.', array('@errorcode' => $result->code, '@remote' => $url)), 'error');\n return FALSE;\n }\n $local = $managed ? file_save_data($result->data, $path, $replace) : file_unmanaged_save_data($result->data, $path, $replace);\n if (!$local) {\n drupal_set_message(t('@remote could not be saved to @path.', array('@remote' => $url, '@path' => $path)), 'error');\n }\n\n return $local;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-30c1d58324", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_get_blocks_by_region/7.x", "instruction": "I need the code for `block_get_blocks_by_region($region)` in Drupal 7 (modules/block/block.module). It must do this: Gets a renderable array of a region containing all enabled blocks.", "context": "Parameters:\n- $region: The requested region.\n\nReturns: A renderable array of a region containing all enabled blocks.\n\nFile: modules/block/block.module", "response": "function block_get_blocks_by_region($region) {\n $build = array();\n if ($list = block_list($region)) {\n $build = _block_get_renderable_array($list);\n }\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-30c459a63e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_prepare_view/7.x", "instruction": "Give me the example code for `hook_entity_prepare_view($entities, $type, $langcode)` in Drupal 7. Hook description: Act on entities as they are being prepared for view.", "context": "Allows you to operate on multiple entities as they are being prepared for view. Only use this if attaching the data during the entity_load() phase is not appropriate, for example when attaching other 'entity' style objects.\n\nParameters:\n- $entities: The entities keyed by entity ID.\n- $type: The type of entities being loaded (i.e. node, user, comment).\n- $langcode: The language to display the entity in.\n\nFile: modules/system/system.api.php", "response": "function hook_entity_prepare_view($entities, $type, $langcode) {\n // Load a specific node into the user object for later theming.\n if ($type == 'user') {\n $nodes = mymodule_get_user_nodes(array_keys($entities));\n foreach ($entities as $uid => $entity) {\n $entity->user_node = $nodes[$uid];\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-30c4bc706d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_array_transpose/7.x", "instruction": "I need the code for `options_array_transpose($array)` in Drupal 7 (modules/field/modules/options/options.module). It must do this: Manipulates a 2D array to reverse rows and columns.", "context": "The default data storage for fields is delta first, column names second. This is sometimes inconvenient for field modules, so this function can be used to present the data in an alternate format.\n\nParameters:\n- $array: The array to be transposed. It must be at least two-dimensional, and the subarrays must all have the same keys or behavior is undefined.\n\nReturns: The transposed array.\n\nFile: modules/field/modules/options/options.module", "response": "function options_array_transpose($array) {\n $result = array();\n if (is_array($array)) {\n foreach ($array as $key1 => $value1) {\n if (is_array($value1)) {\n foreach ($value1 as $key2 => $value2) {\n if (!isset($result[$key2])) {\n $result[$key2] = array();\n }\n $result[$key2][$key1] = $value2;\n }\n }\n }\n }\n return $result;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-30d558cf4c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7003/7.x", "instruction": "Implement `system_update_7003()` in PHP for Drupal 7. Required behavior: Update {blocked_ips} with valid IP addresses from {access}.", "context": "File: modules/system/system.install", "response": "function system_update_7003() {\n $messages = array();\n $type = 'host';\n $result = db_query(\"SELECT mask FROM {access} WHERE status = :status AND type = :type\", array(\n ':status' => 0,\n ':type' => $type,\n ));\n foreach ($result as $blocked) {\n if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) {\n db_insert('blocked_ips')\n ->fields(array('ip' => $blocked->mask))\n ->execute();\n }\n else {\n $invalid_host = check_plain($blocked->mask);\n $messages[] = t('The host !host is no longer blocked because it is not a valid IP address.', array('!host' => $invalid_host ));\n }\n }\n if (isset($invalid_host)) {\n drupal_set_message('Drupal no longer supports wildcard IP address blocking. Visitors whose IP addresses match ranges you have previously set using access rules will no longer be blocked from your site when you put the site online. See the IP address and referrer blocking Handbook page for alternative methods.', 'warning');\n }\n // Make sure not to block any IP addresses that were specifically allowed by access rules.\n if (!empty($result)) {\n $result = db_query(\"SELECT mask FROM {access} WHERE status = :status AND type = :type\", array(\n ':status' => 1,\n ':type' => $type,\n ));\n $or = db_condition('or');\n foreach ($result as $allowed) {\n $or->condition('ip', $allowed->mask, 'LIKE');\n }\n if (count($or)) {\n db_delete('blocked_ips')\n ->condition($or)\n ->execute();\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-30f5a82720", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_attach_rename_bundle/7.x", "instruction": "I need the code for `field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_field_attach_rename_bundle().", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {\n // We need to account for deleted or inactive fields and instances.\n $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle_new), array('include_deleted' => TRUE, 'include_inactive' => TRUE));\n foreach ($instances as $instance) {\n $field = field_info_field_by_id($instance['field_id']);\n if ($field['storage']['type'] == 'field_sql_storage') {\n $table_name = _field_sql_storage_tablename($field);\n $revision_name = _field_sql_storage_revision_tablename($field);\n db_update($table_name)\n ->fields(array('bundle' => $bundle_new))\n ->condition('entity_type', $entity_type)\n ->condition('bundle', $bundle_old)\n ->execute();\n db_update($revision_name)\n ->fields(array('bundle' => $bundle_new))\n ->condition('entity_type', $entity_type)\n ->condition('bundle', $bundle_old)\n ->execute();\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-310011cdb0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_block_view/7.x", "instruction": "Implement `user_block_view($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_view().", "context": "File: modules/user/user.module", "response": "function user_block_view($delta = '') {\n global $user;\n\n $block = array();\n\n switch ($delta) {\n case 'login':\n // For usability's sake, avoid showing two login forms on one page.\n if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {\n\n $block['subject'] = t('User login');\n $block['content'] = drupal_get_form('user_login_block');\n }\n return $block;\n\n case 'new':\n if (user_access('access content')) {\n // Retrieve a list of new users who have subsequently accessed the site successfully.\n $items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, variable_get('user_block_whois_new_count', 5))->fetchAll();\n $output = theme('user_list', array('users' => $items));\n\n $block['subject'] = t('Who\\'s new');\n $block['content'] = $output;\n }\n return $block;\n\n case 'online':\n if (user_access('access content')) {\n // Count users active within the defined period.\n $interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900);\n\n // Perform database queries to gather online user lists. We use s.timestamp\n // rather than u.access because it is much faster.\n $authenticated_count = db_query(\"SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0\", array(':timestamp' => $interval))->fetchField();\n\n $output = '

            ' . format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.') . '

            ';\n\n // Display a list of currently online users.\n $max_users = variable_get('user_block_max_list_count', 10);\n if ($authenticated_count && $max_users) {\n $items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', 0, $max_users, array(':interval' => $interval))->fetchAll();\n $output .= theme('user_list', array('users' => $items));\n }\n\n $block['subject'] = t('Who\\'s online');\n $block['content'] = $output;\n }\n return $block;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-310557bb0c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_access/7.x", "instruction": "In Drupal 7, write the function `comment_access($op, $comment)` (file modules/comment/comment.module) so that it does the following: Determines whether the current user has access to a particular comment.", "context": "Authenticated users can edit their comments as long they have not been replied to. This prevents people from changing or revising their statements based on the replies to their posts.\n\nParameters:\n- $op: The operation that is to be performed on the comment. Only 'edit' is recognized now.\n- $comment: The comment object.\n\nReturns: TRUE if the current user has acces to the comment, FALSE otherwise.\n\nFile: modules/comment/comment.module", "response": "function comment_access($op, $comment) {\n global $user;\n\n if ($op == 'edit') {\n return ($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3139084f02", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_permissions/7.x", "instruction": "I need the code for `user_admin_permissions($form, $form_state, $rid = NULL)` in Drupal 7 (modules/user/user.admin.inc). It must do this: Menu callback: administer permissions.", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_permissions($form, $form_state, $rid = NULL) {\n\n // Retrieve role names for columns.\n $role_names = user_roles();\n if (is_numeric($rid)) {\n $role_names = array($rid => $role_names[$rid]);\n }\n // Fetch permissions for all roles or the one selected role.\n $role_permissions = user_role_permissions($role_names);\n\n // Store $role_names for use when saving the data.\n $form['role_names'] = array(\n '#type' => 'value',\n '#value' => $role_names,\n );\n // Render role/permission overview:\n $options = array();\n $module_info = system_get_info('module');\n $hide_descriptions = system_admin_compact_mode();\n\n // Get a list of all the modules implementing a hook_permission() and sort by\n // display name.\n $modules = array();\n foreach (module_implements('permission') as $module) {\n $modules[$module] = $module_info[$module]['name'];\n }\n asort($modules);\n\n foreach ($modules as $module => $display_name) {\n if ($permissions = module_invoke($module, 'permission')) {\n $form['permission'][] = array(\n '#markup' => $module_info[$module]['name'],\n '#id' => $module,\n );\n foreach ($permissions as $perm => $perm_item) {\n // Fill in default values for the permission.\n $perm_item += array(\n 'description' => '',\n 'restrict access' => FALSE,\n 'warning' => !empty($perm_item['restrict access']) ? t('Warning: Give to trusted roles only; this permission has security implications.') : '',\n );\n $options[$perm] = '';\n $form['permission'][$perm] = array(\n '#type' => 'item',\n '#markup' => $perm_item['title'],\n '#description' => theme('user_permission_description', array('permission_item' => $perm_item, 'hide' => $hide_descriptions)),\n );\n foreach ($role_names as $rid => $name) {\n // Builds arrays for checked boxes for each role\n if (isset($role_permissions[$rid][$perm])) {\n $status[$rid][] = $perm;\n }\n }\n }\n }\n }\n\n // Have to build checkboxes here after checkbox arrays are built\n foreach ($role_names as $rid => $name) {\n $form['checkboxes'][$rid] = array(\n '#type' => 'checkboxes',\n '#options' => $options,\n '#default_value' => isset($status[$rid]) ? $status[$rid] : array(),\n '#attributes' => array('class' => array('rid-' . $rid)),\n );\n $form['role_names'][$rid] = array('#markup' => check_plain($name), '#tree' => TRUE);\n }\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));\n\n $form['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.permissions.js';\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-31785da65f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_deliver_empty_page/7.x", "instruction": "Implement `overlay_deliver_empty_page()` in PHP for Drupal 7. Required behavior: Prints an empty page.", "context": "This function is used to print out a bare minimum empty page which still has the scripts and styles necessary in order to trigger the overlay to close.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_deliver_empty_page() {\n $empty_page = '' . drupal_get_css() . drupal_get_js() . '';\n print $empty_page;\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-31a716d905", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contextual%21contextual.module/function/contextual_preprocess/7.x", "instruction": "I need the code for `contextual_preprocess(&$variables, $hook)` in Drupal 7 (modules/contextual/contextual.module). It must do this: Implements hook_preprocess().", "context": "File: modules/contextual/contextual.module", "response": "function contextual_preprocess(&$variables, $hook) {\n // Nothing to do here if the user is not permitted to access contextual links.\n if (!user_access('access contextual links')) {\n return;\n }\n\n $hooks = theme_get_registry(FALSE);\n\n // Determine the primary theme function argument.\n if (!empty($hooks[$hook]['variables'])) {\n $keys = array_keys($hooks[$hook]['variables']);\n $key = $keys[0];\n }\n elseif (!empty($hooks[$hook]['render element'])) {\n $key = $hooks[$hook]['render element'];\n }\n if (!empty($key) && isset($variables[$key])) {\n $element = $variables[$key];\n }\n\n if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {\n // Initialize the template variable as a renderable array.\n $variables['title_suffix']['contextual_links'] = array(\n '#type' => 'contextual_links',\n '#contextual_links' => $element['#contextual_links'],\n '#element' => $element,\n );\n // Mark this element as potentially having contextual links attached to it.\n $variables['classes_array'][] = 'contextual-links-region';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-31c1f6ff1a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21update.inc/function/update_do_one/7.x", "instruction": "Implement `update_do_one($module, $number, $dependency_map, &$context)` in PHP for Drupal 7. Required behavior: Implements callback_batch_operation().", "context": "Performs one update and stores the results for display on the results page.\n\nIf an update function completes successfully, it should return a message as a string indicating success, for example:\n\nParameters:\n- $module: The module whose update will be run.\n- $number: The update number to run.\n- $dependency_map: An array whose keys are the names of all update functions that will be performed during this batch process, and whose values are arrays of other update functions that each one depends on.\n- $context: The batch context array.\n\nFile: includes/update.inc", "response": "function update_do_one($module, $number, $dependency_map, &$context) {\n $function = $module . '_update_' . $number;\n\n // If this update was aborted in a previous step, or has a dependency that\n // was aborted in a previous step, go no further.\n if (!empty($context['results']['#abort']) && array_intersect($context['results']['#abort'], array_merge($dependency_map, array($function)))) {\n return;\n }\n\n $ret = array();\n if (function_exists($function)) {\n try {\n $ret['results']['query'] = $function($context['sandbox']);\n $ret['results']['success'] = TRUE;\n }\n // @TODO We may want to do different error handling for different\n // exception types, but for now we'll just log the exception and\n // return the message for printing.\n catch (Exception $e) {\n watchdog_exception('update', $e);\n\n require_once DRUPAL_ROOT . '/includes/errors.inc';\n $variables = _drupal_decode_exception($e);\n // The exception message is run through check_plain() by _drupal_decode_exception().\n $ret['#abort'] = array('success' => FALSE, 'query' => t('%type: !message in %function (line %line of %file).', $variables));\n }\n }\n\n if (isset($context['sandbox']['#finished'])) {\n $context['finished'] = $context['sandbox']['#finished'];\n unset($context['sandbox']['#finished']);\n }\n\n if (!isset($context['results'][$module])) {\n $context['results'][$module] = array();\n }\n if (!isset($context['results'][$module][$number])) {\n $context['results'][$module][$number] = array();\n }\n $context['results'][$module][$number] = array_merge($context['results'][$module][$number], $ret);\n\n if (!empty($ret['#abort'])) {\n // Record this function in the list of updates that were aborted.\n $context['results']['#abort'][] = $function;\n }\n\n // Record the schema update if it was completed successfully.\n if ($context['finished'] == 1 && empty($ret['#abort'])) {\n drupal_set_installed_schema_version($module, $number);\n }\n\n $context['message'] = 'Updating ' . check_plain($module) . ' module';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-321ecd24b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.install/function/simpletest_requirements/7.x", "instruction": "Implement `simpletest_requirements($phase)` in PHP for Drupal 7. Required behavior: Implements hook_requirements().", "context": "File: modules/simpletest/simpletest.install", "response": "function simpletest_requirements($phase) {\n $requirements = array();\n $t = get_t();\n\n $has_curl = function_exists('curl_init');\n $has_hash = function_exists('hash_hmac');\n $has_domdocument = method_exists('DOMDocument', 'loadHTML');\n\n $requirements['curl'] = array(\n 'title' => $t('cURL'),\n 'value' => $has_curl ? $t('Enabled') : $t('Not found'),\n );\n if (!$has_curl) {\n $requirements['curl']['severity'] = REQUIREMENT_ERROR;\n $requirements['curl']['description'] = $t('The testing framework could not be installed because the PHP cURL library is not available.', array('@curl_url' => 'http://php.net/manual/en/curl.setup.php'));\n }\n $requirements['hash'] = array(\n 'title' => $t('hash'),\n 'value' => $has_hash ? $t('Enabled') : $t('Not found'),\n );\n if (!$has_hash) {\n $requirements['hash']['severity'] = REQUIREMENT_ERROR;\n $requirements['hash']['description'] = $t('The testing framework could not be installed because the PHP hash extension is disabled.', array('@hash_url' => 'http://php.net/manual/en/book.hash.php'));\n }\n\n $requirements['php_domdocument'] = array(\n 'title' => $t('PHP DOMDocument class'),\n 'value' => $has_domdocument ? $t('Enabled') : $t('Not found'),\n );\n if (!$has_domdocument) {\n $requirements['php_domdocument']['severity'] = REQUIREMENT_ERROR;\n $requirements['php_domdocument']['description'] = $t('The testing framework requires the DOMDocument class to be available. Check the configure command at the PHP info page.', array('@link-phpinfo' => url('admin/reports/status/php')));\n }\n\n // Check the current memory limit. If it is set too low, SimpleTest will fail\n // to load all tests and throw a fatal error.\n $memory_limit = ini_get('memory_limit');\n if (!drupal_check_memory_limit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {\n $requirements['php_memory_limit']['severity'] = REQUIREMENT_ERROR;\n $requirements['php_memory_limit']['description'] = $t('The testing framework requires the PHP memory limit to be at least %memory_minimum_limit. The current value is %memory_limit. Follow these steps to continue.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, '@url' => 'http://drupal.org/node/207036'));\n }\n\n return $requirements;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-32414bcb25", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_account_form_validate/7.x", "instruction": "Implement `user_account_form_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for user_account_form().", "context": "File: modules/user/user.module", "response": "function user_account_form_validate($form, &$form_state) {\n if ($form['#user_category'] == 'account' || $form['#user_category'] == 'register') {\n $account = $form['#user'];\n // Validate new or changing username.\n if (isset($form_state['values']['name'])) {\n if ($error = user_validate_name($form_state['values']['name'])) {\n form_set_error('name', $error);\n }\n elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('name', db_like($form_state['values']['name']), 'LIKE')->range(0, 1)->execute()->fetchField()) {\n form_set_error('name', t('The name %name is already taken.', array('%name' => $form_state['values']['name'])));\n }\n }\n\n // Trim whitespace from mail, to prevent confusing 'e-mail not valid'\n // warnings often caused by cutting and pasting.\n $mail = trim($form_state['values']['mail']);\n form_set_value($form['account']['mail'], $mail, $form_state);\n\n // Validate the e-mail address, and check if it is taken by an existing user.\n if ($error = user_validate_mail($form_state['values']['mail'])) {\n form_set_error('mail', $error);\n }\n elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($form_state['values']['mail']), 'LIKE')->range(0, 1)->execute()->fetchField()) {\n // Format error message dependent on whether the user is logged in or not.\n if ($GLOBALS['user']->uid) {\n // Do not fail the validation if user has not changed e-mail address.\n // This means that multiple accounts with the same e-mail address exist\n // and the logged-in user is one of them.\n if ((isset($account->mail) && $account->mail != $mail) || !isset($account->mail)) {\n form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $form_state['values']['mail'])));\n }\n }\n else {\n form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $form_state['values']['mail'], '@password' => url('user/password'))));\n }\n }\n\n // Make sure the signature isn't longer than the size of the database field.\n // Signatures are disabled by default, so make sure it exists first.\n if (isset($form_state['values']['signature'])) {\n // Move text format for user signature into 'signature_format'.\n $form_state['values']['signature_format'] = $form_state['values']['signature']['format'];\n // Move text value for user signature into 'signature'.\n $form_state['values']['signature'] = $form_state['values']['signature']['value'];\n\n $user_schema = drupal_get_schema('users');\n if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) {\n form_set_error('signature', t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length'])));\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-324adf20d9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_breadcrumb/7.x", "instruction": "I need the code for `drupal_get_breadcrumb()` in Drupal 7 (includes/common.inc). It must do this: Gets the breadcrumb trail for the current page.", "context": "File: includes/common.inc", "response": "function drupal_get_breadcrumb() {\n $breadcrumb = drupal_set_breadcrumb();\n\n if (!isset($breadcrumb)) {\n $breadcrumb = menu_get_active_breadcrumb();\n }\n\n return $breadcrumb;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-324c2fcf26", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_delete/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_storage_delete($entity_type, $entity, $fields)` (modules/field/field.api.php): Delete all field data for an entity.", "context": "This hook is invoked from field_attach_delete() to ask the field storage module to delete field data.\n\nParameters:\n- $entity_type: The entity type of entity, such as 'node' or 'user'.\n- $entity: The entity on which to operate.\n- $fields: An array listing the fields to delete. The keys and values of the array are field IDs.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_delete($entity_type, $entity, $fields) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n foreach (field_info_instances($entity_type, $bundle) as $instance) {\n if (isset($fields[$instance['field_id']])) {\n $field = field_info_field_by_id($instance['field_id']);\n field_sql_storage_field_storage_purge($entity_type, $entity, $field, $instance);\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3251608986", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_performance_settings/7.x", "instruction": "Implement `system_performance_settings()` in PHP for Drupal 7. Required behavior: Form builder; Configure site performance settings.", "context": "File: modules/system/system.admin.inc", "response": "function system_performance_settings() {\n drupal_add_js(drupal_get_path('module', 'system') . '/system.js');\n\n $form['clear_cache'] = array(\n '#type' => 'fieldset',\n '#title' => t('Clear cache'),\n );\n\n $form['clear_cache']['clear'] = array(\n '#type' => 'submit',\n '#value' => t('Clear all caches'),\n '#submit' => array('system_clear_cache_submit'),\n );\n\n $form['caching'] = array(\n '#type' => 'fieldset',\n '#title' => t('Caching'),\n );\n\n $cache = variable_get('cache', 0);\n $form['caching']['cache'] = array(\n '#type' => 'checkbox',\n '#title' => t('Cache pages for anonymous users'),\n '#default_value' => $cache,\n '#weight' => -2,\n );\n $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');\n $period[0] = '<' . t('none') . '>';\n $form['caching']['cache_lifetime'] = array(\n '#type' => 'select',\n '#title' => t('Minimum cache lifetime'),\n '#default_value' => variable_get('cache_lifetime', 0),\n '#options' => $period,\n '#description' => t('Cached pages will not be re-created until at least this much time has elapsed.')\n );\n $form['caching']['page_cache_maximum_age'] = array(\n '#type' => 'select',\n '#title' => t('Expiration of cached pages'),\n '#default_value' => variable_get('page_cache_maximum_age', 0),\n '#options' => $period,\n '#description' => t('The maximum time an external cache can use an old version of a page.')\n );\n\n $directory = 'public://';\n $is_writable = is_dir($directory) && is_writable($directory);\n $disabled = !$is_writable;\n $disabled_message = '';\n if (!$is_writable) {\n $disabled_message = ' ' . t('Set up the public files directory to make these optimizations available.', array('!file-system' => url('admin/config/media/file-system')));\n }\n\n $form['bandwidth_optimization'] = array(\n '#type' => 'fieldset',\n '#title' => t('Bandwidth optimization'),\n '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message,\n );\n\n $js_hide = $cache ? '' : ' class=\"js-hide\"';\n $form['bandwidth_optimization']['page_compression'] = array(\n '#type' => 'checkbox',\n '#title' => t('Compress cached pages.'),\n '#default_value' => variable_get('page_compression', TRUE),\n '#prefix' => '
            ',\n '#suffix' => '
            ',\n );\n $form['bandwidth_optimization']['preprocess_css'] = array(\n '#type' => 'checkbox',\n '#title' => t('Aggregate and compress CSS files.'),\n '#default_value' => intval(variable_get('preprocess_css', 0) && $is_writable),\n '#disabled' => $disabled,\n );\n $form['bandwidth_optimization']['preprocess_js'] = array(\n '#type' => 'checkbox',\n '#title' => t('Aggregate JavaScript files.'),\n '#default_value' => intval(variable_get('preprocess_js', 0) && $is_writable),\n '#disabled' => $disabled,\n );\n\n $form['#submit'][] = 'drupal_clear_css_cache';\n $form['#submit'][] = 'drupal_clear_js_cache';\n // This form allows page compression settings to be changed, which can\n // invalidate the page cache, so it needs to be cleared on form submit.\n $form['#submit'][] = 'system_clear_page_cache_submit';\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3257dcb54e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_install/7.x", "instruction": "I need the code for `system_install()` in Drupal 7 (modules/system/system.install). It must do this: Implements hook_install().", "context": "File: modules/system/system.install", "response": "function system_install() {\n // Create tables.\n drupal_install_schema('system');\n $versions = drupal_get_schema_versions('system');\n $version = $versions ? max($versions) : SCHEMA_INSTALLED;\n drupal_set_installed_schema_version('system', $version);\n\n // Clear out module list and hook implementation statics before calling\n // system_rebuild_theme_data().\n module_list(TRUE);\n module_implements('', FALSE, TRUE);\n\n // Ensure the schema versions are not based on a previous module list.\n drupal_static_reset('drupal_get_schema_versions');\n\n // Load system theme data appropriately.\n system_rebuild_theme_data();\n\n // Enable the default theme.\n variable_set('theme_default', 'bartik');\n db_update('system')\n ->fields(array('status' => 1))\n ->condition('type', 'theme')\n ->condition('name', 'bartik')\n ->execute();\n\n // Populate the cron key variable.\n $cron_key = drupal_random_key();\n variable_set('cron_key', $cron_key);\n\n // This variable indicates that the database is ready for hashed session ids.\n variable_set('hashed_session_ids_supported', TRUE);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-325b1dfbe4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_help/7.x", "instruction": "I need the code for `translation_help($path, $arg)` in Drupal 7 (modules/translation/translation.module). It must do this: Implements hook_help().", "context": "File: modules/translation/translation.module", "response": "function translation_help($path, $arg) {\n switch ($path) {\n case 'admin/help#translation':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Content translation module allows content to be translated into different languages. Working with the Locale module (which manages enabled languages and provides translation for the site interface), the Content translation module is key to creating and maintaining translated site content. For more information, see the online handbook entry for Content translation module.', array('@locale' => url('admin/help/locale'), '@translation' => 'http://drupal.org/documentation/modules/translation/')) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Configuring content types for translation') . '
            ';\n $output .= '
            ' . t('To configure a particular content type for translation, visit the Content types page, and click the edit link for the content type. In the Publishing options section, select Enabled, with translation under Multilingual support.', array('@content-types' => url('admin/structure/types'))) . '
            ';\n $output .= '
            ' . t('Assigning a language to content') . '
            ';\n $output .= '
            ' . t('Use the Language drop down to select the appropriate language when creating or editing content.') . '
            ';\n $output .= '
            ' . t('Translating content') . '
            ';\n $output .= '
            ' . t('Users with the translate content permission can translate content, if the content type has been configured to allow translations. To translate content, select the Translation tab when viewing the content, select the language for which you wish to provide content, and then enter the content.') . '
            ';\n $output .= '
            ' . t('Maintaining translations') . '
            ';\n $output .= '
            ' . t('If editing content in one language requires that translated versions also be updated to reflect the change, use the Flag translations as outdated check box to mark the translations as outdated and in need of revision. Individual translations may also be marked for revision by selecting the This translation needs to be updated check box on the translation editing form.') . '
            ';\n $output .= '
            ';\n return $output;\n case 'node/%/translate':\n $output = '

            ' . t('Translations of a piece of content are managed with translation sets. Each translation set has one source post and any number of translations in any of the enabled languages. All translations are tracked to be up to date or outdated based on whether the source post was modified significantly.', array('!languages' => url('admin/config/regional/language'))) . '

            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-327f4fdc71", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/theme_image_style_list/7.x", "instruction": "Implement `theme_image_style_list($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the page containing the list of image styles.", "context": "Parameters:\n- $variables: An associative array containing: - styles: An array of all the image styles returned by image_get_styles().\n\nFile: modules/image/image.admin.inc", "response": "function theme_image_style_list($variables) {\n $styles = $variables['styles'];\n\n $header = array(t('Style name'), t('Settings'), array('data' => t('Operations'), 'colspan' => 3));\n $rows = array();\n foreach ($styles as $style) {\n $row = array();\n $row[] = l($style['label'], 'admin/config/media/image-styles/edit/' . $style['name']);\n $link_attributes = array(\n 'attributes' => array(\n 'class' => array('image-style-link'),\n ),\n );\n if ($style['storage'] == IMAGE_STORAGE_NORMAL) {\n $row[] = t('Custom');\n $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes);\n $row[] = l(t('delete'), 'admin/config/media/image-styles/delete/' . $style['name'], $link_attributes);\n }\n elseif ($style['storage'] == IMAGE_STORAGE_OVERRIDE) {\n $row[] = t('Overridden');\n $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes);\n $row[] = l(t('revert'), 'admin/config/media/image-styles/revert/' . $style['name'], $link_attributes);\n }\n else {\n $row[] = t('Default');\n $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes);\n $row[] = '';\n }\n $rows[] = $row;\n }\n\n if (empty($rows)) {\n $rows[] = array(array(\n 'colspan' => 4,\n 'data' => t('There are currently no styles. Add a new one.', array('!url' => url('admin/config/media/image-styles/add'))),\n ));\n }\n\n return theme('table', array('header' => $header, 'rows' => $rows));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-329f200edf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/xmlrpc/7.x", "instruction": "In Drupal 7, write the function `xmlrpc($url, $args, $options = array())` (file includes/common.inc) so that it does the following: Performs one or more XML-RPC request(s).", "context": "Usage example:\n\nParameters:\n- $url: An absolute URL of the XML-RPC endpoint.\n- $args: An associative array whose keys are the methods to call and whose values are the arguments to pass to the respective method. If multiple methods are specified, a system.multicall is performed.\n- $options: (optional) An array of options to pass along to drupal_http_request().\n\nReturns: For one request: Either the return value of the method on success, or FALSE. If FALSE is returned, see xmlrpc_errno() and xmlrpc_error_msg(). For multiple requests: An array of results. Each result will either be the result returned by the method called, or an xmlrpc_error object if the call failed. See xmlrpc_error().\n\nFile: includes/common.inc", "response": "function xmlrpc($url, $args, $options = array()) {\n require_once DRUPAL_ROOT . '/includes/xmlrpc.inc';\n return _xmlrpc($url, $args, $options);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32b22fb611", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_display_empty_page/7.x", "instruction": "Implement `overlay_display_empty_page($value = NULL)` in PHP for Drupal 7. Required behavior: Stores and returns whether an empty page override is needed.", "context": "This is used to prevent a page request which closes the overlay (for example, a form submission) from being fully re-rendered before the overlay is closed. Instead, we store a variable which will cause the page to be rendered by a delivery callback function that does not actually print visible HTML (but rather only the bare minimum scripts and styles necessary to trigger the overlay to close), thereby allowing the dialog to be closed faster and with less interruption, and also allowing the display of messages to be deferred to the parent window (rather than displaying them in the child window, which will close before the user has had a chance to read them).\n\nParameters:\n- $value: By default, an empty page will not be displayed. Set to TRUE to request an empty page display, or FALSE to disable the empty page display (if it was previously enabled on this page request).\n\nReturns: TRUE if the current behavior is to display an empty page, or FALSE if not.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_display_empty_page($value = NULL) {\n $display_empty_page = &drupal_static(__FUNCTION__, FALSE);\n if (isset($value)) {\n $display_empty_page = $value;\n }\n return $display_empty_page;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32b25e4f52", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_effect_delete_form_submit/7.x", "instruction": "I need the code for `image_effect_delete_form_submit($form, &$form_state)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Submit handler to delete an image effect.", "context": "File: modules/image/image.admin.inc", "response": "function image_effect_delete_form_submit($form, &$form_state) {\n $style = $form_state['image_style'];\n $effect = $form_state['image_effect'];\n\n image_effect_delete($effect);\n drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $effect['label'])));\n $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32c7dc1b6d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/theme_taxonomy_overview_terms/7.x", "instruction": "Implement `theme_taxonomy_overview_terms($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a terms overview form as a sortable list of terms.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/taxonomy/taxonomy.admin.inc", "response": "function theme_taxonomy_overview_terms($variables) {\n $form = $variables['form'];\n\n $page_increment = $form['#page_increment'];\n $page_entries = $form['#page_entries'];\n $back_step = $form['#back_step'];\n $forward_step = $form['#forward_step'];\n\n // Add drag and drop if parent fields are present in the form.\n if ($form['#parent_fields']) {\n drupal_add_tabledrag('taxonomy', 'match', 'parent', 'term-parent', 'term-parent', 'term-id', FALSE);\n drupal_add_tabledrag('taxonomy', 'depth', 'group', 'term-depth', NULL, NULL, FALSE);\n drupal_add_js(drupal_get_path('module', 'taxonomy') . '/taxonomy.js');\n drupal_add_js(array('taxonomy' => array('backStep' => $back_step, 'forwardStep' => $forward_step)), 'setting');\n drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');\n }\n drupal_add_tabledrag('taxonomy', 'order', 'sibling', 'term-weight');\n\n $errors = form_get_errors() != FALSE ? form_get_errors() : array();\n $rows = array();\n foreach (element_children($form) as $key) {\n if (isset($form[$key]['#term'])) {\n $term = &$form[$key];\n\n $row = array();\n $row[] = (isset($term['#term']['depth']) && $term['#term']['depth'] > 0 ? theme('indentation', array('size' => $term['#term']['depth'])) : ''). drupal_render($term['view']);\n if ($form['#parent_fields']) {\n $term['tid']['#attributes']['class'] = array('term-id');\n $term['parent']['#attributes']['class'] = array('term-parent');\n $term['depth']['#attributes']['class'] = array('term-depth');\n $row[0] .= drupal_render($term['parent']) . drupal_render($term['tid']) . drupal_render($term['depth']);\n }\n $term['weight']['#attributes']['class'] = array('term-weight');\n $row[] = drupal_render($term['weight']);\n $row[] = drupal_render($term['edit']);\n $row = array('data' => $row);\n $rows[$key] = $row;\n }\n }\n\n // Add necessary classes to rows.\n $row_position = 0;\n foreach ($rows as $key => $row) {\n $rows[$key]['class'] = array();\n if (isset($form['#parent_fields'])) {\n $rows[$key]['class'][] = 'draggable';\n }\n\n // Add classes that mark which terms belong to previous and next pages.\n if ($row_position < $back_step || $row_position >= $page_entries - $forward_step) {\n $rows[$key]['class'][] = 'taxonomy-term-preview';\n }\n\n if ($row_position !== 0 && $row_position !== count($rows) - 1) {\n if ($row_position == $back_step - 1 || $row_position == $page_entries - $forward_step - 1) {\n $rows[$key]['class'][] = 'taxonomy-term-divider-top';\n }\n elseif ($row_position == $back_step || $row_position == $page_entries - $forward_step) {\n $rows[$key]['class'][] = 'taxonomy-term-divider-bottom';\n }\n }\n\n // Add an error class if this row contains a form error.\n foreach ($errors as $error_key => $error) {\n if (strpos($error_key, $key) === 0) {\n $rows[$key]['class'][] = 'error';\n }\n }\n $row_position++;\n }\n\n if (empty($rows)) {\n $rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '3'));\n }\n\n $header = array(t('Name'), t('Weight'), t('Operations'));\n $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'taxonomy')));\n $output .= drupal_render_children($form);\n $output .= theme('pager');\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32cf682ffc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7029/7.x", "instruction": "In Drupal 7, write the function `system_update_7029()` (file modules/system/system.install) so that it does the following: Add new 'view own unpublished content' permission for authenticated users. Preserves legacy behavior from Drupal 6.x.", "context": "File: modules/system/system.install", "response": "function system_update_7029() {\n db_insert('role_permission')\n ->fields(array(\n 'rid' => DRUPAL_AUTHENTICATED_RID,\n 'permission' => 'view own unpublished content',\n ))\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32d61c4c27", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7016/7.x", "instruction": "In Drupal 7, write the function `node_update_7016()` (file modules/node/node.install) so that it does the following: Change {history}.nid to an unsigned int in order to match {node}.nid.", "context": "File: modules/node/node.install", "response": "function node_update_7016() {\n db_drop_primary_key('history');\n db_drop_index('history', 'nid');\n db_change_field('history', 'nid', 'nid', array(\n 'description' => 'The {node}.nid that was read.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ));\n db_add_primary_key('history', array('uid', 'nid'));\n db_add_index('history', 'nid', array('nid'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32f08f4134", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/theme_user_admin_permissions/7.x", "instruction": "In Drupal 7, write the function `theme_user_admin_permissions($variables)` (file modules/user/user.admin.inc) so that it does the following: Returns HTML for the administer permissions page.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/user/user.admin.inc", "response": "function theme_user_admin_permissions($variables) {\n $form = $variables['form'];\n\n $roles = user_roles();\n foreach (element_children($form['permission']) as $key) {\n $row = array();\n // Module name\n if (is_numeric($key)) {\n $row[] = array('data' => drupal_render($form['permission'][$key]), 'class' => array('module'), 'id' => 'module-' . $form['permission'][$key]['#id'], 'colspan' => count($form['role_names']['#value']) + 1);\n }\n else {\n // Permission row.\n $row[] = array(\n 'data' => drupal_render($form['permission'][$key]),\n 'class' => array('permission'),\n );\n foreach (element_children($form['checkboxes']) as $rid) {\n $form['checkboxes'][$rid][$key]['#title'] = $roles[$rid] . ': ' . $form['permission'][$key]['#markup'];\n $form['checkboxes'][$rid][$key]['#title_display'] = 'invisible';\n $row[] = array('data' => drupal_render($form['checkboxes'][$rid][$key]), 'class' => array('checkbox'));\n }\n }\n $rows[] = $row;\n }\n $header[] = (t('Permission'));\n foreach (element_children($form['role_names']) as $rid) {\n $header[] = array('data' => drupal_render($form['role_names'][$rid]), 'class' => array('checkbox'));\n }\n $output = theme('system_compact_link');\n $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions')));\n $output .= drupal_render_children($form);\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32f563ede5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_render_images/7.x", "instruction": "Implement `_color_render_images($theme, &$info, &$paths, $palette)` in PHP for Drupal 7. Required behavior: Renders images that match a given palette.", "context": "File: modules/color/color.module", "response": "function _color_render_images($theme, &$info, &$paths, $palette) {\n // Prepare template image.\n $source = $paths['source'] . '/' . $info['base_image'];\n $source = imagecreatefrompng($source);\n $width = imagesx($source);\n $height = imagesy($source);\n\n // Prepare target buffer.\n $target = imagecreatetruecolor($width, $height);\n imagealphablending($target, TRUE);\n\n // Fill regions of solid color.\n foreach ($info['fill'] as $color => $fill) {\n imagefilledrectangle($target, $fill[0], $fill[1], $fill[0] + $fill[2], $fill[1] + $fill[3], _color_gd($target, $palette[$color]));\n }\n\n // Render gradients.\n foreach ($info['gradients'] as $gradient) {\n // Get direction of the gradient.\n if (isset($gradient['direction']) && $gradient['direction'] == 'horizontal') {\n // Horizontal gradient.\n for ($x = 0; $x < $gradient['dimension'][2]; $x++) {\n $color = _color_blend($target, $palette[$gradient['colors'][0]], $palette[$gradient['colors'][1]], $x / ($gradient['dimension'][2] - 1));\n imagefilledrectangle($target, ($gradient['dimension'][0] + $x), $gradient['dimension'][1], ($gradient['dimension'][0] + $x + 1), ($gradient['dimension'][1] + $gradient['dimension'][3]), $color);\n }\n }\n else {\n // Vertical gradient.\n for ($y = 0; $y < $gradient['dimension'][3]; $y++) {\n $color = _color_blend($target, $palette[$gradient['colors'][0]], $palette[$gradient['colors'][1]], $y / ($gradient['dimension'][3] - 1));\n imagefilledrectangle($target, $gradient['dimension'][0], $gradient['dimension'][1] + $y, $gradient['dimension'][0] + $gradient['dimension'][2], $gradient['dimension'][1] + $y + 1, $color);\n }\n }\n }\n\n // Blend over template.\n imagecopy($target, $source, 0, 0, 0, 0, $width, $height);\n\n // Clean up template image.\n imagedestroy($source);\n\n // Cut out slices.\n foreach ($info['slices'] as $file => $coord) {\n list($x, $y, $width, $height) = $coord;\n $base = drupal_basename($file);\n $image = drupal_realpath($paths['target'] . $base);\n\n // Cut out slice.\n if ($file == 'screenshot.png') {\n $slice = imagecreatetruecolor(150, 90);\n imagecopyresampled($slice, $target, 0, 0, $x, $y, 150, 90, $width, $height);\n variable_set('color_' . $theme . '_screenshot', $image);\n }\n else {\n $slice = imagecreatetruecolor($width, $height);\n imagecopy($slice, $target, 0, 0, $x, $y, $width, $height);\n }\n\n // Save image.\n imagepng($slice, $image);\n imagedestroy($slice);\n $paths['files'][] = $image;\n\n // Set standard file permissions for webserver-generated files\n drupal_chmod($image);\n\n // Build before/after map of image paths.\n $paths['map'][$file] = $base;\n }\n\n // Clean up target buffer.\n imagedestroy($target);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-32fbce0d90", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7033/7.x", "instruction": "Implement `system_update_7033()` in PHP for Drupal 7. Required behavior: Move CACHE_AGGRESSIVE to CACHE_NORMAL.", "context": "File: modules/system/system.install", "response": "function system_update_7033() {\n if (variable_get('cache') == 2) {\n variable_set('cache', 1);\n return t('Aggressive caching was disabled and replaced with normal caching. Read the page caching section in default.settings.php for more information on how to enable similar functionality.');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3334fff1d5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_uri/7.x", "instruction": "I need the code for `taxonomy_term_uri($term)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements callback_entity_info_uri().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_term_uri($term) {\n return array(\n 'path' => 'taxonomy/term/' . $term->tid,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3340c458da", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7046/7.x", "instruction": "In Drupal 7, write the function `system_update_7046()` (file modules/system/system.install) so that it does the following: Switch from the Minnelli theme if it is the default or admin theme.", "context": "File: modules/system/system.install", "response": "function system_update_7046() {\n if (variable_get('theme_default') == 'minnelli' || variable_get('admin_theme') == 'minnelli') {\n // Make sure Garland is enabled.\n db_update('system')\n ->fields(array('status' => 1))\n ->condition('type', 'theme')\n ->condition('name', 'garland')\n ->execute();\n if (variable_get('theme_default') != 'garland') {\n // If the default theme isn't Garland, transfer all of Minnelli's old\n // settings to Garland.\n $settings = variable_get('theme_minnelli_settings', array());\n // Set the theme setting width to \"fixed\" to match Minnelli's old layout.\n $settings['garland_width'] = 'fixed';\n variable_set('theme_garland_settings', $settings);\n // Remove Garland's color files since they won't match Minnelli's.\n foreach (variable_get('color_garland_files', array()) as $file) {\n @drupal_unlink($file);\n }\n if (isset($file) && $file = dirname($file)) {\n @drupal_rmdir($file);\n }\n variable_del('color_garland_palette');\n variable_del('color_garland_stylesheets');\n variable_del('color_garland_logo');\n variable_del('color_garland_files');\n variable_del('color_garland_screenshot');\n }\n if (variable_get('theme_default') == 'minnelli') {\n variable_set('theme_default', 'garland');\n }\n if (variable_get('admin_theme') == 'minnelli') {\n variable_set('admin_theme', 'garland');\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-33582f6060", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/template_preprocess_aggregator_summary_item/7.x", "instruction": "Implement `template_preprocess_aggregator_summary_item(&$variables)` in PHP for Drupal 7. Required behavior: Processes variables for aggregator-summary-item.tpl.php.", "context": "File: modules/aggregator/aggregator.pages.inc", "response": "function template_preprocess_aggregator_summary_item(&$variables) {\n $item = $variables['item'];\n\n $variables['feed_url'] = check_url($item->link);\n $variables['feed_title'] = check_plain($item->title);\n $variables['feed_age'] = t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->timestamp)));\n\n $variables['source_url'] = '';\n $variables['source_title'] = '';\n if (!empty($item->feed_link)) {\n $variables['source_url'] = check_url($item->feed_link);\n $variables['source_title'] = check_plain($item->feed_title);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-33763d302e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_get_unique_name/7.x", "instruction": "Implement `shortcut_set_get_unique_name()` in PHP for Drupal 7. Required behavior: Returns a unique, machine-readable shortcut set name.", "context": "File: modules/shortcut/shortcut.module", "response": "function shortcut_set_get_unique_name() {\n // Shortcut sets are numbered sequentially, so we keep trying until we find\n // one that is available. For better performance, we start with a number\n // equal to one more than the current number of shortcut sets, so that if\n // no shortcut sets have been deleted from the database, this will\n // automatically give us the correct one.\n $number = db_query(\"SELECT COUNT(*) FROM {shortcut_set}\")->fetchField() + 1;\n do {\n $name = shortcut_set_name($number);\n $number++;\n } while ($shortcut_set = shortcut_set_load($name));\n return $name;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-337ca98488", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_default_format/7.x", "instruction": "Implement `filter_default_format($account = NULL)` in PHP for Drupal 7. Required behavior: Returns the ID of the default text format for a particular user.", "context": "The default text format is the first available format that the user is allowed to access, when the formats are ordered by weight. It should generally be used as a default choice when presenting the user with a list of possible text formats (for example, in a node creation form).\n\nConversely, when existing content that does not have an assigned text format needs to be filtered for display, the default text format is the wrong choice, because it is not guaranteed to be consistent from user to user, and some trusted users may have an unsafe text format set by default, which should not be used on text of unknown origin. Instead, the fallback format returned by filter_fallback_format() should be used, since that is intended to be a safe, consistent format that is always available to all users.\n\nParameters:\n- $account: (optional) The user account to check. Defaults to the currently logged-in user. Defaults to NULL.\n\nReturns: The ID of the user's default text format.\n\nFile: modules/filter/filter.module", "response": "function filter_default_format($account = NULL) {\n global $user;\n if (!isset($account)) {\n $account = $user;\n }\n // Get a list of formats for this user, ordered by weight. The first one\n // available is the user's default format.\n $formats = filter_formats($account);\n $format = reset($formats);\n return $format->format;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-337d6275df", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_form_add_validate/7.x", "instruction": "I need the code for `image_style_form_add_validate($form, &$form_state)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Validate handler for adding a new image effect to an image style.", "context": "File: modules/image/image.admin.inc", "response": "function image_style_form_add_validate($form, &$form_state) {\n if (!$form_state['values']['new']) {\n form_error($form['effects']['new']['new'], t('Select an effect to add.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-33aded1ed5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_check_incompatibility/7.x", "instruction": "Implement `drupal_check_incompatibility($v, $current_version)` in PHP for Drupal 7. Required behavior: Checks whether a version is compatible with a given dependency.", "context": "Parameters:\n- $v: The parsed dependency structure from drupal_parse_dependency().\n- $current_version: The version to check against (like 4.2).\n\nReturns (NULL): if compatible, otherwise the original dependency version string that caused the incompatibility.\n\nFile: includes/common.inc", "response": "function drupal_check_incompatibility($v, $current_version) {\n if (!empty($v['versions'])) {\n foreach ($v['versions'] as $required_version) {\n if ((isset($required_version['op']) && !version_compare($current_version, $required_version['version'], $required_version['op']))) {\n return $v['original_version'];\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-33db6d6ce7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_page_edit/7.x", "instruction": "Implement `node_page_edit($node)` in PHP for Drupal 7. Required behavior: Menu callback; presents the node editing form.", "context": "File: modules/node/node.pages.inc", "response": "function node_page_edit($node) {\n $type_name = node_type_get_name($node);\n drupal_set_title(t('Edit @type @title', array('@type' => $type_name, '@title' => $node->title)), PASS_THROUGH);\n return drupal_get_form($node->type . '_node_form', $node);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-33e0691241", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_delete_revision/7.x", "instruction": "Give me the example code for `hook_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items)` in Drupal 7. Hook description: Define custom revision delete behavior for this module's field types.", "context": "This hook is invoked just before the data is deleted from field storage in field_attach_delete_revision(), and will only be called for fieldable types that are versioned.\n\nParameters:\n- $entity_type: The type of $entity.\n- $entity: The entity for the operation.\n- $field: The field structure for the operation.\n- $instance: The instance structure for $field on $entity's bundle.\n- $langcode: The language associated with $items.\n- $entity ($items): ->{$field['field_name']}[$langcode], or an empty array if unset.\n\nFile: modules/field/field.api.php", "response": "function hook_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n foreach ($items as $delta => $item) {\n // For hook_file_references, remember that this file is being deleted.\n $item['file_field_name'] = $field['field_name'];\n if (file_field_delete_file($item, $field, $entity_type, $id)) {\n $items[$delta] = NULL;\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-340adb69a1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.admin.inc/function/statistics_settings_form/7.x", "instruction": "Implement `statistics_settings_form()` in PHP for Drupal 7. Required behavior: Form constructor for the statistics administration form.", "context": "File: modules/statistics/statistics.admin.inc", "response": "function statistics_settings_form() {\n // Access log settings.\n $form['access'] = array(\n '#type' => 'fieldset',\n '#title' => t('Access log settings'),\n );\n $form['access']['statistics_enable_access_log'] = array(\n '#type' => 'checkbox',\n '#title' => t('Enable access log'),\n '#default_value' => variable_get('statistics_enable_access_log', 0),\n '#description' => t('Log each page access. Required for referrer statistics.'),\n );\n $form['access']['statistics_flush_accesslog_timer'] = array(\n '#type' => 'select',\n '#title' => t('Discard access logs older than'),\n '#default_value' => variable_get('statistics_flush_accesslog_timer', 259200),\n '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'),\n '#description' => t('Older access log entries (including referrer statistics) will be automatically discarded. (Requires a correctly configured cron maintenance task.)', array('@cron' => url('admin/reports/status'))),\n );\n\n // Content counter settings.\n $form['content'] = array(\n '#type' => 'fieldset',\n '#title' => t('Content viewing counter settings'),\n );\n $form['content']['statistics_count_content_views'] = array(\n '#type' => 'checkbox',\n '#title' => t('Count content views'),\n '#default_value' => variable_get('statistics_count_content_views', 0),\n '#description' => t('Increment a counter each time content is viewed.'),\n );\n $form['content']['statistics_count_content_views_ajax'] = array(\n '#type' => 'checkbox',\n '#title' => t('Use Ajax to increment the counter'),\n '#default_value' => variable_get('statistics_count_content_views_ajax', 0),\n '#description' => t('Perform the count asynchronously after page load rather than during page generation.'),\n '#states' => array(\n 'disabled' => array(\n ':input[name=\"statistics_count_content_views\"]' => array('checked' => FALSE),\n ),\n ),\n );\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3428a7ba8e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21language.inc/function/language_types_disable/7.x", "instruction": "Implement `language_types_disable($types)` in PHP for Drupal 7. Required behavior: Disables the given language types.", "context": "Parameters:\n- $types: An array of language types.\n\nFile: includes/language.inc", "response": "function language_types_disable($types) {\n $enabled_types = variable_get('language_types', drupal_language_types());\n\n foreach ($types as $type) {\n unset($enabled_types[$type]);\n }\n\n variable_set('language_types', $enabled_types);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-343090b6b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_html_alter/7.x", "instruction": "In Drupal 7, write the function `_color_html_alter(&$vars)` (file modules/color/color.module) so that it does the following: Replaces style sheets with color-altered style sheets.", "context": "A theme that supports the color module should call this function from its THEME_process_html() function, so that the correct style sheets are included when html.tpl.php is rendered.\n\nFile: modules/color/color.module", "response": "function _color_html_alter(&$vars) {\n global $theme_key;\n $themes = list_themes();\n\n // Override stylesheets.\n $color_paths = variable_get('color_' . $theme_key . '_stylesheets', array());\n if (!empty($color_paths)) {\n\n foreach ($themes[$theme_key]->stylesheets['all'] as $base_filename => $old_path) {\n // Loop over the path array with recolored CSS files to find matching\n // paths which could replace the non-recolored paths.\n foreach ($color_paths as $color_path) {\n // Color module currently requires unique file names to be used,\n // which allows us to compare different file paths.\n if (drupal_basename($old_path) == drupal_basename($color_path)) {\n // Replace the path to the new css file.\n // This keeps the order of the stylesheets intact.\n $vars['css'][$old_path]['data'] = $color_path;\n }\n }\n }\n\n $vars['styles'] = drupal_get_css($vars['css']);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-34418306f4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_details_alter/7.x", "instruction": "Give me the example code for `hook_field_storage_details_alter(&$details, $field)` in Drupal 7. Hook description: Perform alterations on Field API storage details.", "context": "Parameters:\n- $details: An array of storage details for fields as exposed by hook_field_storage_details() implementations.\n- $field: A field structure.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_details_alter(&$details, $field) {\n if ($field['field_name'] == 'field_of_interest') {\n $columns = array();\n foreach ((array) $field['columns'] as $column_name => $attributes) {\n $columns[$column_name] = $column_name;\n }\n $details['drupal_variables'] = array(\n FIELD_LOAD_CURRENT => array(\n 'moon' => $columns,\n ),\n FIELD_LOAD_REVISION => array(\n 'mars' => $columns,\n ),\n );\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-34584a6570", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7074/7.x", "instruction": "In Drupal 7, write the function `system_update_7074()` (file modules/system/system.install) so that it does the following: This update has been removed and will not run.", "context": "File: modules/system/system.install", "response": "function system_update_7074() {\n // This update function previously converted menu_links query strings to\n // arrays. It has been removed for now due to incompatibility with\n // PostgreSQL.\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-345864543e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_region_descriptions/7.x", "instruction": "Implement `dashboard_region_descriptions()` in PHP for Drupal 7. Required behavior: Returns an array of dashboard region descriptions, keyed by region name.", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_region_descriptions() {\n $regions = module_invoke_all('dashboard_regions');\n drupal_alter('dashboard_regions', $regions);\n return $regions;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-345ca3e43d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_search_status/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_search_status()` (modules/search/search.api.php): Report the status of indexing.", "context": "The core search module only invokes this hook on active modules. Implementing modules do not need to check whether they are active when calculating their return values.\n\nReturns: An associative array with the key-value pairs: - 'remaining': The number of items left to index. - 'total': The total number of items to index.\n\nFile: modules/search/search.api.php", "response": "function hook_search_status() {\n $total = db_query('SELECT COUNT(*) FROM {node} WHERE status = 1')->fetchField();\n $remaining = db_query(\"SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND d.sid IS NULL OR d.reindex <> 0\")->fetchField();\n return array('remaining' => $remaining, 'total' => $total);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-34729659cd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_user_categories/7.x", "instruction": "Implement `user_user_categories()` in PHP for Drupal 7. Required behavior: Implements hook_user_categories().", "context": "File: modules/user/user.module", "response": "function user_user_categories() {\n return array(array(\n 'name' => 'account',\n 'title' => t('Account settings'),\n 'weight' => 1,\n ));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-347ecb19bc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_admin_display_prepare_blocks/7.x", "instruction": "In Drupal 7, write the function `block_admin_display_prepare_blocks($theme)` (file modules/block/block.admin.inc) so that it does the following: Prepares a list of blocks for display on the blocks administration page.", "context": "Parameters:\n- $theme: The machine-readable name of the theme whose blocks should be returned.\n\nReturns: An array of blocks, as returned by _block_rehash(), sorted by region in preparation for display on the blocks administration page.\n\nFile: modules/block/block.admin.inc", "response": "function block_admin_display_prepare_blocks($theme) {\n $blocks = _block_rehash($theme);\n $compare_theme = &drupal_static('_block_compare:theme');\n $compare_theme = $theme;\n usort($blocks, '_block_compare');\n return $blocks;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3480a6fd91", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_add_block_form_validate/7.x", "instruction": "I need the code for `block_add_block_form_validate($form, &$form_state)` in Drupal 7 (modules/block/block.admin.inc). It must do this: Form validation handler for block_add_block_form().", "context": "File: modules/block/block.admin.inc", "response": "function block_add_block_form_validate($form, &$form_state) {\n $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', 0, 1, array(':info' => $form_state['values']['info']))->fetchField();\n\n if (empty($form_state['values']['info']) || $custom_block_exists) {\n form_set_error('info', t('Ensure that each block description is unique.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3490914f35", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.install/function/_update_7000_field_create_instance/7.x", "instruction": "I need the code for `_update_7000_field_create_instance($field, &$instance)` in Drupal 7 (modules/field/field.install). It must do this: Utility function: write a field instance directly to the database.", "context": "This function can be used for databases whose schema is at field module version 7000 or higher.\n\nFile: modules/field/field.install", "response": "function _update_7000_field_create_instance($field, &$instance) {\n // Merge in defaults.\n $instance += array(\n 'field_id' => $field['id'],\n 'field_name' => $field['field_name'],\n 'deleted' => 0,\n );\n\n // The serialized 'data' column contains everything from $instance that does\n // not have its own column and is not automatically populated when the\n // instance is read.\n $data = $instance;\n unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']);\n\n $record = array(\n 'field_id' => $instance['field_id'],\n 'field_name' => $instance['field_name'],\n 'entity_type' => $instance['entity_type'],\n 'bundle' => $instance['bundle'],\n 'data' => serialize($data),\n 'deleted' => (int) $instance['deleted'],\n );\n $instance['id'] = db_insert('field_config_instance')\n ->fields($record)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-34b016a6f9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_message_set/7.x", "instruction": "Implement `xmlrpc_message_set($value = NULL)` in PHP for Drupal 7. Required behavior: Stores a copy of the most recent XML-RPC message object temporarily.", "context": "Parameters:\n- $value: An XML-RPC message to store, or NULL to keep the last message.\n\nReturns (object): The most recently stored message.\n\nFile: includes/xmlrpc.inc", "response": "function xmlrpc_message_set($value = NULL) {\n static $xmlrpc_message;\n if ($value) {\n $xmlrpc_message = $value;\n }\n return $xmlrpc_message;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-34b4e28368", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/theme_text_format_wrapper/7.x", "instruction": "I need the code for `theme_text_format_wrapper($variables)` in Drupal 7 (modules/filter/filter.module). It must do this: Returns HTML for a text format-enabled form element.", "context": "Parameters:\n- $variables: An associative array containing: - element: A render element containing #children and #description.\n\nFile: modules/filter/filter.module", "response": "function theme_text_format_wrapper($variables) {\n $element = $variables['element'];\n $output = '
            ';\n $output .= $element['#children'];\n if (!empty($element['#description'])) {\n $output .= '
            ' . $element['#description'] . '
            ';\n }\n $output .= \"
            \\n\";\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-34baca6de6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/theme_image_formatter/7.x", "instruction": "In Drupal 7, write the function `theme_image_formatter($variables)` (file modules/image/image.field.inc) so that it does the following: Returns HTML for an image field formatter.", "context": "Parameters:\n- $variables: An associative array containing: - item: Associative array of image data, which may include \"uri\", \"alt\", \"width\", \"height\", \"title\" and \"attributes\". - image_style: An optional image style. - path: An array containing the link 'path' and link 'options'.\n\nFile: modules/image/image.field.inc", "response": "function theme_image_formatter($variables) {\n $item = $variables['item'];\n $image = array(\n 'path' => $item['uri'],\n );\n\n if (array_key_exists('alt', $item)) {\n $image['alt'] = $item['alt'];\n }\n\n if (isset($item['attributes'])) {\n $image['attributes'] = $item['attributes'];\n }\n\n if (isset($item['width']) && isset($item['height'])) {\n $image['width'] = $item['width'];\n $image['height'] = $item['height'];\n }\n\n // Do not output an empty 'title' attribute.\n if (isset($item['title']) && drupal_strlen($item['title']) > 0) {\n $image['title'] = $item['title'];\n }\n\n if ($variables['image_style']) {\n $image['style_name'] = $variables['image_style'];\n $output = theme('image_style', $image);\n }\n else {\n $output = theme('image', $image);\n }\n\n // The link path and link options are both optional, but for the options to be\n // processed, the link path must at least be an empty string.\n if (isset($variables['path']['path'])) {\n $path = $variables['path']['path'];\n $options = isset($variables['path']['options']) ? $variables['path']['options'] : array();\n // When displaying an image inside a link, the html option must be TRUE.\n $options['html'] = TRUE;\n $output = l($output, $path, $options);\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-34bbe5f3b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_access/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_node_access($node, $op, $account)` (modules/node/node.api.php): Control access to a node.", "context": "Modules may implement this hook if they want to have a say in whether or not a given user has access to perform a given operation on a node.\n\nThe administrative account (user ID #1) always passes any access check, so this hook is not called in that case. Users with the \"bypass node access\" permission may always view and edit content through the administrative interface.\n\nNote that not all modules will want to influence access on all node types. If your module does not want to actively grant or block access, return NODE_ACCESS_IGNORE or simply return nothing. Blindly returning FALSE will break other node access modules.\n\nAlso note that this function isn't called for node listings (e.g., RSS feeds, the default home page at path 'node', a recent content block, etc.) See\n\nParameters:\n- $node: Either a node object or the machine name of the content type on which to perform the access check.\n- $op: The operation to be performed. Possible values: - \"create\" - \"delete\" - \"update\" - \"view\"\n- $account: The user object to perform the access check operation on.\n\nReturns: - NODE_ACCESS_ALLOW: if the operation is to be allowed. - NODE_ACCESS_DENY: if the operation is to be denied. - NODE_ACCESS_IGNORE: to not affect this operation at all.\n\nFile: modules/node/node.api.php", "response": "function hook_node_access($node, $op, $account) {\n $type = is_string($node) ? $node : $node->type;\n\n if (in_array($type, node_permissions_get_configured_types())) {\n if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {\n return NODE_ACCESS_ALLOW;\n }\n\n if ($op == 'update') {\n if (user_access('edit any ' . $type . ' content', $account) || (user_access('edit own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {\n return NODE_ACCESS_ALLOW;\n }\n }\n\n if ($op == 'delete') {\n if (user_access('delete any ' . $type . ' content', $account) || (user_access('delete own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {\n return NODE_ACCESS_ALLOW;\n }\n }\n }\n\n // Returning nothing from this function would have the same effect.\n return NODE_ACCESS_IGNORE;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-34c75669e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_presave/7.x", "instruction": "In Drupal 7, write the function `profile_user_presave(&$edit, $account, $category)` (file modules/profile/profile.module) so that it does the following: Implements hook_user_presave().", "context": "File: modules/profile/profile.module", "response": "function profile_user_presave(&$edit, $account, $category) {\n if (!empty($account->uid)) {\n profile_save_profile($edit, $account, $category);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-34dd370419", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.api.php/function/hook_path_delete/7.x", "instruction": "Give me the example code for `hook_path_delete($path)` in Drupal 7. Hook description: Respond to a path being deleted.", "context": "Parameters:\n- $path: An associative array containing the following keys: - source: The internal system path. - alias: The URL alias. - pid: Unique path alias identifier. - language: The language of the alias.\n\nFile: modules/path/path.api.php", "response": "function hook_path_delete($path) {\n db_delete('mytable')\n ->condition('pid', $path['pid'])\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-34e33e7d77", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_preferred_language/7.x", "instruction": "In Drupal 7, write the function `user_preferred_language($account, $default = NULL)` (file modules/user/user.module) so that it does the following: Get the language object preferred by the user. This user preference can be set on the user account editing page, and is only available if there are more than one languages enabled on the site. If the user did not choose a preferred language, or is the anonymous user, the $default value, or if it is not set, the site default language will be returned.", "context": "Parameters:\n- $account: User account to look up language for.\n- $default: Optional default language object to return if the account has no valid language.\n\nFile: modules/user/user.module", "response": "function user_preferred_language($account, $default = NULL) {\n $language_list = language_list();\n if (!empty($account->language) && isset($language_list[$account->language])) {\n return $language_list[$account->language];\n }\n else {\n return $default ? $default : language_default();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3506cc797d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_read_instances/7.x", "instruction": "I need the code for `field_read_instances($params = array(), $include_additional = array())` in Drupal 7 (modules/field/field.crud.inc). It must do this: Reads in field instances that match an array of conditions.", "context": "Parameters:\n- $param: An array of properties to use in selecting a field instance. Valid keys include any column of the field_config_instance table. If NULL, all instances will be returned.\n- $include_additional: The default behavior of this function is to not return field instances that have been marked deleted, or whose field is inactive. Setting $include_additional['include_inactive'] or $include_additional['include_deleted'] to TRUE will override this behavior.\n\nReturns: An array of instances matching the arguments.\n\nFile: modules/field/field.crud.inc", "response": "function field_read_instances($params = array(), $include_additional = array()) {\n $include_inactive = isset($include_additional['include_inactive']) && $include_additional['include_inactive'];\n $include_deleted = isset($include_additional['include_deleted']) && $include_additional['include_deleted'];\n\n $query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC));\n $query->join('field_config', 'fc', 'fc.id = fci.field_id');\n $query->fields('fci');\n\n // Turn the conditions into a query.\n foreach ($params as $key => $value) {\n $query->condition('fci.' . $key, $value);\n }\n if (!$include_inactive) {\n $query\n ->condition('fc.active', 1)\n ->condition('fc.storage_active', 1);\n }\n if (!$include_deleted) {\n $query->condition('fc.deleted', 0);\n $query->condition('fci.deleted', 0);\n }\n\n $instances = array();\n $query->orderBy('fci.id');\n $results = $query->execute();\n\n foreach ($results as $record) {\n // Filter out instances on unknown entity types (for instance because the\n // module exposing them was disabled).\n $entity_info = entity_get_info($record['entity_type']);\n if ($include_inactive || $entity_info) {\n $instance = unserialize($record['data']);\n $instance['id'] = $record['id'];\n $instance['field_id'] = $record['field_id'];\n $instance['field_name'] = $record['field_name'];\n $instance['entity_type'] = $record['entity_type'];\n $instance['bundle'] = $record['bundle'];\n $instance['deleted'] = $record['deleted'];\n\n module_invoke_all('field_read_instance', $instance);\n $instances[] = $instance;\n }\n }\n return $instances;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35132ff979", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_managed_file_value/7.x", "instruction": "Implement `file_managed_file_value(&$element, $input = FALSE, $form_state = NULL)` in PHP for Drupal 7. Required behavior: The #value_callback for a managed_file type element.", "context": "File: modules/file/file.module", "response": "function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL) {\n $fid = 0;\n $force_default = FALSE;\n\n // Find the current value of this field from the form state.\n $form_state_fid = $form_state['values'];\n foreach ($element['#parents'] as $parent) {\n $form_state_fid = isset($form_state_fid[$parent]) ? $form_state_fid[$parent] : 0;\n }\n\n if ($element['#extended'] && isset($form_state_fid['fid'])) {\n $fid = $form_state_fid['fid'];\n }\n elseif (is_numeric($form_state_fid)) {\n $fid = $form_state_fid;\n }\n\n // Process any input and save new uploads.\n if ($input !== FALSE) {\n $return = $input;\n\n // Uploads take priority over all other values.\n if ($file = file_managed_file_save_upload($element)) {\n $fid = $file->fid;\n }\n else {\n // Check for #filefield_value_callback values.\n // Because FAPI does not allow multiple #value_callback values like it\n // does for #element_validate and #process, this fills the missing\n // functionality to allow File fields to be extended through FAPI.\n if (isset($element['#file_value_callbacks'])) {\n foreach ($element['#file_value_callbacks'] as $callback) {\n $callback($element, $input, $form_state);\n }\n }\n // If a FID was submitted, load the file (and check access if it's not a\n // public file) to confirm it exists and that the current user has access\n // to it.\n if (isset($input['fid']) && ($file = file_load($input['fid']))) {\n // By default the public:// file scheme provided by Drupal core is the\n // only one that allows files to be publicly accessible to everyone, so\n // it is the only one for which the file access checks are bypassed.\n // Other modules which provide publicly accessible streams of their own\n // in hook_stream_wrappers() can add the corresponding scheme to the\n // 'file_public_schema' variable to bypass file access checks for those\n // as well. This should only be done for schemes that are completely\n // publicly accessible, with no download restrictions; for security\n // reasons all other schemes must go through the file_download_access()\n // check.\n if (!in_array(file_uri_scheme($file->uri), variable_get('file_public_schema', array('public'))) && !file_download_access($file->uri)) {\n $force_default = TRUE;\n }\n // Temporary files that belong to other users should never be allowed.\n elseif ($file->status != FILE_STATUS_PERMANENT) {\n if ($GLOBALS['user']->uid && $file->uid != $GLOBALS['user']->uid) {\n $force_default = TRUE;\n }\n // Since file ownership can't be determined for anonymous users, they\n // are not allowed to reuse temporary files at all. But they do need\n // to be able to reuse their own files from earlier submissions of\n // the same form, so to allow that, check for the token added by\n // file_managed_file_process().\n elseif (!$GLOBALS['user']->uid) {\n $token = drupal_array_get_nested_value($form_state['input'], array_merge($element['#parents'], array('fid_token')));\n if ($token !== drupal_hmac_base64('file-' . $file->fid, drupal_get_private_key() . drupal_get_hash_salt())) {\n $force_default = TRUE;\n }\n }\n }\n // If all checks pass, allow the file to be changed.\n if (!$force_default) {\n $fid = $file->fid;\n }\n }\n }\n }\n\n // If there is no input or if the default value was requested above, use the\n // default value.\n if ($input === FALSE || $force_default) {\n if ($element['#extended']) {\n $default_fid = isset($element['#default_value']['fid']) ? $element['#default_value']['fid'] : 0;\n $return = isset($element['#default_value']) ? $element['#default_value'] : array('fid' => 0);\n }\n else {\n $default_fid = isset($element['#default_value']) ? $element['#default_value'] : 0;\n $return = array('fid' => 0);\n }\n\n // Confirm that the file exists when used as a default value.\n if ($default_fid && $file = file_load($default_fid)) {\n $fid = $file->fid;\n }\n }\n\n $return['fid'] = $fid;\n\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3516897809", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/_announcements_feed_preprocess_item/7.x", "instruction": "In Drupal 7, write the function `_announcements_feed_preprocess_item(&$item)` (file modules/announcements_feed/announcements_feed.module) so that it does the following: Helper to preprocess individual announcement items.", "context": "File: modules/announcements_feed/announcements_feed.module", "response": "function _announcements_feed_preprocess_item(&$item) {\n $item['title'] = filter_xss($item['title']);\n $item['teaser'] = filter_xss($item['teaser']);\n $item['link'] = check_url($item['link']);\n $item['date_modified'] = check_plain($item['date_modified']);\n $item['date_published'] = check_plain($item['date_published']);\n $item['version'] = check_plain($item['version']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3519f59c99", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/_forum_get_topic_order/7.x", "instruction": "I need the code for `_forum_get_topic_order($sortby)` in Drupal 7 (modules/forum/forum.module). It must do this: Gets topic sorting information based on an integer code.", "context": "Parameters:\n- $sortby: One of the following integers indicating the sort criteria: - 1: Date - newest first. - 2: Date - oldest first. - 3: Posts with the most comments first. - 4: Posts with the least comments first.\n\nReturns: An array with the following values: - field: A field for an SQL query. - sort: 'asc' or 'desc'.\n\nFile: modules/forum/forum.module", "response": "function _forum_get_topic_order($sortby) {\n switch ($sortby) {\n case 1:\n return array('field' => 'f.last_comment_timestamp', 'sort' => 'desc');\n break;\n case 2:\n return array('field' => 'f.last_comment_timestamp', 'sort' => 'asc');\n break;\n case 3:\n return array('field' => 'f.comment_count', 'sort' => 'desc');\n break;\n case 4:\n return array('field' => 'f.comment_count', 'sort' => 'asc');\n break;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35293f9c8e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_stream_wrappers/7.x", "instruction": "Implement `system_stream_wrappers()` in PHP for Drupal 7. Required behavior: Implements hook_stream_wrappers().", "context": "File: modules/system/system.module", "response": "function system_stream_wrappers() {\n $wrappers = array(\n 'public' => array(\n 'name' => t('Public files'),\n 'class' => 'DrupalPublicStreamWrapper',\n 'description' => t('Public local files served by the webserver.'),\n 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,\n ),\n 'temporary' => array(\n 'name' => t('Temporary files'),\n 'class' => 'DrupalTemporaryStreamWrapper',\n 'description' => t('Temporary local files for upload and previews.'),\n 'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,\n ),\n );\n\n // Only register the private file stream wrapper if a file path has been set.\n if (variable_get('file_private_path', FALSE)) {\n $wrappers['private'] = array(\n 'name' => t('Private files'),\n 'class' => 'DrupalPrivateStreamWrapper',\n 'description' => t('Private local files served by Drupal.'),\n 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,\n );\n }\n\n return $wrappers;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-352bdd4287", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7007/7.x", "instruction": "I need the code for `user_update_7007()` in Drupal 7 (modules/user/user.install). It must do this: Add a weight column to user roles.", "context": "File: modules/user/user.install", "response": "function user_update_7007() {\n db_add_field('role', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0));\n db_add_index('role', 'name_weight', array('name', 'weight'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35329c0141", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_info/7.x", "instruction": "In Drupal 7, write the function `forum_node_info()` (file modules/forum/forum.module) so that it does the following: Implements hook_node_info().", "context": "File: modules/forum/forum.module", "response": "function forum_node_info() {\n return array(\n 'forum' => array(\n 'name' => t('Forum topic'),\n 'base' => 'forum',\n 'description' => t('A forum topic starts a new discussion thread within a forum.'),\n 'title_label' => t('Subject'),\n )\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3535817057", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.install/function/poll_update_7002/7.x", "instruction": "In Drupal 7, write the function `poll_update_7002()` (file modules/poll/poll.install) so that it does the following: Add timestamp field to {poll_vote}.", "context": "File: modules/poll/poll.install", "response": "function poll_update_7002() {\n $field = array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n );\n db_add_field('poll_vote', 'timestamp', $field);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35359cb317", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.admin.inc/function/profile_admin_overview/7.x", "instruction": "Implement `profile_admin_overview($form)` in PHP for Drupal 7. Required behavior: Form builder to display a listing of all editable profile fields.", "context": "File: modules/profile/profile.admin.inc", "response": "function profile_admin_overview($form) {\n $result = db_query('SELECT title, name, type, category, fid, weight FROM {profile_field} ORDER BY category, weight');\n\n $categories = array();\n foreach ($result as $field) {\n // Collect all category information\n $categories[] = $field->category;\n\n // Save all field information\n $form[$field->fid]['name'] = array('#markup' => check_plain($field->name));\n $form[$field->fid]['title'] = array('#markup' => check_plain($field->title));\n $form[$field->fid]['type'] = array('#markup' => $field->type);\n $form[$field->fid]['category'] = array(\n '#type' => 'select',\n '#title' => t('Category for @title', array('@title' => $field->title)),\n '#title_display' => 'invisible',\n '#default_value' => $field->category,\n '#options' => array(),\n );\n $form[$field->fid]['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight for @title', array('@title' => $field->title)),\n '#title_display' => 'invisible',\n '#default_value' => $field->weight,\n );\n $form[$field->fid]['edit'] = array('#type' => 'link', '#title' => t('edit'), '#href' => \"admin/config/people/profile/edit/$field->fid\");\n $form[$field->fid]['delete'] = array('#type' => 'link', '#title' => t('delete'), '#href' => \"admin/config/people/profile/delete/$field->fid\");\n }\n\n // Add the category combo boxes\n $categories = array_unique($categories);\n foreach ($form as $fid => $field) {\n foreach ($categories as $cat => $category) {\n $form[$fid]['category']['#options'][$category] = $category;\n }\n }\n\n // Display the submit button only when there's more than one field\n if (count($form) > 1) {\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));\n }\n else {\n // Disable combo boxes when there isn't a submit button\n foreach ($form as $fid => $field) {\n unset($form[$fid]['weight']);\n $form[$fid]['category']['#type'] = 'value';\n }\n }\n $form['#tree'] = TRUE;\n\n // @todo: Any reason this isn't done using an element with #theme = 'links'?\n $addnewfields = '

            ' . t('Add new field') . '

            ';\n $addnewfields .= '
              ';\n foreach (_profile_field_types() as $key => $value) {\n $addnewfields .= '
            • ' . l($value, \"admin/config/people/profile/add/$key\") . '
            • ';\n }\n $addnewfields .= '
            ';\n $form['addnewfields'] = array('#markup' => $addnewfields);\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3542be6d6f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_modules_enabled/7.x", "instruction": "In Drupal 7, write the function `node_modules_enabled($modules)` (file modules/node/node.module) so that it does the following: Implements hook_modules_enabled().", "context": "File: modules/node/node.module", "response": "function node_modules_enabled($modules) {\n // Check if any of the newly enabled modules require the node_access table to\n // be rebuilt.\n if (!node_access_needs_rebuild() && array_intersect($modules, module_implements('node_grants'))) {\n node_access_needs_rebuild(TRUE);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-35482b8fc8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/archiver_get_archiver/7.x", "instruction": "I need the code for `archiver_get_archiver($file)` in Drupal 7 (includes/common.inc). It must do this: Creates the appropriate archiver for the specified file.", "context": "Parameters:\n- $file: The full path of the archive file. Note that stream wrapper paths are supported, but not remote ones.\n\nReturns: A newly created instance of the archiver class appropriate for the specified file, already bound to that file. If no appropriate archiver class was found, will return FALSE.\n\nFile: includes/common.inc", "response": "function archiver_get_archiver($file) {\n // Archivers can only work on local paths\n $filepath = drupal_realpath($file);\n if (!is_file($filepath)) {\n throw new Exception(t('Archivers can only operate on local files: %file not supported', array('%file' => $file)));\n }\n $archiver_info = archiver_get_info();\n\n foreach ($archiver_info as $implementation) {\n foreach ($implementation['extensions'] as $extension) {\n // Because extensions may be multi-part, such as .tar.gz,\n // we cannot use simpler approaches like substr() or pathinfo().\n // This method isn't quite as clean but gets the job done.\n // Also note that the file may not yet exist, so we cannot rely\n // on fileinfo() or other disk-level utilities.\n if (strrpos($filepath, '.' . $extension) === strlen($filepath) - strlen('.' . $extension)) {\n return new $implementation['class']($filepath);\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-355328a0c9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_save/7.x", "instruction": "Implement `menu_link_save(&$item, $existing_item = array(), $parent_candidates = array())` in PHP for Drupal 7. Required behavior: Saves a menu link.", "context": "After calling this function, rebuild the menu cache using menu_cache_clear_all().\n\nParameters:\n- $item: An associative array representing a menu link item, with elements: - link_path: (required) The path of the menu item, which should be normalized first by calling drupal_get_normal_path() on it. - link_title: (required) Title to appear in menu for the link. - menu_name: (optional) The machine name of the menu for the link. Defaults to 'navigation'. - weight: (optional) Integer to determine position in menu. Default is 0. - expanded: (optional) Boolean that determines if the item is expanded. - options: (optional) An array of options, see l() for more. - mlid: (optional) Menu link identifier, the primary integer key for each menu link. Can be set to an existing value, or to 0 or NULL to insert a new link. - plid: (optional) The mlid of the parent. - router_path: (optional) The path of the relevant router item.\n- $existing_item: Optional, the current record from the {menu_links} table as an array.\n- $parent_candidates: Optional array of menu links keyed by mlid. Used by _menu_navigation_links_rebuild() only.\n\nReturns: The mlid of the saved menu link, or FALSE if the menu link could not be saved.\n\nFile: includes/menu.inc", "response": "function menu_link_save(&$item, $existing_item = array(), $parent_candidates = array()) {\n drupal_alter('menu_link', $item);\n\n // This is the easiest way to handle the unique internal path '',\n // since a path marked as external does not need to match a router path.\n $item['external'] = (url_is_external($item['link_path']) || $item['link_path'] == '') ? 1 : 0;\n // Load defaults.\n $item += array(\n 'menu_name' => 'navigation',\n 'weight' => 0,\n 'link_title' => '',\n 'hidden' => 0,\n 'has_children' => 0,\n 'expanded' => 0,\n 'options' => array(),\n 'module' => 'menu',\n 'customized' => 0,\n 'updated' => 0,\n );\n if (isset($item['mlid'])) {\n if (!$existing_item) {\n $existing_item = db_query('SELECT * FROM {menu_links} WHERE mlid = :mlid', array('mlid' => $item['mlid']))->fetchAssoc();\n }\n if ($existing_item) {\n $existing_item['options'] = unserialize($existing_item['options']);\n }\n }\n else {\n $existing_item = FALSE;\n }\n\n // Try to find a parent link. If found, assign it and derive its menu.\n $parent = _menu_link_find_parent($item, $parent_candidates);\n if (!empty($parent['mlid'])) {\n $item['plid'] = $parent['mlid'];\n $item['menu_name'] = $parent['menu_name'];\n }\n // If no corresponding parent link was found, move the link to the top-level.\n else {\n $item['plid'] = 0;\n }\n $menu_name = $item['menu_name'];\n\n if (!$existing_item) {\n $item['mlid'] = db_insert('menu_links')\n ->fields(array(\n 'menu_name' => $item['menu_name'],\n 'plid' => $item['plid'],\n 'link_path' => $item['link_path'],\n 'hidden' => $item['hidden'],\n 'external' => $item['external'],\n 'has_children' => $item['has_children'],\n 'expanded' => $item['expanded'],\n 'weight' => (int) $item['weight'],\n 'module' => $item['module'],\n 'link_title' => $item['link_title'],\n 'options' => serialize($item['options']),\n 'customized' => $item['customized'],\n 'updated' => $item['updated'],\n ))\n ->execute();\n }\n\n // Directly fill parents for top-level links.\n if ($item['plid'] == 0) {\n $item['p1'] = $item['mlid'];\n for ($i = 2; $i <= MENU_MAX_DEPTH; $i++) {\n $item[\"p$i\"] = 0;\n }\n $item['depth'] = 1;\n }\n // Otherwise, ensure that this link's depth is not beyond the maximum depth\n // and fill parents based on the parent link.\n else {\n if ($item['has_children'] && $existing_item) {\n $limit = MENU_MAX_DEPTH - menu_link_children_relative_depth($existing_item) - 1;\n }\n else {\n $limit = MENU_MAX_DEPTH - 1;\n }\n if ($parent['depth'] > $limit) {\n return FALSE;\n }\n $item['depth'] = $parent['depth'] + 1;\n _menu_link_parents_set($item, $parent);\n }\n // Need to check both plid and menu_name, since plid can be 0 in any menu.\n if ($existing_item && ($item['plid'] != $existing_item['plid'] || $menu_name != $existing_item['menu_name'])) {\n _menu_link_move_children($item, $existing_item);\n }\n // Find the router_path.\n if (empty($item['router_path']) || !$existing_item || ($existing_item['link_path'] != $item['link_path'])) {\n if ($item['external']) {\n $item['router_path'] = '';\n }\n else {\n // Find the router path which will serve this path.\n $item['parts'] = explode('/', $item['link_path'], MENU_MAX_PARTS);\n $item['router_path'] = _menu_find_router_path($item['link_path']);\n }\n }\n // If every value in $existing_item is the same in the $item, there is no\n // reason to run the update queries or clear the caches. We use\n // array_intersect_key() with the $item as the first parameter because\n // $item may have additional keys left over from building a router entry.\n // The intersect removes the extra keys, allowing a meaningful comparison.\n if (!$existing_item || (array_intersect_key($item, $existing_item) != $existing_item)) {\n db_update('menu_links')\n ->fields(array(\n 'menu_name' => $item['menu_name'],\n 'plid' => $item['plid'],\n 'link_path' => $item['link_path'],\n 'router_path' => $item['router_path'],\n 'hidden' => $item['hidden'],\n 'external' => $item['external'],\n 'has_children' => $item['has_children'],\n 'expanded' => $item['expanded'],\n 'weight' => (int) $item['weight'],\n 'depth' => $item['depth'],\n 'p1' => $item['p1'],\n 'p2' => $item['p2'],\n 'p3' => $item['p3'],\n 'p4' => $item['p4'],\n 'p5' => $item['p5'],\n 'p6' => $item['p6'],\n 'p7' => $item['p7'],\n 'p8' => $item['p8'],\n 'p9' => $item['p9'],\n 'module' => $item['module'],\n 'link_title' => $item['link_title'],\n 'options' => serialize($item['options']),\n 'customized' => $item['customized'],\n ))\n ->condition('mlid', $item['mlid'])\n ->execute();\n // Check the has_children status of the parent.\n _menu_update_parental_status($item);\n menu_cache_clear($menu_name);\n if ($existing_item && $menu_name != $existing_item['menu_name']) {\n menu_cache_clear($existing_item['menu_name']);\n }\n // Notify modules we have acted on a menu item.\n $hook = 'menu_link_insert';\n if ($existing_item) {\n $hook = 'menu_link_update';\n }\n module_invoke_all($hook, $item);\n // Now clear the cache.\n _menu_clear_page_cache();\n }\n return $item['mlid'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-355b0649ec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_build_content/7.x", "instruction": "In Drupal 7, write the function `user_build_content($account, $view_mode = 'full', $langcode = NULL)` (file modules/user/user.module) so that it does the following: Builds a structured array representing the profile content.", "context": "Parameters:\n- $account: A user object.\n- $view_mode: View mode, e.g. 'full'.\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nFile: modules/user/user.module", "response": "function user_build_content($account, $view_mode = 'full', $langcode = NULL) {\n if (!isset($langcode)) {\n $langcode = $GLOBALS['language_content']->language;\n }\n\n // Remove previously built content, if exists.\n $account->content = array();\n\n // Allow modules to change the view mode.\n $view_mode = key(entity_view_mode_prepare('user', array($account->uid => $account), $view_mode, $langcode));\n\n // Build fields content.\n field_attach_prepare_view('user', array($account->uid => $account), $view_mode, $langcode);\n entity_prepare_view('user', array($account->uid => $account), $langcode);\n $account->content += field_attach_view('user', $account, $view_mode, $langcode);\n\n // Populate $account->content with a render() array.\n module_invoke_all('user_view', $account, $view_mode, $langcode);\n module_invoke_all('entity_view', $account, 'user', $view_mode, $langcode);\n\n // Make sure the current view mode is stored if no module has already\n // populated the related key.\n $account->content += array('#view_mode' => $view_mode);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-358ffbb112", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/_drupal_session_destroy/7.x", "instruction": "I need the code for `_drupal_session_destroy($sid)` in Drupal 7 (includes/session.inc). It must do this: Session handler assigned by session_set_save_handler().", "context": "Cleans up a specific session.\n\nParameters:\n- $sid: Session ID.\n\nFile: includes/session.inc", "response": "function _drupal_session_destroy($sid) {\n global $user, $is_https;\n\n // Nothing to do if we are not allowed to change the session.\n if (!drupal_save_session()) {\n return TRUE;\n }\n\n // Delete session data.\n db_delete('sessions')\n ->condition($is_https ? 'ssid' : 'sid', drupal_session_id($sid))\n ->execute();\n\n // Reset $_SESSION and $user to prevent a new session from being started\n // in drupal_session_commit().\n $_SESSION = array();\n $user = drupal_anonymous_user();\n\n // Unset the session cookies.\n _drupal_session_delete_cookie(session_name());\n if ($is_https) {\n _drupal_session_delete_cookie(substr(session_name(), 1), FALSE);\n }\n elseif (variable_get('https', FALSE)) {\n _drupal_session_delete_cookie('S' . session_name(), TRUE);\n }\n\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-359be612ed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/_system_is_incompatible/7.x", "instruction": "I need the code for `_system_is_incompatible(&$incompatible, $files, $file)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Recursively check compatibility.", "context": "Parameters:\n- $incompatible: An associative array which at the end of the check contains all incompatible files as the keys, their values being TRUE.\n- $files: The set of files that will be tested.\n- $file: The file at which the check starts.\n\nReturns: Returns TRUE if an incompatible file is found, NULL (no return value) otherwise.\n\nFile: modules/system/system.admin.inc", "response": "function _system_is_incompatible(&$incompatible, $files, $file) {\n if (isset($incompatible[$file->name])) {\n return TRUE;\n }\n // Recursively traverse required modules, looking for incompatible modules.\n foreach ($file->requires as $requires) {\n if (isset($files[$requires]) && _system_is_incompatible($incompatible, $files, $files[$requires])) {\n $incompatible[$file->name] = TRUE;\n return TRUE;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35a649972f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.authorize.inc/function/_update_authorize_clear_update_status/7.x", "instruction": "Implement `_update_authorize_clear_update_status()` in PHP for Drupal 7. Required behavior: Clears cached available update status data.", "context": "Since this function is run at such a low bootstrap level, the Update Manager module is not loaded. So, we can't just call _update_cache_clear(). However, the database is bootstrapped, so we can do a query ourselves to clear out what we want to clear.\n\nNote that we do not want to just truncate the table, since that would remove items related to currently pending fetch attempts.\n\nFile: modules/update/update.authorize.inc", "response": "function _update_authorize_clear_update_status() {\n $query = db_delete('cache_update');\n $query->condition(\n db_or()\n ->condition('cid', 'update_project_%', 'LIKE')\n ->condition('cid', 'available_releases::%', 'LIKE')\n );\n $query->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35ab70b1de", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_add_css/7.x", "instruction": "I need the code for `ajax_command_add_css($styles)` in Drupal 7 (includes/ajax.inc). It must do this: Creates a Drupal Ajax 'add_css' command.", "context": "This method will add css via ajax in a cross-browser compatible way.\n\nThis command is implemented by Drupal.ajax.prototype.commands.add_css() defined in misc/ajax.js.\n\nParameters:\n- $styles: A string that contains the styles to be added.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_add_css($styles) {\n return array(\n 'command' => 'add_css',\n 'data' => $styles,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35b9007259", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_get_destinations/7.x", "instruction": "Implement `field_ui_get_destinations($destinations)` in PHP for Drupal 7. Required behavior: Extracts next redirect path from an array of multiple destinations.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_get_destinations($destinations) {\n $path = array_shift($destinations);\n $options = drupal_parse_url($path);\n if ($destinations) {\n $options['query']['destinations'] = $destinations;\n }\n return array($options['path'], $options);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35bdfa631c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.admin.inc/function/comment_admin_overview_submit/7.x", "instruction": "I need the code for `comment_admin_overview_submit($form, &$form_state)` in Drupal 7 (modules/comment/comment.admin.inc). It must do this: Process comment_admin_overview form submissions.", "context": "Execute the chosen 'Update option' on the selected comments, such as publishing, unpublishing or deleting.\n\nFile: modules/comment/comment.admin.inc", "response": "function comment_admin_overview_submit($form, &$form_state) {\n $operation = $form_state['values']['operation'];\n $cids = $form_state['values']['comments'];\n\n if ($operation == 'delete') {\n comment_delete_multiple($cids);\n }\n else {\n foreach ($cids as $cid => $value) {\n $comment = comment_load($value);\n\n if ($operation == 'unpublish') {\n $comment->status = COMMENT_NOT_PUBLISHED;\n }\n elseif ($operation == 'publish') {\n $comment->status = COMMENT_PUBLISHED;\n }\n comment_save($comment);\n }\n }\n drupal_set_message(t('The update has been performed.'));\n $form_state['redirect'] = 'admin/content/comment';\n cache_clear_all();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35bf68312a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_theme/7.x", "instruction": "I need the code for `profile_theme()` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_theme().", "context": "File: modules/profile/profile.module", "response": "function profile_theme() {\n return array(\n 'profile_block' => array(\n 'variables' => array('account' => NULL, 'fields' => array()),\n 'template' => 'profile-block',\n ),\n 'profile_listing' => array(\n 'variables' => array('account' => NULL, 'fields' => array()),\n 'template' => 'profile-listing',\n ),\n 'profile_wrapper' => array(\n 'variables' => array('content' => NULL),\n 'template' => 'profile-wrapper',\n ),\n 'profile_admin_overview' => array(\n 'render element' => 'form',\n 'file' => 'profile.admin.inc',\n )\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-35df32992e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/variable_set/7.x", "instruction": "In Drupal 7, write the function `variable_set($name, $value)` (file includes/bootstrap.inc) so that it does the following: Sets a persistent variable.", "context": "Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.\n\nParameters:\n- $name: The name of the variable to set.\n- $value: The value to set. This can be any PHP data type; these functions take care of serialization as necessary.\n\nFile: includes/bootstrap.inc", "response": "function variable_set($name, $value) {\n global $conf;\n\n db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();\n\n cache_clear_all('variables', 'cache_bootstrap');\n\n $conf[$name] = $value;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35f206b283", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_search_page/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_search_page($results)` (modules/search/search.api.php): Override the rendering of search results.", "context": "A module that implements hook_search_info() to define a type of search may implement this hook in order to override the default theming of its search results, which is otherwise themed using theme('search_results').\n\nNote that by default, theme('search_results') and theme('search_result') work together to create an ordered list (OL). So your hook_search_page() implementation should probably do this as well.\n\nParameters:\n- $results: An array of search results.\n\nReturns: A renderable array, which will render the formatted search results with a pager included.\n\nFile: modules/search/search.api.php", "response": "function hook_search_page($results) {\n $output['prefix']['#markup'] = '
              ';\n\n foreach ($results as $entry) {\n $output[] = array(\n '#theme' => 'search_result',\n '#result' => $entry,\n '#module' => 'my_module_name',\n );\n }\n $output['suffix']['#markup'] = '
            ' . theme('pager');\n\n return $output;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-35f26c2550", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_collate_types/7.x", "instruction": "I need the code for `_field_info_collate_types($reset = FALSE)` in Drupal 7 (modules/field/field.info.inc). It must do this: Collates all information on field types, widget types and related structures.", "context": "Parameters:\n- $reset: If TRUE, clear the cache. The information will be rebuilt from the database next time it is needed. Defaults to FALSE.\n\nReturns: If $reset is TRUE, nothing. If $reset is FALSE, an array containing the following elements: - 'field types': Array of hook_field_info() results, keyed by field_type. Each element has the following components: label, description, settings, instance_settings, default_widget, default_formatter, and behaviors from hook_field_info(), as well as module, giving the module that exposes the field type. - 'widget types': Array of hook_field_widget_info() results, keyed by widget_type. Each element has the following components: label, field types, settings, weight, and behaviors from hook_field_widget_info(), as well as module, giving the module that exposes the widget type. - 'formatter types': Array of hook_field_formatter_info() results, keyed by formatter_type. Each element has the following components: label, field types, and behaviors from hook_field_formatter_info(), as well as module, giving the module that exposes the formatter type. - 'storage types': Array of hook_field_storage_info() results, keyed by storage type names. Each element has the following components: label, description, and settings from hook_field_storage_info(), as well as module, giving the module that exposes the storage type. - 'fieldable types': Array of hook_entity_info() results, keyed by entity_type. Each element has the following components: name, id key, revision key, bundle key, cacheable, and bundles from hook_entity_info(), as well as module, giving the module that exposes the entity type.\n\nFile: modules/field/field.info.inc", "response": "function _field_info_collate_types($reset = FALSE) {\n global $language;\n static $info;\n\n // The _info() hooks invoked below include translated strings, so each\n // language is cached separately.\n $langcode = $language->language;\n\n if ($reset) {\n $info = NULL;\n // Clear all languages.\n cache_clear_all('field_info_types:', 'cache_field', TRUE);\n return;\n }\n\n if (!isset($info)) {\n if ($cached = cache_get(\"field_info_types:$langcode\", 'cache_field')) {\n $info = $cached->data;\n }\n else {\n $info = array(\n 'field types' => array(),\n 'widget types' => array(),\n 'formatter types' => array(),\n 'storage types' => array(),\n );\n\n // Populate field types.\n foreach (module_implements('field_info') as $module) {\n $field_types = (array) module_invoke($module, 'field_info');\n foreach ($field_types as $name => $field_info) {\n // Provide defaults.\n $field_info += array(\n 'settings' => array(),\n 'instance_settings' => array(),\n );\n $info['field types'][$name] = $field_info;\n $info['field types'][$name]['module'] = $module;\n }\n }\n drupal_alter('field_info', $info['field types']);\n\n // Populate widget types.\n foreach (module_implements('field_widget_info') as $module) {\n $widget_types = (array) module_invoke($module, 'field_widget_info');\n foreach ($widget_types as $name => $widget_info) {\n // Provide defaults.\n $widget_info += array(\n 'settings' => array(),\n );\n $info['widget types'][$name] = $widget_info;\n $info['widget types'][$name]['module'] = $module;\n }\n }\n drupal_alter('field_widget_info', $info['widget types']);\n uasort($info['widget types'], 'drupal_sort_weight');\n\n // Populate formatter types.\n foreach (module_implements('field_formatter_info') as $module) {\n $formatter_types = (array) module_invoke($module, 'field_formatter_info');\n foreach ($formatter_types as $name => $formatter_info) {\n // Provide defaults.\n $formatter_info += array(\n 'settings' => array(),\n );\n $info['formatter types'][$name] = $formatter_info;\n $info['formatter types'][$name]['module'] = $module;\n }\n }\n drupal_alter('field_formatter_info', $info['formatter types']);\n\n // Populate storage types.\n foreach (module_implements('field_storage_info') as $module) {\n $storage_types = (array) module_invoke($module, 'field_storage_info');\n foreach ($storage_types as $name => $storage_info) {\n // Provide defaults.\n $storage_info += array(\n 'settings' => array(),\n );\n $info['storage types'][$name] = $storage_info;\n $info['storage types'][$name]['module'] = $module;\n }\n }\n drupal_alter('field_storage_info', $info['storage types']);\n\n // Set the cache if we can acquire a lock.\n if (lock_acquire(\"field_info_types:$langcode\")) {\n cache_set(\"field_info_types:$langcode\", $info, 'cache_field');\n lock_release(\"field_info_types:$langcode\");\n }\n }\n }\n\n return $info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-35f838fc7d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_widget_validate/7.x", "instruction": "In Drupal 7, write the function `number_field_widget_validate($element, &$form_state)` (file modules/field/modules/number/number.module) so that it does the following: FAPI validation of an individual number element.", "context": "File: modules/field/modules/number/number.module", "response": "function number_field_widget_validate($element, &$form_state) {\n $field = field_widget_field($element, $form_state);\n $instance = field_widget_instance($element, $form_state);\n\n $type = $element['#number_type'];\n $value = $element['#value'];\n\n // Reject invalid characters.\n if (!empty($value)) {\n switch ($type) {\n case 'float':\n case 'decimal':\n $regexp = '@([^-0-9\\\\' . $field['settings']['decimal_separator'] . '])|(.-)@';\n $message = t('Only numbers and the decimal separator (@separator) allowed in %field.', array('%field' => $instance['label'], '@separator' => $field['settings']['decimal_separator']));\n break;\n\n case 'integer':\n $regexp = '@([^-0-9])|(.-)@';\n $message = t('Only numbers are allowed in %field.', array('%field' => $instance['label']));\n break;\n }\n if ($value != preg_replace($regexp, '', $value)) {\n form_error($element, $message);\n }\n else {\n if ($type == 'decimal' || $type == 'float') {\n // Verify that only one decimal separator exists in the field.\n if (substr_count($value, $field['settings']['decimal_separator']) > 1) {\n $message = t('%field: There should only be one decimal separator (@separator).',\n array(\n '%field' => t($instance['label']),\n '@separator' => $field['settings']['decimal_separator'],\n )\n );\n form_error($element, $message);\n }\n else {\n // Substitute the decimal separator; things should be fine.\n $value = strtr($value, $field['settings']['decimal_separator'], '.');\n }\n }\n form_set_value($element, $value, $form_state);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-36097c0e35", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_palette_color_value/7.x", "instruction": "I need the code for `color_palette_color_value($element, $input = FALSE, $form_state = array())` in Drupal 7 (modules/color/color.module). It must do this: Determines the value for a palette color field.", "context": "Parameters:\n- $element: The form element whose value is being populated.\n- $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.\n- $form_state: A keyed array containing the current state of the form.\n\nReturns: The data that will appear in the $form_state['values'] collection for this element. Return nothing to use the default.\n\nFile: modules/color/color.module", "response": "function color_palette_color_value($element, $input = FALSE, $form_state = array()) {\n // If we suspect a possible cross-site request forgery attack, only accept\n // hexadecimal CSS color strings from user input, to avoid problems when this\n // value is used in the JavaScript preview.\n if ($input !== FALSE) {\n // Start with the provided value for this textfield, and validate that if\n // necessary, falling back on the default value.\n $value = form_type_textfield_value($element, $input, $form_state);\n if (!$value || !isset($form_state['complete form']['#token']) || color_valid_hexadecimal_string($value) || drupal_valid_token($form_state['values']['form_token'], $form_state['complete form']['#token'])) {\n return $value;\n }\n else {\n return $element['#default_value'];\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-361b398240", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_copy/7.x", "instruction": "Give me the example code for `hook_file_copy($file, $source)` in Drupal 7. Hook description: Respond to a file that has been copied.", "context": "Parameters:\n- $file: The newly copied file object.\n- $source: The original file before the copy.\n\nFile: modules/system/system.api.php", "response": "function hook_file_copy($file, $source) {\n $file_user = user_load($file->uid);\n // Make sure that the file name starts with the owner's user name.\n if (strpos($file->filename, $file_user->name) !== 0) {\n $file->filename = $file_user->name . '_' . $file->filename;\n $file->save();\n\n watchdog('file', 'Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename));\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-363dd79ef4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_view/7.x", "instruction": "Implement `comment_node_view($node, $view_mode)` in PHP for Drupal 7. Required behavior: Implements hook_node_view().", "context": "File: modules/comment/comment.module", "response": "function comment_node_view($node, $view_mode) {\n $links = array();\n\n if ($node->comment != COMMENT_NODE_HIDDEN) {\n if ($view_mode == 'rss') {\n // Add a comments RSS element which is a URL to the comments of this node.\n $node->rss_elements[] = array(\n 'key' => 'comments',\n 'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))\n );\n }\n elseif ($view_mode == 'teaser') {\n // Teaser view: display the number of comments that have been posted,\n // or a link to add new comments if the user has permission, the node\n // is open to new comments, and there currently are none.\n if (user_access('access comments')) {\n if (!empty($node->comment_count)) {\n $links['comment-comments'] = array(\n 'title' => format_plural($node->comment_count, '1 comment', '@count comments'),\n 'href' => \"node/$node->nid\",\n 'attributes' => array('title' => t('Jump to the first comment of this posting.')),\n 'fragment' => 'comments',\n 'html' => TRUE,\n );\n // Show a link to the first new comment.\n if ($new = comment_num_new($node->nid)) {\n $links['comment-new-comments'] = array(\n 'title' => format_plural($new, '1 new comment', '@count new comments'),\n 'href' => \"node/$node->nid\",\n 'query' => comment_new_page_count($node->comment_count, $new, $node),\n 'attributes' => array('title' => t('Jump to the first new comment of this posting.')),\n 'fragment' => 'new',\n 'html' => TRUE,\n );\n }\n }\n }\n if ($node->comment == COMMENT_NODE_OPEN) {\n if (user_access('post comments')) {\n $links['comment-add'] = array(\n 'title' => t('Add new comment'),\n 'href' => \"comment/reply/$node->nid\",\n 'attributes' => array('title' => t('Add a new comment to this page.')),\n 'fragment' => 'comment-form',\n );\n }\n else {\n $links['comment_forbidden'] = array(\n 'title' => theme('comment_post_forbidden', array('node' => $node)),\n 'html' => TRUE,\n );\n }\n }\n }\n elseif ($view_mode != 'search_index' && $view_mode != 'search_result') {\n // Node in other view modes: add a \"post comment\" link if the user is\n // allowed to post comments and if this node is allowing new comments.\n // But we don't want this link if we're building the node for search\n // indexing or constructing a search result excerpt.\n if ($node->comment == COMMENT_NODE_OPEN) {\n $comment_form_location = variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW);\n if (user_access('post comments')) {\n // Show the \"post comment\" link if the form is on another page, or\n // if there are existing comments that the link will skip past.\n if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE || (!empty($node->comment_count) && user_access('access comments'))) {\n $links['comment-add'] = array(\n 'title' => t('Add new comment'),\n 'attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')),\n 'href' => \"node/$node->nid\",\n 'fragment' => 'comment-form',\n );\n if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE) {\n $links['comment-add']['href'] = \"comment/reply/$node->nid\";\n }\n }\n }\n else {\n $links['comment_forbidden'] = array(\n 'title' => theme('comment_post_forbidden', array('node' => $node)),\n 'html' => TRUE,\n );\n }\n }\n }\n\n $node->content['links']['comment'] = array(\n '#theme' => 'links__node__comment',\n '#links' => $links,\n '#attributes' => array('class' => array('links', 'inline')),\n );\n\n // Only append comments when we are building a node on its own node detail\n // page. We compare $node and $page_node to ensure that comments are not\n // appended to other nodes shown on the page, for example a node_reference\n // displayed in 'full' view mode within another node.\n if ($node->comment && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {\n $node->content['comments'] = comment_node_page_additions($node);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-364aa88edc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/password_confirm_validate/7.x", "instruction": "Implement `password_confirm_validate($element, &$element_state)` in PHP for Drupal 7. Required behavior: Validates a password_confirm element.", "context": "File: includes/form.inc", "response": "function password_confirm_validate($element, &$element_state) {\n $pass1 = trim($element['pass1']['#value']);\n $pass2 = trim($element['pass2']['#value']);\n if (strlen($pass1) > 0 || strlen($pass2) > 0) {\n if (strcmp($pass1, $pass2)) {\n form_error($element, t('The specified passwords do not match.'));\n }\n }\n elseif ($element['#required'] && !empty($element_state['input'])) {\n form_error($element, t('Password field is required.'));\n }\n\n // Password field must be converted from a two-element array into a single\n // string regardless of validation results.\n form_set_value($element['pass1'], NULL, $element_state);\n form_set_value($element['pass2'], NULL, $element_state);\n form_set_value($element, $pass1, $element_state);\n\n return $element;\n\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-366ac776a8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_reindex/7.x", "instruction": "Implement `search_reindex($sid = NULL, $module = NULL, $reindex = FALSE)` in PHP for Drupal 7. Required behavior: Clears a part of or the entire search index.", "context": "Parameters:\n- $sid: (optional) The ID of the item to remove from the search index. If specified, $module must also be given. Omit both $sid and $module to clear the entire search index.\n- $module: (optional) The machine-readable name of the module for the item to remove from the search index.\n\nFile: modules/search/search.module", "response": "function search_reindex($sid = NULL, $module = NULL, $reindex = FALSE) {\n if ($module == NULL && $sid == NULL) {\n module_invoke_all('search_reset');\n }\n else {\n db_delete('search_dataset')\n ->condition('sid', $sid)\n ->condition('type', $module)\n ->execute();\n db_delete('search_index')\n ->condition('sid', $sid)\n ->condition('type', $module)\n ->execute();\n // Don't remove links if re-indexing.\n if (!$reindex) {\n db_delete('search_node_links')\n ->condition('sid', $sid)\n ->condition('type', $module)\n ->execute();\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-366d08b265", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_path_flush/7.x", "instruction": "Implement `image_path_flush($path)` in PHP for Drupal 7. Required behavior: Clears cached versions of a specific file in all styles.", "context": "Parameters:\n- $path: The Drupal file path to the original image.\n\nFile: modules/image/image.module", "response": "function image_path_flush($path) {\n $styles = image_styles();\n foreach ($styles as $style) {\n $image_path = image_style_path($style['name'], $path);\n if (file_exists($image_path)) {\n file_unmanaged_delete($image_path);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-367af58ba0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_set_cache/7.x", "instruction": "Implement `form_set_cache($form_build_id, $form, $form_state)` in PHP for Drupal 7. Required behavior: Stores a form in the cache.", "context": "File: includes/form.inc", "response": "function form_set_cache($form_build_id, $form, $form_state) {\n // The default cache_form expiration is 6 hours. On busy sites, the cache_form\n // table can become very large. A shorter cache lifetime can help to keep the\n // table's size under control.\n $expire = variable_get('form_cache_expiration', 21600);\n\n // Ensure that the form build_id embedded in the form structure is the same as\n // the one passed in as a parameter. This is an additional safety measure to\n // prevent legacy code operating directly with form_get_cache and\n // form_set_cache from accidentally overwriting immutable form state.\n if ($form['#build_id'] != $form_build_id) {\n watchdog('form', 'Form build-id mismatch detected while attempting to store a form in the cache.', array(), WATCHDOG_ERROR);\n return;\n }\n\n // Cache form structure.\n if (isset($form)) {\n if ($GLOBALS['user']->uid) {\n $form['#cache_token'] = drupal_get_token();\n }\n unset($form['#build_id_old']);\n cache_set('form_' . $form_build_id, $form, 'cache_form', REQUEST_TIME + $expire);\n }\n\n // Cache form state.\n if (variable_get('cache', 0) && drupal_page_is_cacheable()) {\n $form_state['build_info']['immutable'] = TRUE;\n }\n if ($data = array_diff_key($form_state, array_flip(form_state_keys_no_cache()))) {\n cache_set('form_state_' . $form_build_id, $data, 'cache_form', REQUEST_TIME + $expire);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-367c0e5b56", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/watchdog_severity_levels/7.x", "instruction": "I need the code for `watchdog_severity_levels()` in Drupal 7 (includes/common.inc). It must do this: Returns a list of severity levels, as defined in RFC 3164.", "context": "Returns (Array): of the possible severity levels for log messages.\n\nFile: includes/common.inc", "response": "function watchdog_severity_levels() {\n return array(\n WATCHDOG_EMERGENCY => t('emergency'),\n WATCHDOG_ALERT => t('alert'),\n WATCHDOG_CRITICAL => t('critical'),\n WATCHDOG_ERROR => t('error'),\n WATCHDOG_WARNING => t('warning'),\n WATCHDOG_NOTICE => t('notice'),\n WATCHDOG_INFO => t('info'),\n WATCHDOG_DEBUG => t('debug'),\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-368691aee2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_delete_submit/7.x", "instruction": "I need the code for `shortcut_link_delete_submit($form, &$form_state)` in Drupal 7 (modules/shortcut/shortcut.admin.inc). It must do this: Submit handler for shortcut_link_delete_submit().", "context": "File: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_link_delete_submit($form, &$form_state) {\n $shortcut_link = $form_state['values']['shortcut_link'];\n menu_link_delete($shortcut_link['mlid']);\n $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $shortcut_link['menu_name'];\n drupal_set_message(t('The shortcut %title has been deleted.', array('%title' => $shortcut_link['link_title'])));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-36942528c6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_help/7.x", "instruction": "Implement `poll_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/poll/poll.module", "response": "function poll_help($path, $arg) {\n switch ($path) {\n case 'admin/help#poll':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Poll module can be used to create simple surveys or questionnaires that display cumulative results. A poll is a good way to receive feedback from site users and community members. For more information, see the online handbook entry for the Poll module.', array('@poll' => 'http://drupal.org/documentation/modules/poll/')) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Creating a poll') . '
            ';\n $output .= '
            ' . t('Users can create a poll by clicking on Poll on the Add new content page, and entering the question being posed, the answer choices, and beginning vote counts for each choice. The status (closed or active) and duration (length of time the poll remains active for new votes) can also be specified.', array('@add-content' => url('node/add'))) . '
            ';\n $output .= '
            ' . t('Viewing polls') . '
            ';\n $output .= '
            ' . t('You can visit the Polls page to view all current polls, or alternately enable the Most recent poll block on the Blocks administration page. To vote in or view the results of a specific poll, you can click on the poll itself.', array('@poll' => url('poll'), '@blocks' => url('admin/structure/block'))) . '
            ';\n $output .= '
            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-36a803cc58", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_tree_data/7.x", "instruction": "Implement `_menu_tree_data(&$links, $parents, $depth)` in PHP for Drupal 7. Required behavior: Builds the data representing a menu tree.", "context": "The function is a bit complex because the rendering of a link depends on the next menu link.\n\nFile: includes/menu.inc", "response": "function _menu_tree_data(&$links, $parents, $depth) {\n $tree = array();\n while ($item = array_pop($links)) {\n // We need to determine if we're on the path to root so we can later build\n // the correct active trail and breadcrumb.\n $item['in_active_trail'] = in_array($item['mlid'], $parents);\n // Add the current link to the tree.\n $tree[$item['mlid']] = array(\n 'link' => $item,\n 'below' => array(),\n );\n // Look ahead to the next link, but leave it on the array so it's available\n // to other recursive function calls if we return or build a sub-tree.\n $next = end($links);\n // Check whether the next link is the first in a new sub-tree.\n if ($next && $next['depth'] > $depth) {\n // Recursively call _menu_tree_data to build the sub-tree.\n $tree[$item['mlid']]['below'] = _menu_tree_data($links, $parents, $next['depth']);\n // Fetch next link after filling the sub-tree.\n $next = end($links);\n }\n // Determine if we should exit the loop and return.\n if (!$next || $next['depth'] < $depth) {\n break;\n }\n }\n return $tree;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-36b649b5b4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/weight_value/7.x", "instruction": "Implement `weight_value(&$form)` in PHP for Drupal 7. Required behavior: Sets the value for a weight element, with zero as a default.", "context": "File: includes/form.inc", "response": "function weight_value(&$form) {\n if (isset($form['#default_value'])) {\n $form['#value'] = $form['#default_value'];\n }\n else {\n $form['#value'] = 0;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-36dba7a052", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7063/7.x", "instruction": "In Drupal 7, write the function `system_update_7063()` (file modules/system/system.install) so that it does the following: Delete {menu_links} records for 'type' => MENU_CALLBACK which would not appear in a fresh install.", "context": "File: modules/system/system.install", "response": "function system_update_7063() {\n // For router items where 'type' => MENU_CALLBACK, {menu_router}.type is\n // stored as 4 in Drupal 6, and 0 in Drupal 7. Fortunately Drupal 7 doesn't\n // store any types as 4, so delete both.\n $result = db_query('SELECT ml.mlid FROM {menu_links} ml INNER JOIN {menu_router} mr ON ml.router_path = mr.path WHERE ml.module = :system AND ml.customized = 0 AND mr.type IN(:callbacks)', array(':callbacks' => array(0, 4), ':system' => 'system'));\n foreach ($result as $record) {\n db_delete('menu_links')->condition('mlid', $record->mlid)->execute();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-36efac515b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21module.inc/function/drupal_required_modules/7.x", "instruction": "In Drupal 7, write the function `drupal_required_modules()` (file includes/module.inc) so that it does the following: Returns an array of modules required by core.", "context": "File: includes/module.inc", "response": "function drupal_required_modules() {\n $files = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\\.info$/', 'modules', 'name', 0);\n $required = array();\n\n // An installation profile is required and one must always be loaded.\n $required[] = drupal_get_profile();\n\n foreach ($files as $name => $file) {\n $info = drupal_parse_info_file($file->uri);\n if (!empty($info) && !empty($info['required']) && $info['required']) {\n $required[] = $name;\n }\n }\n\n return $required;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-370e2be0c3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_filters/7.x", "instruction": "Implement `user_filters()` in PHP for Drupal 7. Required behavior: List user administration filters that can be applied.", "context": "File: modules/user/user.module", "response": "function user_filters() {\n // Regular filters\n $filters = array();\n $roles = user_roles(TRUE);\n unset($roles[DRUPAL_AUTHENTICATED_RID]); // Don't list authorized role.\n if (count($roles)) {\n $filters['role'] = array(\n 'title' => t('role'),\n 'field' => 'ur.rid',\n 'options' => array(\n '[any]' => t('any'),\n ) + $roles,\n );\n }\n\n $options = array();\n foreach (module_implements('permission') as $module) {\n $function = $module . '_permission';\n if ($permissions = $function()) {\n asort($permissions);\n foreach ($permissions as $permission => $description) {\n $options[t('@module module', array('@module' => $module))][$permission] = t($permission);\n }\n }\n }\n ksort($options);\n $filters['permission'] = array(\n 'title' => t('permission'),\n 'options' => array(\n '[any]' => t('any'),\n ) + $options,\n );\n\n $filters['status'] = array(\n 'title' => t('status'),\n 'field' => 'u.status',\n 'options' => array(\n '[any]' => t('any'),\n 1 => t('active'),\n 0 => t('blocked'),\n ),\n );\n return $filters;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-371fee4d67", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21help%21help.admin.inc/function/help_page/7.x", "instruction": "I need the code for `help_page($name)` in Drupal 7 (modules/help/help.admin.inc). It must do this: Menu callback; prints a page listing general help for a module.", "context": "Parameters:\n- $name: A module name to display a help page for.\n\nFile: modules/help/help.admin.inc", "response": "function help_page($name) {\n $output = '';\n if (module_hook($name, 'help')) {\n $info = system_get_info('module');\n drupal_set_title($info[$name]['name']);\n\n $temp = module_invoke($name, 'help', \"admin/help#$name\", drupal_help_arg());\n if (empty($temp)) {\n $output .= t(\"No help is available for module %module.\", array('%module' => $info[$name]['name']));\n }\n else {\n $output .= $temp;\n }\n\n // Only print list of administration pages if the module in question has\n // any such pages associated to it.\n $admin_tasks = system_get_module_admin_tasks($name, $info[$name]);\n if (!empty($admin_tasks)) {\n $links = array();\n foreach ($admin_tasks as $task) {\n $links[] = l($task['title'], $task['link_path'], $task['localized_options']);\n }\n $output .= theme('item_list', array('items' => $links, 'title' => t('@module administration pages', array('@module' => $info[$name]['name']))));\n }\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3730f87187", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/profiles%21standard%21standard.profile/function/standard_form_install_configure_form_alter/7.x", "instruction": "Implement `standard_form_install_configure_form_alter(&$form, $form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter() for install_configure_form().", "context": "Allows the profile to alter the site configuration form.\n\nFile: profiles/standard/standard.profile", "response": "function standard_form_install_configure_form_alter(&$form, $form_state) {\n // Pre-populate the site name with the server name.\n $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-37375b3327", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load/7.x", "instruction": "Implement `user_load($uid, $reset = FALSE)` in PHP for Drupal 7. Required behavior: Loads a user object.", "context": "Drupal has a global $user object, which represents the currently-logged-in user. So to avoid confusion and to avoid clobbering the global $user object, it is a good idea to assign the result of this function to a different local variable, generally $account. If you actually do want to act as the user you are loading, it is essential to call drupal_save_session(FALSE); first. See\n\nParameters:\n- $uid: Integer specifying the user ID to load.\n- $reset: TRUE to reset the internal cache and load from the database; FALSE (default) to load from the internal cache, if set.\n\nReturns: A fully-loaded user object upon successful user load, or FALSE if the user cannot be loaded.\n\nFile: modules/user/user.module", "response": "function user_load($uid, $reset = FALSE) {\n $users = user_load_multiple(array($uid), array(), $reset);\n return reset($users);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-37406685a9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.api.php/function/hook_taxonomy_vocabulary_delete/7.x", "instruction": "Give me the example code for `hook_taxonomy_vocabulary_delete($vocabulary)` in Drupal 7. Hook description: Respond to the deletion of taxonomy vocabularies.", "context": "Modules implementing this hook can respond to the deletion of taxonomy vocabularies from the database.\n\nParameters:\n- $vocabulary: A taxonomy vocabulary object.\n\nFile: modules/taxonomy/taxonomy.api.php", "response": "function hook_taxonomy_vocabulary_delete($vocabulary) {\n db_delete('mytable')\n ->condition('vid', $vocabulary->vid)\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3786770f20", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_menu_delete/7.x", "instruction": "Implement `block_menu_delete($menu)` in PHP for Drupal 7. Required behavior: Implements hook_menu_delete().", "context": "File: modules/block/block.module", "response": "function block_menu_delete($menu) {\n db_delete('block')\n ->condition('module', 'menu')\n ->condition('delta', $menu['menu_name'])\n ->execute();\n db_delete('block_role')\n ->condition('module', 'menu')\n ->condition('delta', $menu['menu_name'])\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-379f8248a2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/variable_get/7.x", "instruction": "I need the code for `variable_get($name, $default = NULL)` in Drupal 7 (includes/bootstrap.inc). It must do this: Returns a persistent variable.", "context": "Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.\n\nParameters:\n- $name: The name of the variable to return.\n- $default: The default value to use if this variable has never been set.\n\nReturns: The value of the variable. Unserialization is taken care of as necessary.\n\nFile: includes/bootstrap.inc", "response": "function variable_get($name, $default = NULL) {\n global $conf;\n\n return isset($conf[$name]) ? $conf[$name] : $default;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-379fb0c2d2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_download/7.x", "instruction": "In Drupal 7, write the function `file_download()` (file includes/file.inc) so that it does the following: Menu handler for private file transfers.", "context": "Call modules that implement hook_file_download() to find out if a file is accessible and what headers it should be transferred with. If one or more modules returned headers the download will start with the returned headers. If a module returns -1 drupal_access_denied() will be returned. If the file exists but no modules responded drupal_access_denied() will be returned. If the file does not exist drupal_not_found() will be returned.\n\nFile: includes/file.inc", "response": "function file_download() {\n // Merge remainder of arguments from GET['q'], into relative file path.\n $args = func_get_args();\n $scheme = array_shift($args);\n $target = implode('/', $args);\n $uri = $scheme . '://' . $target;\n $uri = file_uri_normalize_dot_segments($uri);\n if (file_stream_wrapper_valid_scheme($scheme) && is_file($uri)) {\n $headers = file_download_headers($uri);\n if (count($headers)) {\n file_transfer($uri, $headers);\n }\n drupal_access_denied();\n }\n else {\n drupal_not_found();\n }\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-37a6716761", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_block_view/7.x", "instruction": "Implement `shortcut_block_view($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_view().", "context": "File: modules/shortcut/shortcut.module", "response": "function shortcut_block_view($delta = '') {\n if ($delta == 'shortcuts') {\n $shortcut_set = shortcut_current_displayed_set();\n $data['subject'] = t('@shortcut_set shortcuts', array('@shortcut_set' => $shortcut_set->title));\n $data['content'] = shortcut_renderable_links($shortcut_set);\n return $data;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-37ab6ac85a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_access/7.x", "instruction": "In Drupal 7, write the function `filter_access($format, $account = NULL)` (file modules/filter/filter.module) so that it does the following: Checks if a user has access to a particular text format.", "context": "Parameters:\n- $format: An object representing the text format.\n- $account: (optional) The user account to check access for; if omitted, the currently logged-in user is used. Defaults to NULL.\n\nReturns (Boolean): TRUE if the user is allowed to access the given format.\n\nFile: modules/filter/filter.module", "response": "function filter_access($format, $account = NULL) {\n global $user;\n if (!isset($account)) {\n $account = $user;\n }\n // Handle special cases up front. All users have access to the fallback\n // format.\n if ($format->format == filter_fallback_format()) {\n return TRUE;\n }\n // Check the permission if one exists; otherwise, we have a non-existent\n // format so we return FALSE.\n $permission = filter_permission_name($format);\n return !empty($permission) && user_access($permission, $account);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-37c5ec6604", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_field_settings/7.x", "instruction": "I need the code for `field_info_field_settings($type)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns a field type's default settings.", "context": "Parameters:\n- $type: A field type name.\n\nReturns: The field type's default settings, as provided by hook_field_info(), or an empty array if type or settings are not defined.\n\nFile: modules/field/field.info.inc", "response": "function field_info_field_settings($type) {\n $info = field_info_field_types($type);\n return isset($info['settings']) ? $info['settings'] : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-37cdeac726", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.tokens.inc/function/system_token_info/7.x", "instruction": "Implement `system_token_info()` in PHP for Drupal 7. Required behavior: Implements hook_token_info().", "context": "File: modules/system/system.tokens.inc", "response": "function system_token_info() {\n $types['site'] = array(\n 'name' => t(\"Site information\"),\n 'description' => t(\"Tokens for site-wide settings and other global information.\"),\n );\n $types['date'] = array(\n 'name' => t(\"Dates\"),\n 'description' => t(\"Tokens related to times and dates.\"),\n );\n $types['file'] = array(\n 'name' => t(\"Files\"),\n 'description' => t(\"Tokens related to uploaded files.\"),\n 'needs-data' => 'file',\n );\n\n // Site-wide global tokens.\n $site['name'] = array(\n 'name' => t(\"Name\"),\n 'description' => t(\"The name of the site.\"),\n );\n $site['slogan'] = array(\n 'name' => t(\"Slogan\"),\n 'description' => t(\"The slogan of the site.\"),\n );\n $site['mail'] = array(\n 'name' => t(\"Email\"),\n 'description' => t(\"The administrative email address for the site.\"),\n );\n $site['url'] = array(\n 'name' => t(\"URL\"),\n 'description' => t(\"The URL of the site's front page.\"),\n );\n $site['url-brief'] = array(\n 'name' => t(\"URL (brief)\"),\n 'description' => t(\"The URL of the site's front page without the protocol.\"),\n );\n $site['login-url'] = array(\n 'name' => t(\"Login page\"),\n 'description' => t(\"The URL of the site's login page.\"),\n );\n\n // Date related tokens.\n $date['short'] = array(\n 'name' => t(\"Short format\"),\n 'description' => t(\"A date in 'short' format. (%date)\", array('%date' => format_date(REQUEST_TIME, 'short'))),\n );\n $date['medium'] = array(\n 'name' => t(\"Medium format\"),\n 'description' => t(\"A date in 'medium' format. (%date)\", array('%date' => format_date(REQUEST_TIME, 'medium'))),\n );\n $date['long'] = array(\n 'name' => t(\"Long format\"),\n 'description' => t(\"A date in 'long' format. (%date)\", array('%date' => format_date(REQUEST_TIME, 'long'))),\n );\n $date['custom'] = array(\n 'name' => t(\"Custom format\"),\n 'description' => t(\"A date in a custom format. See !php-date for details.\", array('!php-date' => l(t('the PHP documentation'), 'http://php.net/manual/en/function.date.php'))),\n );\n $date['since'] = array(\n 'name' => t(\"Time-since\"),\n 'description' => t(\"A date in 'time-since' format. (%date)\", array('%date' => format_interval(REQUEST_TIME - 360, 2))),\n );\n $date['raw'] = array(\n 'name' => t(\"Raw timestamp\"),\n 'description' => t(\"A date in UNIX timestamp format (%date)\", array('%date' => REQUEST_TIME)),\n );\n\n\n // File related tokens.\n $file['fid'] = array(\n 'name' => t(\"File ID\"),\n 'description' => t(\"The unique ID of the uploaded file.\"),\n );\n $file['name'] = array(\n 'name' => t(\"File name\"),\n 'description' => t(\"The name of the file on disk.\"),\n );\n $file['path'] = array(\n 'name' => t(\"Path\"),\n 'description' => t(\"The location of the file relative to Drupal root.\"),\n );\n $file['mime'] = array(\n 'name' => t(\"MIME type\"),\n 'description' => t(\"The MIME type of the file.\"),\n );\n $file['size'] = array(\n 'name' => t(\"File size\"),\n 'description' => t(\"The size of the file.\"),\n );\n $file['url'] = array(\n 'name' => t(\"URL\"),\n 'description' => t(\"The web-accessible URL for the file.\"),\n );\n $file['timestamp'] = array(\n 'name' => t(\"Timestamp\"),\n 'description' => t(\"The date the file was most recently changed.\"),\n 'type' => 'date',\n );\n $file['owner'] = array(\n 'name' => t(\"Owner\"),\n 'description' => t(\"The user who originally uploaded the file.\"),\n 'type' => 'user',\n );\n\n return array(\n 'types' => $types,\n 'tokens' => array(\n 'site' => $site,\n 'date' => $date,\n 'file' => $file,\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-37cf5d537d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_overlay_child_initialize/7.x", "instruction": "I need the code for `overlay_overlay_child_initialize()` in Drupal 7 (modules/overlay/overlay.module). It must do this: Implements hook_overlay_child_initialize().", "context": "File: modules/overlay/overlay.module", "response": "function overlay_overlay_child_initialize() {\n // Check if the parent window needs to refresh any page regions on this page\n // request.\n overlay_trigger_refresh();\n // If this is a POST request, or a GET request with a token parameter, we\n // have an indication that something in the supplemental regions of the\n // overlay might change during the current page request. We therefore store\n // the initial rendered content of those regions here, so that we can compare\n // it to the same content rendered in overlay_exit(), at the end of the page\n // request. This allows us to check if anything actually did change, and, if\n // so, trigger an immediate Ajax refresh of the parent window.\n if (!empty($_POST) || isset($_GET['token'])) {\n foreach (overlay_supplemental_regions() as $region) {\n overlay_store_rendered_content($region, overlay_render_region($region));\n }\n // In addition, notify the parent window that when the overlay closes,\n // the entire parent window should be refreshed.\n overlay_request_page_refresh();\n }\n // Indicate that when the main page rendering occurs later in the page\n // request, only the regions that appear within the overlay should be\n // rendered.\n overlay_set_regions_to_render(overlay_regions());\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-37e5d5f24c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_formatter_view/7.x", "instruction": "I need the code for `number_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` in Drupal 7 (modules/field/modules/number/number.module). It must do this: Implements hook_field_formatter_view().", "context": "File: modules/field/modules/number/number.module", "response": "function number_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {\n $element = array();\n $settings = $display['settings'];\n\n switch ($display['type']) {\n case 'number_integer':\n case 'number_decimal':\n foreach ($items as $delta => $item) {\n $output = number_format($item['value'], $settings['scale'], $settings['decimal_separator'], $settings['thousand_separator']);\n if ($settings['prefix_suffix']) {\n $prefixes = isset($instance['settings']['prefix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['prefix'])) : array('');\n $suffixes = isset($instance['settings']['suffix']) ? array_map('field_filter_xss', explode('|', $instance['settings']['suffix'])) : array('');\n $prefix = (count($prefixes) > 1) ? format_plural($item['value'], $prefixes[0], $prefixes[1]) : $prefixes[0];\n $suffix = (count($suffixes) > 1) ? format_plural($item['value'], $suffixes[0], $suffixes[1]) : $suffixes[0];\n $output = $prefix . $output . $suffix;\n }\n $element[$delta] = array('#markup' => $output);\n }\n break;\n\n case 'number_unformatted':\n foreach ($items as $delta => $item) {\n $element[$delta] = array('#markup' => $item['value']);\n }\n break;\n }\n\n return $element;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-37f753a6e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/_shortcut_link_form_elements/7.x", "instruction": "Implement `_shortcut_link_form_elements($shortcut_link = NULL)` in PHP for Drupal 7. Required behavior: Helper function for building a form for adding or editing shortcut links.", "context": "Parameters:\n- $shortcut_link: (optional) An array representing the shortcut link that will be edited. If not provided, a new link will be created.\n\nReturns: An array of form elements.\n\nFile: modules/shortcut/shortcut.admin.inc", "response": "function _shortcut_link_form_elements($shortcut_link = NULL) {\n if (!isset($shortcut_link)) {\n $shortcut_link = array(\n 'link_title' => '',\n 'link_path' => ''\n );\n }\n else {\n $shortcut_link['link_path'] = ($shortcut_link['link_path'] == '') ? '' : drupal_get_path_alias($shortcut_link['link_path']);\n }\n\n $form['shortcut_link']['#tree'] = TRUE;\n $form['shortcut_link']['link_title'] = array(\n '#type' => 'textfield',\n '#title' => t('Name'),\n '#description' => t('The name of the shortcut.'),\n '#size' => 40,\n '#maxlength' => 255,\n '#default_value' => $shortcut_link['link_title'],\n '#required' => TRUE,\n );\n\n $form['shortcut_link']['link_path'] = array(\n '#type' => 'textfield',\n '#title' => t('Path'),\n '#description' => t('The path to the shortcut.'),\n '#size' => 40,\n '#maxlength' => 255,\n '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),\n '#default_value' => $shortcut_link['link_path'],\n );\n\n $form['#validate'][] = 'shortcut_link_edit_validate';\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-38066245d2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_update_7004/7.x", "instruction": "I need the code for `locale_update_7004()` in Drupal 7 (modules/locale/locale.install). It must do this: Remove duplicates in {locales_source}.", "context": "File: modules/locale/locale.install", "response": "function locale_update_7004() {\n // Look up all duplicates. For each set of duplicates, we select the row\n // with the lowest lid as the \"master\" that will be preserved.\n $result_source = db_query(\"SELECT MIN(lid) AS lid, source, context FROM {locales_source} WHERE textgroup = 'default' GROUP BY source, context HAVING COUNT(*) > 1\");\n\n $conflict = FALSE;\n foreach ($result_source as $source) {\n // Find all rows in {locales_target} that are translations of the same\n // string (incl. context).\n $result_target = db_query(\"SELECT t.lid, t.language, t.plural, t.translation FROM {locales_source} s JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default' ORDER BY lid\", array(\n ':source' => $source->source,\n ':context' => $source->context,\n ));\n\n $translations = array();\n $keep_lids = array($source->lid);\n foreach ($result_target as $target) {\n if (!isset($translations[$target->language])) {\n $translations[$target->language] = $target->translation;\n if ($target->lid != $source->lid) {\n // Move translation to the master lid.\n db_query('UPDATE {locales_target} SET lid = :new_lid WHERE lid = :old_lid', array(\n ':new_lid' => $source->lid,\n ':old_lid' => $target->lid));\n }\n }\n elseif ($translations[$target->language] == $target->translation) {\n // Delete duplicate translation.\n db_query('DELETE FROM {locales_target} WHERE lid = :lid AND language = :language', array(\n ':lid' => $target->lid,\n ':language' => $target->language));\n }\n else {\n // The same string is translated into several different strings in one\n // language. We do not know which is the preferred, so we keep them all.\n $keep_lids[] = $target->lid;\n $conflict = TRUE;\n }\n }\n\n // Delete rows in {locales_source} that are no longer referenced from\n // {locales_target}.\n db_delete('locales_source')\n ->condition('source', $source->source)\n ->condition('context', $source->context)\n ->condition('textgroup', 'default')\n ->condition('lid', $keep_lids, 'NOT IN')\n ->execute();\n }\n\n if ($conflict) {\n $url = 'http://drupal.org/node/746240';\n drupal_set_message('Your {locales_source} table contains duplicates that could not be removed automatically. See ' . $url . ' for more information.', 'warning');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-38068e66fb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_schema/7.x", "instruction": "I need the code for `_field_sql_storage_schema($field)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Return the database schema for a field. This may contain one or more tables. Each table will contain the columns relevant for the specified field. Leave the $field's 'columns' and 'indexes' keys empty to get only the base schema.", "context": "Parameters:\n- $field: The field structure for which to generate a database schema.\n\nReturns: One or more tables representing the schema for the field.\n\nFile: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function _field_sql_storage_schema($field) {\n $deleted = $field['deleted'] ? 'deleted ' : '';\n $current = array(\n 'description' => \"Data storage for {$deleted}field {$field['id']} ({$field['field_name']})\",\n 'fields' => array(\n 'entity_type' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The entity type this data is attached to',\n ),\n 'bundle' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The field instance bundle to which this row belongs, used when deleting a field instance',\n ),\n 'deleted' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'A boolean indicating whether this data item has been deleted'\n ),\n 'entity_id' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'description' => 'The entity id this data is attached to',\n ),\n 'revision_id' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => FALSE,\n 'description' => 'The entity revision id this data is attached to, or NULL if the entity type is not versioned',\n ),\n // @todo Consider storing language as integer.\n 'language' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The language for this data item.',\n ),\n 'delta' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'description' => 'The sequence number for this data item, used for multi-value fields',\n ),\n ),\n 'primary key' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),\n 'indexes' => array(\n 'entity_type' => array('entity_type'),\n 'bundle' => array('bundle'),\n 'deleted' => array('deleted'),\n 'entity_id' => array('entity_id'),\n 'revision_id' => array('revision_id'),\n 'language' => array('language'),\n ),\n );\n\n // If the target entity type uses a string for its entity ID then update\n // the fields entity_id and revision_id columns from INT to VARCHAR.\n if (!empty($field['entity_id_type']) && $field['entity_id_type'] === 'string') {\n $current['fields']['entity_id']['type'] = 'varchar';\n $current['fields']['entity_id']['length'] = 128;\n unset($current['fields']['entity_id']['unsigned']);\n\n $current['fields']['revision_id']['type'] = 'varchar';\n $current['fields']['revision_id']['length'] = 128;\n unset($current['fields']['revision_id']['unsigned']);\n }\n\n $field += array('columns' => array(), 'indexes' => array(), 'foreign keys' => array());\n // Add field columns.\n foreach ($field['columns'] as $column_name => $attributes) {\n $real_name = _field_sql_storage_columnname($field['field_name'], $column_name);\n $current['fields'][$real_name] = $attributes;\n }\n\n // Add indexes.\n foreach ($field['indexes'] as $index_name => $columns) {\n $real_name = _field_sql_storage_indexname($field['field_name'], $index_name);\n foreach ($columns as $column_name) {\n // Indexes can be specified as either a column name or an array with\n // column name and length. Allow for either case.\n if (is_array($column_name)) {\n $current['indexes'][$real_name][] = array(\n _field_sql_storage_columnname($field['field_name'], $column_name[0]),\n $column_name[1],\n );\n }\n else {\n $current['indexes'][$real_name][] = _field_sql_storage_columnname($field['field_name'], $column_name);\n }\n }\n }\n\n // Add foreign keys.\n foreach ($field['foreign keys'] as $specifier => $specification) {\n $real_name = _field_sql_storage_indexname($field['field_name'], $specifier);\n $current['foreign keys'][$real_name]['table'] = $specification['table'];\n foreach ($specification['columns'] as $column_name => $referenced) {\n $sql_storage_column = _field_sql_storage_columnname($field['field_name'], $column_name);\n $current['foreign keys'][$real_name]['columns'][$sql_storage_column] = $referenced;\n }\n }\n\n // Construct the revision table.\n $revision = $current;\n $revision['description'] = \"Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})\";\n $revision['primary key'] = array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language');\n $revision['fields']['revision_id']['not null'] = TRUE;\n $revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';\n\n return array(\n _field_sql_storage_tablename($field) => $current,\n _field_sql_storage_revision_tablename($field) => $revision,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-383201f226", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_permission/7.x", "instruction": "In Drupal 7, write the function `node_permission()` (file modules/node/node.module) so that it does the following: Implements hook_permission().", "context": "File: modules/node/node.module", "response": "function node_permission() {\n $perms = array(\n 'bypass node access' => array(\n 'title' => t('Bypass content access control'),\n 'description' => t('View, edit and delete all content regardless of permission restrictions.'),\n 'restrict access' => TRUE,\n ),\n 'administer content types' => array(\n 'title' => t('Administer content types'),\n 'restrict access' => TRUE,\n ),\n 'administer nodes' => array(\n 'title' => t('Administer content'),\n 'restrict access' => TRUE,\n ),\n 'access content overview' => array(\n 'title' => t('Access the content overview page'),\n 'description' => t('Get an overview of all content.', array('@url' => url('admin/content'))),\n ),\n 'access content' => array(\n 'title' => t('View published content'),\n ),\n 'view own unpublished content' => array(\n 'title' => t('View own unpublished content'),\n ),\n 'view revisions' => array(\n 'title' => t('View content revisions'),\n ),\n 'revert revisions' => array(\n 'title' => t('Revert content revisions'),\n ),\n 'delete revisions' => array(\n 'title' => t('Delete content revisions'),\n ),\n );\n\n // Generate standard node permissions for all applicable node types.\n foreach (node_permissions_get_configured_types() as $type) {\n $perms += node_list_permissions($type);\n }\n\n return $perms;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3837dc3d84", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_image_button_value/7.x", "instruction": "In Drupal 7, write the function `form_type_image_button_value($form, $input, $form_state)` (file includes/form.inc) so that it does the following: Determines the value for an image button form element.", "context": "Parameters:\n- $form: The form element whose value is being populated.\n- $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.\n- $form_state: A keyed array containing the current state of the form.\n\nReturns: The data that will appear in $form_state['values'] for this element, or nothing to use the default.\n\nFile: includes/form.inc", "response": "function form_type_image_button_value($form, $input, $form_state) {\n if ($input !== FALSE) {\n if (!empty($input)) {\n // If we're dealing with Mozilla or Opera, we're lucky. It will\n // return a proper value, and we can get on with things.\n return $form['#return_value'];\n }\n else {\n // Unfortunately, in IE we never get back a proper value for THIS\n // form element. Instead, we get back two split values: one for the\n // X and one for the Y coordinates on which the user clicked the\n // button. We'll find this element in the #post data, and search\n // in the same spot for its name, with '_x'.\n $input = $form_state['input'];\n foreach (explode('[', $form['#name']) as $element_name) {\n // chop off the ] that may exist.\n if (substr($element_name, -1) == ']') {\n $element_name = substr($element_name, 0, -1);\n }\n\n if (!isset($input[$element_name])) {\n if (isset($input[$element_name . '_x'])) {\n return $form['#return_value'];\n }\n return NULL;\n }\n $input = $input[$element_name];\n }\n return $form['#return_value'];\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-38397b0901", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.admin.inc/function/comment_confirm_delete_submit/7.x", "instruction": "In Drupal 7, write the function `comment_confirm_delete_submit($form, &$form_state)` (file modules/comment/comment.admin.inc) so that it does the following: Process comment_confirm_delete form submissions.", "context": "File: modules/comment/comment.admin.inc", "response": "function comment_confirm_delete_submit($form, &$form_state) {\n $comment = $form['#comment'];\n // Delete the comment and its replies.\n comment_delete($comment->cid);\n drupal_set_message(t('The comment and all its replies have been deleted.'));\n watchdog('content', 'Deleted comment @cid and its replies.', array('@cid' => $comment->cid));\n // Clear the cache so an anonymous user sees that his comment was deleted.\n cache_clear_all();\n\n $form_state['redirect'] = \"node/$comment->nid\";\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3855d293e6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7012/7.x", "instruction": "Implement `node_update_7012()` in PHP for Drupal 7. Required behavior: Switches body fields to untranslatable while upgrading from D6 and makes them language neutral.", "context": "File: modules/node/node.install", "response": "function node_update_7012() {\n // If we are upgrading from D6, then body fields should be set back to\n // untranslatable, as D6 did not know about the idea of translating fields,\n // but only nodes. If a D7 > D7 update is running we need to skip this update,\n // as it is a valid use case to have translatable body fields in this context.\n if (variable_get('update_d6', FALSE)) {\n // Make node bodies untranslatable: field_update_field() cannot be used\n // throughout the upgrade process and we do not have an update counterpart\n // for _update_7000_field_create_field(). Hence we are forced to update the\n // 'field_config' table directly. This is a safe operation since it is\n // being performed while upgrading from D6. Perfoming the same operation\n // during a D7 update is highly discouraged.\n db_update('field_config')\n ->fields(array('translatable' => 0))\n ->condition('field_name', 'body')\n ->execute();\n\n // Switch field languages to LANGUAGE_NONE, since initially they were\n // assigned the node language.\n foreach (array('field_data_body', 'field_revision_body') as $table) {\n db_update($table)\n ->fields(array('language' => LANGUAGE_NONE))\n ->execute();\n }\n\n node_type_cache_reset();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-38688dbc40", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.install/function/menu_update_7001/7.x", "instruction": "In Drupal 7, write the function `menu_update_7001()` (file modules/menu/menu.install) so that it does the following: Rename \"Primary Links\" and \"Secondary Links\" to their Drupal 7 equivalents.", "context": "File: modules/menu/menu.install", "response": "function menu_update_7001() {\n // Migrate D6 menu_primary_links_source to D7 menu_main_links_source (without\n // renaming).\n if (variable_get('menu_primary_links_source') !== NULL) {\n variable_set('menu_main_links_source', variable_get('menu_primary_links_source'));\n variable_del('menu_primary_links_source');\n }\n\n // Rename each menu, and any settings that refer to the old menu name.\n // - \"Primary Links\" has become system menu \"Main menu\".\n // - \"Secondary Links\" has become a new custom menu \"Secondary menu\".\n $rename = array(\n 'primary-links' => array('main-menu', 'Main menu'),\n 'secondary-links' => array('secondary-menu', 'Secondary menu'),\n );\n foreach ($rename as $from_menu => $to) {\n list($to_menu, $to_title) = $to;\n // Rename the menu, and links in the menu.\n db_update('menu_custom')\n ->fields(array('menu_name' => $to_menu, 'title' => $to_title))\n ->condition('menu_name', $from_menu)\n ->execute();\n db_update('menu_links')\n ->fields(array('menu_name' => $to_menu))\n ->condition('menu_name', $from_menu)\n ->execute();\n\n // Update any content type that used this menu as a default menu.\n // Note: these variables may be unset/default, in which case we leave them\n // alone. See menu_update_7000()\n foreach (_update_7000_node_get_types() as $type => $type_object) {\n $menu_options = variable_get('menu_options_' . $type);\n if ($menu_options !== NULL) {\n variable_set('menu_options_' . $type, str_replace($from_menu, $to_menu, $menu_options));\n if (variable_get('menu_parent_' . $type) == $from_menu . ':0') {\n variable_set('menu_parent_' . $type, $to_menu . ':0');\n }\n }\n }\n\n // Update the \"source for primary links\" and \"source for secondary links\" to\n // follow.\n if (variable_get('menu_main_links_source') == $from_menu) {\n variable_set('menu_main_links_source', $to_menu);\n }\n if (variable_get('menu_secondary_links_source') == $from_menu) {\n variable_set('menu_secondary_links_source', $to_menu);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3876a20d2e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7010/7.x", "instruction": "I need the code for `taxonomy_update_7010()` in Drupal 7 (modules/taxonomy/taxonomy.install). It must do this: Change {taxonomy_index}.created to support signed int.", "context": "File: modules/taxonomy/taxonomy.install", "response": "function taxonomy_update_7010() {\n db_change_field('taxonomy_index', 'created', 'created', array(\n 'description' => 'The Unix timestamp when the node was created.',\n 'type' => 'int',\n 'unsigned' => FALSE,\n 'not null' => TRUE,\n 'default'=> 0,\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-388ad4824d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/drupal_theme_rebuild/7.x", "instruction": "Implement `drupal_theme_rebuild()` in PHP for Drupal 7. Required behavior: Forces the system to rebuild the theme registry.", "context": "This function should be called when modules are added to the system, or when a dynamic system needs to add more theme hooks.\n\nFile: includes/theme.inc", "response": "function drupal_theme_rebuild() {\n drupal_static_reset('theme_get_registry');\n cache_clear_all('theme_registry', 'cache', TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-389a566d48", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_purge_batch/7.x", "instruction": "In Drupal 7, write the function `field_purge_batch($batch_size)` (file modules/field/field.crud.inc) so that it does the following: Purges a batch of deleted Field API data, instances, or fields.", "context": "This function will purge deleted field data in batches. The batch size is defined as an argument to the function, and once each batch is finished, it continues with the next batch until all have completed. If a deleted field instance with no remaining data records is found, the instance itself will be purged. If a deleted field with no remaining field instances is found, the field itself will be purged.\n\nParameters:\n- $batch_size: The maximum number of field data records to purge before returning.\n\nFile: modules/field/field.crud.inc", "response": "function field_purge_batch($batch_size) {\n // Retrieve all deleted field instances. We cannot use field_info_instances()\n // because that function does not return deleted instances.\n $instances = field_read_instances(array('deleted' => 1), array('include_deleted' => 1));\n\n foreach ($instances as $instance) {\n // field_purge_data() will need the field array.\n $field = field_info_field_by_id($instance['field_id']);\n // Retrieve some entities.\n $query = new EntityFieldQuery();\n $results = $query\n ->fieldCondition($field)\n ->entityCondition('bundle', $instance['bundle'])\n ->deleted(TRUE)\n ->range(0, $batch_size)\n ->execute();\n\n if ($results) {\n foreach ($results as $entity_type => $stub_entities) {\n field_attach_load($entity_type, $stub_entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1));\n foreach ($stub_entities as $stub_entity) {\n // Purge the data for the entity.\n field_purge_data($entity_type, $stub_entity, $field, $instance);\n }\n }\n }\n else {\n // No field data remains for the instance, so we can remove it.\n field_purge_instance($instance);\n }\n }\n\n // Retrieve all deleted fields. Any that have no instances can be purged.\n $fields = field_read_fields(array('deleted' => 1), array('include_deleted' => 1));\n foreach ($fields as $field) {\n $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => 1));\n if (empty($instances)) {\n field_purge_field($field);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-38a86c952b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_user_insert/7.x", "instruction": "I need the code for `openid_user_insert(&$edit, $account, $category)` in Drupal 7 (modules/openid/openid.module). It must do this: Implements hook_user_insert().", "context": "File: modules/openid/openid.module", "response": "function openid_user_insert(&$edit, $account, $category) {\n if (!empty($edit['openid_claimed_id'])) {\n // The user has registered after trying to log in via OpenID.\n if (variable_get('user_email_verification', TRUE)) {\n drupal_set_message(t('Once you have verified your e-mail address, you may log in via OpenID.'));\n }\n user_set_authmaps($account, array('authname_openid' => $edit['openid_claimed_id']));\n unset($_SESSION['openid']);\n unset($edit['openid_claimed_id']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-38bf2455df", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_role_permissions/7.x", "instruction": "In Drupal 7, write the function `user_role_permissions($roles = array())` (file modules/user/user.module) so that it does the following: Determine the permissions for one or more roles.", "context": "Parameters:\n- $roles: An array whose keys are the role IDs of interest, such as $user->roles.\n\nReturns: If $roles is a non-empty array, an array indexed by role ID is returned. Each value is an array whose keys are the permission strings for the given role ID. If $roles is empty nothing is returned.\n\nFile: modules/user/user.module", "response": "function user_role_permissions($roles = array()) {\n $cache = &drupal_static(__FUNCTION__, array());\n\n $role_permissions = $fetch = array();\n\n if ($roles) {\n foreach ($roles as $rid => $name) {\n if (isset($cache[$rid])) {\n $role_permissions[$rid] = $cache[$rid];\n }\n else {\n // Add this rid to the list of those needing to be fetched.\n $fetch[] = $rid;\n // Prepare in case no permissions are returned.\n $cache[$rid] = array();\n }\n }\n\n if ($fetch) {\n // Get from the database permissions that were not in the static variable.\n // Only role IDs with at least one permission assigned will return rows.\n $result = db_query(\"SELECT rid, permission FROM {role_permission} WHERE rid IN (:fetch)\", array(':fetch' => $fetch));\n\n foreach ($result as $row) {\n $cache[$row->rid][$row->permission] = TRUE;\n }\n foreach ($fetch as $rid) {\n // For every rid, we know we at least assigned an empty array.\n $role_permissions[$rid] = $cache[$rid];\n }\n }\n }\n\n return $role_permissions;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-38fe1a96eb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_clear_log_submit/7.x", "instruction": "I need the code for `dblog_clear_log_submit()` in Drupal 7 (modules/dblog/dblog.admin.inc). It must do this: Form submission handler for dblog_clear_log_form().", "context": "File: modules/dblog/dblog.admin.inc", "response": "function dblog_clear_log_submit() {\n $_SESSION['dblog_overview_filter'] = array();\n db_truncate('watchdog')->execute();\n drupal_set_message(t('Database log cleared.'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-390e86c086", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_unserialize/7.x", "instruction": "In Drupal 7, write the function `menu_unserialize($data, $map)` (file includes/menu.inc) so that it does the following: Unserializes menu data, using a map to replace path elements.", "context": "The menu system stores various path-related information (such as the 'page arguments' and 'access arguments' components of a menu item) in the database using serialized arrays, where integer values in the arrays represent arguments to be replaced by values from the path. This function first unserializes such menu information arrays, and then does the path replacement.\n\nThe path replacement acts on each integer-valued element of the unserialized menu data array ($data) using a map array ($map, which is typically an array of path arguments) as a list of replacements. For instance, if there is an element of $data whose value is the number 2, then it is replaced in $data with $map[2]; non-integer values in $data are left alone.\n\nAs an example, an unserialized $data array with elements ('node_load', 1) represents instructions for calling the node_load() function. Specifically, this instruction says to use the path component at index 1 as the input parameter to node_load(). If the path is 'node/123', then $map will be the array ('node', 123), and the returned array from this function will have elements ('node_load', 123), since $map[1] is 123. This return value will indicate specifically that node_load(123) is to be called to load the node whose ID is 123 for this menu item.\n\nParameters:\n- $data: A serialized array of menu data, as read from the database.\n- $map: A path argument array, used to replace integer values in $data; an integer value N in $data will be replaced by value $map[N]. Typically, the $map array is generated from a call to the arg() function.\n\nReturns: The unserialized $data array, with path arguments replaced.\n\nFile: includes/menu.inc", "response": "function menu_unserialize($data, $map) {\n if ($data = unserialize($data)) {\n foreach ($data as $k => $v) {\n if (is_int($v)) {\n $data[$k] = isset($map[$v]) ? $map[$v] : '';\n }\n }\n return $data;\n }\n else {\n return array();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-391940e549", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_date_formats_alter/7.x", "instruction": "Give me the example code for `hook_date_formats_alter(&$formats)` in Drupal 7. Hook description: Alter date formats declared by another module.", "context": "Called by _system_date_format_types_build() to allow modules to alter the return values from implementations of hook_date_formats().\n\nFile: modules/system/system.api.php", "response": "function hook_date_formats_alter(&$formats) {\n foreach ($formats as $id => $format) {\n $formats[$id]['locales'][] = 'en-ca';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-391963d5c4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.api.php/function/hook_taxonomy_vocabulary_load/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_taxonomy_vocabulary_load($vocabularies)` (modules/taxonomy/taxonomy.api.php): Act on taxonomy vocabularies when loaded.", "context": "Modules implementing this hook can act on the vocabulary objects before they are returned by taxonomy_vocabulary_load_multiple().\n\nParameters:\n- $vocabulary: An array of taxonomy vocabulary objects.\n\nFile: modules/taxonomy/taxonomy.api.php", "response": "function hook_taxonomy_vocabulary_load($vocabularies) {\n $result = db_select('mytable', 'm')\n ->fields('m', array('vid', 'foo'))\n ->condition('m.vid', array_keys($vocabularies), 'IN')\n ->execute();\n foreach ($result as $record) {\n $vocabularies[$record->vid]->foo = $record->foo;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-393fe8a2bb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7011/7.x", "instruction": "In Drupal 7, write the function `node_update_7011()` (file modules/node/node.install) so that it does the following: Update the database from Drupal 6 to match the schema.", "context": "File: modules/node/node.install", "response": "function node_update_7011() {\n // Drop node moderation field.\n db_drop_field('node', 'moderate');\n db_drop_index('node', 'node_moderate');\n\n // Change {node_revision}.status field to default to 1.\n db_change_field('node_revision', 'status', 'status', array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 1,\n ));\n\n // Change {node_type}.module field default.\n db_change_field('node_type', 'module', 'module', array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-39416e2ae0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_effect_scale_validate/7.x", "instruction": "Implement `image_effect_scale_validate($element, &$form_state)` in PHP for Drupal 7. Required behavior: Element validate handler to ensure that either a height or a width is specified.", "context": "File: modules/image/image.admin.inc", "response": "function image_effect_scale_validate($element, &$form_state) {\n if (empty($element['width']['#value']) && empty($element['height']['#value'])) {\n form_error($element, t('Width and height can not both be blank.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-394f5cd7c6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_hmac_base64/7.x", "instruction": "I need the code for `drupal_hmac_base64($data, $key)` in Drupal 7 (includes/bootstrap.inc). It must do this: Calculates a base-64 encoded, URL-safe sha-256 hmac.", "context": "Parameters:\n- $data (string): String to be validated with the hmac.\n- $key (string): A secret string key.\n\nReturns (string): A base-64 encoded sha-256 hmac, with + replaced with -, / with _ and any = padding characters removed.\n\nFile: includes/bootstrap.inc", "response": "function drupal_hmac_base64($data, $key) {\n // Casting $data and $key to strings here is necessary to avoid empty string\n // results of the hash function if they are not scalar values. As this\n // function is used in security-critical contexts like token validation it is\n // important that it never returns an empty string.\n $hmac = base64_encode(hash_hmac('sha256', (string) $data, (string) $key, TRUE));\n // Modify the hmac so it's safe to use in URLs.\n return strtr($hmac, array('+' => '-', '/' => '_', '=' => ''));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-395dbd086d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/_drupal_session_read/7.x", "instruction": "Implement `_drupal_session_read($sid)` in PHP for Drupal 7. Required behavior: Reads an entire session from the database (internal use only).", "context": "Also initializes the $user object for the user associated with the session. This function is registered with session_set_save_handler() to support database-backed sessions. It is called on every page load when PHP sets up the $_SESSION superglobal.\n\nThis function is an internal function and must not be called directly. Doing so may result in logging out the current user, corrupting session data or other unexpected behavior. Session data must always be accessed via the $_SESSION superglobal.\n\nParameters:\n- $sid: The session ID of the session to retrieve.\n\nReturns: The user's session, or an empty string if no session exists.\n\nFile: includes/session.inc", "response": "function _drupal_session_read($sid) {\n global $user, $is_https;\n\n // Write and Close handlers are called after destructing objects\n // since PHP 5.0.5.\n // Thus destructors can use sessions but session handler can't use objects.\n // So we are moving session closure before destructing objects.\n drupal_register_shutdown_function('session_write_close');\n\n // Handle the case of first time visitors and clients that don't store\n // cookies (eg. web crawlers).\n $insecure_session_name = substr(session_name(), 1);\n if (empty($sid) || (!isset($_COOKIE[session_name()]) && !isset($_COOKIE[$insecure_session_name]))) {\n $user = drupal_anonymous_user();\n return '';\n }\n\n // Otherwise, if the session is still active, we have a record of the\n // client's session in the database. If it's HTTPS then we are either have\n // a HTTPS session or we are about to log in so we check the sessions table\n // for an anonymous session with the non-HTTPS-only cookie. The session ID\n // that is in the user's cookie is hashed before being stored in the database\n // as a security measure. Thus, we have to hash it to match the database.\n if ($is_https) {\n $user = db_query(\"SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.ssid = :ssid\", array(':ssid' => drupal_session_id($sid)))->fetchObject();\n if (!$user) {\n if (isset($_COOKIE[$insecure_session_name])) {\n $user = db_query(\"SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid AND s.uid = 0\", array(\n ':sid' => drupal_session_id($_COOKIE[$insecure_session_name])))\n ->fetchObject();\n }\n }\n }\n else {\n $user = db_query(\"SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid\", array(':sid' => drupal_session_id($sid)))->fetchObject();\n }\n\n // We found the client's session record and they are an authenticated,\n // active user.\n if ($user && $user->uid > 0 && $user->status == 1) {\n // This is done to unserialize the data member of $user.\n $user->data = unserialize((string) $user->data);\n\n // Add roles element to $user.\n $user->roles = array();\n $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';\n $user->roles += db_query(\"SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid\", array(':uid' => $user->uid))->fetchAllKeyed(0, 1);\n }\n elseif ($user) {\n // The user is anonymous or blocked. Only preserve two fields from the\n // {sessions} table.\n $account = drupal_anonymous_user();\n $account->session = $user->session;\n $account->timestamp = $user->timestamp;\n $user = $account;\n }\n else {\n // The session has expired.\n $user = drupal_anonymous_user();\n $user->session = '';\n }\n\n // Store the session that was read for comparison in _drupal_session_write().\n $last_read = &drupal_static('drupal_session_last_read');\n $last_read = array(\n 'sid' => $sid,\n 'value' => $user->session,\n );\n\n return $user->session;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3964654ccb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_language_list/7.x", "instruction": "I need the code for `locale_language_list($field = 'name', $all = FALSE)` in Drupal 7 (modules/locale/locale.module). It must do this: Returns array of language names", "context": "Parameters:\n- $field: 'name' => names in current language, localized 'native' => native names\n- $all: Boolean to return all languages or only enabled ones\n\nFile: modules/locale/locale.module", "response": "function locale_language_list($field = 'name', $all = FALSE) {\n if ($all) {\n $languages = language_list();\n }\n else {\n $languages = language_list('enabled');\n $languages = $languages[1];\n }\n $list = array();\n foreach ($languages as $language) {\n $list[$language->language] = ($field == 'name') ? t($language->name) : $language->$field;\n }\n return $list;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3977392dcf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_view_link/7.x", "instruction": "I need the code for `book_node_view_link($node, $view_mode)` in Drupal 7 (modules/book/book.module). It must do this: Adds relevant book links to the node's links.", "context": "Parameters:\n- $node: The book page node to add links to.\n- $view_mode: The view mode of the node.\n\nFile: modules/book/book.module", "response": "function book_node_view_link($node, $view_mode) {\n $links = array();\n\n if (isset($node->book['depth'])) {\n if ($view_mode == 'full' && node_is_page($node)) {\n $child_type = variable_get('book_child_type', 'book');\n if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) {\n $links['book_add_child'] = array(\n 'title' => t('Add child page'),\n 'href' => 'node/add/' . str_replace('_', '-', $child_type),\n 'query' => array('parent' => $node->book['mlid']),\n );\n }\n\n if (user_access('access printer-friendly version')) {\n $links['book_printer'] = array(\n 'title' => t('Printer-friendly version'),\n 'href' => 'book/export/html/' . $node->nid,\n 'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))\n );\n }\n }\n }\n\n if (!empty($links)) {\n $node->content['links']['book'] = array(\n '#theme' => 'links__node__book',\n '#links' => $links,\n '#attributes' => array('class' => array('links', 'inline')),\n );\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-39833e7fe9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_menu_site_status_alter/7.x", "instruction": "In Drupal 7, write the function `openid_menu_site_status_alter(&$menu_site_status, $path)` (file modules/openid/openid.module) so that it does the following: Implements hook_menu_site_status_alter().", "context": "File: modules/openid/openid.module", "response": "function openid_menu_site_status_alter(&$menu_site_status, $path) {\n // Allow access to openid/authenticate even if site is in offline mode.\n if ($menu_site_status == MENU_SITE_OFFLINE && user_is_anonymous() && $path == 'openid/authenticate') {\n $menu_site_status = MENU_SITE_ONLINE;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3988371ab4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_help/7.x", "instruction": "Implement `list_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/field/modules/list/list.module", "response": "function list_help($path, $arg) {\n switch ($path) {\n case 'admin/help#list':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The List module defines various fields for storing a list of items, for use with the Field module. Usually these items are entered through a select list, checkboxes, or radio buttons. See the Field module help page for more information about fields.', array('@field-help' => url('admin/help/field'))) . '

            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-39abbe8ce6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_access/7.x", "instruction": "I need the code for `user_access($string, $account = NULL)` in Drupal 7 (modules/user/user.module). It must do this: Determine whether the user has a given privilege.", "context": "Parameters:\n- $string: The permission, such as \"administer nodes\", being checked for.\n- $account: (optional) The account to check, if not given use currently logged in user.\n\nReturns (Boolean): TRUE if the user has the requested permission. All permission checks in Drupal should go through this function. This way, we guarantee consistent behavior, and ensure that the superuser can perform all actions.\n\nFile: modules/user/user.module", "response": "function user_access($string, $account = NULL) {\n global $user;\n\n if (!isset($account)) {\n $account = $user;\n }\n\n // User #1 has all privileges:\n if ($account->uid == 1) {\n return TRUE;\n }\n\n // To reduce the number of SQL queries, we cache the user's permissions\n // in a static variable.\n // Use the advanced drupal_static() pattern, since this is called very often.\n static $drupal_static_fast;\n if (!isset($drupal_static_fast)) {\n $drupal_static_fast['perm'] = &drupal_static(__FUNCTION__);\n }\n $perm = &$drupal_static_fast['perm'];\n if (!isset($perm[$account->uid])) {\n $role_permissions = user_role_permissions($account->roles);\n\n $perms = array();\n foreach ($role_permissions as $one_role) {\n $perms += $one_role;\n }\n $perm[$account->uid] = $perms;\n }\n\n return isset($perm[$account->uid][$string]);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-39aed2dea9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_check_settings/7.x", "instruction": "In Drupal 7, write the function `image_gd_check_settings()` (file modules/system/image.gd.inc) so that it does the following: Verify GD2 settings (that the right version is actually installed).", "context": "Returns: A boolean indicating if the GD toolkit is available on this machine.\n\nFile: modules/system/image.gd.inc", "response": "function image_gd_check_settings() {\n // GD2 support is available.\n return function_exists('imagegd2');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-39f1cbe0e1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/registry_update/7.x", "instruction": "I need the code for `registry_update()` in Drupal 7 (includes/bootstrap.inc). It must do this: Updates the registry based on the latest files listed in the database.", "context": "This function should be used when system_rebuild_module_data() does not need to be called, because it is already known that the list of files in the {system} table matches those in the file system.\n\nReturns: TRUE if the registry was rebuilt, FALSE if another thread was rebuilding in parallel and the current thread just waited for completion.\n\nFile: includes/bootstrap.inc", "response": "function registry_update() {\n // install_system_module() calls module_enable() which calls into this\n // function during initial system installation, so the lock system is neither\n // loaded nor does its storage exist yet.\n $in_installer = drupal_installation_attempted();\n if (!$in_installer && !lock_acquire(__FUNCTION__)) {\n // Another request got the lock, wait for it to finish.\n lock_wait(__FUNCTION__);\n return FALSE;\n }\n\n require_once DRUPAL_ROOT . '/includes/registry.inc';\n _registry_update();\n\n if (!$in_installer) {\n lock_release(__FUNCTION__);\n }\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-39f683ebf6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.api.php/function/hook_comment_presave/7.x", "instruction": "Give me the example code for `hook_comment_presave($comment)` in Drupal 7. Hook description: The comment passed validation and is about to be saved.", "context": "Modules may make changes to the comment before it is saved to the database.\n\nParameters:\n- $comment: The comment object.\n\nFile: modules/comment/comment.api.php", "response": "function hook_comment_presave($comment) {\n // Remove leading & trailing spaces from the comment subject.\n $comment->subject = trim($comment->subject);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-39fe15054a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_implode_tags/7.x", "instruction": "Implement `taxonomy_implode_tags($tags, $vid = NULL)` in PHP for Drupal 7. Required behavior: Implodes a list of tags of a certain vocabulary into a string.", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_implode_tags($tags, $vid = NULL) {\n $typed_tags = array();\n foreach ($tags as $tag) {\n // Extract terms belonging to the vocabulary in question.\n if (!isset($vid) || $tag->vid == $vid) {\n // Make sure we have a completed loaded taxonomy term.\n if (isset($tag->name)) {\n // Commas and quotes in tag names are special cases, so encode 'em.\n if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '\"') !== FALSE) {\n $typed_tags[] = '\"' . str_replace('\"', '\"\"', $tag->name) . '\"';\n }\n else {\n $typed_tags[] = $tag->name;\n }\n }\n }\n }\n return implode(', ', $typed_tags);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a054b0101", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_info/7.x", "instruction": "In Drupal 7, write the function `language_negotiation_info()` (file includes/language.inc) so that it does the following: Returns all the defined language negotiation providers.", "context": "Returns: An array of language negotiation providers.\n\nFile: includes/language.inc", "response": "function language_negotiation_info() {\n $language_providers = &drupal_static(__FUNCTION__);\n\n if (!isset($language_providers)) {\n // Collect all the module-defined language negotiation providers.\n $language_providers = module_invoke_all('language_negotiation_info');\n\n // Add the default language negotiation provider.\n $language_providers[LANGUAGE_NEGOTIATION_DEFAULT] = array(\n 'callbacks' => array('language' => 'language_from_default'),\n 'weight' => 10,\n 'name' => t('Default'),\n 'description' => t('Use the default site language (@language_name).', array('@language_name' => language_default()->native)),\n );\n\n // Let other modules alter the list of language negotiation providers.\n drupal_alter('language_negotiation_info', $language_providers);\n }\n\n return $language_providers;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a0e5ab98e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_menu/7.x", "instruction": "I need the code for `path_menu()` in Drupal 7 (modules/path/path.module). It must do this: Implements hook_menu().", "context": "File: modules/path/path.module", "response": "function path_menu() {\n $items['admin/config/search/path'] = array(\n 'title' => 'URL aliases',\n 'description' => \"Change your site's URL paths by aliasing them.\",\n 'page callback' => 'path_admin_overview',\n 'access arguments' => array('administer url aliases'),\n 'weight' => -5,\n 'file' => 'path.admin.inc',\n );\n $items['admin/config/search/path/edit/%path'] = array(\n 'title' => 'Edit alias',\n 'page callback' => 'path_admin_edit',\n 'page arguments' => array(5),\n 'access arguments' => array('administer url aliases'),\n 'file' => 'path.admin.inc',\n );\n $items['admin/config/search/path/delete/%path'] = array(\n 'title' => 'Delete alias',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('path_admin_delete_confirm', 5),\n 'access arguments' => array('administer url aliases'),\n 'file' => 'path.admin.inc',\n );\n $items['admin/config/search/path/list'] = array(\n 'title' => 'List',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n 'weight' => -10,\n );\n $items['admin/config/search/path/add'] = array(\n 'title' => 'Add alias',\n 'page callback' => 'path_admin_edit',\n 'access arguments' => array('administer url aliases'),\n 'type' => MENU_LOCAL_ACTION,\n 'file' => 'path.admin.inc',\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a165b29ff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_theme/7.x", "instruction": "In Drupal 7, write the function `color_theme()` (file modules/color/color.module) so that it does the following: Implements hook_theme().", "context": "File: modules/color/color.module", "response": "function color_theme() {\n return array(\n 'color_scheme_form' => array(\n 'render element' => 'form',\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a19cfb799", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_machine_name/7.x", "instruction": "In Drupal 7, write the function `form_process_machine_name($element, &$form_state)` (file includes/form.inc) so that it does the following: Processes a machine-readable name form element.", "context": "Parameters:\n- $element: The form element to process. Properties used: - #machine_name: An associative array containing: - exists: A function name to invoke for checking whether a submitted machine name value already exists. The submitted value is passed as argument. In most cases, an existing API or menu argument loader function can be re-used. The callback is only invoked, if the submitted value differs from the element's #default_value. - source: (optional) The #array_parents of the form element containing the human-readable name (i.e., as contained in the $form structure) to use as source for the machine name. Defaults to array('name'). - label: (optional) A text to display as label for the machine name value after the human-readable name form element. Defaults to \"Machine name\". - replace_pattern: (optional) A regular expression (without delimiters) matching disallowed characters in the machine name. Defaults to '[^a-z0-9_]+'. - replace: (optional) A character to replace disallowed characters in the machine name via JavaScript. Defaults to '_' (underscore). When using a different character, 'replace_pattern' needs to be set accordingly. - error: (optional) A custom form error message string to show, if the machine name contains disallowed characters. - standalone: (optional) Whether the live preview should stay in its own form element rather than in the suffix of the source element. Defaults to FALSE. - #maxlength: (optional) Should be set to the maximum allowed length of the machine name. Defaults to 64. - #disabled: (optional) Should be set to TRUE in case an existing machine name must not be changed after initial creation.\n\nFile: includes/form.inc", "response": "function form_process_machine_name($element, &$form_state) {\n // Apply default form element properties.\n $element += array(\n '#title' => t('Machine-readable name'),\n '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),\n '#machine_name' => array(),\n '#field_prefix' => '',\n '#field_suffix' => '',\n '#suffix' => '',\n );\n // A form element that only wants to set one #machine_name property (usually\n // 'source' only) would leave all other properties undefined, if the defaults\n // were defined in hook_element_info(). Therefore, we apply the defaults here.\n $element['#machine_name'] += array(\n 'source' => array('name'),\n 'target' => '#' . $element['#id'],\n 'label' => t('Machine name'),\n 'replace_pattern' => '[^a-z0-9_]+',\n 'replace' => '_',\n 'standalone' => FALSE,\n 'field_prefix' => $element['#field_prefix'],\n 'field_suffix' => $element['#field_suffix'],\n );\n\n // By default, machine names are restricted to Latin alphanumeric characters.\n // So, default to LTR directionality.\n if (!isset($element['#attributes'])) {\n $element['#attributes'] = array();\n }\n $element['#attributes'] += array('dir' => 'ltr');\n\n // The source element defaults to array('name'), but may have been overidden.\n if (empty($element['#machine_name']['source'])) {\n return $element;\n }\n\n // Retrieve the form element containing the human-readable name from the\n // complete form in $form_state. By reference, because we may need to append\n // a #field_suffix that will hold the live preview.\n $key_exists = NULL;\n $source = drupal_array_get_nested_value($form_state['complete form'], $element['#machine_name']['source'], $key_exists);\n if (!$key_exists) {\n return $element;\n }\n\n $suffix_id = $source['#id'] . '-machine-name-suffix';\n $element['#machine_name']['suffix'] = '#' . $suffix_id;\n\n if ($element['#machine_name']['standalone']) {\n $element['#suffix'] .= '  ';\n }\n else {\n // Append a field suffix to the source form element, which will contain\n // the live preview of the machine name.\n $source += array('#field_suffix' => '');\n $source['#field_suffix'] .= '  ';\n\n $parents = array_merge($element['#machine_name']['source'], array('#field_suffix'));\n drupal_array_set_nested_value($form_state['complete form'], $parents, $source['#field_suffix']);\n }\n\n $js_settings = array(\n 'type' => 'setting',\n 'data' => array(\n 'machineName' => array(\n '#' . $source['#id'] => $element['#machine_name'],\n ),\n ),\n );\n $element['#attached']['js'][] = 'misc/machine-name.js';\n $element['#attached']['js'][] = $js_settings;\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a25424b44", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_query_alter/7.x", "instruction": "Give me the example code for `hook_query_alter(QueryAlterableInterface $query)` in Drupal 7. Hook description: Perform alterations to a structured query.", "context": "Structured (aka dynamic) queries that have tags associated may be altered by any module before the query is executed.\n\nParameters:\n- $query: A Query object describing the composite parts of a SQL query.\n\nFile: modules/system/system.api.php", "response": "function hook_query_alter(QueryAlterableInterface $query) {\n if ($query->hasTag('micro_limit')) {\n $query->range(0, 2);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a4124d13b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_array_flatten/7.x", "instruction": "Implement `options_array_flatten($array)` in PHP for Drupal 7. Required behavior: Flattens an array of allowed values.", "context": "Parameters:\n- $array: A single or multidimensional array.\n\nReturns: A flattened array.\n\nFile: modules/field/modules/options/options.module", "response": "function options_array_flatten($array) {\n $result = array();\n if (is_array($array)) {\n foreach ($array as $key => $value) {\n if (is_array($value)) {\n $result += options_array_flatten($value);\n }\n else {\n $result[$key] = $value;\n }\n }\n }\n return $result;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a4670911a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_format_form/7.x", "instruction": "I need the code for `filter_admin_format_form($form, &$form_state, $format)` in Drupal 7 (modules/filter/filter.admin.inc). It must do this: Form constructor for the text format add/edit form.", "context": "Parameters:\n- $format: A format object having the properties: - format: A machine-readable name representing the ID of the text format to save. If this corresponds to an existing text format, that format will be updated; otherwise, a new format will be created. - name: The title of the text format. - cache: An integer indicating whether the text format is cacheable (1) or not (0). Defaults to 1. - status: (optional) An integer indicating whether the text format is enabled (1) or not (0). Defaults to 1. - weight: (optional) The weight of the text format, which controls its placement in text format lists. If omitted, the weight is set to 0.\n\nFile: modules/filter/filter.admin.inc", "response": "function filter_admin_format_form($form, &$form_state, $format) {\n $is_fallback = ($format->format == filter_fallback_format());\n\n $form['#format'] = $format;\n $form['#tree'] = TRUE;\n $form['#attached']['js'][] = drupal_get_path('module', 'filter') . '/filter.admin.js';\n $form['#attached']['css'][] = drupal_get_path('module', 'filter') . '/filter.css';\n\n $form['name'] = array(\n '#type' => 'textfield',\n '#title' => t('Name'),\n '#default_value' => $format->name,\n '#required' => TRUE,\n );\n $form['format'] = array(\n '#type' => 'machine_name',\n '#required' => TRUE,\n '#default_value' => $format->format,\n '#maxlength' => 255,\n '#machine_name' => array(\n 'exists' => 'filter_format_exists',\n ),\n '#disabled' => !empty($format->format),\n );\n\n // Add user role access selection.\n $form['roles'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Roles'),\n '#options' => array_map('check_plain', user_roles()),\n '#disabled' => $is_fallback,\n );\n if ($is_fallback) {\n $form['roles']['#description'] = t('All roles for this text format must be enabled and cannot be changed.');\n }\n if (!empty($format->format)) {\n // If editing an existing text format, pre-select its current permissions.\n $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($format));\n }\n elseif ($admin_role = variable_get('user_admin_role', 0)) {\n // If adding a new text format and the site has an administrative role,\n // pre-select that role so as to grant administrators access to the new\n // text format permission by default.\n $form['roles']['#default_value'] = array($admin_role);\n }\n\n // Retrieve available filters and load all configured filters for existing\n // text formats.\n $filter_info = filter_get_filters();\n $filters = !empty($format->format) ? filter_list_format($format->format) : array();\n\n // Prepare filters for form sections.\n foreach ($filter_info as $name => $filter) {\n // Create an empty filter object for new/unconfigured filters.\n if (!isset($filters[$name])) {\n $filters[$name] = new stdClass();\n $filters[$name]->format = $format->format;\n $filters[$name]->module = $filter['module'];\n $filters[$name]->name = $name;\n $filters[$name]->status = 0;\n $filters[$name]->weight = $filter['weight'];\n $filters[$name]->settings = array();\n }\n }\n $form['#filters'] = $filters;\n\n // Filter status.\n $form['filters']['status'] = array(\n '#type' => 'item',\n '#title' => t('Enabled filters'),\n '#prefix' => '
            ',\n '#suffix' => '
            ',\n );\n foreach ($filter_info as $name => $filter) {\n $form['filters']['status'][$name] = array(\n '#type' => 'checkbox',\n '#title' => $filter['title'],\n '#default_value' => $filters[$name]->status,\n '#parents' => array('filters', $name, 'status'),\n '#description' => $filter['description'],\n '#weight' => $filter['weight'],\n );\n }\n\n // Filter order (tabledrag).\n $form['filters']['order'] = array(\n '#type' => 'item',\n '#title' => t('Filter processing order'),\n '#theme' => 'filter_admin_format_filter_order',\n );\n foreach ($filter_info as $name => $filter) {\n $form['filters']['order'][$name]['filter'] = array(\n '#markup' => $filter['title'],\n );\n $form['filters']['order'][$name]['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight for @title', array('@title' => $filter['title'])),\n '#title_display' => 'invisible',\n '#delta' => 50,\n '#default_value' => $filters[$name]->weight,\n '#parents' => array('filters', $name, 'weight'),\n );\n $form['filters']['order'][$name]['#weight'] = $filters[$name]->weight;\n }\n\n // Filter settings.\n $form['filter_settings_title'] = array(\n '#type' => 'item',\n '#title' => t('Filter settings'),\n );\n $form['filter_settings'] = array(\n '#type' => 'vertical_tabs',\n );\n\n foreach ($filter_info as $name => $filter) {\n if (isset($filter['settings callback']) && function_exists($filter['settings callback'])) {\n $function = $filter['settings callback'];\n // Pass along stored filter settings and default settings, but also the\n // format object and all filters to allow for complex implementations.\n $defaults = (isset($filter['default settings']) ? $filter['default settings'] : array());\n $settings_form = $function($form, $form_state, $filters[$name], $format, $defaults, $filters);\n if (!empty($settings_form)) {\n $form['filters']['settings'][$name] = array(\n '#type' => 'fieldset',\n '#title' => $filter['title'],\n '#parents' => array('filters', $name, 'settings'),\n '#weight' => $filter['weight'],\n '#group' => 'filter_settings',\n );\n $form['filters']['settings'][$name] += $settings_form;\n }\n }\n }\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a49b08e3b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_image_style_save/7.x", "instruction": "I need the code for `image_image_style_save($style)` in Drupal 7 (modules/image/image.module). It must do this: Implements hook_image_style_save().", "context": "File: modules/image/image.module", "response": "function image_image_style_save($style) {\n if (isset($style['old_name']) && $style['old_name'] != $style['name']) {\n $instances = field_read_instances();\n // Loop through all fields searching for image fields.\n foreach ($instances as $instance) {\n if ($instance['widget']['module'] == 'image') {\n $instance_changed = FALSE;\n foreach ($instance['display'] as $view_mode => $display) {\n // Check if the formatter involves an image style.\n if ($display['type'] == 'image' && $display['settings']['image_style'] == $style['old_name']) {\n // Update display information for any instance using the image\n // style that was just deleted.\n $instance['display'][$view_mode]['settings']['image_style'] = $style['name'];\n $instance_changed = TRUE;\n }\n }\n if ($instance['widget']['settings']['preview_image_style'] == $style['old_name']) {\n $instance['widget']['settings']['preview_image_style'] = $style['name'];\n $instance_changed = TRUE;\n }\n if ($instance_changed) {\n field_update_instance($instance);\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a4d95e0f1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_modules_installed/7.x", "instruction": "I need the code for `rdf_modules_installed($modules)` in Drupal 7 (modules/rdf/rdf.module). It must do this: Implements hook_modules_installed().", "context": "Checks if the installed modules have any RDF mapping definitions to declare and stores them in the rdf_mapping table.\n\nWhile both default entity mappings and specific bundle mappings can be defined in hook_rdf_mapping(), default entity mappings are not stored in the database. Only overridden mappings are stored in the database. The default entity mappings can be overriden by specific bundle mappings which are stored in the database and can be altered via the RDF CRUD mapping API.\n\nFile: modules/rdf/rdf.module", "response": "function rdf_modules_installed($modules) {\n foreach ($modules as $module) {\n $function = $module . '_rdf_mapping';\n if (function_exists($function)) {\n foreach ($function() as $mapping) {\n // Only the bundle mappings are saved in the database.\n if ($mapping['bundle'] !== RDF_DEFAULT_BUNDLE) {\n rdf_mapping_save($mapping);\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a545b64a3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.admin.inc/function/path_admin_form_validate/7.x", "instruction": "In Drupal 7, write the function `path_admin_form_validate($form, &$form_state)` (file modules/path/path.admin.inc) so that it does the following: Form validation handler for path_admin_form().", "context": "File: modules/path/path.admin.inc", "response": "function path_admin_form_validate($form, &$form_state) {\n $source = &$form_state['values']['source'];\n $source = drupal_get_normal_path($source);\n $alias = $form_state['values']['alias'];\n $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0;\n // Language is only set if locale module is enabled, otherwise save for all languages.\n $language = isset($form_state['values']['language']) ? $form_state['values']['language'] : LANGUAGE_NONE;\n\n $has_alias = db_query(\"SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND language = :language\", array(\n ':pid' => $pid,\n ':alias' => $alias,\n ':language' => $language,\n ))\n ->fetchField();\n\n if ($has_alias) {\n form_set_error('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias)));\n }\n if (!drupal_valid_path($source)) {\n form_set_error('source', t(\"The path '@link_path' is either invalid or you do not have access to it.\", array('@link_path' => $source)));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a564d7c27", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/tracker_help/7.x", "instruction": "Implement `tracker_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/tracker/tracker.module", "response": "function tracker_help($path, $arg) {\n switch ($path) {\n case 'admin/help#tracker':\n $output = '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Tracker module displays the most recently added and updated content on your site, and allows you to follow new content created by each user. This module has no configuration options. For more information, see the online handbook entry for Tracker module.', array('@tracker' => 'http://drupal.org/documentation/modules/tracker/')) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Navigation') . '
            ';\n $output .= '
            ' . t('The Tracker module adds a new menu item to the Navigation menu, called Recent content. You can configure menu items via the Menus administration page.', array('@menus' => url('admin/structure/menu'))) . '
            ';\n $output .= '
            ' . t('Tracking new and updated site content') . '
            ';\n $output .= '
            ' . t(\"The Recent content page shows new and updated content in reverse chronological order, listing the content type, title, author's name, number of comments, and time of last update. Content is considered updated when changes occur in the text, or when new comments are added. The My recent content tab limits the list to the currently logged-in user.\", array('@recent' => url('tracker'))) . '
            ';\n $output .= '
            ' . t('Tracking user-specific content') . '
            ';\n $output .= '
            ' . t(\"To follow a specific user's new and updated content, select the Track tab from the user's profile page.\") . '
            ';\n $output .= '
            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a5ac6c638", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.pages.inc/function/tracker_page/7.x", "instruction": "Implement `tracker_page($account = NULL, $set_title = FALSE)` in PHP for Drupal 7. Required behavior: Page callback: prints a listing of active nodes on the site.", "context": "Queries the database for info, adds RDFa info if applicable, and generates the render array that will be used to render the page.\n\nFile: modules/tracker/tracker.pages.inc", "response": "function tracker_page($account = NULL, $set_title = FALSE) {\n if ($account) {\n $query = db_select('tracker_user', 't')->extend('PagerDefault');\n $query->condition('t.uid', $account->uid);\n\n if ($set_title) {\n // When viewed from user/%user/track, display the name of the user\n // as page title -- the tab title remains Track so this needs to be done\n // here and not in the menu definition.\n drupal_set_title(format_username($account));\n }\n }\n else {\n $query = db_select('tracker_node', 't', array('target' => 'slave'))->extend('PagerDefault');\n }\n\n // This array acts as a placeholder for the data selected later\n // while keeping the correct order.\n $nodes = $query\n ->addTag('node_access')\n ->fields('t', array('nid', 'changed'))\n ->condition('t.published', 1)\n ->orderBy('t.changed', 'DESC')\n ->limit(25)\n ->execute()\n ->fetchAllAssoc('nid');\n\n $rows = array();\n if (!empty($nodes)) {\n // Now, get the data and put into the placeholder array.\n $result = db_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.nid IN (:nids)', array(':nids' => array_keys($nodes)), array('target' => 'slave'));\n foreach ($result as $node) {\n $node->last_activity = $nodes[$node->nid]->changed;\n $nodes[$node->nid] = $node;\n }\n\n // Display the data.\n foreach ($nodes as $node) {\n // Determine the number of comments.\n $comments = 0;\n if ($node->comment_count) {\n $comments = $node->comment_count;\n\n if ($new = comment_num_new($node->nid)) {\n $comments .= '
            ';\n $comments .= l(format_plural($new, '1 new', '@count new'), 'node/' . $node->nid, array('fragment' => 'new'));\n }\n }\n\n $row = array(\n 'type' => check_plain(node_type_get_name($node->type)),\n 'title' => array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))),\n 'author' => array('data' => theme('username', array('account' => $node))),\n 'replies' => array('class' => array('replies'), 'data' => $comments),\n 'last updated' => array('data' => t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_activity)))),\n );\n\n // Adds extra RDFa markup to the $row array if the RDF module is enabled.\n if (function_exists('rdf_mapping_load')) {\n // Each node is not loaded for performance reasons, as a result we need\n // to retrieve the RDF mapping for each node type.\n $mapping = rdf_mapping_load('node', $node->type);\n // Adds RDFa markup to the title of the node. Because the RDFa markup is\n // added to the td tag which might contain HTML code, we specify an\n // empty datatype to ensure the value of the title read by the RDFa\n // parsers is a plain literal.\n $row['title'] += rdf_rdfa_attributes($mapping['title']) + array('datatype' => '');\n // Annotates the td tag containing the author of the node.\n $row['author'] += rdf_rdfa_attributes($mapping['uid']);\n // Annotates the td tag containing the number of replies. We add the\n // content attribute to ensure that only the comment count is used as\n // the value for 'num_replies'. Otherwise, other text such as a link\n // to the number of new comments could be included in the 'num_replies'\n // value.\n $row['replies'] += rdf_rdfa_attributes($mapping['comment_count']);\n $row['replies'] += array('content' => $node->comment_count);\n // If the node has no comments, we assume the node itself was modified\n // and apply 'changed' in addition to 'last_activity'. If there are\n // comments present, we cannot infer whether the node itself was\n // modified or a comment was posted, so we use only 'last_activity'.\n $mapping_last_activity = rdf_rdfa_attributes($mapping['last_activity'], $node->last_activity);\n if ($node->comment_count == 0) {\n $mapping_changed = rdf_rdfa_attributes($mapping['changed'], $node->last_activity);\n $mapping_last_activity['property'] = array_merge($mapping_last_activity['property'], $mapping_changed['property']);\n }\n $row['last updated'] += $mapping_last_activity;\n\n // We need to add the about attribute on the tr tag to specify which\n // node the RDFa annotations above apply to. We move the content of\n // $row to a 'data' sub array so we can specify attributes for the row.\n $row = array('data' => $row);\n $row['about'] = url('node/' . $node->nid);\n }\n $rows[] = $row;\n }\n }\n\n $page['tracker'] = array(\n '#rows' => $rows,\n '#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')),\n '#theme' => 'table',\n '#empty' => t('No content available.'),\n '#attached' => array(\n 'css' => array(drupal_get_path('module', 'tracker') . '/tracker.css' => array()),\n ),\n );\n $page['pager'] = array(\n '#theme' => 'pager',\n '#weight' => 10,\n );\n $page['#sorted'] = TRUE;\n\n return $page;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a9d8df120", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21actions.inc/function/actions_synchronize/7.x", "instruction": "Implement `actions_synchronize($delete_orphans = FALSE)` in PHP for Drupal 7. Required behavior: Synchronizes actions that are provided by modules in hook_action_info().", "context": "Actions provided by modules in hook_action_info() implementations are synchronized with actions that are stored in the actions database table. This is necessary so that actions that do not require configuration can receive action IDs.\n\nParameters:\n- $delete_orphans: If TRUE, any actions that exist in the database but are no longer found in the code (for example, because the module that provides them has been disabled) will be deleted.\n\nFile: includes/actions.inc", "response": "function actions_synchronize($delete_orphans = FALSE) {\n $actions_in_code = actions_list(TRUE);\n $actions_in_db = db_query(\"SELECT aid, callback, label FROM {actions} WHERE parameters = ''\")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);\n\n // Go through all the actions provided by modules.\n foreach ($actions_in_code as $callback => $array) {\n // Ignore configurable actions since their instances get put in when the\n // user adds the action.\n if (!$array['configurable']) {\n // If we already have an action ID for this action, no need to assign aid.\n if (isset($actions_in_db[$callback])) {\n unset($actions_in_db[$callback]);\n }\n else {\n // This is a new singleton that we don't have an aid for; assign one.\n db_insert('actions')\n ->fields(array(\n 'aid' => $callback,\n 'type' => $array['type'],\n 'callback' => $callback,\n 'parameters' => '',\n 'label' => $array['label'],\n ))\n ->execute();\n watchdog('actions', \"Action '%action' added.\", array('%action' => $array['label']));\n }\n }\n }\n\n // Any actions that we have left in $actions_in_db are orphaned.\n if ($actions_in_db) {\n $orphaned = array_keys($actions_in_db);\n\n if ($delete_orphans) {\n $actions = db_query('SELECT aid, label FROM {actions} WHERE callback IN (:orphaned)', array(':orphaned' => $orphaned))->fetchAll();\n foreach ($actions as $action) {\n actions_delete($action->aid);\n watchdog('actions', \"Removed orphaned action '%action' from database.\", array('%action' => $action->label));\n }\n }\n else {\n $link = l(t('Remove orphaned actions'), 'admin/config/system/actions/orphan');\n $count = count($actions_in_db);\n $orphans = implode(', ', $orphaned);\n watchdog('actions', '@count orphaned actions (%orphans) exist in the actions table. !link', array('@count' => $count, '%orphans' => $orphans, '!link' => $link), WATCHDOG_INFO);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3a9e066dec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_is_xri/7.x", "instruction": "In Drupal 7, write the function `_openid_is_xri($identifier)` (file modules/openid/openid.inc) so that it does the following: Determine if the given identifier is an XRI ID.", "context": "File: modules/openid/openid.inc", "response": "function _openid_is_xri($identifier) {\n // Strip the xri:// scheme from the identifier if present.\n if (stripos($identifier, 'xri://') === 0) {\n $identifier = substr($identifier, 6);\n }\n\n // Test whether the identifier starts with an XRI global context symbol or (.\n $firstchar = substr($identifier, 0, 1);\n if (strpos(\"=@+$!(\", $firstchar) !== FALSE) {\n return TRUE;\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3aa7e5d7e1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid/7.x", "instruction": "Give me the example code for `hook_openid($op, $request)` in Drupal 7. Hook description: Allow modules to modify the OpenID request parameters.", "context": "Parameters:\n- $op: The operation to be performed. Possible values: - request: Modify parameters before they are sent to the OpenID provider.\n- $request: An associative array of parameter defaults to which to modify or append.\n\nReturns: An associative array of parameters to be merged with the default list.\n\nFile: modules/openid/openid.api.php", "response": "function hook_openid($op, $request) {\n if ($op == 'request') {\n $request['openid.identity'] = 'http://myname.myopenid.com/';\n }\n return $request;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ab85fd817", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_delete_form_submit/7.x", "instruction": "Implement `locale_languages_delete_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process language deletion submissions.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_languages_delete_form_submit($form, &$form_state) {\n $languages = language_list();\n if (isset($languages[$form_state['values']['langcode']])) {\n // Remove translations first.\n db_delete('locales_target')\n ->condition('language', $form_state['values']['langcode'])\n ->execute();\n cache_clear_all('locale:' . $form_state['values']['langcode'], 'cache');\n // With no translations, this removes existing JavaScript translations file.\n _locale_rebuild_js($form_state['values']['langcode']);\n // Remove the language.\n db_delete('languages')\n ->condition('language', $form_state['values']['langcode'])\n ->execute();\n db_update('node')\n ->fields(array('language' => ''))\n ->condition('language', $form_state['values']['langcode'])\n ->execute();\n if ($languages[$form_state['values']['langcode']]->enabled) {\n variable_set('language_count', variable_get('language_count', 1) - 1);\n }\n module_invoke_all('multilingual_settings_changed');\n $variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);\n drupal_set_message(t('The language %locale has been removed.', $variables));\n watchdog('locale', 'The language %locale has been removed.', $variables);\n }\n\n // Changing the language settings impacts the interface:\n cache_clear_all('*', 'cache_page', TRUE);\n\n $form_state['redirect'] = 'admin/config/regional/language';\n return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ad30cef64", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_block_configure/7.x", "instruction": "Implement `comment_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().", "context": "File: modules/comment/comment.module", "response": "function comment_block_configure($delta = '') {\n $form['comment_block_count'] = array(\n '#type' => 'select',\n '#title' => t('Number of recent comments'),\n '#default_value' => variable_get('comment_block_count', 10),\n '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)),\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ade200e0d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/_update_7000_node_get_types/7.x", "instruction": "Implement `_update_7000_node_get_types()` in PHP for Drupal 7. Required behavior: Utility function: fetch the node types directly from the database.", "context": "This function is valid for a database schema version 7000.\n\nFile: modules/node/node.install", "response": "function _update_7000_node_get_types() {\n $node_types = db_query('SELECT * FROM {node_type}')->fetchAllAssoc('type', PDO::FETCH_OBJ);\n\n // Create default settings for orphan nodes.\n $all_types = db_query('SELECT DISTINCT type FROM {node}')->fetchCol();\n $extra_types = array_diff($all_types, array_keys($node_types));\n\n foreach ($extra_types as $type) {\n $type_object = new stdClass();\n $type_object->type = $type;\n\n // In Drupal 6, whether you have a body field or not is a flag in the node\n // type table. If it's enabled, nodes may or may not have an empty string\n // for the bodies. As we can't detect what this setting should be in\n // Drupal 7 without access to the Drupal 6 node type settings, we assume\n // the default, which is to enable the body field.\n $type_object->has_body = 1;\n $type_object->body_label = 'Body';\n $node_types[$type_object->type] = $type_object;\n }\n return $node_types;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ae8f3f780", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_field_delete_instance/7.x", "instruction": "Implement `image_field_delete_instance($instance)` in PHP for Drupal 7. Required behavior: Implements hook_field_delete_instance().", "context": "File: modules/image/image.module", "response": "function image_field_delete_instance($instance) {\n // Only act on image fields.\n $field = field_read_field($instance['field_name']);\n if ($field['type'] != 'image') {\n return;\n }\n\n // The value of a managed_file element can be an array if the #extended\n // property is set to TRUE.\n $fid = $instance['settings']['default_image'];\n if (is_array($fid)) {\n $fid = $fid['fid'];\n }\n\n // Remove the default image when the instance is deleted.\n if ($fid && ($file = file_load($fid))) {\n file_usage_delete($file, 'image', 'default_image', $instance['id']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b32e98b20", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_has_role/7.x", "instruction": "Implement `user_has_role($rid, $account = NULL)` in PHP for Drupal 7. Required behavior: Checks if a user has a role.", "context": "Parameters:\n- $rid (int): A role ID.\n- $account (object|null): (optional) A user account. Defaults to the current user.\n\nReturns (bool): TRUE if the user has the role, or FALSE if not.\n\nFile: modules/user/user.module", "response": "function user_has_role($rid, $account = NULL) {\n if (!$account) {\n $account = $GLOBALS['user'];\n }\n\n return isset($account->roles[$rid]);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b45393038", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_item_localize/7.x", "instruction": "Implement `_menu_item_localize(&$item, $map, $link_translate = FALSE)` in PHP for Drupal 7. Required behavior: Localizes the router item title using t() or another callback.", "context": "Translate the title and description to allow storage of English title strings in the database, yet display of them in the language required by the current user.\n\nParameters:\n- $item: A menu router item or a menu link item.\n- $map: The path as an array with objects already replaced. E.g., for path node/123 $map would be array('node', $node) where $node is the node object for node 123.\n- $link_translate: TRUE if we are translating a menu link item; FALSE if we are translating a menu router item.\n\nReturns: No return value. $item['title'] is localized according to $item['title_callback']. If an item's callback is check_plain(), $item['options']['html'] becomes TRUE. $item['description'] is translated using t(). When doing link translation and the $item['options']['attributes']['title'] (link title attribute) matches the description, it is translated as well.\n\nFile: includes/menu.inc", "response": "function _menu_item_localize(&$item, $map, $link_translate = FALSE) {\n $callback = $item['title_callback'];\n $item['localized_options'] = $item['options'];\n // All 'class' attributes are assumed to be an array during rendering, but\n // links stored in the database may use an old string value.\n // @todo In order to remove this code we need to implement a database update\n // including unserializing all existing link options and running this code\n // on them, as well as adding validation to menu_link_save().\n if (isset($item['options']['attributes']['class']) && is_string($item['options']['attributes']['class'])) {\n $item['localized_options']['attributes']['class'] = explode(' ', $item['options']['attributes']['class']);\n }\n // If we are translating the title of a menu link, and its title is the same\n // as the corresponding router item, then we can use the title information\n // from the router. If it's customized, then we need to use the link title\n // itself; can't localize.\n // If we are translating a router item (tabs, page, breadcrumb), then we\n // can always use the information from the router item.\n if (!$link_translate || ($item['title'] == $item['link_title'])) {\n // t() is a special case. Since it is used very close to all the time,\n // we handle it directly instead of using indirect, slower methods.\n if ($callback == 't') {\n if (empty($item['title_arguments'])) {\n $item['title'] = t($item['title']);\n }\n else {\n $item['title'] = t($item['title'], menu_unserialize($item['title_arguments'], $map));\n }\n }\n elseif ($callback && function_exists($callback)) {\n if (empty($item['title_arguments'])) {\n $item['title'] = $callback($item['title']);\n }\n else {\n $item['title'] = call_user_func_array($callback, menu_unserialize($item['title_arguments'], $map));\n }\n // Avoid calling check_plain again on l() function.\n if ($callback == 'check_plain') {\n $item['localized_options']['html'] = TRUE;\n }\n }\n }\n elseif ($link_translate) {\n $item['title'] = $item['link_title'];\n }\n\n // Translate description, see the motivation above.\n if (!empty($item['description'])) {\n $original_description = $item['description'];\n $item['description'] = t($item['description']);\n if ($link_translate && isset($item['options']['attributes']['title']) && $item['options']['attributes']['title'] == $original_description) {\n $item['localized_options']['attributes']['title'] = $item['description'];\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b535edb82", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_secondary_menu/7.x", "instruction": "In Drupal 7, write the function `menu_secondary_menu()` (file includes/menu.inc) so that it does the following: Returns an array of links to be rendered as the Secondary links.", "context": "File: includes/menu.inc", "response": "function menu_secondary_menu() {\n\n // If the secondary menu source is set as the primary menu, we display the\n // second level of the primary menu.\n if (variable_get('menu_secondary_links_source', 'user-menu') == variable_get('menu_main_links_source', 'main-menu')) {\n return menu_navigation_links(variable_get('menu_main_links_source', 'main-menu'), 1);\n }\n else {\n return menu_navigation_links(variable_get('menu_secondary_links_source', 'user-menu'), 0);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b676a07f4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_access_write_grants/7.x", "instruction": "In Drupal 7, write the function `node_access_write_grants($node, $grants, $realm = NULL, $delete = TRUE)` (file modules/node/node.module) so that it does the following: Writes a list of grants to the database, deleting any previously saved ones.", "context": "If a realm is provided, it will only delete grants from that realm, but it will always delete a grant from the 'all' realm. Modules that utilize node_access() can use this function when doing mass updates due to widespread permission changes.\n\nNote: Don't call this function directly from a contributed module. Call node_access_acquire_grants() instead.\n\nParameters:\n- $node: The node whose grants are being written.\n- $grants: A list of grants to write. Each grant is an array that must contain the following keys: realm, gid, grant_view, grant_update, grant_delete. The realm is specified by a particular module; the gid is as well, and is a module-defined id to define grant privileges. each grant_* field is a boolean value.\n- $realm: (optional) If provided, read/write grants for that realm only. Defaults to NULL.\n- $delete: (optional) If false, does not delete records. This is only for optimization purposes, and assumes the caller has already performed a mass delete of some form. Defaults to TRUE.\n\nFile: modules/node/node.module", "response": "function node_access_write_grants($node, $grants, $realm = NULL, $delete = TRUE) {\n if ($delete) {\n $query = db_delete('node_access')->condition('nid', $node->nid);\n if ($realm) {\n $query->condition('realm', array($realm, 'all'), 'IN');\n }\n $query->execute();\n }\n\n // Only perform work when node_access modules are active.\n if (!empty($grants) && count(module_implements('node_grants'))) {\n $query = db_insert('node_access')->fields(array('nid', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete'));\n foreach ($grants as $grant) {\n if ($realm && $realm != $grant['realm']) {\n continue;\n }\n // Only write grants; denies are implicit.\n if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {\n $grant['nid'] = $node->nid;\n $query->values($grant);\n }\n }\n $query->execute();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b7f59d5d6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_effects/7.x", "instruction": "I need the code for `image_style_effects($style)` in Drupal 7 (modules/image/image.module). It must do this: Loads all the effects for an image style.", "context": "Parameters:\n- $style (array): An image style array containing: - isid: The unique image style ID that contains this image effect.\n\nReturns (array): An array of image effects associated with specified image style in the format array('isid' => array()), or an empty array if the specified style has no effects.\n\nFile: modules/image/image.module", "response": "function image_style_effects($style) {\n $effects = image_effects();\n $style_effects = array();\n foreach ($effects as $effect) {\n if ($style['isid'] == $effect['isid']) {\n $style_effects[$effect['ieid']] = $effect;\n }\n }\n\n return $style_effects;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b827d46f9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_is_visible/7.x", "instruction": "In Drupal 7, write the function `dashboard_is_visible()` (file modules/dashboard/dashboard.module) so that it does the following: Determines if the dashboard should be displayed on the current page.", "context": "This function checks if the user is currently viewing the dashboard and has access to see it. It is used by other functions in the dashboard module to decide whether or not the dashboard content should be displayed to the current user.\n\nAlthough the menu system normally handles the above tasks, it only does so for the main page content. However, the dashboard is not part of the main page content, but rather is displayed in special regions of the page (so it can interface with the Block module's method of managing page regions). We therefore need to maintain this separate function to check the menu item for us.\n\nReturns: TRUE if the dashboard should be visible on the current page, FALSE otherwise.\n\nFile: modules/dashboard/dashboard.module", "response": "function dashboard_is_visible() {\n static $is_visible;\n if (!isset($is_visible)) {\n // If the current menu item represents the page on which we want to display\n // the dashboard, and if the current user has access to see it, return\n // TRUE.\n $menu_item = menu_get_item();\n $is_visible = isset($menu_item['page_callback']) && $menu_item['page_callback'] == 'dashboard_admin' && !empty($menu_item['access']);\n }\n return $is_visible;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b84c2b25d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_info_alter/7.x", "instruction": "Give me the example code for `hook_block_info_alter(&$blocks, $theme, $code_blocks)` in Drupal 7. Hook description: Change block definition before saving to the database.", "context": "Parameters:\n- $blocks: A multidimensional array of blocks keyed by the defining module and delta; the values are blocks returned by hook_block_info(). This hook is fired after the blocks are collected from hook_block_info() and the database, right before saving back to the database.\n- $theme: The theme these blocks belong to.\n- $code_blocks: The blocks as defined in hook_block_info() before being overwritten by the database data.\n\nFile: modules/block/block.api.php", "response": "function hook_block_info_alter(&$blocks, $theme, $code_blocks) {\n // Disable the login block.\n $blocks['user']['login']['status'] = 0;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b8f7b6331", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_form_node_form_alter/7.x", "instruction": "Implement `menu_form_node_form_alter(&$form, $form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_BASE_FORM_ID_alter().", "context": "Adds menu item fields to the node form.\n\nFile: modules/menu/menu.module", "response": "function menu_form_node_form_alter(&$form, $form_state) {\n // Generate a list of possible parents (not including this link or descendants).\n // @todo This must be handled in a #process handler.\n $link = $form['#node']->menu;\n $type = $form['#node']->type;\n // menu_parent_options() is goofy and can actually handle either a menu link\n // or a node type both as second argument. Pick based on whether there is\n // a link already (menu_node_prepare() sets mlid default to 0).\n $options = menu_parent_options(menu_get_menus(), $link['mlid'] ? $link : $type, $type);\n // If no possible parent menu items were found, there is nothing to display.\n if (empty($options)) {\n return;\n }\n\n $form['menu'] = array(\n '#type' => 'fieldset',\n '#title' => t('Menu settings'),\n '#access' => user_access('administer menu'),\n '#collapsible' => TRUE,\n '#collapsed' => !$link['link_title'],\n '#group' => 'additional_settings',\n '#attached' => array(\n 'js' => array(drupal_get_path('module', 'menu') . '/menu.js'),\n ),\n '#tree' => TRUE,\n '#weight' => -2,\n '#attributes' => array('class' => array('menu-link-form')),\n );\n $form['menu']['enabled'] = array(\n '#type' => 'checkbox',\n '#title' => t('Provide a menu link'),\n '#default_value' => (int) (bool) $link['mlid'],\n );\n $form['menu']['link'] = array(\n '#type' => 'container',\n '#parents' => array('menu'),\n '#states' => array(\n 'invisible' => array(\n 'input[name=\"menu[enabled]\"]' => array('checked' => FALSE),\n ),\n ),\n );\n\n // Populate the element with the link data.\n foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden', 'parent_depth_limit') as $key) {\n $form['menu']['link'][$key] = array('#type' => 'value', '#value' => $link[$key]);\n }\n\n $form['menu']['link']['link_title'] = array(\n '#type' => 'textfield',\n '#title' => t('Menu link title'),\n '#maxlength' => 255,\n '#default_value' => $link['link_title'],\n );\n\n $form['menu']['link']['description'] = array(\n '#type' => 'textarea',\n '#title' => t('Description'),\n '#default_value' => isset($link['options']['attributes']['title']) ? $link['options']['attributes']['title'] : '',\n '#rows' => 1,\n '#description' => t('Shown when hovering over the menu link.'),\n );\n\n $default = ($link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : variable_get('menu_parent_' . $type, 'main-menu:0'));\n // If the current parent menu item is not present in options, use the first\n // available option as default value.\n // @todo User should not be allowed to access menu link settings in such a\n // case.\n if (!isset($options[$default])) {\n $array = array_keys($options);\n $default = reset($array);\n }\n $form['menu']['link']['parent'] = array(\n '#type' => 'select',\n '#title' => t('Parent item'),\n '#default_value' => $default,\n '#options' => $options,\n '#attributes' => array('class' => array('menu-parent-select')),\n );\n // Get number of items in all possible parent menus so the weight selector is\n // sized appropriately.\n $menu_names = array_keys(menu_get_menus());\n $menu_options = array();\n foreach ($menu_names as $menu_name) {\n if (isset($options[$menu_name . ':0'])) {\n $menu_options[] = $menu_name;\n }\n }\n // Make sure that we always have values in menu_options.\n $menu_options = !empty($menu_options) ? $menu_options : $menu_names;\n\n $form['menu']['link']['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight'),\n '#delta' => _menu_get_menu_weight_delta($menu_options),\n '#default_value' => $link['weight'],\n '#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3b98d047ff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7009/7.x", "instruction": "In Drupal 7, write the function `node_update_7009()` (file modules/node/node.install) so that it does the following: Convert node languages from the empty string to LANGUAGE_NONE.", "context": "File: modules/node/node.install", "response": "function node_update_7009() {\n db_update('node')\n ->fields(array('language' => LANGUAGE_NONE))\n ->condition('language', '')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ba04720b1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/theme_system_themes_page/7.x", "instruction": "Implement `theme_system_themes_page($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the Appearance page.", "context": "Parameters:\n- $variables: An associative array containing: - theme_groups: An associative array containing groups of themes.\n\nFile: modules/system/system.admin.inc", "response": "function theme_system_themes_page($variables) {\n $theme_groups = $variables['theme_groups'];\n\n $output = '
            ';\n\n foreach ($variables['theme_group_titles'] as $state => $title) {\n if (!count($theme_groups[$state])) {\n // Skip this group of themes if no theme is there.\n continue;\n }\n // Start new theme group.\n $output .= '

            '. $title .'

            ';\n\n foreach ($theme_groups[$state] as $theme) {\n\n // Theme the screenshot.\n $screenshot = $theme->screenshot ? theme('image', $theme->screenshot) : '
            ' . t('no screenshot') . '
            ';\n\n // Localize the theme description.\n $description = t($theme->info['description']);\n\n // Style theme info\n $notes = count($theme->notes) ? ' (' . join(', ', $theme->notes) . ')' : '';\n $theme->classes[] = 'theme-selector';\n $theme->classes[] = 'clearfix';\n $output .= '
            classes) .'\">' . $screenshot . '

            ' . $theme->info['name'] . ' ' . (isset($theme->info['version']) ? $theme->info['version'] : '') . $notes . '

            ' . $description . '
            ';\n\n // Make sure to provide feedback on compatibility.\n if (!empty($theme->incompatible_core)) {\n $output .= '
            ' . t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => DRUPAL_CORE_COMPATIBILITY)) . '
            ';\n }\n elseif (!empty($theme->incompatible_php)) {\n if (substr_count($theme->info['php'], '.') < 2) {\n $theme->info['php'] .= '.*';\n }\n $output .= '
            ' . t('This theme requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $theme->info['php'], '!php_version' => phpversion())) . '
            ';\n }\n else {\n $output .= theme('links', array('links' => $theme->operations, 'attributes' => array('class' => array('operations', 'clearfix'))));\n }\n $output .= '
            ';\n }\n $output .= '
            ';\n }\n $output .= '
            ';\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ba3661dcf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.authorize.inc/function/update_authorize_batch_copy_project/7.x", "instruction": "Implement `update_authorize_batch_copy_project($project, $updater_name, $local_url, $filetransfer, &$context)` in PHP for Drupal 7. Required behavior: Implements callback_batch_operation().", "context": "Copies project to its proper place when authorized to do so.\n\nParameters:\n- $project (string): The canonical short name of the project being installed.\n- $updater_name (string): The name of the Updater class to use for installing this project.\n- $local_url (string): The URL to the locally installed temp directory where the project has already been downloaded and extracted into.\n- $filetransfer (FileTransfer): The FileTransfer object to use for performing this operation.\n- $context (array): Reference to an array used for Batch API storage.\n\nFile: modules/update/update.authorize.inc", "response": "function update_authorize_batch_copy_project($project, $updater_name, $local_url, $filetransfer, &$context) {\n\n // Initialize some variables in the Batch API $context array.\n if (!isset($context['results']['log'])) {\n $context['results']['log'] = array();\n }\n if (!isset($context['results']['log'][$project])) {\n $context['results']['log'][$project] = array();\n }\n\n if (!isset($context['results']['tasks'])) {\n $context['results']['tasks'] = array();\n }\n\n // The batch API uses a session, and since all the arguments are serialized\n // and unserialized between requests, although the FileTransfer object itself\n // will be reconstructed, the connection pointer itself will be lost. However,\n // the FileTransfer object will still have the connection variable, even\n // though the connection itself is now gone. So, although it's ugly, we have\n // to unset the connection variable at this point so that the FileTransfer\n // object will re-initiate the actual connection.\n unset($filetransfer->connection);\n\n if (!empty($context['results']['log'][$project]['#abort'])) {\n $context['finished'] = 1;\n return;\n }\n\n $updater = new $updater_name($local_url);\n\n try {\n if ($updater->isInstalled()) {\n // This is an update.\n $tasks = $updater->update($filetransfer);\n }\n else {\n $tasks = $updater->install($filetransfer);\n }\n }\n catch (UpdaterException $e) {\n _update_batch_create_message($context['results']['log'][$project], t('Error installing / updating'), FALSE);\n _update_batch_create_message($context['results']['log'][$project], $e->getMessage(), FALSE);\n $context['results']['log'][$project]['#abort'] = TRUE;\n return;\n }\n\n _update_batch_create_message($context['results']['log'][$project], t('Installed %project_name successfully', array('%project_name' => $project)));\n if (!empty($tasks)) {\n $context['results']['tasks'] += $tasks;\n }\n\n // This particular operation is now complete, even though the batch might\n // have other operations to perform.\n $context['finished'] = 1;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ba450fe57", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_help/7.x", "instruction": "Implement `rdf_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_help($path, $arg) {\n switch ($path) {\n case 'admin/help#rdf':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The RDF module enriches your content with metadata to let other applications (e.g., search engines, aggregators, and so on) better understand its relationships and attributes. This semantically enriched, machine-readable output for Drupal sites uses the RDFa specification which allows RDF data to be embedded in HTML markup. Other modules can define mappings of their data to RDF terms, and the RDF module makes this RDF data available to the theme. The core Drupal modules define RDF mappings for their data model, and the core Drupal themes output this RDF metadata information along with the human-readable visual information. For more information, see the online handbook entry for RDF module.', array('@rdfa' => 'http://www.w3.org/TR/xhtml-rdfa-primer/', '@rdf' => 'http://drupal.org/documentation/modules/rdf')) . '

            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3bba9f2c96", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_check_rebuild/7.x", "instruction": "I need the code for `_menu_check_rebuild()` in Drupal 7 (includes/menu.inc). It must do this: Checks whether a menu_rebuild() is necessary.", "context": "File: includes/menu.inc", "response": "function _menu_check_rebuild() {\n // To absolutely ensure that the menu rebuild is required, re-load the\n // variables in case they were set by another process.\n $variables = variable_initialize();\n if (empty($variables['menu_rebuild_needed']) && !empty($variables['menu_masks'])) {\n unset($GLOBALS['conf']['menu_rebuild_needed']);\n $GLOBALS['conf']['menu_masks'] = $variables['menu_masks'];\n return FALSE;\n }\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3be1f90c7c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tab_root_path/7.x", "instruction": "Implement `menu_tab_root_path()` in PHP for Drupal 7. Required behavior: Returns the router path, or the path for a default local task's parent.", "context": "File: includes/menu.inc", "response": "function menu_tab_root_path() {\n $links = menu_local_tasks();\n return $links['root_path'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3bec1ca1af", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/theme_aggregator_page_rss/7.x", "instruction": "Implement `theme_aggregator_page_rss($variables)` in PHP for Drupal 7. Required behavior: Prints the RSS page for a feed.", "context": "Parameters:\n- $variables: An associative array containing: - feeds: An array of the feeds to theme. - category: A common category, if any, for all the feeds.\n\nReturns (void)\n\nFile: modules/aggregator/aggregator.pages.inc", "response": "function theme_aggregator_page_rss($variables) {\n $feeds = $variables['feeds'];\n $category = $variables['category'];\n\n drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');\n\n $items = '';\n $feed_length = variable_get('feed_item_length', 'fulltext');\n foreach ($feeds as $feed) {\n switch ($feed_length) {\n case 'teaser':\n $summary = text_summary($feed->description, NULL, variable_get('aggregator_teaser_length', 600));\n if ($summary != $feed->description) {\n $summary .= '

            link) . '\">' . t('read more') . \"

            \\n\";\n }\n $feed->description = $summary;\n break;\n case 'title':\n $feed->description = '';\n break;\n }\n $items .= format_rss_item($feed->ftitle . ': ' . $feed->title, $feed->link, $feed->description, array('pubDate' => date('r', $feed->timestamp)));\n }\n\n $site_name = variable_get('site_name', 'Drupal');\n $url = url((isset($category) ? 'aggregator/categories/' . $category->cid : 'aggregator'), array('absolute' => TRUE));\n $description = isset($category) ? t('@site_name - aggregated feeds in category @title', array('@site_name' => $site_name, '@title' => $category->title)) : t('@site_name - aggregated feeds', array('@site_name' => $site_name));\n\n $output = \"\\n\";\n $output .= \"\\n\";\n $output .= format_rss_channel(t('@site_name aggregator', array('@site_name' => $site_name)), $url, $description, $items);\n $output .= \"\\n\";\n\n print $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3bf519d6e6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_assign_form_validate/7.x", "instruction": "Implement `trigger_assign_form_validate($form, $form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for trigger_assign_form().", "context": "Makes sure that the user is not re-assigning an action to an event.\n\nFile: modules/trigger/trigger.admin.inc", "response": "function trigger_assign_form_validate($form, $form_state) {\n $form_values = $form_state['values'];\n if (!empty($form_values['aid'])) {\n $aid = actions_function_lookup($form_values['aid']);\n $aid_exists = db_query(\"SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid\", array(\n ':hook' => $form_values['hook'],\n ':aid' => $aid,\n ))->fetchField();\n if ($aid_exists) {\n form_set_error($form_values['hook'], t('The action you chose is already assigned to that trigger.'));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3bfb63ac26", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_html_head/7.x", "instruction": "In Drupal 7, write the function `drupal_get_html_head()` (file includes/common.inc) so that it does the following: Retrieves output to be displayed in the HEAD tag of the HTML page.", "context": "File: includes/common.inc", "response": "function drupal_get_html_head() {\n $elements = drupal_add_html_head();\n drupal_alter('html_head', $elements);\n return drupal_render($elements);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3c039ed05b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_file_download_access/7.x", "instruction": "Implement `taxonomy_file_download_access($field, $entity_type, $entity)` in PHP for Drupal 7. Required behavior: Implements hook_file_download_access().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_file_download_access($field, $entity_type, $entity) {\n if ($entity_type == 'taxonomy_term') {\n return user_access('access content');\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3c2a2815b2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_block_view/7.x", "instruction": "I need the code for `statistics_block_view($delta = '')` in Drupal 7 (modules/statistics/statistics.module). It must do this: Implements hook_block_view().", "context": "File: modules/statistics/statistics.module", "response": "function statistics_block_view($delta = '') {\n if (user_access('access content')) {\n $content = array();\n\n $daytop = variable_get('statistics_block_top_day_num', 0);\n if ($daytop && ($result = statistics_title_list('daycount', $daytop)) && ($node_title_list = node_title_list($result, t(\"Today's:\")))) {\n $content['top_day'] = $node_title_list;\n $content['top_day']['#suffix'] = '
            ';\n }\n\n $alltimetop = variable_get('statistics_block_top_all_num', 0);\n if ($alltimetop && ($result = statistics_title_list('totalcount', $alltimetop)) && ($node_title_list = node_title_list($result, t('All time:')))) {\n $content['top_all'] = $node_title_list;\n $content['top_all']['#suffix'] = '
            ';\n }\n\n $lasttop = variable_get('statistics_block_top_last_num', 0);\n if ($lasttop && ($result = statistics_title_list('timestamp', $lasttop)) && ($node_title_list = node_title_list($result, t('Last viewed:')))) {\n $content['top_last'] = $node_title_list;\n $content['top_last']['#suffix'] = '
            ';\n }\n\n if (count($content)) {\n $block['content'] = $content;\n $block['subject'] = t('Popular content');\n return $block;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3c35df2f22", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_schema_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_schema_alter(&$schema, $field)` (modules/field/field.api.php): Allow modules to alter the schema for a field.", "context": "Parameters:\n- $schema (array): The schema definition as returned by hook_field_schema().\n- $field (array): The field definition.\n\nFile: modules/field/field.api.php", "response": "function hook_field_schema_alter(&$schema, $field) {\n if ($field['type'] == 'image') {\n // Alter the length of a field.\n $schema['columns']['alt']['length'] = 2048;\n // Add an additional column of data.\n $schema['columns']['additional_column'] = array(\n 'description' => \"Additional column added to image field table.\",\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => FALSE,\n );\n // Add an additional index.\n $schema['indexes']['fid_additional_column'] = array('fid', 'additional_column');\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3c4bfca4b2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_rotate_form/7.x", "instruction": "Implement `image_rotate_form($data)` in PHP for Drupal 7. Required behavior: Form structure for the image rotate form.", "context": "Note that this is not a complete form, it only contains the portion of the form for configuring the rotate options. Therefore it does not not need to include metadata about the effect, nor a submit button.\n\nParameters:\n- $data: The current configuration for this rotate effect.\n\nFile: modules/image/image.admin.inc", "response": "function image_rotate_form($data) {\n $form['degrees'] = array(\n '#type' => 'textfield',\n '#default_value' => (isset($data['degrees'])) ? $data['degrees'] : 0,\n '#title' => t('Rotation angle'),\n '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'),\n '#field_suffix' => '°',\n '#required' => TRUE,\n '#size' => 6,\n '#maxlength' => 4,\n '#element_validate' => array('image_effect_integer_validate'),\n '#allow_negative' => TRUE,\n );\n $form['bgcolor'] = array(\n '#type' => 'textfield',\n '#default_value' => (isset($data['bgcolor'])) ? $data['bgcolor'] : '#FFFFFF',\n '#title' => t('Background color'),\n '#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'),\n '#size' => 7,\n '#maxlength' => 7,\n '#element_validate' => array('image_effect_color_validate'),\n );\n $form['random'] = array(\n '#type' => 'checkbox',\n '#default_value' => (isset($data['random'])) ? $data['random'] : 0,\n '#title' => t('Randomize'),\n '#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'),\n );\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3c753fa585", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_message_text/7.x", "instruction": "Implement `_update_message_text($msg_type, $msg_reason, $report_link = FALSE, $language = NULL)` in PHP for Drupal 7. Required behavior: Returns the appropriate message text when site is out of date or not secure.", "context": "These error messages are shared by both update_requirements() for the site-wide status report at admin/reports/status and in the body of the notification e-mail messages generated by update_cron().\n\nParameters:\n- $msg_type: String to indicate what kind of message to generate. Can be either 'core' or 'contrib'.\n- $msg_reason: Integer constant specifying why message is generated.\n- $report_link: (optional) Boolean that controls if a link to the updates report should be added. Defaults to FALSE.\n- $language: (optional) A language object to use. Defaults to NULL.\n\nReturns: The properly translated error message for the given key.\n\nFile: modules/update/update.module", "response": "function _update_message_text($msg_type, $msg_reason, $report_link = FALSE, $language = NULL) {\n $langcode = isset($language) ? $language->language : NULL;\n $text = '';\n switch ($msg_reason) {\n case UPDATE_NOT_SECURE:\n if ($msg_type == 'core') {\n $text = t('There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately!', array(), array('langcode' => $langcode));\n }\n else {\n $text = t('There are security updates available for one or more of your modules or themes. To ensure the security of your server, you should update immediately!', array(), array('langcode' => $langcode));\n }\n break;\n\n case UPDATE_REVOKED:\n if ($msg_type == 'core') {\n $text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), array('langcode' => $langcode));\n }\n else {\n $text = t('The installed version of at least one of your modules or themes has been revoked and is no longer available for download. Upgrading or disabling is strongly recommended!', array(), array('langcode' => $langcode));\n }\n break;\n\n case UPDATE_NOT_SUPPORTED:\n if ($msg_type == 'core') {\n $text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), array('langcode' => $langcode));\n }\n else {\n $text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended. See the project homepage for more details.', array(), array('langcode' => $langcode));\n }\n break;\n\n case UPDATE_NOT_CURRENT:\n if ($msg_type == 'core') {\n $text = t('There are updates available for your version of Drupal. To ensure the proper functioning of your site, you should update as soon as possible.', array(), array('langcode' => $langcode));\n }\n else {\n $text = t('There are updates available for one or more of your modules or themes. To ensure the proper functioning of your site, you should update as soon as possible.', array(), array('langcode' => $langcode));\n }\n break;\n\n case UPDATE_UNKNOWN:\n case UPDATE_NOT_CHECKED:\n case UPDATE_NOT_FETCHED:\n case UPDATE_FETCH_PENDING:\n if ($msg_type == 'core') {\n $text = t('There was a problem checking available updates for Drupal.', array('@update-report' => url('admin/reports/updates')), array('langcode' => $langcode));\n }\n else {\n $text = t('There was a problem checking available updates for your modules or themes.', array('@update-report' => url('admin/reports/updates')), array('langcode' => $langcode));\n }\n break;\n }\n\n if ($report_link) {\n if (update_manager_access()) {\n $text .= ' ' . t('See the available updates page for more information and to install your missing updates.', array('@available_updates' => url('admin/reports/updates/update', array('language' => $language))), array('langcode' => $langcode));\n }\n else {\n $text .= ' ' . t('See the available updates page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), array('langcode' => $langcode));\n }\n }\n\n return $text;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3c75d4055a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_prepare_field/7.x", "instruction": "In Drupal 7, write the function `_field_info_prepare_field($field)` (file modules/field/field.info.inc) so that it does the following: Prepares a field definition for the current run-time context.", "context": "The functionality has moved to the FieldInfo class. This function is kept as a backwards-compatibility layer. See http://drupal.org/node/1915646.\n\nFile: modules/field/field.info.inc", "response": "function _field_info_prepare_field($field) {\n $cache = _field_info_field_cache();\n return $cache->prepareField($field);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3c8ed71af0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_admin_paths/7.x", "instruction": "I need the code for `system_admin_paths()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_admin_paths().", "context": "File: modules/system/system.module", "response": "function system_admin_paths() {\n $paths = array(\n 'admin' => TRUE,\n 'admin/*' => TRUE,\n 'batch' => TRUE,\n // This page should not be treated as administrative since it outputs its\n // own content (outside of any administration theme).\n 'admin/reports/status/php' => FALSE,\n );\n return $paths;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3cae48a6d1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_configure_form_validate/7.x", "instruction": "I need the code for `install_configure_form_validate($form, &$form_state)` in Drupal 7 (includes/install.core.inc). It must do this: Form validation handler for install_configure_form().", "context": "File: includes/install.core.inc", "response": "function install_configure_form_validate($form, &$form_state) {\n if ($error = user_validate_name($form_state['values']['account']['name'])) {\n form_error($form['admin_account']['account']['name'], $error);\n }\n if ($error = user_validate_mail($form_state['values']['account']['mail'])) {\n form_error($form['admin_account']['account']['mail'], $error);\n }\n if ($error = user_validate_mail($form_state['values']['site_mail'])) {\n form_error($form['site_information']['site_mail'], $error);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3cbf3c5011", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_prepare_extra_fields/7.x", "instruction": "Implement `_field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Prepares 'extra fields' for the current run-time context.", "context": "The functionality has moved to the FieldInfo class. This function is kept as a backwards-compatibility layer. See http://drupal.org/node/1915646.\n\nFile: modules/field/field.info.inc", "response": "function _field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle) {\n $cache = _field_info_field_cache();\n return $cache->prepareExtraFields($extra_fields, $entity_type, $bundle);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3cc6b58698", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21help%21help.module/function/help_help/7.x", "instruction": "I need the code for `help_help($path, $arg)` in Drupal 7 (modules/help/help.module). It must do this: Implements hook_help().", "context": "File: modules/help/help.module", "response": "function help_help($path, $arg) {\n switch ($path) {\n case 'admin/help':\n $output = '

            ' . t('Follow these steps to set up and start using your website:') . '

            ';\n $output .= '
              ';\n $output .= '
            1. ' . t('Configure your website Once logged in, visit the administration section, where you can customize and configure all aspects of your website.', array('@admin' => url('admin'), '@config' => url('admin/config'))) . '
            2. ';\n $output .= '
            3. ' . t('Enable additional functionality Next, visit the module list and enable features which suit your specific needs. You can find additional modules in the Drupal modules download section.', array('@modules' => url('admin/modules'), '@download_modules' => 'http://drupal.org/project/modules')) . '
            4. ';\n $output .= '
            5. ' . t('Customize your website design To change the \"look and feel\" of your website, visit the themes section. You may choose from one of the included themes or download additional themes from the Drupal themes download section.', array('@themes' => url('admin/appearance'), '@download_themes' => 'http://drupal.org/project/themes')) . '
            6. ';\n $output .= '
            7. ' . t('Start posting content Finally, you can add new content for your website.', array('@content' => url('node/add'))) . '
            8. ';\n $output .= '
            ';\n $output .= '

            ' . t('For more information, refer to the specific topics listed in the next section or to the online Drupal handbooks. You may also post at the Drupal forum or view the wide range of other support options available.', array('@help' => url('admin/help'), '@handbook' => 'http://drupal.org/documentation', '@forum' => 'http://drupal.org/forum', '@support' => 'http://drupal.org/support')) . '

            ';\n return $output;\n case 'admin/help#help':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Help module provides Help reference pages and context-sensitive advice to guide you through the use and configuration of modules. It is a starting point for the online Drupal handbooks. The handbooks contain more extensive and up-to-date information, are annotated with user-contributed comments, and serve as the definitive reference point for all Drupal documentation. For more information, see the online handbook entry for the Help module.', array('@help' => 'http://drupal.org/documentation/modules/help/', '@handbook' => 'http://drupal.org/documentation', '@help-page' => url('admin/help'))) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Providing a help reference') . '
            ';\n $output .= '
            ' . t('The Help module displays explanations for using each module listed on the main Help reference page.', array('@help' => url('admin/help'))) . '
            ';\n $output .= '
            ' . t('Providing context-sensitive help') . '
            ';\n $output .= '
            ' . t('The Help module displays context-sensitive advice and explanations on various pages.') . '
            ';\n $output .= '
            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ccf854aeb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_install/7.x", "instruction": "In Drupal 7, write the function `locale_install()` (file modules/locale/locale.install) so that it does the following: Implements hook_install().", "context": "File: modules/locale/locale.install", "response": "function locale_install() {\n // locales_source.source and locales_target.target are not used as binary\n // fields; non-MySQL database servers need to ensure the field type is text\n // and that LIKE produces a case-sensitive comparison.\n\n db_insert('languages')\n ->fields(array(\n 'language' => 'en',\n 'name' => 'English',\n 'native' => 'English',\n 'direction' => 0,\n 'enabled' => 1,\n 'weight' => 0,\n 'javascript' => '',\n ))\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3cd6526a59", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_links/7.x", "instruction": "Implement `comment_links($comment, $node)` in PHP for Drupal 7. Required behavior: Helper function, build links for an individual comment.", "context": "Adds reply, edit, delete etc. depending on the current user permissions.\n\nParameters:\n- $comment: The comment object.\n- $node: The node the comment is attached to.\n\nReturns: A structured array of links.\n\nFile: modules/comment/comment.module", "response": "function comment_links($comment, $node) {\n $links = array();\n if ($node->comment == COMMENT_NODE_OPEN) {\n if (user_access('administer comments') && user_access('post comments')) {\n $links['comment-delete'] = array(\n 'title' => t('delete'),\n 'href' => \"comment/$comment->cid/delete\",\n 'html' => TRUE,\n );\n $links['comment-edit'] = array(\n 'title' => t('edit'),\n 'href' => \"comment/$comment->cid/edit\",\n 'html' => TRUE,\n );\n $links['comment-reply'] = array(\n 'title' => t('reply'),\n 'href' => \"comment/reply/$comment->nid/$comment->cid\",\n 'html' => TRUE,\n );\n if ($comment->status == COMMENT_NOT_PUBLISHED) {\n $links['comment-approve'] = array(\n 'title' => t('approve'),\n 'href' => \"comment/$comment->cid/approve\",\n 'html' => TRUE,\n 'query' => array('token' => drupal_get_token(\"comment/$comment->cid/approve\")),\n );\n }\n }\n elseif (user_access('post comments')) {\n if (comment_access('edit', $comment)) {\n $links['comment-edit'] = array(\n 'title' => t('edit'),\n 'href' => \"comment/$comment->cid/edit\",\n 'html' => TRUE,\n );\n }\n $links['comment-reply'] = array(\n 'title' => t('reply'),\n 'href' => \"comment/reply/$comment->nid/$comment->cid\",\n 'html' => TRUE,\n );\n }\n else {\n $links['comment_forbidden']['title'] = theme('comment_post_forbidden', array('node' => $node));\n $links['comment_forbidden']['html'] = TRUE;\n }\n }\n return $links;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d04e2a095", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_usage_list/7.x", "instruction": "In Drupal 7, write the function `file_usage_list(stdClass $file)` (file includes/file.inc) so that it does the following: Determines where a file is used.", "context": "Parameters:\n- $file: A file object.\n\nReturns: A nested array with usage data. The first level is keyed by module name, the second by object type and the third by the object id. The value of the third level contains the usage count.\n\nFile: includes/file.inc", "response": "function file_usage_list(stdClass $file) {\n $result = db_select('file_usage', 'f')\n ->fields('f', array('module', 'type', 'id', 'count'))\n ->condition('fid', $file->fid)\n ->condition('count', 0, '>')\n ->execute();\n $references = array();\n foreach ($result as $usage) {\n $references[$usage->module][$usage->type][$usage->id] = $usage->count;\n }\n return $references;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d0c380fb6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_permission/7.x", "instruction": "Implement `filter_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/filter/filter.module", "response": "function filter_permission() {\n $perms['administer filters'] = array(\n 'title' => t('Administer text formats and filters'),\n 'description' => t('Define how text is handled by combining filters into text formats.', array('@url' => url('admin/config/content/formats'))),\n 'restrict access' => TRUE,\n );\n\n // Generate permissions for each text format. Warn the administrator that any\n // of them are potentially unsafe.\n foreach (filter_formats() as $format) {\n $permission = filter_permission_name($format);\n if (!empty($permission)) {\n $format_name_replacement = l($format->name, 'admin/config/content/formats/' . $format->format);\n $perms[$permission] = array(\n 'title' => t(\"Use the !text_format text format\", array('!text_format' => $format_name_replacement,)),\n 'description' => drupal_placeholder(t('Warning: This permission may have security implications depending on how the text format is configured.')),\n );\n }\n }\n return $perms;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d1c906116", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_verify_pdo/7.x", "instruction": "Implement `install_verify_pdo()` in PHP for Drupal 7. Required behavior: Verifies the PDO library.", "context": "File: includes/install.core.inc", "response": "function install_verify_pdo() {\n // PDO was moved to PHP core in 5.2.0, but the old extension (targeting 5.0\n // and 5.1) is still available from PECL, and can still be built without\n // errors. To verify that the correct version is in use, we check the\n // PDO::ATTR_DEFAULT_FETCH_MODE constant, which is not available in the\n // PECL extension.\n return extension_loaded('pdo') && defined('PDO::ATTR_DEFAULT_FETCH_MODE');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d5af1bb29", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/install_profile_info/7.x", "instruction": "In Drupal 7, write the function `install_profile_info($profile, $locale = 'en')` (file includes/install.inc) so that it does the following: Retrieves information about an installation profile from its .info file.", "context": "The information stored in a profile .info file is similar to that stored in\na normal Drupal module .info file. For example:\n- name: The real name of the installation profile for display purposes.\n- description: A brief description of the profile.\n- dependencies: An array of shortnames of other modules that this install\n profile requires.\n\nAdditional, less commonly-used information that can appear in a profile.info\nfile but not in a normal Drupal module .info file includes:\n- distribution_name: The name of the Drupal distribution that is being\n installed, to be shown throughout the installation process. Defaults to\n 'Drupal'.\n- exclusive: If the install profile is intended to be the only eligible\n choice in a distribution, setting exclusive = TRUE will auto-select it\n during installation, and the install profile selection screen will be\n skipped. If more than one profile is found where exclusive = TRUE then\n this property will have no effect and the profile selection screen will\n be shown as normal with all available profiles shown.\n\nNote that this function does an expensive file system scan to get info file information for dependencies. If you only need information from the info file itself, use system_get_info().\n\nExample of .info file:\n\nParameters:\n- $profile: Name of profile.\n- $locale: Name of locale used (if any).\n\nReturns: The info array.\n\nFile: includes/install.inc", "response": "function install_profile_info($profile, $locale = 'en') {\n $cache = &drupal_static(__FUNCTION__, array());\n\n if (!isset($cache[$profile])) {\n // Set defaults for module info.\n $defaults = array(\n 'dependencies' => array(),\n 'description' => '',\n 'distribution_name' => 'Drupal',\n 'version' => NULL,\n 'hidden' => FALSE,\n 'php' => DRUPAL_MINIMUM_PHP,\n );\n $info = drupal_parse_info_file(\"profiles/$profile/$profile.info\") + $defaults;\n $info['dependencies'] = array_unique(array_merge(\n drupal_required_modules(),\n $info['dependencies'],\n ($locale != 'en' && !empty($locale) ? array('locale') : array()))\n );\n\n // drupal_required_modules() includes the current profile as a dependency.\n // Since a module can't depend on itself we remove that element of the array.\n array_shift($info['dependencies']);\n\n $cache[$profile] = $info;\n }\n return $cache[$profile];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d6b826132", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_event/7.x", "instruction": "In Drupal 7, write the function `dblog_event($id)` (file modules/dblog/dblog.admin.inc) so that it does the following: Page callback: Displays details about a specific database log message.", "context": "Parameters:\n- $id (int): Unique ID of the database log message.\n\nReturns (array|string): If the ID is located in the Database Logging table, a build array in the format expected by drupal_render(); otherwise, an empty string.\n\nFile: modules/dblog/dblog.admin.inc", "response": "function dblog_event($id) {\n $severity = watchdog_severity_levels();\n $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = :id', array(':id' => $id))->fetchObject();\n if ($dblog = $result) {\n $rows = array(\n array(\n array('data' => t('Type'), 'header' => TRUE),\n t($dblog->type),\n ),\n array(\n array('data' => t('Date'), 'header' => TRUE),\n format_date($dblog->timestamp, 'long'),\n ),\n array(\n array('data' => t('User'), 'header' => TRUE),\n theme('username', array('account' => $dblog)),\n ),\n array(\n array('data' => t('Location'), 'header' => TRUE),\n l($dblog->location, $dblog->location),\n ),\n array(\n array('data' => t('Referrer'), 'header' => TRUE),\n l($dblog->referer, $dblog->referer),\n ),\n array(\n array('data' => t('Message'), 'header' => TRUE),\n theme('dblog_message', array('event' => $dblog)),\n ),\n array(\n array('data' => t('Severity'), 'header' => TRUE),\n $severity[$dblog->severity],\n ),\n array(\n array('data' => t('Hostname'), 'header' => TRUE),\n check_plain($dblog->hostname),\n ),\n array(\n array('data' => t('Operations'), 'header' => TRUE),\n filter_xss($dblog->link),\n ),\n );\n $build['dblog_table'] = array(\n '#theme' => 'table',\n '#rows' => $rows,\n '#attributes' => array('class' => array('dblog-event')),\n );\n return $build;\n }\n else {\n return '';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d7617655d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_role_delete_confirm_submit/7.x", "instruction": "Implement `user_admin_role_delete_confirm_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submit handler for user_admin_role_delete_confirm().", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_role_delete_confirm_submit($form, &$form_state) {\n user_role_delete((int) $form_state['values']['rid']);\n drupal_set_message(t('The role has been deleted.'));\n $form_state['redirect'] = 'admin/people/permissions/roles';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d82cb6760", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_info_cache_clear/7.x", "instruction": "I need the code for `entity_info_cache_clear()` in Drupal 7 (includes/common.inc). It must do this: Resets the cached information about entity types.", "context": "File: includes/common.inc", "response": "function entity_info_cache_clear() {\n drupal_static_reset('entity_get_info');\n // Clear all languages.\n cache_clear_all('entity_info:', 'cache', TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d8d8f016d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/parse_size/7.x", "instruction": "Implement `parse_size($size)` in PHP for Drupal 7. Required behavior: Parses a given byte count.", "context": "Parameters:\n- $size: A size expressed as a number of bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8 bytes, 9mbytes).\n\nReturns: An integer representation of the size in bytes.\n\nFile: includes/common.inc", "response": "function parse_size($size) {\n $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.\n $size = (float) preg_replace('/[^0-9\\.]/', '', $size); // Remove the non-numeric characters from the size.\n if ($unit) {\n // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.\n return round($size * pow(DRUPAL_KILOBYTE, stripos('bkmgtpezy', $unit[0])));\n }\n else {\n return round($size);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3d9ec84069", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_autop_tips/7.x", "instruction": "In Drupal 7, write the function `_filter_autop_tips($filter, $format, $long = FALSE)` (file modules/filter/filter.module) so that it does the following: Implements callback_filter_tips().", "context": "Provides help for the auto-paragraph filter.\n\nFile: modules/filter/filter.module", "response": "function _filter_autop_tips($filter, $format, $long = FALSE) {\n if ($long) {\n return t('Lines and paragraphs are automatically recognized. The <br /> line break, <p> paragraph and </p> close paragraph tags are inserted automatically. If paragraphs are not recognized simply add a couple blank lines.');\n }\n else {\n return t('Lines and paragraphs break automatically.');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3da392478e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_form_user_admin_settings_alter/7.x", "instruction": "In Drupal 7, write the function `contact_form_user_admin_settings_alter(&$form, &$form_state)` (file modules/contact/contact.module) so that it does the following: Implements hook_form_FORM_ID_alter().", "context": "Add the default personal contact setting on the user settings page.\n\nFile: modules/contact/contact.module", "response": "function contact_form_user_admin_settings_alter(&$form, &$form_state) {\n $form['contact'] = array(\n '#type' => 'fieldset',\n '#title' => t('Contact settings'),\n '#weight' => 0,\n );\n $form['contact']['contact_default_status'] = array(\n '#type' => 'checkbox',\n '#title' => t('Enable the personal contact form by default for new users.'),\n '#description' => t('Changing this setting will not affect existing users.'),\n '#default_value' => variable_get('contact_default_status', 1),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3db2995f72", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_check_directory/7.x", "instruction": "In Drupal 7, write the function `system_check_directory($form_element)` (file modules/system/system.module) so that it does the following: Checks the existence of the directory specified in $form_element.", "context": "This function is called from the system_settings form to check all core file directories (file_public_path, file_private_path, file_temporary_path).\n\nParameters:\n- $form_element: The form element containing the name of the directory to check.\n\nFile: modules/system/system.module", "response": "function system_check_directory($form_element) {\n $directory = $form_element['#value'];\n if (strlen($directory) == 0) {\n return $form_element;\n }\n\n if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {\n // If the directory does not exists and cannot be created.\n form_set_error($form_element['#parents'][0], t('The directory %directory does not exist and could not be created.', array('%directory' => $directory)));\n watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR);\n }\n\n if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) {\n // If the directory is not writable and cannot be made so.\n form_set_error($form_element['#parents'][0], t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory)));\n watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR);\n }\n elseif (is_dir($directory)) {\n if ($form_element['#name'] == 'file_public_path') {\n // Create public .htaccess file.\n file_create_htaccess($directory, FALSE);\n }\n else {\n // Create private .htaccess file.\n file_create_htaccess($directory);\n }\n }\n\n return $form_element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3dc483b365", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_save_data/7.x", "instruction": "Implement `file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME)` in PHP for Drupal 7. Required behavior: Saves a file to the specified destination and creates a database entry.", "context": "Parameters:\n- $data: A string containing the contents of the file.\n- $destination: A string containing the destination URI. This must be a stream wrapper URI. If no value is provided, a randomized name will be generated and the file will be saved using Drupal's default files scheme, usually \"public://\".\n- $replace: Replace behavior when the destination file already exists: - FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with the destination name exists then its database entry will be updated. If no database entry is found then a new one will be created. - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique. - FILE_EXISTS_ERROR - Do nothing and return FALSE.\n\nReturns: A file object, or FALSE on error.\n\nFile: includes/file.inc", "response": "function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) {\n global $user;\n\n if (empty($destination)) {\n $destination = file_default_scheme() . '://';\n }\n if (!file_valid_uri($destination)) {\n watchdog('file', 'The data could not be saved because the destination %destination is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.', array('%destination' => $destination));\n drupal_set_message(t('The data could not be saved, because the destination is invalid. More information is available in the system log.'), 'error');\n return FALSE;\n }\n\n if ($uri = file_unmanaged_save_data($data, $destination, $replace)) {\n // Create a file object.\n $file = new stdClass();\n $file->fid = NULL;\n $file->uri = $uri;\n $file->filename = drupal_basename($uri);\n $file->filemime = file_get_mimetype($file->uri);\n $file->uid = $user->uid;\n $file->status = FILE_STATUS_PERMANENT;\n // If we are replacing an existing file re-use its database record.\n if ($replace == FILE_EXISTS_REPLACE) {\n $existing_files = file_load_multiple(array(), array('uri' => $uri));\n if (count($existing_files)) {\n $existing = reset($existing_files);\n $file->fid = $existing->fid;\n $file->filename = $existing->filename;\n }\n }\n // If we are renaming around an existing file (rather than a directory),\n // use its basename for the filename.\n elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {\n $file->filename = drupal_basename($destination);\n }\n\n return file_save($file);\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3dcb9098fd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_query_parameters/7.x", "instruction": "In Drupal 7, write the function `drupal_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '')` (file includes/common.inc) so that it does the following: Processes a URL query parameter array to remove unwanted elements.", "context": "Parameters:\n- $query: (optional) An array to be processed. Defaults to $_GET.\n- $exclude: (optional) A list of $query array keys to remove. Use \"parent[child]\" to exclude nested items. Defaults to array('q').\n- $parent: Internal use only. Used to build the $query array key for nested items.\n\nReturns: An array containing query parameters, which can be used for url().\n\nFile: includes/common.inc", "response": "function drupal_get_query_parameters(array $query = NULL, array $exclude = array('q'), $parent = '') {\n // Set defaults, if none given.\n if (!isset($query)) {\n $query = $_GET;\n }\n // If $exclude is empty, there is nothing to filter.\n if (empty($exclude)) {\n return $query;\n }\n elseif (!$parent) {\n $exclude = array_flip($exclude);\n }\n\n $params = array();\n foreach ($query as $key => $value) {\n $string_key = ($parent ? $parent . '[' . $key . ']' : $key);\n if (isset($exclude[$string_key])) {\n continue;\n }\n\n if (is_array($value)) {\n $params[$key] = drupal_get_query_parameters($value, $exclude, $string_key);\n }\n else {\n $params[$key] = $value;\n }\n }\n\n return $params;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3de14a8c41", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_admin_add_link/7.x", "instruction": "In Drupal 7, write the function `shortcut_admin_add_link($shortcut_link, &$shortcut_set, $limit = NULL)` (file modules/shortcut/shortcut.admin.inc) so that it does the following: Adds a link to the end of a shortcut set, keeping within a prescribed limit.", "context": "Parameters:\n- $link: An array representing a shortcut link.\n- $shortcut_set: An object representing the shortcut set which the link will be added to. The links in the shortcut set will be re-weighted so that the new link is at the end, and some existing links may be disabled (if the $limit parameter is provided).\n- $limit: (optional) The maximum number of links that are allowed to be enabled for this shortcut set. If provided, existing links at the end of the list that exceed the limit will be automatically disabled. If not provided, no limit will be enforced.\n\nFile: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_admin_add_link($shortcut_link, &$shortcut_set, $limit = NULL) {\n if (isset($limit)) {\n // Disable any existing links at the end of the list that would cause the\n // limit to be exceeded. Take into account whether or not the new link will\n // be enabled and count towards the total.\n $number_enabled = !empty($shortcut_link['hidden']) ? 0 : 1;\n foreach ($shortcut_set->links as &$link) {\n if (!$link['hidden']) {\n $number_enabled++;\n if ($number_enabled > $limit) {\n $link['hidden'] = 1;\n }\n }\n }\n }\n\n // Normalize the path in case it is an alias.\n $shortcut_link['link_path'] = drupal_get_normal_path($shortcut_link['link_path']);\n if (empty($shortcut_link['link_path'])) {\n $shortcut_link['link_path'] = '';\n }\n\n // Add the link to the end of the list.\n $shortcut_set->links[] = $shortcut_link;\n shortcut_set_reset_link_weights($shortcut_set);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3de2b723c9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/drupal_session_regenerate/7.x", "instruction": "In Drupal 7, write the function `drupal_session_regenerate()` (file includes/session.inc) so that it does the following: Called when an anonymous user becomes authenticated or vice-versa.", "context": "File: includes/session.inc", "response": "function drupal_session_regenerate() {\n global $user, $is_https;\n // Nothing to do if we are not allowed to change the session.\n if (!drupal_save_session()) {\n return;\n }\n\n if ($is_https && variable_get('https', FALSE)) {\n $insecure_session_name = substr(session_name(), 1);\n if (!isset($GLOBALS['lazy_session']) && isset($_COOKIE[$insecure_session_name])) {\n $old_insecure_session_id = $_COOKIE[$insecure_session_name];\n }\n $params = session_get_cookie_params();\n $session_id = drupal_random_key();\n // If a session cookie lifetime is set, the session will expire\n // $params['lifetime'] seconds from the current request. If it is not set,\n // it will expire when the browser is closed.\n $expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;\n $options = array(\n 'expires' => $expire,\n 'path' => $params['path'],\n 'domain' => $params['domain'],\n 'secure' => FALSE,\n 'httponly' => $params['httponly'],\n );\n drupal_setcookie($insecure_session_name, $session_id, $options);\n $_COOKIE[$insecure_session_name] = $session_id;\n }\n\n if (drupal_session_started()) {\n $old_session_id = session_id();\n _drupal_session_regenerate_existing();\n }\n else {\n session_id(drupal_random_key());\n }\n\n if (isset($old_session_id)) {\n $params = session_get_cookie_params();\n $expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;\n $options = array(\n 'expires' => $expire,\n 'path' => $params['path'],\n 'domain' => $params['domain'],\n 'secure' => $params['secure'],\n 'httponly' => $params['httponly'],\n );\n drupal_setcookie(session_name(), session_id(), $options);\n $fields = array('sid' => drupal_session_id(session_id()));\n if ($is_https) {\n $fields['ssid'] = drupal_session_id(session_id());\n // If the \"secure pages\" setting is enabled, use the newly-created\n // insecure session identifier as the regenerated sid.\n if (variable_get('https', FALSE)) {\n $fields['sid'] = drupal_session_id($session_id);\n }\n }\n db_update('sessions')\n ->fields($fields)\n ->condition($is_https ? 'ssid' : 'sid', drupal_session_id($old_session_id))\n ->execute();\n }\n elseif (isset($old_insecure_session_id)) {\n // If logging in to the secure site, and there was no active session on the\n // secure site but a session was active on the insecure site, update the\n // insecure session with the new session identifiers.\n db_update('sessions')\n ->fields(array('sid' => drupal_session_id($session_id), 'ssid' => drupal_session_id(session_id())))\n ->condition('sid', drupal_session_id($old_insecure_session_id))\n ->execute();\n }\n else {\n // Start the session when it doesn't exist yet.\n // Preserve the logged in user, as it will be reset to anonymous\n // by _drupal_session_read.\n $account = $user;\n drupal_session_start();\n $user = $account;\n }\n date_default_timezone_set(drupal_get_user_timezone());\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3de8ca8782", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_user_cancel/7.x", "instruction": "I need the code for `trigger_user_cancel($edit, $account, $method)` in Drupal 7 (modules/trigger/trigger.module). It must do this: Implements hook_user_cancel().", "context": "File: modules/trigger/trigger.module", "response": "function trigger_user_cancel($edit, $account, $method) {\n switch ($method) {\n case 'user_cancel_reassign':\n _trigger_user('user_delete', $edit, $account, $method);\n break;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3dff2e2b0e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_switch/7.x", "instruction": "I need the code for `shortcut_set_switch($form, &$form_state, $account = NULL)` in Drupal 7 (modules/shortcut/shortcut.admin.inc). It must do this: Form callback: builds the form for switching shortcut sets.", "context": "Parameters:\n- $form: An associative array containing the structure of the form.\n- $form_state: An associative array containing the current state of the form.\n- $account: (optional) The user account whose shortcuts will be switched. Defaults to the current logged-in user.\n\nReturns: An array representing the form definition.\n\nFile: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_set_switch($form, &$form_state, $account = NULL) {\n global $user;\n if (!isset($account)) {\n $account = $user;\n }\n\n // Prepare the list of shortcut sets.\n $sets = shortcut_sets();\n $current_set = shortcut_current_displayed_set($account);\n\n $options = array();\n foreach ($sets as $name => $set) {\n $options[$name] = check_plain($set->title);\n }\n\n // Only administrators can add shortcut sets.\n $add_access = user_access('administer shortcuts');\n if ($add_access) {\n $options['new'] = t('New set');\n }\n\n if (count($options) > 1) {\n $form['account'] = array(\n '#type' => 'value',\n '#value' => $account,\n );\n\n $form['set'] = array(\n '#type' => 'radios',\n '#title' => $user->uid == $account->uid ? t('Choose a set of shortcuts to use') : t('Choose a set of shortcuts for this user'),\n '#options' => $options,\n '#default_value' => $current_set->set_name,\n );\n\n $form['new'] = array(\n '#type' => 'textfield',\n '#title' => t('Name'),\n '#title_display' => 'invisible',\n '#description' => t('The new set is created by copying items from your default shortcut set.'),\n '#access' => $add_access,\n );\n\n if ($user->uid != $account->uid) {\n $default_set = shortcut_default_set($account);\n $form['new']['#description'] = t('The new set is created by copying items from the %default set.', array('%default' => $default_set->title));\n }\n\n $form['#attached'] = array(\n 'css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.css'),\n 'js' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.js'),\n );\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Change set'),\n );\n }\n else {\n // There is only 1 option, so output a message in the $form array.\n $form['info'] = array(\n '#markup' => '

            ' . t('You are currently using the %set-name shortcut set.', array('%set-name' => $current_set->title)) . '

            ',\n );\n }\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3e01b960f3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_page_delivery_callback_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_page_delivery_callback_alter(&$callback)` (modules/system/system.api.php): Alters the delivery callback used to send the result of the page callback to the browser.", "context": "Called by drupal_deliver_page() to allow modules to alter how the page is delivered to the browser.\n\nThis hook is intended for altering the delivery callback based on information unrelated to the path of the page accessed. For example, it can be used to set the delivery callback based on a HTTP request header (as shown in the code sample). To specify a delivery callback based on path information, use hook_menu() or hook_menu_alter().\n\nThis hook can also be used as an API function that can be used to explicitly set the delivery callback from some other function. For example, for a module named MODULE:\n\nParameters:\n- $callback: The name of a function.\n\nFile: modules/system/system.api.php", "response": "function hook_page_delivery_callback_alter(&$callback) {\n // jQuery sets a HTTP_X_REQUESTED_WITH header of 'XMLHttpRequest'.\n // If a page would normally be delivered as an html page, and it is called\n // from jQuery, deliver it instead as an Ajax response.\n if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && $callback == 'drupal_deliver_html_page') {\n $callback = 'ajax_deliver';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3e0944fae1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_date_format_type_delete/7.x", "instruction": "I need the code for `system_date_format_type_delete($type)` in Drupal 7 (modules/system/system.module). It must do this: Deletes a date type from the database.", "context": "Parameters:\n- $type: The machine-readable name of the date type.\n\nFile: modules/system/system.module", "response": "function system_date_format_type_delete($type) {\n db_delete('date_formats')\n ->condition('type', $type)\n ->execute();\n db_delete('date_format_type')\n ->condition('type', $type)\n ->execute();\n db_delete('date_format_locale')\n ->condition('type', $type)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3e530c440c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_form_forum/7.x", "instruction": "I need the code for `forum_form_forum($form, &$form_state, $edit = array())` in Drupal 7 (modules/forum/forum.admin.inc). It must do this: Form constructor for adding and editing a forum.", "context": "Parameters:\n- $edit: (optional) Associative array containing a forum term to be added or edited. Defaults to an empty array.\n\nFile: modules/forum/forum.admin.inc", "response": "function forum_form_forum($form, &$form_state, $edit = array()) {\n $edit += array(\n 'name' => '',\n 'description' => '',\n 'tid' => NULL,\n 'weight' => 0,\n );\n $form['name'] = array('#type' => 'textfield',\n '#title' => t('Forum name'),\n '#default_value' => $edit['name'],\n '#maxlength' => 255,\n '#description' => t('Short but meaningful name for this collection of threaded discussions.'),\n '#required' => TRUE,\n );\n $form['description'] = array('#type' => 'textarea',\n '#title' => t('Description'),\n '#default_value' => $edit['description'],\n '#description' => t('Description and guidelines for discussions within this forum.'),\n );\n $form['parent']['#tree'] = TRUE;\n $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');\n $form['weight'] = array('#type' => 'weight',\n '#title' => t('Weight'),\n '#default_value' => $edit['weight'],\n '#description' => t('Forums are displayed in ascending order by weight (forums with equal weights are displayed alphabetically).'),\n );\n\n $form['vid'] = array('#type' => 'hidden', '#value' => variable_get('forum_nav_vocabulary', ''));\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));\n if ($edit['tid']) {\n $form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));\n $form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']);\n }\n $form['#submit'][] = 'forum_form_submit';\n $form['#theme'] = 'forum_form';\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3e63b7cb92", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/forum_form_container/7.x", "instruction": "Implement `forum_form_container($form, &$form_state, $edit = array())` in PHP for Drupal 7. Required behavior: Form constructor for adding and editing forum containers.", "context": "Parameters:\n- $edit: (optional) Associative array containing a container term to be added or edited. Defaults to an empty array.\n\nFile: modules/forum/forum.admin.inc", "response": "function forum_form_container($form, &$form_state, $edit = array()) {\n $edit += array(\n 'name' => '',\n 'description' => '',\n 'tid' => NULL,\n 'weight' => 0,\n );\n // Handle a delete operation.\n $form['name'] = array(\n '#title' => t('Container name'),\n '#type' => 'textfield',\n '#default_value' => $edit['name'],\n '#maxlength' => 255,\n '#description' => t('Short but meaningful name for this collection of related forums.'),\n '#required' => TRUE\n );\n\n $form['description'] = array(\n '#type' => 'textarea',\n '#title' => t('Description'),\n '#default_value' => $edit['description'],\n '#description' => t('Description and guidelines for forums within this container.')\n );\n $form['parent']['#tree'] = TRUE;\n $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');\n $form['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight'),\n '#default_value' => $edit['weight'],\n '#description' => t('Containers are displayed in ascending order by weight (containers with equal weights are displayed alphabetically).')\n );\n\n $form['vid'] = array(\n '#type' => 'hidden',\n '#value' => variable_get('forum_nav_vocabulary', ''),\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save')\n );\n if ($edit['tid']) {\n $form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));\n $form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);\n }\n $form['#submit'][] = 'forum_form_submit';\n $form['#theme'] = 'forum_form';\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3e8a449809", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_view_mode_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_entity_view_mode_alter(&$view_mode, $context)` (modules/system/system.api.php): Change the view mode of an entity that is being displayed.", "context": "Parameters:\n- $view_mode (string): The view_mode that is to be used to display the entity.\n- $context (array): Array with contextual information, including: - entity_type: The type of the entity that is being viewed. - entity: The entity object. - langcode: The langcode the entity is being viewed in.\n\nFile: modules/system/system.api.php", "response": "function hook_entity_view_mode_alter(&$view_mode, $context) {\n // For nodes, change the view mode when it is teaser.\n if ($context['entity_type'] == 'node' && $view_mode == 'teaser') {\n $view_mode = 'my_custom_view_mode';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ed6435c43", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_simplify/7.x", "instruction": "I need the code for `search_simplify($text)` in Drupal 7 (modules/search/search.module). It must do this: Simplifies a string according to indexing rules.", "context": "Parameters:\n- $text: Text to simplify.\n\nReturns: Simplified text.\n\nFile: modules/search/search.module", "response": "function search_simplify($text) {\n // Decode entities to UTF-8\n $text = decode_entities($text);\n\n // Lowercase\n $text = drupal_strtolower($text);\n\n // Call an external processor for word handling.\n search_invoke_preprocess($text);\n\n // Simple CJK handling\n if (variable_get('overlap_cjk', TRUE)) {\n $text = preg_replace_callback('/[' . PREG_CLASS_CJK . ']+/u', 'search_expand_cjk', $text);\n }\n\n // To improve searching for numerical data such as dates, IP addresses\n // or version numbers, we consider a group of numerical characters\n // separated only by punctuation characters to be one piece.\n // This also means that searching for e.g. '20/03/1984' also returns\n // results with '20-03-1984' in them.\n // Readable regexp: ([number]+)[punctuation]+(?=[number])\n $text = preg_replace('/([' . PREG_CLASS_NUMBERS . ']+)[' . PREG_CLASS_PUNCTUATION . ']+(?=[' . PREG_CLASS_NUMBERS . '])/u', '\\1', $text);\n\n // Multiple dot and dash groups are word boundaries and replaced with space.\n // No need to use the unicode modifer here because 0-127 ASCII characters\n // can't match higher UTF-8 characters as the leftmost bit of those are 1.\n $text = preg_replace('/[.-]{2,}/', ' ', $text);\n\n // The dot, underscore and dash are simply removed. This allows meaningful\n // search behavior with acronyms and URLs. See unicode note directly above.\n $text = preg_replace('/[._-]+/', '', $text);\n\n // With the exception of the rules above, we consider all punctuation,\n // marks, spacers, etc, to be a word boundary.\n $text = preg_replace('/[' . PREG_CLASS_UNICODE_WORD_BOUNDARY . ']+/u', ' ', $text);\n\n // Truncate everything to 50 characters.\n $words = explode(' ', $text);\n array_walk($words, '_search_index_truncate');\n $text = implode(' ', $words);\n\n return $text;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ed9b3371c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/_drupal_default_html_head/7.x", "instruction": "Implement `_drupal_default_html_head()` in PHP for Drupal 7. Required behavior: Returns elements that are always displayed in the HEAD tag of the HTML page.", "context": "File: includes/common.inc", "response": "function _drupal_default_html_head() {\n // Add default elements. Make sure the Content-Type comes first because the\n // IE browser may be vulnerable to XSS via encoding attacks from any content\n // that comes before this META tag, such as a TITLE tag.\n $elements['system_meta_content_type'] = array(\n '#type' => 'html_tag',\n '#tag' => 'meta',\n '#attributes' => array(\n 'http-equiv' => 'Content-Type',\n 'content' => 'text/html; charset=utf-8',\n ),\n // Security: This always has to be output first.\n '#weight' => -1000,\n );\n // Show Drupal and the major version number in the META GENERATOR tag.\n // Get the major version.\n list($version, ) = explode('.', VERSION);\n $elements['system_meta_generator'] = array(\n '#type' => 'html_tag',\n '#tag' => 'meta',\n '#attributes' => array(\n 'name' => 'Generator',\n 'content' => 'Drupal ' . $version . ' (http://drupal.org)',\n ),\n );\n // Also send the generator in the HTTP header.\n $elements['system_meta_generator']['#attached']['drupal_add_http_header'][] = array('X-Generator', $elements['system_meta_generator']['#attributes']['content']);\n return $elements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3edfabf931", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_view_results/7.x", "instruction": "In Drupal 7, write the function `poll_view_results($node, $view_mode, $block = FALSE)` (file modules/poll/poll.module) so that it does the following: Generates a graphical representation of the results of a poll.", "context": "File: modules/poll/poll.module", "response": "function poll_view_results($node, $view_mode, $block = FALSE) {\n // Make sure that choices are ordered by their weight.\n uasort($node->choice, 'drupal_sort_weight');\n\n // Count the votes and find the maximum.\n $total_votes = 0;\n $max_votes = 0;\n foreach ($node->choice as $choice) {\n if (isset($choice['chvotes'])) {\n $total_votes += $choice['chvotes'];\n $max_votes = max($max_votes, $choice['chvotes']);\n }\n }\n\n $poll_results = '';\n foreach ($node->choice as $i => $choice) {\n if (!empty($choice['chtext'])) {\n $chvotes = isset($choice['chvotes']) ? $choice['chvotes'] : NULL;\n $poll_results .= theme('poll_bar', array('title' => $choice['chtext'], 'votes' => $chvotes, 'total_votes' => $total_votes, 'vote' => isset($node->vote) && $node->vote == $i, 'block' => $block));\n }\n }\n\n return theme('poll_results', array('raw_title' => $node->title, 'results' => $poll_results, 'votes' => $total_votes, 'raw_links' => isset($node->links) ? $node->links : array(), 'block' => $block, 'nid' => $node->nid, 'vote' => isset($node->vote) ? $node->vote : NULL));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3f22db44a5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_radio/7.x", "instruction": "Implement `theme_radio($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a radio button form element.", "context": "Note: The input \"name\" attribute needs to be sanitized before output, which\n is currently done by passing all attributes to drupal_attributes().\n\nParameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #required, #return_value, #value, #attributes, #title, #description\n\nFile: includes/form.inc", "response": "function theme_radio($variables) {\n $element = $variables['element'];\n $element['#attributes']['type'] = 'radio';\n element_set_attributes($element, array('id', 'name', '#return_value' => 'value'));\n\n if (isset($element['#return_value']) && $element['#value'] !== FALSE && $element['#value'] == $element['#return_value']) {\n $element['#attributes']['checked'] = 'checked';\n }\n _form_set_class($element, array('form-radio'));\n\n return '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3f2943a1b2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_permission_name/7.x", "instruction": "Implement `filter_permission_name($format)` in PHP for Drupal 7. Required behavior: Returns the machine-readable permission name for a provided text format.", "context": "Parameters:\n- $format: An object representing a text format.\n\nReturns: The machine-readable permission name, or FALSE if the provided text format is malformed or is the fallback format (which is available to all users).\n\nFile: modules/filter/filter.module", "response": "function filter_permission_name($format) {\n if (isset($format->format) && $format->format != filter_fallback_format()) {\n return 'use text format ' . $format->format;\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3f321344e8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_ranking/7.x", "instruction": "In Drupal 7, write the function `comment_ranking()` (file modules/comment/comment.module) so that it does the following: Implements hook_ranking().", "context": "File: modules/comment/comment.module", "response": "function comment_ranking() {\n return array(\n 'comments' => array(\n 'title' => t('Number of comments'),\n 'join' => array(\n 'type' => 'LEFT',\n 'table' => 'node_comment_statistics',\n 'alias' => 'node_comment_statistics',\n 'on' => 'node_comment_statistics.nid = i.sid',\n ),\n // Inverse law that maps the highest reply count on the site to 1 and 0 to 0.\n 'score' => '2.0 - 2.0 / (1.0 + node_comment_statistics.comment_count * CAST(:scale AS DECIMAL))',\n 'arguments' => array(':scale' => variable_get('node_cron_comments_scale', 0)),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3f357c43e8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_clear_page_cache/7.x", "instruction": "Implement `_menu_clear_page_cache()` in PHP for Drupal 7. Required behavior: Clears the page and block caches at most twice per page load.", "context": "File: includes/menu.inc", "response": "function _menu_clear_page_cache() {\n $cache_cleared = &drupal_static(__FUNCTION__, 0);\n\n // Clear the page and block caches, but at most twice, including at\n // the end of the page load when there are multiple links saved or deleted.\n if ($cache_cleared == 0) {\n cache_clear_all();\n // Keep track of which menus have expanded items.\n _menu_set_expanded_menus();\n $cache_cleared = 1;\n }\n elseif ($cache_cleared == 1) {\n drupal_register_shutdown_function('cache_clear_all');\n // Keep track of which menus have expanded items.\n drupal_register_shutdown_function('_menu_set_expanded_menus');\n $cache_cleared = 2;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3f49818adb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.api.php/function/hook_dashboard_regions/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_dashboard_regions()` (modules/dashboard/dashboard.api.php): Add regions to the dashboard.", "context": "Returns: An array whose keys are the names of the dashboard regions and whose values are the titles that will be displayed in the blocks administration interface. The keys are also used as theme wrapper functions.\n\nFile: modules/dashboard/dashboard.api.php", "response": "function hook_dashboard_regions() {\n // Define a new dashboard region. Your module can also then define\n // theme_mymodule_dashboard_region() as a theme wrapper function to control\n // the region's appearance.\n return array('mymodule_dashboard_region' => \"My module's dashboard region\");\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-3f9e24007a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_write_record/7.x", "instruction": "Implement `drupal_write_record($table, &$record, $primary_keys = array())` in PHP for Drupal 7. Required behavior: Saves (inserts or updates) a record to the database based upon the schema.", "context": "Do not use drupal_write_record() within hook_update_N() functions, since the database schema cannot be relied upon when a user is running a series of updates. Instead, use db_insert() or db_update() to save the record.\n\nParameters:\n- $table: The name of the table; this must be defined by a hook_schema() implementation.\n- $record: An object or array representing the record to write, passed in by reference. If inserting a new record, values not provided in $record will be populated in $record and in the database with the default values from the schema, as well as a single serial (auto-increment) field (if present). If updating an existing record, only provided values are updated in the database, and $record is not modified.\n- $primary_keys: To indicate that this is a new record to be inserted, omit this argument. If this is an update, this argument specifies the primary keys' field names. If there is only 1 field in the key, you may pass in a string; if there are multiple fields in the key, pass in an array.\n\nReturns: If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.\n\nFile: includes/common.inc", "response": "function drupal_write_record($table, &$record, $primary_keys = array()) {\n // Standardize $primary_keys to an array.\n if (is_string($primary_keys)) {\n $primary_keys = array($primary_keys);\n }\n\n $schema = drupal_get_schema($table);\n if (empty($schema)) {\n return FALSE;\n }\n\n $object = (object) $record;\n $fields = array();\n\n // Go through the schema to determine fields to write.\n foreach ($schema['fields'] as $field => $info) {\n if ($info['type'] == 'serial') {\n // Skip serial types if we are updating.\n if (!empty($primary_keys)) {\n continue;\n }\n // Track serial field so we can helpfully populate them after the query.\n // NOTE: Each table should come with one serial field only.\n $serial = $field;\n }\n\n // Skip field if it is in $primary_keys as it is unnecessary to update a\n // field to the value it is already set to.\n if (in_array($field, $primary_keys)) {\n continue;\n }\n\n if (!property_exists($object, $field)) {\n // Skip fields that are not provided, default values are already known\n // by the database.\n continue;\n }\n\n // Build array of fields to update or insert.\n if (empty($info['serialize'])) {\n $fields[$field] = $object->$field;\n }\n else {\n $fields[$field] = serialize($object->$field);\n }\n\n // Type cast to proper datatype, except when the value is NULL and the\n // column allows this.\n //\n // MySQL PDO silently casts e.g. FALSE and '' to 0 when inserting the value\n // into an integer column, but PostgreSQL PDO does not. Also type cast NULL\n // when the column does not allow this.\n if (isset($object->$field) || !empty($info['not null'])) {\n if ($info['type'] == 'int' || $info['type'] == 'serial') {\n $fields[$field] = (int) $fields[$field];\n }\n elseif ($info['type'] == 'float') {\n $fields[$field] = (float) $fields[$field];\n }\n else {\n $fields[$field] = (string) $fields[$field];\n }\n }\n }\n\n if (empty($fields)) {\n return;\n }\n\n // Build the SQL.\n if (empty($primary_keys)) {\n // We are doing an insert.\n $options = array('return' => Database::RETURN_INSERT_ID);\n if (isset($serial) && isset($fields[$serial])) {\n // If the serial column has been explicitly set with an ID, then we don't\n // require the database to return the last insert id.\n if ($fields[$serial]) {\n $options['return'] = Database::RETURN_AFFECTED;\n }\n // If a serial column does exist with no value (i.e. 0) then remove it as\n // the database will insert the correct value for us.\n else {\n unset($fields[$serial]);\n }\n }\n $query = db_insert($table, $options)->fields($fields);\n $return = SAVED_NEW;\n }\n else {\n $query = db_update($table)->fields($fields);\n foreach ($primary_keys as $key) {\n $query->condition($key, $object->$key);\n }\n $return = SAVED_UPDATED;\n }\n\n // Execute the SQL.\n if ($query_return = $query->execute()) {\n if (isset($serial)) {\n // If the database was not told to return the last insert id, it will be\n // because we already know it.\n if (isset($options) && $options['return'] != Database::RETURN_INSERT_ID) {\n $object->$serial = $fields[$serial];\n }\n else {\n $object->$serial = $query_return;\n }\n }\n }\n // If we have a single-field primary key but got no insert ID, the\n // query failed. Note that we explicitly check for FALSE, because\n // a valid update query which doesn't change any values will return\n // zero (0) affected rows.\n elseif ($query_return === FALSE && count($primary_keys) == 1) {\n $return = FALSE;\n }\n\n // If we are inserting, populate empty fields with default values.\n if (empty($primary_keys)) {\n foreach ($schema['fields'] as $field => $info) {\n if (isset($info['default']) && !property_exists($object, $field)) {\n $object->$field = $info['default'];\n }\n }\n }\n\n // If we began with an array, convert back.\n if (is_array($record)) {\n $record = (array) $object;\n }\n\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3fbd52b36a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_project_status_sort/7.x", "instruction": "I need the code for `_update_project_status_sort($a, $b)` in Drupal 7 (modules/update/update.module). It must do this: Orders projects based on their status.", "context": "Callback for uasort() within update_requirements().\n\nFile: modules/update/update.module", "response": "function _update_project_status_sort($a, $b) {\n // The status constants are numerically in the right order, so we can\n // usually subtract the two to compare in the order we want. However,\n // negative status values should be treated as if they are huge, since we\n // always want them at the bottom of the list.\n $a_status = $a['status'] > 0 ? $a['status'] : (-10 * $a['status']);\n $b_status = $b['status'] > 0 ? $b['status'] : (-10 * $b['status']);\n return $a_status - $b_status;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3fc89eb83e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_delete/7.x", "instruction": "Implement `poll_delete($node)` in PHP for Drupal 7. Required behavior: Implements hook_delete().", "context": "File: modules/poll/poll.module", "response": "function poll_delete($node) {\n db_delete('poll')\n ->condition('nid', $node->nid)\n ->execute();\n db_delete('poll_choice')\n ->condition('nid', $node->nid)\n ->execute();\n db_delete('poll_vote')\n ->condition('nid', $node->nid)\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-3fccbd3700", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_delete_revision/7.x", "instruction": "Implement `field_attach_delete_revision($entity_type, $entity)` in PHP for Drupal 7. Required behavior: Delete field data for a single revision of an existing entity. The passed entity must have a revision id attribute.", "context": "Parameters:\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entity: The entity with fields to save.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_delete_revision($entity_type, $entity) {\n _field_invoke('delete_revision', $entity_type, $entity);\n\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n // Collect the storage backends used by the fields in the entities.\n $storages = array();\n foreach (field_info_instances($entity_type, $bundle) as $instance) {\n $field = field_info_field_by_id($instance['field_id']);\n $field_id = $field['id'];\n $storages[$field['storage']['type']][$field_id] = $field_id;\n }\n\n // Field storage backends delete their data.\n foreach ($storages as $storage => $fields) {\n $storage_info = field_info_storage_types($storage);\n module_invoke($storage_info['module'], 'field_storage_delete_revision', $entity_type, $entity, $fields);\n }\n\n // Let other modules act on deleting the revision.\n module_invoke_all('field_attach_delete_revision', $entity_type, $entity);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-3ffda884af", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_7004/7.x", "instruction": "Implement `image_update_7004()` in PHP for Drupal 7. Required behavior: Use a large setting (512 and 1024 characters) for the length of the image alt and title fields.", "context": "File: modules/image/image.install", "response": "function image_update_7004() {\n $alt_spec = array(\n 'type' => 'varchar',\n 'length' => 512,\n 'not null' => FALSE,\n );\n\n $title_spec = array(\n 'type' => 'varchar',\n 'length' => 1024,\n 'not null' => FALSE,\n );\n\n $fields = _update_7000_field_read_fields(array(\n 'module' => 'image',\n 'storage_type' => 'field_sql_storage',\n ));\n\n foreach ($fields as $field_name => $field) {\n $tables = array(\n _field_sql_storage_tablename($field),\n _field_sql_storage_revision_tablename($field),\n );\n $alt_column = $field['field_name'] . '_alt';\n $title_column = $field['field_name'] . '_title';\n foreach ($tables as $table) {\n db_change_field($table, $alt_column, $alt_column, $alt_spec);\n db_change_field($table, $title_column, $title_column, $title_spec);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-4027fb270f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_view_multiple/7.x", "instruction": "I need the code for `taxonomy_term_view_multiple($terms, $view_mode = 'teaser', $weight = 0, $langcode = NULL)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Constructs a drupal_render() style array from an array of loaded terms.", "context": "Parameters:\n- $terms: An array of taxonomy terms as returned by taxonomy_term_load_multiple().\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $weight: An integer representing the weight of the first taxonomy term in the list.\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nReturns: An array in the format expected by drupal_render().\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_term_view_multiple($terms, $view_mode = 'teaser', $weight = 0, $langcode = NULL) {\n $build = array();\n $entities_by_view_mode = entity_view_mode_prepare('taxonomy_term', $terms, $view_mode, $langcode);\n foreach ($entities_by_view_mode as $entity_view_mode => $entities) {\n field_attach_prepare_view('taxonomy_term', $entities, $entity_view_mode, $langcode);\n entity_prepare_view('taxonomy_term', $entities, $langcode);\n\n foreach ($entities as $entity) {\n $build['taxonomy_terms'][$entity->tid] = taxonomy_term_view($entity, $entity_view_mode, $langcode);\n }\n }\n\n foreach ($terms as $term) {\n $build['taxonomy_terms'][$term->tid]['#weight'] = $weight;\n $weight++;\n }\n // Sort here, to preserve the input order of the entities that were passed to\n // this function.\n uasort($build['taxonomy_terms'], 'element_sort');\n $build['taxonomy_terms']['#sorted'] = TRUE;\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-403b1734e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.tokens.inc/function/node_token_info/7.x", "instruction": "Implement `node_token_info()` in PHP for Drupal 7. Required behavior: Implements hook_token_info().", "context": "File: modules/node/node.tokens.inc", "response": "function node_token_info() {\n $type = array(\n 'name' => t('Nodes'),\n 'description' => t('Tokens related to individual content items, or \"nodes\".'),\n 'needs-data' => 'node',\n );\n\n // Core tokens for nodes.\n $node['nid'] = array(\n 'name' => t(\"Content ID\"),\n 'description' => t('The unique ID of the content item, or \"node\".'),\n );\n $node['vid'] = array(\n 'name' => t(\"Revision ID\"),\n 'description' => t(\"The unique ID of the node's latest revision.\"),\n );\n $node['tnid'] = array(\n 'name' => t(\"Translation set ID\"),\n 'description' => t(\"The unique ID of the original-language version of this node, if one exists.\"),\n );\n $node['type'] = array(\n 'name' => t(\"Content type\"),\n 'description' => t(\"The type of the node.\"),\n );\n $node['type-name'] = array(\n 'name' => t(\"Content type name\"),\n 'description' => t(\"The human-readable name of the node type.\"),\n );\n $node['title'] = array(\n 'name' => t(\"Title\"),\n 'description' => t(\"The title of the node.\"),\n );\n $node['body'] = array(\n 'name' => t(\"Body\"),\n 'description' => t(\"The main body text of the node.\"),\n );\n $node['summary'] = array(\n 'name' => t(\"Summary\"),\n 'description' => t(\"The summary of the node's main body text.\"),\n );\n $node['language'] = array(\n 'name' => t(\"Language\"),\n 'description' => t(\"The language the node is written in.\"),\n );\n $node['url'] = array(\n 'name' => t(\"URL\"),\n 'description' => t(\"The URL of the node.\"),\n );\n $node['edit-url'] = array(\n 'name' => t(\"Edit URL\"),\n 'description' => t(\"The URL of the node's edit page.\"),\n );\n\n // Chained tokens for nodes.\n $node['created'] = array(\n 'name' => t(\"Date created\"),\n 'description' => t(\"The date the node was posted.\"),\n 'type' => 'date',\n );\n $node['changed'] = array(\n 'name' => t(\"Date changed\"),\n 'description' => t(\"The date the node was most recently updated.\"),\n 'type' => 'date',\n );\n $node['author'] = array(\n 'name' => t(\"Author\"),\n 'description' => t(\"The author of the node.\"),\n 'type' => 'user',\n );\n\n return array(\n 'types' => array('node' => $type),\n 'tokens' => array('node' => $node),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-408efa0ddb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_build_content/7.x", "instruction": "In Drupal 7, write the function `node_build_content($node, $view_mode = 'full', $langcode = NULL)` (file modules/node/node.module) so that it does the following: Builds a structured array representing the node's content.", "context": "The content built for the node (field values, comments, file attachments or other node components) will vary depending on the $view_mode parameter.\n\nDrupal core defines the following view modes for nodes, with the following\ndefault use cases:\n - full (default): node is being displayed on its own page (node/123)\n - teaser: node is being displayed on the default home page listing, on\n taxonomy listing pages, or on blog listing pages.\n - rss: node displayed in an RSS feed.\n If search.module is enabled:\n - search_index: node is being indexed for search.\n - search_result: node is being displayed as a search result.\n If book.module is enabled:\n - print: node is being displayed in print-friendly mode.\nContributed modules might define additional view modes, or use existing\nview modes in additional contexts.\n\nParameters:\n- $node: A node object.\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nFile: modules/node/node.module", "response": "function node_build_content($node, $view_mode = 'full', $langcode = NULL) {\n if (!isset($langcode)) {\n $langcode = $GLOBALS['language_content']->language;\n }\n\n // Remove previously built content, if exists.\n $node->content = array();\n\n // Allow modules to change the view mode.\n $view_mode = key(entity_view_mode_prepare('node', array($node->nid => $node), $view_mode, $langcode));\n\n // The 'view' hook can be implemented to overwrite the default function\n // to display nodes.\n if (node_hook($node, 'view')) {\n $node = node_invoke($node, 'view', $view_mode, $langcode);\n }\n\n // Build fields content.\n // In case of a multiple view, node_view_multiple() already ran the\n // 'prepare_view' step. An internal flag prevents the operation from running\n // twice.\n field_attach_prepare_view('node', array($node->nid => $node), $view_mode, $langcode);\n entity_prepare_view('node', array($node->nid => $node), $langcode);\n $node->content += field_attach_view('node', $node, $view_mode, $langcode);\n\n // Always display a read more link on teasers because we have no way to know\n // when a teaser view is different than a full view.\n $links = array();\n $node->content['links'] = array(\n '#theme' => 'links__node',\n '#pre_render' => array('drupal_pre_render_links'),\n '#attributes' => array('class' => array('links', 'inline')),\n );\n if ($view_mode == 'teaser') {\n $node_title_stripped = strip_tags($node->title);\n $links['node-readmore'] = array(\n 'title' => t('Read more about @title', array('@title' => $node_title_stripped)),\n 'href' => 'node/' . $node->nid,\n 'html' => TRUE,\n 'attributes' => array('rel' => 'tag', 'title' => $node_title_stripped),\n );\n }\n $node->content['links']['node'] = array(\n '#theme' => 'links__node__node',\n '#links' => $links,\n '#attributes' => array('class' => array('links', 'inline')),\n );\n\n // Allow modules to make their own additions to the node.\n module_invoke_all('node_view', $node, $view_mode, $langcode);\n module_invoke_all('entity_view', $node, 'node', $view_mode, $langcode);\n\n // Make sure the current view mode is stored if no module has already\n // populated the related key.\n $node->content += array('#view_mode' => $view_mode);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-409e339be7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/drupal_session_destroy_uid/7.x", "instruction": "Implement `drupal_session_destroy_uid($uid)` in PHP for Drupal 7. Required behavior: Ends a specific user's session(s).", "context": "Parameters:\n- $uid: User ID.\n\nFile: includes/session.inc", "response": "function drupal_session_destroy_uid($uid) {\n // Nothing to do if we are not allowed to change the session.\n if (!drupal_save_session()) {\n return;\n }\n\n db_delete('sessions')\n ->condition('uid', $uid)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-409f440e66", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.parser.inc/function/aggregator_element_start/7.x", "instruction": "In Drupal 7, write the function `aggregator_element_start($parser, $name, $attributes)` (file modules/aggregator/aggregator.parser.inc) so that it does the following: Performs an action when an opening tag is encountered.", "context": "Callback function used by xml_parse() within aggregator_parse_feed().\n\nFile: modules/aggregator/aggregator.parser.inc", "response": "function aggregator_element_start($parser, $name, $attributes) {\n global $item, $element, $tag, $items, $channel;\n\n $name = strtolower($name);\n switch ($name) {\n case 'image':\n case 'textinput':\n case 'summary':\n case 'tagline':\n case 'subtitle':\n case 'logo':\n case 'info':\n $element = $name;\n break;\n case 'id':\n case 'content':\n if ($element != 'item') {\n $element = $name;\n }\n case 'link':\n // According to RFC 4287, link elements in Atom feeds without a 'rel'\n // attribute should be interpreted as though the relation type is\n // \"alternate\".\n if (!empty($attributes['HREF']) && (empty($attributes['REL']) || $attributes['REL'] == 'alternate')) {\n if ($element == 'item') {\n $items[$item]['link'] = $attributes['HREF'];\n }\n else {\n $channel['link'] = $attributes['HREF'];\n }\n }\n break;\n case 'item':\n $element = $name;\n $item += 1;\n break;\n case 'entry':\n $element = 'item';\n $item += 1;\n break;\n }\n\n $tag = $name;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-40d2b48aff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_static/7.x", "instruction": "Implement `&drupal_static($name, $default_value = NULL, $reset = FALSE)` in PHP for Drupal 7. Required behavior: Provides central static variable storage.", "context": "All functions requiring a static variable to persist or cache data within a single page request are encouraged to use this function unless it is absolutely certain that the static variable will not need to be reset during the page request. By centralizing static variable storage through this function, other functions can rely on a consistent API for resetting any other function's static variables.\n\nExample:\n\nParameters:\n- $name: Globally unique name for the variable. For a function with only one static, variable, the function name (e.g. via the PHP magic __FUNCTION__ constant) is recommended. For a function with multiple static variables add a distinguishing suffix to the function name for each one.\n- $default_value: Optional default value.\n- $reset: TRUE to reset one or all variables(s). This parameter is only used internally and should not be passed in; use drupal_static_reset() instead. (This function's return value should not be used when TRUE is passed in.)\n\nReturns: Returns a variable by reference.\n\nFile: includes/bootstrap.inc", "response": "function &drupal_static($name, $default_value = NULL, $reset = FALSE) {\n static $data = array(), $default = array();\n // First check if dealing with a previously defined static variable.\n if (isset($data[$name]) || array_key_exists($name, $data)) {\n // Non-NULL $name and both $data[$name] and $default[$name] statics exist.\n if ($reset) {\n // Reset pre-existing static variable to its default value.\n $data[$name] = $default[$name];\n }\n return $data[$name];\n }\n // Neither $data[$name] nor $default[$name] static variables exist.\n if (isset($name)) {\n if ($reset) {\n // Reset was called before a default is set and yet a variable must be\n // returned.\n return $data;\n }\n // First call with new non-NULL $name. Initialize a new static variable.\n $default[$name] = $data[$name] = $default_value;\n return $data[$name];\n }\n // Reset all: ($name == NULL). This needs to be done one at a time so that\n // references returned by earlier invocations of drupal_static() also get\n // reset.\n foreach ($default as $name => $value) {\n $data[$name] = $value;\n }\n // As the function returns a reference, the return should always be a\n // variable.\n return $data;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-40d689703d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_message_parse/7.x", "instruction": "Implement `xmlrpc_message_parse($xmlrpc_message)` in PHP for Drupal 7. Required behavior: Parses an XML-RPC message.", "context": "If parsing fails, the faultCode and faultString will be added to the message object.\n\nParameters:\n- $xmlrpc_message: An object generated by xmlrpc_message().\n\nReturns: TRUE if parsing succeeded; FALSE otherwise.\n\nFile: includes/xmlrpc.inc", "response": "function xmlrpc_message_parse($xmlrpc_message) {\n $xmlrpc_message->_parser = xml_parser_create();\n // Set XML parser to take the case of tags into account.\n xml_parser_set_option($xmlrpc_message->_parser, XML_OPTION_CASE_FOLDING, FALSE);\n // Set XML parser callback functions\n xml_set_element_handler($xmlrpc_message->_parser, 'xmlrpc_message_tag_open', 'xmlrpc_message_tag_close');\n xml_set_character_data_handler($xmlrpc_message->_parser, 'xmlrpc_message_cdata');\n xmlrpc_message_set($xmlrpc_message);\n\n // Strip XML declaration.\n $header = preg_replace('/<\\?xml.*?\\?'.'>/s', '', substr($xmlrpc_message->message, 0, 100), 1);\n $xml = trim(substr_replace($xmlrpc_message->message, $header, 0, 100));\n if ($xml == '') {\n return FALSE;\n }\n // Strip DTD.\n $header = preg_replace('/^]*+>/i', '', substr($xml, 0, 200), 1);\n $xml = trim(substr_replace($xml, $header, 0, 200));\n if ($xml == '') {\n return FALSE;\n }\n // Confirm the XML now starts with a valid root tag. A root tag can end in [> \\t\\r\\n]\n $root_tag = substr($xml, 0, strcspn(substr($xml, 0, 20), \"> \\t\\r\\n\"));\n // Reject a second DTD.\n if (strtoupper($root_tag) == 'loadXML($xml);\n if ($dom->getElementsByTagName('*')->length > variable_get('xmlrpc_message_maximum_tag_count', 30000)) {\n return FALSE;\n }\n }\n catch (Exception $e) {\n return FALSE;\n }\n\n if (!xml_parse($xmlrpc_message->_parser, $xml)) {\n return FALSE;\n }\n xml_parser_free($xmlrpc_message->_parser);\n\n // Grab the error messages, if any.\n $xmlrpc_message = xmlrpc_message_get();\n if (!isset($xmlrpc_message->messagetype)) {\n return FALSE;\n }\n elseif ($xmlrpc_message->messagetype == 'fault') {\n $xmlrpc_message->fault_code = $xmlrpc_message->params[0]['faultCode'];\n $xmlrpc_message->fault_string = $xmlrpc_message->params[0]['faultString'];\n }\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-40fae1b6cb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_link_insert/7.x", "instruction": "Give me the example code for `hook_menu_link_insert($link)` in Drupal 7. Hook description: Inform modules that a menu link has been created.", "context": "This hook is used to notify modules that menu items have been created. Contributed modules may use the information to perform actions based on the information entered into the menu system.\n\nParameters:\n- $link: Associative array defining a menu link as passed into menu_link_save().\n\nFile: modules/system/system.api.php", "response": "function hook_menu_link_insert($link) {\n // In our sample case, we track menu items as editing sections\n // of the site. These are stored in our table as 'disabled' items.\n $record['mlid'] = $link['mlid'];\n $record['menu_name'] = $link['menu_name'];\n $record['status'] = 0;\n drupal_write_record('menu_example', $record);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-4111f2a27f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_submit/7.x", "instruction": "Give me the example code for `hook_node_submit($node, $form, &$form_state)` in Drupal 7. Hook description: Act on a node after validated form values have been copied to it.", "context": "This hook is invoked when a node form is submitted with either the \"Save\" or \"Preview\" button, after form values have been copied to the form state's node object, but before the node is saved or previewed. It is a chance for modules to adjust the node's properties from what they are simply after a copy from $form_state['values']. This hook is intended for adjusting non-field-related properties. See hook_field_attach_submit() for customizing field-related properties.\n\nParameters:\n- $node: The node object being updated in response to a form submission.\n- $form: The form being used to edit the node.\n- $form_state: The form state array.\n\nFile: modules/node/node.api.php", "response": "function hook_node_submit($node, $form, &$form_state) {\n // Decompose the selected menu parent option into 'menu_name' and 'plid', if\n // the form used the default parent selection widget.\n if (!empty($form_state['values']['menu']['parent'])) {\n list($node->menu['menu_name'], $node->menu['plid']) = explode(':', $form_state['values']['menu']['parent']);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-41274b839f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/element_sort/7.x", "instruction": "In Drupal 7, write the function `element_sort($a, $b)` (file includes/common.inc) so that it does the following: Function used by uasort to sort structured arrays by weight.", "context": "File: includes/common.inc", "response": "function element_sort($a, $b) {\n $a_weight = (is_array($a) && isset($a['#weight'])) ? $a['#weight'] : 0;\n $b_weight = (is_array($b) && isset($b['#weight'])) ? $b['#weight'] : 0;\n if ($a_weight == $b_weight) {\n return 0;\n }\n return ($a_weight < $b_weight) ? -1 : 1;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-412775b638", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_url_inbound_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_url_inbound_alter(&$path, $original_path, $path_language)` (modules/system/system.api.php): Alters inbound URL requests.", "context": "Parameters:\n- $path: The path being constructed, which, if a path alias, has been resolved to a Drupal path by the database, and which also may have been altered by other modules before this one.\n- $original_path: The original path, before being checked for path aliases or altered by any modules.\n- $path_language: The language of the path.\n\nFile: modules/system/system.api.php", "response": "function hook_url_inbound_alter(&$path, $original_path, $path_language) {\n // Create the path user/me/edit, which allows a user to edit their account.\n if (preg_match('|^user/me/edit(/.*)?|', $path, $matches)) {\n global $user;\n $path = 'user/' . $user->uid . '/edit' . $matches[1];\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-41379b2f04", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_names/7.x", "instruction": "I need the code for `menu_get_names()` in Drupal 7 (includes/menu.inc). It must do this: Build a list of named menus.", "context": "File: includes/menu.inc", "response": "function menu_get_names() {\n $names = &drupal_static(__FUNCTION__);\n\n if (empty($names)) {\n $names = db_select('menu_links')\n ->distinct()\n ->fields('menu_links', array('menu_name'))\n ->orderBy('menu_name')\n ->execute()->fetchCol();\n }\n return $names;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-413c95ecc1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_router_cache/7.x", "instruction": "Implement `_menu_router_cache($new_menu = NULL)` in PHP for Drupal 7. Required behavior: Stores the menu router if we have it in memory.", "context": "File: includes/menu.inc", "response": "function _menu_router_cache($new_menu = NULL) {\n $menu = &drupal_static(__FUNCTION__);\n\n if (isset($new_menu)) {\n $menu = $new_menu;\n }\n return $menu;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-41532fb1be", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_languages_overview_form_submit/7.x", "instruction": "Implement `locale_languages_overview_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process language overview form submissions, updating existing languages.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_languages_overview_form_submit($form, &$form_state) {\n $languages = language_list();\n $default = language_default();\n $url_prefixes = variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX;\n $enabled_count = 0;\n\n foreach ($languages as $langcode => $language) {\n if ($form_state['values']['site_default'] == $langcode || $default->language == $langcode) {\n // Automatically enable the default language and the language\n // which was default previously (because we will not get the\n // value from that disabled checkbox).\n $form_state['values']['enabled'][$langcode] = 1;\n }\n\n // If language URL prefixes are enabled we must clear language domains and\n // assign a valid prefix to each non-default language.\n if ($url_prefixes) {\n $language->domain = '';\n if (empty($language->prefix) && $form_state['values']['site_default'] != $langcode) {\n $language->prefix = $langcode;\n }\n }\n\n if ($form_state['values']['enabled'][$langcode]) {\n $enabled_count++;\n $language->enabled = 1;\n }\n else {\n $language->enabled = 0;\n }\n\n $language->weight = $form_state['values']['weight'][$langcode];\n\n db_update('languages')\n ->fields(array(\n 'enabled' => $language->enabled,\n 'weight' => $language->weight,\n 'prefix' => $language->prefix,\n 'domain' => $language->domain,\n ))\n ->condition('language', $langcode)\n ->execute();\n\n $languages[$langcode] = $language;\n }\n\n variable_set('language_default', $languages[$form_state['values']['site_default']]);\n variable_set('language_count', $enabled_count);\n drupal_set_message(t('Configuration saved.'));\n\n // Changing the language settings impacts the interface.\n cache_clear_all('*', 'cache_page', TRUE);\n module_invoke_all('multilingual_settings_changed');\n\n $form_state['redirect'] = 'admin/config/regional/language';\n return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-41a6dd50cc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/template_preprocess_aggregator_item/7.x", "instruction": "I need the code for `template_preprocess_aggregator_item(&$variables)` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Processes variables for aggregator-item.tpl.php.", "context": "File: modules/aggregator/aggregator.pages.inc", "response": "function template_preprocess_aggregator_item(&$variables) {\n $item = $variables['item'];\n\n $variables['feed_url'] = check_url($item->link);\n $variables['feed_title'] = check_plain($item->title);\n $variables['content'] = aggregator_filter_xss($item->description);\n\n $variables['source_url'] = '';\n $variables['source_title'] = '';\n if (isset($item->ftitle) && isset($item->fid)) {\n $variables['source_url'] = url(\"aggregator/sources/$item->fid\");\n $variables['source_title'] = check_plain($item->ftitle);\n }\n if (date('Ymd', $item->timestamp) == date('Ymd')) {\n $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->timestamp)));\n }\n else {\n $variables['source_date'] = format_date($item->timestamp, 'custom', variable_get('date_format_medium', 'D, m/d/Y - H:i'));\n }\n\n $variables['categories'] = array();\n foreach ($item->categories as $category) {\n $variables['categories'][$category->cid] = l($category->title, 'aggregator/categories/' . $category->cid);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-41bad8771b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_mapping_save/7.x", "instruction": "Implement `rdf_mapping_save($mapping)` in PHP for Drupal 7. Required behavior: Saves an RDF mapping to the database.", "context": "Takes a mapping structure returned by hook_rdf_mapping() implementations and creates or updates a record mapping for each encountered entity type/bundle pair. If available, adds default values for non-existent mapping keys.\n\nParameters:\n- $mapping: The RDF mapping to save, as an array.\n\nReturns: Status flag indicating the outcome of the operation.\n\nFile: modules/rdf/rdf.module", "response": "function rdf_mapping_save($mapping) {\n // In the case where a field has a mapping defined in the default entity\n // mapping, but a mapping is not specified in the bundle-specific mapping,\n // then use the default mapping for that field.\n $mapping['mapping'] += _rdf_get_default_mapping($mapping['type']);\n\n $status = db_merge('rdf_mapping')\n ->key(array(\n 'type' => $mapping['type'],\n 'bundle' => $mapping['bundle'],\n ))\n ->fields(array(\n 'mapping' => serialize($mapping['mapping']),\n ))\n ->execute();\n\n entity_info_cache_clear();\n\n return $status;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-41d13b8a68", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_theme/7.x", "instruction": "Give me the example code for `hook_theme($existing, $type, $theme, $path)` in Drupal 7. Hook description: Register a module (or theme's) theme implementations.", "context": "The implementations declared by this hook have two purposes: either they specify how a particular render array is to be rendered as HTML (this is usually the case if the theme function is assigned to the render array's #theme property), or they return the HTML that should be returned by an invocation of theme(). See\n\nParameters:\n- $existing (array): An array of existing implementations that may be used for override purposes. This is primarily useful for themes that may wish to examine existing implementations to extract data (such as arguments) so that it may properly register its own, higher priority implementations.\n- $type: Whether a theme, module, etc. is being processed. This is primarily useful so that themes tell if they are the actual theme being called or a parent theme. May be one of: - 'module': A module is being checked for theme implementations. - 'base_theme_engine': A theme engine is being checked for a theme that is a parent of the actual theme being used. - 'theme_engine': A theme engine is being checked for the actual theme being used. - 'base_theme': A base theme is being checked for theme implementations. - 'theme': The actual theme in use is being checked.\n- $theme: The actual name of theme, module, etc. that is being being processed.\n- $path: The directory path of the theme or module, so that it doesn't need to be looked up.\n\nReturns (array): An associative array of theme hook information. The keys on the outer array are the internal names of the hooks, and the values are arrays containing information about the hook. Each information array must contain either a 'variables' element or a 'render element' element, but not both. Use 'render element' if you are theming a single element or element tree composed of elements, such as a form array, a page array, or a single checkbox element. Use 'variables' if your theme implementation is intended to be called directly through theme() and has multiple arguments for the data and style; in this case, the variables not supplied by the calling function will be given default values and passed to the template or theme function. The returned theme information array can contain the following key/value pairs: - variables: (see above) Each array key is the name of the variable, and the value given is used as the default value if the function calling theme() does not supply it. Template implementations receive each array key as a variable in the template file (so they must be legal PHP variable names). Function implementations are passed the variables in a single $variables function argument. - render element: (see above) The name of the renderable element or element tree to pass to the theme function. This name is used as the name of the variable that holds the renderable element or tree in preprocess and process functions. - file: The file the implementation resides in. This file will be included prior to the theme being rendered, to make sure that the function or preprocess function (as needed) is actually loaded; this makes it possible to split theme functions out into separate files quite easily. - path: Override the path of the file to be used. Ordinarily the module or theme path will be used, but if the file will not be in the default path, include it here. This path should be relative to the Drupal root directory. - template: If specified, this theme implementation is a template, and this is the template file without an extension. Do not put .tpl.php on this file; that extension will be added automatically by the default rendering engine (which is PHPTemplate). If 'path', above, is specified, the template should also be in this path. - function: If specified, this will be the function name to invoke for this implementation. If neither 'template' nor 'function' is specified, a default function name will be assumed. For example, if a module registers the 'node' theme hook, 'theme_node' will be assigned to its function. If the chameleon theme registers the node hook, it will be assigned 'chameleon_node' as its function. - base hook: A string declaring the base theme hook if this theme implementation is actually implementing a suggestion for another theme hook. - pattern: A regular expression pattern to be used to allow this theme implementation to have a dynamic name. The convention is to use __ to differentiate the dynamic portion of the theme. For example, to allow forums to be themed individually, the pattern might be: 'forum__'. Then, when the forum is themed, call: @code theme(array('forum__' . $tid, 'forum'), $forum) @endcode - preprocess functions: A list of functions used to preprocess this data. Ordinarily this won't be used; it's automatically filled in. By default, for a module this will be filled in as template_preprocess_HOOK. For a theme this will be filled in as phptemplate_preprocess and phptemplate_preprocess_HOOK as well as themename_preprocess and themename_preprocess_HOOK. - override preprocess functions: Set to TRUE when a theme does NOT want the standard preprocess functions to run. This can be used to give a theme FULL control over how variables are set. For example, if a theme wants total control over how certain variables in the page.tpl.php are set, this can be set to true. Please keep in mind that when this is used by a theme, that theme becomes responsible for making sure necessary variables are set. - type: (automatically derived) Where the theme hook is defined: 'module', 'theme_engine', or 'theme'. - theme path: (automatically derived) The directory path of the theme or module, so that it doesn't need to be looked up.\n\nFile: modules/system/system.api.php", "response": "function hook_theme($existing, $type, $theme, $path) {\n return array(\n 'forum_display' => array(\n 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),\n ),\n 'forum_list' => array(\n 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),\n ),\n 'forum_topic_list' => array(\n 'variables' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),\n ),\n 'forum_icon' => array(\n 'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0),\n ),\n 'status_report' => array(\n 'render element' => 'requirements',\n 'file' => 'system.admin.inc',\n ),\n 'system_date_time_settings' => array(\n 'render element' => 'form',\n 'file' => 'system.admin.inc',\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-41dbfe76a1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/_field_invoke_multiple/7.x", "instruction": "In Drupal 7, write the function `_field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b = NULL, $options = array())` (file modules/field/field.attach.inc) so that it does the following: Invoke a field hook across fields on multiple entities.", "context": "Parameters:\n- $op: Possible operations include: - load - prepare_view For all other operations, use _field_invoke() / field_invoke_default() instead.\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entities: An array of entities, keyed by entity id.\n- $a: - The $age parameter in the 'load' operation. - Otherwise NULL.\n- $b: Currently always NULL.\n- $options: An associative array of additional options, with the following keys: - 'field_name': The name of the field whose operation should be invoked. By default, the operation is invoked on all the fields in the entity's bundle. NOTE: This option is not compatible with the 'deleted' option; the 'field_id' option should be used instead. - 'field_id': The id of the field whose operation should be invoked. By default, the operation is invoked on all the fields in the entity's' bundles. - 'default': A boolean value, specifying which implementation of the operation should be invoked. - if FALSE (default), the field types implementation of the operation will be invoked (hook_field_[op]) - If TRUE, the default field implementation of the field operation will be invoked (field_default_[op]) Internal use only. Do not explicitely set to TRUE, but use _field_invoke_multiple_default() instead. - 'deleted': If TRUE, the function will operate on deleted fields as well as non-deleted fields. If unset or FALSE, only non-deleted fields are operated on. - 'language': A language code or an array of arrays of language codes keyed by entity id and field name. It will be used to narrow down to a single value the available languages to act on.\n\nReturns: An array of returned values keyed by entity id.\n\nFile: modules/field/field.attach.inc", "response": "function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b = NULL, $options = array()) {\n // Merge default options.\n $default_options = array(\n 'default' => FALSE,\n 'deleted' => FALSE,\n 'language' => NULL,\n );\n $options += $default_options;\n\n $fields = array();\n $grouped_instances = array();\n $grouped_entities = array();\n $grouped_items = array();\n $return = array();\n\n // Go through the entities and collect the fields on which the hook should be\n // invoked.\n //\n // We group fields by id, not by name, because this function can operate on\n // deleted fields which may have non-unique names. However, entities can only\n // contain data for a single field for each name, even if that field\n // is deleted, so we reference field data via the\n // $entity->$field_name property.\n foreach ($entities as $entity) {\n // Determine the list of instances to iterate on.\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n $instances = _field_invoke_get_instances($entity_type, $bundle, $options);\n\n foreach ($instances as $instance) {\n $field_id = $instance['field_id'];\n $field_name = $instance['field_name'];\n $field = field_info_field_by_id($field_id);\n $function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op;\n if (function_exists($function)) {\n // Add the field to the list of fields to invoke the hook on.\n if (!isset($fields[$field_id])) {\n $fields[$field_id] = $field;\n }\n // Extract the field values into a separate variable, easily accessed\n // by hook implementations.\n // Unless a language suggestion is provided we iterate on all the\n // available languages.\n $available_languages = field_available_languages($entity_type, $field);\n $language = is_array($options['language']) && !empty($options['language'][$id]) ? $options['language'][$id] : $options['language'];\n $languages = _field_language_suggestion($available_languages, $language, $field_name);\n foreach ($languages as $langcode) {\n $grouped_items[$field_id][$langcode][$id] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();\n // Group the instances and entities corresponding to the current\n // field.\n $grouped_instances[$field_id][$langcode][$id] = $instance;\n $grouped_entities[$field_id][$langcode][$id] = $entities[$id];\n }\n }\n }\n // Initialize the return value for each entity.\n $return[$id] = array();\n }\n\n // For each field, invoke the field hook and collect results.\n foreach ($fields as $field_id => $field) {\n $field_name = $field['field_name'];\n $function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op;\n // Iterate over all the field translations.\n foreach ($grouped_items[$field_id] as $langcode => &$items) {\n $entities = $grouped_entities[$field_id][$langcode];\n $instances = $grouped_instances[$field_id][$langcode];\n $results = $function($entity_type, $entities, $field, $instances, $langcode, $items, $a, $b);\n if (isset($results)) {\n // Collect results by entity.\n // For hooks with array results, we merge results together.\n // For hooks with scalar results, we collect results in an array.\n foreach ($results as $id => $result) {\n if (is_array($result)) {\n $return[$id] = array_merge($return[$id], $result);\n }\n else {\n $return[$id][] = $result;\n }\n }\n }\n }\n\n // Populate field values back in the entities, but avoid replacing missing\n // fields with an empty array (those are not equivalent on update).\n foreach ($grouped_entities[$field_id] as $langcode => $entities) {\n foreach ($entities as $id => $entity) {\n if ($grouped_items[$field_id][$langcode][$id] !== array() || isset($entity->{$field_name}[$langcode])) {\n $entity->{$field_name}[$langcode] = $grouped_items[$field_id][$langcode][$id];\n }\n }\n }\n }\n\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-41e2dbb020", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_system_info_alter/7.x", "instruction": "In Drupal 7, write the function `user_system_info_alter(&$info, $file, $type)` (file modules/user/user.module) so that it does the following: Implements hook_system_info_alter().", "context": "Drupal 7 ships with two methods to add additional fields to users: Profile module, a legacy module dating back from 2002, and Field API integration with users. While Field API support for users currently provides less end user features, the inefficient data storage mechanism of Profile module, as well as its lack of consistency with the rest of the entity / field based systems in Drupal 7, make this a sub-optimal solution to those who were not using it in previous releases of Drupal.\n\nTo prevent new Drupal 7 sites from installing Profile module, and unwittingly ending up with two completely different and incompatible methods of extending users, only make the Profile module available if the profile_* tables are present.\n\nFile: modules/user/user.module", "response": "function user_system_info_alter(&$info, $file, $type) {\n if ($type == 'module' && $file->name == 'profile' && db_table_exists('profile_field')) {\n $info['hidden'] = FALSE;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-41f41e81e6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_configure_form/7.x", "instruction": "In Drupal 7, write the function `install_configure_form($form, &$form_state, &$install_state)` (file includes/install.core.inc) so that it does the following: Form constructor for a form to configure the new site.", "context": "Parameters:\n- $install_state: An array of information about the current installation state.\n\nFile: includes/install.core.inc", "response": "function install_configure_form($form, &$form_state, &$install_state) {\n drupal_set_title(st('Configure site'));\n\n // Warn about settings.php permissions risk\n $settings_dir = conf_path();\n $settings_file = $settings_dir . '/settings.php';\n // Check that $_POST is empty so we only show this message when the form is\n // first displayed, not on the next page after it is submitted. (We do not\n // want to repeat it multiple times because it is a general warning that is\n // not related to the rest of the installation process; it would also be\n // especially out of place on the last page of the installer, where it would\n // distract from the message that the Drupal installation has completed\n // successfully.)\n\n $skip_permissions_hardening = variable_get('skip_permissions_hardening', FALSE);\n // Allow system administrators to ignore permissions hardening for the site\n // directory. This allows additional files in the site directory to be\n // updated when they are managed in a version control system.\n if (!$skip_permissions_hardening) {\n if (empty($_POST) && (!drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_dir, FILE_NOT_WRITABLE, 'dir'))) {\n drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the online handbook.', array(\n '%dir' => $settings_dir,\n '%file' => $settings_file,\n '@handbook_url' => 'http://drupal.org/server-permissions'\n )), 'warning');\n }\n }\n\n drupal_add_js(drupal_get_path('module', 'system') . '/system.js');\n // Add JavaScript time zone detection.\n drupal_add_js('misc/timezone.js');\n // We add these strings as settings because JavaScript translation does not\n // work during installation.\n drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting');\n drupal_add_js('jQuery(function () { Drupal.cleanURLsInstallCheck(); });', 'inline');\n // Add JS to show / hide the 'Email administrator about site updates' elements\n drupal_add_js('jQuery(function () { Drupal.hideEmailAdministratorCheckbox() });', 'inline');\n // Build menu to allow clean URL check.\n menu_rebuild();\n\n // Cache a fully-built schema. This is necessary for any invocation of\n // index.php because: (1) setting cache table entries requires schema\n // information, (2) that occurs during bootstrap before any module are\n // loaded, so (3) if there is no cached schema, drupal_get_schema() will\n // try to generate one but with no loaded modules will return nothing.\n //\n // This logically could be done during the 'install_finished' task, but the\n // clean URL check requires it now.\n drupal_get_schema(NULL, TRUE);\n\n // Return the form.\n return _install_configure_form($form, $form_state, $install_state);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-41f91e0f70", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.pages.inc/function/book_remove_form_submit/7.x", "instruction": "Implement `book_remove_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for book_remove_form().", "context": "File: modules/book/book.pages.inc", "response": "function book_remove_form_submit($form, &$form_state) {\n $node = $form['#node'];\n if (_book_node_is_removable($node)) {\n menu_link_delete($node->book['mlid']);\n db_delete('book')\n ->condition('nid', $node->nid)\n ->execute();\n drupal_set_message(t('The post has been removed from the book.'));\n }\n $form_state['redirect'] = 'node/' . $node->nid;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-4208313a21", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_url_parse_email_links/7.x", "instruction": "In Drupal 7, write the function `_filter_url_parse_email_links($match)` (file modules/filter/filter.module) so that it does the following: Makes links out of e-mail addresses.", "context": "Callback for preg_replace_callback() within _filter_url().\n\nFile: modules/filter/filter.module", "response": "function _filter_url_parse_email_links($match) {\n // The $i:th parenthesis in the regexp contains the URL.\n $i = 0;\n\n $match[$i] = decode_entities($match[$i]);\n $caption = check_plain(_filter_url_trim($match[$i]));\n $match[$i] = check_plain($match[$i]);\n return '' . $caption . '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-421342c714", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_process_project_info/7.x", "instruction": "I need the code for `update_process_project_info(&$projects)` in Drupal 7 (modules/update/update.compare.inc). It must do this: Determines version and type information for currently installed projects.", "context": "Processes the list of projects on the system to figure out the currently installed versions, and other information that is required before we can compare against the available releases to produce the status report.\n\nParameters:\n- $projects: Array of project information from update_get_projects().\n\nFile: modules/update/update.compare.inc", "response": "function update_process_project_info(&$projects) {\n foreach ($projects as $key => $project) {\n // Assume an official release until we see otherwise.\n $install_type = 'official';\n\n $info = $project['info'];\n\n if (isset($info['version'])) {\n // Check for development snapshots\n if (preg_match('@(dev|HEAD)@', $info['version'])) {\n $install_type = 'dev';\n }\n\n // Figure out what the currently installed major version is. We need\n // to handle both contribution (e.g. \"5.x-1.3\", major = 1) and core\n // (e.g. \"5.1\", major = 5) version strings.\n $matches = array();\n if (preg_match('/^(\\d+\\.x-)?(\\d+)\\..*$/', $info['version'], $matches)) {\n $info['major'] = $matches[2];\n }\n elseif (!isset($info['major'])) {\n // This would only happen for version strings that don't follow the\n // drupal.org convention. We let contribs define \"major\" in their\n // .info in this case, and only if that's missing would we hit this.\n $info['major'] = -1;\n }\n }\n else {\n // No version info available at all.\n $install_type = 'unknown';\n $info['version'] = t('Unknown');\n $info['major'] = -1;\n }\n\n // Finally, save the results we care about into the $projects array.\n $projects[$key]['existing_version'] = $info['version'];\n $projects[$key]['existing_major'] = $info['major'];\n $projects[$key]['install_type'] = $install_type;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-422d4554b5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7005/7.x", "instruction": "In Drupal 7, write the function `system_update_7005()` (file modules/system/system.install) so that it does the following: Remove throttle columns and variables.", "context": "File: modules/system/system.install", "response": "function system_update_7005() {\n db_drop_field('blocks', 'throttle');\n db_drop_field('system', 'throttle');\n variable_del('throttle_user');\n variable_del('throttle_anonymous');\n variable_del('throttle_level');\n variable_del('throttle_probability_limiter');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-42362897c3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_request_refresh/7.x", "instruction": "I need the code for `overlay_request_refresh($region)` in Drupal 7 (modules/overlay/overlay.module). It must do this: Requests that the parent window refreshes a particular page region.", "context": "Parameters:\n- $region: The name of the page region to refresh. The parent window will trigger a refresh of this region on the next page load.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_request_refresh($region) {\n $class = drupal_region_class($region);\n $_SESSION['overlay_regions_to_refresh'][] = array($class => $region);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-4243783207", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate_image_resolution/7.x", "instruction": "In Drupal 7, write the function `file_validate_image_resolution(stdClass $file, $maximum_dimensions = 0, $minimum_dimensions = 0)` (file includes/file.inc) so that it does the following: Verifies that image dimensions are within the specified maximum and minimum.", "context": "Non-image files will be ignored. If an image toolkit is available the image will be scaled to fit within the desired maximum dimensions.\n\nParameters:\n- $file: A Drupal file object. This function may resize the file affecting its size.\n- $maximum_dimensions: An optional string in the form WIDTHxHEIGHT e.g. '640x480' or '85x85'. If an image toolkit is installed the image will be resized down to these dimensions. A value of 0 indicates no restriction on size, so resizing will be attempted.\n- $minimum_dimensions: An optional string in the form WIDTHxHEIGHT. This will check that the image meets a minimum size. A value of 0 indicates no restriction.\n\nReturns: An array. If the file is an image and did not meet the requirements, it will contain an error message.\n\nFile: includes/file.inc", "response": "function file_validate_image_resolution(stdClass $file, $maximum_dimensions = 0, $minimum_dimensions = 0) {\n $errors = array();\n\n // Check first that the file is an image.\n if ($info = image_get_info($file->uri)) {\n if ($maximum_dimensions) {\n // Check that it is smaller than the given dimensions.\n list($width, $height) = explode('x', $maximum_dimensions);\n if ($info['width'] > $width || $info['height'] > $height) {\n // Try to resize the image to fit the dimensions.\n if ($image = image_load($file->uri)) {\n image_scale($image, $width, $height);\n image_save($image);\n // Update the image info since we have resized it.\n $info = $image->info;\n $file->filesize = $image->info['file_size'];\n drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions)));\n }\n else {\n $errors[] = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $maximum_dimensions));\n }\n }\n }\n\n if ($minimum_dimensions) {\n // Check that it is larger than the given dimensions.\n list($width, $height) = explode('x', $minimum_dimensions);\n if ($info['width'] < $width || $info['height'] < $height) {\n $errors[] = t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => $minimum_dimensions));\n }\n }\n }\n\n return $errors;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-424fd58694", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_set_active_item/7.x", "instruction": "In Drupal 7, write the function `menu_set_active_item($path)` (file includes/menu.inc) so that it does the following: Sets the active path, which determines which page is loaded.", "context": "Note that this may not have the desired effect unless invoked very early in the page load, such as during hook_boot(), or unless you call menu_execute_active_handler() to generate your page output.\n\nParameters:\n- $path: A Drupal path - not a path alias.\n\nFile: includes/menu.inc", "response": "function menu_set_active_item($path) {\n $_GET['q'] = $path;\n // Since the active item has changed, the active menu trail may also be out\n // of date.\n drupal_static_reset('menu_set_active_trail');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-4287840d7c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/_locale_languages_common_controls/7.x", "instruction": "In Drupal 7, write the function `_locale_languages_common_controls(&$form, $language = NULL)` (file modules/locale/locale.admin.inc) so that it does the following: Common elements of the language addition and editing form.", "context": "Parameters:\n- $form: A parent form item (or empty array) to add items below.\n- $language: Language object to edit.\n\nFile: modules/locale/locale.admin.inc", "response": "function _locale_languages_common_controls(&$form, $language = NULL) {\n if (!is_object($language)) {\n $language = new stdClass();\n }\n if (isset($language->language)) {\n $form['langcode_view'] = array(\n '#type' => 'item',\n '#title' => t('Language code'),\n '#markup' => $language->language\n );\n $form['langcode'] = array(\n '#type' => 'value',\n '#value' => $language->language\n );\n }\n else {\n $form['langcode'] = array('#type' => 'textfield',\n '#title' => t('Language code'),\n '#maxlength' => 12,\n '#required' => TRUE,\n '#default_value' => @$language->language,\n '#disabled' => (isset($language->language)),\n '#description' => t('Use language codes as defined by the W3C for interoperability. Examples: \"en\", \"en-gb\" and \"zh-hant\".', array('@w3ctags' => 'http://www.w3.org/International/articles/language-tags/')),\n );\n }\n $form['name'] = array('#type' => 'textfield',\n '#title' => t('Language name in English'),\n '#maxlength' => 64,\n '#default_value' => @$language->name,\n '#required' => TRUE,\n '#description' => t('Name of the language in English. Will be available for translation in all languages.'),\n );\n $form['native'] = array('#type' => 'textfield',\n '#title' => t('Native language name'),\n '#maxlength' => 64,\n '#default_value' => @$language->native,\n '#required' => TRUE,\n '#description' => t('Name of the language in the language being added.'),\n );\n $form['prefix'] = array('#type' => 'textfield',\n '#title' => t('Path prefix language code'),\n '#maxlength' => 64,\n '#default_value' => @$language->prefix,\n '#description' => t('Language code or other custom text to use as a path prefix for URL language detection, if your Detection and selection settings use URL path prefixes. For the default language, this value may be left blank. Modifying this value may break existing URLs. Use with caution in a production environment. Example: Specifying \"deutsch\" as the path prefix code for German results in URLs like \"example.com/deutsch/contact\".')\n );\n $form['domain'] = array('#type' => 'textfield',\n '#title' => t('Language domain'),\n '#maxlength' => 128,\n '#default_value' => @$language->domain,\n '#description' => t('The domain name to use for this language if URL domains are used for Detection and selection. Leave blank for the default language. Changing this value may break existing URLs. Example: Specifying \"de.example.com\" as language domain for German will result in an URL like \"http://de.example.com/contact\".'),\n );\n $form['direction'] = array('#type' => 'radios',\n '#title' => t('Direction'),\n '#required' => TRUE,\n '#description' => t('Direction that text in this language is presented.'),\n '#default_value' => @$language->direction,\n '#options' => array(LANGUAGE_LTR => t('Left to right'), LANGUAGE_RTL => t('Right to left'))\n );\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-429bfe102a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21bartik%21template.php/function/bartik_field__taxonomy_term_reference/7.x", "instruction": "In Drupal 7, write the function `bartik_field__taxonomy_term_reference($variables)` (file themes/bartik/template.php) so that it does the following: Implements theme_field__field_type().", "context": "File: themes/bartik/template.php", "response": "function bartik_field__taxonomy_term_reference($variables) {\n $output = '';\n\n // Render the label, if it's not hidden.\n if (!$variables['label_hidden']) {\n $output .= '

            ' . $variables['label'] . ':

            ';\n }\n\n // Render the items.\n $output .= ($variables['element']['#label_display'] == 'inline') ? '
            ';\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-90497a7571", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_flush_caches/7.x", "instruction": "I need the code for `field_flush_caches()` in Drupal 7 (modules/field/field.module). It must do this: Implements hook_flush_caches().", "context": "File: modules/field/field.module", "response": "function field_flush_caches() {\n // Refresh the 'active' status of fields.\n field_sync_field_status();\n\n // Request a flush of our cache table.\n return array('cache_field');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-9058bf62fb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_next_destination/7.x", "instruction": "In Drupal 7, write the function `field_ui_next_destination($entity_type, $bundle)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Returns the next redirect path in a multipage sequence.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_next_destination($entity_type, $bundle) {\n $destinations = !empty($_REQUEST['destinations']) ? $_REQUEST['destinations'] : array();\n if (!empty($destinations)) {\n unset($_REQUEST['destinations']);\n }\n // Remove any external URLs.\n $destinations = array_diff($destinations, array_filter($destinations, 'url_is_external'));\n if ($destinations) {\n return field_ui_get_destinations($destinations);\n }\n $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);\n return $admin_path . '/fields';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-906f857d71", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_block_view/7.x", "instruction": "I need the code for `poll_block_view($delta = '')` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_block_view().", "context": "Generates a block containing the latest poll.\n\nFile: modules/poll/poll.module", "response": "function poll_block_view($delta = '') {\n if (user_access('access content')) {\n // Retrieve the latest poll.\n $select = db_select('node', 'n');\n $select->join('poll', 'p', 'p.nid = n.nid');\n $select->fields('n', array('nid'))\n ->condition('n.status', 1)\n ->condition('p.active', 1)\n ->orderBy('n.created', 'DESC')\n ->range(0, 1)\n ->addTag('node_access');\n\n $record = $select->execute()->fetchObject();\n if ($record) {\n $poll = node_load($record->nid);\n if ($poll->nid) {\n $poll = poll_block_latest_poll_view($poll);\n $block['subject'] = t('Poll');\n $block['content'] = $poll->content;\n return $block;\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-90711200e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render_cache_by_query/7.x", "instruction": "Implement `drupal_render_cache_by_query($query, $function, $expire = CACHE_TEMPORARY, $granularity = NULL)` in PHP for Drupal 7. Required behavior: Prepares an element for caching based on a query.", "context": "This smart caching strategy saves Drupal from querying and rendering to HTML when the underlying query is unchanged.\n\nExpensive queries should use the query builder to create the query and then call this function. Executing the query and formatting results should happen in a #pre_render callback.\n\nParameters:\n- $query: A select query object as returned by db_select().\n- $function: The name of the function doing this caching. A _pre_render suffix will be added to this string and is also part of the cache key in drupal_render_cache_set() and drupal_render_cache_get().\n- $expire: The cache expire time, passed eventually to cache_set().\n- $granularity: One or more granularity constants passed to drupal_render_cid_parts().\n\nReturns: A renderable array with the following keys and values: - #query: The passed-in $query. - #pre_render: $function with a _pre_render suffix. - #cache: An associative array prepared for drupal_render_cache_set().\n\nFile: includes/common.inc", "response": "function drupal_render_cache_by_query($query, $function, $expire = CACHE_TEMPORARY, $granularity = NULL) {\n $cache_keys = array_merge(array($function), drupal_render_cid_parts($granularity));\n $query->preExecute();\n $cache_keys[] = hash('sha256', serialize(array((string) $query, $query->getArguments())));\n return array(\n '#query' => $query,\n '#pre_render' => array($function . '_pre_render'),\n '#cache' => array(\n 'keys' => $cache_keys,\n 'expire' => $expire,\n ),\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9085f8b88e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/_drupal_theme_initialize/7.x", "instruction": "In Drupal 7, write the function `_drupal_theme_initialize($theme, $base_theme = array(), $registry_callback = '_theme_load_registry')` (file includes/theme.inc) so that it does the following: Initializes the theme system given already loaded information.", "context": "This function is useful to initialize a theme when no database is present.\n\nParameters:\n- $theme: An object with the following information: filename The .info file for this theme. The 'path' to the theme will be in this file's directory. (Required) owner The path to the .theme file or the .engine file to load for the theme. (Required) stylesheet The primary stylesheet for the theme. (Optional) engine The name of theme engine to use. (Optional)\n- $base_theme: An optional array of objects that represent the 'base theme' if the theme is meant to be derivative of another theme. It requires the same information as the $theme object. It should be in 'oldest first' order, meaning the top level of the chain will be first.\n- $registry_callback: The callback to invoke to set the theme registry.\n\nFile: includes/theme.inc", "response": "function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callback = '_theme_load_registry') {\n global $theme_info, $base_theme_info, $theme_engine, $theme_path;\n $theme_info = $theme;\n $base_theme_info = $base_theme;\n\n $theme_path = dirname($theme->filename);\n\n // Prepare stylesheets from this theme as well as all ancestor themes.\n // We work it this way so that we can have child themes override parent\n // theme stylesheets easily.\n $final_stylesheets = array();\n\n // Grab stylesheets from base theme\n foreach ($base_theme as $base) {\n if (!empty($base->stylesheets)) {\n foreach ($base->stylesheets as $media => $stylesheets) {\n foreach ($stylesheets as $name => $stylesheet) {\n $final_stylesheets[$media][$name] = $stylesheet;\n }\n }\n }\n }\n\n // Add stylesheets used by this theme.\n if (!empty($theme->stylesheets)) {\n foreach ($theme->stylesheets as $media => $stylesheets) {\n foreach ($stylesheets as $name => $stylesheet) {\n $final_stylesheets[$media][$name] = $stylesheet;\n }\n }\n }\n\n // And now add the stylesheets properly\n foreach ($final_stylesheets as $media => $stylesheets) {\n foreach ($stylesheets as $stylesheet) {\n drupal_add_css($stylesheet, array('group' => CSS_THEME, 'every_page' => TRUE, 'media' => $media));\n }\n }\n\n // Do basically the same as the above for scripts\n $final_scripts = array();\n\n // Grab scripts from base theme\n foreach ($base_theme as $base) {\n if (!empty($base->scripts)) {\n foreach ($base->scripts as $name => $script) {\n $final_scripts[$name] = $script;\n }\n }\n }\n\n // Add scripts used by this theme.\n if (!empty($theme->scripts)) {\n foreach ($theme->scripts as $name => $script) {\n $final_scripts[$name] = $script;\n }\n }\n\n // Add scripts used by this theme.\n foreach ($final_scripts as $script) {\n drupal_add_js($script, array('group' => JS_THEME, 'every_page' => TRUE));\n }\n\n $theme_engine = NULL;\n\n // Initialize the theme.\n if (isset($theme->engine)) {\n // Include the engine.\n include_once DRUPAL_ROOT . '/' . $theme->owner;\n\n $theme_engine = $theme->engine;\n if (function_exists($theme_engine . '_init')) {\n foreach ($base_theme as $base) {\n call_user_func($theme_engine . '_init', $base);\n }\n call_user_func($theme_engine . '_init', $theme);\n }\n }\n else {\n // include non-engine theme files\n foreach ($base_theme as $base) {\n // Include the theme file or the engine.\n if (!empty($base->owner)) {\n include_once DRUPAL_ROOT . '/' . $base->owner;\n }\n }\n // and our theme gets one too.\n if (!empty($theme->owner)) {\n include_once DRUPAL_ROOT . '/' . $theme->owner;\n }\n }\n\n if (isset($registry_callback)) {\n _theme_registry_callback($registry_callback, array($theme, $base_theme, $theme_engine));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-90c6e97d49", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_from_interface/7.x", "instruction": "Implement `locale_language_from_interface()` in PHP for Drupal 7. Required behavior: Identifies the language from the current interface language.", "context": "Returns: The current interface language code.\n\nFile: includes/locale.inc", "response": "function locale_language_from_interface() {\n global $language;\n return isset($language->language) ? $language->language : FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-90cf238c81", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_css/7.x", "instruction": "In Drupal 7, write the function `drupal_get_css($css = NULL, $skip_alter = FALSE)` (file includes/common.inc) so that it does the following: Returns a themed representation of all stylesheets to attach to the page.", "context": "It loads the CSS in order, with 'module' first, then 'theme' afterwards. This ensures proper cascading of styles so themes can easily override module styles through CSS selectors.\n\nThemes may replace module-defined CSS files by adding a stylesheet with the same filename. For example, themes/bartik/system-menus.css would replace modules/system/system-menus.css. This allows themes to override complete CSS files, rather than specific selectors, when necessary.\n\nIf the original CSS file is being overridden by a theme, the theme is responsible for supplying an accompanying RTL CSS file to replace the module's.\n\nParameters:\n- $css: (optional) An array of CSS files. If no array is provided, the default stylesheets array is used instead.\n- $skip_alter: (optional) If set to TRUE, this function skips calling drupal_alter() on $css, useful when the calling function passes a $css array that has already been altered.\n\nReturns: A string of XHTML CSS tags.\n\nFile: includes/common.inc", "response": "function drupal_get_css($css = NULL, $skip_alter = FALSE) {\n if (!isset($css)) {\n $css = drupal_add_css();\n }\n\n // Allow modules and themes to alter the CSS items.\n if (!$skip_alter) {\n drupal_alter('css', $css);\n }\n\n // Sort CSS items, so that they appear in the correct order.\n uasort($css, 'drupal_sort_css_js');\n\n // Provide the page with information about the individual CSS files used,\n // information not otherwise available when CSS aggregation is enabled. The\n // setting is attached later in this function, but is set here, so that CSS\n // files removed below are still considered \"used\" and prevented from being\n // added in a later AJAX request.\n // Skip if no files were added to the page or jQuery.extend() will overwrite\n // the Drupal.settings.ajaxPageState.css object with an empty array.\n if (!empty($css)) {\n // Cast the array to an object to be on the safe side even if not empty.\n $setting['ajaxPageState']['css'] = (object) array_fill_keys(array_keys($css), 1);\n }\n\n // Remove the overridden CSS files. Later CSS files override former ones.\n $previous_item = array();\n foreach ($css as $key => $item) {\n if ($item['type'] == 'file') {\n // If defined, force a unique basename for this file.\n $basename = isset($item['basename']) ? $item['basename'] : drupal_basename($item['data']);\n if (isset($previous_item[$basename])) {\n // Remove the previous item that shared the same base name.\n unset($css[$previous_item[$basename]]);\n }\n $previous_item[$basename] = $key;\n }\n }\n\n // Render the HTML needed to load the CSS.\n $styles = array(\n '#type' => 'styles',\n '#items' => $css,\n );\n\n if (!empty($setting)) {\n $styles['#attached']['js'][] = array('type' => 'setting', 'data' => $setting);\n }\n\n return drupal_render($styles);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-90d48f285e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_load/7.x", "instruction": "Give me the example code for `hook_node_load($nodes, $types)` in Drupal 7. Hook description: Act on arbitrary nodes being loaded from the database.", "context": "This hook should be used to add information that is not in the node or node revisions table, not to replace information that is in these tables (which could interfere with the entity cache). For performance reasons, information for all available nodes should be loaded in a single query where possible.\n\nThis hook is invoked during node loading, which is handled by entity_load(), via classes NodeController and DrupalDefaultEntityController. After the node information is read from the database or the entity cache, hook_load() is invoked on the node's content type module, then field_attach_load_revision() or field_attach_load() is called, then hook_entity_load() is invoked on all implementing modules, and finally hook_node_load() is invoked on all implementing modules.\n\nParameters:\n- $nodes: An array of the nodes being loaded, keyed by nid.\n- $types: An array containing the node types present in $nodes. Allows for an early return for modules that only support certain node types. However, if your module defines a content type, you can use hook_load() to respond to loading of just that content type. For a detailed usage example, see nodeapi_example.module.\n\nFile: modules/node/node.api.php", "response": "function hook_node_load($nodes, $types) {\n // Decide whether any of $types are relevant to our purposes.\n if (count(array_intersect($types_we_want_to_process, $types))) {\n // Gather our extra data for each of these nodes.\n $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));\n // Add our extra data to the node objects.\n foreach ($result as $record) {\n $nodes[$record->nid]->foo = $record->foo;\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-90e6d720d7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_get_form/7.x", "instruction": "Implement `ajax_get_form()` in PHP for Drupal 7. Required behavior: Gets a form submitted via #ajax during an Ajax callback.", "context": "This will load a form from the form cache used during Ajax operations. It pulls the form info from $_POST.\n\nReturns: An array containing the $form, $form_state, $form_id, $form_build_id and an initial list of Ajax $commands. Use the list() function to break these apart: @code list($form, $form_state, $form_id, $form_build_id, $commands) = ajax_get_form(); @endcode\n\nFile: includes/ajax.inc", "response": "function ajax_get_form() {\n $form_state = form_state_defaults();\n\n $form_build_id = (isset($_POST['form_build_id']) ? $_POST['form_build_id'] : '');\n\n // Get the form from the cache.\n $form = form_get_cache($form_build_id, $form_state);\n if (!$form) {\n // If $form cannot be loaded from the cache, the form_build_id in $_POST\n // must be invalid, which means that someone performed a POST request onto\n // system/ajax without actually viewing the concerned form in the browser.\n // This is likely a hacking attempt as it never happens under normal\n // circumstances, so we just do nothing.\n watchdog('ajax', 'Invalid form POST data.', array(), WATCHDOG_WARNING);\n drupal_exit();\n }\n\n // When a page level cache is enabled, the form-build id might have been\n // replaced from within form_get_cache. If this is the case, it is also\n // necessary to update it in the browser by issuing an appropriate Ajax\n // command.\n $commands = array();\n if (isset($form['#build_id_old']) && $form['#build_id_old'] != $form['#build_id']) {\n // If the form build ID has changed, issue an Ajax command to update it.\n $commands[] = ajax_command_update_build_id($form);\n $form_build_id = $form['#build_id'];\n }\n\n // Since some of the submit handlers are run, redirects need to be disabled.\n $form_state['no_redirect'] = TRUE;\n\n // When a form is rebuilt after Ajax processing, its #build_id and #action\n // should not change.\n // @see drupal_rebuild_form()\n $form_state['rebuild_info']['copy']['#build_id'] = TRUE;\n $form_state['rebuild_info']['copy']['#action'] = TRUE;\n\n // The form needs to be processed; prepare for that by setting a few internal\n // variables.\n $form_state['input'] = $_POST;\n $form_id = $form['#form_id'];\n\n return array($form, $form_state, $form_id, $form_build_id, $commands);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-90f255e83b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_indentation/7.x", "instruction": "Implement `theme_indentation($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for an indentation div; used for drag and drop tables.", "context": "Parameters:\n- $variables: An associative array containing: - size: Optional. The number of indentations to create.\n\nFile: includes/theme.inc", "response": "function theme_indentation($variables) {\n $output = '';\n for ($n = 0; $n < $variables['size']; $n++) {\n $output .= '
             
            ';\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-90f92325dc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_help/7.x", "instruction": "Implement `node_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/node/node.module", "response": "function node_help($path, $arg) {\n // Remind site administrators about the {node_access} table being flagged\n // for rebuild. We don't need to issue the message on the confirm form, or\n // while the rebuild is being processed.\n if ($path != 'admin/reports/status/rebuild' && $path != 'batch' && strpos($path, '#') === FALSE\n && user_access('access administration pages') && node_access_needs_rebuild()) {\n if ($path == 'admin/reports/status') {\n $message = t('The content access permissions need to be rebuilt.');\n }\n else {\n $message = t('The content access permissions need to be rebuilt. Rebuild permissions.', array('@node_access_rebuild' => url('admin/reports/status/rebuild')));\n }\n drupal_set_message($message, 'error');\n }\n\n switch ($path) {\n case 'admin/help#node':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the Field module). For more information, see the online handbook entry for Node module.', array('@node' => 'http://drupal.org/documentation/modules/node', '@field' => url('admin/help/field'))) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Creating content') . '
            ';\n $output .= '
            ' . t('When new content is created, the Node module records basic information about the content, including the author, date of creation, and the Content type. It also manages the publishing options, which define whether or not the content is published, promoted to the front page of the site, and/or sticky at the top of content lists. Default settings can be configured for each type of content on your site.', array('@content-type' => url('admin/structure/types'))) . '
            ';\n $output .= '
            ' . t('Creating custom content types') . '
            ';\n $output .= '
            ' . t('The Node module gives users with the Administer content types permission the ability to create new content types in addition to the default ones already configured. Creating custom content types allows you the flexibility to add fields and configure default settings that suit the differing needs of various site content.', array('@content-new' => url('admin/structure/types/add'), '@field' => url('admin/help/field'))) . '
            ';\n $output .= '
            ' . t('Administering content') . '
            ';\n $output .= '
            ' . t('The Content administration page allows you to review and bulk manage your site content.', array('@content' => url('admin/content'))) . '
            ';\n $output .= '
            ' . t('Creating revisions') . '
            ';\n $output .= '
            ' . t('The Node module also enables you to create multiple versions of any content, and revert to older versions using the Revision information settings.') . '
            ';\n $output .= '
            ' . t('User permissions') . '
            ';\n $output .= '
            ' . t('The Node module makes a number of permissions available for each content type, which can be set by role on the permissions page.', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-node')))) . '
            ';\n $output .= '
            ';\n return $output;\n\n case 'admin/structure/types/add':\n return '

            ' . t('Individual content types can have different fields, behaviors, and permissions assigned to them.') . '

            ';\n\n case 'admin/structure/types/manage/%/display':\n return '

            ' . t('Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. Teaser is a short format that is typically used in lists of multiple content items. Full content is typically used when the content is displayed on its own page.') . '

            ' .\n '

            ' . t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', array('%type' => node_type_get_name($arg[4]))) . '

            ';\n\n case 'node/%/revisions':\n return '

            ' . t('Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.') . '

            ';\n\n case 'node/%/edit':\n $node = node_load($arg[1]);\n $type = node_type_get_type($node);\n return (!empty($type->help) ? '

            ' . filter_xss_admin($type->help) . '

            ' : '');\n }\n\n if ($arg[0] == 'node' && $arg[1] == 'add' && $arg[2]) {\n $type = node_type_get_type(str_replace('-', '_', $arg[2]));\n return (!empty($type->help) ? '

            ' . filter_xss_admin($type->help) . '

            ' : '');\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-9111c900c8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.api.php/function/callback_filter_process/7.x", "instruction": "Give me the example code for `callback_filter_process($text, $filter, $format, $langcode, $cache, $cache_id)` in Drupal 7. Hook description: Provide text filtered to conform to the supplied format.", "context": "Callback for hook_filter_info().\n\nSee hook_filter_info() for a description of the filtering process. This step is where the filter actually transforms the text.\n\nParameters:\n- $text: The text string to be filtered.\n- $filter: The filter object containing settings for the given format.\n- $format: The text format object assigned to the text to be filtered.\n- $langcode: The language code of the text to be filtered.\n- $cache: A Boolean indicating whether the filtered text is going to be cached in {cache_filter}.\n- $cache_id: The ID of the filtered text in {cache_filter}, if $cache is TRUE.\n\nReturns: The filtered text.\n\nFile: modules/filter/filter.api.php", "response": "function callback_filter_process($text, $filter, $format, $langcode, $cache, $cache_id) {\n $text = preg_replace('|\\[codefilter_code\\](.+?)\\[/codefilter_code\\]|s', \"
            $1
            \", $text);\n\n return $text;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-911943e7e6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_collate_fields/7.x", "instruction": "Implement `_field_info_collate_fields($reset = FALSE)` in PHP for Drupal 7. Required behavior: Collates all information on existing fields and instances.", "context": "Deprecated. This function is kept to ensure backwards compatibility, but has a serious performance impact, and should be absolutely avoided. See http://drupal.org/node/1915646.\n\nUse the regular field_info_*() API functions to access the information, or field_info_cache_clear() to clear the cached data.\n\nFile: modules/field/field.info.inc", "response": "function _field_info_collate_fields($reset = FALSE) {\n if ($reset) {\n _field_info_field_cache()->flush();\n return;\n }\n\n $cache = _field_info_field_cache();\n\n // Collect fields, and build the array of IDs keyed by field_name.\n $fields = $cache->getFields();\n $field_ids = array();\n foreach ($fields as $id => $field) {\n if (!$field['deleted']) {\n $field_ids[$field['field_name']] = $id;\n }\n }\n\n // Collect extra fields for all entity types.\n $extra_fields = array();\n foreach (field_info_bundles() as $entity_type => $bundles) {\n foreach ($bundles as $bundle => $info) {\n $extra_fields[$entity_type][$bundle] = $cache->getBundleExtraFields($entity_type, $bundle);\n }\n }\n\n return array(\n 'fields' => $fields,\n 'field_ids' => $field_ids,\n 'instances' => $cache->getInstances(),\n 'extra_fields' => $extra_fields,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-912de4fa93", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7010/7.x", "instruction": "Implement `user_update_7010()` in PHP for Drupal 7. Required behavior: Update the {user}.signature_format column.", "context": "File: modules/user/user.install", "response": "function user_update_7010() {\n // Update the database column to allow NULL values.\n db_change_field('users', 'signature_format', 'signature_format', array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => FALSE,\n 'description' => 'The {filter_format}.format of the signature.',\n ));\n\n // Replace the signature format with NULL if the signature is empty and does\n // not already have a stored text format.\n //\n // In Drupal 6, \"0\" (the former FILTER_FORMAT_DEFAULT constant) could be used\n // to indicate this situation, but in Drupal 7, only NULL is supported. This\n // update therefore preserves the ability of user accounts which were never\n // given a signature (for example, if the site did not have user signatures\n // enabled, or if the user never edited their account information) to not\n // have a particular text format assumed for them the first time the\n // signature is edited.\n db_update('users')\n ->fields(array('signature_format' => NULL))\n ->condition('signature', '')\n ->condition('signature_format', 0)\n ->execute();\n\n // There are a number of situations in which a Drupal 6 site could store\n // content with a nonexistent text format. This includes text formats that\n // had later been deleted, or non-empty content stored with a value of \"0\"\n // (the former FILTER_FORMAT_DEFAULT constant). Drupal 6 would filter this\n // content using whatever the site-wide default text format was at the moment\n // the text was being displayed.\n //\n // In Drupal 7, this behavior is no longer supported, and all content must be\n // stored with an explicit text format (or it will not be displayed when it\n // is filtered). Therefore, to preserve the behavior of the site after the\n // upgrade, we must replace all instances described above with the current\n // value of the (old) site-wide default format at the moment of the upgrade.\n $existing_formats = db_query(\"SELECT format FROM {filter_format}\")->fetchCol();\n $default_format = variable_get('filter_default_format', 1);\n db_update('users')\n ->fields(array('signature_format' => $default_format))\n ->isNotNull('signature_format')\n ->condition('signature_format', $existing_formats, 'NOT IN')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9145669e3e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_instance_settings_form/7.x", "instruction": "Implement `number_field_instance_settings_form($field, $instance)` in PHP for Drupal 7. Required behavior: Implements hook_field_instance_settings_form().", "context": "File: modules/field/modules/number/number.module", "response": "function number_field_instance_settings_form($field, $instance) {\n $settings = $instance['settings'];\n\n $form['min'] = array(\n '#type' => 'textfield',\n '#title' => t('Minimum'),\n '#default_value' => $settings['min'],\n '#description' => t('The minimum value that should be allowed in this field. Leave blank for no minimum.'),\n '#element_validate' => array('element_validate_number'),\n );\n $form['max'] = array(\n '#type' => 'textfield',\n '#title' => t('Maximum'),\n '#default_value' => $settings['max'],\n '#description' => t('The maximum value that should be allowed in this field. Leave blank for no maximum.'),\n '#element_validate' => array('element_validate_number'),\n );\n $form['prefix'] = array(\n '#type' => 'textfield',\n '#title' => t('Prefix'),\n '#default_value' => $settings['prefix'],\n '#size' => 60,\n '#description' => t(\"Define a string that should be prefixed to the value, like '$ ' or '€ '. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds').\"),\n );\n $form['suffix'] = array(\n '#type' => 'textfield',\n '#title' => t('Suffix'),\n '#default_value' => $settings['suffix'],\n '#size' => 60,\n '#description' => t(\"Define a string that should be suffixed to the value, like ' m', ' kb/s'. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds').\"),\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-9150bb25d9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.api.php/function/hook_comment_insert/7.x", "instruction": "Give me the example code for `hook_comment_insert($comment)` in Drupal 7. Hook description: The comment is being inserted.", "context": "Parameters:\n- $comment: The comment object.\n\nFile: modules/comment/comment.api.php", "response": "function hook_comment_insert($comment) {\n // Reindex the node when comments are added.\n search_touch_node($comment->nid);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-9158308c8f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_stream_wrapper_get_instance_by_scheme/7.x", "instruction": "I need the code for `file_stream_wrapper_get_instance_by_scheme($scheme)` in Drupal 7 (includes/file.inc). It must do this: Returns a reference to the stream wrapper class responsible for a scheme.", "context": "This helper method returns a stream instance using a scheme. That is, the passed string does not contain a \"://\". For example, \"public\" is a scheme but \"public://\" is a URI (stream). This is because the later contains both a scheme and target despite target being empty.\n\nNote: the instance URI will be initialized to \"scheme://\" so that you can make the customary method calls as if you had retrieved an instance by URI.\n\nParameters:\n- $scheme: If the stream was \"public://target\", \"public\" would be the scheme.\n\nReturns: Returns a new stream wrapper object appropriate for the given $scheme. For example, for the public scheme a stream wrapper object (DrupalPublicStreamWrapper). FALSE is returned if no registered handler could be found.\n\nFile: includes/file.inc", "response": "function file_stream_wrapper_get_instance_by_scheme($scheme) {\n $class = file_stream_wrapper_get_class($scheme);\n if (class_exists($class)) {\n $instance = new $class();\n $instance->setUri($scheme . '://');\n return $instance;\n }\n else {\n return FALSE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-915a41b0a2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_menu_local_tasks_alter/7.x", "instruction": "Implement `forum_menu_local_tasks_alter(&$data, $router_item, $root_path)` in PHP for Drupal 7. Required behavior: Implements hook_menu_local_tasks_alter().", "context": "File: modules/forum/forum.module", "response": "function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {\n global $user;\n\n // Add action link to 'node/add/forum' on 'forum' sub-pages.\n if ($root_path == 'forum' || $root_path == 'forum/%') {\n $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);\n $forum_term = forum_forum_load($tid);\n if ($forum_term) {\n $links = array();\n // Loop through all bundles for forum taxonomy vocabulary field.\n $field = field_info_field('taxonomy_forums');\n foreach ($field['bundles']['node'] as $type) {\n if (node_access('create', $type)) {\n $links[$type] = array(\n '#theme' => 'menu_local_action',\n '#link' => array(\n 'title' => t('Add new @node_type', array('@node_type' => node_type_get_name($type))),\n 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $forum_term->tid,\n ),\n );\n }\n }\n if (empty($links)) {\n // Authenticated user does not have access to create new topics.\n if ($user->uid) {\n $links['disallowed'] = array(\n '#theme' => 'menu_local_action',\n '#link' => array(\n 'title' => t('You are not allowed to post new content in the forum.'),\n ),\n );\n }\n // Anonymous user does not have access to create new topics.\n else {\n $links['login'] = array(\n '#theme' => 'menu_local_action',\n '#link' => array(\n 'title' => t('Log in to post new content in the forum.', array(\n '@login' => url('user/login', array('query' => drupal_get_destination())),\n )),\n 'localized_options' => array('html' => TRUE),\n ),\n );\n }\n }\n $data['actions']['output'] = array_merge($data['actions']['output'], $links);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-91655579f3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_edit_menu_name_exists/7.x", "instruction": "Implement `menu_edit_menu_name_exists($value)` in PHP for Drupal 7. Required behavior: Returns whether a menu name already exists.", "context": "File: modules/menu/menu.admin.inc", "response": "function menu_edit_menu_name_exists($value) {\n // 'menu-' is added to the menu name to avoid name-space conflicts.\n $value = 'menu-' . $value;\n $custom_exists = db_query_range('SELECT 1 FROM {menu_custom} WHERE menu_name = :menu', 0, 1, array(':menu' => $value))->fetchField();\n $link_exists = db_query_range(\"SELECT 1 FROM {menu_links} WHERE menu_name = :menu\", 0, 1, array(':menu' => $value))->fetchField();\n\n return $custom_exists || $link_exists;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9178541172", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7016/7.x", "instruction": "Implement `user_update_7016()` in PHP for Drupal 7. Required behavior: Update the database to match the schema.", "context": "File: modules/user/user.install", "response": "function user_update_7016() {\n // Add field default.\n db_change_field('users', 'uid', 'uid', array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-91886502a0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_authorized_run/7.x", "instruction": "Implement `system_authorized_run($callback, $file, $arguments = array(), $page_title = NULL)` in PHP for Drupal 7. Required behavior: Setup and invoke an operation using authorize.php.", "context": "File: modules/system/system.module", "response": "function system_authorized_run($callback, $file, $arguments = array(), $page_title = NULL) {\n system_authorized_init($callback, $file, $arguments, $page_title);\n drupal_goto(system_authorized_get_url());\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-91ca15af4c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_validate/7.x", "instruction": "Give me the example code for `hook_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors)` in Drupal 7. Hook description: Validate this module's field data.", "context": "If there are validation problems, add to the $errors array (passed by reference). There is no return value.\n\nParameters:\n- $entity_type: The type of $entity.\n- $entity: The entity for the operation.\n- $field: The field structure for the operation.\n- $instance: The instance structure for $field on $entity's bundle.\n- $langcode: The language associated with $items.\n- $entity ($items): ->{$field['field_name']}[$langcode], or an empty array if unset.\n- $errors: The array of errors (keyed by field name, language code, and delta) that have already been reported for the entity. The function should add its errors to this array. Each error is an associative array with the following keys and values: - error: An error code (should be a string prefixed with the module name). - message: The human readable message to be displayed.\n\nFile: modules/field/field.api.php", "response": "function hook_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {\n foreach ($items as $delta => $item) {\n if (!empty($item['value'])) {\n if (!empty($field['settings']['max_length']) && drupal_strlen($item['value']) > $field['settings']['max_length']) {\n $errors[$field['field_name']][$langcode][$delta][] = array(\n 'error' => 'text_max_length',\n 'message' => t('%name: the value may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])),\n );\n }\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-91e0211a78", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_theme/7.x", "instruction": "I need the code for `announcements_feed_theme()` in Drupal 7 (modules/announcements_feed/announcements_feed.module). It must do this: Implements hook_theme().", "context": "File: modules/announcements_feed/announcements_feed.module", "response": "function announcements_feed_theme() {\n return array(\n 'announcements_feed' => array(\n 'variables' => array(\n 'featured' => NULL,\n 'standard' => NULL,\n 'feed_link' => NULL,\n 'count' => 0,\n ),\n 'template' => 'announcements-feed',\n 'path' => drupal_get_path('module', 'announcements_feed'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-91e855eea8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_build_filter_query/7.x", "instruction": "Implement `node_build_filter_query(SelectQueryInterface $query)` in PHP for Drupal 7. Required behavior: Applies filters for node administration filters based on session.", "context": "Parameters:\n- $query: A SelectQuery to which the filters should be applied.\n\nFile: modules/node/node.admin.inc", "response": "function node_build_filter_query(SelectQueryInterface $query) {\n // Build query\n $filter_data = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();\n foreach ($filter_data as $index => $filter) {\n list($key, $value) = $filter;\n switch ($key) {\n case 'status':\n // Note: no exploitable hole as $key/$value have already been checked when submitted\n list($key, $value) = explode('-', $value, 2);\n case 'type':\n case 'language':\n $query->condition('n.' . $key, $value);\n break;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-91ea61e35b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_add_node_grants_to_query/7.x", "instruction": "In Drupal 7, write the function `node_add_node_grants_to_query($node_access_grants, $table_alias = '')` (file modules/node/node.module) so that it does the following: Helper function to create the or condition for a node grants check.", "context": "Parameters:\n- $account: The grants to add to the query, usually gotten via node_access_grants().\n- $table_alias: Optional, the alias to the node access table.\n\nReturns: TRUE if the operation may be performed, FALSE otherwise.\n\nFile: modules/node/node.module", "response": "function node_add_node_grants_to_query($node_access_grants, $table_alias = '') {\n $grants = db_or();\n $prefix = $table_alias ? $table_alias . '.' : '';\n foreach ($node_access_grants as $realm => $gids) {\n if (!empty($gids)) {\n $grants->condition(db_and()\n ->condition($prefix . 'gid', $gids, 'IN')\n ->condition($prefix . 'realm', $realm)\n );\n }\n }\n return $grants;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-91ead0c9bf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_update/7.x", "instruction": "Give me the example code for `hook_file_update($file)` in Drupal 7. Hook description: Respond to a file being updated.", "context": "This hook is called when file_save() is called on an existing file.\n\nParameters:\n- $file: The file that has just been updated.\n\nFile: modules/system/system.api.php", "response": "function hook_file_update($file) {\n $file_user = user_load($file->uid);\n // Make sure that the file name starts with the owner's user name.\n if (strpos($file->filename, $file_user->name) !== 0) {\n $old_filename = $file->filename;\n $file->filename = $file_user->name . '_' . $file->filename;\n $file->save();\n\n watchdog('file', '%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->filename));\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-91eb016d42", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_local_tasks/7.x", "instruction": "I need the code for `theme_menu_local_tasks(&$variables)` in Drupal 7 (includes/menu.inc). It must do this: Returns HTML for primary and secondary local tasks.", "context": "Parameters:\n- $variables: An associative array containing: - primary: (optional) An array of local tasks (tabs). - secondary: (optional) An array of local tasks (tabs).\n\nFile: includes/menu.inc", "response": "function theme_menu_local_tasks(&$variables) {\n $output = '';\n\n if (!empty($variables['primary'])) {\n $variables['primary']['#prefix'] = '

            ' . t('Primary tabs') . '

            ';\n $variables['primary']['#prefix'] .= '
              ';\n $variables['primary']['#suffix'] = '
            ';\n $output .= drupal_render($variables['primary']);\n }\n if (!empty($variables['secondary'])) {\n $variables['secondary']['#prefix'] = '

            ' . t('Secondary tabs') . '

            ';\n $variables['secondary']['#prefix'] .= '
              ';\n $variables['secondary']['#suffix'] = '
            ';\n $output .= drupal_render($variables['secondary']);\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-920ac58e0b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_help/7.x", "instruction": "I need the code for `contact_help($path, $arg)` in Drupal 7 (modules/contact/contact.module). It must do this: Implements hook_help().", "context": "File: modules/contact/contact.module", "response": "function contact_help($path, $arg) {\n switch ($path) {\n case 'admin/help#contact':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Contact module allows visitors to contact site administrators and other users. Users specify a subject, write their message, and can have a copy of their message sent to their own e-mail address. For more information, see the online handbook entry for Contact module.', array('@contact' => 'http://drupal.org/documentation/modules/contact/')) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('User contact forms') . '
            ';\n $output .= '
            ' . t('Site users can be contacted with a user contact form that keeps their e-mail address private. Users may enable or disable their personal contact forms by editing their My account page. If enabled, a Contact tab leads to a personal contact form displayed on their user profile. Site administrators are still able to use the contact form, even if has been disabled. The Contact tab is not shown when you view your own profile.') . '
            ';\n $output .= '
            ' . t('Site-wide contact forms') . '
            ';\n $output .= '
            ' . t('The Contact page provides a simple form for users with the Use the site-wide contact form permission to send comments, feedback, or other requests. You can create categories for directing the contact form messages to a set of defined recipients. Common categories for a business site, for example, might include \"Website feedback\" (messages are forwarded to website administrators) and \"Product information\" (messages are forwarded to members of the sales department). E-mail addresses defined within a category are not displayed publicly.', array('@contact' => url('contact'))) . '

            ';\n $output .= '
            ' . t('Navigation') . '
            ';\n $output .= '
            ' . t(\"When the site-wide contact form is enabled, a link in the main Navigation menu is created, but the link is disabled by default. This menu link can be enabled on the Menus administration page.\", array('@contact' => url('contact'), '@menu' => url('admin/structure/menu'))) . '
            ';\n $output .= '
            ' . t('Customization') . '
            ';\n $output .= '
            ' . t('If you would like additional text to appear on the site-wide or personal contact page, use a block. You can create and edit blocks on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '
            ';\n $output .= '
            ';\n return $output;\n case 'admin/structure/contact':\n $output = '

            ' . t('Add one or more categories on this page to set up your site-wide contact form.', array('@form' => url('contact'))) . '

            ';\n $output .= '

            ' . t('A Contact menu item (disabled by default) is added to the Navigation menu, which you can modify on the Menus administration page.', array('@menu-settings' => url('admin/structure/menu'))) . '

            ';\n $output .= '

            ' . t('If you would like additional text to appear on the site-wide contact page, use a block. You can create and edit blocks on the Blocks administration page.', array('@blocks' => url('admin/structure/block'))) . '

            ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-9212b6fd65", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_stream_wrapper_valid_scheme/7.x", "instruction": "In Drupal 7, write the function `file_stream_wrapper_valid_scheme($scheme)` (file includes/file.inc) so that it does the following: Checks that the scheme of a stream URI is valid.", "context": "Confirms that there is a registered stream handler for the provided scheme and that it is callable. This is useful if you want to confirm a valid scheme without creating a new instance of the registered handler.\n\nParameters:\n- $scheme: A URI scheme, a stream is referenced as \"scheme://target\".\n\nReturns: Returns TRUE if the string is the name of a validated stream, or FALSE if the scheme does not have a registered handler.\n\nFile: includes/file.inc", "response": "function file_stream_wrapper_valid_scheme($scheme) {\n // Does the scheme have a registered handler that is callable?\n $class = file_stream_wrapper_get_class($scheme);\n if (class_exists($class)) {\n return TRUE;\n }\n else {\n return FALSE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-921c846f26", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21bartik%21template.php/function/bartik_preprocess_maintenance_page/7.x", "instruction": "I need the code for `bartik_preprocess_maintenance_page(&$variables)` in Drupal 7 (themes/bartik/template.php). It must do this: Implements hook_preprocess_maintenance_page().", "context": "File: themes/bartik/template.php", "response": "function bartik_preprocess_maintenance_page(&$variables) {\n // By default, site_name is set to Drupal if no db connection is available\n // or during site installation. Setting site_name to an empty string makes\n // the site and update pages look cleaner.\n // @see template_preprocess_maintenance_page\n if (!$variables['db_is_active']) {\n $variables['site_name'] = '';\n }\n drupal_add_css(drupal_get_path('theme', 'bartik') . '/css/maintenance-page.css');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-921d6d87ff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.api.php/function/hook_taxonomy_term_delete/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_taxonomy_term_delete($term)` (modules/taxonomy/taxonomy.api.php): Respond to the deletion of taxonomy terms.", "context": "Modules implementing this hook can respond to the deletion of taxonomy terms from the database.\n\nParameters:\n- $term: A taxonomy term object.\n\nFile: modules/taxonomy/taxonomy.api.php", "response": "function hook_taxonomy_term_delete($term) {\n db_delete('mytable')\n ->condition('tid', $term->tid)\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-92433600f9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_info/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_block_info()` (modules/block/block.api.php): Define all blocks provided by the module.", "context": "This hook declares to Drupal what blocks are provided by your module and can optionally specify initial block configuration settings.\n\nIn hook_block_info(), each block your module provides is given a unique\nidentifier referred to as \"delta\" (the array key in the return value). Delta\nvalues only need to be unique within your module, and they are used in the\nfollowing ways:\n- Passed into the other block hooks in your module as an argument to identify\n the block being configured or viewed.\n- Used to construct the default HTML ID of \"block-MODULE-DELTA\" applied to\n each block when it is rendered. This ID may then be used for CSS styling or\n JavaScript programming.\n- Used to define a theming template suggestion of block__MODULE__DELTA, for\n advanced theming possibilities.\n- Used by other modules to identify your block in hook_block_info_alter() and\n other alter hooks.\nThe values of delta can be strings or numbers, but because of the uses above\nit is preferable to use descriptive strings whenever possible, and only use a\nnumeric identifier if you have to (for instance if your module allows users\nto create several similar blocks that you identify within your module code\nwith numeric IDs). The maximum length for delta values is 32 bytes.\n\nReturns: An associative array whose keys define the delta for each block and whose values contain the block descriptions. Each block description is itself an associative array, with the following key-value pairs: - info: (required) The human-readable administrative name of the block. This is used to identify the block on administration screens, and is not displayed to non-administrative users. - cache: (optional) A bitmask describing what kind of caching is appropriate for the block. Drupal provides the following bitmask constants for defining cache granularity: - DRUPAL_CACHE_PER_ROLE (default): The block can change depending on the roles the user viewing the page belongs to. - DRUPAL_CACHE_PER_USER: The block can change depending on the user viewing the page. This setting can be resource-consuming for sites with large number of users, and should only be used when DRUPAL_CACHE_PER_ROLE is not sufficient. - DRUPAL_CACHE_PER_PAGE: The block can change depending on the page being viewed. - DRUPAL_CACHE_GLOBAL: The block is the same for every user on every page where it is visible. - DRUPAL_CACHE_CUSTOM: The module implements its own caching system. - DRUPAL_NO_CACHE: The block should not get cached. - properties: (optional) Array of additional metadata to add to the block. Common properties include: - administrative: Boolean that categorizes this block as usable in an administrative context. This might include blocks that help an administrator approve/deny comments, or view recently created user accounts. - weight: (optional) Initial value for the ordering weight of this block. Most modules do not provide an initial value, and any value provided can be modified by a user on the block configuration screen. - status: (optional) Initial value for block enabled status. (1 = enabled, 0 = disabled). Most modules do not provide an initial value, and any value provided can be modified by a user on the block configuration screen. - region: (optional) Initial value for theme region within which this block is set. Most modules do not provide an initial value, and any value provided can be modified by a user on the block configuration screen. Note: If you set a region that isn't available in the currently enabled theme, the block will be disabled. - visibility: (optional) Initial value for the visibility flag, which tells how to interpret the 'pages' value. Possible values are: - BLOCK_VISIBILITY_NOTLISTED: Show on all pages except listed pages. 'pages' lists the paths where the block should not be shown. - BLOCK_VISIBILITY_LISTED: Show only on listed pages. 'pages' lists the paths where the block should be shown. - BLOCK_VISIBILITY_PHP: Use custom PHP code to determine visibility. 'pages' gives the PHP code to use. Most modules do not provide an initial value for 'visibility' or 'pages', and any value provided can be modified by a user on the block configuration screen. - pages: (optional) See 'visibility' above. A string that contains one or more page paths separated by \"\\n\", \"\\r\", or \"\\r\\n\" when 'visibility' is set to BLOCK_VISIBILITY_NOTLISTED or BLOCK_VISIBILITY_LISTED (example: \"\\nnode/1\"), or custom PHP code when 'visibility' is set to BLOCK_VISIBILITY_PHP. Paths may use '*' as a wildcard (matching any number of characters); '' designates the site's front page. For BLOCK_VISIBILITY_PHP, the PHP code's return value should be TRUE if the block is to be made visible or FALSE if the block should not be visible. For a detailed usage example, see block_example.module.\n\nFile: modules/block/block.api.php", "response": "function hook_block_info() {\n // This example comes from node.module.\n $blocks['syndicate'] = array(\n 'info' => t('Syndicate'),\n 'cache' => DRUPAL_NO_CACHE\n );\n\n $blocks['recent'] = array(\n 'info' => t('Recent content'),\n // DRUPAL_CACHE_PER_ROLE will be assumed.\n );\n\n return $blocks;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-9256894622", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_type_options/7.x", "instruction": "I need the code for `field_ui_field_type_options()` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Returns an array of field_type options.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_field_type_options() {\n $options = &drupal_static(__FUNCTION__);\n\n if (!isset($options)) {\n $options = array();\n $field_types = field_info_field_types();\n $field_type_options = array();\n foreach ($field_types as $name => $field_type) {\n // Skip field types which have no widget types, or should not be add via\n // uesr interface.\n if (field_ui_widget_type_options($name) && empty($field_type['no_ui'])) {\n $options[$name] = $field_type['label'];\n }\n }\n asort($options);\n }\n return $options;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9259ad2c39", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.admin.inc/function/_forum_parent_select/7.x", "instruction": "Implement `_forum_parent_select($tid, $title, $child_type)` in PHP for Drupal 7. Required behavior: Returns a select box for available parent terms.", "context": "Parameters:\n- $tid: ID of the term that is being added or edited.\n- $title: Title for the select box.\n- $child_type: Whether the child is a forum or a container.\n\nReturns: A select form element.\n\nFile: modules/forum/forum.admin.inc", "response": "function _forum_parent_select($tid, $title, $child_type) {\n\n $parents = taxonomy_get_parents($tid);\n if ($parents) {\n $parent = array_shift($parents);\n $parent = $parent->tid;\n }\n else {\n $parent = 0;\n }\n\n $vid = variable_get('forum_nav_vocabulary', '');\n $children = taxonomy_get_tree($vid, $tid);\n\n // A term can't be the child of itself, nor of its children.\n foreach ($children as $child) {\n $exclude[] = $child->tid;\n }\n $exclude[] = $tid;\n\n $tree = taxonomy_get_tree($vid);\n $options[0] = '<' . t('root') . '>';\n if ($tree) {\n foreach ($tree as $term) {\n if (!in_array($term->tid, $exclude)) {\n $options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->name;\n }\n }\n }\n if ($child_type == 'container') {\n $description = t('Containers are usually placed at the top (root) level, but may also be placed inside another container or forum.');\n }\n elseif ($child_type == 'forum') {\n $description = t('Forums may be placed at the top (root) level, or inside another container or forum.');\n }\n\n return array('#type' => 'select', '#title' => $title, '#default_value' => $parent, '#options' => $options, '#description' => $description, '#required' => TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-92677ed756", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_radios/7.x", "instruction": "I need the code for `form_process_radios($element)` in Drupal 7 (includes/form.inc). It must do this: Expands a radios element into individual radio elements.", "context": "File: includes/form.inc", "response": "function form_process_radios($element) {\n if (count($element['#options']) > 0) {\n $weight = 0;\n foreach ($element['#options'] as $key => $choice) {\n // Maintain order of options as defined in #options, in case the element\n // defines custom option sub-elements, but does not define all option\n // sub-elements.\n $weight += 0.001;\n\n $element += array($key => array());\n // Generate the parents as the autogenerator does, so we will have a\n // unique id for each radio button.\n $parents_for_id = array_merge($element['#parents'], array($key));\n $element[$key] += array(\n '#type' => 'radio',\n '#title' => $choice,\n // The key is sanitized in drupal_attributes() during output from the\n // theme function.\n '#return_value' => $key,\n // Use default or FALSE. A value of FALSE means that the radio button is\n // not 'checked'.\n '#default_value' => isset($element['#default_value']) ? $element['#default_value'] : FALSE,\n '#attributes' => $element['#attributes'],\n '#parents' => $element['#parents'],\n '#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),\n '#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,\n '#weight' => $weight,\n );\n }\n }\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9269f7134e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_field_widget_validate/7.x", "instruction": "In Drupal 7, write the function `options_field_widget_validate($element, &$form_state)` (file modules/field/modules/options/options.module) so that it does the following: Form element validation handler for options element.", "context": "File: modules/field/modules/options/options.module", "response": "function options_field_widget_validate($element, &$form_state) {\n if ($element['#required'] && $element['#value'] == '_none') {\n form_error($element, t('!name field is required.', array('!name' => $element['#title'])));\n }\n // Transpose selections from field => delta to delta => field, turning\n // multiple selected options into multiple parent elements.\n $items = _options_form_to_storage($element);\n form_set_value($element, $items, $form_state);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-92708c8195", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.api.php/function/hook_menu_update/7.x", "instruction": "Give me the example code for `hook_menu_update($menu)` in Drupal 7. Hook description: Respond to a custom menu update.", "context": "This hook is used to notify modules that a custom menu has been updated. Contributed modules may use the information to perform actions based on the information entered into the menu system.\n\nParameters:\n- $menu: An array representing a custom menu: - menu_name: The unique name of the custom menu. - title: The human readable menu title. - description: The custom menu description. - old_name: The current 'menu_name'. Note that internal menu names cannot be changed after initial creation.\n\nFile: modules/menu/menu.api.php", "response": "function hook_menu_update($menu) {\n // For example, we track available menus in a variable.\n $my_menus = variable_get('my_module_menus', array());\n $my_menus[$menu['menu_name']] = $menu['menu_name'];\n variable_set('my_module_menus', $my_menus);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-92807ee7db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.pages.inc/function/openid_user_add/7.x", "instruction": "In Drupal 7, write the function `openid_user_add()` (file modules/openid/openid.pages.inc) so that it does the following: Form builder; Add an OpenID identity.", "context": "File: modules/openid/openid.pages.inc", "response": "function openid_user_add() {\n $form['openid_identifier'] = array(\n '#type' => 'textfield',\n '#title' => t('OpenID'),\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Add an OpenID'));\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9299a2edd9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_formatter_info/7.x", "instruction": "I need the code for `text_field_formatter_info()` in Drupal 7 (modules/field/modules/text/text.module). It must do this: Implements hook_field_formatter_info().", "context": "File: modules/field/modules/text/text.module", "response": "function text_field_formatter_info() {\n return array(\n 'text_default' => array(\n 'label' => t('Default'),\n 'field types' => array('text', 'text_long', 'text_with_summary'),\n ),\n 'text_plain' => array(\n 'label' => t('Plain text'),\n 'field types' => array('text', 'text_long', 'text_with_summary'),\n ),\n\n // The text_trimmed formatter displays the trimmed version of the\n // full element of the field. It is intended to be used with text\n // and text_long fields. It also works with text_with_summary\n // fields though the text_summary_or_trimmed formatter makes more\n // sense for that field type.\n 'text_trimmed' => array(\n 'label' => t('Trimmed'),\n 'field types' => array('text', 'text_long', 'text_with_summary'),\n 'settings' => array('trim_length' => 600),\n ),\n\n // The 'summary or trimmed' field formatter for text_with_summary\n // fields displays returns the summary element of the field or, if\n // the summary is empty, the trimmed version of the full element\n // of the field.\n 'text_summary_or_trimmed' => array(\n 'label' => t('Summary or trimmed'),\n 'field types' => array('text_with_summary'),\n 'settings' => array('trim_length' => 600),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-92a20b294c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21graph.inc/function/_drupal_depth_first_search/7.x", "instruction": "In Drupal 7, write the function `_drupal_depth_first_search(&$graph, &$state, $start, &$component = NULL)` (file includes/graph.inc) so that it does the following: Performs a depth-first search on a graph.", "context": "Parameters:\n- $graph: A three dimensional associated graph array.\n- $state: An associative array. The key 'last_visit_order' stores a list of the vertices visited. The key components stores list of vertices belonging to the same the component.\n- $start: An arbitrary vertex where we started traversing the graph.\n- $component: The component of the last vertex.\n\nFile: includes/graph.inc", "response": "function _drupal_depth_first_search(&$graph, &$state, $start, &$component = NULL) {\n // Assign new component for each new vertex, i.e. when not called recursively.\n if (!isset($component)) {\n $component = $start;\n }\n // Nothing to do, if we already visited this vertex.\n if (isset($graph[$start]['paths'])) {\n return;\n }\n // Mark $start as visited.\n $graph[$start]['paths'] = array();\n\n // Assign $start to the current component.\n $graph[$start]['component'] = $component;\n $state['components'][$component][] = $start;\n\n // Visit edges of $start.\n if (isset($graph[$start]['edges'])) {\n foreach ($graph[$start]['edges'] as $end => $v) {\n // Mark that $start can reach $end.\n $graph[$start]['paths'][$end] = $v;\n\n if (isset($graph[$end]['component']) && $component != $graph[$end]['component']) {\n // This vertex already has a component, use that from now on and\n // reassign all the previously explored vertices.\n $new_component = $graph[$end]['component'];\n foreach ($state['components'][$component] as $vertex) {\n $graph[$vertex]['component'] = $new_component;\n $state['components'][$new_component][] = $vertex;\n }\n unset($state['components'][$component]);\n $component = $new_component;\n }\n // Only visit existing vertices.\n if (isset($graph[$end])) {\n // Visit the connected vertex.\n _drupal_depth_first_search($graph, $state, $end, $component);\n\n // All vertices reachable by $end are also reachable by $start.\n $graph[$start]['paths'] += $graph[$end]['paths'];\n }\n }\n }\n\n // Now that any other subgraph has been explored, add $start to all reverse\n // paths.\n foreach ($graph[$start]['paths'] as $end => $v) {\n if (isset($graph[$end])) {\n $graph[$end]['reverse_paths'][$start] = $v;\n }\n }\n\n // Record the order of the last visit. This is the reverse of the\n // topological order if the graph is acyclic.\n $state['last_visit_order'][] = $start;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-92a7077d8c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_install_profile_distribution_name/7.x", "instruction": "I need the code for `drupal_install_profile_distribution_name()` in Drupal 7 (includes/install.inc). It must do this: Loads the installation profile, extracting its defined distribution name.", "context": "Returns: The distribution name defined in the profile's .info file. Defaults to \"Drupal\" if none is explicitly provided by the installation profile.\n\nFile: includes/install.inc", "response": "function drupal_install_profile_distribution_name() {\n // During installation, the profile information is stored in the global\n // installation state (it might not be saved anywhere yet).\n if (drupal_installation_attempted()) {\n global $install_state;\n return $install_state['profile_info']['distribution_name'];\n }\n // At all other times, we load the profile via standard methods.\n else {\n $profile = drupal_get_profile();\n $info = system_get_info('module', $profile);\n return $info['distribution_name'];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-92bad06531", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.install/function/statistics_schema/7.x", "instruction": "I need the code for `statistics_schema()` in Drupal 7 (modules/statistics/statistics.install). It must do this: Implements hook_schema().", "context": "File: modules/statistics/statistics.install", "response": "function statistics_schema() {\n $schema['accesslog'] = array(\n 'description' => 'Stores site access information for statistics.',\n 'fields' => array(\n 'aid' => array(\n 'type' => 'serial',\n 'not null' => TRUE,\n 'description' => 'Primary Key: Unique accesslog ID.',\n ),\n 'sid' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Browser session ID of user that visited page.',\n ),\n 'title' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n 'description' => 'Title of page visited.',\n ),\n 'path' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n 'description' => 'Internal path to page visited (relative to Drupal root.)',\n ),\n 'url' => array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'description' => 'Referrer URI.',\n ),\n 'hostname' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => FALSE,\n 'description' => 'Hostname of user that visited the page.',\n ),\n 'uid' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => FALSE,\n 'default' => 0,\n 'description' => 'User {users}.uid that visited the page.',\n ),\n 'timer' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Time in milliseconds that the page took to load.',\n ),\n 'timestamp' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Timestamp of when the page was visited.',\n ),\n ),\n 'indexes' => array(\n 'accesslog_timestamp' => array('timestamp'),\n 'uid' => array('uid'),\n ),\n 'primary key' => array('aid'),\n 'foreign keys' => array(\n 'visitor' => array(\n 'table' => 'users',\n 'columns' => array('uid' => 'uid'),\n ),\n ),\n );\n\n $schema['node_counter'] = array(\n 'description' => 'Access statistics for {node}s.',\n 'fields' => array(\n 'nid' => array(\n 'description' => 'The {node}.nid for these statistics.',\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'totalcount' => array(\n 'description' => 'The total number of times the {node} has been viewed.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'big',\n ),\n 'daycount' => array(\n 'description' => 'The total number of times the {node} has been viewed today.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'medium',\n ),\n 'timestamp' => array(\n 'description' => 'The most recent time the {node} has been viewed.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n ),\n 'primary key' => array('nid'),\n );\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-92d8d214e7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_rdf_mapping/7.x", "instruction": "I need the code for `forum_rdf_mapping()` in Drupal 7 (modules/forum/forum.module). It must do this: Implements hook_rdf_mapping().", "context": "File: modules/forum/forum.module", "response": "function forum_rdf_mapping() {\n return array(\n array(\n 'type' => 'node',\n 'bundle' => 'forum',\n 'mapping' => array(\n 'rdftype' => array('sioc:Post', 'sioct:BoardPost'),\n 'taxonomy_forums' => array(\n 'predicates' => array('sioc:has_container'),\n 'type' => 'rel',\n ),\n ),\n ),\n array(\n 'type' => 'taxonomy_term',\n 'bundle' => 'forums',\n 'mapping' => array(\n 'rdftype' => array('sioc:Container', 'sioc:Forum'),\n ),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-92e218186f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_preprocess_page/7.x", "instruction": "Implement `shortcut_preprocess_page(&$variables)` in PHP for Drupal 7. Required behavior: Implements hook_preprocess_page().", "context": "File: modules/shortcut/shortcut.module", "response": "function shortcut_preprocess_page(&$variables) {\n // Only display the shortcut link if the user has the ability to edit\n // shortcuts and if the page's actual content is being shown (for example,\n // we do not want to display it on \"access denied\" or \"page not found\"\n // pages).\n if (shortcut_set_edit_access() && ($item = menu_get_item()) && $item['access']) {\n $link = $_GET['q'];\n $query_parameters = drupal_get_query_parameters();\n if (!empty($query_parameters)) {\n $link .= '?' . drupal_http_build_query($query_parameters);\n }\n $query = array(\n 'link' => $link,\n 'name' => drupal_get_title(),\n );\n $query += drupal_get_destination();\n\n $shortcut_set = shortcut_current_displayed_set();\n\n // Check if $link is already a shortcut and set $link_mode accordingly.\n foreach ($shortcut_set->links as $shortcut) {\n if ($link == $shortcut['link_path']) {\n $mlid = $shortcut['mlid'];\n break;\n }\n }\n $link_mode = isset($mlid) ? \"remove\" : \"add\";\n\n if ($link_mode == \"add\") {\n $query['token'] = drupal_get_token('shortcut-add-link');\n $link_text = shortcut_set_switch_access() ? t('Add to %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->title)) : t('Add to shortcuts');\n $link_path = 'admin/config/user-interface/shortcut/' . $shortcut_set->set_name . '/add-link-inline';\n }\n else {\n $query['mlid'] = $mlid;\n $link_text = shortcut_set_switch_access() ? t('Remove from %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->title)) : t('Remove from shortcuts');\n $link_path = 'admin/config/user-interface/shortcut/link/' . $mlid . '/delete';\n }\n\n if (theme_get_setting('shortcut_module_link')) {\n $variables['title_suffix']['add_or_remove_shortcut'] = array(\n '#attached' => array('css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.css')),\n '#prefix' => '
            ',\n '#type' => 'link',\n '#title' => '' . $link_text . '',\n '#href' => $link_path,\n '#options' => array('query' => $query, 'html' => TRUE),\n '#suffix' => '
            ',\n );\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-92f2df1966", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_remove/7.x", "instruction": "I need the code for `ajax_command_remove($selector)` in Drupal 7 (includes/ajax.inc). It must do this: Creates a Drupal Ajax 'remove' command.", "context": "The 'remove' command instructs the client to use jQuery's remove() method to remove each of elements matched by the given selector, and everything within them.\n\nThis command is implemented by Drupal.ajax.prototype.commands.remove() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_remove($selector) {\n return array(\n 'command' => 'remove',\n 'selector' => $selector,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-92f3d3483f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21tablesort.inc/function/tablesort_cell/7.x", "instruction": "I need the code for `tablesort_cell($cell, $header, $ts, $i)` in Drupal 7 (includes/tablesort.inc). It must do this: Formats a table cell.", "context": "Adds a class attribute to all cells in the currently active column.\n\nParameters:\n- $cell: The cell to format.\n- $header: An array of column headers in the format described in theme_table().\n- $ts: The current table sort context as returned from tablesort_init().\n- $i: The index of the cell's table column.\n\nReturns: A properly formatted cell, ready for _theme_table_cell().\n\nFile: includes/tablesort.inc", "response": "function tablesort_cell($cell, $header, $ts, $i) {\n if (isset($header[$i]['data']) && $header[$i]['data'] == $ts['name'] && !empty($header[$i]['field'])) {\n if (is_array($cell)) {\n $cell['class'][] = 'active';\n }\n else {\n $cell = array('data' => $cell, 'class' => array('active'));\n }\n }\n return $cell;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-92fc0e3e14", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_get_error/7.x", "instruction": "I need the code for `form_get_error($element)` in Drupal 7 (includes/form.inc). It must do this: Returns the error message filed against the given form element.", "context": "Form errors higher up in the form structure override deeper errors as well as errors on the element itself.\n\nFile: includes/form.inc", "response": "function form_get_error($element) {\n $form = form_set_error();\n $parents = array();\n foreach ($element['#parents'] as $parent) {\n $parents[] = $parent;\n $key = implode('][', $parents);\n if (isset($form[$key])) {\n return $form[$key];\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9302cf48e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_errno/7.x", "instruction": "Implement `xmlrpc_errno()` in PHP for Drupal 7. Required behavior: Returns the last XML-RPC client error number.", "context": "File: includes/xmlrpc.inc", "response": "function xmlrpc_errno() {\n $error = xmlrpc_error();\n return ($error != NULL ? $error->code : NULL);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9318beff30", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.install/function/field_sql_storage_update_7002/7.x", "instruction": "In Drupal 7, write the function `field_sql_storage_update_7002()` (file modules/field/modules/field_sql_storage/field_sql_storage.install) so that it does the following: Fix primary keys in field revision data tables.", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.install", "response": "function field_sql_storage_update_7002() {\n $results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))\n ->fields('fc')\n ->condition('storage_module', 'field_sql_storage')\n ->execute();\n foreach ($results as $field) {\n // Revision tables of deleted fields do not need to be fixed, since no new\n // data is written to them.\n if (!$field['deleted']) {\n $table = \"field_revision_{$field['field_name']}\";\n db_drop_primary_key($table);\n db_add_primary_key($table, array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-932e7688b2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_date/7.x", "instruction": "In Drupal 7, write the function `theme_date($variables)` (file includes/form.inc) so that it does the following: Returns HTML for a date selection form element.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #title, #value, #options, #description, #required, #attributes.\n\nFile: includes/form.inc", "response": "function theme_date($variables) {\n $element = $variables['element'];\n\n $attributes = array();\n if (isset($element['#id'])) {\n $attributes['id'] = $element['#id'];\n }\n if (!empty($element['#attributes']['class'])) {\n $attributes['class'] = (array) $element['#attributes']['class'];\n }\n $attributes['class'][] = 'container-inline';\n\n return '' . drupal_render_children($element) . '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-933d74d19c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.install/function/tracker_schema/7.x", "instruction": "In Drupal 7, write the function `tracker_schema()` (file modules/tracker/tracker.install) so that it does the following: Implements hook_schema().", "context": "File: modules/tracker/tracker.install", "response": "function tracker_schema() {\n $schema['tracker_node'] = array(\n 'description' => 'Tracks when nodes were last changed or commented on.',\n 'fields' => array(\n 'nid' => array(\n 'description' => 'The {node}.nid this record tracks.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'published' => array(\n 'description' => 'Boolean indicating whether the node is published.',\n 'type' => 'int',\n 'not null' => FALSE,\n 'default' => 0,\n 'size' => 'tiny',\n ),\n 'changed' => array(\n 'description' => 'The Unix timestamp when the node was most recently saved or commented on.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n ),\n 'indexes' => array(\n 'tracker' => array('published', 'changed'),\n ),\n 'primary key' => array('nid'),\n 'foreign keys' => array(\n 'tracked_node' => array(\n 'table' => 'node',\n 'columns' => array('nid' => 'nid'),\n ),\n ),\n );\n\n $schema['tracker_user'] = array(\n 'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',\n 'fields' => array(\n 'nid' => array(\n 'description' => 'The {node}.nid this record tracks.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'uid' => array(\n 'description' => 'The {users}.uid of the node author or commenter.',\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'published' => array(\n 'description' => 'Boolean indicating whether the node is published.',\n 'type' => 'int',\n 'not null' => FALSE,\n 'default' => 0,\n 'size' => 'tiny',\n ),\n 'changed' => array(\n 'description' => 'The Unix timestamp when the node was most recently saved or commented on.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n ),\n 'indexes' => array(\n 'tracker' => array('uid', 'published', 'changed'),\n ),\n 'primary key' => array('nid', 'uid'),\n 'foreign keys' => array(\n 'tracked_node' => array(\n 'table' => 'node',\n 'columns' => array('nid' => 'nid'),\n ),\n 'tracked_user' => array(\n 'table' => 'users',\n 'columns' => array('uid' => 'uid'),\n ),\n ),\n );\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-934f104258", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_set_assign_user/7.x", "instruction": "Implement `shortcut_set_assign_user($shortcut_set, $account)` in PHP for Drupal 7. Required behavior: Assigns a user to a particular shortcut set.", "context": "Parameters:\n- $shortcut_set: An object representing the shortcut set.\n- $account: A user account that will be assigned to use the set.\n\nFile: modules/shortcut/shortcut.module", "response": "function shortcut_set_assign_user($shortcut_set, $account) {\n db_merge('shortcut_set_users')\n ->key(array('uid' => $account->uid))\n ->fields(array('set_name' => $shortcut_set->set_name))\n ->execute();\n drupal_static_reset('shortcut_current_displayed_set');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-938e20db6c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_field_settings_form/7.x", "instruction": "I need the code for `list_field_settings_form($field, $instance, $has_data)` in Drupal 7 (modules/field/modules/list/list.module). It must do this: Implements hook_field_settings_form().", "context": "File: modules/field/modules/list/list.module", "response": "function list_field_settings_form($field, $instance, $has_data) {\n $settings = $field['settings'];\n\n switch ($field['type']) {\n case 'list_integer':\n case 'list_float':\n case 'list_text':\n $form['allowed_values'] = array(\n '#type' => 'textarea',\n '#title' => t('Allowed values list'),\n '#default_value' => empty($settings['allowed_values_function']) ? list_allowed_values_string($settings['allowed_values']) : '',\n '#rows' => 10,\n '#element_validate' => array('list_allowed_values_setting_validate'),\n '#field_has_data' => $has_data,\n '#field' => $field,\n '#field_type' => $field['type'],\n '#access' => empty($settings['allowed_values_function']),\n );\n\n $description = '

            ' . t('The possible values this field can contain. Enter one value per line, in the format key|label.');\n if ($field['type'] == 'list_integer' || $field['type'] == 'list_float') {\n $description .= '
            ' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.');\n $description .= '
            ' . t('The label is optional: if a line contains a single number, it will be used as key and label.');\n $description .= '
            ' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.');\n }\n else {\n $description .= '
            ' . t('The key is the stored value. The label will be used in displayed values and edit forms.');\n $description .= '
            ' . t('The label is optional: if a line contains a single string, it will be used as key and label.');\n }\n $description .= '

            ';\n $form['allowed_values']['#description'] = $description;\n\n break;\n\n case 'list_boolean':\n $values = $settings['allowed_values'];\n $off_value = array_shift($values);\n $on_value = array_shift($values);\n\n $form['allowed_values'] = array(\n '#type' => 'value',\n '#description' => '',\n '#value_callback' => 'list_boolean_allowed_values_callback',\n '#access' => empty($settings['allowed_values_function']),\n );\n $form['allowed_values']['on'] = array(\n '#type' => 'textfield',\n '#title' => t('On value'),\n '#default_value' => $on_value,\n '#required' => FALSE,\n '#description' => t('If left empty, \"1\" will be used.'),\n // Change #parents to make sure the element is not saved into field\n // settings.\n '#parents' => array('on'),\n );\n $form['allowed_values']['off'] = array(\n '#type' => 'textfield',\n '#title' => t('Off value'),\n '#default_value' => $off_value,\n '#required' => FALSE,\n '#description' => t('If left empty, \"0\" will be used.'),\n // Change #parents to make sure the element is not saved into field\n // settings.\n '#parents' => array('off'),\n );\n\n // Link the allowed value to the on / off elements to prepare for the rare\n // case of an alter changing #parents.\n $form['allowed_values']['#on_parents'] = &$form['allowed_values']['on']['#parents'];\n $form['allowed_values']['#off_parents'] = &$form['allowed_values']['off']['#parents'];\n\n break;\n }\n\n // Alter the description for allowed values depending on the widget type.\n if ($instance['widget']['type'] == 'options_onoff') {\n $form['allowed_values']['#description'] .= '

            ' . t(\"For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the Allowed values section. Note that the checkbox will be labeled with the label of the 'on' value.\") . '

            ';\n }\n elseif ($instance['widget']['type'] == 'options_buttons') {\n $form['allowed_values']['#description'] .= '

            ' . t(\"The 'checkboxes/radio buttons' widget will display checkboxes if the Number of values option is greater than 1 for this field, otherwise radios will be displayed.\") . '

            ';\n }\n $form['allowed_values']['#description'] .= '

            ' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '

            ';\n\n $form['allowed_values_function'] = array(\n '#type' => 'value',\n '#value' => $settings['allowed_values_function'],\n );\n $form['allowed_values_function_display'] = array(\n '#type' => 'item',\n '#title' => t('Allowed values list'),\n '#markup' => t('The value of this field is being determined by the %function function and may not be changed.', array('%function' => $settings['allowed_values_function'])),\n '#access' => !empty($settings['allowed_values_function']),\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-9392375920", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_unassign_submit/7.x", "instruction": "I need the code for `trigger_unassign_submit($form, &$form_state)` in Drupal 7 (modules/trigger/trigger.admin.inc). It must do this: Form submission handler for trigger_unassign().", "context": "File: modules/trigger/trigger.admin.inc", "response": "function trigger_unassign_submit($form, &$form_state) {\n if ($form_state['values']['confirm'] == 1) {\n $aid = actions_function_lookup($form_state['values']['aid']);\n db_delete('trigger_assignments')\n ->condition('hook', $form_state['values']['hook'])\n ->condition('aid', $aid)\n ->execute();\n drupal_static_reset('trigger_get_assigned_actions');\n $actions = actions_get_all_actions();\n watchdog('actions', 'Action %action has been unassigned.', array('%action' => $actions[$aid]['label']));\n drupal_set_message(t('Action %action has been unassigned.', array('%action' => $actions[$aid]['label'])));\n $form_state['redirect'] = 'admin/structure/trigger/' . $form_state['values']['module'];\n }\n else {\n drupal_goto('admin/structure/trigger');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-939b535dbb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_delete_instance/7.x", "instruction": "In Drupal 7, write the function `field_delete_instance($instance, $field_cleanup = TRUE)` (file modules/field/field.crud.inc) so that it does the following: Marks a field instance and its data for deletion.", "context": "Parameters:\n- $instance: An instance structure.\n- $field_cleanup: If TRUE, the field will be deleted as well if its last instance is being deleted. If FALSE, it is the caller's responsibility to handle the case of fields left without instances. Defaults to TRUE.\n\nFile: modules/field/field.crud.inc", "response": "function field_delete_instance($instance, $field_cleanup = TRUE) {\n // Mark the field instance for deletion.\n db_update('field_config_instance')\n ->fields(array('deleted' => 1))\n ->condition('field_name', $instance['field_name'])\n ->condition('entity_type', $instance['entity_type'])\n ->condition('bundle', $instance['bundle'])\n ->execute();\n\n // Clear the cache.\n field_cache_clear();\n\n // Mark instance data for deletion.\n $field = field_info_field($instance['field_name']);\n module_invoke($field['storage']['module'], 'field_storage_delete_instance', $instance);\n\n // Let modules react to the deletion of the instance.\n module_invoke_all('field_delete_instance', $instance);\n\n // Delete the field itself if we just deleted its last instance.\n if ($field_cleanup && count($field['bundles']) == 0) {\n field_delete_field($field['field_name']);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-939c82c727", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_view/7.x", "instruction": "In Drupal 7, write the function `toolbar_view()` (file modules/toolbar/toolbar.module) so that it does the following: Builds the admin menu as a structured array ready for drupal_render().", "context": "Returns (Array): of links and settings relating to the admin menu.\n\nFile: modules/toolbar/toolbar.module", "response": "function toolbar_view() {\n global $user;\n\n $module_path = drupal_get_path('module', 'toolbar');\n $build = array(\n '#theme' => 'toolbar',\n '#attached'=> array(\n 'js' => array(\n $module_path . '/toolbar.js',\n array(\n 'data' => array('tableHeaderOffset' => 'Drupal.toolbar.height'),\n 'type' => 'setting'\n ),\n ),\n 'css' => array(\n $module_path . '/toolbar.css',\n $module_path . '/toolbar-print.css' => array(\n 'media' => 'print',\n ),\n ),\n 'library' => array(array('system', 'jquery.cookie')),\n ),\n );\n\n // Retrieve the admin menu from the database.\n $links = toolbar_menu_navigation_links(toolbar_get_menu_tree());\n $build['toolbar_menu'] = array(\n '#theme' => 'links__toolbar_menu',\n '#links' => $links,\n '#attributes' => array('id' => 'toolbar-menu'),\n '#heading' => array('text' => t('Administrative toolbar'), 'level' => 'h2', 'class' => 'element-invisible'),\n );\n\n // Add logout & user account links or login link.\n if ($user->uid) {\n $links = array(\n 'account' => array(\n 'title' => t('Hello @username', array('@username' => format_username($user))),\n 'href' => 'user',\n 'html' => TRUE,\n 'attributes' => array('title' => t('User account')),\n ),\n 'logout' => array(\n 'title' => t('Log out'),\n 'href' => 'user/logout',\n ),\n );\n }\n else {\n $links = array(\n 'login' => array(\n 'title' => t('Log in'),\n 'href' => 'user',\n ),\n );\n }\n $build['toolbar_user'] = array(\n '#theme' => 'links__toolbar_user',\n '#links' => $links,\n '#attributes' => array('id' => 'toolbar-user'),\n );\n\n // Add a \"home\" link.\n $link = array(\n 'home' => array(\n 'title' => 'Home',\n 'href' => '',\n 'html' => TRUE,\n 'attributes' => array('title' => t('Home')),\n ),\n );\n $build['toolbar_home'] = array(\n '#theme' => 'links',\n '#links' => $link,\n '#attributes' => array('id' => 'toolbar-home'),\n );\n\n // Add an anchor to be able to toggle the visibility of the drawer.\n $build['toolbar_toggle'] = array(\n '#theme' => 'toolbar_toggle',\n '#collapsed' => _toolbar_is_collapsed(),\n '#attributes' => array('class' => array('toggle')),\n );\n\n // Prepare the drawer links CSS classes.\n $toolbar_drawer_classes = array(\n 'toolbar-drawer',\n 'clearfix',\n );\n if(_toolbar_is_collapsed()) {\n $toolbar_drawer_classes[] = 'collapsed';\n }\n $build['toolbar_drawer_classes'] = implode(' ', $toolbar_drawer_classes);\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-93b822dfc4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21language.api.php/function/hook_language_types_info_alter/7.x", "instruction": "Give me the example code for `hook_language_types_info_alter(array &$language_types)` in Drupal 7. Hook description: Perform alterations on language types.", "context": "Parameters:\n- $language_types: Array of language type definitions.\n\nFile: modules/system/language.api.php", "response": "function hook_language_types_info_alter(array &$language_types) {\n if (isset($language_types['custom_language_type'])) {\n $language_types['custom_language_type_custom']['description'] = t('A far better description.');\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-93db41588a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_settings_form/7.x", "instruction": "Implement `file_field_settings_form($field, $instance, $has_data)` in PHP for Drupal 7. Required behavior: Implements hook_field_settings_form().", "context": "File: modules/file/file.field.inc", "response": "function file_field_settings_form($field, $instance, $has_data) {\n $defaults = field_info_field_settings($field['type']);\n $settings = array_merge($defaults, $field['settings']);\n\n $form['#attached']['js'][] = drupal_get_path('module', 'file') . '/file.js';\n\n $form['display_field'] = array(\n '#type' => 'checkbox',\n '#title' => t('Enable Display field'),\n '#default_value' => $settings['display_field'],\n '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'),\n );\n $form['display_default'] = array(\n '#type' => 'checkbox',\n '#title' => t('Files displayed by default'),\n '#default_value' => $settings['display_default'],\n '#description' => t('This setting only has an effect if the display option is enabled.'),\n );\n\n $scheme_options = array();\n foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {\n $scheme_options[$scheme] = $stream_wrapper['name'];\n }\n $form['uri_scheme'] = array(\n '#type' => 'radios',\n '#title' => t('Upload destination'),\n '#options' => $scheme_options,\n '#default_value' => $settings['uri_scheme'],\n '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'),\n '#disabled' => $has_data,\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-93f2808514", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.install/function/rdf_schema/7.x", "instruction": "In Drupal 7, write the function `rdf_schema()` (file modules/rdf/rdf.install) so that it does the following: Implements hook_schema().", "context": "File: modules/rdf/rdf.install", "response": "function rdf_schema() {\n $schema['rdf_mapping'] = array(\n 'description' => 'Stores custom RDF mappings for user defined content types or overriden module-defined mappings',\n 'fields' => array(\n 'type' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'description' => 'The name of the entity type a mapping applies to (node, user, comment, etc.).',\n ),\n 'bundle' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'description' => 'The name of the bundle a mapping applies to.',\n ),\n 'mapping' => array(\n 'description' => 'The serialized mapping of the bundle type and fields to RDF terms.',\n 'type' => 'blob',\n 'not null' => FALSE,\n 'size' => 'big',\n 'serialize' => TRUE,\n ),\n ),\n 'primary key' => array('type', 'bundle'),\n );\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-93fa4e1378", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_link_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_menu_link_alter(&$item)` (modules/system/system.api.php): Alter the data being saved to the {menu_links} table by menu_link_save().", "context": "Parameters:\n- $item: Associative array defining a menu link as passed into menu_link_save().\n\nFile: modules/system/system.api.php", "response": "function hook_menu_link_alter(&$item) {\n // Make all new admin links hidden (a.k.a disabled).\n if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) {\n $item['hidden'] = 1;\n }\n // Flag a link to be altered by hook_translated_menu_link_alter().\n if ($item['link_path'] == 'devel/cache/clear') {\n $item['options']['alter'] = TRUE;\n }\n // Flag a link to be altered by hook_translated_menu_link_alter(), but only\n // if it is derived from a menu router item; i.e., do not alter a custom\n // menu link pointing to the same path that has been created by a user.\n if ($item['link_path'] == 'user' && $item['module'] == 'system') {\n $item['options']['alter'] = TRUE;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-93fe03d7e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.default.inc/function/field_default_extract_form_values/7.x", "instruction": "I need the code for `field_default_extract_form_values($entity_type, $entity, $field, $instance, $langcode, &$items, $form, &$form_state)` in Drupal 7 (modules/field/field.default.inc). It must do this: Extracts field values from submitted form values.", "context": "Parameters:\n- $entity_type: The type of $entity.\n- $entity: The entity for the operation.\n- $field: The field structure for the operation.\n- $instance: The instance structure for $field on $entity's bundle.\n- $langcode: The language associated to $items.\n- $items: The field values. This parameter is altered by reference to receive the incoming form values.\n- $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.\n- $form_state: The form state.\n\nFile: modules/field/field.default.inc", "response": "function field_default_extract_form_values($entity_type, $entity, $field, $instance, $langcode, &$items, $form, &$form_state) {\n $path = array_merge($form['#parents'], array($field['field_name'], $langcode));\n $key_exists = NULL;\n $values = drupal_array_get_nested_value($form_state['values'], $path, $key_exists);\n if ($key_exists) {\n // Remove the 'value' of the 'add more' button.\n unset($values['add_more']);\n $items = $values;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9415202c83", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_delete_form_submit/7.x", "instruction": "Implement `image_style_delete_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Submit handler to delete an image style.", "context": "File: modules/image/image.admin.inc", "response": "function image_style_delete_form_submit($form, &$form_state) {\n $style = $form_state['image_style'];\n\n image_style_delete($style, $form_state['values']['replacement']);\n drupal_set_message(t('Style %name was deleted.', array('%name' => $style['label'])));\n $form_state['redirect'] = 'admin/config/media/image-styles';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9415e2c80a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/flood_register_event/7.x", "instruction": "Implement `flood_register_event($name, $window = 3600, $identifier = NULL)` in PHP for Drupal 7. Required behavior: Registers an event for the current visitor to the flood control mechanism.", "context": "Parameters:\n- $name: The name of an event.\n- $window: Optional number of seconds before this event expires. Defaults to 3600 (1 hour). Typically uses the same value as the flood_is_allowed() $window parameter. Expired events are purged on cron run to prevent the flood table from growing indefinitely.\n- $identifier: Optional identifier (defaults to the current user's IP address).\n\nFile: includes/common.inc", "response": "function flood_register_event($name, $window = 3600, $identifier = NULL) {\n if (!isset($identifier)) {\n $identifier = ip_address();\n }\n db_insert('flood')\n ->fields(array(\n 'event' => $name,\n 'identifier' => $identifier,\n 'timestamp' => REQUEST_TIME,\n 'expiration' => REQUEST_TIME + $window,\n ))\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-941aec66e1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21tablesort.inc/function/tablesort_get_sort/7.x", "instruction": "Implement `tablesort_get_sort($headers)` in PHP for Drupal 7. Required behavior: Determines the current sort direction.", "context": "Parameters:\n- $headers: An array of column headers in the format described in theme_table().\n\nReturns: The current sort direction (\"asc\" or \"desc\").\n\nFile: includes/tablesort.inc", "response": "function tablesort_get_sort($headers) {\n if (isset($_GET['sort'])) {\n return (strtolower($_GET['sort']) == 'desc') ? 'desc' : 'asc';\n }\n // The user has not specified a sort. Use the default for the currently sorted\n // header if specified; otherwise use \"asc\".\n else {\n // Find out which header is currently being sorted.\n $ts = tablesort_get_order($headers);\n foreach ($headers as $header) {\n if (is_array($header) && isset($header['data']) && $header['data'] == $ts['name'] && isset($header['sort'])) {\n return $header['sort'];\n }\n }\n }\n return 'asc';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-942754fa25", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_entity_info/7.x", "instruction": "Implement `taxonomy_entity_info()` in PHP for Drupal 7. Required behavior: Implements hook_entity_info().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_entity_info() {\n $return = array(\n 'taxonomy_term' => array(\n 'label' => t('Taxonomy term'),\n 'controller class' => 'TaxonomyTermController',\n 'base table' => 'taxonomy_term_data',\n 'uri callback' => 'taxonomy_term_uri',\n 'fieldable' => TRUE,\n 'entity keys' => array(\n 'id' => 'tid',\n 'bundle' => 'vocabulary_machine_name',\n 'label' => 'name',\n ),\n 'bundle keys' => array(\n 'bundle' => 'machine_name',\n ),\n 'bundles' => array(),\n 'view modes' => array(\n // @todo View mode for display as a field (when attached to nodes etc).\n 'full' => array(\n 'label' => t('Taxonomy term page'),\n 'custom settings' => FALSE,\n ),\n ),\n ),\n );\n foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) {\n $return['taxonomy_term']['bundles'][$machine_name] = array(\n 'label' => $vocabulary->name,\n 'admin' => array(\n 'path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name',\n 'real path' => 'admin/structure/taxonomy/' . $machine_name,\n 'bundle argument' => 3,\n 'access arguments' => array('administer taxonomy'),\n ),\n );\n }\n $return['taxonomy_vocabulary'] = array(\n 'label' => t('Taxonomy vocabulary'),\n 'controller class' => 'TaxonomyVocabularyController',\n 'base table' => 'taxonomy_vocabulary',\n 'entity keys' => array(\n 'id' => 'vid',\n 'label' => 'name',\n ),\n 'fieldable' => FALSE,\n );\n\n return $return;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-942cf03da7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_valid_http_host/7.x", "instruction": "I need the code for `drupal_valid_http_host($host)` in Drupal 7 (includes/bootstrap.inc). It must do this: Validates that a hostname (for example $_SERVER['HTTP_HOST']) is safe.", "context": "Returns (bool): TRUE if it only contains valid characters, FALSE otherwise.\n\nFile: includes/bootstrap.inc", "response": "function drupal_valid_http_host($host) {\n // Limit the length of the host name to 1000 bytes to prevent DoS attacks with\n // long host names.\n return strlen($host) <= 1000\n // Limit the number of subdomains and port separators to prevent DoS attacks\n // in conf_path().\n && substr_count($host, '.') <= 100\n && substr_count($host, ':') <= 100\n && preg_match('/^\\[?(?:[a-zA-Z0-9-:\\]_]+\\.?)+$/', $host);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-943ae2d8d1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/_theme_build_registry/7.x", "instruction": "I need the code for `_theme_build_registry($theme, $base_theme, $theme_engine)` in Drupal 7 (includes/theme.inc). It must do this: Builds the theme registry cache.", "context": "Parameters:\n- $theme: The loaded $theme object as returned by list_themes().\n- $base_theme: An array of loaded $theme objects representing the ancestor themes in oldest first order.\n- $theme_engine: The name of the theme engine.\n\nFile: includes/theme.inc", "response": "function _theme_build_registry($theme, $base_theme, $theme_engine) {\n $cache = array();\n // First, process the theme hooks advertised by modules. This will\n // serve as the basic registry. Since the list of enabled modules is the same\n // regardless of the theme used, this is cached in its own entry to save\n // building it for every theme.\n if ($cached = cache_get('theme_registry:build:modules')) {\n $cache = $cached->data;\n }\n else {\n foreach (module_implements('theme') as $module) {\n _theme_process_registry($cache, $module, 'module', $module, drupal_get_path('module', $module));\n }\n // Only cache this registry if all modules are loaded.\n if (module_load_all(NULL)) {\n cache_set('theme_registry:build:modules', $cache);\n }\n }\n\n // Process each base theme.\n foreach ($base_theme as $base) {\n // If the base theme uses a theme engine, process its hooks.\n $base_path = dirname($base->filename);\n if ($theme_engine) {\n _theme_process_registry($cache, $theme_engine, 'base_theme_engine', $base->name, $base_path);\n }\n _theme_process_registry($cache, $base->name, 'base_theme', $base->name, $base_path);\n }\n\n // And then the same thing, but for the theme.\n if ($theme_engine) {\n _theme_process_registry($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename));\n }\n\n // Finally, hooks provided by the theme itself.\n _theme_process_registry($cache, $theme->name, 'theme', $theme->name, dirname($theme->filename));\n\n // Let modules alter the registry.\n drupal_alter('theme_registry', $cache);\n\n // Optimize the registry to not have empty arrays for functions.\n foreach ($cache as $hook => $info) {\n foreach (array('preprocess functions', 'process functions') as $phase) {\n if (empty($info[$phase])) {\n unset($cache[$hook][$phase]);\n }\n }\n }\n return $cache;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-946de8ab23", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_install/7.x", "instruction": "Implement `user_install()` in PHP for Drupal 7. Required behavior: Implements hook_install().", "context": "File: modules/user/user.install", "response": "function user_install() {\n // Insert a row for the anonymous user.\n db_insert('users')\n ->fields(array(\n 'uid' => 0,\n 'name' => '',\n 'mail' => '',\n ))\n ->execute();\n\n // We need some placeholders here as name and mail are uniques and data is\n // presumed to be a serialized array. This will be changed by the settings\n // form in the installer.\n db_insert('users')\n ->fields(array(\n 'uid' => 1,\n 'name' => 'placeholder-for-uid-1',\n 'mail' => 'placeholder-for-uid-1',\n 'created' => REQUEST_TIME,\n 'changed' => REQUEST_TIME,\n 'status' => 1,\n 'data' => NULL,\n ))\n ->execute();\n\n // Built-in roles.\n $rid_anonymous = db_insert('role')\n ->fields(array('name' => 'anonymous user', 'weight' => 0))\n ->execute();\n $rid_authenticated = db_insert('role')\n ->fields(array('name' => 'authenticated user', 'weight' => 1))\n ->execute();\n\n // Sanity check to ensure the anonymous and authenticated role IDs are the\n // same as the drupal defined constants. In certain situations, this will\n // not be true.\n if ($rid_anonymous != DRUPAL_ANONYMOUS_RID) {\n db_update('role')\n ->fields(array('rid' => DRUPAL_ANONYMOUS_RID))\n ->condition('rid', $rid_anonymous)\n ->execute();\n }\n if ($rid_authenticated != DRUPAL_AUTHENTICATED_RID) {\n db_update('role')\n ->fields(array('rid' => DRUPAL_AUTHENTICATED_RID))\n ->condition('rid', $rid_authenticated)\n ->execute();\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-9470a2f593", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_registry_files_alter/7.x", "instruction": "I need the code for `system_registry_files_alter(&$files, $modules)` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_registry_files_alter", "context": "File: modules/system/system.module", "response": "function system_registry_files_alter(&$files, $modules) {\n // Database drivers that use DatabaseStatementPrefetch must include this file.\n unset($files['includes/database/prefetch.inc']);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-947b7e1fdd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_delete/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_node_delete($node)` (modules/node/node.api.php): Respond to node deletion.", "context": "This hook is invoked from node_delete_multiple() after the type-specific hook_delete() has been invoked, but before hook_entity_delete and field_attach_delete() are called, and before the node is removed from the node table in the database.\n\nParameters:\n- $node: The node that is being deleted.\n\nFile: modules/node/node.api.php", "response": "function hook_node_delete($node) {\n db_delete('mytable')\n ->condition('nid', $node->nid)\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-9489b03906", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21actions.inc/function/actions_delete/7.x", "instruction": "Implement `actions_delete($aid)` in PHP for Drupal 7. Required behavior: Deletes a single action from the database.", "context": "Parameters:\n- $aid: The ID of the action to delete.\n\nFile: includes/actions.inc", "response": "function actions_delete($aid) {\n db_delete('actions')\n ->condition('aid', $aid)\n ->execute();\n module_invoke_all('actions_delete', $aid);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-94a24e199b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_image/7.x", "instruction": "Implement `rdf_preprocess_image(&$variables)` in PHP for Drupal 7. Required behavior: Implements MODULE_preprocess_HOOK().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_preprocess_image(&$variables) {\n // Adds the RDF type for image. We cannot use the usual entity-based mapping\n // to get 'foaf:Image' because image does not have its own entity type or\n // bundle.\n $variables['attributes']['typeof'] = array('foaf:Image');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-94bb192bff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21password.inc/function/user_check_password/7.x", "instruction": "Implement `user_check_password($password, $account)` in PHP for Drupal 7. Required behavior: Check whether a plain text password matches a stored hashed password.", "context": "Alternative implementations of this function may use other data in the $account object, for example the uid to look up the hash in a custom table or remote database.\n\nParameters:\n- $password: A plain-text password\n- $account: A user object with at least the fields from the {users} table.\n\nReturns: TRUE or FALSE.\n\nFile: includes/password.inc", "response": "function user_check_password($password, $account) {\n if (substr($account->pass, 0, 2) == 'U$') {\n // This may be an updated password from user_update_7000(). Such hashes\n // have 'U' added as the first character and need an extra md5().\n $stored_hash = substr($account->pass, 1);\n $password = md5($password);\n }\n else {\n $stored_hash = $account->pass;\n }\n\n $type = substr($stored_hash, 0, 3);\n switch ($type) {\n case '$S$':\n // A normal Drupal 7 password using sha512.\n $hash = _password_crypt('sha512', $password, $stored_hash);\n break;\n case '$H$':\n // phpBB3 uses \"$H$\" for the same thing as \"$P$\".\n case '$P$':\n // A phpass password generated using md5. This is an\n // imported password or from an earlier Drupal version.\n $hash = _password_crypt('md5', $password, $stored_hash);\n break;\n default:\n return FALSE;\n }\n return ($hash && $stored_hash == $hash);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-94c3459748", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_table_pre_render/7.x", "instruction": "I need the code for `field_ui_table_pre_render($elements)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Pre-render callback for field_ui_table elements.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_table_pre_render($elements) {\n $js_settings = array();\n\n // For each region, build the tree structure from the weight and parenting\n // data contained in the flat form structure, to determine row order and\n // indentation.\n $regions = $elements['#regions'];\n $tree = array('' => array('name' => '', 'children' => array()));\n $trees = array_fill_keys(array_keys($regions), $tree);\n\n $parents = array();\n $list = drupal_map_assoc(element_children($elements));\n\n // Iterate on rows until we can build a known tree path for all of them.\n while ($list) {\n foreach ($list as $name) {\n $row = &$elements[$name];\n $parent = $row['parent_wrapper']['parent']['#value'];\n // Proceed if parent is known.\n if (empty($parent) || isset($parents[$parent])) {\n // Grab parent, and remove the row from the next iteration.\n $parents[$name] = $parent ? array_merge($parents[$parent], array($parent)) : array();\n unset($list[$name]);\n\n // Determine the region for the row.\n $function = $row['#region_callback'];\n $region_name = $function($row);\n\n // Add the element in the tree.\n $target = &$trees[$region_name][''];\n foreach ($parents[$name] as $key) {\n $target = &$target['children'][$key];\n }\n $target['children'][$name] = array('name' => $name, 'weight' => $row['weight']['#value']);\n\n // Add tabledrag indentation to the first row cell.\n if ($depth = count($parents[$name])) {\n $children = element_children($row);\n $cell = current($children);\n $row[$cell]['#prefix'] = theme('indentation', array('size' => $depth)) . (isset($row[$cell]['#prefix']) ? $row[$cell]['#prefix'] : '');\n }\n\n // Add row id and associate JS settings.\n $id = drupal_html_class($name);\n $row['#attributes']['id'] = $id;\n if (isset($row['#js_settings'])) {\n $row['#js_settings'] += array(\n 'rowHandler' => $row['#row_type'],\n 'name' => $name,\n 'region' => $region_name,\n );\n $js_settings[$id] = $row['#js_settings'];\n }\n }\n }\n }\n // Determine rendering order from the tree structure.\n foreach ($regions as $region_name => $region) {\n $elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], '_field_ui_reduce_order');\n }\n\n $elements['#attached']['js'][] = array(\n 'type' => 'setting',\n 'data' => array('fieldUIRowsData' => $js_settings),\n );\n\n return $elements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-94cab2f0f4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_admin_paths/7.x", "instruction": "I need the code for `taxonomy_admin_paths()` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_admin_paths().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_admin_paths() {\n $paths = array(\n 'taxonomy/term/*/edit' => TRUE,\n );\n return $paths;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-94ff1ac9f6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21batch.inc/function/batch_load/7.x", "instruction": "I need the code for `batch_load($id)` in Drupal 7 (includes/batch.inc). It must do this: Loads a batch from the database.", "context": "Parameters:\n- $id: The ID of the batch to load. When a progressive batch is being processed, the relevant ID is found in $_REQUEST['id'].\n\nReturns: An array representing the batch, or FALSE if no batch was found.\n\nFile: includes/batch.inc", "response": "function batch_load($id) {\n $batch = db_query(\"SELECT batch FROM {batch} WHERE bid = :bid AND token = :token\", array(\n ':bid' => $id,\n ':token' => drupal_get_token($id),\n ))->fetchField();\n if ($batch) {\n return unserialize($batch);\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9526e769a7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_vote/7.x", "instruction": "In Drupal 7, write the function `poll_vote($form, &$form_state)` (file modules/poll/poll.module) so that it does the following: Submit handler for processing a vote.", "context": "File: modules/poll/poll.module", "response": "function poll_vote($form, &$form_state) {\n $node = $form['#node'];\n $choice = $form_state['values']['choice'];\n\n global $user;\n db_insert('poll_vote')\n ->fields(array(\n 'nid' => $node->nid,\n 'chid' => $choice,\n 'uid' => $user->uid,\n 'hostname' => ip_address(),\n 'timestamp' => REQUEST_TIME,\n ))\n ->execute();\n\n // Add one to the votes.\n db_update('poll_choice')\n ->expression('chvotes', 'chvotes + 1')\n ->condition('chid', $choice)\n ->execute();\n\n cache_clear_all();\n\n if (!$user->uid) {\n // The vote is recorded so the user gets the result view instead of the\n // voting form when viewing the poll. Saving a value in $_SESSION has the\n // convenient side effect of preventing the user from hitting the page\n // cache. When anonymous voting is allowed, the page cache should only\n // contain the voting form, not the results.\n $_SESSION['poll_vote'][$node->nid] = $choice;\n }\n\n drupal_set_message(t('Your vote was recorded.'));\n\n // Return the user to whatever page they voted from.\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9561e67a57", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21mail.inc/function/_drupal_wrap_mail_line/7.x", "instruction": "In Drupal 7, write the function `_drupal_wrap_mail_line(&$line, $key, $values)` (file includes/mail.inc) so that it does the following: Wraps words on a single line.", "context": "Callback for array_walk() within drupal_wrap_mail().\n\nFile: includes/mail.inc", "response": "function _drupal_wrap_mail_line(&$line, $key, $values) {\n // Use soft-breaks only for purely quoted or unindented text.\n $line = wordwrap($line, 77 - $values['length'], $values['soft'] ? \" \\n\" : \"\\n\");\n // Break really long words at the maximum width allowed.\n $line = wordwrap($line, 996 - $values['length'], $values['soft'] ? \" \\n\" : \"\\n\", TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-95742b2099", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_link_map_translate/7.x", "instruction": "Implement `_menu_link_map_translate(&$map, $to_arg_functions)` in PHP for Drupal 7. Required behavior: Translates the path elements in the map using any to_arg helper function.", "context": "Parameters:\n- $map: An array of path arguments; for example, array('node', '5').\n- $to_arg_functions: An array of helper functions; for example, array(2 => 'menu_tail_to_arg').\n\nFile: includes/menu.inc", "response": "function _menu_link_map_translate(&$map, $to_arg_functions) {\n $to_arg_functions = unserialize($to_arg_functions);\n foreach ($to_arg_functions as $index => $function) {\n // Translate place-holders into real values.\n $arg = $function(!empty($map[$index]) ? $map[$index] : '', $map, $index);\n if (!empty($map[$index]) || isset($arg)) {\n $map[$index] = $arg;\n }\n else {\n unset($map[$index]);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9587ccba12", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_field/7.x", "instruction": "I need the code for `field_info_field($field_name)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns data about an individual field, given a field name.", "context": "Parameters:\n- $field_name: The name of the field to retrieve. $field_name can only refer to a non-deleted, active field. For deleted fields, use field_info_field_by_id(). To retrieve information about inactive fields, use field_read_fields().\n\nReturns: 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 keyed by entity type. NULL if the field was not found.\n\nFile: modules/field/field.info.inc", "response": "function field_info_field($field_name) {\n $cache = _field_info_field_cache();\n return $cache->getField($field_name);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9589427dd0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_search_validate/7.x", "instruction": "In Drupal 7, write the function `node_search_validate($form, &$form_state)` (file modules/node/node.module) so that it does the following: Form validation handler for node_form_alter().", "context": "File: modules/node/node.module", "response": "function node_search_validate($form, &$form_state) {\n // Initialize using any existing basic search keywords.\n $keys = $form_state['values']['processed_keys'];\n\n // Insert extra restrictions into the search keywords string.\n if (isset($form_state['values']['type']) && is_array($form_state['values']['type'])) {\n // Retrieve selected types - Form API sets the value of unselected\n // checkboxes to 0.\n $form_state['values']['type'] = array_filter($form_state['values']['type']);\n if (count($form_state['values']['type'])) {\n $keys = search_expression_insert($keys, 'type', implode(',', array_keys($form_state['values']['type'])));\n }\n }\n\n if (isset($form_state['values']['term']) && is_array($form_state['values']['term']) && count($form_state['values']['term'])) {\n $keys = search_expression_insert($keys, 'term', implode(',', $form_state['values']['term']));\n }\n if (isset($form_state['values']['language']) && is_array($form_state['values']['language'])) {\n $languages = array_filter($form_state['values']['language']);\n if (count($languages)) {\n $keys = search_expression_insert($keys, 'language', implode(',', $languages));\n }\n }\n if ($form_state['values']['or'] != '') {\n if (preg_match_all('/ (\"[^\"]+\"|[^\" ]+)/i', ' ' . $form_state['values']['or'], $matches)) {\n $keys .= ' ' . implode(' OR ', $matches[1]);\n }\n }\n if ($form_state['values']['negative'] != '') {\n if (preg_match_all('/ (\"[^\"]+\"|[^\" ]+)/i', ' ' . $form_state['values']['negative'], $matches)) {\n $keys .= ' -' . implode(' -', $matches[1]);\n }\n }\n if ($form_state['values']['phrase'] != '') {\n $keys .= ' \"' . str_replace('\"', ' ', $form_state['values']['phrase']) . '\"';\n }\n if (!empty($keys)) {\n form_set_value($form['basic']['processed_keys'], trim($keys), $form_state);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9594a19a80", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/_file_generic_settings_file_directory_validate/7.x", "instruction": "I need the code for `_file_generic_settings_file_directory_validate($element, &$form_state)` in Drupal 7 (modules/file/file.field.inc). It must do this: Element validate callback for the file destination field.", "context": "Remove slashes from the beginning and end of the destination value and ensure that the file directory path is not included at the beginning of the value.\n\nFile: modules/file/file.field.inc", "response": "function _file_generic_settings_file_directory_validate($element, &$form_state) {\n // Strip slashes from the beginning and end of $widget['file_directory'].\n $value = trim($element['#value'], '\\\\/');\n form_set_value($element, $value, $form_state);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-95a9879d2a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_update_7003/7.x", "instruction": "In Drupal 7, write the function `locale_update_7003()` (file modules/locale/locale.install) so that it does the following: Update \"language_count\" variable.", "context": "File: modules/locale/locale.install", "response": "function locale_update_7003() {\n $languages = language_list('enabled');\n variable_set('language_count', count($languages[1]));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-95aca1c10a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_clean_temporary_directories/7.x", "instruction": "Implement `simpletest_clean_temporary_directories()` in PHP for Drupal 7. Required behavior: Find all leftover temporary directories and remove them.", "context": "File: modules/simpletest/simpletest.module", "response": "function simpletest_clean_temporary_directories() {\n $count = 0;\n if (is_dir('public://simpletest')) {\n $files = scandir('public://simpletest');\n foreach ($files as $file) {\n $path = 'public://simpletest/' . $file;\n // Ensure that cache directories are cleaned as well.\n if (is_dir($path) && (is_numeric($file) || strpos($file, '1c') === 0)) {\n file_unmanaged_delete_recursive($path);\n $count++;\n }\n }\n }\n\n if ($count > 0) {\n drupal_set_message(format_plural($count, 'Removed 1 temporary directory.', 'Removed @count temporary directories.'));\n }\n else {\n drupal_set_message(t('No temporary directories to remove.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-95aee17cd9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.pages.inc/function/blog_page_last/7.x", "instruction": "I need the code for `blog_page_last()` in Drupal 7 (modules/blog/blog.pages.inc). It must do this: Menu callback; displays a Drupal page containing recent blog entries of all users.", "context": "File: modules/blog/blog.pages.inc", "response": "function blog_page_last() {\n global $user;\n $build = array();\n\n $query = db_select('node', 'n')->extend('PagerDefault');\n $nids = $query\n ->fields('n', array('nid', 'sticky', 'created'))\n ->condition('type', 'blog')\n ->condition('status', 1)\n ->orderBy('sticky', 'DESC')\n ->orderBy('created', 'DESC')\n ->limit(variable_get('default_nodes_main', 10))\n ->addTag('node_access')\n ->execute()\n ->fetchCol();\n\n if (!empty($nids)) {\n $nodes = node_load_multiple($nids);\n $build += node_view_multiple($nodes);\n $build['pager'] = array(\n '#theme' => 'pager',\n '#weight' => 5,\n );\n }\n else {\n drupal_set_message(t('No blog entries have been created.'));\n }\n drupal_add_feed('blog/feed', t('RSS - blogs'));\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-95bbdc23cd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_user_presave/7.x", "instruction": "In Drupal 7, write the function `contact_user_presave(&$edit, $account, $category)` (file modules/contact/contact.module) so that it does the following: Implements hook_user_presave().", "context": "File: modules/contact/contact.module", "response": "function contact_user_presave(&$edit, $account, $category) {\n if (isset($edit['contact'])) {\n // Set new value.\n $edit['data']['contact'] = $edit['contact'];\n }\n elseif (!isset($account->data['contact'])) {\n // Use default if none has been set.\n $edit['data']['contact'] = variable_get('contact_default_status', 1);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-95d151cfcc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_prepare_view/7.x", "instruction": "Implement `file_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items)` in PHP for Drupal 7. Required behavior: Implements hook_field_prepare_view().", "context": "File: modules/file/file.field.inc", "response": "function file_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {\n // Remove files specified to not be displayed.\n foreach ($entities as $id => $entity) {\n foreach ($items[$id] as $delta => $item) {\n if (!file_field_displayed($item, $field)) {\n unset($items[$id][$delta]);\n }\n }\n // Ensure consecutive deltas.\n $items[$id] = array_values($items[$id]);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-95d685bd2d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_check_access/7.x", "instruction": "Implement `_menu_check_access(&$item, $map)` in PHP for Drupal 7. Required behavior: Checks access to a menu item using the access callback.", "context": "Parameters:\n- $item: A menu router or menu link item\n- $map: An array of path arguments; for example, array('node', '5').\n\nReturns: $item['access'] becomes TRUE if the item is accessible, FALSE otherwise.\n\nFile: includes/menu.inc", "response": "function _menu_check_access(&$item, $map) {\n $item['access'] = FALSE;\n // Determine access callback, which will decide whether or not the current\n // user has access to this path.\n $callback = empty($item['access_callback']) ? 0 : trim($item['access_callback']);\n // Check for a TRUE or FALSE value.\n if (is_numeric($callback)) {\n $item['access'] = (bool) $callback;\n }\n else {\n $arguments = menu_unserialize($item['access_arguments'], $map);\n // As call_user_func_array is quite slow and user_access is a very common\n // callback, it is worth making a special case for it.\n if ($callback == 'user_access') {\n $item['access'] = (count($arguments) == 1) ? user_access($arguments[0]) : user_access($arguments[0], $arguments[1]);\n }\n elseif (function_exists($callback)) {\n $item['access'] = call_user_func_array($callback, $arguments);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9600f2842d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_block_view/7.x", "instruction": "Implement `menu_block_view($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_view().", "context": "File: modules/menu/menu.module", "response": "function menu_block_view($delta = '') {\n $menus = menu_get_menus(FALSE);\n $data['subject'] = check_plain($menus[$delta]);\n $data['content'] = menu_tree($delta);\n // Add contextual links for this block.\n if (!empty($data['content'])) {\n $data['content']['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($delta));\n }\n return $data;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-96214d84dd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.admin.inc/function/contact_category_edit_form_submit/7.x", "instruction": "Implement `contact_category_edit_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for contact_category_edit_form().", "context": "File: modules/contact/contact.admin.inc", "response": "function contact_category_edit_form_submit($form, &$form_state) {\n if ($form_state['values']['selected']) {\n // Unselect all other contact categories.\n db_update('contact')\n ->fields(array('selected' => '0'))\n ->execute();\n }\n\n if (empty($form_state['values']['cid'])) {\n drupal_write_record('contact', $form_state['values']);\n }\n else {\n drupal_write_record('contact', $form_state['values'], array('cid'));\n }\n\n drupal_set_message(t('Category %category has been saved.', array('%category' => $form_state['values']['category'])));\n watchdog('contact', 'Category %category has been saved.', array('%category' => $form_state['values']['category']), WATCHDOG_NOTICE, l(t('Edit'), 'admin/structure/contact/edit/' . $form_state['values']['cid']));\n $form_state['redirect'] = 'admin/structure/contact';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9656e46647", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7009/7.x", "instruction": "I need the code for `user_update_7009()` in Drupal 7 (modules/user/user.install). It must do this: Converts fields that store serialized variables from text to blob.", "context": "File: modules/user/user.install", "response": "function user_update_7009() {\n $spec = array(\n 'type' => 'blob',\n 'not null' => FALSE,\n 'size' => 'big',\n 'serialize' => TRUE,\n 'description' => 'A serialized array of name value pairs that are related to the user. Any form values posted during user edit are stored and are loaded into the $user object during user_load(). Use of this field is discouraged and it will likely disappear in a future version of Drupal.',\n );\n db_change_field('users', 'data', 'data', $spec);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9664ab90c3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_fetch_data/7.x", "instruction": "In Drupal 7, write the function `update_fetch_data()` (file modules/update/update.module) so that it does the following: Attempts to fetch update data after loading the necessary include file.", "context": "File: modules/update/update.module", "response": "function update_fetch_data() {\n module_load_include('inc', 'update', 'update.fetch');\n return _update_fetch_data();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9669ce03a6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7077/7.x", "instruction": "Implement `system_update_7077()` in PHP for Drupal 7. Required behavior: Revert {file_managed}.filename changed to a binary column.", "context": "File: modules/system/system.install", "response": "function system_update_7077() {\n db_change_field('file_managed', 'filename', 'filename', array(\n 'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-969102bad6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.api.php/function/hook_overlay_child_initialize/7.x", "instruction": "Give me the example code for `hook_overlay_child_initialize()` in Drupal 7. Hook description: Allow modules to act when an overlay child window is initialized.", "context": "The child window is initialized when a page is displayed from within the overlay, so modules can act here if they need to take action to work from within the confines of the overlay.\n\nFile: modules/overlay/overlay.api.php", "response": "function hook_overlay_child_initialize() {\n // Add our custom JavaScript.\n drupal_add_js(drupal_get_path('module', 'hook') . '/hook-overlay-child.js');\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-96aef0cfa1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.install/function/book_install/7.x", "instruction": "Implement `book_install()` in PHP for Drupal 7. Required behavior: Implements hook_install().", "context": "File: modules/book/book.install", "response": "function book_install() {\n // Add the node type.\n _book_install_type_create();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-96e924649e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/template_preprocess_book_node_export_html/7.x", "instruction": "Implement `template_preprocess_book_node_export_html(&$variables)` in PHP for Drupal 7. Required behavior: Processes variables for book-node-export-html.tpl.php.", "context": "Parameters:\n- $variables: An associative array containing the following keys: - node - children\n\nFile: modules/book/book.module", "response": "function template_preprocess_book_node_export_html(&$variables) {\n $variables['depth'] = $variables['node']->book['depth'];\n $variables['title'] = check_plain($variables['node']->title);\n $variables['content'] = $variables['node']->rendered;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-96f5f0cfee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_file_download/7.x", "instruction": "In Drupal 7, write the function `image_file_download($uri)` (file modules/image/image.module) so that it does the following: Implements hook_file_download().", "context": "Control the access to files underneath the styles directory.\n\nFile: modules/image/image.module", "response": "function image_file_download($uri) {\n $path = file_uri_target($uri);\n\n // Private file access for image style derivatives.\n if (strpos($path, 'styles/') === 0) {\n $args = explode('/', $path);\n // Discard the first part of the path (styles).\n array_shift($args);\n // Get the style name from the second part.\n $style_name = array_shift($args);\n // Remove the scheme from the path.\n array_shift($args);\n\n // Then the remaining parts are the path to the image.\n $original_uri = file_uri_scheme($uri) . '://' . implode('/', $args);\n\n // Check that the file exists and is an image.\n if ($info = image_get_info($uri)) {\n // Check the permissions of the original to grant access to this image.\n $headers = module_invoke_all('file_download', $original_uri);\n // Confirm there's at least one module granting access and none denying access.\n if (!empty($headers) && !in_array(-1, $headers)) {\n return array(\n // Send headers describing the image's size, and MIME-type...\n 'Content-Type' => $info['mime_type'],\n 'Content-Length' => $info['file_size'],\n // By not explicitly setting them here, this uses normal Drupal\n // Expires, Cache-Control and ETag headers to prevent proxy or\n // browser caching of private images.\n );\n }\n }\n return -1;\n }\n\n // Private file access for the original files. Note that we only check access\n // for non-temporary images, since file.module will grant access for all\n // temporary files.\n $files = file_load_multiple(array(), array('uri' => $uri));\n if (count($files)) {\n $file = reset($files);\n if ($file->status) {\n return file_file_download($uri, 'image');\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-971037a2ed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/_file_field_get_description_from_element/7.x", "instruction": "In Drupal 7, write the function `_file_field_get_description_from_element($element)` (file modules/file/file.field.inc) so that it does the following: Retrieves the file description from a field field element.", "context": "This helper function is used by file_field_widget_process_multiple().\n\nParameters:\n- $element: The element being processed.\n\nReturns: A description of the file suitable for use in the administrative interface.\n\nFile: modules/file/file.field.inc", "response": "function _file_field_get_description_from_element($element) {\n // Use the actual file description, if it's available.\n if (!empty($element['#default_value']['description'])) {\n return $element['#default_value']['description'];\n }\n // Otherwise, fall back to the filename.\n if (!empty($element['#default_value']['filename'])) {\n return $element['#default_value']['filename'];\n }\n // This is probably a newly uploaded file; no description is available.\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9722fb9729", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_select_locale/7.x", "instruction": "I need the code for `install_select_locale(&$install_state)` in Drupal 7 (includes/install.core.inc). It must do this: Installation task; select which locale to use for the current profile.", "context": "Parameters:\n- $install_state: An array of information about the current installation state. The chosen locale will be added here, if it was not already selected previously, as will a list of all available locales.\n\nReturns: For interactive installations, a form or other page output allowing the locale to be selected or providing information about locale selection, if a locale has not been chosen. Otherwise, an exception is thrown if a locale cannot be chosen automatically.\n\nFile: includes/install.core.inc", "response": "function install_select_locale(&$install_state) {\n // Find all available locales.\n $profilename = $install_state['parameters']['profile'];\n $locales = install_find_locales($profilename);\n $install_state['locales'] += $locales;\n\n if (!empty($_POST['locale'])) {\n foreach ($locales as $locale) {\n if ($_POST['locale'] == $locale->langcode) {\n $install_state['parameters']['locale'] = $locale->langcode;\n return;\n }\n }\n }\n\n if (empty($install_state['parameters']['locale'])) {\n // If only the built-in (English) language is available, and we are\n // performing an interactive installation, inform the user that the\n // installer can be localized. Otherwise we assume the user knows what he\n // is doing.\n if (count($locales) == 1) {\n if ($install_state['interactive']) {\n drupal_set_title(st('Choose language'));\n if (!empty($install_state['parameters']['localize'])) {\n $output = '

            Follow these steps to translate Drupal into your language:

            ';\n $output .= '
              ';\n $output .= '
            1. Download a translation from the translation server.
            2. ';\n $output .= '
            3. Place it into the following directory:\n
              \n/profiles/' . $profilename . '/translations/\n
            4. ';\n $output .= '
            ';\n $output .= '

            For more information on installing Drupal in different languages, visit the drupal.org handbook page.

            ';\n $output .= '

            How should the installation continue?

            ';\n $output .= '';\n }\n else {\n include_once DRUPAL_ROOT . '/includes/form.inc';\n $elements = drupal_get_form('install_select_locale_form', $locales, $profilename);\n $output = drupal_render($elements);\n }\n return $output;\n }\n // One language, but not an interactive installation. Assume the user\n // knows what he is doing.\n $locale = current($locales);\n $install_state['parameters']['locale'] = $locale->name;\n return;\n }\n else {\n // Allow profile to pre-select the language, skipping the selection.\n $function = $profilename . '_profile_details';\n if (function_exists($function)) {\n $details = $function();\n if (isset($details['language'])) {\n foreach ($locales as $locale) {\n if ($details['language'] == $locale->name) {\n $install_state['parameters']['locale'] = $locale->name;\n return;\n }\n }\n }\n }\n\n // We still don't have a locale, so display a form for selecting one.\n // Only do this in the case of interactive installations, since this is\n // not a real form with submit handlers (the database isn't even set up\n // yet), rather just a convenience method for setting parameters in the\n // URL.\n if ($install_state['interactive']) {\n drupal_set_title(st('Choose language'));\n include_once DRUPAL_ROOT . '/includes/form.inc';\n $elements = drupal_get_form('install_select_locale_form', $locales, $profilename);\n return drupal_render($elements);\n }\n else {\n throw new Exception(st('Sorry, you must select a language to continue the installation.'));\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-972450bb87", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7062/7.x", "instruction": "I need the code for `system_update_7062()` in Drupal 7 (modules/system/system.install). It must do this: Replace 'system_list' index with 'bootstrap' index on {system}.", "context": "File: modules/system/system.install", "response": "function system_update_7062() {\n db_drop_index('system', 'bootstrap');\n db_drop_index('system', 'system_list');\n db_add_index('system', 'system_list', array('status', 'bootstrap', 'type', 'weight', 'name'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-972d881e77", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_widget_process_multiple/7.x", "instruction": "Implement `file_field_widget_process_multiple($element, &$form_state, $form)` in PHP for Drupal 7. Required behavior: An element #process callback for a group of file_generic fields.", "context": "Adds the weight field to each row so it can be ordered and adds a new Ajax wrapper around the entire group so it can be replaced all at once.\n\nFile: modules/file/file.field.inc", "response": "function file_field_widget_process_multiple($element, &$form_state, $form) {\n $element_children = element_children($element, TRUE);\n $count = count($element_children);\n\n foreach ($element_children as $delta => $key) {\n if ($key != $element['#file_upload_delta']) {\n $description = _file_field_get_description_from_element($element[$key]);\n $element[$key]['_weight'] = array(\n '#type' => 'weight',\n '#title' => $description ? t('Weight for @title', array('@title' => $description)) : t('Weight for new file'),\n '#title_display' => 'invisible',\n '#delta' => $count,\n '#default_value' => $delta,\n );\n }\n else {\n // The title needs to be assigned to the upload field so that validation\n // errors include the correct widget label.\n $element[$key]['#title'] = $element['#title'];\n $element[$key]['_weight'] = array(\n '#type' => 'hidden',\n '#default_value' => $delta,\n );\n }\n }\n\n // Add a new wrapper around all the elements for Ajax replacement.\n $element['#prefix'] = '
            ';\n $element['#suffix'] = '
            ';\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-972f419bbc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_build_form/7.x", "instruction": "Implement `drupal_build_form($form_id, &$form_state)` in PHP for Drupal 7. Required behavior: Builds and process a form based on a form id.", "context": "The form may also be retrieved from the cache if the form was built in a previous page-load. The form is then passed on for processing, validation and submission if there is proper input.\n\nParameters:\n- $form_id: The unique string identifying the desired form. If a function with that name exists, it is called to build the form array. Modules that need to generate the same form (or very similar forms) using different $form_ids can implement hook_forms(), which maps different $form_id values to the proper form constructor function. Examples may be found in node_forms(), and search_forms().\n- $form_state: An array which stores information about the form. This is passed as a reference so that the caller can use it to examine what in the form changed when the form submission process is complete. Furthermore, it may be used to store information related to the processed data in the form, which will persist across page requests when the 'cache' or 'rebuild' flag is set. The following parameters may be set in $form_state to affect how the form is rendered: - build_info: Internal. An associative array of information stored by Form API that is necessary to build and rebuild the form from cache when the original context may no longer be available: - args: A list of arguments to pass to the form constructor. - files: An optional array defining include files that need to be loaded for building the form. Each array entry may be the path to a file or another array containing values for the parameters 'type', 'module' and 'name' as needed by module_load_include(). The files listed here are automatically loaded by form_get_cache(). By default the current menu router item's 'file' definition is added, if any. Use form_load_include() to add include files from a form constructor. - form_id: Identification of the primary form being constructed and processed. - base_form_id: Identification for a base form, as declared in a hook_forms() implementation. - immutable: If this flag is set to TRUE, a new form build id is generated when the form is loaded from the cache. If it is subsequently saved to the cache again, it will have another cache id and therefore the original form and form-state will remain unaltered. This is important when page caching is enabled in order to prevent form state from leaking between anonymous users. - rebuild_info: Internal. Similar to 'build_info', but pertaining to drupal_rebuild_form(). - rebuild: Normally, after the entire form processing is completed and submit handlers have run, a form is considered to be done and drupal_redirect_form() will redirect the user to a new page using a GET request (so a browser refresh does not re-submit the form). However, if 'rebuild' has been set to TRUE, then a new copy of the form is immediately built and sent to the browser, instead of a redirect. This is used for multi-step forms, such as wizards and confirmation forms. Normally, $form_state['rebuild'] is set by a submit handler, since it is usually logic within a submit handler that determines whether a form is done or requires another step. However, a validation handler may already set $form_state['rebuild'] to cause the form processing to bypass submit handlers and rebuild the form instead, even if there are no validation errors. - redirect: Used to redirect the form on submission. It may either be a string containing the destination URL, or an array of arguments compatible with drupal_goto(). See drupal_redirect_form() for complete information. - no_redirect: If set to TRUE the form will NOT perform a drupal_goto(), even if 'redirect' is set. - method: The HTTP form method to use for finding the input for this form. May be 'post' or 'get'. Defaults to 'post'. Note that 'get' method forms do not use form ids so are always considered to be submitted, which can have unexpected effects. The 'get' method should only be used on forms that do not change data, as that is exclusively the domain of 'post.' - cache: If set to TRUE the original, unprocessed form structure will be cached, which allows the entire form to be rebuilt from cache. A typical form workflow involves two page requests; first, a form is built and rendered for the user to fill in. Then, the user fills the form in and submits it, triggering a second page request in which the form must be built and processed. By default, $form and $form_state are built from scratch during each of these page requests. Often, it is necessary or desired to persist the $form and $form_state variables from the initial page request to the one that processes the submission. 'cache' can be set to TRUE to do this. A prominent example is an Ajax-enabled form, in which ajax_process_form() enables form caching for all forms that include an element with the #ajax property. (The Ajax handler has no way to build the form itself, so must rely on the cached version.) Note that the persistence of $form and $form_state happens automatically for (multi-step) forms having the 'rebuild' flag set, regardless of the value for 'cache'. - no_cache: If set to TRUE the form will NOT be cached, even if 'cache' is set. - values: An associative array of values submitted to the form. The validation functions and submit functions use this array for nearly all their decision making. (Note that #tree determines whether the values are a flat array or an array whose structure parallels the $form array. See @link forms_api_reference.html Form API reference @endlink for more information.) These are raw and unvalidated, so should not be used without a thorough understanding of security implications. In almost all cases, code should use the data in the 'values' array exclusively. The most common use of this key is for multi-step forms that need to clear some of the user input when setting 'rebuild'. The values correspond to $_POST or $_GET, depending on the 'method' chosen. - always_process: If TRUE and the method is GET, a form_id is not necessary. This should only be used on RESTful GET forms that do NOT write data, as this could lead to security issues. It is useful so that searches do not need to have a form_id in their query arguments to trigger the search. - must_validate: Ordinarily, a form is only validated once, but there are times when a form is resubmitted internally and should be validated again. Setting this to TRUE will force that to happen. This is most likely to occur during Ajax operations. - programmed: If TRUE, the form was submitted programmatically, usually invoked via drupal_form_submit(). Defaults to FALSE. - programmed_bypass_access_check: If TRUE, programmatic form submissions are processed without taking #access into account. Set this to FALSE when submitting a form programmatically with values that may have been input by the user executing the current request; this will cause #access to be respected as it would on a normal form submission. Defaults to TRUE. - process_input: Boolean flag. TRUE signifies correct form submission. This is always TRUE for programmed forms coming from drupal_form_submit() (see 'programmed' key), or if the form_id coming from the $_POST data is set and matches the current form_id. - submitted: If TRUE, the form has been submitted. Defaults to FALSE. - executed: If TRUE, the form was submitted and has been processed and executed. Defaults to FALSE. - triggering_element: (read-only) The form element that triggered submission. This is the same as the deprecated $form_state['clicked_button']. It is the element that caused submission, which may or may not be a button (in the case of Ajax forms). This key is often used to distinguish between various buttons in a submit handler, and is also used in Ajax handlers. - clicked_button: Deprecated. Use triggering_element instead. - has_file_element: Internal. If TRUE, there is a file element and Form API will set the appropriate 'enctype' HTML attribute on the form. - groups: Internal. An array containing references to fieldsets to render them within vertical tabs. - storage: $form_state['storage'] is not a special key, and no specific support is provided for it in the Form API. By tradition it was the location where application-specific data was stored for communication between the submit, validation, and form builder functions, especially in a multi-step-style form. Form implementations may use any key(s) within $form_state (other than the keys listed here and other reserved ones used by Form API internals) for this kind of storage. The recommended way to ensure that the chosen key doesn't conflict with ones used by the Form API or other modules is to use the module name as the key name or a prefix for the key name. For example, the Node module uses $form_state['node'] in node editing forms to store information about the node being edited, and this information stays available across successive clicks of the \"Preview\" button as well as when the \"Save\" button is finally clicked. - buttons: A list containing copies of all submit and button elements in the form. - complete form: A reference to the $form variable containing the complete form structure. #process, #after_build, #element_validate, and other handlers being invoked on a form element may use this reference to access other information in the form the element is contained in. - temporary: An array holding temporary data accessible during the current page request only. All $form_state properties that are not reserved keys (see form_state_keys_no_cache()) persist throughout a multistep form sequence. Form API provides this key for modules to communicate information across form-related functions during a single page request. It may be used to temporarily save data that does not need to or should not be cached during the whole form workflow; e.g., data that needs to be accessed during the current form build process only. There is no use-case for this functionality in Drupal core. - wrapper_callback: Modules that wish to pre-populate certain forms with common elements, such as back/next/save buttons in multi-step form wizards, may define a form builder function name that returns a form structure, which is passed on to the actual form builder function. Such implementations may either define the 'wrapper_callback' via hook_forms() or have to invoke drupal_build_form() (instead of drupal_get_form()) on their own in a custom menu callback to prepare $form_state accordingly. Information on how certain $form_state properties control redirection behavior after form submission may be found in drupal_redirect_form().\n\nReturns: The rendered form. This function may also perform a redirect and hence may not return at all, depending upon the $form_state flags that were set.\n\nFile: includes/form.inc", "response": "function drupal_build_form($form_id, &$form_state) {\n // Ensure some defaults; if already set they will not be overridden.\n $form_state += form_state_defaults();\n\n if (!isset($form_state['input'])) {\n $form_state['input'] = $form_state['method'] == 'get' ? $_GET : $_POST;\n }\n\n if (isset($_SESSION['batch_form_state'])) {\n // We've been redirected here after a batch processing. The form has\n // already been processed, but needs to be rebuilt. See _batch_finished().\n $form_state = $_SESSION['batch_form_state'];\n unset($_SESSION['batch_form_state']);\n return drupal_rebuild_form($form_id, $form_state);\n }\n\n // If the incoming input contains a form_build_id, we'll check the cache for a\n // copy of the form in question. If it's there, we don't have to rebuild the\n // form to proceed. In addition, if there is stored form_state data from a\n // previous step, we'll retrieve it so it can be passed on to the form\n // processing code.\n $check_cache = isset($form_state['input']['form_id']) && $form_state['input']['form_id'] == $form_id && !empty($form_state['input']['form_build_id']);\n if ($check_cache) {\n $form = form_get_cache($form_state['input']['form_build_id'], $form_state);\n }\n\n // If the previous bit of code didn't result in a populated $form object, we\n // are hitting the form for the first time and we need to build it from\n // scratch.\n if (!isset($form)) {\n // If we attempted to serve the form from cache, uncacheable $form_state\n // keys need to be removed after retrieving and preparing the form, except\n // any that were already set prior to retrieving the form.\n if ($check_cache) {\n $form_state_before_retrieval = $form_state;\n }\n\n $form = drupal_retrieve_form($form_id, $form_state);\n drupal_prepare_form($form_id, $form, $form_state);\n\n // form_set_cache() removes uncacheable $form_state keys defined in\n // form_state_keys_no_cache() in order for multi-step forms to work\n // properly. This means that form processing logic for single-step forms\n // using $form_state['cache'] may depend on data stored in those keys\n // during drupal_retrieve_form()/drupal_prepare_form(), but form\n // processing should not depend on whether the form is cached or not, so\n // $form_state is adjusted to match what it would be after a\n // form_set_cache()/form_get_cache() sequence. These exceptions are\n // allowed to survive here:\n // - always_process: Does not make sense in conjunction with form caching\n // in the first place, since passing form_build_id as a GET parameter is\n // not desired.\n // - temporary: Any assigned data is expected to survives within the same\n // page request.\n if ($check_cache) {\n $uncacheable_keys = array_flip(array_diff(form_state_keys_no_cache(), array('always_process', 'temporary')));\n $form_state = array_diff_key($form_state, $uncacheable_keys);\n $form_state += $form_state_before_retrieval;\n }\n }\n\n // Now that we have a constructed form, process it. This is where:\n // - Element #process functions get called to further refine $form.\n // - User input, if any, gets incorporated in the #value property of the\n // corresponding elements and into $form_state['values'].\n // - Validation and submission handlers are called.\n // - If this submission is part of a multistep workflow, the form is rebuilt\n // to contain the information of the next step.\n // - If necessary, the form and form state are cached or re-cached, so that\n // appropriate information persists to the next page request.\n // All of the handlers in the pipeline receive $form_state by reference and\n // can use it to know or update information about the state of the form.\n drupal_process_form($form_id, $form, $form_state);\n\n // If this was a successful submission of a single-step form or the last step\n // of a multi-step form, then drupal_process_form() issued a redirect to\n // another page, or back to this page, but as a new request. Therefore, if\n // we're here, it means that this is either a form being viewed initially\n // before any user input, or there was a validation error requiring the form\n // to be re-displayed, or we're in a multi-step workflow and need to display\n // the form's next step. In any case, we have what we need in $form, and can\n // return it for rendering.\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-973c70b1a2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_widget_upload_validators/7.x", "instruction": "I need the code for `file_field_widget_upload_validators($field, $instance)` in Drupal 7 (modules/file/file.field.inc). It must do this: Retrieves the upload validators for a file field.", "context": "Parameters:\n- $field: A field array.\n\nReturns: An array suitable for passing to file_save_upload() or the file field element's '#upload_validators' property.\n\nFile: modules/file/file.field.inc", "response": "function file_field_widget_upload_validators($field, $instance) {\n // Cap the upload size according to the PHP limit.\n $max_filesize = parse_size(file_upload_max_size());\n if (!empty($instance['settings']['max_filesize']) && parse_size($instance['settings']['max_filesize']) < $max_filesize) {\n $max_filesize = parse_size($instance['settings']['max_filesize']);\n }\n\n $validators = array();\n\n // There is always a file size limit due to the PHP server limit.\n $validators['file_validate_size'] = array($max_filesize);\n\n // Add the extension check if necessary.\n if (!empty($instance['settings']['file_extensions'])) {\n $validators['file_validate_extensions'] = array($instance['settings']['file_extensions']);\n }\n\n return $validators;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-976519b989", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_get_info/7.x", "instruction": "In Drupal 7, write the function `entity_get_info($entity_type = NULL)` (file includes/common.inc) so that it does the following: Get the entity info array of an entity type.", "context": "Parameters:\n- $entity_type: The entity type, e.g. node, for which the info shall be returned, or NULL to return an array with info about all types.\n\nFile: includes/common.inc", "response": "function entity_get_info($entity_type = NULL) {\n global $language;\n\n // Use the advanced drupal_static() pattern, since this is called very often.\n static $drupal_static_fast;\n if (!isset($drupal_static_fast)) {\n $drupal_static_fast['entity_info'] = &drupal_static(__FUNCTION__);\n }\n $entity_info = &$drupal_static_fast['entity_info'];\n\n // hook_entity_info() includes translated strings, so each language is cached\n // separately.\n $langcode = $language->language;\n\n if (empty($entity_info)) {\n if ($cache = cache_get(\"entity_info:$langcode\")) {\n $entity_info = $cache->data;\n }\n else {\n $entity_info = module_invoke_all('entity_info');\n // Merge in default values.\n foreach ($entity_info as $name => $data) {\n $entity_info[$name] += array(\n 'fieldable' => FALSE,\n 'controller class' => 'DrupalDefaultEntityController',\n 'static cache' => TRUE,\n 'field cache' => TRUE,\n 'load hook' => $name . '_load',\n 'bundles' => array(),\n 'view modes' => array(),\n 'entity keys' => array(),\n 'translation' => array(),\n );\n $entity_info[$name]['entity keys'] += array(\n 'revision' => '',\n 'bundle' => '',\n );\n foreach ($entity_info[$name]['view modes'] as $view_mode => $view_mode_info) {\n $entity_info[$name]['view modes'][$view_mode] += array(\n 'custom settings' => FALSE,\n );\n }\n // If no bundle key is provided, assume a single bundle, named after\n // the entity type.\n if (empty($entity_info[$name]['entity keys']['bundle']) && empty($entity_info[$name]['bundles'])) {\n $entity_info[$name]['bundles'] = array($name => array('label' => $entity_info[$name]['label']));\n }\n // Prepare entity schema fields SQL info for\n // DrupalEntityControllerInterface::buildQuery().\n if (isset($entity_info[$name]['base table'])) {\n $entity_info[$name]['base table field types'] = drupal_schema_field_types($entity_info[$name]['base table']);\n $entity_info[$name]['schema_fields_sql']['base table'] = drupal_schema_fields_sql($entity_info[$name]['base table']);\n if (isset($entity_info[$name]['revision table'])) {\n $entity_info[$name]['schema_fields_sql']['revision table'] = drupal_schema_fields_sql($entity_info[$name]['revision table']);\n }\n }\n }\n // Let other modules alter the entity info.\n drupal_alter('entity_info', $entity_info);\n cache_set(\"entity_info:$langcode\", $entity_info);\n }\n }\n\n if (empty($entity_type)) {\n return $entity_info;\n }\n elseif (isset($entity_info[$entity_type])) {\n return $entity_info[$entity_type];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-97697d7bd8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_view_mode_settings/7.x", "instruction": "Implement `field_view_mode_settings($entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Returns view mode settings in a given bundle.", "context": "Parameters:\n- $entity_type: The type of entity; e.g. 'node' or 'user'.\n- $bundle: The bundle name to return view mode settings for.\n\nReturns: An array keyed by view mode, with the following key/value pairs: - custom_settings: Boolean specifying whether the view mode uses a dedicated set of display options (TRUE), or the 'default' options (FALSE). Defaults to FALSE.\n\nFile: modules/field/field.module", "response": "function field_view_mode_settings($entity_type, $bundle) {\n $cache = &drupal_static(__FUNCTION__, array());\n\n if (!isset($cache[$entity_type][$bundle])) {\n $bundle_settings = field_bundle_settings($entity_type, $bundle);\n $settings = $bundle_settings['view_modes'];\n // Include view modes for which nothing has been stored yet, but whose\n // definition in hook_entity_info() specify they should use custom settings\n // by default.\n $entity_info = entity_get_info($entity_type);\n foreach ($entity_info['view modes'] as $view_mode => $view_mode_info) {\n if (!isset($settings[$view_mode]['custom_settings']) && $view_mode_info['custom settings']) {\n $settings[$view_mode]['custom_settings'] = TRUE;\n }\n }\n $cache[$entity_type][$bundle] = $settings;\n }\n\n return $cache[$entity_type][$bundle];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-9769891487", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_permission/7.x", "instruction": "In Drupal 7, write the function `contact_permission()` (file modules/contact/contact.module) so that it does the following: Implements hook_permission().", "context": "File: modules/contact/contact.module", "response": "function contact_permission() {\n return array(\n 'administer contact forms' => array(\n 'title' => t('Administer contact forms and contact form settings'),\n ),\n 'access site-wide contact form' => array(\n 'title' => t('Use the site-wide contact form'),\n ),\n 'access user contact forms' => array(\n 'title' => t(\"Use users' personal contact forms\"),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-976cd825c7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.install/function/field_sql_storage_update_7000/7.x", "instruction": "I need the code for `field_sql_storage_update_7000()` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.install). It must do this: Field SQL storage update version placeholder.", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.install", "response": "function field_sql_storage_update_7000() {\n // Some update helper functions (such as\n // _update_7000_field_sql_storage_write()) modify the database directly. They\n // can be used safely only if the database schema matches the field module\n // schema established for Drupal 7.0 (i.e. version 7000). This function exists\n // solely to set the schema version to 7000, so that update functions calling\n // those helpers can do so safely by declaring a dependency on\n // field_sql_storage_update_7000().\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-97726d756e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/_drupal_invalid_token_set_form_error/7.x", "instruction": "Implement `_drupal_invalid_token_set_form_error()` in PHP for Drupal 7. Required behavior: Helper function to call form_set_error() if there is a token error.", "context": "File: includes/form.inc", "response": "function _drupal_invalid_token_set_form_error() {\n // Setting this error will cause the form to fail validation.\n form_set_error('form_token', t('The form has become outdated. Press the back button, copy any unsaved work in the form, and then reload the page.'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-977330f104", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_prepare/7.x", "instruction": "Give me the example code for `hook_node_prepare($node)` in Drupal 7. Hook description: Act on a node object about to be shown on the add/edit form.", "context": "This hook is invoked from node_object_prepare() after the type-specific hook_prepare() is invoked.\n\nParameters:\n- $node: The node that is about to be shown on the add/edit form.\n\nFile: modules/node/node.api.php", "response": "function hook_node_prepare($node) {\n if (!isset($node->comment)) {\n $node->comment = variable_get(\"comment_$node->type\", COMMENT_NODE_OPEN);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-9791fea54d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_math_add/7.x", "instruction": "Implement `_openid_math_add($x, $y)` in PHP for Drupal 7. Required behavior: Calls the add function from the available math library for OpenID.", "context": "File: modules/openid/openid.inc", "response": "function _openid_math_add($x, $y) {\n $library = _openid_get_math_library();\n switch ($library) {\n case 'gmp':\n return gmp_strval(gmp_add($x, $y));\n case 'bcmath':\n return bcadd($x, $y);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-97b7ded938", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.install/function/search_update_7000/7.x", "instruction": "Implement `search_update_7000()` in PHP for Drupal 7. Required behavior: Replace unique keys in 'search_dataset' and 'search_index' by primary keys.", "context": "File: modules/search/search.install", "response": "function search_update_7000() {\n db_drop_unique_key('search_dataset', 'sid_type');\n $dataset_type_spec = array(\n 'type' => 'varchar',\n 'length' => 16,\n 'not null' => TRUE,\n 'description' => 'Type of item, e.g. node.',\n );\n db_change_field('search_dataset', 'type', 'type', $dataset_type_spec);\n db_add_primary_key('search_dataset', array('sid', 'type'));\n\n db_drop_index('search_index', 'word');\n db_drop_unique_key('search_index', 'word_sid_type');\n $index_type_spec = array(\n 'type' => 'varchar',\n 'length' => 16,\n 'not null' => TRUE,\n 'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',\n );\n db_change_field('search_index', 'type', 'type', $index_type_spec);\n db_add_primary_key('search_index', array('word', 'sid', 'type'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-97cc7434b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/theme_file_upload_help/7.x", "instruction": "I need the code for `theme_file_upload_help($variables)` in Drupal 7 (modules/file/file.field.inc). It must do this: Returns HTML for help text based on file upload validators.", "context": "Parameters:\n- $variables: An associative array containing: - description: The normal description for this field, specified by the user. - upload_validators: An array of upload validators as used in $element['#upload_validators'].\n\nFile: modules/file/file.field.inc", "response": "function theme_file_upload_help($variables) {\n $description = $variables['description'];\n $upload_validators = $variables['upload_validators'];\n\n $descriptions = array();\n\n if (!empty($description)) {\n $descriptions[] = $description;\n }\n if (isset($upload_validators['file_validate_size'])) {\n $descriptions[] = t('Files must be less than !size.', array('!size' => '' . format_size($upload_validators['file_validate_size'][0]) . ''));\n }\n if (isset($upload_validators['file_validate_extensions'])) {\n $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '' . check_plain($upload_validators['file_validate_extensions'][0]) . ''));\n }\n if (isset($upload_validators['file_validate_image_resolution'])) {\n $max = $upload_validators['file_validate_image_resolution'][0];\n $min = $upload_validators['file_validate_image_resolution'][1];\n if ($min && $max) {\n $descriptions[] = t('Images must be at least !min pixels. Images larger than !max pixels will be resized.', array('!min' => '' . $min . '', '!max' => '' . $max . ''));\n }\n elseif ($min) {\n $descriptions[] = t('Images must be at least !min pixels.', array('!min' => '' . $min . ''));\n }\n elseif ($max) {\n $descriptions[] = t('Images larger than !max pixels will be resized.', array('!max' => '' . $max . ''));\n }\n }\n\n return implode('
            ', $descriptions);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-98374f66f1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_load/7.x", "instruction": "In Drupal 7, write the function `entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE)` (file includes/common.inc) so that it does the following: Load entities from the database.", "context": "The entities are stored in a static memory cache, and will not require database access if loaded again during the same page request.\n\nThe actual loading is done through a class that has to implement the DrupalEntityControllerInterface interface. By default, DrupalDefaultEntityController is used. Entity types can specify that a different class should be used by setting the 'controller class' key in hook_entity_info(). These classes can either implement the DrupalEntityControllerInterface interface, or, most commonly, extend the DrupalDefaultEntityController class. See node_entity_info() and the NodeController in node.module as an example.\n\nParameters:\n- $entity_type: The entity type to load, e.g. node or user.\n- $ids: An array of entity IDs, or FALSE to load all entities.\n- $conditions: (deprecated) An associative array of conditions on the base table, where the keys are the database fields and the values are the values those fields must have. Instead, it is preferable to use EntityFieldQuery to retrieve a list of entity IDs loadable by this function.\n- $reset: Whether to reset the internal cache for the requested entity type.\n\nReturns: An array of entity objects indexed by their ids. When no results are found, an empty array is returned.\n\nFile: includes/common.inc", "response": "function entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) {\n if ($reset) {\n entity_get_controller($entity_type)->resetCache();\n }\n return entity_get_controller($entity_type)->load($ids, $conditions);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-983a54359f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_add/7.x", "instruction": "In Drupal 7, write the function `shortcut_link_add($form, &$form_state, $shortcut_set)` (file modules/shortcut/shortcut.admin.inc) so that it does the following: Form callback: builds the form for adding a new shortcut link.", "context": "Parameters:\n- $form: An associative array containing the structure of the form.\n- $form_state: An associative array containing the current state of the form.\n- $shortcut_set: An object representing the shortcut set to which the link will be added.\n\nReturns: An array representing the form definition.\n\nFile: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_link_add($form, &$form_state, $shortcut_set) {\n drupal_set_title(t('Add new shortcut'));\n $form['shortcut_set'] = array(\n '#type' => 'value',\n '#value' => $shortcut_set,\n );\n $form += _shortcut_link_form_elements();\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-983bf3a71f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_autop/7.x", "instruction": "I need the code for `_filter_autop($text)` in Drupal 7 (modules/filter/filter.module). It must do this: Implements callback_filter_process().", "context": "Converts line breaks into

            and
            in an intelligent fashion.\n\nBased on: http://photomatt.net/scripts/autop\n\nFile: modules/filter/filter.module", "response": "function _filter_autop($text) {\n // All block level tags\n $block = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|p|h[1-6]|hr)';\n\n // Split at opening and closing PRE, SCRIPT, STYLE, OBJECT, IFRAME tags\n // and comments. We don't apply any processing to the contents of these tags\n // to avoid messing up code. We look for matched pairs and allow basic\n // nesting. For example:\n // \"processed

             ignored  ignored 
            processed\"\n $chunks = preg_split('@(|]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);\n // Note: PHP ensures the array consists of alternating delimiters and literals\n // and begins and ends with a literal (inserting NULL as required).\n $ignore = FALSE;\n $ignoretag = '';\n $output = '';\n foreach ($chunks as $i => $chunk) {\n if ($i % 2) {\n $comment = (substr($chunk, 0, 4) == ' system_update_7001 ---> system_update_7002\n\nVisually, this indicates that system_update_7000() must run before system_update_7001(), which in turn must run before system_update_7002().\n\nThe function takes into account standard dependencies within each module, as shown above (i.e., the fact that each module's updates must run in numerical order), but also finds any cross-module dependencies that are defined by modules which implement hook_update_dependencies(), and builds them into the graph as well.\n\nParameters:\n- $update_functions: An organized array of update functions, in the format returned by update_get_update_function_list().\n\nReturns: A multidimensional array representing the dependency graph, suitable for passing in to drupal_depth_first_search(), but with extra information about each update function also included. Each array key contains the name of an update function, including all update functions from the provided list as well as any outside update functions which they directly depend on. Each value is an associative array containing the following keys: - 'edges': A representation of any other update functions that immediately depend on this one. See drupal_depth_first_search() for more details on the format. - 'module': The name of the module that this update function belongs to. - 'number': The number of this update function within that module.\n\nFile: includes/update.inc", "response": "function update_build_dependency_graph($update_functions) {\n // Initialize an array that will define a directed graph representing the\n // dependencies between update functions.\n $graph = array();\n\n // Go through each update function and build an initial list of dependencies.\n foreach ($update_functions as $module => $functions) {\n $previous_function = NULL;\n foreach ($functions as $number => $function) {\n // Add an edge to the directed graph representing the fact that each\n // update function in a given module must run after the update that\n // numerically precedes it.\n if ($previous_function) {\n $graph[$previous_function]['edges'][$function] = TRUE;\n }\n $previous_function = $function;\n\n // Define the module and update number associated with this function.\n $graph[$function]['module'] = $module;\n $graph[$function]['number'] = $number;\n }\n }\n\n // Now add any explicit update dependencies declared by modules.\n $update_dependencies = update_retrieve_dependencies();\n foreach ($graph as $function => $data) {\n if (!empty($update_dependencies[$data['module']][$data['number']])) {\n foreach ($update_dependencies[$data['module']][$data['number']] as $module => $number) {\n $dependency = $module . '_update_' . $number;\n $graph[$dependency]['edges'][$function] = TRUE;\n $graph[$dependency]['module'] = $module;\n $graph[$dependency]['number'] = $number;\n }\n }\n }\n\n return $graph;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9419a0135", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_filters/7.x", "instruction": "I need the code for `node_filters()` in Drupal 7 (modules/node/node.admin.inc). It must do this: List node administration filters that can be applied.", "context": "Returns: An associative array of filters.\n\nFile: modules/node/node.admin.inc", "response": "function node_filters() {\n // Regular filters\n $filters['status'] = array(\n 'title' => t('status'),\n 'options' => array(\n '[any]' => t('any'),\n 'status-1' => t('published'),\n 'status-0' => t('not published'),\n 'promote-1' => t('promoted'),\n 'promote-0' => t('not promoted'),\n 'sticky-1' => t('sticky'),\n 'sticky-0' => t('not sticky'),\n ),\n );\n // Include translation states if we have this module enabled\n if (module_exists('translation')) {\n $filters['status']['options'] += array(\n 'translate-0' => t('Up to date translation'),\n 'translate-1' => t('Outdated translation'),\n );\n }\n\n $filters['type'] = array(\n 'title' => t('type'),\n 'options' => array(\n '[any]' => t('any'),\n ) + node_type_get_names(),\n );\n\n // Language filter if there is a list of languages\n if ($languages = module_invoke('locale', 'language_list')) {\n $languages = array(LANGUAGE_NONE => t('Language neutral')) + $languages;\n $filters['language'] = array(\n 'title' => t('language'),\n 'options' => array(\n '[any]' => t('any'),\n ) + $languages,\n );\n }\n return $filters;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a950bee86a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/tracker_node_delete/7.x", "instruction": "In Drupal 7, write the function `tracker_node_delete($node, $arg = 0)` (file modules/tracker/tracker.module) so that it does the following: Implements hook_node_delete().", "context": "Deletes tracking information for a node.\n\nFile: modules/tracker/tracker.module", "response": "function tracker_node_delete($node, $arg = 0) {\n db_delete('tracker_node')\n ->condition('nid', $node->nid)\n ->execute();\n db_delete('tracker_user')\n ->condition('nid', $node->nid)\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-a95c981b2a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_file/7.x", "instruction": "Implement `theme_file($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a file upload form element.", "context": "For assistance with handling the uploaded file correctly, see the API provided by file.inc.\n\nParameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #title, #name, #size, #description, #required, #attributes.\n\nFile: includes/form.inc", "response": "function theme_file($variables) {\n $element = $variables['element'];\n $element['#attributes']['type'] = 'file';\n element_set_attributes($element, array('id', 'name', 'size'));\n _form_set_class($element, array('form-file'));\n\n return '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a96ebe065e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_set_active_trail/7.x", "instruction": "Implement `menu_set_active_trail($new_trail = NULL)` in PHP for Drupal 7. Required behavior: Sets the active trail (path to the menu tree root) of the current page.", "context": "Any trail set by this function will only be used for functionality that calls menu_get_active_trail(). Drupal core only uses trails set here for breadcrumbs and the page title and not for menu trees or page content. Additionally, breadcrumbs set by drupal_set_breadcrumb() will override any trail set here.\n\nTo affect the trail used by menu trees, use menu_tree_set_path(). To affect the page content, use menu_set_active_item() instead.\n\nParameters:\n- $new_trail: Menu trail to set; the value is saved in a static variable and can be retrieved by menu_get_active_trail(). The format of this array should be the same as the return value of menu_get_active_trail().\n\nReturns: The active trail. See menu_get_active_trail() for details.\n\nFile: includes/menu.inc", "response": "function menu_set_active_trail($new_trail = NULL) {\n $trail = &drupal_static(__FUNCTION__);\n\n if (isset($new_trail)) {\n $trail = $new_trail;\n }\n elseif (!isset($trail)) {\n $trail = array();\n $trail[] = array(\n 'title' => t('Home'),\n 'href' => '',\n 'link_path' => '',\n 'localized_options' => array(),\n 'type' => 0,\n );\n\n // Try to retrieve a menu link corresponding to the current path. If more\n // than one exists, the link from the most preferred menu is returned.\n $preferred_link = menu_link_get_preferred();\n $current_item = menu_get_item();\n\n // There is a link for the current path.\n if ($preferred_link) {\n // Pass TRUE for $only_active_trail to make menu_tree_page_data() build\n // a stripped down menu tree containing the active trail only, in case\n // the given menu has not been built in this request yet.\n $tree = menu_tree_page_data($preferred_link['menu_name'], NULL, TRUE);\n $curr = current($tree);\n next($tree);\n }\n // There is no link for the current path.\n else {\n $preferred_link = $current_item;\n $curr = FALSE;\n }\n\n while ($curr) {\n $link = $curr['link'];\n if ($link['in_active_trail']) {\n // Add the link to the trail, unless it links to its parent.\n if (!($link['type'] & MENU_LINKS_TO_PARENT)) {\n // The menu tree for the active trail may contain additional links\n // that have not been translated yet, since they contain dynamic\n // argument placeholders (%). Such links are not contained in regular\n // menu trees, and have only been loaded for the additional\n // translation that happens here, so as to be able to display them in\n // the breadcrumb for the current page.\n // @see _menu_tree_check_access()\n // @see _menu_link_translate()\n if (strpos($link['href'], '%') !== FALSE) {\n _menu_link_translate($link, TRUE);\n }\n if ($link['access']) {\n $trail[] = $link;\n }\n }\n $tree = $curr['below'] ? $curr['below'] : array();\n }\n $curr = current($tree);\n next($tree);\n }\n // Make sure the current page is in the trail to build the page title, by\n // appending either the preferred link or the menu router item for the\n // current page. Exclude it if we are on the front page.\n $last = end($trail);\n if ($preferred_link && $last['href'] != $preferred_link['href'] && !drupal_is_front_page()) {\n $trail[] = $preferred_link;\n }\n }\n return $trail;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a97a39518f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/format_xml_elements/7.x", "instruction": "I need the code for `format_xml_elements($array)` in Drupal 7 (includes/common.inc). It must do this: Formats XML elements.", "context": "Parameters:\n- $array: An array where each item represents an element and is either a: - (key => value) pair (value) - Associative array with fields: - 'key': element name - 'value': element contents - 'attributes': associative array of element attributes - 'encoded': TRUE if 'value' is already encoded In both cases, 'value' can be a simple string, or it can be another array with the same format as $array itself for nesting. If 'encoded' is TRUE it is up to the caller to ensure that 'value' is either entity-encoded or CDATA-escaped. Using this option is not recommended when working with untrusted user input, since failing to escape the data correctly has security implications.\n\nFile: includes/common.inc", "response": "function format_xml_elements($array) {\n $output = '';\n foreach ($array as $key => $value) {\n if (is_numeric($key)) {\n if ($value['key']) {\n $output .= ' <' . $value['key'];\n if (isset($value['attributes']) && is_array($value['attributes'])) {\n $output .= drupal_attributes($value['attributes']);\n }\n\n if (isset($value['value']) && $value['value'] != '') {\n $output .= '>' . (is_array($value['value']) ? format_xml_elements($value['value']) : (!empty($value['encoded']) ? $value['value'] : check_plain($value['value']))) . '\\n\";\n }\n else {\n $output .= \" />\\n\";\n }\n }\n }\n else {\n $output .= ' <' . $key . '>' . (is_array($value) ? format_xml_elements($value) : check_plain($value)) . \"\\n\";\n }\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a97fa69794", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_vocabulary_confirm_delete/7.x", "instruction": "Implement `taxonomy_vocabulary_confirm_delete($form, &$form_state, $vid)` in PHP for Drupal 7. Required behavior: Form builder for the vocabulary delete confirmation form.", "context": "File: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_vocabulary_confirm_delete($form, &$form_state, $vid) {\n $vocabulary = taxonomy_vocabulary_load($vid);\n\n // Always provide entity id in the same form key as in the entity edit form.\n $form['vid'] = array('#type' => 'value', '#value' => $vid);\n\n $form['#vocabulary'] = $vocabulary;\n $form['#id'] = 'taxonomy_vocabulary_confirm_delete';\n $form['type'] = array('#type' => 'value', '#value' => 'vocabulary');\n $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name);\n $form['#submit'] = array('taxonomy_vocabulary_confirm_delete_submit');\n return confirm_form($form,\n t('Are you sure you want to delete the vocabulary %title?',\n array('%title' => $vocabulary->name)),\n 'admin/structure/taxonomy',\n t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'),\n t('Delete'),\n t('Cancel'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9bb6d911d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_file_system_settings/7.x", "instruction": "In Drupal 7, write the function `system_file_system_settings()` (file modules/system/system.admin.inc) so that it does the following: Form builder; Configure the site file handling.", "context": "File: modules/system/system.admin.inc", "response": "function system_file_system_settings() {\n $form['file_public_path'] = array(\n '#type' => 'textfield',\n '#title' => t('Public file system path'),\n '#default_value' => variable_get('file_public_path', conf_path() . '/files'),\n '#maxlength' => 255,\n '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'),\n '#after_build' => array('system_check_directory'),\n );\n\n $form['file_private_path'] = array(\n '#type' => 'textfield',\n '#title' => t('Private file system path'),\n '#default_value' => variable_get('file_private_path', ''),\n '#maxlength' => 255,\n '#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. See the online handbook for more information about securing private files.', array('@handbook' => 'https://www.drupal.org/docs/7/core/modules/file/overview')),\n '#after_build' => array('system_check_directory'),\n );\n\n $form['file_temporary_path'] = array(\n '#type' => 'textfield',\n '#title' => t('Temporary directory'),\n '#default_value' => variable_get('file_temporary_path', file_directory_temp()),\n '#maxlength' => 255,\n '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'),\n '#after_build' => array('system_check_directory'),\n );\n // Any visible, writeable wrapper can potentially be used for the files\n // directory, including a remote file system that integrates with a CDN.\n foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) {\n $options[$scheme] = check_plain($info['description']);\n }\n\n if (!empty($options)) {\n $form['file_default_scheme'] = array(\n '#type' => 'radios',\n '#title' => t('Default download method'),\n '#default_value' => variable_get('file_default_scheme', isset($options['public']) ? 'public' : key($options)),\n '#options' => $options,\n '#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'),\n );\n }\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9bebb1e43", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_taxonomy_term_delete/7.x", "instruction": "I need the code for `path_taxonomy_term_delete($term)` in Drupal 7 (modules/path/path.module). It must do this: Implements hook_taxonomy_term_delete().", "context": "File: modules/path/path.module", "response": "function path_taxonomy_term_delete($term) {\n // Delete all aliases associated with this term.\n path_delete(array('source' => 'taxonomy/term/' . $term->tid));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9cd3718e4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_stream_wrapper_get_class/7.x", "instruction": "In Drupal 7, write the function `file_stream_wrapper_get_class($scheme)` (file includes/file.inc) so that it does the following: Returns the stream wrapper class name for a given scheme.", "context": "Parameters:\n- $scheme: Stream scheme.\n\nReturns: Return string if a scheme has a registered handler, or FALSE.\n\nFile: includes/file.inc", "response": "function file_stream_wrapper_get_class($scheme) {\n $wrappers = file_get_stream_wrappers();\n return empty($wrappers[$scheme]) ? FALSE : $wrappers[$scheme]['class'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9d3d2d0b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/_install_configure_form/7.x", "instruction": "Implement `_install_configure_form($form, &$form_state, &$install_state)` in PHP for Drupal 7. Required behavior: Form constructor for a site configuration form.", "context": "Parameters:\n- $install_state: An array of information about the current installation state.\n\nFile: includes/install.core.inc", "response": "function _install_configure_form($form, &$form_state, &$install_state) {\n include_once DRUPAL_ROOT . '/includes/locale.inc';\n\n $form['site_information'] = array(\n '#type' => 'fieldset',\n '#title' => st('Site information'),\n '#collapsible' => FALSE,\n );\n $form['site_information']['site_name'] = array(\n '#type' => 'textfield',\n '#title' => st('Site name'),\n '#required' => TRUE,\n '#weight' => -20,\n );\n $form['site_information']['site_mail'] = array(\n '#type' => 'textfield',\n '#title' => st('Site e-mail address'),\n '#default_value' => ini_get('sendmail_from'),\n '#description' => st(\"Automated e-mails, such as registration information, will be sent from this address. Use an address ending in your site's domain to help prevent these e-mails from being flagged as spam.\"),\n '#required' => TRUE,\n '#weight' => -15,\n );\n $form['admin_account'] = array(\n '#type' => 'fieldset',\n '#title' => st('Site maintenance account'),\n '#collapsible' => FALSE,\n );\n\n $form['admin_account']['account']['#tree'] = TRUE;\n $form['admin_account']['account']['name'] = array('#type' => 'textfield',\n '#title' => st('Username'),\n '#maxlength' => USERNAME_MAX_LENGTH,\n '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'),\n '#required' => TRUE,\n '#weight' => -10,\n '#attributes' => array('class' => array('username')),\n );\n\n $form['admin_account']['account']['mail'] = array('#type' => 'textfield',\n '#title' => st('E-mail address'),\n '#maxlength' => EMAIL_MAX_LENGTH,\n '#required' => TRUE,\n '#weight' => -5,\n );\n $form['admin_account']['account']['pass'] = array(\n '#type' => 'password_confirm',\n '#required' => TRUE,\n '#size' => 25,\n '#weight' => 0,\n );\n\n $form['server_settings'] = array(\n '#type' => 'fieldset',\n '#title' => st('Server settings'),\n '#collapsible' => FALSE,\n );\n\n $countries = country_get_list();\n $form['server_settings']['site_default_country'] = array(\n '#type' => 'select',\n '#title' => st('Default country'),\n '#empty_value' => '',\n '#default_value' => variable_get('site_default_country', NULL),\n '#options' => $countries,\n '#description' => st('Select the default country for the site.'),\n '#weight' => 0,\n );\n\n $form['server_settings']['date_default_timezone'] = array(\n '#type' => 'select',\n '#title' => st('Default time zone'),\n '#default_value' => date_default_timezone_get(),\n '#options' => system_time_zones(),\n '#description' => st('By default, dates in this site will be displayed in the chosen time zone.'),\n '#weight' => 5,\n '#attributes' => array('class' => array('timezone-detect')),\n );\n\n $form['server_settings']['clean_url'] = array(\n '#type' => 'hidden',\n '#default_value' => 0,\n '#attributes' => array('id' => 'edit-clean-url', 'class' => array('install')),\n );\n\n $form['update_notifications'] = array(\n '#type' => 'fieldset',\n '#title' => st('Update notifications'),\n '#collapsible' => FALSE,\n );\n $form['update_notifications']['update_status_module'] = array(\n '#type' => 'checkboxes',\n '#options' => array(\n 1 => st('Check for updates automatically'),\n 2 => st('Receive e-mail notifications'),\n ),\n '#default_value' => array(1, 2),\n '#description' => st('The system will notify you when updates and important security releases are available for installed components. Anonymous information about your site is sent to Drupal.org.', array('@drupal' => 'http://drupal.org')),\n '#weight' => 15,\n );\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => st('Save and continue'),\n '#weight' => 15,\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9d6680f7f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_weight/7.x", "instruction": "I need the code for `form_process_weight($element)` in Drupal 7 (includes/form.inc). It must do this: Expands a weight element into a select element.", "context": "File: includes/form.inc", "response": "function form_process_weight($element) {\n $element['#is_weight'] = TRUE;\n\n // If the number of options is small enough, use a select field.\n $max_elements = variable_get('drupal_weight_select_max', DRUPAL_WEIGHT_SELECT_MAX);\n if ($element['#delta'] <= $max_elements) {\n $element['#type'] = 'select';\n $weights = array();\n for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) {\n $weights[$n] = $n;\n }\n if (isset($element['#default_value'])) {\n $default_value = (int) $element['#default_value'];\n if (!isset($weights[$default_value])) {\n $weights[$default_value] = $default_value;\n ksort($weights);\n }\n }\n $element['#options'] = $weights;\n $element += element_info('select');\n }\n // Otherwise, use a text field.\n else {\n $element['#type'] = 'textfield';\n // Use a field big enough to fit most weights.\n $element['#size'] = 10;\n $element['#element_validate'] = array('element_validate_integer');\n $element += element_info('textfield');\n }\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9e60bbef5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/_field_invoke_default/7.x", "instruction": "In Drupal 7, write the function `_field_invoke_default($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $options = array())` (file modules/field/field.attach.inc) so that it does the following: Invoke field.module's version of a field hook.", "context": "This function invokes the field_default_[op]() function. Use _field_invoke() to invoke the field type implementation, hook_field_[op]().\n\nFile: modules/field/field.attach.inc", "response": "function _field_invoke_default($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $options = array()) {\n $options['default'] = TRUE;\n return _field_invoke($op, $entity_type, $entity, $a, $b, $options);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9f64f6509", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_managed_file_process/7.x", "instruction": "I need the code for `file_managed_file_process($element, &$form_state, $form)` in Drupal 7 (modules/file/file.module). It must do this: Process function to expand the managed_file element type.", "context": "Expands the file type to include Upload and Remove buttons, as well as support for a default value.\n\nFile: modules/file/file.module", "response": "function file_managed_file_process($element, &$form_state, $form) {\n $fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0;\n\n // Set some default element properties.\n $element['#progress_indicator'] = empty($element['#progress_indicator']) ? 'none' : $element['#progress_indicator'];\n $element['#file'] = $fid ? file_load($fid) : FALSE;\n $element['#tree'] = TRUE;\n\n $ajax_settings = array(\n 'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],\n 'wrapper' => $element['#id'] . '-ajax-wrapper',\n 'effect' => 'fade',\n 'progress' => array(\n 'type' => $element['#progress_indicator'],\n 'message' => $element['#progress_message'],\n ),\n );\n\n // Set up the buttons first since we need to check if they were clicked.\n $element['upload_button'] = array(\n '#name' => implode('_', $element['#parents']) . '_upload_button',\n '#type' => 'submit',\n '#value' => t('Upload'),\n '#validate' => array(),\n '#submit' => array('file_managed_file_submit'),\n '#limit_validation_errors' => array($element['#parents']),\n '#ajax' => $ajax_settings,\n '#weight' => -5,\n );\n\n // Force the progress indicator for the remove button to be either 'none' or\n // 'throbber', even if the upload button is using something else.\n $ajax_settings['progress']['type'] = ($element['#progress_indicator'] == 'none') ? 'none' : 'throbber';\n $ajax_settings['progress']['message'] = NULL;\n $ajax_settings['effect'] = 'none';\n $element['remove_button'] = array(\n '#name' => implode('_', $element['#parents']) . '_remove_button',\n '#type' => 'submit',\n '#value' => t('Remove'),\n '#validate' => array(),\n '#submit' => array('file_managed_file_submit'),\n '#limit_validation_errors' => array($element['#parents']),\n '#ajax' => $ajax_settings,\n '#weight' => -5,\n );\n\n $element['fid'] = array(\n '#type' => 'hidden',\n '#value' => $fid,\n );\n\n // Add progress bar support to the upload if possible.\n if ($element['#progress_indicator'] == 'bar' && $implementation = file_progress_implementation()) {\n $upload_progress_key = mt_rand();\n\n if ($implementation == 'uploadprogress') {\n $element['UPLOAD_IDENTIFIER'] = array(\n '#type' => 'hidden',\n '#value' => $upload_progress_key,\n '#attributes' => array('class' => array('file-progress')),\n // Uploadprogress extension requires this field to be at the top of the\n // form.\n '#weight' => -20,\n );\n }\n elseif ($implementation == 'apc') {\n $element['APC_UPLOAD_PROGRESS'] = array(\n '#type' => 'hidden',\n '#value' => $upload_progress_key,\n '#attributes' => array('class' => array('file-progress')),\n // Uploadprogress extension requires this field to be at the top of the\n // form.\n '#weight' => -20,\n );\n }\n\n // Add the upload progress callback.\n $element['upload_button']['#ajax']['progress']['path'] = 'file/progress/' . $upload_progress_key;\n }\n\n // The file upload field itself.\n $element['upload'] = array(\n '#name' => 'files[' . implode('_', $element['#parents']) . ']',\n '#type' => 'file',\n // This #title will not actually be used as the upload field's HTML label,\n // since the theme function for upload fields never passes the element\n // through theme('form_element'). Instead the parent element's #title is\n // used as the label (see below). That is usually a more meaningful label\n // anyway.\n '#title' => t('Choose a file'),\n '#title_display' => 'invisible',\n // Set the ID manually so the desired field label can be associated with it\n // below. Use the same method for setting the ID that the form API\n // autogenerator does.\n '#id' => drupal_html_id('edit-' . implode('-', array_merge($element['#parents'], array('upload')))),\n '#size' => $element['#size'],\n '#theme_wrappers' => array(),\n '#weight' => -10,\n );\n\n // Indicate that $element['#title'] should be used as the HTML label for the\n // file upload field.\n $element['#label_for'] = $element['upload']['#id'];\n\n if ($fid && $element['#file']) {\n $element['filename'] = array(\n '#type' => 'markup',\n '#markup' => theme('file_link', array('file' => $element['#file'])) . ' ',\n '#weight' => -10,\n );\n // Anonymous users who have uploaded a temporary file need a\n // non-session-based token added so file_managed_file_value() can check\n // that they have permission to use this file on subsequent submissions of\n // the same form (for example, after an Ajax upload or form validation\n // error).\n if (!$GLOBALS['user']->uid && $element['#file']->status != FILE_STATUS_PERMANENT) {\n $element['fid_token'] = array(\n '#type' => 'hidden',\n '#value' => drupal_hmac_base64('file-' . $fid, drupal_get_private_key() . drupal_get_hash_salt()),\n );\n }\n }\n\n // Add the extension list to the page as JavaScript settings.\n if (isset($element['#upload_validators']['file_validate_extensions'][0])) {\n $extension_list = implode(',', array_filter(explode(' ', $element['#upload_validators']['file_validate_extensions'][0])));\n $element['upload']['#attached']['js'] = array(\n array(\n 'type' => 'setting',\n 'data' => array('file' => array('elements' => array('#' . $element['upload']['#id'] => $extension_list)))\n )\n );\n }\n\n // Prefix and suffix used for Ajax replacement.\n $element['#prefix'] = '
            ';\n $element['#suffix'] = '
            ';\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-a9f8b5032e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_menu/7.x", "instruction": "In Drupal 7, write the function `image_menu()` (file modules/image/image.module) so that it does the following: Implements hook_menu().", "context": "File: modules/image/image.module", "response": "function image_menu() {\n $items = array();\n\n // Generate image derivatives of publicly available files.\n // If clean URLs are disabled, image derivatives will always be served\n // through the menu system.\n // If clean URLs are enabled and the image derivative already exists,\n // PHP will be bypassed.\n $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();\n $items[$directory_path . '/styles/%image_style'] = array(\n 'title' => 'Generate image style',\n 'page callback' => 'image_style_deliver',\n 'page arguments' => array(count(explode('/', $directory_path)) + 1),\n 'access callback' => TRUE,\n 'type' => MENU_CALLBACK,\n );\n // Generate and deliver image derivatives of private files.\n // These image derivatives are always delivered through the menu system.\n $items['system/files/styles/%image_style'] = array(\n 'title' => 'Generate image style',\n 'page callback' => 'image_style_deliver',\n 'page arguments' => array(3),\n 'access callback' => TRUE,\n 'type' => MENU_CALLBACK,\n );\n $items['admin/config/media/image-styles'] = array(\n 'title' => 'Image styles',\n 'description' => 'Configure styles that can be used for resizing or adjusting images on display.',\n 'page callback' => 'image_style_list',\n 'access arguments' => array('administer image styles'),\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/list'] = array(\n 'title' => 'List',\n 'description' => 'List the current image styles on the site.',\n 'page callback' => 'image_style_list',\n 'access arguments' => array('administer image styles'),\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n 'weight' => 1,\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/add'] = array(\n 'title' => 'Add style',\n 'description' => 'Add a new image style.',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('image_style_add_form'),\n 'access arguments' => array('administer image styles'),\n 'type' => MENU_LOCAL_ACTION,\n 'weight' => 2,\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/edit/%image_style'] = array(\n 'title' => 'Edit style',\n 'description' => 'Configure an image style.',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('image_style_form', 5),\n 'access arguments' => array('administer image styles'),\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/delete/%image_style'] = array(\n 'title' => 'Delete style',\n 'description' => 'Delete an image style.',\n 'load arguments' => array(NULL, (string) IMAGE_STORAGE_NORMAL),\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('image_style_delete_form', 5),\n 'access arguments' => array('administer image styles'),\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/revert/%image_style'] = array(\n 'title' => 'Revert style',\n 'description' => 'Revert an image style.',\n 'load arguments' => array(NULL, (string) IMAGE_STORAGE_OVERRIDE),\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('image_style_revert_form', 5),\n 'access arguments' => array('administer image styles'),\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/edit/%image_style/effects/%image_effect'] = array(\n 'title' => 'Edit image effect',\n 'description' => 'Edit an existing effect within a style.',\n 'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE),\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('image_effect_form', 5, 7),\n 'access arguments' => array('administer image styles'),\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/edit/%image_style/effects/%image_effect/delete'] = array(\n 'title' => 'Delete image effect',\n 'description' => 'Delete an existing effect from a style.',\n 'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE),\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('image_effect_delete_form', 5, 7),\n 'access arguments' => array('administer image styles'),\n 'file' => 'image.admin.inc',\n );\n $items['admin/config/media/image-styles/edit/%image_style/add/%image_effect_definition'] = array(\n 'title' => 'Add image effect',\n 'description' => 'Add a new effect to a style.',\n 'load arguments' => array(5),\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('image_effect_form', 5, 7),\n 'access arguments' => array('administer image styles'),\n 'file' => 'image.admin.inc',\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa048c9525", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_link_parents_set/7.x", "instruction": "I need the code for `_menu_link_parents_set(&$item, $parent)` in Drupal 7 (includes/menu.inc). It must do this: Sets the p1 through p9 values for a menu link being saved.", "context": "File: includes/menu.inc", "response": "function _menu_link_parents_set(&$item, $parent) {\n $i = 1;\n while ($i < $item['depth']) {\n $p = 'p' . $i++;\n $item[$p] = $parent[$p];\n }\n $p = 'p' . $i++;\n // The parent (p1 - p9) corresponding to the depth always equals the mlid.\n $item[$p] = $item['mlid'];\n while ($i <= MENU_MAX_DEPTH) {\n $p = 'p' . $i++;\n $item[$p] = 0;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa118c9290", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_actions_manage/7.x", "instruction": "In Drupal 7, write the function `system_actions_manage()` (file modules/system/system.admin.inc) so that it does the following: Menu callback; Displays an overview of available and configured actions.", "context": "File: modules/system/system.admin.inc", "response": "function system_actions_manage() {\n actions_synchronize();\n $actions = actions_list();\n $actions_map = actions_actions_map($actions);\n $options = array();\n $unconfigurable = array();\n\n foreach ($actions_map as $key => $array) {\n if ($array['configurable']) {\n $options[$key] = $array['label'] . '...';\n }\n else {\n $unconfigurable[] = $array;\n }\n }\n\n $row = array();\n $instances_present = db_query(\"SELECT aid FROM {actions} WHERE parameters <> ''\")->fetchField();\n $header = array(\n array('data' => t('Action type'), 'field' => 'type'),\n array('data' => t('Label'), 'field' => 'label'),\n array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')\n );\n $query = db_select('actions')->extend('PagerDefault')->extend('TableSort');\n $result = $query\n ->fields('actions')\n ->limit(50)\n ->orderByHeader($header)\n ->execute();\n\n foreach ($result as $action) {\n $row[] = array(\n array('data' => $action->type),\n array('data' => check_plain($action->label)),\n array('data' => $action->parameters ? l(t('configure'), \"admin/config/system/actions/configure/$action->aid\") : ''),\n array('data' => $action->parameters ? l(t('delete'), \"admin/config/system/actions/delete/$action->aid\") : '')\n );\n }\n\n if ($row) {\n $pager = theme('pager');\n if (!empty($pager)) {\n $row[] = array(array('data' => $pager, 'colspan' => '3'));\n }\n $build['system_actions_header'] = array('#markup' => '

            ' . t('Available actions:') . '

            ');\n $build['system_actions_table'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $row)));\n }\n\n if ($actions_map) {\n $build['system_actions_manage_form'] = drupal_get_form('system_actions_manage_form', $options);\n }\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa2c70d682", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_sort_css_js/7.x", "instruction": "In Drupal 7, write the function `drupal_sort_css_js($a, $b)` (file includes/common.inc) so that it does the following: Sorts CSS and JavaScript resources.", "context": "Callback for uasort() within:\n- drupal_get_css()\n- drupal_get_js()\n\nThis sort order helps optimize front-end performance while providing modules and themes with the necessary control for ordering the CSS and JavaScript appearing on a page.\n\nParameters:\n- $a: First item for comparison. The compared items should be associative arrays of member items from drupal_add_css() or drupal_add_js().\n- $b: Second item for comparison.\n\nFile: includes/common.inc", "response": "function drupal_sort_css_js($a, $b) {\n // First order by group, so that, for example, all items in the CSS_SYSTEM\n // group appear before items in the CSS_DEFAULT group, which appear before\n // all items in the CSS_THEME group. Modules may create additional groups by\n // defining their own constants.\n if ($a['group'] < $b['group']) {\n return -1;\n }\n elseif ($a['group'] > $b['group']) {\n return 1;\n }\n // Within a group, order all infrequently needed, page-specific files after\n // common files needed throughout the website. Separating this way allows for\n // the aggregate file generated for all of the common files to be reused\n // across a site visit without being cut by a page using a less common file.\n elseif ($a['every_page'] && !$b['every_page']) {\n return -1;\n }\n elseif (!$a['every_page'] && $b['every_page']) {\n return 1;\n }\n // Finally, order by weight.\n elseif ($a['weight'] < $b['weight']) {\n return -1;\n }\n elseif ($a['weight'] > $b['weight']) {\n return 1;\n }\n else {\n return 0;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa43bbc5ab", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.install/function/_book_install_type_create/7.x", "instruction": "In Drupal 7, write the function `_book_install_type_create()` (file modules/book/book.install) so that it does the following: Creates the book content type.", "context": "File: modules/book/book.install", "response": "function _book_install_type_create() {\n // Create an additional node type.\n $book_node_type = array(\n 'type' => 'book',\n 'name' => t('Book page'),\n 'base' => 'node_content',\n 'description' => t('Books have a built-in hierarchical navigation. Use for handbooks or tutorials.'),\n 'custom' => 1,\n 'modified' => 1,\n 'locked' => 0,\n );\n\n $book_node_type = node_type_set_defaults($book_node_type);\n node_type_save($book_node_type);\n node_add_body_field($book_node_type);\n // Default to not promoted.\n variable_set('node_options_book', array('status'));\n // Use this default type for adding content to books.\n variable_set('book_allowed_types', array('book'));\n variable_set('book_child_type', 'book');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa73ef8143", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/_filter_xss_split/7.x", "instruction": "In Drupal 7, write the function `_filter_xss_split($m, $store = FALSE)` (file includes/common.inc) so that it does the following: Processes an HTML tag.", "context": "Parameters:\n- $m: An array with various meaning depending on the value of $store. If $store is TRUE then the array contains the allowed tags. If $store is FALSE then the array has one element, the HTML tag to process.\n- $store: Whether to store $m.\n\nReturns: If the element isn't allowed, an empty string. Otherwise, the cleaned up version of the HTML element.\n\nFile: includes/common.inc", "response": "function _filter_xss_split($m, $store = FALSE) {\n static $allowed_html;\n\n if ($store) {\n $allowed_html = array_flip($m);\n return;\n }\n\n $string = $m[1];\n\n if (substr($string, 0, 1) != '<') {\n // We matched a lone \">\" character.\n return '>';\n }\n elseif (strlen($string) == 1) {\n // We matched a lone \"<\" character.\n return '<';\n }\n\n if (!preg_match('%^<\\s*(/\\s*)?([a-zA-Z0-9\\-]+)\\s*([^>]*)>?|()$%', $string, $matches)) {\n // Seriously malformed.\n return '';\n }\n\n $slash = trim($matches[1]);\n $elem = &$matches[2];\n $attrlist = &$matches[3];\n $comment = &$matches[4];\n\n if ($comment) {\n $elem = '!--';\n }\n\n if (!isset($allowed_html[strtolower($elem)])) {\n // Disallowed HTML element.\n return '';\n }\n\n if ($comment) {\n return $comment;\n }\n\n if ($slash != '') {\n return \"\";\n }\n\n // Is there a closing XHTML slash at the end of the attributes?\n $attrlist = preg_replace('%(\\s?)/\\s*$%', '\\1', $attrlist, -1, $count);\n $xhtml_slash = $count ? ' /' : '';\n\n // Clean up attributes.\n $attr2 = implode(' ', _filter_xss_attributes($attrlist));\n $attr2 = preg_replace('/[<>]/', '', $attr2);\n $attr2 = strlen($attr2) ? ' ' . $attr2 : '';\n\n return \"<$elem$attr2$xhtml_slash>\";\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa89a6c29c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21php%21php.module/function/php_eval/7.x", "instruction": "Implement `php_eval($code)` in PHP for Drupal 7. Required behavior: Evaluates a string of PHP code.", "context": "This is a wrapper around PHP's eval(). It uses output buffering to capture both returned and printed text. Unlike eval(), we require code to be surrounded by tags; in other words, we evaluate the code as if it were a stand-alone PHP file.\n\nUsing this wrapper also ensures that the PHP code which is evaluated can not overwrite any variables in the calling code, unlike a regular eval() call.\n\nThis function is also used as an implementation of callback_filter_process().\n\nParameters:\n- $code: The code to evaluate.\n\nReturns: A string containing the printed output of the code, followed by the returned output of the code.\n\nFile: modules/php/php.module", "response": "function php_eval($code) {\n global $theme_path, $theme_info, $conf;\n\n // Store current theme path.\n $old_theme_path = $theme_path;\n\n // Restore theme_path to the theme, as long as php_eval() executes,\n // so code evaluated will not see the caller module as the current theme.\n // If theme info is not initialized get the path from theme_default.\n if (!isset($theme_info)) {\n $theme_path = drupal_get_path('theme', $conf['theme_default']);\n }\n else {\n $theme_path = dirname($theme_info->filename);\n }\n\n ob_start();\n print eval('?>' . $code);\n $output = ob_get_contents();\n ob_end_clean();\n\n // Recover original theme path.\n $theme_path = $old_theme_path;\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa8d249d8f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_ancestors/7.x", "instruction": "I need the code for `menu_get_ancestors($parts)` in Drupal 7 (includes/menu.inc). It must do this: Returns the ancestors (and relevant placeholders) for any given path.", "context": "For example, the ancestors of node/12345/edit are:\n- node/12345/edit\n- node/12345/%\n- node/%/edit\n- node/%/%\n- node/12345\n- node/%\n- node\n\nTo generate these, we will use binary numbers. Each bit represents a part of the path. If the bit is 1, then it represents the original value while 0 means wildcard. If the path is node/12/edit/foo then the 1011 bitstring represents node/%/edit/foo where % means that any argument matches that part. We limit ourselves to using binary numbers that correspond the patterns of wildcards of router items that actually exists. This list of 'masks' is built in menu_rebuild().\n\nParameters:\n- $parts: An array of path parts; for the above example, array('node', '12345', 'edit').\n\nReturns: An array which contains the ancestors and placeholders. Placeholders simply contain as many '%s' as the ancestors.\n\nFile: includes/menu.inc", "response": "function menu_get_ancestors($parts) {\n $number_parts = count($parts);\n $ancestors = array();\n $length = $number_parts - 1;\n $end = (1 << $number_parts) - 1;\n $masks = variable_get('menu_masks');\n // If the optimized menu_masks array is not available use brute force to get\n // the correct $ancestors and $placeholders returned. Do not use this as the\n // default value of the menu_masks variable to avoid building such a big\n // array.\n if (!$masks) {\n $masks = range(511, 1);\n }\n // Only examine patterns that actually exist as router items (the masks).\n foreach ($masks as $i) {\n if ($i > $end) {\n // Only look at masks that are not longer than the path of interest.\n continue;\n }\n elseif ($i < (1 << $length)) {\n // We have exhausted the masks of a given length, so decrease the length.\n --$length;\n }\n $current = '';\n for ($j = $length; $j >= 0; $j--) {\n // Check the bit on the $j offset.\n if ($i & (1 << $j)) {\n // Bit one means the original value.\n $current .= $parts[$length - $j];\n }\n else {\n // Bit zero means means wildcard.\n $current .= '%';\n }\n // Unless we are at offset 0, add a slash.\n if ($j) {\n $current .= '/';\n }\n }\n $ancestors[] = $current;\n }\n return $ancestors;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aa9e8cb688", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_load_links/7.x", "instruction": "Implement `menu_load_links($menu_name)` in PHP for Drupal 7. Required behavior: Returns an array containing all links for a menu.", "context": "Parameters:\n- $menu_name: The name of the menu whose links should be returned.\n\nReturns: An array of menu links.\n\nFile: includes/menu.inc", "response": "function menu_load_links($menu_name) {\n $links = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC))\n ->fields('ml')\n ->condition('ml.menu_name', $menu_name)\n // Order by weight so as to be helpful for menus that are only one level\n // deep.\n ->orderBy('weight')\n ->execute()\n ->fetchAll();\n\n foreach ($links as &$link) {\n $link['options'] = unserialize($link['options']);\n }\n return $links;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aab54682a9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/tracker_menu/7.x", "instruction": "I need the code for `tracker_menu()` in Drupal 7 (modules/tracker/tracker.module). It must do this: Implements hook_menu().", "context": "File: modules/tracker/tracker.module", "response": "function tracker_menu() {\n $items['tracker'] = array(\n 'title' => 'Recent content',\n 'page callback' => 'tracker_page',\n 'access arguments' => array('access content'),\n 'weight' => 1,\n 'file' => 'tracker.pages.inc',\n );\n $items['tracker/all'] = array(\n 'title' => 'All recent content',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n );\n $items['tracker/%user_uid_optional'] = array(\n 'title' => 'My recent content',\n 'page callback' => 'tracker_page',\n 'access callback' => '_tracker_myrecent_access',\n 'access arguments' => array(1),\n 'page arguments' => array(1),\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'tracker.pages.inc',\n );\n\n $items['user/%user/track'] = array(\n 'title' => 'Track',\n 'page callback' => 'tracker_page',\n 'page arguments' => array(1, TRUE),\n 'access callback' => '_tracker_user_access',\n 'access arguments' => array(1),\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'tracker.pages.inc',\n );\n $items['user/%user/track/content'] = array(\n 'title' => 'Track content',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-aabd5fdf91", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_preprocess_page/7.x", "instruction": "Implement `seven_preprocess_page(&$vars)` in PHP for Drupal 7. Required behavior: Override or insert variables into the page template.", "context": "File: themes/seven/template.php", "response": "function seven_preprocess_page(&$vars) {\n $vars['primary_local_tasks'] = $vars['tabs'];\n unset($vars['primary_local_tasks']['#secondary']);\n $vars['secondary_local_tasks'] = array(\n '#theme' => 'menu_local_tasks',\n '#secondary' => $vars['tabs']['#secondary'],\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aacca57732", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.install/function/menu_schema/7.x", "instruction": "I need the code for `menu_schema()` in Drupal 7 (modules/menu/menu.install). It must do this: Implements hook_schema().", "context": "File: modules/menu/menu.install", "response": "function menu_schema() {\n $schema['menu_custom'] = array(\n 'description' => 'Holds definitions for top-level custom menus (for example, Main menu).',\n 'fields' => array(\n 'menu_name' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Primary Key: Unique key for menu. This is used as a block delta so length is 32.',\n ),\n 'title' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Menu title; displayed at top of block.',\n 'translatable' => TRUE,\n ),\n 'description' => array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'description' => 'Menu description.',\n 'translatable' => TRUE,\n ),\n ),\n 'primary key' => array('menu_name'),\n );\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-aaccb62a8d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_delete_form/7.x", "instruction": "In Drupal 7, write the function `field_ui_field_delete_form($form, &$form_state, $instance)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Form constructor for removing a field instance from a bundle.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_field_delete_form($form, &$form_state, $instance) {\n $bundle = $instance['bundle'];\n $entity_type = $instance['entity_type'];\n $field = field_info_field($instance['field_name']);\n\n $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);\n\n $form['entity_type'] = array('#type' => 'value', '#value' => $entity_type);\n $form['bundle'] = array('#type' => 'value', '#value' => $bundle);\n $form['field_name'] = array('#type' => 'value', '#value' => $field['field_name']);\n\n $output = confirm_form($form,\n t('Are you sure you want to delete the field %field?', array('%field' => $instance['label'])),\n $admin_path . '/fields',\n t('If you have any content left in this field, it will be lost. This action cannot be undone.'),\n t('Delete'), t('Cancel'),\n 'confirm'\n );\n\n if ($field['locked']) {\n unset($output['actions']['submit']);\n $output['description']['#markup'] = t('This field is locked and cannot be deleted.');\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aad4713d65", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_update_last_removed/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_update_last_removed()` (modules/system/system.api.php): Return a number which is no longer available as hook_update_N().", "context": "If you remove some update functions from your mymodule.install file, you should notify Drupal of those missing functions. This way, Drupal can ensure that no update is accidentally skipped.\n\nImplementations of this hook should be placed in a mymodule.install file in the same directory as mymodule.module.\n\nReturns: An integer, corresponding to hook_update_N() which has been removed from mymodule.install.\n\nFile: modules/system/system.api.php", "response": "function hook_update_last_removed() {\n // We've removed the 5.x-1.x version of mymodule, including database updates.\n // The next update function is mymodule_update_5200().\n return 5103;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-aad9a26efd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_timezone/7.x", "instruction": "In Drupal 7, write the function `system_timezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL)` (file modules/system/system.module) so that it does the following: Menu callback; Retrieve a JSON object containing a suggested time zone name.", "context": "File: modules/system/system.module", "response": "function system_timezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL) {\n // An abbreviation of \"0\" passed in the callback arguments should be\n // interpreted as the empty string.\n $abbreviation = $abbreviation ? $abbreviation : '';\n $timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time);\n drupal_json_output($timezone);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aae02210ce", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7036/7.x", "instruction": "Implement `system_update_7036()` in PHP for Drupal 7. Required behavior: Split the 'access site in maintenance mode' permission from 'administer site configuration'.", "context": "File: modules/system/system.install", "response": "function system_update_7036() {\n // Get existing roles that can 'administer site configuration'.\n $rids = db_query(\"SELECT rid FROM {role_permission} WHERE permission = :perm\", array(':perm' => 'administer site configuration'))->fetchCol();\n // None found.\n if (empty($rids)) {\n return;\n }\n $insert = db_insert('role_permission')->fields(array('rid', 'permission'));\n foreach ($rids as $rid) {\n $insert->values(array(\n 'rid' => $rid,\n 'permission' => 'access site in maintenance mode',\n ));\n }\n $insert->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab1be357e3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_menu/7.x", "instruction": "Implement `menu_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu().", "context": "File: modules/menu/menu.module", "response": "function menu_menu() {\n $items['admin/structure/menu'] = array(\n 'title' => 'Menus',\n 'description' => 'Add new menus to your site, edit existing menus, and rename and reorganize menu links.',\n 'page callback' => 'menu_overview_page',\n 'access callback' => 'user_access',\n 'access arguments' => array('administer menu'),\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/parents'] = array(\n 'title' => 'Parent menu items',\n 'page callback' => 'menu_parent_options_js',\n 'type' => MENU_CALLBACK,\n 'access arguments' => array('administer menu'),\n );\n $items['admin/structure/menu/list'] = array(\n 'title' => 'List menus',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n 'weight' => -10,\n );\n $items['admin/structure/menu/add'] = array(\n 'title' => 'Add menu',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('menu_edit_menu', 'add'),\n 'access arguments' => array('administer menu'),\n 'type' => MENU_LOCAL_ACTION,\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/settings'] = array(\n 'title' => 'Settings',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('menu_configure'),\n 'access arguments' => array('administer menu'),\n 'type' => MENU_LOCAL_TASK,\n 'weight' => 5,\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/manage/%menu'] = array(\n 'title' => 'Customize menu',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('menu_overview_form', 4),\n 'title callback' => 'menu_overview_title',\n 'title arguments' => array(4),\n 'access arguments' => array('administer menu'),\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/manage/%menu/list'] = array(\n 'title' => 'List links',\n 'weight' => -10,\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,\n );\n $items['admin/structure/menu/manage/%menu/add'] = array(\n 'title' => 'Add link',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('menu_edit_item', 'add', NULL, 4),\n 'access arguments' => array('administer menu'),\n 'type' => MENU_LOCAL_ACTION,\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/manage/%menu/edit'] = array(\n 'title' => 'Edit menu',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('menu_edit_menu', 'edit', 4),\n 'access arguments' => array('administer menu'),\n 'type' => MENU_LOCAL_TASK,\n 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/manage/%menu/delete'] = array(\n 'title' => 'Delete menu',\n 'page callback' => 'menu_delete_menu_page',\n 'page arguments' => array(4),\n 'access arguments' => array('administer menu'),\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/item/%menu_link/edit'] = array(\n 'title' => 'Edit menu link',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('menu_edit_item', 'edit', 4, NULL),\n 'access arguments' => array('administer menu'),\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/item/%menu_link/reset'] = array(\n 'title' => 'Reset menu link',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('menu_reset_item_confirm', 4),\n 'access arguments' => array('administer menu'),\n 'file' => 'menu.admin.inc',\n );\n $items['admin/structure/menu/item/%menu_link/delete'] = array(\n 'title' => 'Delete menu link',\n 'page callback' => 'menu_item_delete_page',\n 'page arguments' => array(4),\n 'access arguments' => array('administer menu'),\n 'file' => 'menu.admin.inc',\n );\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab217fdec5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_form/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode)` (modules/field/field.api.php): Act on field_attach_form().", "context": "This hook is invoked after the field module has performed the operation. Implementing modules should alter the $form or $form_state parameters.\n\nParameters:\n- $entity_type: The type of $entity; for example, 'node' or 'user'.\n- $entity: The entity for which an edit form is being built.\n- $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form. The $form['#parents'] property can be used to identify the corresponding part of $form_state['values']. Hook implementations that need to act on the top-level properties of the global form (like #submit, #validate...) can add a #process callback to the array received in the $form parameter, and act on the $complete_form parameter in the process callback.\n- $form_state: An associative array containing the current state of the form.\n- $langcode: The language the field values are going to be entered in. If no language is provided the default site language will be used.\n\nFile: modules/field/field.api.php", "response": "function hook_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {\n // Add a checkbox allowing a given field to be emptied.\n // See hook_field_attach_submit() for the corresponding processing code.\n $form['empty_field_foo'] = array(\n '#type' => 'checkbox',\n '#title' => t(\"Empty the 'field_foo' field\"),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab2a011751", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_mass_update/7.x", "instruction": "Implement `node_mass_update($nodes, $updates)` in PHP for Drupal 7. Required behavior: Make mass update of nodes, changing all nodes in the $nodes array to update them with the field values in $updates.", "context": "IMPORTANT NOTE: This function is intended to work when called from a form submission handler. Calling it outside of the form submission process may not work correctly.\n\nParameters:\n- $nodes (array): Array of node nids to update.\n- $updates (array): Array of key/value pairs with node field names and the value to update that field to.\n\nFile: modules/node/node.admin.inc", "response": "function node_mass_update($nodes, $updates) {\n // We use batch processing to prevent timeout when updating a large number\n // of nodes.\n if (count($nodes) > 10) {\n $batch = array(\n 'operations' => array(\n array('_node_mass_update_batch_process', array($nodes, $updates))\n ),\n 'finished' => '_node_mass_update_batch_finished',\n 'title' => t('Processing'),\n // We use a single multi-pass operation, so the default\n // 'Remaining x of y operations' message will be confusing here.\n 'progress_message' => '',\n 'error_message' => t('The update has encountered an error.'),\n // The operations do not live in the .module file, so we need to\n // tell the batch engine which file to load before calling them.\n 'file' => drupal_get_path('module', 'node') . '/node.admin.inc',\n );\n batch_set($batch);\n }\n else {\n foreach ($nodes as $nid) {\n _node_mass_update_helper($nid, $updates);\n }\n drupal_set_message(t('The update has been performed.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab327c70c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_tableselect/7.x", "instruction": "I need the code for `theme_tableselect($variables)` in Drupal 7 (includes/form.inc). It must do this: Returns HTML for a table with radio buttons or checkboxes.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties and children of the tableselect element. Properties used: #header, #options, #empty, and #js_select. The #options property is an array of selection options; each array element of #options is an array of properties. These properties can include #attributes, which is added to the table row's HTML attributes; see theme_table(). An example of per-row options: @code $options = array( array( 'title' => 'How to Learn Drupal', 'content_type' => 'Article', 'status' => 'published', '#attributes' => array('class' => array('article-row')), ), array( 'title' => 'Privacy Policy', 'content_type' => 'Page', 'status' => 'published', '#attributes' => array('class' => array('page-row')), ), ); $header = array( 'title' => t('Title'), 'content_type' => t('Content type'), 'status' => t('Status'), ); $form['table'] = array( '#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => t('No content available.'), ); @endcode\n\nFile: includes/form.inc", "response": "function theme_tableselect($variables) {\n $element = $variables['element'];\n $rows = array();\n $header = $element['#header'];\n if (!empty($element['#options'])) {\n // Generate a table row for each selectable item in #options.\n foreach (element_children($element) as $key) {\n $row = array();\n\n $row['data'] = array();\n if (isset($element['#options'][$key]['#attributes'])) {\n $row += $element['#options'][$key]['#attributes'];\n }\n // Render the checkbox / radio element.\n $row['data'][] = drupal_render($element[$key]);\n\n // As theme_table only maps header and row columns by order, create the\n // correct order by iterating over the header fields.\n foreach ($element['#header'] as $fieldname => $title) {\n $row['data'][] = $element['#options'][$key][$fieldname];\n }\n $rows[] = $row;\n }\n // Add an empty header or a \"Select all\" checkbox to provide room for the\n // checkboxes/radios in the first table column.\n if ($element['#js_select']) {\n // Add a \"Select all\" checkbox.\n drupal_add_js('misc/tableselect.js');\n array_unshift($header, array('class' => array('select-all')));\n }\n else {\n // Add an empty header when radio buttons are displayed or a \"Select all\"\n // checkbox is not desired.\n array_unshift($header, '');\n }\n }\n return theme('table', array('header' => $header, 'rows' => $rows, 'empty' => $element['#empty'], 'attributes' => $element['#attributes']));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab3e19ba2d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.api.php/function/hook_menu_delete/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_menu_delete($menu)` (modules/menu/menu.api.php): Respond to a custom menu deletion.", "context": "This hook is used to notify modules that a custom menu along with all links contained in it (if any) has been deleted. Contributed modules may use the information to perform actions based on the information entered into the menu system.\n\nParameters:\n- $menu: An array representing a custom menu: - menu_name: The unique name of the custom menu. - title: The human readable menu title. - description: The custom menu description.\n\nFile: modules/menu/menu.api.php", "response": "function hook_menu_delete($menu) {\n // Delete the record from our variable.\n $my_menus = variable_get('my_module_menus', array());\n unset($my_menus[$menu['menu_name']]);\n variable_set('my_module_menus', $my_menus);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab3f95f216", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_in_active_trail/7.x", "instruction": "In Drupal 7, write the function `toolbar_in_active_trail($path)` (file modules/toolbar/toolbar.module) so that it does the following: Checks whether an item is in the active trail.", "context": "Useful when using a menu generated by menu_tree_all_data() which does not set the 'in_active_trail' flag on items.\n\nReturns: TRUE when path is in the active trail, FALSE if not.\n\nFile: modules/toolbar/toolbar.module", "response": "function toolbar_in_active_trail($path) {\n $active_paths = &drupal_static(__FUNCTION__);\n\n // Gather active paths.\n if (!isset($active_paths)) {\n $active_paths = array();\n $trail = menu_get_active_trail();\n foreach ($trail as $item) {\n if (!empty($item['href'])) {\n $active_paths[] = $item['href'];\n }\n }\n }\n return in_array($path, $active_paths);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab59b65213", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.admin.inc/function/comment_confirm_delete/7.x", "instruction": "I need the code for `comment_confirm_delete($form, &$form_state, $comment)` in Drupal 7 (modules/comment/comment.admin.inc). It must do this: Form builder; Builds the confirmation form for deleting a single comment.", "context": "File: modules/comment/comment.admin.inc", "response": "function comment_confirm_delete($form, &$form_state, $comment) {\n $form['#comment'] = $comment;\n // Always provide entity id in the same form key as in the entity edit form.\n $form['cid'] = array('#type' => 'value', '#value' => $comment->cid);\n return confirm_form(\n $form,\n t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)),\n 'node/' . $comment->nid,\n t('Any replies to this comment will be lost. This action cannot be undone.'),\n t('Delete'),\n t('Cancel'),\n 'comment_confirm_delete');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab6bb907de", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/openid_normalize/7.x", "instruction": "I need the code for `openid_normalize($identifier)` in Drupal 7 (modules/openid/openid.inc). It must do this: Normalize the given identifier.", "context": "The procedure is described in OpenID Authentication 2.0, section 7.2.\n\nFile: modules/openid/openid.inc", "response": "function openid_normalize($identifier) {\n $methods = module_invoke_all('openid_normalization_method_info');\n drupal_alter('openid_normalization_method_info', $methods);\n\n // Execute each method in turn, stopping after the first method accepted\n // the identifier.\n foreach ($methods as $method) {\n $result = $method($identifier);\n if ($result !== NULL) {\n $identifier = $result;\n break;\n }\n }\n\n return $identifier;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab778fb9a4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_vocabulary_confirm_reset_alphabetical_submit/7.x", "instruction": "In Drupal 7, write the function `taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_state)` (file modules/taxonomy/taxonomy.admin.inc) so that it does the following: Submit handler to reset a vocabulary to alphabetical order after confirmation.", "context": "File: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_state) {\n db_update('taxonomy_term_data')\n ->fields(array('weight' => 0))\n ->condition('vid', $form_state['values']['vid'])\n ->execute();\n drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name'])));\n watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);\n $form_state['redirect'] = 'admin/structure/taxonomy/' . $form_state['values']['machine_name'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ab7909deee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_view_multiple/7.x", "instruction": "In Drupal 7, write the function `node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL)` (file modules/node/node.module) so that it does the following: Constructs a drupal_render() style array from an array of loaded nodes.", "context": "Parameters:\n- $nodes: An array of nodes as returned by node_load_multiple().\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $weight: An integer representing the weight of the first node in the list.\n- $langcode: (optional) A language code to use for rendering. Defaults to NULL which is the global content language of the current request.\n\nReturns: An array in the format expected by drupal_render().\n\nFile: modules/node/node.module", "response": "function node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL) {\n $build = array('nodes' => array());\n $entities_by_view_mode = entity_view_mode_prepare('node', $nodes, $view_mode, $langcode);\n foreach ($entities_by_view_mode as $entity_view_mode => $entities) {\n field_attach_prepare_view('node', $entities, $entity_view_mode, $langcode);\n entity_prepare_view('node', $entities, $langcode);\n\n foreach ($entities as $entity) {\n $build['nodes'][$entity->nid] = node_view($entity, $entity_view_mode, $langcode);\n }\n }\n\n foreach ($nodes as $node) {\n $build['nodes'][$node->nid]['#weight'] = $weight;\n $weight++;\n }\n // Sort here, to preserve the input order of the entities that were passed to\n // this function.\n uasort($build['nodes'], 'element_sort');\n $build['nodes']['#sorted'] = TRUE;\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-abb0af0218", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/template_preprocess_profile_wrapper/7.x", "instruction": "Implement `template_preprocess_profile_wrapper(&$variables)` in PHP for Drupal 7. Required behavior: Process variables for profile-wrapper.tpl.php.", "context": "The $variables array contains the following arguments:\n- $content\n\nFile: modules/profile/profile.module", "response": "function template_preprocess_profile_wrapper(&$variables) {\n $variables['current_field'] = '';\n if ($field = arg(1)) {\n $variables['current_field'] = $field;\n $variables['theme_hook_suggestions'][] = 'profile_wrapper__' . $field;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-abc6f5b3e8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_archive_extract/7.x", "instruction": "I need the code for `update_manager_archive_extract($file, $directory)` in Drupal 7 (modules/update/update.manager.inc). It must do this: Unpacks a downloaded archive file.", "context": "Parameters:\n- $file (string): The filename of the archive you wish to extract.\n- $directory (string): The directory you wish to extract the archive into.\n\nReturns: Archiver The Archiver object used to extract the archive.\n\nFile: modules/update/update.manager.inc", "response": "function update_manager_archive_extract($file, $directory) {\n $archiver = archiver_get_archiver($file);\n if (!$archiver) {\n throw new Exception(t('Cannot extract %file, not a valid archive.', array ('%file' => $file)));\n }\n\n // Remove the directory if it exists, otherwise it might contain a mixture of\n // old files mixed with the new files (e.g. in cases where files were removed\n // from a later release).\n $files = $archiver->listContents();\n\n // Unfortunately, we can only use the directory name to determine the project\n // name. Some archivers list the first file as the directory (i.e., MODULE/)\n // and others list an actual file (i.e., MODULE/README.TXT).\n $project = strtok($files[0], '/\\\\');\n\n $extract_location = $directory . '/' . $project;\n if (file_exists($extract_location)) {\n file_unmanaged_delete_recursive($extract_location);\n }\n\n $archiver->extract($directory);\n return $archiver;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac366d3b52", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/_field_write_instance/7.x", "instruction": "I need the code for `_field_write_instance($instance, $update = FALSE)` in Drupal 7 (modules/field/field.crud.inc). It must do this: Stores an instance record in the field configuration database.", "context": "Parameters:\n- $instance: An instance structure.\n- $update: Whether this is a new or existing instance.\n\nFile: modules/field/field.crud.inc", "response": "function _field_write_instance($instance, $update = FALSE) {\n $field = field_read_field($instance['field_name']);\n $field_type = field_info_field_types($field['type']);\n\n // Set defaults.\n $instance += array(\n 'settings' => array(),\n 'display' => array(),\n 'widget' => array(),\n 'required' => FALSE,\n 'label' => $instance['field_name'],\n 'description' => '',\n 'deleted' => 0,\n );\n\n // Set default instance settings.\n $instance['settings'] += field_info_instance_settings($field['type']);\n\n // Set default widget and settings.\n $instance['widget'] += array(\n // TODO: what if no 'default_widget' specified ?\n 'type' => $field_type['default_widget'],\n 'settings' => array(),\n );\n // If no weight specified, make sure the field sinks at the bottom.\n if (!isset($instance['widget']['weight'])) {\n $max_weight = field_info_max_weight($instance['entity_type'], $instance['bundle'], 'form');\n $instance['widget']['weight'] = isset($max_weight) ? $max_weight + 1 : 0;\n }\n // Check widget module.\n $widget_type = field_info_widget_types($instance['widget']['type']);\n $instance['widget']['module'] = $widget_type['module'];\n $instance['widget']['settings'] += field_info_widget_settings($instance['widget']['type']);\n\n // Make sure there are at least display settings for the 'default' view mode,\n // and fill in defaults for each view mode specified in the definition.\n $instance['display'] += array(\n 'default' => array(),\n );\n foreach ($instance['display'] as $view_mode => $display) {\n $display += array(\n 'label' => 'above',\n 'type' => isset($field_type['default_formatter']) ? $field_type['default_formatter'] : 'hidden',\n 'settings' => array(),\n );\n if ($display['type'] != 'hidden') {\n $formatter_type = field_info_formatter_types($display['type']);\n $display['module'] = $formatter_type['module'];\n $display['settings'] += field_info_formatter_settings($display['type']);\n }\n // If no weight specified, make sure the field sinks at the bottom.\n if (!isset($display['weight'])) {\n $max_weight = field_info_max_weight($instance['entity_type'], $instance['bundle'], $view_mode);\n $display['weight'] = isset($max_weight) ? $max_weight + 1 : 0;\n }\n $instance['display'][$view_mode] = $display;\n }\n\n // The serialized 'data' column contains everything from $instance that does\n // not have its own column and is not automatically populated when the\n // instance is read.\n $data = $instance;\n unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']);\n\n $record = array(\n 'field_id' => $instance['field_id'],\n 'field_name' => $instance['field_name'],\n 'entity_type' => $instance['entity_type'],\n 'bundle' => $instance['bundle'],\n 'data' => $data,\n 'deleted' => $instance['deleted'],\n );\n // We need to tell drupal_update_record() the primary keys to trigger an\n // update.\n if ($update) {\n $record['id'] = $instance['id'];\n $primary_key = array('id');\n }\n else {\n $primary_key = array();\n }\n drupal_write_record('field_config_instance', $record, $primary_key);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac4174f908", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_node_insert/7.x", "instruction": "I need the code for `path_node_insert($node)` in Drupal 7 (modules/path/path.module). It must do this: Implements hook_node_insert().", "context": "File: modules/path/path.module", "response": "function path_node_insert($node) {\n if (isset($node->path) && isset($node->path['alias'])) {\n $path = $node->path;\n $path['alias'] = trim($path['alias']);\n // Only save a non-empty alias.\n if (!empty($path['alias'])) {\n // Ensure fields for programmatic executions.\n $langcode = entity_language('node', $node);\n $path['source'] = 'node/' . $node->nid;\n $path['language'] = isset($langcode) ? $langcode : LANGUAGE_NONE;\n path_save($path);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac47865616", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_random_bytes/7.x", "instruction": "I need the code for `drupal_random_bytes($count)` in Drupal 7 (includes/bootstrap.inc). It must do this: Returns a string of highly randomized bytes (over the full 8-bit range).", "context": "On PHP 7 and later, this function is a wrapper around the built-in PHP function random_bytes(). If that function does not exist or cannot find an appropriate source of randomness, this function is better than simply calling mt_rand() or any other built-in PHP function because it can return a long string of bytes (compared to < 4 bytes normally from mt_rand()) and uses the best available pseudo-random source.\n\nParameters:\n- $count (int): The number of characters (bytes) to return in the string.\n\nReturns (string): A randomly generated string.\n\nFile: includes/bootstrap.inc", "response": "function drupal_random_bytes($count) {\n if (function_exists('random_bytes')) {\n try {\n return random_bytes($count);\n }\n catch (Exception $e) {\n // An appropriate source of randomness could not be found. Fall back to a\n // less secure implementation.\n }\n }\n\n // $random_state does not use drupal_static as it stores random bytes.\n static $random_state, $bytes, $has_openssl;\n\n $missing_bytes = $count - strlen((string) $bytes);\n\n if ($missing_bytes > 0) {\n // PHP versions prior 5.3.4 experienced openssl_random_pseudo_bytes()\n // locking on Windows and rendered it unusable.\n if (!isset($has_openssl)) {\n $has_openssl = version_compare(PHP_VERSION, '5.3.4', '>=') && function_exists('openssl_random_pseudo_bytes');\n }\n\n // openssl_random_pseudo_bytes() will find entropy in a system-dependent\n // way.\n if ($has_openssl) {\n $bytes .= openssl_random_pseudo_bytes($missing_bytes);\n }\n\n // Else, read directly from /dev/urandom, which is available on many *nix\n // systems and is considered cryptographically secure.\n elseif ($fh = @fopen('/dev/urandom', 'rb')) {\n // PHP only performs buffered reads, so in reality it will always read\n // at least 4096 bytes. Thus, it costs nothing extra to read and store\n // that much so as to speed any additional invocations.\n $bytes .= fread($fh, max(4096, $missing_bytes));\n fclose($fh);\n }\n\n // If we couldn't get enough entropy, this simple hash-based PRNG will\n // generate a good set of pseudo-random bytes on any system.\n // Note that it may be important that our $random_state is passed\n // through hash() prior to being rolled into $output, that the two hash()\n // invocations are different, and that the extra input into the first one -\n // the microtime() - is prepended rather than appended. This is to avoid\n // directly leaking $random_state via the $output stream, which could\n // allow for trivial prediction of further \"random\" numbers.\n if (strlen((string) $bytes) < $count) {\n // Initialize on the first call. The contents of $_SERVER includes a mix of\n // user-specific and system information that varies a little with each page.\n if (!isset($random_state)) {\n $random_state = print_r($_SERVER, TRUE);\n if (function_exists('getmypid')) {\n // Further initialize with the somewhat random PHP process ID.\n $random_state .= getmypid();\n }\n $bytes = '';\n }\n\n do {\n $random_state = hash('sha256', microtime() . mt_rand() . $random_state);\n $bytes .= hash('sha256', mt_rand() . $random_state, TRUE);\n }\n while (strlen($bytes) < $count);\n }\n }\n $output = substr($bytes, 0, $count);\n $bytes = substr($bytes, $count);\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac52110e8c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_mail/7.x", "instruction": "Implement `system_mail($key, &$message, $params)` in PHP for Drupal 7. Required behavior: Implements hook_mail().", "context": "File: modules/system/system.module", "response": "function system_mail($key, &$message, $params) {\n $context = $params['context'];\n\n $subject = token_replace($context['subject'], $context);\n $body = token_replace($context['message'], $context);\n\n $message['subject'] .= str_replace(array(\"\\r\", \"\\n\"), '', $subject);\n $message['body'][] = $body;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac53fafac6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_7003/7.x", "instruction": "I need the code for `image_update_7003()` in Drupal 7 (modules/image/image.install). It must do this: Remove the variables that set alt and title length since they were not used for database column size and could cause PDO exceptions.", "context": "File: modules/image/image.install", "response": "function image_update_7003() {\n variable_del('image_alt_length');\n variable_del('image_title_length');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac7f8807f2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7086/7.x", "instruction": "In Drupal 7, write the function `system_update_7086()` (file modules/system/system.install) so that it does the following: Prepare the schema and data of the sessions table for hashed session ids.", "context": "File: modules/system/system.install", "response": "function system_update_7086() {\n // Update the session ID fields' description.\n $spec = array(\n 'description' => \"A session ID (hashed). The value is generated by Drupal's session handlers.\",\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n );\n db_drop_primary_key('sessions');\n db_change_field('sessions', 'sid', 'sid', $spec, array('primary key' => array('sid', 'ssid')));\n // Updates the secure session ID field's description.\n $spec = array(\n 'description' => \"Secure session ID (hashed). The value is generated by Drupal's session handlers.\",\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n );\n db_drop_primary_key('sessions');\n db_change_field('sessions', 'ssid', 'ssid', $spec, array('primary key' => array('sid', 'ssid')));\n\n // Update all existing sessions.\n if (!variable_get('do_not_hash_session_ids', FALSE)) {\n $sessions = db_query('SELECT sid, ssid FROM {sessions}');\n while ($session = $sessions->fetchAssoc()) {\n $query = db_update('sessions');\n $fields = array();\n if (!empty($session['sid'])) {\n $fields['sid'] = drupal_hash_base64($session['sid']);\n $query->condition('sid', $session['sid']);\n }\n if (!empty($session['ssid'])) {\n $fields['ssid'] = drupal_hash_base64($session['ssid']);\n $query->condition('ssid', $session['ssid']);\n }\n $query\n ->fields($fields)\n ->execute();\n }\n }\n\n // This variable indicates that the database is ready for hashed session ids.\n variable_set('hashed_session_ids_supported', TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac86ac6d33", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_execute_handlers/7.x", "instruction": "I need the code for `form_execute_handlers($type, &$form, &$form_state)` in Drupal 7 (includes/form.inc). It must do this: Executes custom validation and submission handlers for a given form.", "context": "Button-specific handlers are checked first. If none exist, the function falls back to form-level handlers.\n\nParameters:\n- $type: The type of handler to execute. 'validate' or 'submit' are the defaults used by Form API.\n- $form: An associative array containing the structure of the form.\n- $form_state: A keyed array containing the current state of the form. If the user submitted the form by clicking a button with custom handler functions defined, those handlers will be stored here.\n\nFile: includes/form.inc", "response": "function form_execute_handlers($type, &$form, &$form_state) {\n $return = FALSE;\n // If there was a button pressed, use its handlers.\n if (isset($form_state[$type . '_handlers'])) {\n $handlers = $form_state[$type . '_handlers'];\n }\n // Otherwise, check for a form-level handler.\n elseif (isset($form['#' . $type])) {\n $handlers = $form['#' . $type];\n }\n else {\n $handlers = array();\n }\n\n foreach ($handlers as $function) {\n // Check if a previous _submit handler has set a batch, but make sure we\n // do not react to a batch that is already being processed (for instance\n // if a batch operation performs a drupal_form_submit()).\n if ($type == 'submit' && ($batch =& batch_get()) && !isset($batch['id'])) {\n // Some previous submit handler has set a batch. To ensure correct\n // execution order, store the call in a special 'control' batch set.\n // See _batch_next_set().\n $batch['sets'][] = array('form_submit' => $function);\n $batch['has_form_submits'] = TRUE;\n }\n else {\n $function($form, $form_state);\n }\n $return = TRUE;\n }\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ac9c5e9467", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_progress_bar/7.x", "instruction": "In Drupal 7, write the function `theme_progress_bar($variables)` (file includes/theme.inc) so that it does the following: Returns HTML for a progress bar.", "context": "Note that the core Batch API uses this only for non-JavaScript batch jobs.\n\nParameters:\n- $variables: An associative array containing: - percent: The percentage of the progress. - message: A string containing information to be displayed.\n\nFile: includes/theme.inc", "response": "function theme_progress_bar($variables) {\n $output = '
            ';\n $output .= '
            ';\n $output .= '
            ' . $variables['percent'] . '%
            ';\n $output .= '
            ' . $variables['message'] . '
            ';\n $output .= '
            ';\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-acb02ec731", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_wait/7.x", "instruction": "Implement `lock_wait($name, $delay = 30)` in PHP for Drupal 7. Required behavior: Wait for a lock to be available.", "context": "This function may be called in a request that fails to acquire a desired lock. This will block further execution until the lock is available or the specified delay in seconds is reached. This should not be used with locks that are acquired very frequently, since the lock is likely to be acquired again by a different request while waiting.\n\nParameters:\n- $name: The name of the lock.\n- $delay: The maximum number of seconds to wait, as an integer.\n\nReturns: TRUE if the lock holds, FALSE if it is available.\n\nFile: includes/lock.inc", "response": "function lock_wait($name, $delay = 30) {\n // Pause the process for short periods between calling\n // lock_may_be_available(). This prevents hitting the database with constant\n // database queries while waiting, which could lead to performance issues.\n // However, if the wait period is too long, there is the potential for a\n // large number of processes to be blocked waiting for a lock, especially\n // if the item being rebuilt is commonly requested. To address both of these\n // concerns, begin waiting for 25ms, then add 25ms to the wait period each\n // time until it reaches 500ms. After this point polling will continue every\n // 500ms until $delay is reached.\n\n // $delay is passed in seconds, but we will be using usleep(), which takes\n // microseconds as a parameter. Multiply it by 1 million so that all\n // further numbers are equivalent.\n $delay = (int) $delay * 1000000;\n\n // Begin sleeping at 25ms.\n $sleep = 25000;\n while ($delay > 0) {\n // This function should only be called by a request that failed to get a\n // lock, so we sleep first to give the parallel request a chance to finish\n // and release the lock.\n usleep($sleep);\n // After each sleep, increase the value of $sleep until it reaches\n // 500ms, to reduce the potential for a lock stampede.\n $delay = $delay - $sleep;\n $sleep = min(500000, $sleep + 25000, $delay);\n if (lock_may_be_available($name)) {\n // No longer need to wait.\n return FALSE;\n }\n }\n // The caller must still wait longer to get the lock.\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-acd0af653e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/_drupal_session_write/7.x", "instruction": "Implement `_drupal_session_write($sid, $value)` in PHP for Drupal 7. Required behavior: Writes an entire session to the database (internal use only).", "context": "This function is registered with session_set_save_handler() to support database-backed sessions.\n\nThis function is an internal function and must not be called directly. Doing so may result in corrupted session data or other unexpected behavior. Session data must always be accessed via the $_SESSION superglobal.\n\nParameters:\n- $sid: The session ID of the session to write to.\n- $value: Session data to write as a serialized string.\n\nReturns: Always returns TRUE.\n\nFile: includes/session.inc", "response": "function _drupal_session_write($sid, $value) {\n global $user, $is_https;\n\n // The exception handler is not active at this point, so we need to do it\n // manually.\n try {\n if (!drupal_save_session()) {\n // We don't have anything to do if we are not allowed to save the session.\n return TRUE;\n }\n\n // Check whether $_SESSION has been changed in this request.\n $last_read = &drupal_static('drupal_session_last_read');\n $is_changed = !isset($last_read) || $last_read['sid'] != $sid || $last_read['value'] !== $value;\n\n // For performance reasons, do not update the sessions table, unless\n // $_SESSION has changed or more than 180 has passed since the last update.\n if ($is_changed || !isset($user->timestamp) || REQUEST_TIME - $user->timestamp > variable_get('session_write_interval', 180)) {\n // Either ssid or sid or both will be added from $key below.\n $fields = array(\n 'uid' => $user->uid,\n 'cache' => isset($user->cache) ? $user->cache : 0,\n 'hostname' => ip_address(),\n 'session' => $value,\n 'timestamp' => REQUEST_TIME,\n );\n\n // Use the session ID as 'sid' and an empty string as 'ssid' by default.\n // _drupal_session_read() does not allow empty strings so that's a safe\n // default.\n $key = array('sid' => drupal_session_id($sid), 'ssid' => '');\n // On HTTPS connections, use the session ID as both 'sid' and 'ssid'.\n if ($is_https) {\n $key['ssid'] = drupal_session_id($sid);\n // The \"secure pages\" setting allows a site to simultaneously use both\n // secure and insecure session cookies. If enabled and both cookies are\n // presented then use both keys. The session ID from the cookie is\n // hashed before being stored in the database as a security measure.\n if (variable_get('https', FALSE)) {\n $insecure_session_name = substr(session_name(), 1);\n if (isset($_COOKIE[$insecure_session_name])) {\n $key['sid'] = drupal_session_id($_COOKIE[$insecure_session_name]);\n }\n }\n }\n elseif (variable_get('https', FALSE)) {\n unset($key['ssid']);\n }\n\n db_merge('sessions')\n ->key($key)\n ->fields($fields)\n ->execute();\n }\n\n // Likewise, do not update access time more than once per 180 seconds.\n if ($user->uid && REQUEST_TIME - $user->access > variable_get('session_write_interval', 180)) {\n db_update('users')\n ->fields(array(\n 'access' => REQUEST_TIME\n ))\n ->condition('uid', $user->uid)\n ->execute();\n }\n\n return TRUE;\n }\n catch (Exception $exception) {\n require_once DRUPAL_ROOT . '/includes/errors.inc';\n // If we are displaying errors, then do so with no possibility of a further\n // uncaught exception being thrown.\n if (error_displayable()) {\n print '

            Uncaught exception thrown in session handler.

            ';\n print '

            ' . _drupal_render_exception_safe($exception) . '


            ';\n }\n return FALSE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-acdba8bbc8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_revision_delete_confirm_submit/7.x", "instruction": "In Drupal 7, write the function `node_revision_delete_confirm_submit($form, &$form_state)` (file modules/node/node.pages.inc) so that it does the following: Form submission handler for node_revision_delete_confirm().", "context": "File: modules/node/node.pages.inc", "response": "function node_revision_delete_confirm_submit($form, &$form_state) {\n $node_revision = $form['#node_revision'];\n node_revision_delete($node_revision->vid);\n\n watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid));\n drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_type_get_name($node_revision), '%title' => $node_revision->title)));\n $form_state['redirect'] = 'node/' . $node_revision->nid;\n if (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchField() > 1) {\n $form_state['redirect'] .= '/revisions';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ace3d0ec2d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_field_delete_field/7.x", "instruction": "Implement `image_field_delete_field($field)` in PHP for Drupal 7. Required behavior: Implements hook_field_delete_field().", "context": "File: modules/image/image.module", "response": "function image_field_delete_field($field) {\n if ($field['type'] != 'image') {\n return;\n }\n\n // The value of a managed_file element can be an array if #extended == TRUE.\n $fid = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']);\n if ($fid && ($file = file_load($fid))) {\n file_usage_delete($file, 'image', 'default_image', $field['id']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ace7f778fa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/_drupal_session_garbage_collection/7.x", "instruction": "In Drupal 7, write the function `_drupal_session_garbage_collection($lifetime)` (file includes/session.inc) so that it does the following: Session handler assigned by session_set_save_handler().", "context": "Cleans up stalled sessions.\n\nParameters:\n- $lifetime: The value of session.gc_maxlifetime, passed by PHP. Sessions not updated for more than $lifetime seconds will be removed.\n\nFile: includes/session.inc", "response": "function _drupal_session_garbage_collection($lifetime) {\n // Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough\n // value. For example, if you want user sessions to stay in your database\n // for three weeks before deleting them, you need to set gc_maxlifetime\n // to '1814400'. At that value, only after a user doesn't log in after\n // three weeks (1814400 seconds) will his/her session be removed.\n db_delete('sessions')\n ->condition('timestamp', REQUEST_TIME - $lifetime, '<')\n ->execute();\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ace9d91ff4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_search_result/7.x", "instruction": "In Drupal 7, write the function `comment_node_search_result($node)` (file modules/comment/comment.module) so that it does the following: Implements hook_node_search_result().", "context": "Formats a comment count string and returns it, for display with search results.\n\nFile: modules/comment/comment.module", "response": "function comment_node_search_result($node) {\n // Do not make a string if comments are hidden.\n if (user_access('access comments') && $node->comment != COMMENT_NODE_HIDDEN) {\n $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();\n // Do not make a string if comments are closed and there are currently\n // zero comments.\n if ($node->comment != COMMENT_NODE_CLOSED || $comments > 0) {\n return array('comment' => format_plural($comments, '1 comment', '@count comments'));\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-acea67960f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_group_css/7.x", "instruction": "I need the code for `drupal_group_css($css)` in Drupal 7 (includes/common.inc). It must do this: Default callback to group CSS items.", "context": "This function arranges the CSS items that are in the #items property of the styles element into groups. Arranging the CSS items into groups serves two purposes. When aggregation is enabled, files within a group are aggregated into a single file, significantly improving page loading performance by minimizing network traffic overhead. When aggregation is disabled, grouping allows multiple files to be loaded from a single STYLE tag, enabling sites with many modules enabled or a complex theme being used to stay within IE's 31 CSS inclusion tag limit: http://drupal.org/node/228818.\n\nThis function puts multiple items into the same group if they are groupable and if they are for the same 'media' and 'browsers'. Items of the 'file' type are groupable if their 'preprocess' flag is TRUE, items of the 'inline' type are always groupable, and items of the 'external' type are never groupable. This function also ensures that the process of grouping items does not change their relative order. This requirement may result in multiple groups for the same type, media, and browsers, if needed to accommodate other items in between.\n\nParameters:\n- $css: An array of CSS items, as returned by drupal_add_css(), but after alteration performed by drupal_get_css().\n\nReturns: An array of CSS groups. Each group contains the same keys (e.g., 'media', 'data', etc.) as a CSS item from the $css parameter, with the value of each key applying to the group as a whole. Each group also contains an 'items' key, which is the subset of items from $css that are in the group.\n\nFile: includes/common.inc", "response": "function drupal_group_css($css) {\n $groups = array();\n // If a group can contain multiple items, we track the information that must\n // be the same for each item in the group, so that when we iterate the next\n // item, we can determine if it can be put into the current group, or if a\n // new group needs to be made for it.\n $current_group_keys = NULL;\n // When creating a new group, we pre-increment $i, so by initializing it to\n // -1, the first group will have index 0.\n $i = -1;\n foreach ($css as $item) {\n // The browsers for which the CSS item needs to be loaded is part of the\n // information that determines when a new group is needed, but the order of\n // keys in the array doesn't matter, and we don't want a new group if all\n // that's different is that order.\n ksort($item['browsers']);\n\n // If the item can be grouped with other items, set $group_keys to an array\n // of information that must be the same for all items in its group. If the\n // item can't be grouped with other items, set $group_keys to FALSE. We\n // put items into a group that can be aggregated together: whether they will\n // be aggregated is up to the _drupal_css_aggregate() function or an\n // override of that function specified in hook_css_alter(), but regardless\n // of the details of that function, a group represents items that can be\n // aggregated. Since a group may be rendered with a single HTML tag, all\n // items in the group must share the same information that would need to be\n // part of that HTML tag.\n switch ($item['type']) {\n case 'file':\n // Group file items if their 'preprocess' flag is TRUE.\n // Help ensure maximum reuse of aggregate files by only grouping\n // together items that share the same 'group' value and 'every_page'\n // flag. See drupal_add_css() for details about that.\n $group_keys = $item['preprocess'] ? array($item['type'], $item['group'], $item['every_page'], $item['media'], $item['browsers']) : FALSE;\n break;\n case 'inline':\n // Always group inline items.\n $group_keys = array($item['type'], $item['media'], $item['browsers']);\n break;\n case 'external':\n // Do not group external items.\n $group_keys = FALSE;\n break;\n }\n\n // If the group keys don't match the most recent group we're working with,\n // then a new group must be made.\n if ($group_keys !== $current_group_keys) {\n $i++;\n // Initialize the new group with the same properties as the first item\n // being placed into it. The item's 'data' and 'weight' properties are\n // unique to the item and should not be carried over to the group.\n $groups[$i] = $item;\n unset($groups[$i]['data'], $groups[$i]['weight']);\n $groups[$i]['items'] = array();\n $current_group_keys = $group_keys ? $group_keys : NULL;\n }\n\n // Add the item to the current group.\n $groups[$i]['items'][] = $item;\n }\n return $groups;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad0472d5f9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.install/function/trigger_install/7.x", "instruction": "I need the code for `trigger_install()` in Drupal 7 (modules/trigger/trigger.install). It must do this: Implements hook_install().", "context": "File: modules/trigger/trigger.install", "response": "function trigger_install() {\n // Do initial synchronization of actions in code and the database.\n actions_synchronize();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad069b832f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/_system_modules_build_row/7.x", "instruction": "In Drupal 7, write the function `_system_modules_build_row($info, $extra)` (file modules/system/system.admin.inc) so that it does the following: Build a table row for the system modules page.", "context": "File: modules/system/system.admin.inc", "response": "function _system_modules_build_row($info, $extra) {\n // Add in the defaults.\n $extra += array(\n 'requires' => array(),\n 'required_by' => array(),\n 'disabled' => FALSE,\n 'enabled' => FALSE,\n 'links' => array(),\n );\n $form = array(\n '#tree' => TRUE,\n );\n // Set the basic properties.\n $form['name'] = array(\n '#markup' => $info['name'],\n );\n $form['description'] = array(\n '#markup' => t($info['description']),\n );\n $form['version'] = array(\n '#markup' => $info['version'],\n );\n $form['#requires'] = $extra['requires'];\n $form['#required_by'] = $extra['required_by'];\n\n // Check the compatibilities.\n $compatible = TRUE;\n $status_short = '';\n $status_long = '';\n\n // Initialize empty arrays of long and short reasons explaining why the\n // module is incompatible.\n // Add each reason as a separate element in both the arrays.\n $reasons_short = array();\n $reasons_long = array();\n\n // Check the core compatibility.\n if (!isset($info['core']) || $info['core'] != DRUPAL_CORE_COMPATIBILITY) {\n $compatible = FALSE;\n $reasons_short[] = t('Incompatible with this version of Drupal core.');\n $reasons_long[] = t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => DRUPAL_CORE_COMPATIBILITY));\n }\n\n // Ensure this module is compatible with the currently installed version of PHP.\n if (version_compare(phpversion(), $info['php']) < 0) {\n $compatible = FALSE;\n $reasons_short[] = t('Incompatible with this version of PHP');\n $php_required = $info['php'];\n if (substr_count($info['php'], '.') < 2) {\n $php_required .= '.*';\n }\n $reasons_long[] = t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $php_required, '!php_version' => phpversion()));\n }\n\n // If this module is compatible, present a checkbox indicating\n // this module may be installed. Otherwise, show a big red X.\n if ($compatible) {\n $form['enable'] = array(\n '#type' => 'checkbox',\n '#title' => t('Enable'),\n '#default_value' => $extra['enabled'],\n );\n if ($extra['disabled']) {\n $form['enable']['#disabled'] = TRUE;\n }\n }\n else {\n $status_short = implode(' ', $reasons_short);\n $status_long = implode(' ', $reasons_long);\n $form['enable'] = array(\n '#markup' => theme('image', array('path' => 'misc/watchdog-error.png', 'alt' => $status_short, 'title' => $status_short)),\n );\n $form['description']['#markup'] .= theme('system_modules_incompatible', array('message' => $status_long));\n }\n\n // Build operation links.\n foreach (array('help', 'permissions', 'configure') as $key) {\n $form['links'][$key] = (isset($extra['links'][$key]) ? $extra['links'][$key] : array());\n }\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad0c8e6b74", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_help/7.x", "instruction": "I need the code for `forum_help($path, $arg)` in Drupal 7 (modules/forum/forum.module). It must do this: Implements hook_help().", "context": "File: modules/forum/forum.module", "response": "function forum_help($path, $arg) {\n switch ($path) {\n case 'admin/help#forum':\n $output = '';\n $output .= '

            ' . t('About') . '

            ';\n $output .= '

            ' . t('The Forum module lets you create threaded discussion forums with functionality similar to other message board systems. Forums are useful because they allow community members to discuss topics with one another while ensuring those conversations are archived for later reference. In a forum, users post topics and threads in nested hierarchies, allowing discussions to be categorized and grouped. The forum hierarchy consists of:') . '

            ';\n $output .= '
              ';\n $output .= '
            • ' . t('Optional containers (for example, Support), which can hold:') . '
            • ';\n $output .= '
              • ' . t('Forums (for example, Installing Drupal), which can hold:') . '
              • ';\n $output .= '
                • ' . t('Forum topics submitted by users (for example, How to start a Drupal 6 Multisite), which start discussions and are starting points for:') . '
                • ';\n $output .= '
                  • ' . t('Threaded comments submitted by users (for example, You have these options...).') . '
                  • ';\n $output .= '
                  ';\n $output .= '
                ';\n $output .= '
              ';\n $output .= '
            ';\n $output .= '

            ' . t('For more information, see the online handbook entry for Forum module.', array('@forum' => 'http://drupal.org/documentation/modules/forum')) . '

            ';\n $output .= '

            ' . t('Uses') . '

            ';\n $output .= '
            ';\n $output .= '
            ' . t('Setting up forum structure') . '
            ';\n $output .= '
            ' . t('Visit the Forums page to set up containers and forums to hold your discussion topics.', array('@forums' => url('admin/structure/forum'))) . '
            ';\n $output .= '
            ' . t('Starting a discussion') . '
            ';\n $output .= '
            ' . t('The Forum topic link on the Add new content page creates the first post of a new threaded discussion, or thread.', array('@create-topic' => url('node/add/forum'), '@content-add' => url('node/add'))) . '
            ';\n $output .= '
            ' . t('Navigation') . '
            ';\n $output .= '
            ' . t('Enabling the Forum module provides a default Forums menu item in the navigation menu that links to the Forums page.', array('@forums' => url('forum'))) . '
            ';\n $output .= '
            ' . t('Moving forum topics') . '
            ';\n $output .= '
            ' . t('A forum topic (and all of its comments) may be moved between forums by selecting a different forum while editing a forum topic. When moving a forum topic between forums, the Leave shadow copy option creates a link in the original forum pointing to the new location.') . '
            ';\n $output .= '
            ' . t('Locking and disabling comments') . '
            ';\n $output .= '
            ' . t('Selecting Closed under Comment settings while editing a forum topic will lock (prevent new comments on) the thread. Selecting Hidden under Comment settings while editing a forum topic will hide all existing comments on the thread, and prevent new ones.') . '
            ';\n $output .= '
            ';\n return $output;\n case 'admin/structure/forum':\n $output = '

            ' . t('Forums contain forum topics. Use containers to group related forums.') . '

            ';\n $output .= theme('more_help_link', array('url' => 'admin/help/forum'));\n return $output;\n case 'admin/structure/forum/add/container':\n return '

            ' . t('Use containers to group related forums.') . '

            ';\n case 'admin/structure/forum/add/forum':\n return '

            ' . t('A forum holds related forum topics.') . '

            ';\n case 'admin/structure/forum/settings':\n return '

            ' . t('Adjust the display of your forum topics. Organize the forums on the forum structure page.', array('@forum-structure' => url('admin/structure/forum'))) . '

            ';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad132e3ef2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/_image_field_resolution_validate/7.x", "instruction": "I need the code for `_image_field_resolution_validate($element, &$form_state)` in Drupal 7 (modules/image/image.field.inc). It must do this: Element validate function for resolution fields.", "context": "File: modules/image/image.field.inc", "response": "function _image_field_resolution_validate($element, &$form_state) {\n if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) {\n foreach (array('x', 'y') as $dimension) {\n $value = $element[$dimension]['#value'];\n if (!is_numeric($value)) {\n form_error($element[$dimension], t('Height and width values must be numeric.'));\n return;\n }\n if (intval($value) < 0) {\n form_error($element[$dimension], t('Height and width values must be positive numbers.'));\n return;\n }\n if (intval($value) == 0) {\n form_error($element[$dimension], t('Both a height and width value must be specified in the !name field.', array('!name' => $element['#title'])));\n return;\n }\n }\n form_set_value($element, intval($element['x']['#value']) . 'x' . intval($element['y']['#value']), $form_state);\n }\n else {\n form_set_value($element, '', $form_state);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad17fc506b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_import_locales_remaining/7.x", "instruction": "Implement `install_import_locales_remaining(&$install_state)` in PHP for Drupal 7. Required behavior: Installation task; import remaining languages via a batch process.", "context": "Parameters:\n- $install_state: An array of information about the current installation state.\n\nReturns: The batch definition, if there are language files to import.\n\nFile: includes/install.core.inc", "response": "function install_import_locales_remaining(&$install_state) {\n include_once DRUPAL_ROOT . '/includes/locale.inc';\n // Collect files to import for this language. Skip components already covered\n // in the initial batch set.\n $install_locale = $install_state['parameters']['locale'];\n $batch = locale_batch_by_language($install_locale, NULL, variable_get('install_locale_batch_components', array()));\n // Remove temporary variable.\n variable_del('install_locale_batch_components');\n return $batch;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad2c071117", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_display_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_display_alter(&$display, $context)` (modules/field/field.api.php): Alters the display settings of a field before it gets displayed.", "context": "Note that instead of hook_field_display_alter(), which is called for all fields on all entity types, hook_field_display_ENTITY_TYPE_alter() may be used to alter display settings for fields on a specific entity type only.\n\nThis hook is called once per field per displayed entity. If the result of the hook involves reading from the database, it is highly recommended to statically cache the information.\n\nParameters:\n- $display: The display settings that will be used to display the field values, as found in the 'display' key of $instance definitions.\n- $context: An associative array containing: - entity_type: The entity type; e.g., 'node' or 'user'. - field: The field being rendered. - instance: The instance being rendered. - entity: The entity being rendered. - view_mode: The view mode, e.g. 'full', 'teaser'...\n\nFile: modules/field/field.api.php", "response": "function hook_field_display_alter(&$display, $context) {\n // Leave field labels out of the search index.\n // Note: The check against $context['entity_type'] == 'node' could be avoided\n // by using hook_field_display_node_alter() instead of\n // hook_field_display_alter(), resulting in less function calls when\n // rendering non-node entities.\n if ($context['entity_type'] == 'node' && $context['view_mode'] == 'search_index') {\n $display['label'] = 'hidden';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad2c3c080c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_field/7.x", "instruction": "In Drupal 7, write the function `rdf_preprocess_field(&$variables)` (file modules/rdf/rdf.module) so that it does the following: Implements MODULE_preprocess_HOOK().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_preprocess_field(&$variables) {\n $element = $variables['element'];\n $mapping = rdf_mapping_load($element['#entity_type'], $element['#bundle']);\n $field_name = $element['#field_name'];\n\n if (!empty($mapping) && !empty($mapping[$field_name])) {\n foreach ($element['#items'] as $delta => $item) {\n $variables['item_attributes_array'][$delta] = rdf_rdfa_attributes($mapping[$field_name], $item);\n // If this field is an image, RDFa will not output correctly when the\n // image is in a containing tag. If the field is a file, RDFa will\n // not output correctly if the filetype icon comes before the link to the\n // file. We correct this by adding a resource attribute to the div if\n // this field has a URI.\n if (isset($item['uri'])) {\n if (!empty($element[$delta]['#image_style'])) {\n $variables['item_attributes_array'][$delta]['resource'] = image_style_url($element[$delta]['#image_style'], $item['uri']);\n }\n else {\n $variables['item_attributes_array'][$delta]['resource'] = file_create_url($item['uri']);\n }\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad53f20d52", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_array_merge_deep_array/7.x", "instruction": "Implement `drupal_array_merge_deep_array($arrays)` in PHP for Drupal 7. Required behavior: Merges multiple arrays, recursively, and returns the merged array.", "context": "This function is equivalent to drupal_array_merge_deep(), except the input arrays are passed as a single array parameter rather than a variable parameter list.\n\nThe following are equivalent:\n- drupal_array_merge_deep($a, $b);\n- drupal_array_merge_deep_array(array($a, $b));\n\nThe following are also equivalent:\n- call_user_func_array('drupal_array_merge_deep', $arrays_to_merge);\n- drupal_array_merge_deep_array($arrays_to_merge);\n\nFile: includes/bootstrap.inc", "response": "function drupal_array_merge_deep_array($arrays) {\n $result = array();\n\n foreach ($arrays as $array) {\n foreach ($array as $key => $value) {\n // Renumber integer keys as array_merge_recursive() does. Note that PHP\n // automatically converts array keys that are integer strings (e.g., '1')\n // to integers.\n if (is_integer($key)) {\n $result[] = $value;\n }\n // Recurse when both values are arrays.\n elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {\n $result[$key] = drupal_array_merge_deep_array(array($result[$key], $value));\n }\n // Otherwise, use the latter value, overriding any previous value.\n else {\n $result[$key] = $value;\n }\n }\n }\n\n return $result;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad589a0e70", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21image.inc/function/image_scale/7.x", "instruction": "In Drupal 7, write the function `image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = FALSE)` (file includes/image.inc) so that it does the following: Scales an image while maintaining aspect ratio.", "context": "The resulting image can be smaller for one or both target dimensions.\n\nParameters:\n- $image: An image object returned by image_load().\n- $width: The target width, in pixels. If this value is NULL then the scaling will be based only on the height value.\n- $height: The target height, in pixels. If this value is NULL then the scaling will be based only on the width value.\n- $upscale: Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image.\n\nReturns: TRUE on success, FALSE on failure.\n\nFile: includes/image.inc", "response": "function image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = FALSE) {\n $dimensions = $image->info;\n\n // Scale the dimensions - if they don't change then just return success.\n if (!image_dimensions_scale($dimensions, $width, $height, $upscale)) {\n return TRUE;\n }\n\n return image_resize($image, $dimensions['width'], $dimensions['height']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad5902660d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_access_records/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_node_access_records($node)` (modules/node/node.api.php): Set permissions for a node to be written to the database.", "context": "When a node is saved, a module implementing hook_node_access_records() will be asked if it is interested in the access permissions for a node. If it is interested, it must respond with an array of permissions arrays for that node.\n\nNode access grants apply regardless of the published or unpublished status of the node. Implementations must make sure not to grant access to unpublished nodes if they don't want to change the standard access control behavior. Your module may need to create a separate access realm to handle access to unpublished nodes.\n\nNote that the grant values in the return value from your hook must be integers and not boolean TRUE and FALSE.\n\nEach permissions item in the array is an array with the following elements:\n- 'realm': The name of a realm that the module has defined in\n hook_node_grants().\n- 'gid': A 'grant ID' from hook_node_grants().\n- 'grant_view': If set to 1 a user that has been identified as a member\n of this gid within this realm can view this node. This should usually be\n set to $node->status. Failure to do so may expose unpublished content\n to some users.\n- 'grant_update': If set to 1 a user that has been identified as a member\n of this gid within this realm can edit this node.\n- 'grant_delete': If set to 1 a user that has been identified as a member\n of this gid within this realm can delete this node.\n- 'priority': If multiple modules seek to set permissions on a node, the\n realms that have the highest priority will win out, and realms with a lower\n priority will not be written. If there is any doubt, it is best to\n leave this 0.\n\nWhen an implementation is interested in a node but want to deny access to everyone, it may return a \"deny all\" grant:\n\nParameters:\n- $node: The node that has just been saved.\n\nReturns: An array of grants as defined above.\n\nFile: modules/node/node.api.php", "response": "function hook_node_access_records($node) {\n // We only care about the node if it has been marked private. If not, it is\n // treated just like any other node and we completely ignore it.\n if ($node->private) {\n $grants = array();\n // Only published nodes should be viewable to all users. If we allow access\n // blindly here, then all users could view an unpublished node.\n if ($node->status) {\n $grants[] = array(\n 'realm' => 'example',\n 'gid' => 1,\n 'grant_view' => 1,\n 'grant_update' => 0,\n 'grant_delete' => 0,\n 'priority' => 0,\n );\n }\n // For the example_author array, the GID is equivalent to a UID, which\n // means there are many groups of just 1 user.\n // Note that an author can always view his or her nodes, even if they\n // have status unpublished.\n $grants[] = array(\n 'realm' => 'example_author',\n 'gid' => $node->uid,\n 'grant_view' => 1,\n 'grant_update' => 1,\n 'grant_delete' => 1,\n 'priority' => 0,\n );\n\n return $grants;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad88ccbe83", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_user_cancel/7.x", "instruction": "In Drupal 7, write the function `node_user_cancel($edit, $account, $method)` (file modules/node/node.module) so that it does the following: Implements hook_user_cancel().", "context": "File: modules/node/node.module", "response": "function node_user_cancel($edit, $account, $method) {\n switch ($method) {\n case 'user_cancel_block_unpublish':\n // Unpublish nodes (current revisions).\n module_load_include('inc', 'node', 'node.admin');\n $nodes = db_select('node', 'n')\n ->fields('n', array('nid'))\n ->condition('uid', $account->uid)\n ->execute()\n ->fetchCol();\n node_mass_update($nodes, array('status' => 0));\n break;\n\n case 'user_cancel_reassign':\n // Anonymize nodes (current revisions).\n module_load_include('inc', 'node', 'node.admin');\n $nodes = db_select('node', 'n')\n ->fields('n', array('nid'))\n ->condition('uid', $account->uid)\n ->execute()\n ->fetchCol();\n node_mass_update($nodes, array('uid' => 0));\n // Anonymize old revisions.\n db_update('node_revision')\n ->fields(array('uid' => 0))\n ->condition('uid', $account->uid)\n ->execute();\n // Clean history.\n db_delete('history')\n ->condition('uid', $account->uid)\n ->execute();\n break;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ad98a3ab87", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.install/function/field_update_7004/7.x", "instruction": "Implement `field_update_7004()` in PHP for Drupal 7. Required behavior: Grant the new \"administer fields\" permission to trusted users.", "context": "File: modules/field/field.install", "response": "function field_update_7004() {\n // Assign the permission to anyone that already has a trusted core permission\n // that would have previously let them administer fields on an entity type.\n $rids = array();\n $permissions = array(\n 'administer site configuration',\n 'administer content types',\n 'administer users',\n );\n foreach ($permissions as $permission) {\n $rids = array_merge($rids, array_keys(user_roles(FALSE, $permission)));\n }\n $rids = array_unique($rids);\n foreach ($rids as $rid) {\n _update_7000_user_role_grant_permissions($rid, array('administer fields'), 'field');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ada8ad4772", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_show_disabled/7.x", "instruction": "In Drupal 7, write the function `dashboard_show_disabled()` (file modules/dashboard/dashboard.module) so that it does the following: Ajax callback: Shows disabled blocks in the dashboard customization mode.", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_show_disabled() {\n global $theme_key;\n\n // Blocks are not necessarily initialized at this point.\n $blocks = _block_rehash();\n\n // Limit the list to blocks that are marked as disabled for the dashboard.\n foreach ($blocks as $key => $block) {\n if ($block['theme'] != $theme_key || $block['region'] != 'dashboard_inactive') {\n unset($blocks[$key]);\n }\n }\n\n // Theme the output and end the page request.\n print theme('dashboard_disabled_blocks', array('blocks' => $blocks));\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-adc7de11fe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.tokens.inc/function/comment_token_info/7.x", "instruction": "I need the code for `comment_token_info()` in Drupal 7 (modules/comment/comment.tokens.inc). It must do this: Implements hook_token_info().", "context": "File: modules/comment/comment.tokens.inc", "response": "function comment_token_info() {\n $type = array(\n 'name' => t('Comments'),\n 'description' => t('Tokens for comments posted on the site.'),\n 'needs-data' => 'comment',\n );\n\n // Comment-related tokens for nodes\n $node['comment-count'] = array(\n 'name' => t(\"Comment count\"),\n 'description' => t(\"The number of comments posted on a node.\"),\n );\n $node['comment-count-new'] = array(\n 'name' => t(\"New comment count\"),\n 'description' => t(\"The number of comments posted on a node since the reader last viewed it.\"),\n );\n\n // Core comment tokens\n $comment['cid'] = array(\n 'name' => t(\"Comment ID\"),\n 'description' => t(\"The unique ID of the comment.\"),\n );\n $comment['hostname'] = array(\n 'name' => t(\"IP Address\"),\n 'description' => t(\"The IP address of the computer the comment was posted from.\"),\n );\n $comment['name'] = array(\n 'name' => t(\"Name\"),\n 'description' => t(\"The name left by the comment author.\"),\n );\n $comment['mail'] = array(\n 'name' => t(\"Email address\"),\n 'description' => t(\"The email address left by the comment author.\"),\n );\n $comment['homepage'] = array(\n 'name' => t(\"Home page\"),\n 'description' => t(\"The home page URL left by the comment author.\"),\n );\n $comment['title'] = array(\n 'name' => t(\"Title\"),\n 'description' => t(\"The title of the comment.\"),\n );\n $comment['body'] = array(\n 'name' => t(\"Content\"),\n 'description' => t(\"The formatted content of the comment itself.\"),\n );\n $comment['url'] = array(\n 'name' => t(\"URL\"),\n 'description' => t(\"The URL of the comment.\"),\n );\n $comment['edit-url'] = array(\n 'name' => t(\"Edit URL\"),\n 'description' => t(\"The URL of the comment's edit page.\"),\n );\n\n // Chained tokens for comments\n $comment['created'] = array(\n 'name' => t(\"Date created\"),\n 'description' => t(\"The date the comment was posted.\"),\n 'type' => 'date',\n );\n $comment['changed'] = array(\n 'name' => t(\"Date changed\"),\n 'description' => t(\"The date the comment was most recently updated.\"),\n 'type' => 'date',\n );\n $comment['parent'] = array(\n 'name' => t(\"Parent\"),\n 'description' => t(\"The comment's parent, if comment threading is active.\"),\n 'type' => 'comment',\n );\n $comment['node'] = array(\n 'name' => t(\"Node\"),\n 'description' => t(\"The node the comment was posted to.\"),\n 'type' => 'node',\n );\n $comment['author'] = array(\n 'name' => t(\"Author\"),\n 'description' => t(\"The author of the comment, if they were logged in.\"),\n 'type' => 'user',\n );\n\n return array(\n 'types' => array('comment' => $type),\n 'tokens' => array(\n 'node' => $node,\n 'comment' => $comment,\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-add6d1ef0a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_is_relevant_item/7.x", "instruction": "Implement `announcements_feed_is_relevant_item($version)` in PHP for Drupal 7. Required behavior: Check whether the version given is relevant to the Drupal version used.", "context": "Parameters:\n- $version (string): Version to check.\n\nReturns (bool): Return TRUE if the version matches Drupal version.\n\nFile: modules/announcements_feed/announcements_feed.inc", "response": "function announcements_feed_is_relevant_item($version) {\n if ($version == '*') {\n return TRUE;\n }\n // Split the version if received in || formats.\n $version_patterns = '/\\|\\|/';\n $all_versions = preg_split($version_patterns, $version);\n // The operation is optional and defaults to equals.\n $p_op = '(?P!=|\\^|==|=|<|<=|>|>=|<>)?';\n $operations = '=';\n // Extracts major version from version string like 7, 8, 9.\n $p_major = '(?P\\d+)';\n // Extracts minor version from version string.\n $p_minor = '(?P(?:\\d+|x)(?:-[A-Za-z]+\\d+)?)';\n foreach ($all_versions as $version) {\n if (preg_match(\"/^\\s*$p_op\\s*$p_major(\\.$p_minor)?/\", $version, $matches)) {\n $feed_version = $matches['major'];\n if (!empty($matches['minor'])) {\n $feed_version = $matches['major'] . '.' . $matches['minor'];\n }\n if (!empty($matches['operation'])) {\n $operations = $matches['operation'];\n if ($operations == '^') {\n $operations = '>=';\n }\n }\n if (isset($operations) && version_compare(VERSION, $feed_version, $operations)) {\n return TRUE;\n }\n }\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-add73aa4c9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_get_namespaces/7.x", "instruction": "I need the code for `rdf_get_namespaces()` in Drupal 7 (modules/rdf/rdf.module). It must do this: Returns an array of RDF namespaces defined in modules that implement hook_rdf_namespaces().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_get_namespaces() {\n $rdf_namespaces = module_invoke_all('rdf_namespaces');\n // module_invoke_all() uses array_merge_recursive() which might return nested\n // arrays if several modules redefine the same prefix multiple times. We need\n // to ensure the array of namespaces is flat and only contains strings as\n // URIs.\n foreach ($rdf_namespaces as $prefix => $uri) {\n if (is_array($uri)) {\n if (count(array_unique($uri)) == 1) {\n // All namespaces declared for this prefix are the same, merge them all\n // into a single namespace.\n $rdf_namespaces[$prefix] = $uri[0];\n }\n else {\n // There are conflicting namespaces for this prefix, do not include\n // duplicates in order to avoid asserting any inaccurate RDF\n // statements.\n unset($rdf_namespaces[$prefix]);\n }\n }\n }\n return $rdf_namespaces;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ade59489af", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_date_formats/7.x", "instruction": "In Drupal 7, write the function `system_date_formats()` (file modules/system/system.module) so that it does the following: Implements hook_date_formats().", "context": "File: modules/system/system.module", "response": "function system_date_formats() {\n include_once DRUPAL_ROOT . '/includes/date.inc';\n return system_default_date_formats();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-adf20d7afb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.api.php/function/hook_rdf_mapping/7.x", "instruction": "Give me the example code for `hook_rdf_mapping()` in Drupal 7. Hook description: Allow modules to define RDF mappings for field bundles.", "context": "Modules defining their own field bundles can specify which RDF semantics should be used to annotate these bundles. These mappings are then used for automatic RDFa output in the HTML code.\n\nReturns: A list of mapping structures, where each mapping is an associative array: - type: The name of an entity type (e.g., 'node', 'comment', and so on.) - bundle: The name of the bundle (e.g., 'page', 'blog', or RDF_DEFAULT_BUNDLE for default mappings.) - mapping: The mapping structure which applies to the entity type and bundle. A mapping structure is an array with keys corresponding to existing field instances in the bundle. Each field is then described in terms of the RDF mapping: - predicates: An array of RDF predicates which describe the relation between the bundle (RDF subject) and the value of the field (RDF object). This value is either some text, another bundle, or a URI in general. - datatype: Is used along with 'callback' to format data so that it is readable by machines. A typical example is a date which can be written in many different formats but should be translated into a uniform format for machine consumption. - callback: A function name to invoke for 'datatype'. - type: A string used to determine the type of RDFa markup which will be used in the final HTML output, depending on whether the RDF object is a literal text or another RDF resource. - rdftype: A special property used to define the type of the instance. Its value should be an array of RDF classes. @ingroup rdf\n\nFile: modules/rdf/rdf.api.php", "response": "function hook_rdf_mapping() {\n return array(\n array(\n 'type' => 'node',\n 'bundle' => 'blog',\n 'mapping' => array(\n 'rdftype' => array('sioct:Weblog'),\n 'title' => array(\n 'predicates' => array('dc:title'),\n ),\n 'created' => array(\n 'predicates' => array('dc:date', 'dc:created'),\n 'datatype' => 'xsd:dateTime',\n 'callback' => 'date_iso8601',\n ),\n 'body' => array(\n 'predicates' => array('content:encoded'),\n ),\n 'uid' => array(\n 'predicates' => array('sioc:has_creator'),\n 'type' => 'rel',\n ),\n 'name' => array(\n 'predicates' => array('foaf:name'),\n ),\n ),\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae12e818d7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_updaters/7.x", "instruction": "Implement `drupal_get_updaters()` in PHP for Drupal 7. Required behavior: Assembles the Drupal Updater registry.", "context": "An Updater is a class that knows how to update various parts of the Drupal file system, for example to update modules that have newer releases, or to install a new theme.\n\nReturns: The Drupal Updater class registry.\n\nFile: includes/common.inc", "response": "function drupal_get_updaters() {\n $updaters = &drupal_static(__FUNCTION__);\n if (!isset($updaters)) {\n $updaters = module_invoke_all('updater_info');\n drupal_alter('updater_info', $updaters);\n uasort($updaters, 'drupal_sort_weight');\n }\n return $updaters;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae16209199", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_file_download_access/7.x", "instruction": "I need the code for `user_file_download_access($field, $entity_type, $entity)` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_file_download_access().", "context": "File: modules/user/user.module", "response": "function user_file_download_access($field, $entity_type, $entity) {\n if ($entity_type == 'user') {\n return user_view_access($entity);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae1826fd8a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_find_locales/7.x", "instruction": "Implement `install_find_locales($profilename)` in PHP for Drupal 7. Required behavior: Find all .po files for the current profile.", "context": "File: includes/install.core.inc", "response": "function install_find_locales($profilename) {\n $locales = file_scan_directory('./profiles/' . $profilename . '/translations', '/\\.po$/', array('recurse' => FALSE));\n array_unshift($locales, (object) array('name' => 'en'));\n foreach ($locales as $key => $locale) {\n // The locale (file name) might be drupal-7.2.cs.po instead of cs.po.\n $locales[$key]->langcode = preg_replace('!^(.+\\.)?([^\\.]+)$!', '\\2', $locale->name);\n // Language codes cannot exceed 12 characters to fit into the {languages}\n // table.\n if (strlen($locales[$key]->langcode) > 12) {\n unset($locales[$key]);\n }\n }\n return $locales;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae1d12935b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_filter_form_validate/7.x", "instruction": "In Drupal 7, write the function `dblog_filter_form_validate($form, &$form_state)` (file modules/dblog/dblog.admin.inc) so that it does the following: Form validation handler for dblog_filter_form().", "context": "File: modules/dblog/dblog.admin.inc", "response": "function dblog_filter_form_validate($form, &$form_state) {\n if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['type']) && empty($form_state['values']['severity'])) {\n form_set_error('type', t('You must select something to filter by.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae2aa85346", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_purge_field_instance/7.x", "instruction": "Give me the example code for `hook_field_storage_purge_field_instance($instance)` in Drupal 7. Hook description: Remove field storage information when a field instance is purged.", "context": "Called from field_purge_instance() to allow the field storage module to remove field instance information when a field instance is being purged.\n\nParameters:\n- $instance: The instance being purged.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_purge_field_instance($instance) {\n db_delete('my_module_field_instance_info')\n ->condition('id', $instance['id'])\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae30f0994e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_deliver_html_page/7.x", "instruction": "I need the code for `drupal_deliver_html_page($page_callback_result)` in Drupal 7 (includes/common.inc). It must do this: Packages and sends the result of a page callback to the browser as HTML.", "context": "Parameters:\n- $page_callback_result: The result of a page callback. Can be one of: - NULL: to indicate no content. - An integer menu status constant: to indicate an error condition. - A string of HTML content. - A renderable array of content.\n\nFile: includes/common.inc", "response": "function drupal_deliver_html_page($page_callback_result) {\n // Emit the correct charset HTTP header, but not if the page callback\n // result is NULL, since that likely indicates that it printed something\n // in which case, no further headers may be sent, and not if code running\n // for this page request has already set the content type header.\n if (isset($page_callback_result) && is_null(drupal_get_http_header('Content-Type'))) {\n drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');\n }\n\n // Send appropriate HTTP-Header for browsers and search engines.\n global $language;\n drupal_add_http_header('Content-Language', $language->language);\n\n // By default, do not allow the site to be rendered in an iframe on another\n // domain, but provide a variable to override this. If the code running for\n // this page request already set the X-Frame-Options header earlier, don't\n // overwrite it here.\n $frame_options = variable_get('x_frame_options', 'SAMEORIGIN');\n if ($frame_options && is_null(drupal_get_http_header('X-Frame-Options'))) {\n drupal_add_http_header('X-Frame-Options', $frame_options);\n }\n drupal_add_http_header('X-Content-Type-Options', 'nosniff');\n\n // Menu status constants are integers; page content is a string or array.\n if (is_int($page_callback_result)) {\n // @todo: Break these up into separate functions?\n switch ($page_callback_result) {\n case MENU_NOT_FOUND:\n // Print a 404 page.\n drupal_add_http_header('Status', '404 Not Found');\n\n watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);\n\n // Check for and return a fast 404 page if configured.\n drupal_fast_404();\n\n // Keep old path for reference, and to allow forms to redirect to it.\n if (!isset($_GET['destination'])) {\n // Make sure that the current path is not interpreted as external URL.\n if (!url_is_external($_GET['q'])) {\n $_GET['destination'] = $_GET['q'];\n }\n }\n\n $path = drupal_get_normal_path(variable_get('site_404', ''));\n if ($path && $path != $_GET['q']) {\n // Custom 404 handler. Set the active item in case there are tabs to\n // display, or other dependencies on the path.\n menu_set_active_item($path);\n $return = menu_execute_active_handler($path, FALSE);\n }\n\n if (empty($return) || $return == MENU_NOT_FOUND || $return == MENU_ACCESS_DENIED) {\n // Standard 404 handler.\n drupal_set_title(t('Page not found'));\n $return = t('The requested page \"@path\" could not be found.', array('@path' => request_uri()));\n }\n\n drupal_set_page_content($return);\n $page = element_info('page');\n print drupal_render_page($page);\n break;\n\n case MENU_ACCESS_DENIED:\n // Print a 403 page.\n drupal_add_http_header('Status', '403 Forbidden');\n watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);\n\n // Keep old path for reference, and to allow forms to redirect to it.\n if (!isset($_GET['destination'])) {\n // Make sure that the current path is not interpreted as external URL.\n if (!url_is_external($_GET['q'])) {\n $_GET['destination'] = $_GET['q'];\n }\n }\n\n $path = drupal_get_normal_path(variable_get('site_403', ''));\n if ($path && $path != $_GET['q']) {\n // Custom 403 handler. Set the active item in case there are tabs to\n // display or other dependencies on the path.\n menu_set_active_item($path);\n $return = menu_execute_active_handler($path, FALSE);\n }\n\n if (empty($return) || $return == MENU_NOT_FOUND || $return == MENU_ACCESS_DENIED) {\n // Standard 403 handler.\n drupal_set_title(t('Access denied'));\n $return = t('You are not authorized to access this page.');\n }\n\n print drupal_render_page($return);\n break;\n\n case MENU_SITE_OFFLINE:\n // Print a 503 page.\n drupal_maintenance_theme();\n drupal_add_http_header('Status', '503 Service unavailable');\n drupal_set_title(t('Site under maintenance'));\n print theme('maintenance_page', array('content' => filter_xss_admin(variable_get('maintenance_mode_message',\n t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))))));\n break;\n }\n }\n elseif (isset($page_callback_result)) {\n // Print anything besides a menu constant, assuming it's not NULL or\n // undefined.\n print drupal_render_page($page_callback_result);\n }\n\n // Perform end-of-request tasks.\n drupal_page_footer();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae5ab65e6a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/_drupal_http_use_proxy/7.x", "instruction": "In Drupal 7, write the function `_drupal_http_use_proxy($host)` (file includes/common.inc) so that it does the following: Helper function for determining hosts excluded from needing a proxy.", "context": "Returns: TRUE if a proxy should be used for this host.\n\nFile: includes/common.inc", "response": "function _drupal_http_use_proxy($host) {\n $proxy_exceptions = variable_get('proxy_exceptions', array('localhost', '127.0.0.1'));\n return !in_array(strtolower($host), $proxy_exceptions, TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae61e27936", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_preprocess_html/7.x", "instruction": "Implement `overlay_preprocess_html(&$variables)` in PHP for Drupal 7. Required behavior: Implements hook_preprocess_html().", "context": "If the current page request is inside the overlay, add appropriate classes to the element, and simplify the page title.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_preprocess_html(&$variables) {\n if (overlay_get_mode() == 'child') {\n // Add overlay class, so themes can react to being displayed in the overlay.\n $variables['classes_array'][] = 'overlay';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ae634944f4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_form/7.x", "instruction": "Implement `theme_form($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a form.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #action, #method, #attributes, #children\n\nFile: includes/form.inc", "response": "function theme_form($variables) {\n $element = $variables['element'];\n if (isset($element['#action'])) {\n $element['#attributes']['action'] = drupal_strip_dangerous_protocols($element['#action']);\n }\n element_set_attributes($element, array('method', 'id'));\n if (empty($element['#attributes']['accept-charset'])) {\n $element['#attributes']['accept-charset'] = \"UTF-8\";\n }\n // Anonymous DIV to satisfy XHTML compliance.\n return '
            ' . $element['#children'] . '
            ';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aeb858fd46", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_themes_disabled/7.x", "instruction": "In Drupal 7, write the function `update_themes_disabled($themes)` (file modules/update/update.module) so that it does the following: Implements hook_themes_disabled().", "context": "If themes are disabled, we invalidate the cache of available updates.\n\nFile: modules/update/update.module", "response": "function update_themes_disabled($themes) {\n // Clear all update module caches.\n _update_cache_clear();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-aec1f65be9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_rebuild/7.x", "instruction": "Implement `menu_rebuild()` in PHP for Drupal 7. Required behavior: Populates the database tables used by various menu functions.", "context": "This function will clear and populate the {menu_router} table, add entries to {menu_links} for new router items, and then remove stale items from {menu_links}. If called from update.php or install.php, it will also schedule a call to itself on the first real page load from menu_execute_active_handler(), because the maintenance page environment is different and leaves stale data in the menu tables.\n\nReturns: TRUE if the menu was rebuilt, FALSE if another thread was rebuilding in parallel and the current thread just waited for completion.\n\nFile: includes/menu.inc", "response": "function menu_rebuild() {\n if (!lock_acquire('menu_rebuild')) {\n // Wait for another request that is already doing this work.\n // We choose to block here since otherwise the router item may not\n // be available in menu_execute_active_handler() resulting in a 404.\n lock_wait('menu_rebuild');\n\n if (_menu_check_rebuild()) {\n // If we get here and menu_masks was not set, then it is possible a menu\n // is being reloaded, or that the process rebuilding the menu was unable\n // to complete successfully. A missing menu_masks variable could result\n // in a 404, so re-run the function.\n return menu_rebuild();\n }\n return FALSE;\n }\n\n $transaction = db_transaction();\n\n try {\n list($menu, $masks) = menu_router_build();\n _menu_router_save($menu, $masks);\n _menu_navigation_links_rebuild($menu);\n // Clear the menu, page and block caches.\n menu_cache_clear_all();\n _menu_clear_page_cache();\n\n if (defined('MAINTENANCE_MODE')) {\n variable_set('menu_rebuild_needed', TRUE);\n }\n else {\n variable_del('menu_rebuild_needed');\n }\n }\n catch (Exception $e) {\n $transaction->rollback();\n watchdog_exception('menu', $e);\n }\n // Explicitly commit the transaction now; this ensures that the database\n // operations during the menu rebuild are committed before the lock is made\n // available again, since locks may not always reside in the same database\n // connection. The lock is acquired outside of the transaction so should also\n // be released outside of it.\n unset($transaction);\n\n lock_release('menu_rebuild');\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-aec2c0fd1f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/format_username/7.x", "instruction": "Implement `format_username($account)` in PHP for Drupal 7. Required behavior: Format a username.", "context": "This is also the label callback implementation of callback_entity_info_label() for user_entity_info().\n\nBy default, the passed-in object's 'name' property is used if it exists, or else, the site-defined value for the 'anonymous' variable. However, a module may override this by implementing hook_username_alter(&$name, $account).\n\nParameters:\n- $account: The account object for the user whose name is to be formatted.\n\nReturns: An unsanitized string with the username to display. The code receiving this result must ensure that check_plain() is called on it before it is printed to the page.\n\nFile: includes/common.inc", "response": "function format_username($account) {\n $name = !empty($account->name) ? $account->name : variable_get('anonymous', t('Anonymous'));\n drupal_alter('username', $name, $account);\n return $name;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-af0ae8a021", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/_field_ui_view_mode_menu_access/7.x", "instruction": "I need the code for `_field_ui_view_mode_menu_access($entity_type, $bundle, $view_mode, $access_callback)` in Drupal 7 (modules/field_ui/field_ui.module). It must do this: Menu access callback for the 'view mode display settings' pages.", "context": "File: modules/field_ui/field_ui.module", "response": "function _field_ui_view_mode_menu_access($entity_type, $bundle, $view_mode, $access_callback) {\n // It's good practice to call func_get_args() at the beginning of a function\n // to avoid problems with function parameters being modified later. The\n // behavior of func_get_args() changed in PHP7.\n // @see https://www.php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.func-parameter-modified\n $all_args = func_get_args();\n\n // First, determine visibility according to the 'use custom display'\n // setting for the view mode.\n $bundle = field_extract_bundle($entity_type, $bundle);\n $view_mode_settings = field_view_mode_settings($entity_type, $bundle);\n $visibility = ($view_mode == 'default') || !empty($view_mode_settings[$view_mode]['custom_settings']);\n\n // Then, determine access according to the $access parameter. This duplicates\n // part of _menu_check_access().\n if ($visibility) {\n // Grab the variable 'access arguments' part.\n $args = array_slice($all_args, 4);\n $callback = empty($access_callback) ? 0 : trim($access_callback);\n if (is_numeric($callback)) {\n return (bool) $callback;\n }\n else {\n // As call_user_func_array() is quite slow and user_access is a very\n // common callback, it is worth making a special case for it.\n if ($access_callback == 'user_access') {\n return (count($args) == 1) ? user_access($args[0]) : user_access($args[0], $args[1]);\n }\n elseif (function_exists($access_callback)) {\n return call_user_func_array($access_callback, $args);\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-af3da77e22", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_category_access/7.x", "instruction": "I need the code for `profile_category_access($account, $category)` in Drupal 7 (modules/profile/profile.module). It must do this: Menu item access callback - check if a user has access to a profile category.", "context": "File: modules/profile/profile.module", "response": "function profile_category_access($account, $category) {\n if (user_access('administer users') && $account->uid > 0) {\n return TRUE;\n }\n else {\n $category_visible = (bool) db_query_range('SELECT 1 FROM {profile_field} WHERE category = :category AND visibility <> :visibility', 0, 1, array(\n ':category' => $category,\n ':visibility' => PROFILE_HIDDEN\n ))->fetchField();\n return user_edit_access($account) && $category_visible;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-af3f907dcd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7002/7.x", "instruction": "In Drupal 7, write the function `node_update_7002()` (file modules/node/node.install) so that it does the following: Extend the node_promote_status index to include all fields required for the node page query.", "context": "File: modules/node/node.install", "response": "function node_update_7002() {\n db_drop_index('node', 'node_promote_status');\n db_add_index('node', 'node_frontpage', array('promote', 'status', 'sticky', 'created'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-af5f560b10", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_insert/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items)` (modules/field/field.api.php): Define custom insert behavior for this module's field data.", "context": "This hook is invoked from field_attach_insert() on the module that defines a field, during the process of inserting an entity object (node, taxonomy term, etc.). It is invoked just before the data for this field on the particular entity object is inserted into field storage. Only field modules that are storing or tracking information outside the standard field storage mechanism need to implement this hook.\n\nParameters:\n- $entity_type: The type of $entity.\n- $entity: The entity for the operation.\n- $field: The field structure for the operation.\n- $instance: The instance structure for $field on $entity's bundle.\n- $langcode: The language associated with $items.\n- $entity ($items): ->{$field['field_name']}[$langcode], or an empty array if unset.\n\nFile: modules/field/field.api.php", "response": "function hook_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {\n if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node' && $entity->status) {\n $query = db_insert('taxonomy_index')->fields(array('nid', 'tid', 'sticky', 'created', ));\n foreach ($items as $item) {\n $query->values(array(\n 'nid' => $entity->nid,\n 'tid' => $item['tid'],\n 'sticky' => $entity->sticky,\n 'created' => $entity->created,\n ));\n }\n $query->execute();\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-af7430fc4b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_default_styles/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_image_default_styles()` (modules/image/image.api.php): Provide module-based image styles for reuse throughout Drupal.", "context": "This hook allows your module to provide image styles. This may be useful if you require images to fit within exact dimensions. Note that you should attempt to re-use the default styles provided by Image module whenever possible, rather than creating image styles that are specific to your module. Image provides the styles \"thumbnail\", \"medium\", and \"large\".\n\nYou may use this hook to more easily manage your site's changes by moving existing image styles from the database to a custom module. Note however that moving image styles to code instead storing them in the database has a negligible effect on performance, since custom image styles are loaded from the database all at once. Even if all styles are pulled from modules, Image module will still perform the same queries to check the database for any custom styles.\n\nReturns: An array of image styles, keyed by the style name.\n\nFile: modules/image/image.api.php", "response": "function hook_image_default_styles() {\n $styles = array();\n\n $styles['mymodule_preview'] = array(\n 'label' => 'My module preview',\n 'effects' => array(\n array(\n 'name' => 'image_scale',\n 'data' => array('width' => 400, 'height' => 400, 'upscale' => 1),\n 'weight' => 0,\n ),\n array(\n 'name' => 'image_desaturate',\n 'data' => array(),\n 'weight' => 1,\n ),\n ),\n );\n\n return $styles;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-af830966f8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_exit/7.x", "instruction": "I need the code for `overlay_exit()` in Drupal 7 (modules/overlay/overlay.module). It must do this: Implements hook_exit().", "context": "When viewing an overlay child page, check if we need to trigger a refresh of the supplemental regions of the overlay on the next page request.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_exit() {\n // Check that we are in an overlay child page. Note that this should never\n // return TRUE on a cached page view, since the child mode is not set until\n // overlay_init() is called.\n if (overlay_get_mode() == 'child') {\n // Load any markup that was stored earlier in the page request, via calls\n // to overlay_store_rendered_content(). If none was stored, this is not a\n // page request where we expect any changes to the overlay supplemental\n // regions to have occurred, so we do not need to proceed any further.\n $original_markup = overlay_get_rendered_content();\n if (!empty($original_markup)) {\n // Compare the original markup to the current markup that we get from\n // rendering each overlay supplemental region now. If they don't match,\n // something must have changed, so we request a refresh of that region\n // within the parent window on the next page request.\n foreach (overlay_supplemental_regions() as $region) {\n if (!isset($original_markup[$region]) || $original_markup[$region] != overlay_render_region($region)) {\n overlay_request_refresh($region);\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-af91a36475", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7018/7.x", "instruction": "In Drupal 7, write the function `user_update_7018()` (file modules/user/user.install) so that it does the following: Ensure there is an index on {users}.picture.", "context": "File: modules/user/user.install", "response": "function user_update_7018() {\n if (!db_index_exists('users', 'picture')) {\n db_add_index('users', 'picture', array('picture'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-af938a7beb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_uri/7.x", "instruction": "I need the code for `forum_uri($forum)` in Drupal 7 (modules/forum/forum.module). It must do this: Implements callback_entity_info_uri().", "context": "Entity URI callback used in forum_entity_info_alter().\n\nFile: modules/forum/forum.module", "response": "function forum_uri($forum) {\n return array(\n 'path' => 'forum/' . $forum->tid,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-af97fbd8f6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_state_values_clean/7.x", "instruction": "I need the code for `form_state_values_clean(&$form_state)` in Drupal 7 (includes/form.inc). It must do this: Removes internal Form API elements and buttons from submitted form values.", "context": "This function can be used when a module wants to store all submitted form\nvalues, for example, by serializing them into a single database column. In\nsuch cases, all internal Form API values and all form button elements should\nnot be contained, and this function allows to remove them before the module\nproceeds to storage. Next to button elements, the following internal values\nare removed:\n- form_id\n- form_token\n- form_build_id\n- op\n\nParameters:\n- $form_state: A keyed array containing the current state of the form, including submitted form values; altered by reference.\n\nFile: includes/form.inc", "response": "function form_state_values_clean(&$form_state) {\n // Remove internal Form API values.\n unset($form_state['values']['form_id'], $form_state['values']['form_token'], $form_state['values']['form_build_id'], $form_state['values']['op']);\n\n // Remove button values.\n // form_builder() collects all button elements in a form. We remove the button\n // value separately for each button element.\n foreach ($form_state['buttons'] as $button) {\n // Remove this button's value from the submitted form values by finding\n // the value corresponding to this button.\n // We iterate over the #parents of this button and move a reference to\n // each parent in $form_state['values']. For example, if #parents is:\n // array('foo', 'bar', 'baz')\n // then the corresponding $form_state['values'] part will look like this:\n // array(\n // 'foo' => array(\n // 'bar' => array(\n // 'baz' => 'button_value',\n // ),\n // ),\n // )\n // We start by (re)moving 'baz' to $last_parent, so we are able unset it\n // at the end of the iteration. Initially, $values will contain a\n // reference to $form_state['values'], but in the iteration we move the\n // reference to $form_state['values']['foo'], and finally to\n // $form_state['values']['foo']['bar'], which is the level where we can\n // unset 'baz' (that is stored in $last_parent).\n $parents = $button['#parents'];\n $last_parent = array_pop($parents);\n $key_exists = NULL;\n $values = &drupal_array_get_nested_value($form_state['values'], $parents, $key_exists);\n if ($key_exists && is_array($values)) {\n unset($values[$last_parent]);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-afa9a75653", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.maintenance.inc/function/theme_install_page/7.x", "instruction": "In Drupal 7, write the function `theme_install_page($variables)` (file includes/theme.maintenance.inc) so that it does the following: Returns HTML for the installation page.", "context": "Note: this function is not themeable.\n\nParameters:\n- $variables: An associative array containing: - content: The page content to show.\n\nFile: includes/theme.maintenance.inc", "response": "function theme_install_page($variables) {\n drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');\n return theme('maintenance_page', $variables);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-afb10e6122", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_delete/7.x", "instruction": "Implement `shortcut_link_delete($form, &$form_state, $shortcut_link)` in PHP for Drupal 7. Required behavior: Form callback: builds the confirmation form for deleting a shortcut link.", "context": "Parameters:\n- $form: An associative array containing the structure of the form.\n- $form_state: An associative array containing the current state of the form.\n- $shortcut_link: An array representing the link that will be deleted.\n\nReturns: An array representing the form definition.\n\nFile: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_link_delete($form, &$form_state, $shortcut_link) {\n $form['shortcut_link'] = array(\n '#type' => 'value',\n '#value' => $shortcut_link,\n );\n\n return confirm_form(\n $form,\n t('Are you sure you want to delete the shortcut %title?', array('%title' => $shortcut_link['link_title'])),\n 'admin/config/user-interface/shortcut/' . $shortcut_link['menu_name'],\n t('This action cannot be undone.'),\n t('Delete'),\n t('Cancel')\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-afb2f3058b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_info/7.x", "instruction": "Implement `system_get_info($type, $name = NULL)` in PHP for Drupal 7. Required behavior: Returns an array of information about enabled modules or themes.", "context": "This function returns the information from the {system} table corresponding to the cached contents of the .info file for each active module or theme.\n\nParameters:\n- $type: Either 'module' or 'theme'.\n- $name: (optional) The name of a module or theme whose information shall be returned. If omitted, all records for the provided $type will be returned. If $name does not exist in the provided $type or is not enabled, an empty array will be returned.\n\nReturns: An associative array of module or theme information keyed by name, or only information for $name, if given. If no records are available, an empty array is returned.\n\nFile: modules/system/system.module", "response": "function system_get_info($type, $name = NULL) {\n $info = array();\n if ($type == 'module') {\n $type = 'module_enabled';\n }\n $list = system_list($type);\n foreach ($list as $shortname => $item) {\n if (!empty($item->status)) {\n $info[$shortname] = $item->info;\n }\n }\n if (isset($name)) {\n return isset($info[$name]) ? $info[$name] : array();\n }\n return $info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-afb6155bd6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7002/7.x", "instruction": "In Drupal 7, write the function `system_update_7002()` (file modules/system/system.install) so that it does the following: Add a table to store blocked IP addresses.", "context": "File: modules/system/system.install", "response": "function system_update_7002() {\n $schema['blocked_ips'] = array(\n 'description' => 'Stores blocked IP addresses.',\n 'fields' => array(\n 'iid' => array(\n 'description' => 'Primary Key: unique ID for IP addresses.',\n 'type' => 'serial',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n ),\n 'ip' => array(\n 'description' => 'IP address',\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => '',\n ),\n ),\n 'indexes' => array(\n 'blocked_ip' => array('ip'),\n ),\n 'primary key' => array('iid'),\n );\n\n db_create_table('blocked_ips', $schema['blocked_ips']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-afc19a82bb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_get_http_header/7.x", "instruction": "I need the code for `drupal_get_http_header($name = NULL)` in Drupal 7 (includes/bootstrap.inc). It must do this: Gets the HTTP response headers for the current page.", "context": "Parameters:\n- $name: An HTTP header name. If omitted, all headers are returned as name/value pairs. If an array value is FALSE, the header has been unset.\n\nReturns: A string containing the header value, or FALSE if the header has been set, or NULL if the header has not been set.\n\nFile: includes/bootstrap.inc", "response": "function drupal_get_http_header($name = NULL) {\n $headers = &drupal_static('drupal_http_headers', array());\n if (isset($name)) {\n $name = strtolower($name);\n return isset($headers[$name]) ? $headers[$name] : NULL;\n }\n else {\n return $headers;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-afec5f793f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_view/7.x", "instruction": "Implement `blog_view($node, $view_mode)` in PHP for Drupal 7. Required behavior: Implements hook_view().", "context": "File: modules/blog/blog.module", "response": "function blog_view($node, $view_mode) {\n if ($view_mode == 'full' && node_is_page($node)) {\n // Breadcrumb navigation. l() escapes title, so we should not escape !name.\n drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t(\"!name's blog\", array('!name' => format_username($node))), 'blog/' . $node->uid)));\n }\n return $node;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-aff9e1bf7c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/_field_sort_items/7.x", "instruction": "Implement `_field_sort_items($field, $items)` in PHP for Drupal 7. Required behavior: Helper function to sort items in a field according to user drag-n-drop reordering.", "context": "File: modules/field/field.module", "response": "function _field_sort_items($field, $items) {\n if (($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) && isset($items[0]['_weight'])) {\n usort($items, '_field_sort_items_helper');\n foreach ($items as $delta => $item) {\n if (is_array($items[$delta])) {\n unset($items[$delta]['_weight']);\n }\n }\n }\n return $items;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b03296b0b2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/profiles%21testing%21testing.install/function/testing_install/7.x", "instruction": "Implement `testing_install()` in PHP for Drupal 7. Required behavior: Implements hook_install().", "context": "Perform actions to set up the site for this profile.\n\nFile: profiles/testing/testing.install", "response": "function testing_install() {\n // Allow visitor account creation, but with administrative approval.\n variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);\n\n // Enable default permissions for system roles.\n user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));\n user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content'));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b05db3e5ef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_process_HOOK/7.x", "instruction": "Give me the example code for `hook_process_HOOK(&$variables)` in Drupal 7. Hook description: Process theme variables for a specific theme hook.", "context": "This hook allows modules to process theme variables for a specific theme hook. It should only be used if a module needs to override or add to the theme processing for a theme hook it didn't define.\n\nFor more detailed information, see theme().\n\nParameters:\n- $variables: The variables array (modify in place).\n\nFile: modules/system/theme.api.php", "response": "function hook_process_HOOK(&$variables) {\n // @todo There are no use-cases in Drupal core for this hook. Find one from a\n // contributed module, or come up with a good example. Coming up with a good\n // example might be tough, since the intent is for nearly everything to be\n // achievable via preprocess functions, and for process functions to only be\n // used when requiring the later execution time.\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b065d4dc6b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_prepare_translation/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode)` (modules/field/field.api.php): Define custom prepare_translation behavior for this module's field types.", "context": "Parameters:\n- $entity_type: The type of $entity.\n- $entity: The entity for the operation.\n- $field: The field structure for the operation.\n- $instance: The instance structure for $field on $entity's bundle.\n- $langcode: The language associated to $items.\n- $entity ($items): ->{$field['field_name']}[$langcode], or an empty array if unset.\n- $source_entity: The source entity from which field values are being copied.\n- $source_langcode: The source language from which field values are being copied.\n\nFile: modules/field/field.api.php", "response": "function hook_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode) {\n // If the translating user is not permitted to use the assigned text format,\n // we must not expose the source values.\n $field_name = $field['field_name'];\n $formats = filter_formats();\n $format_id = $source_entity->{$field_name}[$source_langcode][0]['format'];\n if (!filter_access($formats[$format_id])) {\n $items = array();\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b066bcd6ff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_delete/7.x", "instruction": "Implement `menu_link_delete($mlid, $path = NULL)` in PHP for Drupal 7. Required behavior: Delete one or several menu links.", "context": "Parameters:\n- $mlid: A valid menu link mlid or NULL. If NULL, $path is used.\n- $path: The path to the menu items to be deleted. $mlid must be NULL.\n\nFile: includes/menu.inc", "response": "function menu_link_delete($mlid, $path = NULL) {\n if (isset($mlid)) {\n _menu_delete_item(db_query(\"SELECT * FROM {menu_links} WHERE mlid = :mlid\", array(':mlid' => $mlid))->fetchAssoc());\n }\n else {\n $result = db_query(\"SELECT * FROM {menu_links} WHERE link_path = :link_path\", array(':link_path' => $path));\n foreach ($result as $link) {\n _menu_delete_item($link);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b07085d885", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_fieldset/7.x", "instruction": "In Drupal 7, write the function `theme_fieldset($variables)` (file includes/form.inc) so that it does the following: Returns HTML for a fieldset form element and its children.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #attributes, #children, #collapsed, #collapsible, #description, #id, #title, #value.\n\nFile: includes/form.inc", "response": "function theme_fieldset($variables) {\n $element = $variables['element'];\n element_set_attributes($element, array('id'));\n _form_set_class($element, array('form-wrapper'));\n\n $output = '';\n if (!empty($element['#title'])) {\n // Always wrap fieldset legends in a SPAN for CSS positioning.\n $output .= '' . $element['#title'] . '';\n }\n $output .= '
            ';\n if (!empty($element['#description'])) {\n $output .= '
            ' . $element['#description'] . '
            ';\n }\n $output .= $element['#children'];\n if (isset($element['#value'])) {\n $output .= $element['#value'];\n }\n $output .= '
            ';\n $output .= \"\\n\";\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b080e8a30e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_cron_queue_info/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_cron_queue_info()` (modules/system/system.api.php): Declare queues holding items that need to be run periodically.", "context": "While there can be only one hook_cron() process running at the same time, there can be any number of processes defined here running. Because of this, long running tasks are much better suited for this API. Items queued in hook_cron() might be processed in the same cron run if there are not many items in the queue, otherwise it might take several requests, which can be run in parallel.\n\nReturns: An associative array where the key is the queue name and the value is again an associative array. Possible keys are: - 'worker callback': The name of an implementation of callback_queue_worker(). - 'time': (optional) How much time Drupal should spend on calling this worker in seconds. Defaults to 15. - 'skip on cron': (optional) Set to TRUE to avoid being processed during cron runs (for example, if you want to control all queue execution manually).\n\nFile: modules/system/system.api.php", "response": "function hook_cron_queue_info() {\n $queues['aggregator_feeds'] = array(\n 'worker callback' => 'aggregator_refresh',\n 'time' => 60,\n );\n return $queues;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b09e4e88ce", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_access/7.x", "instruction": "I need the code for `field_access($op, $field, $entity_type, $entity = NULL, $account = NULL)` in Drupal 7 (modules/field/field.module). It must do this: Determine whether the user has access to a given field.", "context": "This function does not determine whether access is granted to the entity itself, only the specific field. Callers are responsible for ensuring that entity access is also respected. For example, when checking field access for nodes, check node_access() before checking field_access(), and when checking field access for entities using the Entity API contributed module, check entity_access() before checking field_access().\n\nParameters:\n- $op: The operation to be performed. Possible values: - 'edit' - 'view'\n- $field: The full field structure array for the field on which the operation is to be performed. See field_info_field().\n- $entity_type: The type of $entity; e.g., 'node' or 'user'.\n- $entity: (optional) The entity for the operation.\n- $account: (optional) The account to check, if not given use currently logged in user.\n\nReturns: TRUE if the operation is allowed; FALSE if the operation is denied.\n\nFile: modules/field/field.module", "response": "function field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) {\n global $user;\n\n if (!isset($account)) {\n $account = $user;\n }\n\n foreach (module_implements('field_access') as $module) {\n $function = $module . '_field_access';\n $access = $function($op, $field, $entity_type, $entity, $account);\n if ($access === FALSE) {\n return FALSE;\n }\n }\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0a457fe59", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_create_tmp/7.x", "instruction": "In Drupal 7, write the function `image_gd_create_tmp(stdClass $image, $width, $height)` (file modules/system/image.gd.inc) so that it does the following: Create a truecolor image preserving transparency from a provided image.", "context": "Parameters:\n- $image: An image object.\n- $width: The new width of the new image, in pixels.\n- $height: The new height of the new image, in pixels.\n\nReturns: A GD image handle.\n\nFile: modules/system/image.gd.inc", "response": "function image_gd_create_tmp(stdClass $image, $width, $height) {\n $res = imagecreatetruecolor($width, $height);\n\n if ($image->info['extension'] == 'gif') {\n // Find out if a transparent color is set, will return -1 if no\n // transparent color has been defined in the image.\n $transparent = imagecolortransparent($image->resource);\n\n if ($transparent >= 0) {\n // Find out the number of colors in the image palette. It will be 0 for\n // truecolor images.\n $palette_size = imagecolorstotal($image->resource);\n if ($palette_size == 0 || $transparent < $palette_size) {\n // Set the transparent color in the new resource, either if it is a\n // truecolor image or if the transparent color is part of the palette.\n // Since the index of the transparency color is a property of the\n // image rather than of the palette, it is possible that an image\n // could be created with this index set outside the palette size (see\n // http://stackoverflow.com/a/3898007).\n $transparent_color = imagecolorsforindex($image->resource, $transparent);\n $transparent = imagecolorallocate($res, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);\n\n // Flood with our new transparent color.\n imagefill($res, 0, 0, $transparent);\n imagecolortransparent($res, $transparent);\n }\n else {\n imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255));\n }\n }\n }\n elseif ($image->info['extension'] == 'png') {\n imagealphablending($res, FALSE);\n $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);\n imagefill($res, 0, 0, $transparency);\n imagealphablending($res, TRUE);\n imagesavealpha($res, TRUE);\n }\n else {\n imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255));\n }\n\n return $res;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0a825a045", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_menu/7.x", "instruction": "I need the code for `poll_menu()` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_menu().", "context": "File: modules/poll/poll.module", "response": "function poll_menu() {\n $items['poll'] = array(\n 'title' => 'Polls',\n 'page callback' => 'poll_page',\n 'access arguments' => array('access content'),\n 'type' => MENU_SUGGESTED_ITEM,\n 'file' => 'poll.pages.inc',\n );\n\n $items['node/%node/votes'] = array(\n 'title' => 'Votes',\n 'page callback' => 'poll_votes',\n 'page arguments' => array(1),\n 'access callback' => '_poll_menu_access',\n 'access arguments' => array(1, 'inspect all votes', FALSE),\n 'weight' => 3,\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'poll.pages.inc',\n );\n\n $items['node/%node/results'] = array(\n 'title' => 'Results',\n 'page callback' => 'poll_results',\n 'page arguments' => array(1),\n 'access callback' => '_poll_menu_access',\n 'access arguments' => array(1, 'access content', TRUE),\n 'weight' => 3,\n 'type' => MENU_LOCAL_TASK,\n 'file' => 'poll.pages.inc',\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0c2fb053f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/profiles%21minimal%21minimal.install/function/minimal_install/7.x", "instruction": "I need the code for `minimal_install()` in Drupal 7 (profiles/minimal/minimal.install). It must do this: Implements hook_install().", "context": "Performs actions to set up the site for this profile.\n\nFile: profiles/minimal/minimal.install", "response": "function minimal_install() {\n // Enable some standard blocks.\n $default_theme = variable_get('theme_default', 'bartik');\n $values = array(\n array(\n 'module' => 'system',\n 'delta' => 'main',\n 'theme' => $default_theme,\n 'status' => 1,\n 'weight' => 0,\n 'region' => 'content',\n 'pages' => '',\n 'cache' => -1,\n ),\n array(\n 'module' => 'user',\n 'delta' => 'login',\n 'theme' => $default_theme,\n 'status' => 1,\n 'weight' => 0,\n 'region' => 'sidebar_first',\n 'pages' => '',\n 'cache' => -1,\n ),\n array(\n 'module' => 'system',\n 'delta' => 'navigation',\n 'theme' => $default_theme,\n 'status' => 1,\n 'weight' => 0,\n 'region' => 'sidebar_first',\n 'pages' => '',\n 'cache' => -1,\n ),\n array(\n 'module' => 'system',\n 'delta' => 'management',\n 'theme' => $default_theme,\n 'status' => 1,\n 'weight' => 1,\n 'region' => 'sidebar_first',\n 'pages' => '',\n 'cache' => -1,\n ),\n array(\n 'module' => 'system',\n 'delta' => 'help',\n 'theme' => $default_theme,\n 'status' => 1,\n 'weight' => 0,\n 'region' => 'help',\n 'pages' => '',\n 'cache' => -1,\n ),\n );\n $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));\n foreach ($values as $record) {\n $query->values($record);\n }\n $query->execute();\n\n // Allow visitor account creation, but with administrative approval.\n variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);\n\n // Enable default permissions for system roles.\n user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));\n user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content'));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0c3ae83c4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_external_load/7.x", "instruction": "Implement `user_external_load($authname)` in PHP for Drupal 7. Required behavior: Fetches a user object based on an external authentication source.", "context": "Parameters:\n- $authname (string): The external authentication username.\n\nReturns: A fully-loaded user object if the user is found or FALSE if not found.\n\nFile: modules/user/user.module", "response": "function user_external_load($authname) {\n $uid = db_query(\"SELECT uid FROM {authmap} WHERE authname = :authname\", array(':authname' => $authname))->fetchField();\n\n if ($uid) {\n return user_load($uid);\n }\n else {\n return FALSE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0c7c6bf98", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_delete_bundle/7.x", "instruction": "In Drupal 7, write the function `field_attach_delete_bundle($entity_type, $bundle)` (file modules/field/field.attach.inc) so that it does the following: Notify field.module the a bundle was deleted.", "context": "This deletes the data for the field instances as well as the field instances themselves. This function actually just marks the data and field instances and deleted, leaving the garbage collection for a separate process, because it is not always possible to delete this much data in a single page request (particularly since for some field types, the deletion is more than just a simple DELETE query).\n\nParameters:\n- $entity_type: The entity type to which the bundle is bound.\n- $bundle: The bundle to delete.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_delete_bundle($entity_type, $bundle) {\n // First, delete the instances themselves. field_read_instances() must be\n // used here since field_info_instances() does not return instances for\n // disabled entity types or bundles.\n $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle), array('include_inactive' => 1));\n foreach ($instances as $instance) {\n field_delete_instance($instance);\n }\n\n // Clear the cache.\n field_cache_clear();\n\n // Clear bundle display settings.\n variable_del('field_bundle_settings_' . $entity_type . '__' . $bundle);\n\n // Let other modules act on deleting the bundle.\n module_invoke_all('field_attach_delete_bundle', $entity_type, $bundle, $instances);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0ce56fbd6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_form_required_marker/7.x", "instruction": "I need the code for `theme_form_required_marker($variables)` in Drupal 7 (includes/form.inc). It must do this: Returns HTML for a marker for required form elements.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element.\n\nFile: includes/form.inc", "response": "function theme_form_required_marker($variables) {\n // This is also used in the installer, pre-database setup.\n $t = get_t();\n $attributes = array(\n 'class' => 'form-required',\n 'title' => $t('This field is required.'),\n );\n return '*';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0cff085df", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/theme_system_modules_fieldset/7.x", "instruction": "I need the code for `theme_system_modules_fieldset($variables)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Returns HTML for the modules form.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/system/system.admin.inc", "response": "function theme_system_modules_fieldset($variables) {\n $form = $variables['form'];\n\n // Individual table headers.\n $rows = array();\n // Iterate through all the modules, which are\n // children of this fieldset.\n foreach (element_children($form) as $key) {\n // Stick it into $module for easier accessing.\n $module = $form[$key];\n $row = array();\n unset($module['enable']['#title']);\n $row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable']));\n $label = '' . drupal_render($module['name']) . '';\n $row[] = drupal_render($module['version']);\n // Add the description, along with any modules it requires.\n $description = drupal_render($module['description']);\n if ($module['#requires']) {\n $description .= '
            ' . t('Requires: !module-list', array('!module-list' => implode(', ', $module['#requires']))) . '
            ';\n }\n if ($module['#required_by']) {\n $description .= '
            ' . t('Required by: !module-list', array('!module-list' => implode(', ', $module['#required_by']))) . '
            ';\n }\n $row[] = array('data' => $description, 'class' => array('description'));\n // Display links (such as help or permissions) in their own columns.\n foreach (array('help', 'permissions', 'configure') as $link_type) {\n $row[] = array('data' => drupal_render($module['links'][$link_type]), 'class' => array($link_type));\n }\n $rows[] = $row;\n }\n\n return theme('table', array('header' => $form['#header'], 'rows' => $rows));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0ddeb47bd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21registry.inc/function/_registry_parse_file/7.x", "instruction": "Implement `_registry_parse_file($filename, $contents, $module = '', $weight = 0)` in PHP for Drupal 7. Required behavior: Parse a file and save its interface and class listings.", "context": "Parameters:\n- $filename: Name of the file we are going to parse.\n- $contents: Contents of the file we are going to parse as a string.\n- $module: (optional) Name of the module this file belongs to.\n- $weight: (optional) Weight of the module.\n\nFile: includes/registry.inc", "response": "function _registry_parse_file($filename, $contents, $module = '', $weight = 0) {\n if (preg_match_all('/^\\s*(?:abstract|final)?\\s*(class|interface|trait)\\s+([a-zA-Z0-9_]+)/m', $contents, $matches)) {\n foreach ($matches[2] as $key => $name) {\n db_merge('registry')\n ->key(array(\n 'name' => $name,\n 'type' => $matches[1][$key],\n ))\n ->fields(array(\n 'filename' => $filename,\n 'module' => $module,\n 'weight' => $weight,\n ))\n ->execute();\n }\n // Delete any resources for this file where the name is not in the list\n // we just merged in.\n db_delete('registry')\n ->condition('filename', $filename)\n ->condition('name', $matches[2], 'NOT IN')\n ->execute();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0ede103b4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_language_types_info/7.x", "instruction": "I need the code for `locale_language_types_info()` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_language_types_info().", "context": "Defines the three core language types:\n- Interface language is the only configurable language type in core. It is\n used by t() as the default language if none is specified.\n- Content language is by default non-configurable and inherits the interface\n language negotiated value. It is used by the Field API to determine the\n display language for fields if no explicit value is specified.\n- URL language is by default non-configurable and is determined through the\n URL language provider or the URL fallback provider if no language can be\n detected. It is used by l() as the default language if none is specified.\n\nFile: modules/locale/locale.module", "response": "function locale_language_types_info() {\n require_once DRUPAL_ROOT . '/includes/locale.inc';\n return array(\n LANGUAGE_TYPE_INTERFACE => array(\n 'name' => t('User interface text'),\n 'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'),\n ),\n LANGUAGE_TYPE_CONTENT => array(\n 'name' => t('Content'),\n 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),\n 'fixed' => array(LOCALE_LANGUAGE_NEGOTIATION_INTERFACE),\n ),\n LANGUAGE_TYPE_URL => array(\n 'name' => t('URL'),\n 'description' => t('Order of language detection methods for URLs. The detected language will be used as the default when generating URLs for internal links on the site.'),\n 'fixed' => array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_URL_FALLBACK),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b0f9142ac8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/theme_user_list/7.x", "instruction": "I need the code for `theme_user_list($variables)` in Drupal 7 (modules/user/user.module). It must do this: Returns HTML for a list of users.", "context": "Parameters:\n- $variables: An associative array containing: - users: An array with user objects. Should contain at least the name and uid. - title: (optional) Title to pass on to theme_item_list().\n\nFile: modules/user/user.module", "response": "function theme_user_list($variables) {\n $users = $variables['users'];\n $title = $variables['title'];\n $items = array();\n\n if (!empty($users)) {\n foreach ($users as $user) {\n $items[] = theme('username', array('account' => $user));\n }\n }\n return theme('item_list', array('items' => $items, 'title' => $title));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b106b7bfc1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_write/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_storage_write($entity_type, $entity, $op, $fields)` (modules/field/field.api.php): Write field data for an entity.", "context": "This hook is invoked from field_attach_insert() and field_attach_update(), to ask the field storage module to save field data.\n\nParameters:\n- $entity_type: The entity type of entity, such as 'node' or 'user'.\n- $entity: The entity on which to operate.\n- $op: FIELD_STORAGE_UPDATE when updating an existing entity, FIELD_STORAGE_INSERT when inserting a new entity.\n- $fields: An array listing the fields to be written. The keys and values of the array are field IDs.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_write($entity_type, $entity, $op, $fields) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n if (!isset($vid)) {\n $vid = $id;\n }\n\n foreach ($fields as $field_id) {\n $field = field_info_field_by_id($field_id);\n $field_name = $field['field_name'];\n $table_name = _field_sql_storage_tablename($field);\n $revision_name = _field_sql_storage_revision_tablename($field);\n\n $all_languages = field_available_languages($entity_type, $field);\n $field_languages = array_intersect($all_languages, array_keys((array) $entity->$field_name));\n\n // Delete and insert, rather than update, in case a value was added.\n if ($op == FIELD_STORAGE_UPDATE) {\n // Delete languages present in the incoming $entity->$field_name.\n // Delete all languages if $entity->$field_name is empty.\n $languages = !empty($entity->$field_name) ? $field_languages : $all_languages;\n if ($languages) {\n db_delete($table_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $id)\n ->condition('language', $languages, 'IN')\n ->execute();\n db_delete($revision_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $id)\n ->condition('revision_id', $vid)\n ->condition('language', $languages, 'IN')\n ->execute();\n }\n }\n\n // Prepare the multi-insert query.\n $do_insert = FALSE;\n $columns = array('entity_type', 'entity_id', 'revision_id', 'bundle', 'delta', 'language');\n foreach ($field['columns'] as $column => $attributes) {\n $columns[] = _field_sql_storage_columnname($field_name, $column);\n }\n $query = db_insert($table_name)->fields($columns);\n $revision_query = db_insert($revision_name)->fields($columns);\n\n foreach ($field_languages as $langcode) {\n $items = (array) $entity->{$field_name}[$langcode];\n $delta_count = 0;\n foreach ($items as $delta => $item) {\n // We now know we have something to insert.\n $do_insert = TRUE;\n $record = array(\n 'entity_type' => $entity_type,\n 'entity_id' => $id,\n 'revision_id' => $vid,\n 'bundle' => $bundle,\n 'delta' => $delta,\n 'language' => $langcode,\n );\n foreach ($field['columns'] as $column => $attributes) {\n $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;\n }\n $query->values($record);\n if (isset($vid)) {\n $revision_query->values($record);\n }\n\n if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) {\n break;\n }\n }\n }\n\n // Execute the query if we have values to insert.\n if ($do_insert) {\n $query->execute();\n $revision_query->execute();\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b12a59a685", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.pages.inc/function/openid_authentication_page/7.x", "instruction": "I need the code for `openid_authentication_page()` in Drupal 7 (modules/openid/openid.pages.inc). It must do this: Menu callback; Process an OpenID authentication.", "context": "File: modules/openid/openid.pages.inc", "response": "function openid_authentication_page() {\n $result = openid_complete();\n switch ($result['status']) {\n case 'success':\n return openid_authentication($result);\n case 'failed':\n drupal_set_message(t('OpenID login failed.'), 'error');\n break;\n case 'cancel':\n drupal_set_message(t('OpenID login cancelled.'));\n break;\n }\n drupal_goto();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b130452d67", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_admin_nodes_validate/7.x", "instruction": "Implement `node_admin_nodes_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Validate node_admin_nodes form submissions.", "context": "Checks whether any nodes have been selected to perform the chosen 'Update option' on.\n\nFile: modules/node/node.admin.inc", "response": "function node_admin_nodes_validate($form, &$form_state) {\n // Error if there are no items to select.\n if (!is_array($form_state['values']['nodes']) || !count(array_filter($form_state['values']['nodes']))) {\n form_set_error('', t('No items selected.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b17f64092b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/_drupal_schema_initialize/7.x", "instruction": "In Drupal 7, write the function `_drupal_schema_initialize(&$schema, $module, $remove_descriptions = TRUE)` (file includes/common.inc) so that it does the following: Fills in required default values for table definitions from hook_schema().", "context": "Parameters:\n- $schema: The schema definition array as it was returned by the module's hook_schema().\n- $module: The module for which hook_schema() was invoked.\n- $remove_descriptions: (optional) Whether to additionally remove 'description' keys of all tables and fields to improve performance of serialize() and unserialize(). Defaults to TRUE.\n\nFile: includes/common.inc", "response": "function _drupal_schema_initialize(&$schema, $module, $remove_descriptions = TRUE) {\n // Set the name and module key for all tables.\n foreach ($schema as $name => &$table) {\n if (empty($table['module'])) {\n $table['module'] = $module;\n }\n if (!isset($table['name'])) {\n $table['name'] = $name;\n }\n if ($remove_descriptions) {\n unset($table['description']);\n foreach ($table['fields'] as &$field) {\n unset($field['description']);\n }\n }\n // Set the type key for all fields where it is not set (mostly when using\n // datatabase specific data types).\n foreach ($table['fields'] as &$field) {\n if (!isset($field['type'])) {\n $field['type'] = NULL;\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b180e04927", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_instance/7.x", "instruction": "I need the code for `field_info_instance($entity_type, $field_name, $bundle_name)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns an array of instance data for a specific field and bundle.", "context": "The function populates a static cache with all fields and instances used in the bundle, allowing fast retrieval of field_info_field() or field_info_instance() later in the request.\n\nParameters:\n- $entity_type: The entity type for the instance.\n- $field_name: The field name for the instance.\n- $bundle_name: The bundle name for the instance.\n\nReturns: An associative array of instance data for the specific field and bundle; NULL if the instance does not exist.\n\nFile: modules/field/field.info.inc", "response": "function field_info_instance($entity_type, $field_name, $bundle_name) {\n $cache = _field_info_field_cache();\n $info = $cache->getBundleInstances($entity_type, $bundle_name);\n if (isset($info[$field_name])) {\n return $info[$field_name];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b1854372b4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7004/7.x", "instruction": "I need the code for `system_update_7004(&$sandbox)` in Drupal 7 (modules/system/system.install). It must do this: Remove hardcoded numeric deltas from all blocks in core.", "context": "File: modules/system/system.install", "response": "function system_update_7004(&$sandbox) {\n // Get an array of the renamed block deltas, organized by module.\n $renamed_deltas = array(\n 'blog' => array('0' => 'recent'),\n 'book' => array('0' => 'navigation'),\n 'comment' => array('0' => 'recent'),\n 'forum' => array(\n '0' => 'active',\n '1' => 'new',\n ),\n 'locale' => array('0' => LANGUAGE_TYPE_INTERFACE),\n 'node' => array('0' => 'syndicate'),\n 'poll' => array('0' => 'recent'),\n 'profile' => array('0' => 'author-information'),\n 'search' => array('0' => 'form'),\n 'statistics' => array('0' => 'popular'),\n 'system' => array('0' => 'powered-by'),\n 'user' => array(\n '0' => 'login',\n '1' => 'navigation',\n '2' => 'new',\n '3' => 'online',\n ),\n );\n\n $moved_deltas = array(\n 'user' => array('navigation' => 'system'),\n );\n\n // Only run this the first time through the batch update.\n if (!isset($sandbox['progress'])) {\n // Rename forum module's block variables.\n $forum_block_num_0 = variable_get('forum_block_num_0');\n if (isset($forum_block_num_0)) {\n variable_set('forum_block_num_active', $forum_block_num_0);\n variable_del('forum_block_num_0');\n }\n $forum_block_num_1 = variable_get('forum_block_num_1');\n if (isset($forum_block_num_1)) {\n variable_set('forum_block_num_new', $forum_block_num_1);\n variable_del('forum_block_num_1');\n }\n }\n\n update_fix_d7_block_deltas($sandbox, $renamed_deltas, $moved_deltas);\n\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b19216cf8c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_stream_wrapper_uri_normalize/7.x", "instruction": "Implement `file_stream_wrapper_uri_normalize($uri)` in PHP for Drupal 7. Required behavior: Normalizes a URI by making it syntactically correct.", "context": "A stream is referenced as \"scheme://target\".\n\nThe following actions are taken:\n- Remove trailing slashes from target\n- Trim erroneous leading slashes from target. e.g. \":///\" becomes \"://\".\n\nParameters:\n- $uri: String reference containing the URI to normalize.\n\nReturns: The normalized URI.\n\nFile: includes/file.inc", "response": "function file_stream_wrapper_uri_normalize($uri) {\n // Inline file_uri_scheme() function call for performance reasons.\n $position = strpos($uri, '://');\n $scheme = $position ? substr($uri, 0, $position) : FALSE;\n\n if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {\n $target = file_uri_target($uri);\n\n if ($target !== FALSE) {\n $uri = $scheme . '://' . $target;\n }\n }\n return $uri;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b1a7f30305", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/callback_search_conditions/7.x", "instruction": "In Drupal 7, show an example implementation for `callback_search_conditions($keys)` (modules/search/search.api.php): Provide search query conditions.", "context": "Callback for hook_search_info().\n\nThis callback is invoked by search_view() to get an array of additional search conditions to pass to search_data(). For example, a search module may get additional keywords, filters, or modifiers for the search from the query string.\n\nThis example pulls additional search keywords out of the $_REQUEST variable, (i.e. from the query string of the request). The conditions may also be generated internally - for example based on a module's settings.\n\nParameters:\n- $keys: The search keywords string.\n\nReturns: An array of additional conditions, such as filters.\n\nFile: modules/search/search.api.php", "response": "function callback_search_conditions($keys) {\n $conditions = array();\n\n if (!empty($_REQUEST['keys'])) {\n $conditions['keys'] = $_REQUEST['keys'];\n }\n if (!empty($_REQUEST['sample_search_keys'])) {\n $conditions['sample_search_keys'] = $_REQUEST['sample_search_keys'];\n }\n if ($force_keys = config('sample_search.settings')->get('force_keywords')) {\n $conditions['sample_search_force_keywords'] = $force_keys;\n }\n return $conditions;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b1a8088c44", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_get_tree/7.x", "instruction": "In Drupal 7, write the function `taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE)` (file modules/taxonomy/taxonomy.module) so that it does the following: Create a hierarchical representation of a vocabulary.", "context": "Parameters:\n- $vid: Which vocabulary to generate the tree for.\n- $parent: The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary.\n- $max_depth: The number of levels of the tree to return. Leave NULL to return all levels.\n- $load_entities: If TRUE, a full entity load will occur on the term objects. Otherwise they are partial objects queried directly from the {taxonomy_term_data} table to save execution time and memory consumption when listing large numbers of terms. Defaults to FALSE.\n\nReturns: An array of all term objects in the tree. Each term object is extended to have \"depth\" and \"parents\" attributes in addition to its normal ones. Results are statically cached. Term objects will be partial or complete depending on the $load_entities parameter.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE) {\n $children = &drupal_static(__FUNCTION__, array());\n $parents = &drupal_static(__FUNCTION__ . ':parents', array());\n $terms = &drupal_static(__FUNCTION__ . ':terms', array());\n\n // We cache trees, so it's not CPU-intensive to call taxonomy_get_tree() on a\n // term and its children, too.\n if (!isset($children[$vid])) {\n $children[$vid] = array();\n $parents[$vid] = array();\n $terms[$vid] = array();\n\n $query = db_select('taxonomy_term_data', 't');\n $query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');\n $result = $query\n ->addTag('translatable')\n ->addTag('taxonomy_term_access')\n ->fields('t')\n ->fields('h', array('parent'))\n ->condition('t.vid', $vid)\n ->orderBy('t.weight')\n ->orderBy('t.name')\n ->execute();\n\n foreach ($result as $term) {\n $children[$vid][$term->parent][] = $term->tid;\n $parents[$vid][$term->tid][] = $term->parent;\n $terms[$vid][$term->tid] = $term;\n }\n }\n\n // Load full entities, if necessary. The entity controller statically\n // caches the results.\n if ($load_entities) {\n $term_entities = taxonomy_term_load_multiple(array_keys($terms[$vid]));\n }\n\n $max_depth = (!isset($max_depth)) ? count($children[$vid]) : $max_depth;\n $tree = array();\n\n // Keeps track of the parents we have to process, the last entry is used\n // for the next processing step.\n $process_parents = array();\n $process_parents[] = $parent;\n\n // Loops over the parent terms and adds its children to the tree array.\n // Uses a loop instead of a recursion, because it's more efficient.\n while (count($process_parents)) {\n $parent = array_pop($process_parents);\n // The number of parents determines the current depth.\n $depth = count($process_parents);\n if ($max_depth > $depth && !empty($children[$vid][$parent])) {\n $has_children = FALSE;\n $child = current($children[$vid][$parent]);\n do {\n if (empty($child)) {\n break;\n }\n $term = $load_entities ? $term_entities[$child] : $terms[$vid][$child];\n if (isset($parents[$vid][$term->tid])) {\n // Clone the term so that the depth attribute remains correct\n // in the event of multiple parents.\n $term = clone $term;\n }\n $term->depth = $depth;\n unset($term->parent);\n $term->parents = $parents[$vid][$term->tid];\n $tree[] = $term;\n if (!empty($children[$vid][$term->tid])) {\n $has_children = TRUE;\n\n // We have to continue with this parent later.\n $process_parents[] = $parent;\n // Use the current term as parent for the next iteration.\n $process_parents[] = $term->tid;\n\n // Reset pointers for child lists because we step in there more often\n // with multi parents.\n reset($children[$vid][$term->tid]);\n // Move pointer so that we get the correct term the next time.\n next($children[$vid][$parent]);\n break;\n }\n } while ($child = next($children[$vid][$parent]));\n\n if (!$has_children) {\n // We processed all terms in this hierarchy-level, reset pointer\n // so that this function works the next time it gets called.\n reset($children[$vid][$parent]);\n }\n }\n }\n\n return $tree;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b1ed781598", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_block_save/7.x", "instruction": "In Drupal 7, write the function `book_block_save($delta = '', $edit = array())` (file modules/book/book.module) so that it does the following: Implements hook_block_save().", "context": "File: modules/book/book.module", "response": "function book_block_save($delta = '', $edit = array()) {\n $block = array();\n variable_set('book_block_mode', $edit['book_block_mode']);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b214116ec0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_unassign/7.x", "instruction": "I need the code for `trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL)` in Drupal 7 (modules/trigger/trigger.admin.inc). It must do this: Form constructor for confirmation page for removal of an assigned action.", "context": "Parameters:\n- $module: The tab of triggers the user will be directed to after successful removal of the action, or if the confirmation form is cancelled.\n- $hook: The name of the trigger hook, e.g., 'node_insert'.\n- $aid: The action ID.\n\nFile: modules/trigger/trigger.admin.inc", "response": "function trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL) {\n if (!isset($hook, $aid)) {\n drupal_goto('admin/structure/trigger');\n }\n\n $form['hook'] = array(\n '#type' => 'value',\n '#value' => $hook,\n );\n $form['module'] = array(\n '#type' => 'value',\n '#value' => $module,\n );\n $form['aid'] = array(\n '#type' => 'value',\n '#value' => $aid,\n );\n\n $action = actions_function_lookup($aid);\n $actions = actions_get_all_actions();\n\n $destination = 'admin/structure/trigger/' . $module;\n\n return confirm_form($form,\n t('Are you sure you want to unassign the action %title?', array('%title' => $actions[$action]['label'])),\n $destination,\n t('You can assign it again later if you wish.'),\n t('Unassign'), t('Cancel')\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b2236f417d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail/7.x", "instruction": "Implement `drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)` in PHP for Drupal 7. Required behavior: Composes and optionally sends an e-mail message.", "context": "Sending an e-mail works with defining an e-mail template (subject, text and possibly e-mail headers) and the replacement values to use in the appropriate places in the template. Processed e-mail templates are requested from hook_mail() from the module sending the e-mail. Any module can modify the composed e-mail message array using hook_mail_alter(). Finally drupal_mail_system()->mail() sends the e-mail, which can be reused if the exact same composed e-mail is to be sent to multiple recipients.\n\nFinding out what language to send the e-mail with needs some consideration. If you send e-mail to a user, her preferred language should be fine, so use user_preferred_language(). If you send email based on form values filled on the page, there are two additional choices if you are not sending the e-mail to a user on the site. You can either use the language used to generate the page ($language global variable) or the site default language. See language_default(). The former is good if sending e-mail to the person filling the form, the later is good if you send e-mail to an address previously set up (like contact addresses in a contact form).\n\nTaking care of always using the proper language is even more important when sending e-mails in a row to multiple users. Hook_mail() abstracts whether the mail text comes from an administrator setting or is static in the source code. It should also deal with common mail tokens, only receiving $params which are unique to the actual e-mail at hand.\n\nAn example:\n\nParameters:\n- $module: A module name to invoke hook_mail() on. The {$module}_mail() hook will be called to complete the $message structure which will already contain common defaults.\n- $key: A key to identify the e-mail sent. The final e-mail id for e-mail altering will be {$module}_{$key}.\n- $to: The e-mail address or addresses where the message will be sent to. The formatting of this string will be validated with the @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink Some examples are: - user@example.com - user@example.com, anotheruser@example.com - User - User , Another User \n- $language: Language object to use to compose the e-mail.\n- $params: Optional parameters to build the e-mail.\n- $from: Sets From to this value, if given.\n- $send: If TRUE, drupal_mail() will call drupal_mail_system()->mail() to deliver the message, and store the result in $message['result']. Modules implementing hook_mail_alter() may cancel sending by setting $message['send'] to FALSE.\n\nReturns: The $message array structure containing all details of the message. If already sent ($send = TRUE), then the 'result' element will contain the success indicator of the e-mail, failure being already written to the watchdog. (Success means nothing more than the message being accepted at php-level, which still doesn't guarantee it to be delivered.)\n\nFile: includes/mail.inc", "response": "function drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE) {\n $default_from = variable_get('site_mail', ini_get('sendmail_from'));\n\n // Bundle up the variables into a structured array for altering.\n $message = array(\n 'id' => $module . '_' . $key,\n 'module' => $module,\n 'key' => $key,\n 'to' => $to,\n 'from' => isset($from) ? $from : $default_from,\n 'language' => $language,\n 'params' => $params,\n 'send' => TRUE,\n 'subject' => '',\n 'body' => array()\n );\n\n // Build the default headers\n $headers = array(\n 'MIME-Version' => '1.0',\n 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',\n 'Content-Transfer-Encoding' => '8Bit',\n 'X-Mailer' => 'Drupal'\n );\n if ($default_from) {\n // To prevent e-mail from looking like spam, the addresses in the Sender and\n // Return-Path headers should have a domain authorized to use the originating\n // SMTP server.\n $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $default_from;\n\n if (variable_get('mail_display_name_site_name', FALSE)) {\n $display_name = variable_get('site_name', 'Drupal');\n $headers['From'] = drupal_mail_format_display_name($display_name) . ' <' . $default_from . '>';\n }\n }\n if ($from && $from != $default_from) {\n $headers['From'] = $from;\n }\n $message['headers'] = $headers;\n\n // Build the e-mail (get subject and body, allow additional headers) by\n // invoking hook_mail() on this module. We cannot use module_invoke() as\n // we need to have $message by reference in hook_mail().\n if (function_exists($function = $module . '_mail')) {\n $function($key, $message, $params);\n }\n\n // Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.\n drupal_alter('mail', $message);\n\n // Retrieve the responsible implementation for this message.\n $system = drupal_mail_system($module, $key);\n\n // Format the message body.\n $message = $system->format($message);\n\n // Optionally send e-mail.\n if ($send) {\n // The original caller requested sending. Sending was canceled by one or\n // more hook_mail_alter() implementations. We set 'result' to NULL, because\n // FALSE indicates an error in sending.\n if (empty($message['send'])) {\n $message['result'] = NULL;\n }\n // Sending was originally requested and was not canceled.\n else {\n $message['result'] = $system->mail($message);\n // Log errors.\n if (!$message['result']) {\n watchdog('mail', 'Error sending e-mail (from %from to %to).', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_ERROR);\n drupal_set_message(t('Unable to send e-mail. Contact the site administrator if the problem persists.'), 'error');\n }\n }\n }\n\n return $message;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b224741078", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_url_rewrite_session/7.x", "instruction": "Implement `locale_language_url_rewrite_session(&$path, &$options)` in PHP for Drupal 7. Required behavior: Rewrite URLs for the Session language provider.", "context": "File: includes/locale.inc", "response": "function locale_language_url_rewrite_session(&$path, &$options) {\n static $query_rewrite, $query_param, $query_value;\n\n // The following values are not supposed to change during a single page\n // request processing.\n if (!isset($query_rewrite)) {\n global $user;\n if (!$user->uid) {\n $languages = language_list('enabled');\n $languages = $languages[1];\n $query_param = check_plain(variable_get('locale_language_negotiation_session_param', 'language'));\n $query_value = isset($_GET[$query_param]) ? check_plain($_GET[$query_param]) : NULL;\n $query_rewrite = isset($languages[$query_value]) && language_negotiation_get_any(LOCALE_LANGUAGE_NEGOTIATION_SESSION);\n }\n else {\n $query_rewrite = FALSE;\n }\n }\n\n // If the user is anonymous, the user language provider is enabled, and the\n // corresponding option has been set, we must preserve any explicit user\n // language preference even with cookies disabled.\n if ($query_rewrite) {\n if (is_string($options['query'])) {\n $options['query'] = drupal_get_query_array($options['query']);\n }\n if (!isset($options['query'][$query_param])) {\n $options['query'][$query_param] = $query_value;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b2358acfa9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_menu/7.x", "instruction": "In Drupal 7, write the function `taxonomy_menu()` (file modules/taxonomy/taxonomy.module) so that it does the following: Implements hook_menu().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_menu() {\n $items['admin/structure/taxonomy'] = array(\n 'title' => 'Taxonomy',\n 'description' => 'Manage tagging, categorization, and classification of your content.',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('taxonomy_overview_vocabularies'),\n 'access arguments' => array('administer taxonomy'),\n 'file' => 'taxonomy.admin.inc',\n );\n $items['admin/structure/taxonomy/list'] = array(\n 'title' => 'List',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n 'weight' => -10,\n );\n $items['admin/structure/taxonomy/add'] = array(\n 'title' => 'Add vocabulary',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('taxonomy_form_vocabulary'),\n 'access arguments' => array('administer taxonomy'),\n 'type' => MENU_LOCAL_ACTION,\n 'file' => 'taxonomy.admin.inc',\n );\n\n $items['taxonomy/term/%taxonomy_term'] = array(\n 'title' => 'Taxonomy term',\n 'title callback' => 'taxonomy_term_title',\n 'title arguments' => array(2),\n // The page callback also invokes drupal_set_title() in case\n // the menu router's title is overridden by a menu link.\n 'page callback' => 'taxonomy_term_page',\n 'page arguments' => array(2),\n 'access arguments' => array('access content'),\n 'file' => 'taxonomy.pages.inc',\n );\n $items['taxonomy/term/%taxonomy_term/view'] = array(\n 'title' => 'View',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n );\n $items['taxonomy/term/%taxonomy_term/edit'] = array(\n 'title' => 'Edit',\n 'page callback' => 'drupal_get_form',\n // Pass a NULL argument to ensure that additional path components are not\n // passed to taxonomy_form_term() as the vocabulary machine name argument.\n 'page arguments' => array('taxonomy_form_term', 2, NULL),\n 'access callback' => 'taxonomy_term_edit_access',\n 'access arguments' => array(2),\n 'type' => MENU_LOCAL_TASK,\n 'weight' => 10,\n 'file' => 'taxonomy.admin.inc',\n );\n $items['taxonomy/term/%taxonomy_term/feed'] = array(\n 'title' => 'Taxonomy term',\n 'title callback' => 'taxonomy_term_title',\n 'title arguments' => array(2),\n 'page callback' => 'taxonomy_term_feed',\n 'page arguments' => array(2),\n 'access arguments' => array('access content'),\n 'type' => MENU_CALLBACK,\n 'file' => 'taxonomy.pages.inc',\n );\n $items['taxonomy/autocomplete'] = array(\n 'title' => 'Autocomplete taxonomy',\n 'page callback' => 'taxonomy_autocomplete',\n 'access arguments' => array('access content'),\n 'type' => MENU_CALLBACK,\n 'file' => 'taxonomy.pages.inc',\n );\n\n $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name'] = array(\n 'title callback' => 'entity_label',\n 'title arguments' => array('taxonomy_vocabulary', 3),\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('taxonomy_overview_terms', 3),\n 'access arguments' => array('administer taxonomy'),\n 'file' => 'taxonomy.admin.inc',\n );\n $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list'] = array(\n 'title' => 'List',\n 'type' => MENU_DEFAULT_LOCAL_TASK,\n 'weight' => -20,\n );\n $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/edit'] = array(\n 'title' => 'Edit',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('taxonomy_form_vocabulary', 3),\n 'access arguments' => array('administer taxonomy'),\n 'type' => MENU_LOCAL_TASK,\n 'weight' => -10,\n 'file' => 'taxonomy.admin.inc',\n );\n\n $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/add'] = array(\n 'title' => 'Add term',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('taxonomy_form_term', array(), 3),\n 'access arguments' => array('administer taxonomy'),\n 'type' => MENU_LOCAL_ACTION,\n 'file' => 'taxonomy.admin.inc',\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b23a552735", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_purge/7.x", "instruction": "Give me the example code for `hook_field_attach_purge($entity_type, $entity, $field, $instance)` in Drupal 7. Hook description: Act on field_purge_data().", "context": "This hook is invoked in field_purge_data() and allows modules to act on purging data from a single field pseudo-entity. For example, if a module relates data in the field with its own data, it may purge its own data during this process as well.\n\nParameters:\n- $entity_type: The type of $entity; for example, 'node' or 'user'.\n- $entity: The pseudo-entity whose field data is being purged.\n- $field: The (possibly deleted) field whose data is being purged.\n- $instance: The deleted field instance whose data is being purged.\n\nFile: modules/field/field.api.php", "response": "function hook_field_attach_purge($entity_type, $entity, $field, $instance) {\n // find the corresponding data in mymodule and purge it\n if ($entity_type == 'node' && $field->field_name == 'my_field_name') {\n mymodule_remove_mydata($entity->nid);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b24437beb3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_widget_settings_form/7.x", "instruction": "Implement `image_field_widget_settings_form($field, $instance)` in PHP for Drupal 7. Required behavior: Implements hook_field_widget_settings_form().", "context": "File: modules/image/image.field.inc", "response": "function image_field_widget_settings_form($field, $instance) {\n $widget = $instance['widget'];\n $settings = $widget['settings'];\n\n // Use the file widget settings form.\n $form = file_field_widget_settings_form($field, $instance);\n\n $form['preview_image_style'] = array(\n '#title' => t('Preview image style'),\n '#type' => 'select',\n '#options' => image_style_options(FALSE, PASS_THROUGH),\n '#empty_option' => '<' . t('no preview') . '>',\n '#default_value' => $settings['preview_image_style'],\n '#description' => t('The preview image will be shown while editing the content.'),\n '#weight' => 15,\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b25128be8d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_htaccess_lines/7.x", "instruction": "In Drupal 7, write the function `file_htaccess_lines($private = TRUE)` (file includes/file.inc) so that it does the following: Returns the standard .htaccess lines that Drupal writes to file directories.", "context": "Parameters:\n- $private: (Optional) Set to FALSE to return the .htaccess lines for an open and public directory. The default is TRUE, which returns the .htaccess lines for a private and protected directory.\n\nReturns: A string representing the desired contents of the .htaccess file.\n\nFile: includes/file.inc", "response": "function file_htaccess_lines($private = TRUE) {\n $lines = <<\n # Override the handler again if we're run later in the evaluation list.\n SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003\n\n\n# If we know how to do it safely, disable the PHP engine entirely.\n\n php_flag engine off\n\n\n php_flag engine off\n\n# From PHP 8 there is no number in the module name.\n\n php_flag engine off\n\nEOF;\n\n if ($private) {\n $lines = <<\n Require all denied\n\n\n# Deny all requests from Apache 2.0-2.2.\n\n Deny from all\n\nEOF\n . \"\\n\\n\" . $lines;\n }\n\n return $lines;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b264cf6769", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_json_encode/7.x", "instruction": "I need the code for `drupal_json_encode($var)` in Drupal 7 (includes/common.inc). It must do this: Converts a PHP variable into its JavaScript equivalent.", "context": "We use HTML-safe strings, with several characters escaped.\n\nFile: includes/common.inc", "response": "function drupal_json_encode($var) {\n // The PHP version cannot change within a request.\n static $php530;\n\n if (!isset($php530)) {\n $php530 = version_compare(PHP_VERSION, '5.3.0', '>=');\n }\n\n if ($php530) {\n // Encode <, >, ', &, and \" using the json_encode() options parameter.\n return json_encode($var, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);\n }\n\n // json_encode() escapes <, >, ', &, and \" using its options parameter, but\n // does not support this parameter prior to PHP 5.3.0. Use a helper instead.\n include_once DRUPAL_ROOT . '/includes/json-encode.inc';\n return drupal_json_encode_helper($var);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b269bb1e9c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_unpublish_action/7.x", "instruction": "Implement `node_unpublish_action($node, $context = array())` in PHP for Drupal 7. Required behavior: Sets the status of a node to 0 (unpublished).", "context": "Parameters:\n- $node: A node object.\n- $context: (optional) Array of additional information about what triggered the action. Not used for this action.\n\nFile: modules/node/node.module", "response": "function node_unpublish_action($node, $context = array()) {\n $node->status = NODE_NOT_PUBLISHED;\n watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->title));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b26db95cff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_schema/7.x", "instruction": "Give me the example code for `hook_field_schema($field)` in Drupal 7. Hook description: Define the Field API schema for a field structure.", "context": "This is invoked when a field is created, in order to obtain the database schema from the module that defines the field's type.\n\nThis hook must be defined in the module's .install file for it to be detected during installation and upgrade.\n\nParameters:\n- $field: A field structure.\n\nReturns: An associative array with the following keys: - columns: An array of Schema API column specifications, keyed by column name. This specifies what comprises a value for a given field. For example, a value for a number field is simply 'value', while a value for a formatted text field is the combination of 'value' and 'format'. It is recommended to avoid having the column definitions depend on field settings when possible. No assumptions should be made on how storage engines internally use the original column name to structure their storage. - indexes: (optional) An array of Schema API indexes definitions. Only columns that appear in the 'columns' array are allowed. Those indexes will be used as default indexes. Callers of field_create_field() can specify additional indexes, or, at their own risk, modify the default indexes specified by the field-type module. Some storage engines might not support indexes. - foreign keys: (optional) An array of Schema API foreign keys definitions.\n\nFile: modules/field/field.api.php", "response": "function hook_field_schema($field) {\n if ($field['type'] == 'text_long') {\n $columns = array(\n 'value' => array(\n 'type' => 'text',\n 'size' => 'big',\n 'not null' => FALSE,\n ),\n );\n }\n else {\n $columns = array(\n 'value' => array(\n 'type' => 'varchar',\n 'length' => $field['settings']['max_length'],\n 'not null' => FALSE,\n ),\n );\n }\n $columns += array(\n 'format' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n ),\n );\n return array(\n 'columns' => $columns,\n 'indexes' => array(\n 'format' => array('format'),\n ),\n 'foreign keys' => array(\n 'format' => array(\n 'table' => 'filter_format',\n 'columns' => array('format' => 'format'),\n ),\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b26fb6bd9f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_overview_form_submit/7.x", "instruction": "In Drupal 7, write the function `menu_overview_form_submit($form, &$form_state)` (file modules/menu/menu.admin.inc) so that it does the following: Submit handler for the menu overview form.", "context": "This function takes great care in saving parent items first, then items underneath them. Saving items in the incorrect order can break the menu tree.\n\nFile: modules/menu/menu.admin.inc", "response": "function menu_overview_form_submit($form, &$form_state) {\n // When dealing with saving menu items, the order in which these items are\n // saved is critical. If a changed child item is saved before its parent,\n // the child item could be saved with an invalid path past its immediate\n // parent. To prevent this, save items in the form in the same order they\n // are sent by $_POST, ensuring parents are saved first, then their children.\n // See http://drupal.org/node/181126#comment-632270\n $order = array_flip(array_keys($form_state['input'])); // Get the $_POST order.\n $form = array_merge($order, $form); // Update our original form with the new order.\n\n $updated_items = array();\n $fields = array('weight', 'plid');\n foreach (element_children($form) as $mlid) {\n if (isset($form[$mlid]['#item'])) {\n $element = $form[$mlid];\n // Update any fields that have changed in this menu item.\n foreach ($fields as $field) {\n if ($element[$field]['#value'] != $element[$field]['#default_value']) {\n $element['#item'][$field] = $element[$field]['#value'];\n $updated_items[$mlid] = $element['#item'];\n }\n }\n // Hidden is a special case, the value needs to be reversed.\n if ($element['hidden']['#value'] != $element['hidden']['#default_value']) {\n // Convert to integer rather than boolean due to PDO cast to string.\n $element['#item']['hidden'] = $element['hidden']['#value'] ? 0 : 1;\n $updated_items[$mlid] = $element['#item'];\n }\n }\n }\n\n // Save all our changed items to the database.\n foreach ($updated_items as $item) {\n $item['customized'] = 1;\n menu_link_save($item);\n }\n drupal_set_message(t('Your configuration has been saved.'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b272b7c45e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_field_extra_fields/7.x", "instruction": "I need the code for `comment_field_extra_fields()` in Drupal 7 (modules/comment/comment.module). It must do this: Implements hook_field_extra_fields().", "context": "File: modules/comment/comment.module", "response": "function comment_field_extra_fields() {\n $return = array();\n\n foreach (node_type_get_types() as $type) {\n if (variable_get('comment_subject_field_' . $type->type, 1) == 1) {\n $return['comment']['comment_node_' . $type->type] = array(\n 'form' => array(\n 'author' => array(\n 'label' => t('Author'),\n 'description' => t('Author textfield'),\n 'weight' => -2,\n ),\n 'subject' => array(\n 'label' => t('Subject'),\n 'description' => t('Subject textfield'),\n 'weight' => -1,\n ),\n ),\n );\n }\n }\n\n return $return;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b29f653566", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21graph.inc/function/drupal_depth_first_search/7.x", "instruction": "In Drupal 7, write the function `drupal_depth_first_search(&$graph)` (file includes/graph.inc) so that it does the following: Performs a depth-first search and sort on a directed acyclic graph.", "context": "Parameters:\n- $graph: A three dimensional associated array, with the first keys being the names of the vertices, these can be strings or numbers. The second key is 'edges' and the third one are again vertices, each such key representing an edge. Values of array elements are copied over. Example: @code $graph[1]['edges'][2] = 1; $graph[2]['edges'][3] = 1; $graph[2]['edges'][4] = 1; $graph[3]['edges'][4] = 1; @endcode On return you will also have: @code $graph[1]['paths'][2] = 1; $graph[1]['paths'][3] = 1; $graph[2]['reverse_paths'][1] = 1; $graph[3]['reverse_paths'][1] = 1; @endcode\n\nReturns: The passed-in $graph with more secondary keys filled in: - 'paths': Contains a list of vertices than can be reached on a path from this vertex. - 'reverse_paths': Contains a list of vertices that has a path from them to this vertex. - 'weight': If there is a path from a vertex to another then the weight of the latter is higher. - 'component': Vertices in the same component have the same component identifier.\n\nFile: includes/graph.inc", "response": "function drupal_depth_first_search(&$graph) {\n $state = array(\n // The order of last visit of the depth first search. This is the reverse\n // of the topological order if the graph is acyclic.\n 'last_visit_order' => array(),\n // The components of the graph.\n 'components' => array(),\n );\n // Perform the actual search.\n foreach ($graph as $start => $data) {\n _drupal_depth_first_search($graph, $state, $start);\n }\n\n // We do such a numbering that every component starts with 0. This is useful\n // for module installs as we can install every 0 weighted module in one\n // request, and then every 1 weighted etc.\n $component_weights = array();\n\n foreach ($state['last_visit_order'] as $vertex) {\n $component = $graph[$vertex]['component'];\n if (!isset($component_weights[$component])) {\n $component_weights[$component] = 0;\n }\n $graph[$vertex]['weight'] = $component_weights[$component]--;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b2bb6570c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7018/7.x", "instruction": "I need the code for `system_update_7018()` in Drupal 7 (modules/system/system.install). It must do this: Shorten the {system}.type column and modify indexes.", "context": "File: modules/system/system.install", "response": "function system_update_7018() {\n db_drop_index('system', 'modules');\n db_drop_index('system', 'type_name');\n db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));\n db_add_index('system', 'type_name', array('type', 'name'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b2ce285f06", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_opml/7.x", "instruction": "I need the code for `aggregator_form_opml($form, &$form_state)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Form constructor for importing feeds from OPML.", "context": "File: modules/aggregator/aggregator.admin.inc", "response": "function aggregator_form_opml($form, &$form_state) {\n $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');\n\n $form['upload'] = array(\n '#type' => 'file',\n '#title' => t('OPML File'),\n '#description' => t('Upload an OPML file containing a list of feeds to be imported.'),\n );\n $form['remote'] = array(\n '#type' => 'textfield',\n '#title' => t('OPML Remote URL'),\n '#maxlength' => 1024,\n '#description' => t('Enter the URL of an OPML file. This file will be downloaded and processed only once on submission of the form.'),\n );\n $form['refresh'] = array(\n '#type' => 'select',\n '#title' => t('Update interval'),\n '#default_value' => 3600,\n '#options' => $period,\n '#description' => t('The length of time between feed updates. Requires a correctly configured
            cron maintenance task.', array('@cron' => url('admin/reports/status'))),\n );\n $form['block'] = array('#type' => 'select',\n '#title' => t('News items in block'),\n '#default_value' => 5,\n '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),\n '#description' => t(\"Drupal can make a block with the most recent news items of a feed. You can configure blocks to be displayed in the sidebar of your page. This setting lets you configure the number of news items to show in a feed's block. If you choose '0' these feeds' blocks will be disabled.\", array('@block-admin' => url('admin/structure/block'))),\n );\n\n // Handling of categories.\n $options = array_map('check_plain', db_query(\"SELECT cid, title FROM {aggregator_category} ORDER BY title\")->fetchAllKeyed());\n if ($options) {\n $form['category'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Categorize news items'),\n '#options' => $options,\n '#description' => t('New feed items are automatically filed in the checked categories.'),\n );\n }\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Import')\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b2d5a806be", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.install/function/_image_update_7002_add_columns/7.x", "instruction": "Implement `_image_update_7002_add_columns($table, $field_name)` in PHP for Drupal 7. Required behavior: Add width and height columns to a specific table.", "context": "Parameters:\n- $table: The name of the database table to be updated.\n- $columns: Keyed array of columns this table is supposed to have.\n\nFile: modules/image/image.install", "response": "function _image_update_7002_add_columns($table, $field_name) {\n $spec = array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n );\n\n $spec['description'] = 'The width of the image in pixels.';\n db_add_field($table, $field_name . '_width', $spec);\n\n $spec['description'] = 'The height of the image in pixels.';\n db_add_field($table, $field_name . '_height', $spec);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b302b6b67f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_validate_picture/7.x", "instruction": "Implement `user_validate_picture(&$form, &$form_state)` in PHP for Drupal 7. Required behavior: Validates an image uploaded by a user.", "context": "File: modules/user/user.module", "response": "function user_validate_picture(&$form, &$form_state) {\n // If required, validate the uploaded picture.\n $validators = array(\n 'file_validate_is_image' => array(),\n 'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),\n 'file_validate_size' => array((int) variable_get('user_picture_file_size', '30') * 1024),\n // file_validate_is_image() uses the image toolkit to validate whether the\n // file is a valid image type, so set file_validate_extensions to an empty\n // array in order to signal to file_save_upload() that there is no need to\n // validate the upload against a default list of file extensions.\n 'file_validate_extensions' => array(),\n );\n\n // Save the file as a temporary file.\n $file = file_save_upload('picture_upload', $validators);\n if ($file === FALSE) {\n form_set_error('picture_upload', t(\"Failed to upload the picture image; the %directory directory doesn't exist or is not writable.\", array('%directory' => variable_get('user_picture_path', 'pictures'))));\n }\n elseif ($file !== NULL) {\n $form_state['values']['picture_upload'] = $file;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b34181e3c2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_clean_environment/7.x", "instruction": "In Drupal 7, write the function `simpletest_clean_environment()` (file modules/simpletest/simpletest.module) so that it does the following: Remove all temporary database tables and directories.", "context": "File: modules/simpletest/simpletest.module", "response": "function simpletest_clean_environment() {\n simpletest_clean_database();\n simpletest_clean_temporary_directories();\n if (variable_get('simpletest_clear_results', TRUE)) {\n $count = simpletest_clean_results_table();\n drupal_set_message(format_plural($count, 'Removed 1 test result.', 'Removed @count test results.'));\n }\n else {\n drupal_set_message(t('Clear results is disabled and the test results table will not be cleared.'), 'warning');\n }\n\n // Detect test classes that have been added, renamed or deleted.\n registry_rebuild();\n cache_clear_all('simpletest', 'cache');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b34bd5c503", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_cron_cleanup/7.x", "instruction": "Implement `drupal_cron_cleanup()` in PHP for Drupal 7. Required behavior: DEPRECATED: Shutdown function: Performs cron cleanup.", "context": "This function is deprecated because the 'cron_semaphore' variable it references no longer exists. It is therefore no longer used as a shutdown function by Drupal core.\n\nFile: includes/common.inc", "response": "function drupal_cron_cleanup() {\n // See if the semaphore is still locked.\n if (variable_get('cron_semaphore', FALSE)) {\n watchdog('cron', 'Cron run exceeded the time limit and was aborted.', array(), WATCHDOG_WARNING);\n\n // Release cron semaphore.\n variable_del('cron_semaphore');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b3621dba1b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/registry_rebuild/7.x", "instruction": "Implement `registry_rebuild()` in PHP for Drupal 7. Required behavior: Rescans all enabled modules and rebuilds the registry.", "context": "Rescans all code in modules or includes directories, storing the location of each interface or class in the database.\n\nFile: includes/bootstrap.inc", "response": "function registry_rebuild() {\n system_rebuild_module_data();\n registry_update();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b365b55a0e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_theme_settings_submit/7.x", "instruction": "In Drupal 7, write the function `system_theme_settings_submit($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Process system_theme_settings form submissions.", "context": "File: modules/system/system.admin.inc", "response": "function system_theme_settings_submit($form, &$form_state) {\n // Exclude unnecessary elements before saving.\n form_state_values_clean($form_state);\n\n $values = $form_state['values'];\n\n // Extract the name of the theme from the submitted form values, then remove\n // it from the array so that it is not saved as part of the variable.\n $key = $values['var'];\n unset($values['var']);\n\n // If the user uploaded a new logo or favicon, save it to a permanent location\n // and use it in place of the default theme-provided file.\n if (!empty($values['logo_upload'])) {\n $file = $values['logo_upload'];\n unset($values['logo_upload']);\n $filename = file_unmanaged_copy($file->uri);\n $values['default_logo'] = 0;\n $values['logo_path'] = $filename;\n $values['toggle_logo'] = 1;\n }\n if (!empty($values['favicon_upload'])) {\n $file = $values['favicon_upload'];\n unset($values['favicon_upload']);\n $filename = file_unmanaged_copy($file->uri);\n $values['default_favicon'] = 0;\n $values['favicon_path'] = $filename;\n $values['toggle_favicon'] = 1;\n }\n\n // If the user entered a path relative to the system files directory for\n // a logo or favicon, store a public:// URI so the theme system can handle it.\n if (!empty($values['logo_path'])) {\n $values['logo_path'] = _system_theme_settings_validate_path($values['logo_path']);\n }\n if (!empty($values['favicon_path'])) {\n $values['favicon_path'] = _system_theme_settings_validate_path($values['favicon_path']);\n }\n\n if (empty($values['default_favicon']) && !empty($values['favicon_path'])) {\n $values['favicon_mimetype'] = file_get_mimetype($values['favicon_path']);\n }\n\n variable_set($key, $values);\n drupal_set_message(t('The configuration options have been saved.'));\n\n cache_clear_all();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b37c122d7a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_js_defaults/7.x", "instruction": "Implement `drupal_js_defaults($data = NULL)` in PHP for Drupal 7. Required behavior: Constructs an array of the defaults that are used for JavaScript items.", "context": "Parameters:\n- $data: (optional) The default data parameter for the JavaScript item array.\n\nFile: includes/common.inc", "response": "function drupal_js_defaults($data = NULL) {\n return array(\n 'type' => 'file',\n 'group' => JS_DEFAULT,\n 'every_page' => FALSE,\n 'weight' => 0,\n 'requires_jquery' => TRUE,\n 'scope' => 'header',\n 'cache' => TRUE,\n 'defer' => FALSE,\n 'preprocess' => TRUE,\n 'version' => NULL,\n 'data' => $data,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b3a522f650", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_get_renderable_array/7.x", "instruction": "I need the code for `_block_get_renderable_array($list = array())` in Drupal 7 (modules/block/block.module). It must do this: Gets an array of blocks suitable for drupal_render().", "context": "Parameters:\n- $list: A list of blocks such as that returned by block_list().\n\nReturns: A renderable array.\n\nFile: modules/block/block.module", "response": "function _block_get_renderable_array($list = array()) {\n $weight = 0;\n $build = array();\n foreach ($list as $key => $block) {\n $build[$key] = $block->content;\n unset($block->content);\n\n // Add contextual links for this block; skip the main content block, since\n // contextual links are basically output as tabs/local tasks already. Also\n // skip the help block, since we assume that most users do not need or want\n // to perform contextual actions on the help block, and the links needlessly\n // draw attention on it.\n if ($key != 'system_main' && $key != 'system_help') {\n $build[$key]['#contextual_links']['block'] = array(\n 'admin/structure/block/manage',\n array($block->module, $block->delta),\n );\n }\n\n $build[$key] += array(\n '#block' => $block,\n '#weight' => ++$weight,\n );\n $build[$key]['#theme_wrappers'][] = 'block';\n }\n $build['#sorted'] = TRUE;\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b3ac09d668", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_theme/7.x", "instruction": "In Drupal 7, write the function `filter_theme()` (file modules/filter/filter.module) so that it does the following: Implements hook_theme().", "context": "File: modules/filter/filter.module", "response": "function filter_theme() {\n return array(\n 'filter_admin_overview' => array(\n 'render element' => 'form',\n 'file' => 'filter.admin.inc',\n ),\n 'filter_admin_format_filter_order' => array(\n 'render element' => 'element',\n 'file' => 'filter.admin.inc',\n ),\n 'filter_tips' => array(\n 'variables' => array('tips' => NULL, 'long' => FALSE),\n 'file' => 'filter.pages.inc',\n ),\n 'text_format_wrapper' => array(\n 'render element' => 'element',\n ),\n 'filter_tips_more_info' => array(\n 'variables' => array(),\n ),\n 'filter_guidelines' => array(\n 'variables' => array('format' => NULL),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b3d8f878e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_storage_types/7.x", "instruction": "In Drupal 7, write the function `field_info_storage_types($storage_type = NULL)` (file modules/field/field.info.inc) so that it does the following: Returns information about field storage from hook_field_storage_info().", "context": "Parameters:\n- $storage_type: (optional) A storage type name. If omitted, all storage types will be returned.\n\nReturns: Either a storage type description, as provided by hook_field_storage_info(), or an array of all existing storage types, keyed by storage type name.\n\nFile: modules/field/field.info.inc", "response": "function field_info_storage_types($storage_type = NULL) {\n $info = _field_info_collate_types();\n $storage_types = $info['storage types'];\n if ($storage_type) {\n if (isset($storage_types[$storage_type])) {\n return $storage_types[$storage_type];\n }\n }\n else {\n return $storage_types;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b3e3258b13", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_field_name_exists/7.x", "instruction": "In Drupal 7, write the function `_field_ui_field_name_exists($value)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Render API callback: Checks if a field machine name is taken.", "context": "Parameters:\n- $value: The machine name, not prefixed with 'field_'.\n\nReturns: Whether or not the field machine name is taken.\n\nFile: modules/field_ui/field_ui.admin.inc", "response": "function _field_ui_field_name_exists($value) {\n // Prefix with 'field_'.\n $field_name = 'field_' . $value;\n\n // We need to check inactive fields as well, so we can't use\n // field_info_fields().\n return (bool) field_read_fields(array('field_name' => $field_name), array('include_inactive' => TRUE));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b3f307faf0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_admin_block_content/7.x", "instruction": "I need the code for `seven_admin_block_content($variables)` in Drupal 7 (themes/seven/template.php). It must do this: Overrides theme_admin_block_content().", "context": "Use unordered list markup in both compact and extended mode.\n\nFile: themes/seven/template.php", "response": "function seven_admin_block_content($variables) {\n $content = $variables['content'];\n $output = '';\n if (!empty($content)) {\n $output = system_admin_compact_mode() ? '
              ' : '
                ';\n foreach ($content as $item) {\n $output .= '
              • ';\n $output .= l($item['title'], $item['href'], $item['localized_options']);\n if (isset($item['description']) && !system_admin_compact_mode()) {\n $output .= '
                ' . filter_xss_admin($item['description']) . '
                ';\n }\n $output .= '
              • ';\n }\n $output .= '
              ';\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b3f93c6767", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_permission/7.x", "instruction": "Implement `overlay_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/overlay/overlay.module", "response": "function overlay_permission() {\n return array(\n 'access overlay' => array(\n 'title' => t('Access the administrative overlay'),\n 'description' => t('View administrative pages in the overlay.'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b40fbd5de6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/_theme_registry_callback/7.x", "instruction": "In Drupal 7, write the function `_theme_registry_callback($callback = NULL, array $arguments = array())` (file includes/theme.inc) so that it does the following: Sets the callback that will be used by theme_get_registry().", "context": "Parameters:\n- $callback: The name of the callback function.\n- $arguments: The arguments to pass to the function.\n\nFile: includes/theme.inc", "response": "function _theme_registry_callback($callback = NULL, array $arguments = array()) {\n static $stored;\n if (isset($callback)) {\n $stored = array($callback, $arguments);\n }\n return $stored;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b42f1616b9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_get_registry/7.x", "instruction": "In Drupal 7, write the function `theme_get_registry($complete = TRUE)` (file includes/theme.inc) so that it does the following: Gets the theme registry.", "context": "Parameters:\n- $complete: Optional boolean to indicate whether to return the complete theme registry array or an instance of the ThemeRegistry class. If TRUE, the complete theme registry array will be returned. This is useful if you want to foreach over the whole registry, use array_* functions or inspect it in a debugger. If FALSE, an instance of the ThemeRegistry class will be returned, this provides an ArrayObject which allows it to be accessed with array syntax and isset(), and should be more lightweight than the full registry. Defaults to TRUE.\n\nReturns: The complete theme registry array, or an instance of the ThemeRegistry class.\n\nFile: includes/theme.inc", "response": "function theme_get_registry($complete = TRUE) {\n // Use the advanced drupal_static() pattern, since this is called very often.\n static $drupal_static_fast;\n if (!isset($drupal_static_fast)) {\n $drupal_static_fast['registry'] = &drupal_static('theme_get_registry');\n }\n $theme_registry = &$drupal_static_fast['registry'];\n\n // Initialize the theme, if this is called early in the bootstrap, or after\n // static variables have been reset.\n if (!is_array($theme_registry)) {\n drupal_theme_initialize();\n $theme_registry = array();\n }\n\n $key = (int) $complete;\n\n if (!isset($theme_registry[$key])) {\n list($callback, $arguments) = _theme_registry_callback();\n if (!$complete) {\n $arguments[] = FALSE;\n }\n $theme_registry[$key] = call_user_func_array($callback, $arguments);\n }\n\n return $theme_registry[$key];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4c563bd2b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.install/function/shortcut_schema/7.x", "instruction": "Implement `shortcut_schema()` in PHP for Drupal 7. Required behavior: Implements hook_schema().", "context": "File: modules/shortcut/shortcut.install", "response": "function shortcut_schema() {\n $schema['shortcut_set'] = array(\n 'description' => 'Stores information about sets of shortcuts links.',\n 'fields' => array(\n 'set_name' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => \"Primary Key: The {menu_links}.menu_name under which the set's links are stored.\",\n ),\n 'title' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The title of the set.',\n ),\n ),\n 'primary key' => array('set_name'),\n 'foreign keys' => array(\n 'menu_name' => array(\n 'table' => 'menu_links',\n 'columns' => array('set_name' => 'menu_name'),\n ),\n ),\n );\n\n $schema['shortcut_set_users'] = array(\n 'description' => 'Maps users to shortcut sets.',\n 'fields' => array(\n 'uid' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The {users}.uid for this set.',\n ),\n 'set_name' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => \"The {shortcut_set}.set_name that will be displayed for this user.\",\n ),\n ),\n 'primary key' => array('uid'),\n 'indexes' => array(\n 'set_name' => array('set_name'),\n ),\n 'foreign keys' => array(\n 'set_user' => array(\n 'table' => 'users',\n 'columns' => array('uid' => 'uid'),\n ),\n 'set_name' => array(\n 'table' => 'shortcut_set',\n 'columns' => array('set_name' => 'set_name'),\n ),\n ),\n );\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4cd7ba0ea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_ip_blocking_delete_submit/7.x", "instruction": "I need the code for `system_ip_blocking_delete_submit($form, &$form_state)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Process system_ip_blocking_delete form submissions.", "context": "File: modules/system/system.admin.inc", "response": "function system_ip_blocking_delete_submit($form, &$form_state) {\n $blocked_ip = $form_state['values']['blocked_ip'];\n db_delete('blocked_ips')\n ->condition('iid', $blocked_ip['iid'])\n ->execute();\n watchdog('user', 'Deleted %ip', array('%ip' => $blocked_ip['ip']));\n drupal_set_message(t('The IP address %ip was deleted.', array('%ip' => $blocked_ip['ip'])));\n $form_state['redirect'] = 'admin/config/people/ip-blocking';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4d1bd7b2a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/check_markup/7.x", "instruction": "I need the code for `check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)` in Drupal 7 (modules/filter/filter.module). It must do this: Runs all the enabled filters on a piece of text.", "context": "Note: Because filters can inject JavaScript or execute PHP code, security is vital here. When a user supplies a text format, you should validate it using filter_access() before accepting/using it. This is normally done in the validation stage of the Form API. You should for example never make a preview of content in a disallowed format.\n\nParameters:\n- $text: The text to be filtered.\n- $format_id: (optional) The machine name of the filter format to be used to filter the text. Defaults to the fallback format. See filter_fallback_format().\n- $langcode: (optional) The language code of the text to be filtered, e.g. 'en' for English. This allows filters to be language aware so language specific text replacement can be implemented. Defaults to an empty string.\n- $cache: (optional) A Boolean indicating whether to cache the filtered output in the {cache_filter} table. The caller may set this to FALSE when the output is already cached elsewhere to avoid duplicate cache lookups and storage. Defaults to FALSE.\n\nReturns: The filtered text.\n\nFile: modules/filter/filter.module", "response": "function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE) {\n if (!isset($format_id)) {\n $format_id = filter_fallback_format();\n }\n // If the requested text format does not exist, the text cannot be filtered.\n if (!$format = filter_format_load($format_id)) {\n watchdog('filter', 'Missing text format: %format.', array('%format' => $format_id), WATCHDOG_ALERT);\n return '';\n }\n\n $text = (string) $text;\n\n // Check for a cached version of this piece of text.\n $cache = $cache && !empty($format->cache);\n $cache_id = '';\n if ($cache) {\n $cache_id = $format->format . ':' . $langcode . ':' . hash('sha256', $text);\n if ($cached = cache_get($cache_id, 'cache_filter')) {\n return $cached->data;\n }\n }\n\n // Convert all Windows and Mac newlines to a single newline, so filters only\n // need to deal with one possibility.\n $text = str_replace(array(\"\\r\\n\", \"\\r\"), \"\\n\", $text);\n\n // Get a complete list of filters, ordered properly.\n $filters = filter_list_format($format->format);\n $filter_info = filter_get_filters();\n\n // Give filters the chance to escape HTML-like data such as code or formulas.\n foreach ($filters as $name => $filter) {\n if ($filter->status && isset($filter_info[$name]['prepare callback']) && function_exists($filter_info[$name]['prepare callback'])) {\n $function = $filter_info[$name]['prepare callback'];\n $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);\n }\n }\n\n // Perform filtering.\n foreach ($filters as $name => $filter) {\n if ($filter->status && isset($filter_info[$name]['process callback']) && function_exists($filter_info[$name]['process callback'])) {\n $function = $filter_info[$name]['process callback'];\n $text = $function($text, $filter, $format, $langcode, $cache, $cache_id);\n }\n }\n\n // Cache the filtered text. This cache is infinitely valid. It becomes\n // obsolete when $text changes (which leads to a new $cache_id). It is\n // automatically flushed when the text format is updated.\n // @see filter_format_save()\n if ($cache) {\n cache_set($cache_id, $text, 'cache_filter');\n }\n\n return $text;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4db61a4d9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_cache_set/7.x", "instruction": "Implement `_update_cache_set($cid, $data, $expire)` in PHP for Drupal 7. Required behavior: Stores data in the private update status cache table.", "context": "Parameters:\n- $cid: The cache ID to save the data with.\n- $data: The data to store.\n- $expire: One of the following values: - CACHE_PERMANENT: Indicates that the item should never be removed except by explicitly using _update_cache_clear(). - A Unix timestamp: Indicates that the item should be kept at least until the given time, after which it will be invalidated.\n\nFile: modules/update/update.module", "response": "function _update_cache_set($cid, $data, $expire) {\n $fields = array(\n 'created' => REQUEST_TIME,\n 'expire' => $expire,\n );\n if (!is_string($data)) {\n $fields['data'] = serialize($data);\n $fields['serialized'] = 1;\n }\n else {\n $fields['data'] = $data;\n $fields['serialized'] = 0;\n }\n db_merge('cache_update')\n ->key(array('cid' => $cid))\n ->fields($fields)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4dcfcc0db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_theme/7.x", "instruction": "I need the code for `file_theme()` in Drupal 7 (modules/file/file.module). It must do this: Implements hook_theme().", "context": "File: modules/file/file.module", "response": "function file_theme() {\n return array(\n // file.module.\n 'file_link' => array(\n 'variables' => array('file' => NULL, 'icon_directory' => NULL),\n ),\n 'file_icon' => array(\n 'variables' => array('file' => NULL, 'icon_directory' => NULL, 'alt' => ''),\n ),\n 'file_managed_file' => array(\n 'render element' => 'element',\n ),\n\n // file.field.inc.\n 'file_widget' => array(\n 'render element' => 'element',\n ),\n 'file_widget_multiple' => array(\n 'render element' => 'element',\n ),\n 'file_formatter_table' => array(\n 'variables' => array('items' => NULL),\n ),\n 'file_upload_help' => array(\n 'variables' => array('description' => NULL, 'upload_validators' => NULL),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4eec14f43", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_feed_items_load/7.x", "instruction": "I need the code for `aggregator_feed_items_load($type, $data = NULL)` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Loads and optionally filters feed items.", "context": "Parameters:\n- $type: The type of filter for the items. Possible values are: - sum: No filtering. - source: Filter the feed items, limiting the result to items from a single source. - category: Filter the feed items by category.\n- $data: Feed or category data used for filtering. The type and value of $data depends on $type: - source: $data is an object with $data->fid identifying the feed used to as filter. - category: $data is an array with $data['cid'] being the category id to filter on. The $data parameter is not used when $type is 'sum'.\n\nReturns: An array of the feed items.\n\nFile: modules/aggregator/aggregator.pages.inc", "response": "function aggregator_feed_items_load($type, $data = NULL) {\n $items = array();\n switch ($type) {\n case 'sum':\n $query = db_select('aggregator_item', 'i');\n $query->join('aggregator_feed', 'f', 'i.fid = f.fid');\n $query->fields('i');\n $query->addField('f', 'title', 'ftitle');\n $query->addField('f', 'link', 'flink');\n break;\n case 'source':\n $query = db_select('aggregator_item', 'i');\n $query\n ->fields('i')\n ->condition('i.fid', $data->fid);\n break;\n case 'category':\n $query = db_select('aggregator_category_item', 'c');\n $query->leftJoin('aggregator_item', 'i', 'c.iid = i.iid');\n $query->leftJoin('aggregator_feed', 'f', 'i.fid = f.fid');\n $query\n ->fields('i')\n ->condition('cid', $data['cid']);\n $query->addField('f', 'title', 'ftitle');\n $query->addField('f', 'link', 'flink');\n break;\n }\n\n $result = $query\n ->extend('PagerDefault')\n ->limit(20)\n ->orderBy('i.timestamp', 'DESC')\n ->orderBy('i.iid', 'DESC')\n ->execute();\n\n foreach ($result as $item) {\n $item->categories = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = :iid ORDER BY c.title', array(':iid' => $item->iid))->fetchAll();\n $items[] = $item;\n }\n\n return $items;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4f869db80", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/_book_add_form_elements/7.x", "instruction": "Implement `_book_add_form_elements(&$form, &$form_state, $node)` in PHP for Drupal 7. Required behavior: Builds the common elements of the book form for the node and outline forms.", "context": "Parameters:\n- $node: The node whose form is being viewed.\n\nFile: modules/book/book.module", "response": "function _book_add_form_elements(&$form, &$form_state, $node) {\n // If the form is being processed during the Ajax callback of our book bid\n // dropdown, then $form_state will hold the value that was selected.\n if (isset($form_state['values']['book'])) {\n $node->book = $form_state['values']['book'];\n }\n\n $form['book'] = array(\n '#type' => 'fieldset',\n '#title' => t('Book outline'),\n '#weight' => 10,\n '#collapsible' => TRUE,\n '#collapsed' => TRUE,\n '#group' => 'additional_settings',\n '#attributes' => array(\n 'class' => array('book-outline-form'),\n ),\n '#attached' => array(\n 'js' => array(drupal_get_path('module', 'book') . '/book.js'),\n ),\n '#tree' => TRUE,\n );\n foreach (array('menu_name', 'mlid', 'nid', 'router_path', 'has_children', 'options', 'module', 'original_bid', 'parent_depth_limit') as $key) {\n $form['book'][$key] = array(\n '#type' => 'value',\n '#value' => $node->book[$key],\n );\n }\n\n $form['book']['plid'] = _book_parent_select($node->book);\n\n // @see _book_admin_table_tree(). The weight may be larger than 15.\n $form['book']['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight'),\n '#default_value' => $node->book['weight'],\n '#delta' => max(15, abs($node->book['weight'])),\n '#weight' => 5,\n '#description' => t('Pages at a given level are ordered first by weight and then by title.'),\n );\n $options = array();\n $nid = isset($node->nid) ? $node->nid : 'new';\n\n if (isset($node->nid) && ($nid == $node->book['original_bid']) && ($node->book['parent_depth_limit'] == 0)) {\n // This is the top level node in a maximum depth book and thus cannot be moved.\n $options[$node->nid] = $node->title;\n }\n else {\n foreach (book_get_books() as $book) {\n $options[$book['nid']] = $book['title'];\n }\n }\n\n if (user_access('create new books') && ($nid == 'new' || ($nid != $node->book['original_bid']))) {\n // The node can become a new book, if it is not one already.\n $options = array($nid => '<' . t('create a new book') . '>') + $options;\n }\n if (!$node->book['mlid']) {\n // The node is not currently in the hierarchy.\n $options = array(0 => '<' . t('none') . '>') + $options;\n }\n\n // Add a drop-down to select the destination book.\n $form['book']['bid'] = array(\n '#type' => 'select',\n '#title' => t('Book'),\n '#default_value' => $node->book['bid'],\n '#options' => $options,\n '#access' => (bool) $options,\n '#description' => t('Your page will be a part of the selected book.'),\n '#weight' => -5,\n '#attributes' => array('class' => array('book-title-select')),\n '#ajax' => array(\n 'callback' => 'book_form_update',\n 'wrapper' => 'edit-book-plid-wrapper',\n 'effect' => 'fade',\n 'speed' => 'fast',\n ),\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b4f8f29545", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_effect_save/7.x", "instruction": "Implement `image_effect_save($effect)` in PHP for Drupal 7. Required behavior: Saves an image effect.", "context": "Parameters:\n- $effect: An image effect array.\n\nReturns: An image effect array. In the case of a new effect, 'ieid' will be set.\n\nFile: modules/image/image.module", "response": "function image_effect_save($effect) {\n if (!empty($effect['ieid'])) {\n drupal_write_record('image_effects', $effect, 'ieid');\n }\n else {\n drupal_write_record('image_effects', $effect);\n }\n $style = image_style_load(NULL, $effect['isid']);\n image_style_flush($style);\n return $effect;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b51a9e9080", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/theme_image_style_effects/7.x", "instruction": "I need the code for `theme_image_style_effects($variables)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Returns HTML for a listing of the effects within a specific image style.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/image/image.admin.inc", "response": "function theme_image_style_effects($variables) {\n $form = $variables['form'];\n\n $rows = array();\n\n foreach (element_children($form) as $key) {\n $row = array();\n $form[$key]['weight']['#attributes']['class'] = array('image-effect-order-weight');\n if (is_numeric($key)) {\n $summary = drupal_render($form[$key]['summary']);\n $row[] = drupal_render($form[$key]['label']) . (empty($summary) ? '' : ' ' . $summary);\n $row[] = drupal_render($form[$key]['weight']);\n $row[] = drupal_render($form[$key]['configure']);\n $row[] = drupal_render($form[$key]['remove']);\n }\n else {\n // Add the row for adding a new image effect.\n $row[] = '
              ' . drupal_render($form['new']['new']) . drupal_render($form['new']['add']) . '
              ';\n $row[] = drupal_render($form['new']['weight']);\n $row[] = array('data' => '', 'colspan' => 2);\n }\n\n if (!isset($form[$key]['#access']) || $form[$key]['#access']) {\n $rows[] = array(\n 'data' => $row,\n // Use a strict (===) comparison since $key can be 0.\n 'class' => !empty($form[$key]['weight']['#access']) || $key === 'new' ? array('draggable') : array(),\n );\n }\n }\n\n $header = array(\n t('Effect'),\n t('Weight'),\n array('data' => t('Operations'), 'colspan' => 2),\n );\n\n if (count($rows) == 1 && $form['new']['#access']) {\n array_unshift($rows, array(array(\n 'data' => t('There are currently no effects in this style. Add one by selecting an option below.'),\n 'colspan' => 4,\n )));\n }\n\n $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'image-style-effects')));\n drupal_add_tabledrag('image-style-effects', 'order', 'sibling', 'image-effect-order-weight');\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b51e6f214b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/theme_update_last_check/7.x", "instruction": "Implement `theme_update_last_check($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the last time we checked for update data.", "context": "In addition to properly formatting the given timestamp, this function also provides a \"Check manually\" link that refreshes the available update and redirects back to the same page.\n\nParameters:\n- $variables: An associative array containing: - last: The timestamp when the site last checked for available updates.\n\nFile: modules/update/update.module", "response": "function theme_update_last_check($variables) {\n $last = $variables['last'];\n $output = '
              ';\n $output .= $last ? t('Last checked: @time ago', array('@time' => format_interval(REQUEST_TIME - $last))) : t('Last checked: never');\n $output .= ' (' . l(t('Check manually'), 'admin/reports/updates/check', array('query' => drupal_get_destination())) . ')';\n $output .= \"
              \\n\";\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5270ae802", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_options_list/7.x", "instruction": "I need the code for `taxonomy_options_list($field, $instance, $entity_type, $entity)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_options_list().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_options_list($field, $instance, $entity_type, $entity) {\n $function = !empty($field['settings']['options_list_callback']) ? $field['settings']['options_list_callback'] : 'taxonomy_allowed_values';\n return $function($field);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5426cc57f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_info/7.x", "instruction": "Give me the example code for `hook_node_info()` in Drupal 7. Hook description: Define module-provided node types.", "context": "This hook allows a module to define one or more of its own node types. For example, the blog module uses it to define a blog node-type named \"Blog entry.\" The name and attributes of each desired node type are specified in an array returned by the hook.\n\nOnly module-provided node types should be defined through this hook. User- provided (or 'custom') node types should be defined only in the 'node_type' database table, and should be maintained by using the node_type_save() and node_type_delete() functions.\n\nReturns: An array of information defining the module's node types. The array contains a sub-array for each node type, with the machine-readable type name as the key. Each sub-array has up to 10 attributes. Possible attributes: - name: (required) The human-readable name of the node type. - base: (required) The base name for implementations of node-type-specific hooks that respond to this node type. Base is usually the name of the module or 'node_content', but not always. See @link node_api_hooks Node API hooks @endlink for more information. - description: (required) A brief description of the node type. - help: (optional) Help information shown to the user when creating a node of this type. - has_title: (optional) A Boolean indicating whether or not this node type has a title field. - title_label: (optional) The label for the title field of this content type. - locked: (optional) A Boolean indicating whether the administrator can change the machine name of this type. FALSE = changeable (not locked), TRUE = unchangeable (locked). The machine name of a node type should contain only letters, numbers, and underscores. Underscores will be converted into hyphens for the purpose of constructing URLs. All attributes of a node type that are defined through this hook (except for 'locked') can be edited by a site administrator. This includes the machine-readable name of a node type, if 'locked' is set to FALSE.\n\nFile: modules/node/node.api.php", "response": "function hook_node_info() {\n return array(\n 'blog' => array(\n 'name' => t('Blog entry'),\n 'base' => 'blog',\n 'description' => t('Use for multi-user blogs. Every user gets a personal blog.'),\n )\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5628aa797", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_parent_options/7.x", "instruction": "Implement `menu_parent_options($menus, $item, $type = '')` in PHP for Drupal 7. Required behavior: Return a list of menu items that are valid possible parents for the given menu item.", "context": "Parameters:\n- $menus: An array of menu names and titles, such as from menu_get_menus().\n- $item: The menu item or the node type for which to generate a list of parents. If $item['mlid'] == 0 then the complete tree is returned.\n- $type: The node type for which to generate a list of parents. If $item itself is a node type then $type is ignored.\n\nReturns: An array of menu link titles keyed on the a string containing the menu name and mlid. The list excludes the given item and its children.\n\nFile: modules/menu/menu.module", "response": "function menu_parent_options($menus, $item, $type = '') {\n // The menu_links table can be practically any size and we need a way to\n // allow contrib modules to provide more scalable pattern choosers.\n // hook_form_alter is too late in itself because all the possible parents are\n // retrieved here, unless menu_override_parent_selector is set to TRUE.\n if (variable_get('menu_override_parent_selector', FALSE)) {\n return array();\n }\n\n $available_menus = array();\n if (!is_array($item)) {\n // If $item is not an array then it is a node type.\n // Use it as $type and prepare a dummy menu item for _menu_get_options().\n $type = $item;\n $item = array('mlid' => 0);\n }\n if (empty($type)) {\n // If no node type is set, use all menus given to this function.\n $available_menus = $menus;\n }\n else {\n // If a node type is set, use all available menus for this type.\n $type_menus = variable_get('menu_options_' . $type, array('main-menu' => 'main-menu'));\n foreach ($type_menus as $menu) {\n $available_menus[$menu] = $menu;\n }\n }\n\n return _menu_get_options($menus, $available_menus, $item);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5652e54e8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_form_taxonomy_form_vocabulary_alter/7.x", "instruction": "Implement `forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state, $form_id)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter() for taxonomy_form_vocabulary().", "context": "File: modules/forum/forum.module", "response": "function forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state, $form_id) {\n $vid = variable_get('forum_nav_vocabulary', 0);\n if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) {\n $form['help_forum_vocab'] = array(\n '#markup' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'),\n '#weight' => -1,\n );\n // Forum's vocabulary always has single hierarchy. Forums and containers\n // have only one parent or no parent for root items. By default this value\n // is 0.\n $form['hierarchy']['#value'] = 1;\n // Do not allow to delete forum's vocabulary.\n $form['actions']['delete']['#access'] = FALSE;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b56c2747fc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_uninstall_schema/7.x", "instruction": "I need the code for `drupal_uninstall_schema($module)` in Drupal 7 (includes/common.inc). It must do this: Removes all tables defined in a module's hook_schema().", "context": "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.\n\nParameters:\n- $module: The module for which the tables will be removed.\n\nReturns: An array of arrays with the following key/value pairs: - success: a boolean indicating whether the query succeeded. - query: the SQL query(s) executed, passed through check_plain().\n\nFile: includes/common.inc", "response": "function drupal_uninstall_schema($module) {\n $schema = drupal_get_schema_unprocessed($module);\n _drupal_schema_initialize($schema, $module, FALSE);\n\n foreach ($schema as $table) {\n if (db_table_exists($table['name'])) {\n db_drop_table($table['name']);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b57fd97c8a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.pages.inc/function/openid_user_delete_form/7.x", "instruction": "Implement `openid_user_delete_form($form, $form_state, $account, $aid = 0)` in PHP for Drupal 7. Required behavior: Menu callback; Delete the specified OpenID identity from the system.", "context": "File: modules/openid/openid.pages.inc", "response": "function openid_user_delete_form($form, $form_state, $account, $aid = 0) {\n $authname = db_query(\"SELECT authname FROM {authmap} WHERE uid = :uid AND aid = :aid AND module = 'openid'\", array(\n ':uid' => $account->uid,\n ':aid' => $aid,\n ))\n ->fetchField();\n return confirm_form(array(), t('Are you sure you want to delete the OpenID %authname for %user?', array('%authname' => $authname, '%user' => $account->name)), 'user/' . $account->uid . '/openid');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b586045e6a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_insert/7.x", "instruction": "In Drupal 7, write the function `forum_node_insert($node)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_insert().", "context": "File: modules/forum/forum.module", "response": "function forum_node_insert($node) {\n if (_forum_node_check_node_type($node)) {\n if (!empty($node->forum_tid)) {\n $nid = db_insert('forum')\n ->fields(array(\n 'tid' => $node->forum_tid,\n 'vid' => $node->vid,\n 'nid' => $node->nid,\n ))\n ->execute();\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b588f0efb7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_formatter_info/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_formatter_info()` (modules/field/field.api.php): Expose Field API formatter types.", "context": "Formatters handle the display of field values. Formatter hooks are typically called by the Field Attach API field_attach_prepare_view() and field_attach_view() functions.\n\nReturns: An array describing the formatter types implemented by the module. The keys are formatter type names. To avoid name clashes, formatter type names should be prefixed with the name of the module that exposes them. The values are arrays describing the formatter type, with the following key/value pairs: - label: The human-readable name of the formatter type. - description: A short description for the formatter type. - field types: An array of field types the formatter supports. - settings: An array whose keys are the names of the settings available for the formatter type, and whose values are the default values for those settings.\n\nFile: modules/field/field.api.php", "response": "function hook_field_formatter_info() {\n return array(\n 'text_default' => array(\n 'label' => t('Default'),\n 'field types' => array('text', 'text_long', 'text_with_summary'),\n ),\n 'text_plain' => array(\n 'label' => t('Plain text'),\n 'field types' => array('text', 'text_long', 'text_with_summary'),\n ),\n\n // The text_trimmed formatter displays the trimmed version of the\n // full element of the field. It is intended to be used with text\n // and text_long fields. It also works with text_with_summary\n // fields though the text_summary_or_trimmed formatter makes more\n // sense for that field type.\n 'text_trimmed' => array(\n 'label' => t('Trimmed'),\n 'field types' => array('text', 'text_long', 'text_with_summary'),\n ),\n\n // The 'summary or trimmed' field formatter for text_with_summary\n // fields displays returns the summary element of the field or, if\n // the summary is empty, the trimmed version of the full element\n // of the field.\n 'text_summary_or_trimmed' => array(\n 'label' => t('Summary or trimmed'),\n 'field types' => array('text_with_summary'),\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5a8494e46", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.install/function/_update_7000_field_sql_storage_write/7.x", "instruction": "Implement `_update_7000_field_sql_storage_write($entity_type, $bundle, $entity_id, $revision_id, $field_name, $data)` in PHP for Drupal 7. Required behavior: Utility function: write field data directly to SQL storage.", "context": "This function can be used for databases whose schema is at field module version 7000 or higher.\n\nFile: modules/field/modules/field_sql_storage/field_sql_storage.install", "response": "function _update_7000_field_sql_storage_write($entity_type, $bundle, $entity_id, $revision_id, $field_name, $data) {\n $table_name = \"field_data_{$field_name}\";\n $revision_name = \"field_revision_{$field_name}\";\n\n db_delete($table_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $entity_id)\n ->execute();\n db_delete($revision_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $entity_id)\n ->condition('revision_id', $revision_id)\n ->execute();\n\n $columns = array();\n foreach ($data as $langcode => $items) {\n foreach ($items as $delta => $item) {\n $record = array(\n 'entity_type' => $entity_type,\n 'entity_id' => $entity_id,\n 'revision_id' => $revision_id,\n 'bundle' => $bundle,\n 'delta' => $delta,\n 'language' => $langcode,\n );\n foreach ($item as $column => $value) {\n $record[_field_sql_storage_columnname($field_name, $column)] = $value;\n }\n\n $records[] = $record;\n // Record the columns used.\n $columns += $record;\n }\n }\n\n if ($columns) {\n $query = db_insert($table_name)->fields(array_keys($columns));\n $revision_query = db_insert($revision_name)->fields(array_keys($columns));\n foreach ($records as $record) {\n $query->values($record);\n if ($revision_id) {\n $revision_query->values($record);\n }\n }\n $query->execute();\n $revision_query->execute();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5b9388c6d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_build_filter_query/7.x", "instruction": "Implement `dblog_build_filter_query()` in PHP for Drupal 7. Required behavior: Builds a query for database log administration filters based on session.", "context": "Returns (array): An associative array with keys 'where' and 'args'.\n\nFile: modules/dblog/dblog.admin.inc", "response": "function dblog_build_filter_query() {\n if (empty($_SESSION['dblog_overview_filter'])) {\n return;\n }\n\n $filters = dblog_filters();\n\n // Build query\n $where = $args = array();\n foreach ($_SESSION['dblog_overview_filter'] as $key => $filter) {\n $filter_where = array();\n foreach ($filter as $value) {\n $filter_where[] = $filters[$key]['where'];\n $args[] = $value;\n }\n if (!empty($filter_where)) {\n $where[] = '(' . implode(' OR ', $filter_where) . ')';\n }\n }\n $where = !empty($where) ? implode(' AND ', $where) : '';\n\n return array(\n 'where' => $where,\n 'args' => $args,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5cd726ba6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/_node_revision_access/7.x", "instruction": "I need the code for `_node_revision_access($node, $op = 'view', $account = NULL)` in Drupal 7 (modules/node/node.module). It must do this: Access callback: Checks node revision access.", "context": "Parameters:\n- $node: The node to check.\n- $op: (optional) The specific operation being checked. Defaults to 'view.'\n- $account (object): (optional) A user object representing the user for whom the operation is to be performed. Determines access for a user other than the current user.\n\nReturns: TRUE if the operation may be performed, FALSE otherwise.\n\nFile: modules/node/node.module", "response": "function _node_revision_access($node, $op = 'view', $account = NULL) {\n $access = &drupal_static(__FUNCTION__, array());\n\n $map = array(\n 'view' => 'view revisions',\n 'update' => 'revert revisions',\n 'delete' => 'delete revisions',\n );\n\n if (!$node || !isset($map[$op])) {\n // If there was no node to check against, or the $op was not one of the\n // supported ones, we return access denied.\n return FALSE;\n }\n\n if (!isset($account)) {\n $account = $GLOBALS['user'];\n }\n\n // Statically cache access by revision ID, user account ID, and operation.\n $cid = $node->vid . ':' . $account->uid . ':' . $op;\n\n if (!isset($access[$cid])) {\n // Perform basic permission checks first.\n if (!user_access($map[$op], $account) && !user_access('administer nodes', $account)) {\n return $access[$cid] = FALSE;\n }\n\n $node_current_revision = node_load($node->nid);\n $is_current_revision = $node_current_revision->vid == $node->vid;\n\n // There should be at least two revisions. If the vid of the given node and\n // the vid of the current revision differ, then we already have two\n // different revisions so there is no need for a separate database check.\n // Also, if you try to revert to or delete the current revision, that's not\n // good.\n if ($is_current_revision && (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() == 1 || $op == 'update' || $op == 'delete')) {\n $access[$cid] = FALSE;\n }\n elseif (user_access('administer nodes', $account)) {\n $access[$cid] = TRUE;\n }\n else {\n // First check the access to the current revision and finally, if the node\n // passed in is not the current revision then access to that, too.\n $access[$cid] = node_access($op, $node_current_revision, $account) && ($is_current_revision || node_access($op, $node, $account));\n }\n }\n\n return $access[$cid];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b5e390a8df", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_valid_token/7.x", "instruction": "I need the code for `drupal_valid_token($token, $value = '', $skip_anonymous = FALSE)` in Drupal 7 (includes/common.inc). It must do this: Validates a token based on $value, the user session, and the private key.", "context": "Parameters:\n- $token: The token to be validated.\n- $value: An additional value to base the token on.\n- $skip_anonymous: Set to true to skip token validation for anonymous users.\n\nReturns: True for a valid token, false for an invalid token. When $skip_anonymous is true, the return value will always be true for anonymous users.\n\nFile: includes/common.inc", "response": "function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) {\n global $user;\n return (($skip_anonymous && $user->uid == 0) || ($token === drupal_get_token($value)));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b621d71af9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_show/7.x", "instruction": "Implement `node_show($node, $message = FALSE)` in PHP for Drupal 7. Required behavior: Generates an array which displays a node detail page.", "context": "Parameters:\n- $node: A node object.\n- $message: A flag which sets a page title relevant to the revision being viewed.\n\nReturns: A $page element suitable for use by drupal_render().\n\nFile: modules/node/node.module", "response": "function node_show($node, $message = FALSE) {\n if ($message) {\n drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp))), PASS_THROUGH);\n }\n\n // For markup consistency with other pages, use node_view_multiple() rather than node_view().\n $nodes = node_view_multiple(array($node->nid => $node), 'full');\n\n // Update the history table, stating that this user viewed this node.\n node_tag_new($node);\n\n return $nodes;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b623babea1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_realpath/7.x", "instruction": "In Drupal 7, write the function `drupal_realpath($uri)` (file includes/file.inc) so that it does the following: Resolves the absolute filepath of a local URI or filepath.", "context": "The use of drupal_realpath() is discouraged, because it does not work for remote URIs. Except in rare cases, URIs should not be manually resolved.\n\nOnly use this function if you know that the stream wrapper in the URI uses the local file system, and you need to pass an absolute path to a function that is incompatible with stream URIs.\n\nParameters:\n- $uri (string): A stream wrapper URI or a filepath, possibly including one or more symbolic links.\n\nReturns (string|false): The absolute local filepath (with no symbolic links), or FALSE on failure.\n\nFile: includes/file.inc", "response": "function drupal_realpath($uri) {\n // If this URI is a stream, pass it off to the appropriate stream wrapper.\n // Otherwise, attempt PHP's realpath. This allows use of drupal_realpath even\n // for unmanaged files outside of the stream wrapper interface.\n if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {\n return $wrapper->realpath();\n }\n // Check that the URI has a value. There is a bug in PHP 5.2 on *BSD systems\n // that makes realpath not return FALSE as expected when passing an empty\n // variable.\n // @todo Remove when Drupal drops support for PHP 5.2.\n elseif (!empty($uri)) {\n return realpath($uri);\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b63cf632e0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_make_sticky_action/7.x", "instruction": "I need the code for `node_make_sticky_action($node, $context = array())` in Drupal 7 (modules/node/node.module). It must do this: Sets the sticky-at-top-of-list property of a node to 1.", "context": "Parameters:\n- $node: A node object.\n- $context: (optional) Array of additional information about what triggered the action. Not used for this action.\n\nFile: modules/node/node.module", "response": "function node_make_sticky_action($node, $context = array()) {\n $node->sticky = NODE_STICKY;\n watchdog('action', 'Set @type %title to sticky.', array('@type' => node_type_get_name($node), '%title' => $node->title));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b63e9bde8d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_delete/7.x", "instruction": "Give me the example code for `hook_file_delete($file)` in Drupal 7. Hook description: Respond to a file being deleted.", "context": "Parameters:\n- $file: The file that has just been deleted.\n\nFile: modules/system/system.api.php", "response": "function hook_file_delete($file) {\n // Delete all information associated with the file.\n db_delete('upload')->condition('fid', $file->fid)->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b63fee30fd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_children_relative_depth/7.x", "instruction": "In Drupal 7, write the function `menu_link_children_relative_depth($item)` (file includes/menu.inc) so that it does the following: Finds the depth of an item's children relative to its depth.", "context": "For example, if the item has a depth of 2, and the maximum of any child in the menu link tree is 5, the relative depth is 3.\n\nParameters:\n- $item: An array representing a menu link item.\n\nReturns: The relative depth, or zero.\n\nFile: includes/menu.inc", "response": "function menu_link_children_relative_depth($item) {\n $query = db_select('menu_links');\n $query->addField('menu_links', 'depth');\n $query->condition('menu_name', $item['menu_name']);\n $query->orderBy('depth', 'DESC');\n $query->range(0, 1);\n\n $i = 1;\n $p = 'p1';\n while ($i <= MENU_MAX_DEPTH && $item[$p]) {\n $query->condition($p, $item[$p]);\n $p = 'p' . ++$i;\n }\n\n $max_depth = $query->execute()->fetchField();\n\n return ($max_depth > $item['depth']) ? $max_depth - $item['depth'] : 0;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b6422bb89b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/_user_mail_notify/7.x", "instruction": "I need the code for `_user_mail_notify($op, $account, $language = NULL)` in Drupal 7 (modules/user/user.module). It must do this: Conditionally create and send a notification email when a certain operation happens on the given user account.", "context": "Parameters:\n- $op: The operation being performed on the account. Possible values: - 'register_admin_created': Welcome message for user created by the admin. - 'register_no_approval_required': Welcome message when user self-registers. - 'register_pending_approval': Welcome message, user pending admin approval. - 'password_reset': Password recovery request. - 'status_activated': Account activated. - 'status_blocked': Account blocked. - 'cancel_confirm': Account cancellation request. - 'status_canceled': Account canceled.\n- $account: The user object of the account being notified. Must contain at least the fields 'uid', 'name', and 'mail'.\n- $language: Optional language to use for the notification, overriding account language.\n\nReturns: The return value from drupal_mail_system()->mail(), if ends up being called.\n\nFile: modules/user/user.module", "response": "function _user_mail_notify($op, $account, $language = NULL) {\n // By default, we always notify except for canceled and blocked.\n $default_notify = ($op != 'status_canceled' && $op != 'status_blocked');\n $notify = variable_get('user_mail_' . $op . '_notify', $default_notify);\n if ($notify) {\n $params['account'] = $account;\n $language = $language ? $language : user_preferred_language($account);\n $mail = drupal_mail('user', $op, $account->mail, $language, $params);\n if ($op == 'register_pending_approval') {\n // If a user registered requiring admin approval, notify the admin, too.\n // We use the site default language for this.\n drupal_mail('user', 'register_pending_approval_admin', variable_get('site_mail', ini_get('sendmail_from')), language_default(), $params);\n }\n }\n return empty($mail) ? NULL : $mail['result'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b64d807d73", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_meta_httpequiv/7.x", "instruction": "In Drupal 7, write the function `_openid_meta_httpequiv($equiv, $html)` (file modules/openid/openid.inc) so that it does the following: Pull the http-equiv attribute out of an html meta element", "context": "File: modules/openid/openid.inc", "response": "function _openid_meta_httpequiv($equiv, $html) {\n preg_match('||iUs', $html, $matches);\n if (isset($matches[1])) {\n preg_match('|content=[\"\\']([^\"]+)[\"\\']|iUs', $matches[1], $content);\n if (isset($content[1])) {\n return $content[1];\n }\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b6679cb9a3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_discovery_method_info_alter/7.x", "instruction": "Give me the example code for `hook_openid_discovery_method_info_alter(&$methods)` in Drupal 7. Hook description: Allow modules to alter discovery methods.", "context": "File: modules/openid/openid.api.php", "response": "function hook_openid_discovery_method_info_alter(&$methods) {\n // Remove XRI discovery scheme.\n unset($methods['xri']);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b670028d85", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/url/7.x", "instruction": "I need the code for `url($path = NULL, array $options = array())` in Drupal 7 (includes/common.inc). It must do this: Generates an internal or external URL.", "context": "When creating links in modules, consider whether l() could be a better alternative than url().\n\nParameters:\n- $path: (optional) The internal path or external URL being linked to, such as \"node/34\" or \"http://example.com/foo\". The default value is equivalent to passing in ''. A few notes: - If you provide a full URL, it will be considered an external URL. - If you provide only the path (e.g. \"node/34\"), it will be considered an internal link. In this case, it should be a system URL, and it will be replaced with the alias, if one exists. Additional query arguments for internal paths must be supplied in $options['query'], not included in $path. - If you provide an internal path and $options['alias'] is set to TRUE, the path is assumed already to be the correct path alias, and the alias is not looked up. - The special string '' generates a link to the site's base URL. - If your external URL contains a query (e.g. http://example.com/foo?a=b), then you can either URL encode the query keys and values yourself and include them in $path, or use $options['query'] to let this function URL encode them.\n- $options: (optional) An associative array of additional options, with the following elements: - 'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL. - 'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character. - 'absolute': Defaults to FALSE. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed. - 'alias': Defaults to FALSE. Whether the given path is a URL alias already. - 'external': Whether the given path is an external URL. - 'language': An optional language object. If the path being linked to is internal to the site, $options['language'] is used to look up the alias for the URL. If $options['language'] is omitted, the global $language_url will be used. - 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can only be enforced when the variable 'https' is set to TRUE. - 'base_url': Only used internally, to modify the base URL when a language dependent URL requires so. - 'prefix': Only used internally, to modify the path when a language dependent URL requires so. - 'script': The script filename in Drupal's root directory to use when clean URLs are disabled, such as 'index.php'. Defaults to an empty string, as most modern web servers automatically find 'index.php'. If clean URLs are disabled, the value of $path is appended as query parameter 'q' to $options['script'] in the returned URL. When deploying Drupal on a web server that cannot be configured to automatically find index.php, then hook_url_outbound_alter() can be implemented to force this value to 'index.php'. - 'entity_type': The entity type of the object that called url(). Only set if url() is invoked by entity_uri(). - 'entity': The entity object (such as a node) for which the URL is being generated. Only set if url() is invoked by entity_uri().\n\nReturns: A string containing a URL to the given path.\n\nFile: includes/common.inc", "response": "function url($path = NULL, array $options = array()) {\n // Merge in defaults.\n $options += array(\n 'fragment' => '',\n 'query' => array(),\n 'absolute' => FALSE,\n 'alias' => FALSE,\n 'prefix' => ''\n );\n\n // Determine whether this is an external link, but ensure that the current\n // path is always treated as internal by default (to prevent external link\n // injection vulnerabilities).\n if (!isset($options['external'])) {\n $options['external'] = $path === $_GET['q'] ? FALSE : url_is_external($path);\n }\n\n // Preserve the original path before altering or aliasing.\n $original_path = $path;\n\n // Allow other modules to alter the outbound URL and options.\n drupal_alter('url_outbound', $path, $options, $original_path);\n\n if (isset($options['fragment']) && $options['fragment'] !== '') {\n $options['fragment'] = '#' . $options['fragment'];\n }\n\n if ($options['external']) {\n // Split off the fragment.\n if (strpos($path, '#') !== FALSE) {\n list($path, $old_fragment) = explode('#', $path, 2);\n // If $options contains no fragment, take it over from the path.\n if (isset($old_fragment) && !$options['fragment']) {\n $options['fragment'] = '#' . $old_fragment;\n }\n }\n // Append the query.\n if ($options['query']) {\n $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . drupal_http_build_query($options['query']);\n }\n if (isset($options['https']) && variable_get('https', FALSE)) {\n if ($options['https'] === TRUE) {\n $path = str_replace('http://', 'https://', $path);\n }\n elseif ($options['https'] === FALSE) {\n $path = str_replace('https://', 'http://', $path);\n }\n }\n // Reassemble.\n return $path . $options['fragment'];\n }\n\n // Strip leading slashes from internal paths to prevent them becoming external\n // URLs without protocol. /example.com should not be turned into\n // //example.com.\n $path = ltrim((string) $path, '/');\n\n global $base_url, $base_secure_url, $base_insecure_url;\n\n // The base_url might be rewritten from the language rewrite in domain mode.\n if (!isset($options['base_url'])) {\n if (isset($options['https']) && variable_get('https', FALSE)) {\n if ($options['https'] === TRUE) {\n $options['base_url'] = $base_secure_url;\n $options['absolute'] = TRUE;\n }\n elseif ($options['https'] === FALSE) {\n $options['base_url'] = $base_insecure_url;\n $options['absolute'] = TRUE;\n }\n }\n else {\n $options['base_url'] = $base_url;\n }\n }\n\n // The special path '' links to the default front page.\n if ($path == '') {\n $path = '';\n }\n elseif (!empty($path) && !$options['alias']) {\n $language = isset($options['language']) && isset($options['language']->language) ? $options['language']->language : '';\n require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');\n $alias = drupal_get_path_alias($original_path, $language);\n if ($alias != $original_path) {\n // Strip leading slashes from internal path aliases to prevent them\n // becoming external URLs without protocol. /example.com should not be\n // turned into //example.com.\n $path = ltrim($alias, '/');\n }\n }\n\n $base = $options['absolute'] ? $options['base_url'] . '/' : base_path();\n $prefix = empty($path) ? rtrim((string) $options['prefix'], '/') : $options['prefix'];\n\n // With Clean URLs.\n if (!empty($GLOBALS['conf']['clean_url'])) {\n $path = drupal_encode_path($prefix . $path);\n if ($options['query']) {\n return $base . $path . '?' . drupal_http_build_query($options['query']) . $options['fragment'];\n }\n else {\n return $base . $path . $options['fragment'];\n }\n }\n // Without Clean URLs.\n else {\n $path = $prefix . $path;\n $query = array();\n if (!empty($path)) {\n $query['q'] = $path;\n }\n if ($options['query']) {\n // We do not use array_merge() here to prevent overriding $path via query\n // parameters.\n $query += $options['query'];\n }\n $query = $query ? ('?' . drupal_http_build_query($query)) : '';\n $script = isset($options['script']) ? $options['script'] : '';\n return $base . $script . $query . $options['fragment'];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b673df4a11", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_render_region/7.x", "instruction": "Implement `overlay_render_region($region)` in PHP for Drupal 7. Required behavior: Renders an individual page region.", "context": "This function is primarily intended to be used for checking the content of supplemental overlay regions (e.g., a region containing a toolbar). Passing in a region that is intended to display the main page content is not supported; the region will be rendered by this function, but the main page content will not appear in it. In addition, although this function returns the rendered HTML for the provided region, it does not place it on the final page, nor add any of its associated JavaScript or CSS to the page.\n\nParameters:\n- $region: The name of the page region that should be rendered.\n\nReturns: The rendered HTML of the provided region.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_render_region($region) {\n // Indicate the region that we will be rendering, so that other regions will\n // be hidden by overlay_page_alter() and overlay_block_list_alter().\n overlay_set_regions_to_render(array($region));\n // Do what is necessary to force drupal_render_page() to only display HTML\n // from the requested region. Specifically, declare that the main page\n // content does not need to automatically be added to the page, and pass in\n // a page array that has all theme functions removed (so that overall HTML\n // for the page will not be added either).\n $system_main_content_added = &drupal_static('system_main_content_added');\n $system_main_content_added = TRUE;\n $page = array(\n '#type' => 'page',\n '#theme' => NULL,\n '#theme_wrappers' => array(),\n );\n // Render the region, but do not cache any JavaScript or CSS associated with\n // it. This region might not be included the next time drupal_render_page()\n // is called, and we do not want its JavaScript or CSS to erroneously appear\n // on the final rendered page.\n $original_js = drupal_add_js();\n $original_css = drupal_add_css();\n $original_libraries = drupal_static('drupal_add_library');\n $js = &drupal_static('drupal_add_js');\n $css = &drupal_static('drupal_add_css');\n $libraries = &drupal_static('drupal_add_library');\n $markup = drupal_render_page($page);\n $js = $original_js;\n $css = $original_css;\n $libraries = $original_libraries;\n // Indicate that the main page content has not, in fact, been displayed, so\n // that future calls to drupal_render_page() will be able to render it\n // correctly.\n $system_main_content_added = FALSE;\n // Restore the original behavior of rendering all regions for the next time\n // drupal_render_page() is called.\n overlay_set_regions_to_render(array());\n return $markup;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b68af68508", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_7001/7.x", "instruction": "I need the code for `image_update_7001()` in Drupal 7 (modules/image/image.install). It must do this: Rename possibly misnamed {image_effect} table to {image_effects}.", "context": "File: modules/image/image.install", "response": "function image_update_7001() {\n // Due to a bug in earlier versions of image_update_7000() it is possible\n // to end up with an {image_effect} table where there should be an\n // {image_effects} table.\n if (!db_table_exists('image_effects') && db_table_exists('image_effect')) {\n db_rename_table('image_effect', 'image_effects');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b68f351554", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_delete_page/7.x", "instruction": "Implement `locale_translate_delete_page($lid)` in PHP for Drupal 7. Required behavior: String deletion confirmation page.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_translate_delete_page($lid) {\n if ($source = db_query('SELECT lid, source FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject()) {\n return drupal_get_form('locale_translate_delete_form', $source);\n }\n return MENU_NOT_FOUND;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b695ee6624", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_response/7.x", "instruction": "Give me the example code for `hook_openid_response($response, $account)` in Drupal 7. Hook description: Allow modules to act upon a successful OpenID login.", "context": "Parameters:\n- $response: Response values from the OpenID Provider.\n- $account: The Drupal user account that logged in\n\nFile: modules/openid/openid.api.php", "response": "function hook_openid_response($response, $account) {\n if (isset($response['openid.ns.ax'])) {\n _mymodule_store_ax_fields($response, $account);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-b69853d937", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.phar.inc/function/file_register_phar_wrapper/7.x", "instruction": "Implement `file_register_phar_wrapper()` in PHP for Drupal 7. Required behavior: Registers a phar stream wrapper that is more secure than PHP's built-in one.", "context": "File: includes/file.phar.inc", "response": "function file_register_phar_wrapper() {\n $directory = DRUPAL_ROOT . '/misc/typo3/phar-stream-wrapper/src';\n include_once $directory . '/Assertable.php';\n include_once $directory . '/Behavior.php';\n include_once $directory . '/Exception.php';\n include_once $directory . '/Helper.php';\n include_once $directory . '/Manager.php';\n include_once $directory . '/PharStreamWrapper.php';\n include_once $directory . '/Collectable.php';\n include_once $directory . '/Interceptor/ConjunctionInterceptor.php';\n include_once $directory . '/Interceptor/PharMetaDataInterceptor.php';\n include_once $directory . '/Phar/Container.php';\n include_once $directory . '/Phar/DeserializationException.php';\n include_once $directory . '/Phar/Manifest.php';\n include_once $directory . '/Phar/Reader.php';\n include_once $directory . '/Phar/ReaderException.php';\n include_once $directory . '/Phar/Stub.php';\n include_once $directory . '/Resolvable.php';\n include_once $directory . '/Resolver/PharInvocation.php';\n include_once $directory . '/Resolver/PharInvocationCollection.php';\n include_once $directory . '/Resolver/PharInvocationResolver.php';\n include_once DRUPAL_ROOT . '/misc/typo3/drupal-security/PharExtensionInterceptor.php';\n include_once DRUPAL_ROOT . '/misc/brumann/polyfill-unserialize/src/Unserialize.php';\n\n // Set up a stream wrapper to handle insecurities due to PHP's built-in\n // phar stream wrapper.\n try {\n $behavior = new PharStreamWrapperBehavior();\n PharStreamWrapperManager::initialize(\n $behavior->withAssertion(new PharExtensionInterceptor())\n );\n }\n catch (\\LogicException $e) {\n // Continue if the PharStreamWrapperManager is already initialized.\n // For example, this occurs following a drupal_static_reset(), such\n // as during tests.\n };\n\n // To prevent file_stream_wrapper_valid_scheme() treating \"phar\" as a valid\n // scheme, this is registered with PHP only, not with hook_stream_wrappers()\n // or the internal storage of file_get_stream_wrappers().\n stream_wrapper_register('phar', '\\\\TYPO3\\\\PharStreamWrapper\\\\PharStreamWrapper');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b6ab8a65ed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_object/7.x", "instruction": "I need the code for `menu_get_object($type = 'node', $position = 1, $path = NULL)` in Drupal 7 (includes/menu.inc). It must do this: Gets a loaded object from a router item.", "context": "menu_get_object() provides access to objects loaded by the current router item. For example, on the page node/%node, the router loads the %node object, and calling menu_get_object() will return that. Normally, it is necessary to specify the type of object referenced, however node is the default. The following example tests to see whether the node being displayed is of the \"story\" content type:\n\nParameters:\n- $type: Type of the object. These appear in hook_menu definitions as %type. Core provides aggregator_feed, aggregator_category, contact, filter_format, forum_term, menu, menu_link, node, taxonomy_vocabulary, user. See the relevant {$type}_load function for more on each. Defaults to node.\n- $position: The position of the object in the path, where the first path segment is 0. For node/%node, the position of %node is 1, but for comment/reply/%node, it's 2. Defaults to 1.\n- $path: See menu_get_item() for more on this. Defaults to the current path.\n\nFile: includes/menu.inc", "response": "function menu_get_object($type = 'node', $position = 1, $path = NULL) {\n $router_item = menu_get_item($path);\n if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type . '_load') {\n return $router_item['map'][$position];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b6c619c6ed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_mark/7.x", "instruction": "In Drupal 7, write the function `node_mark($nid, $timestamp)` (file modules/node/node.module) so that it does the following: Determines the type of marker to be displayed for a given node.", "context": "Parameters:\n- $nid: Node ID whose history supplies the \"last viewed\" timestamp.\n- $timestamp: Time which is compared against node's \"last viewed\" timestamp.\n\nReturns: One of the MARK constants.\n\nFile: modules/node/node.module", "response": "function node_mark($nid, $timestamp) {\n global $user;\n $cache = &drupal_static(__FUNCTION__, array());\n\n if (!$user->uid) {\n return MARK_READ;\n }\n if (!isset($cache[$nid])) {\n $cache[$nid] = node_last_viewed($nid);\n }\n if ($cache[$nid] == 0 && $timestamp > NODE_NEW_LIMIT) {\n return MARK_NEW;\n }\n elseif ($timestamp > $cache[$nid] && $timestamp > NODE_NEW_LIMIT) {\n return MARK_UPDATED;\n }\n return MARK_READ;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b6e55395b1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_form_block_admin_configure_submit/7.x", "instruction": "In Drupal 7, write the function `node_form_block_admin_configure_submit($form, &$form_state)` (file modules/node/node.module) so that it does the following: Form submission handler for node_form_block_admin_configure_alter().", "context": "File: modules/node/node.module", "response": "function node_form_block_admin_configure_submit($form, &$form_state) {\n db_delete('block_node_type')\n ->condition('module', $form_state['values']['module'])\n ->condition('delta', $form_state['values']['delta'])\n ->execute();\n $query = db_insert('block_node_type')->fields(array('type', 'module', 'delta'));\n foreach (array_filter($form_state['values']['types']) as $type) {\n $query->values(array(\n 'type' => $type,\n 'module' => $form_state['values']['module'],\n 'delta' => $form_state['values']['delta'],\n ));\n }\n $query->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b6ef7ab89a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_generate_file/7.x", "instruction": "Implement `simpletest_generate_file($filename, $width, $lines, $type = 'binary-text')` in PHP for Drupal 7. Required behavior: Generate test file.", "context": "File: modules/simpletest/simpletest.module", "response": "function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {\n $text = '';\n for ($i = 0; $i < $lines; $i++) {\n // Generate $width - 1 characters to leave space for the \"\\n\" character.\n for ($j = 0; $j < $width - 1; $j++) {\n switch ($type) {\n case 'text':\n $text .= chr(rand(32, 126));\n break;\n case 'binary':\n $text .= chr(rand(0, 31));\n break;\n case 'binary-text':\n default:\n $text .= rand(0, 1);\n break;\n }\n }\n $text .= \"\\n\";\n }\n\n // Create filename.\n file_put_contents('public://' . $filename . '.txt', $text);\n return $filename;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b70366e82b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_drupal/7.x", "instruction": "I need the code for `install_drupal($settings = array())` in Drupal 7 (includes/install.core.inc). It must do this: Installs Drupal either interactively or via an array of passed-in settings.", "context": "The Drupal installation happens in a series of steps, which may be spread out over multiple page requests. Each request begins by trying to determine the last completed installation step (also known as a \"task\"), if one is available from a previous request. Control is then passed to the task handler, which processes the remaining tasks that need to be run until (a) an error is thrown, (b) a new page needs to be displayed, or (c) the installation finishes (whichever happens first).\n\nParameters:\n- $settings: An optional array of installation settings. Leave this empty for a normal, interactive, browser-based installation intended to occur over multiple page requests. Alternatively, if an array of settings is passed in, the installer will attempt to use it to perform the installation in a single page request (optimized for the command line) and not send any output intended for the web browser. See install_state_defaults() for a list of elements that are allowed to appear in this array.\n\nFile: includes/install.core.inc", "response": "function install_drupal($settings = array()) {\n global $install_state;\n // Initialize the installation state with the settings that were passed in,\n // as well as a boolean indicating whether or not this is an interactive\n // installation.\n $interactive = empty($settings);\n $install_state = $settings + array('interactive' => $interactive) + install_state_defaults();\n try {\n // Begin the page request. This adds information about the current state of\n // the Drupal installation to the passed-in array.\n install_begin_request($install_state);\n // Based on the installation state, run the remaining tasks for this page\n // request, and collect any output.\n $output = install_run_tasks($install_state);\n }\n catch (Exception $e) {\n // When an installation error occurs, either send the error to the web\n // browser or pass on the exception so the calling script can use it.\n if ($install_state['interactive']) {\n install_display_output($e->getMessage(), $install_state);\n }\n else {\n throw $e;\n }\n }\n // All available tasks for this page request are now complete. Interactive\n // installations can send output to the browser or redirect the user to the\n // next page.\n if ($install_state['interactive']) {\n if ($install_state['parameters_changed']) {\n // Redirect to the correct page if the URL parameters have changed.\n install_goto(install_redirect_url($install_state));\n }\n elseif (isset($output)) {\n // Display a page only if some output is available. Otherwise it is\n // possible that we are printing a JSON page and theme output should\n // not be shown.\n install_display_output($output, $install_state);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b70678632a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_user_cancel/7.x", "instruction": "Implement `statistics_user_cancel($edit, $account, $method)` in PHP for Drupal 7. Required behavior: Implements hook_user_cancel().", "context": "File: modules/statistics/statistics.module", "response": "function statistics_user_cancel($edit, $account, $method) {\n switch ($method) {\n case 'user_cancel_reassign':\n db_update('accesslog')\n ->fields(array('uid' => 0))\n ->condition('uid', $account->uid)\n ->execute();\n break;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-b71743bf06", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21language.inc/function/language_provider_invoke/7.x", "instruction": "In Drupal 7, write the function `language_provider_invoke($provider_id, $provider = NULL)` (file includes/language.inc) so that it does the following: Helper function used to cache the language negotiation providers results.", "context": "Parameters:\n- $provider_id: The language negotiation provider's identifier.\n- $provider: (optional) An associative array of information about the provider to be invoked (see hook_language_negotiation_info() for details). If not passed in, it will be loaded through language_negotiation_info().\n\nReturns: A language object representing the language chosen by the provider.\n\nFile: includes/language.inc", "response": "function language_provider_invoke($provider_id, $provider = NULL) {\n $results = &drupal_static(__FUNCTION__);\n\n if (!isset($results[$provider_id])) {\n global $user;\n\n // Get languages grouped by status and select only the enabled ones.\n $languages = language_list('enabled');\n $languages = $languages[1];\n\n if (!isset($provider)) {\n $providers = language_negotiation_info();\n $provider = $providers[$provider_id];\n }\n\n if (isset($provider['file'])) {\n require_once DRUPAL_ROOT . '/' . $provider['file'];\n }\n\n // If the language negotiation provider has no cache preference or this is\n // satisfied we can execute the callback.\n $cache = !isset($provider['cache']) || $user->uid || $provider['cache'] == variable_get('cache', 0);\n $callback = isset($provider['callbacks']['language']) ? $provider['callbacks']['language'] : FALSE;\n $langcode = $cache && function_exists($callback) ? $callback($languages) : FALSE;\n $results[$provider_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;\n }\n\n // Since objects are resources, we need to return a clone to prevent the\n // language negotiation provider cache from being unintentionally altered. The\n // same providers might be used with different language types based on\n // configuration.\n return !empty($results[$provider_id]) ? clone($results[$provider_id]) : $results[$provider_id];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b71bc01da6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21authorize.inc/function/authorize_filetransfer_form_submit/7.x", "instruction": "Implement `authorize_filetransfer_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for authorize_filetransfer_form().", "context": "File: includes/authorize.inc", "response": "function authorize_filetransfer_form_submit($form, &$form_state) {\n global $base_url;\n switch ($form_state['triggering_element']['#name']) {\n case 'process_updates':\n\n // Save the connection settings to the DB.\n $filetransfer_backend = $form_state['values']['connection_settings']['authorize_filetransfer_default'];\n\n // If the database is available then try to save our settings. We have\n // to make sure it is available since this code could potentially (will\n // likely) be called during the installation process, before the\n // database is set up.\n try {\n $connection_settings = array();\n foreach ($form_state['values']['connection_settings'][$filetransfer_backend] as $key => $value) {\n // We do *not* want to store passwords in the database, unless the\n // backend explicitly says so via the magic #filetransfer_save form\n // property. Otherwise, we store everything that's not explicitly\n // marked with #filetransfer_save set to FALSE.\n if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) {\n if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') {\n $connection_settings[$key] = $value;\n }\n }\n // The attribute is defined, so only save if set to TRUE.\n elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) {\n $connection_settings[$key] = $value;\n }\n }\n // Set this one as the default authorize method.\n variable_set('authorize_filetransfer_default', $filetransfer_backend);\n // Save the connection settings minus the password.\n variable_set('authorize_filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);\n\n $filetransfer = authorize_get_filetransfer($filetransfer_backend, $form_state['values']['connection_settings'][$filetransfer_backend]);\n\n // Now run the operation.\n authorize_run_operation($filetransfer);\n }\n catch (Exception $e) {\n // If there is no database available, we don't care and just skip\n // this part entirely.\n }\n\n break;\n\n case 'enter_connection_settings':\n $form_state['rebuild'] = TRUE;\n break;\n\n case 'change_connection_type':\n $form_state['rebuild'] = TRUE;\n unset($form_state['values']['connection_settings']['authorize_filetransfer_default']);\n break;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b71e7d5dff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_publish_action/7.x", "instruction": "I need the code for `node_publish_action($node, $context = array())` in Drupal 7 (modules/node/node.module). It must do this: Sets the status of a node to 1 (published).", "context": "Parameters:\n- $node: A node object.\n- $context: (optional) Array of additional information about what triggered the action. Not used for this action.\n\nFile: modules/node/node.module", "response": "function node_publish_action($node, $context = array()) {\n $node->status = NODE_PUBLISHED;\n watchdog('action', 'Set @type %title to published.', array('@type' => node_type_get_name($node), '%title' => $node->title));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b72f8148d5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_image/7.x", "instruction": "Implement `theme_image($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for an image.", "context": "Parameters:\n- $variables: An associative array containing: - path: Either the path of the image file (relative to base_path()) or a full URL. - width: The width of the image (if known). - height: The height of the image (if known). - alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0 always require an alt attribute. The HTML 5 draft allows the alt attribute to be omitted in some cases. Therefore, this variable defaults to an empty string, but can be set to NULL for the attribute to be omitted. Usually, neither omission nor an empty string satisfies accessibility requirements, so it is strongly encouraged for code calling theme('image') to pass a meaningful value for this variable. - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8 - http://www.w3.org/TR/xhtml1/dtds.html - http://dev.w3.org/html5/spec/Overview.html#alt - title: The title text is displayed when the image is hovered in some popular browsers. - attributes: Associative array of attributes to be placed in the img tag.\n\nFile: includes/theme.inc", "response": "function theme_image($variables) {\n $attributes = $variables['attributes'];\n $attributes['src'] = file_create_url($variables['path']);\n\n foreach (array('width', 'height', 'alt', 'title') as $key) {\n\n if (isset($variables[$key])) {\n $attributes[$key] = $variables[$key];\n }\n }\n\n return '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b73b2f298b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_menu_load/7.x", "instruction": "In Drupal 7, write the function `field_ui_menu_load($field_name, $entity_type, $bundle_name, $bundle_pos, $map)` (file modules/field_ui/field_ui.module) so that it does the following: Menu loader; Load a field instance based on field and bundle name.", "context": "Parameters:\n- $field_name: The name of the field, as contained in the path.\n- $entity_type: The name of the entity.\n- $bundle_name: The name of the bundle, as contained in the path.\n- $bundle_pos: The position of $bundle_name in $map.\n- $map: The translated menu router path argument map.\n\nReturns: The field instance array.\n\nFile: modules/field_ui/field_ui.module", "response": "function field_ui_menu_load($field_name, $entity_type, $bundle_name, $bundle_pos, $map) {\n // Extract the actual bundle name from the translated argument map.\n // The menu router path to manage fields of an entity can be shared among\n // multiple bundles. For example:\n // - admin/structure/types/manage/%node_type/fields/%field_ui_menu\n // - admin/structure/types/manage/%comment_node_type/fields/%field_ui_menu\n // The menu system will automatically load the correct bundle depending on the\n // actual path arguments, but this menu loader function only receives the node\n // type string as $bundle_name, which is not the bundle name for comments.\n // We therefore leverage the dynamically translated $map provided by the menu\n // system to retrieve the actual bundle and bundle name for the current path.\n if ($bundle_pos > 0) {\n $bundle = $map[$bundle_pos];\n $bundle_name = field_extract_bundle($entity_type, $bundle);\n }\n // Check whether the field exists at all.\n if ($field = field_info_field($field_name)) {\n // Only return the field if a field instance exists for the given entity\n // type and bundle.\n if ($instance = field_info_instance($entity_type, $field_name, $bundle_name)) {\n return $instance;\n }\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-b7709fb793", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_filter_info/7.x", "instruction": "Implement `filter_filter_info()` in PHP for Drupal 7. Required behavior: Implements hook_filter_info().", "context": "File: modules/filter/filter.module", "response": "function filter_filter_info() {\n $filters['filter_html'] = array(\n 'title' => t('Limit allowed HTML tags'),\n 'process callback' => '_filter_html',\n 'settings callback' => '_filter_html_settings',\n 'default settings' => array(\n 'allowed_html' => '
              ';\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d10ab69828", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_help/7.x", "instruction": "Implement `color_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/color/color.module", "response": "function color_help($path, $arg) {\n switch ($path) {\n case 'admin/help#color':\n $output = '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The Color module allows users with the Administer site configuration permission to quickly and easily change the color scheme of themes that have been built to be compatible with it. For more information, see the online handbook entry for Color module.', array('@color' => 'http://drupal.org/documentation/modules/color')) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Changing colors') . '
              ';\n $output .= '
              ' . t(\"Using the Color module allows you to easily change the color of links, backgrounds, text, and other theme elements. To change the color settings for a compatible theme, select the Settings link for your theme on the Themes administration page. If you don't see a color picker on that page, then your theme is not compatible with the color module. If you are sure that the theme does indeed support the color module, but the color picker does not appear, then follow these troubleshooting procedures.\", array('@configure' => url('admin/appearance'), '@troubleshoot' => 'http://drupal.org/node/109457')) . '
              ';\n $output .= '
              ' . t(\"The Color module saves a modified copy of the theme's specified stylesheets in the files directory. This means that if you make any manual changes to your theme's stylesheet, you must save your color settings again, even if they haven't changed. This step is required because the module stylesheets (in the files directory) need to be recreated to include your changes.\") . '
              ';\n $output .= '
              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d11eeab128", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_build_content/7.x", "instruction": "In Drupal 7, write the function `taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NULL)` (file modules/taxonomy/taxonomy.module) so that it does the following: Builds a structured array representing the term's content.", "context": "The content built for the taxonomy term (field values, file attachments or other term components) will vary depending on the $view_mode parameter.\n\nDrupal core defines the following view modes for terms, with the following\ndefault use cases:\n - full (default): term is displayed on its own page (taxonomy/term/123)\nContributed modules might define additional view modes, or use existing\nview modes in additional contexts.\n\nParameters:\n- $term: A taxonomy term object.\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NULL) {\n if (!isset($langcode)) {\n $langcode = $GLOBALS['language_content']->language;\n }\n\n // Remove previously built content, if exists.\n $term->content = array();\n\n // Allow modules to change the view mode.\n $view_mode = key(entity_view_mode_prepare('taxonomy_term', array($term->tid => $term), $view_mode, $langcode));\n\n // Add the term description if the term has one and it is visible.\n $type = 'taxonomy_term';\n $entity_ids = entity_extract_ids($type, $term);\n $settings = field_view_mode_settings($type, $entity_ids[2]);\n $fields = field_extra_fields_get_display($type, $entity_ids[2], $view_mode);\n if (!empty($term->description) && isset($fields['description']) && $fields['description']['visible']) {\n $term->content['description'] = array(\n '#markup' => check_markup($term->description, $term->format, '', TRUE),\n '#weight' => $fields['description']['weight'],\n '#prefix' => '
              ',\n '#suffix' => '
              ',\n );\n }\n\n // Build fields content.\n // In case of a multiple view, taxonomy_term_view_multiple() already ran the\n // 'prepare_view' step. An internal flag prevents the operation from running\n // twice.\n field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode, $langcode);\n entity_prepare_view('taxonomy_term', array($term->tid => $term), $langcode);\n $term->content += field_attach_view('taxonomy_term', $term, $view_mode, $langcode);\n\n // Allow modules to make their own additions to the taxonomy term.\n module_invoke_all('taxonomy_term_view', $term, $view_mode, $langcode);\n module_invoke_all('entity_view', $term, 'taxonomy_term', $view_mode, $langcode);\n\n // Make sure the current view mode is stored if no module has already\n // populated the related key.\n $term->content += array('#view_mode' => $view_mode);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1281f524d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_has_data/7.x", "instruction": "I need the code for `field_has_data($field)` in Drupal 7 (modules/field/field.module). It must do this: Determine whether a field has any data.", "context": "Parameters:\n- $field: A field structure.\n\nReturns: TRUE if the field has data for any entity; FALSE otherwise.\n\nFile: modules/field/field.module", "response": "function field_has_data($field) {\n $query = new EntityFieldQuery();\n $query = $query->fieldCondition($field)\n ->range(0, 1)\n ->count()\n // Neutralize the 'entity_field_access' query tag added by\n // field_sql_storage_field_storage_query(). The result cannot depend on the\n // access grants of the current user.\n ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');\n\n return (bool) $query\n ->execute() || (bool) $query\n ->age(FIELD_LOAD_REVISION)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d150b7cbdf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/openid_extract_ax_values/7.x", "instruction": "Implement `openid_extract_ax_values($values, $uris)` in PHP for Drupal 7. Required behavior: Extracts values from an OpenID AX Response.", "context": "The values can be returned in two forms:\n - only openid.ax.value. (for single-valued answers)\n - both openid.ax.count. and openid.ax.value.. (for both\n single and multiple-valued answers)\n\nParameters:\n- $values: An array as returned by openid_extract_namespace(..., OPENID_NS_AX).\n- $uris: An array of identifier URIs.\n\nReturns: An array of values.\n\nFile: modules/openid/openid.inc", "response": "function openid_extract_ax_values($values, $uris) {\n $output = array();\n foreach ($values as $key => $value) {\n if (in_array($value, $uris) && preg_match('/^type\\.([^.]+)$/', $key, $matches)) {\n $alias = $matches[1];\n if (isset($values['count.' . $alias])) {\n for ($i = 1; $i <= $values['count.' . $alias]; $i++) {\n $output[] = $values['value.' . $alias . '.' . $i];\n }\n }\n elseif (isset($values['value.' . $alias])) {\n $output[] = $values['value.' . $alias];\n }\n break;\n }\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d154d933ea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_permission/7.x", "instruction": "Implement `user_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/user/user.module", "response": "function user_permission() {\n return array(\n 'administer permissions' => array(\n 'title' => t('Administer permissions'),\n 'restrict access' => TRUE,\n ),\n 'administer users' => array(\n 'title' => t('Administer users'),\n 'restrict access' => TRUE,\n ),\n 'access user profiles' => array(\n 'title' => t('View user profiles'),\n ),\n 'change own username' => array(\n 'title' => t('Change own username'),\n ),\n 'cancel account' => array(\n 'title' => t('Cancel own user account'),\n 'description' => t('Note: content may be kept, unpublished, deleted or transferred to the %anonymous-name user depending on the configured user settings.', array('%anonymous-name' => variable_get('anonymous', t('Anonymous')), '@user-settings-url' => url('admin/config/people/accounts'))),\n ),\n 'select account cancellation method' => array(\n 'title' => t('Select method for cancelling own account'),\n 'restrict access' => TRUE,\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d159d9119c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/_aggregator_parse_opml/7.x", "instruction": "I need the code for `_aggregator_parse_opml($opml)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Parses an OPML file.", "context": "Feeds are recognized as elements with the attributes \"text\" and \"xmlurl\" set.\n\nParameters:\n- $opml: The complete contents of an OPML document.\n\nReturns: An array of feeds, each an associative array with a \"title\" and a \"url\" element, or NULL if the OPML document failed to be parsed. An empty array will be returned if the document is valid but contains no feeds, as some OPML documents do.\n\nFile: modules/aggregator/aggregator.admin.inc", "response": "function _aggregator_parse_opml($opml) {\n $feeds = array();\n $xml_parser = drupal_xml_parser_create($opml);\n if (xml_parse_into_struct($xml_parser, $opml, $values)) {\n foreach ($values as $entry) {\n if ($entry['tag'] == 'OUTLINE' && isset($entry['attributes'])) {\n $item = $entry['attributes'];\n if (!empty($item['XMLURL']) && !empty($item['TEXT'])) {\n $feeds[] = array('title' => $item['TEXT'], 'url' => $item['XMLURL']);\n }\n }\n }\n }\n xml_parser_free($xml_parser);\n\n return $feeds;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d160f49b53", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_help/7.x", "instruction": "I need the code for `file_help($path, $arg)` in Drupal 7 (modules/file/file.module). It must do this: Implements hook_help().", "context": "File: modules/file/file.module", "response": "function file_help($path, $arg) {\n switch ($path) {\n case 'admin/help#file':\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The File module defines a File field type for the Field module, which lets you manage and validate uploaded files attached to content on your site (see the Field module help page for more information about fields). For more information, see the online handbook entry for File module.', array('@field-help' => url('admin/help/field'), '@file' => 'http://drupal.org/documentation/modules/file')) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Attaching files to content') . '
              ';\n $output .= '
              ' . t('The File module allows users to attach files to content (e.g., PDF files, spreadsheets, etc.), when a File field is added to a given content type using the Field UI module. You can add validation options to your File field, such as specifying a maximum file size and allowed file extensions.', array('@fieldui-help' => url('admin/help/field_ui'))) . '
              ';\n $output .= '
              ' . t('Managing attachment display') . '
              ';\n $output .= '
              ' . t('When you attach a file to content, you can specify whether it is listed or not. Listed files are displayed automatically in a section at the bottom of your content; non-listed files are available for embedding in your content, but are not included in the list at the bottom.') . '
              ';\n $output .= '
              ' . t('Managing file locations') . '
              ';\n $output .= '
              ' . t(\"When you create a File field, you can specify a directory where the files will be stored, which can be within either the public or private files directory. Files in the public directory can be accessed directly through the web server; when public files are listed, direct links to the files are used, and anyone who knows a file's URL can download the file. Files in the private directory are not accessible directly through the web server; when private files are listed, the links are Drupal path requests. This adds to server load and download time, since Drupal must start up and resolve the path for each file download request, but allows for access restrictions.\") . '
              ';\n $output .= '
              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d186675024", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_pre_render_conditional_comments/7.x", "instruction": "In Drupal 7, write the function `drupal_pre_render_conditional_comments($elements)` (file includes/common.inc) so that it does the following: #pre_render callback to render #browsers into #prefix and #suffix.", "context": "Parameters:\n- $elements: A render array with a '#browsers' property. The '#browsers' property can contain any or all of the following keys: - 'IE': If FALSE, the element is not rendered by Internet Explorer. If TRUE, the element is rendered by Internet Explorer. Can also be a string containing an expression for Internet Explorer to evaluate as part of a conditional comment. For example, this can be set to 'lt IE 7' for the element to be rendered in Internet Explorer 6, but not in Internet Explorer 7 or higher. Defaults to TRUE. - '!IE': If FALSE, the element is not rendered by browsers other than Internet Explorer. If TRUE, the element is rendered by those browsers. Defaults to TRUE. Examples: - To render an element in all browsers, '#browsers' can be left out or set to array('IE' => TRUE, '!IE' => TRUE). - To render an element in Internet Explorer only, '#browsers' can be set to array('!IE' => FALSE). - To render an element in Internet Explorer 6 only, '#browsers' can be set to array('IE' => 'lt IE 7', '!IE' => FALSE). - To render an element in Internet Explorer 8 and higher and in all other browsers, '#browsers' can be set to array('IE' => 'gte IE 8').\n\nReturns: The passed-in element with markup for conditional comments potentially added to '#prefix' and '#suffix'.\n\nFile: includes/common.inc", "response": "function drupal_pre_render_conditional_comments($elements) {\n $browsers = isset($elements['#browsers']) ? $elements['#browsers'] : array();\n $browsers += array(\n 'IE' => TRUE,\n '!IE' => TRUE,\n );\n\n // If rendering in all browsers, no need for conditional comments.\n if ($browsers['IE'] === TRUE && $browsers['!IE']) {\n return $elements;\n }\n\n // Determine the conditional comment expression for Internet Explorer to\n // evaluate.\n if ($browsers['IE'] === TRUE) {\n $expression = 'IE';\n }\n elseif ($browsers['IE'] === FALSE) {\n $expression = '!IE';\n }\n else {\n $expression = $browsers['IE'];\n }\n\n // Wrap the element's potentially existing #prefix and #suffix properties with\n // conditional comment markup. The conditional comment expression is evaluated\n // by Internet Explorer only. To control the rendering by other browsers,\n // either the \"downlevel-hidden\" or \"downlevel-revealed\" technique must be\n // used. See http://en.wikipedia.org/wiki/Conditional_comment for details.\n $elements += array(\n '#prefix' => '',\n '#suffix' => '',\n );\n if (!$browsers['!IE']) {\n // \"downlevel-hidden\".\n $elements['#prefix'] = \"\\n\\n\";\n }\n else {\n // \"downlevel-revealed\".\n $elements['#prefix'] = \"\\n\\n\" . $elements['#prefix'];\n $elements['#suffix'] .= \"\\n\";\n }\n\n return $elements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d189d97dd3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_url/7.x", "instruction": "In Drupal 7, write the function `file_create_url($uri)` (file includes/file.inc) so that it does the following: Creates a web-accessible URL for a stream to an external or local file.", "context": "Compatibility: normal paths and stream wrappers.\n\nThere are two kinds of local files:\n- \"managed files\", i.e. those stored by a Drupal-compatible stream wrapper.\n These are files that have either been uploaded by users or were generated\n automatically (for example through CSS aggregation).\n- \"shipped files\", i.e. those outside of the files directory, which ship as\n part of Drupal core or contributed modules or themes.\n\nParameters:\n- $uri: The URI to a file for which we need an external URL, or the path to a shipped file.\n\nReturns: A string containing a URL that may be used to access the file. If the provided string already contains a preceding 'http', 'https', or '/', nothing is done and the same string is returned. If a stream wrapper could not be found to generate an external URL, then FALSE is returned.\n\nFile: includes/file.inc", "response": "function file_create_url($uri) {\n // Allow the URI to be altered, e.g. to serve a file from a CDN or static\n // file server.\n drupal_alter('file_url', $uri);\n\n $scheme = file_uri_scheme($uri);\n\n if (!$scheme) {\n // Allow for:\n // - root-relative URIs (e.g. /foo.jpg in http://example.com/foo.jpg)\n // - protocol-relative URIs (e.g. //bar.jpg, which is expanded to\n // http://example.com/bar.jpg by the browser when viewing a page over\n // HTTP and to https://example.com/bar.jpg when viewing a HTTPS page)\n // Both types of relative URIs are characterized by a leading slash, hence\n // we can use a single check.\n if (drupal_substr($uri, 0, 1) == '/') {\n return $uri;\n }\n else {\n // If this is not a properly formatted stream, then it is a shipped file.\n // Therefore, return the urlencoded URI with the base URL prepended.\n return $GLOBALS['base_url'] . '/' . drupal_encode_path($uri);\n }\n }\n elseif ($scheme == 'http' || $scheme == 'https') {\n // Check for HTTP so that we don't have to implement getExternalUrl() for\n // the HTTP wrapper.\n return $uri;\n }\n else {\n // Attempt to return an external URL using the appropriate wrapper.\n if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {\n return $wrapper->getExternalUrl();\n }\n else {\n return FALSE;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d189f17420", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_update_7004/7.x", "instruction": "In Drupal 7, write the function `comment_update_7004()` (file modules/comment/comment.install) so that it does the following: Upgrade the {node_comment_statistics} table.", "context": "File: modules/comment/comment.install", "response": "function comment_update_7004() {\n db_add_field('node_comment_statistics', 'cid', array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The {comment}.cid of the last comment.',\n ));\n db_add_index('node_comment_statistics', 'cid', array('cid'));\n\n // The comment_count index may have been added in Drupal 6.\n if (!db_index_exists('node_comment_statistics', 'comment_count')) {\n // Add an index on the comment_count.\n db_add_index('node_comment_statistics', 'comment_count', array('comment_count'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d19df2475f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_math_mod/7.x", "instruction": "Implement `_openid_math_mod($x, $y)` in PHP for Drupal 7. Required behavior: Calls the mod function from the available math library for OpenID.", "context": "File: modules/openid/openid.inc", "response": "function _openid_math_mod($x, $y) {\n $library = _openid_get_math_library();\n switch ($library) {\n case 'gmp':\n return gmp_mod($x, $y);\n case 'bcmath':\n return bcmod($x, $y);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1a2e39b3a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_element_info/7.x", "instruction": "Implement `user_element_info()` in PHP for Drupal 7. Required behavior: Implements hook_element_info().", "context": "File: modules/user/user.module", "response": "function user_element_info() {\n $types['user_profile_category'] = array(\n '#theme_wrappers' => array('user_profile_category'),\n );\n $types['user_profile_item'] = array(\n '#theme' => 'user_profile_item',\n );\n return $types;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1af756c43", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.pages.inc/function/blog_page_user/7.x", "instruction": "In Drupal 7, write the function `blog_page_user($account)` (file modules/blog/blog.pages.inc) so that it does the following: Menu callback; displays a Drupal page containing recent blog entries of a given user.", "context": "File: modules/blog/blog.pages.inc", "response": "function blog_page_user($account) {\n global $user;\n\n drupal_set_title($title = t(\"@name's blog\", array('@name' => format_username($account))), PASS_THROUGH);\n\n $build = array();\n\n $query = db_select('node', 'n')->extend('PagerDefault');\n $nids = $query\n ->fields('n', array('nid', 'sticky', 'created'))\n ->condition('type', 'blog')\n ->condition('uid', $account->uid)\n ->condition('status', 1)\n ->orderBy('sticky', 'DESC')\n ->orderBy('created', 'DESC')\n ->limit(variable_get('default_nodes_main', 10))\n ->addTag('node_access')\n ->execute()\n ->fetchCol();\n\n if (!empty($nids)) {\n $nodes = node_load_multiple($nids);\n $build += node_view_multiple($nodes);\n $build['pager'] = array(\n '#theme' => 'pager',\n '#weight' => 5,\n );\n }\n else {\n if ($account->uid == $user->uid) {\n drupal_set_message(t('You have not created any blog entries.'));\n }\n else {\n drupal_set_message(t('!author has not created any blog entries.', array('!author' => theme('username', array('account' => $account)))));\n }\n }\n drupal_add_feed('blog/' . $account->uid . '/feed', t('RSS - !title', array('!title' => $title)));\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1bf6c0bc7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_form_vocabulary_validate/7.x", "instruction": "Implement `taxonomy_form_vocabulary_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for taxonomy_form_vocabulary().", "context": "Makes sure that the machine name of the vocabulary is not in the disallowed list (names that conflict with menu items, such as 'list' and 'add').\n\nFile: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_form_vocabulary_validate($form, &$form_state) {\n // During the deletion there is no 'machine_name' key\n if (isset($form_state['values']['machine_name'])) {\n // Do not allow machine names to conflict with taxonomy path arguments.\n $machine_name = $form_state['values']['machine_name'];\n $disallowed = array('add', 'list');\n if (in_array($machine_name, $disallowed)) {\n form_set_error('machine_name', t('The machine-readable name cannot be \"add\" or \"list\".'));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1c7e917c2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_user_operations_block/7.x", "instruction": "Implement `user_user_operations_block($accounts)` in PHP for Drupal 7. Required behavior: Callback function for admin mass blocking users.", "context": "File: modules/user/user.module", "response": "function user_user_operations_block($accounts) {\n $accounts = user_load_multiple($accounts);\n foreach ($accounts as $account) {\n // Skip blocking user if they are already blocked.\n if ($account !== FALSE && $account->status == 1) {\n // For efficiency manually save the original account before applying any\n // changes.\n $account->original = clone $account;\n user_save($account, array('status' => 0));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1d21dfa7d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_error/7.x", "instruction": "I need the code for `xmlrpc_error($code = NULL, $message = NULL, $reset = FALSE)` in Drupal 7 (includes/xmlrpc.inc). It must do this: Generates, temporarily saves, and returns an XML-RPC error object.", "context": "Parameters:\n- $code: The error code.\n- $message: The error message.\n- $reset: TRUE to empty the temporary error storage. Ignored if $code is supplied.\n\nReturns (object): An XML-RPC error object representing $code and $message, or the most recently stored error object if omitted.\n\nFile: includes/xmlrpc.inc", "response": "function xmlrpc_error($code = NULL, $message = NULL, $reset = FALSE) {\n static $xmlrpc_error;\n if (isset($code)) {\n $xmlrpc_error = new stdClass();\n $xmlrpc_error->is_error = TRUE;\n $xmlrpc_error->code = $code;\n $xmlrpc_error->message = $message;\n }\n elseif ($reset) {\n $xmlrpc_error = NULL;\n }\n return $xmlrpc_error;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1dfaf7d73", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_build_uri/7.x", "instruction": "In Drupal 7, write the function `file_build_uri($path)` (file includes/file.inc) so that it does the following: Constructs a URI to Drupal's default files location given a relative path.", "context": "File: includes/file.inc", "response": "function file_build_uri($path) {\n $uri = file_default_scheme() . '://' . $path;\n return file_stream_wrapper_uri_normalize($uri);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1e153481c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_overview/7.x", "instruction": "Implement `book_admin_overview()` in PHP for Drupal 7. Required behavior: Returns an administrative overview of all books.", "context": "Returns (string): A HTML-formatted string with the administrative page content.\n\nFile: modules/book/book.admin.inc", "response": "function book_admin_overview() {\n $rows = array();\n\n $headers = array(t('Book'), t('Operations'));\n\n // Add any recognized books to the table list.\n foreach (book_get_books() as $book) {\n $rows[] = array(l($book['title'], $book['href'], $book['options']), l(t('edit order and titles'), 'admin/content/book/' . $book['nid']));\n }\n\n return theme('table', array('header' => $headers, 'rows' => $rows, 'empty' => t('No books available.')));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d1fe2f5c09", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_filter_form/7.x", "instruction": "Implement `user_filter_form()` in PHP for Drupal 7. Required behavior: Form builder; Return form for user administration filters.", "context": "File: modules/user/user.admin.inc", "response": "function user_filter_form() {\n $session = isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array();\n $filters = user_filters();\n\n $i = 0;\n $form['filters'] = array(\n '#type' => 'fieldset',\n '#title' => t('Show only users where'),\n '#theme' => 'exposed_filters__user',\n );\n foreach ($session as $filter) {\n list($type, $value) = $filter;\n if ($type == 'permission') {\n // Merge arrays of module permissions into one.\n // Slice past the first element '[any]' whose value is not an array.\n $options = call_user_func_array('array_merge', array_values(array_slice($filters[$type]['options'], 1)));\n $value = $options[$value];\n }\n else {\n $value = $filters[$type]['options'][$value];\n }\n $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);\n if ($i++) {\n $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));\n }\n else {\n $form['filters']['current'][] = array('#markup' => t('%property is %value', $t_args));\n }\n }\n\n $form['filters']['status'] = array(\n '#type' => 'container',\n '#attributes' => array('class' => array('clearfix')),\n '#prefix' => ($i ? '
              ' . t('and where') . '
              ' : ''),\n );\n $form['filters']['status']['filters'] = array(\n '#type' => 'container',\n '#attributes' => array('class' => array('filters')),\n );\n foreach ($filters as $key => $filter) {\n $form['filters']['status']['filters'][$key] = array(\n '#type' => 'select',\n '#options' => $filter['options'],\n '#title' => $filter['title'],\n '#default_value' => '[any]',\n );\n }\n\n $form['filters']['status']['actions'] = array(\n '#type' => 'actions',\n '#attributes' => array('class' => array('container-inline')),\n );\n $form['filters']['status']['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => (count($session) ? t('Refine') : t('Filter')),\n );\n if (count($session)) {\n $form['filters']['status']['actions']['undo'] = array(\n '#type' => 'submit',\n '#value' => t('Undo'),\n );\n $form['filters']['status']['actions']['reset'] = array(\n '#type' => 'submit',\n '#value' => t('Reset'),\n );\n }\n\n drupal_add_library('system', 'drupal.form');\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d217064bd1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21xmlrpcs.inc/function/xmlrpc_server_method_help/7.x", "instruction": "In Drupal 7, write the function `xmlrpc_server_method_help($method)` (file includes/xmlrpcs.inc) so that it does the following: Returns the help for an XML-RPC method.", "context": "XML-RPC method system.methodHelp maps to this function.\n\nParameters:\n- $method (string): Name of method for which we return a help string.\n\nReturns (string): Help text for $method.\n\nFile: includes/xmlrpcs.inc", "response": "function xmlrpc_server_method_help($method) {\n $xmlrpc_server = xmlrpc_server_get();\n return $xmlrpc_server->help[$method];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d22e0d4e46", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21module.inc/function/_module_build_dependencies/7.x", "instruction": "Implement `_module_build_dependencies($files)` in PHP for Drupal 7. Required behavior: Determines which modules require and are required by each module.", "context": "Parameters:\n- $files: The array of filesystem objects used to rebuild the cache.\n\nReturns: The same array with the new keys for each module: - requires: An array with the keys being the modules that this module requires. - required_by: An array with the keys being the modules that will not work without this module.\n\nFile: includes/module.inc", "response": "function _module_build_dependencies($files) {\n require_once DRUPAL_ROOT . '/includes/graph.inc';\n foreach ($files as $filename => $file) {\n $graph[$file->name]['edges'] = array();\n if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) {\n foreach ($file->info['dependencies'] as $dependency) {\n $dependency_data = drupal_parse_dependency($dependency);\n $graph[$file->name]['edges'][$dependency_data['name']] = $dependency_data;\n }\n }\n }\n drupal_depth_first_search($graph);\n foreach ($graph as $module => $data) {\n $files[$module]->required_by = isset($data['reverse_paths']) ? $data['reverse_paths'] : array();\n $files[$module]->requires = isset($data['paths']) ? $data['paths'] : array();\n $files[$module]->sort = $data['weight'];\n }\n return $files;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d24a8bfdbe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_system_info_alter/7.x", "instruction": "Give me the example code for `hook_system_info_alter(&$info, $file, $type)` in Drupal 7. Hook description: Alter the information parsed from module and theme .info files", "context": "This hook is invoked in _system_rebuild_module_data() and in _system_rebuild_theme_data(). A module may implement this hook in order to add to or alter the data generated by reading the .info file with drupal_parse_info_file().\n\nParameters:\n- $info: The .info file contents, passed by reference so that it can be altered.\n- $file: Full information about the module or theme, including $file->name, and $file->filename\n- $type: Either 'module' or 'theme', depending on the type of .info file that was passed.\n\nFile: modules/system/system.api.php", "response": "function hook_system_info_alter(&$info, $file, $type) {\n // Only fill this in if the .info file does not define a 'datestamp'.\n if (empty($info['datestamp'])) {\n $info['datestamp'] = filemtime($file->filename);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d2548620d5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_field_types/7.x", "instruction": "I need the code for `field_info_field_types($field_type = NULL)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns information about field types from hook_field_info().", "context": "Parameters:\n- $field_type: (optional) A field type name. If omitted, all field types will be returned.\n\nReturns: Either a field type description, as provided by hook_field_info(), or an array of all existing field types, keyed by field type name.\n\nFile: modules/field/field.info.inc", "response": "function field_info_field_types($field_type = NULL) {\n $info = _field_info_collate_types();\n $field_types = $info['field types'];\n if ($field_type) {\n if (isset($field_types[$field_type])) {\n return $field_types[$field_type];\n }\n }\n else {\n return $field_types;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d26d86afc6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/_fix_gpc_magic_files/7.x", "instruction": "In Drupal 7, write the function `_fix_gpc_magic_files(&$item, $key)` (file includes/common.inc) so that it does the following: Strips slashes from $_FILES items.", "context": "Callback for array_walk() within fix_gpc_magic().\n\nThe tmp_name key is skipped keys since PHP generates single backslashes for file paths on Windows systems.\n\nParameters:\n- $item: An item from $_FILES.\n- $key: The key for the item within $_FILES.\n\nFile: includes/common.inc", "response": "function _fix_gpc_magic_files(&$item, $key) {\n if ($key != 'tmp_name') {\n if (is_array($item)) {\n array_walk($item, '_fix_gpc_magic_files');\n }\n else {\n $item = stripslashes($item);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d27560989f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_formatter_view/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` (modules/field/field.api.php): Build a renderable array for a field value.", "context": "Parameters:\n- $entity_type: The type of $entity.\n- $entity: The entity being displayed.\n- $field: The field structure.\n- $instance: The field instance.\n- $langcode: The language associated with $items.\n- $items: Array of values for this field.\n- $display: The display settings to use, as found in the 'display' entry of instance definitions. The array notably contains the following keys and values; - type: The name of the formatter to use. - settings: The array of formatter settings.\n\nReturns: A renderable array for the $items, as an array of child elements keyed by numeric indexes starting from 0.\n\nFile: modules/field/field.api.php", "response": "function hook_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {\n $element = array();\n $settings = $display['settings'];\n\n switch ($display['type']) {\n case 'sample_field_formatter_simple':\n // Common case: each value is displayed individually in a sub-element\n // keyed by delta. The field.tpl.php template specifies the markup\n // wrapping each value.\n foreach ($items as $delta => $item) {\n $element[$delta] = array('#markup' => $settings['some_setting'] . $item['value']);\n }\n break;\n\n case 'sample_field_formatter_themeable':\n // More elaborate formatters can defer to a theme function for easier\n // customization.\n foreach ($items as $delta => $item) {\n $element[$delta] = array(\n '#theme' => 'mymodule_theme_sample_field_formatter_themeable',\n '#data' => $item['value'],\n '#some_setting' => $settings['some_setting'],\n );\n }\n break;\n\n case 'sample_field_formatter_combined':\n // Some formatters might need to display all values within a single piece\n // of markup.\n $rows = array();\n foreach ($items as $delta => $item) {\n $rows[] = array($delta, $item['value']);\n }\n $element[0] = array(\n '#theme' => 'table',\n '#header' => array(t('Delta'), t('Value')),\n '#rows' => $rows,\n );\n break;\n }\n\n return $element;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d275e0eb2c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_select_locale_form/7.x", "instruction": "In Drupal 7, write the function `install_select_locale_form($form, &$form_state, $locales, $profilename)` (file includes/install.core.inc) so that it does the following: Form constructor for the language selection form.", "context": "File: includes/install.core.inc", "response": "function install_select_locale_form($form, &$form_state, $locales, $profilename) {\n include_once DRUPAL_ROOT . '/includes/iso.inc';\n $languages = _locale_get_predefined_list();\n foreach ($locales as $locale) {\n $name = $locale->langcode;\n if (isset($languages[$name])) {\n $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array('@language' => $languages[$name][1])) : '');\n }\n $form['locale'][$locale->langcode] = array(\n '#type' => 'radio',\n '#return_value' => $locale->langcode,\n '#default_value' => $locale->langcode == 'en' ? 'en' : '',\n '#title' => $name . ($locale->langcode == 'en' ? ' ' . st('(built-in)') : ''),\n '#parents' => array('locale')\n );\n }\n if (count($locales) == 1) {\n $form['help'] = array(\n '#markup' => '

              ' . st('Learn how to install Drupal in other languages') . '

              ',\n );\n }\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => st('Save and continue'),\n );\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d279cd1155", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_is_denied/7.x", "instruction": "I need the code for `drupal_is_denied($ip)` in Drupal 7 (includes/bootstrap.inc). It must do this: Checks to see if an IP address has been blocked.", "context": "Blocked IP addresses are stored in the database by default. However for performance reasons we allow an override in settings.php. This allows us to avoid querying the database at this critical stage of the bootstrap if an administrative interface for IP address blocking is not required.\n\nParameters:\n- $ip: IP address to check.\n\nReturns (bool): TRUE if access is denied, FALSE if access is allowed.\n\nFile: includes/bootstrap.inc", "response": "function drupal_is_denied($ip) {\n // Because this function is called on every page request, we first check\n // for an array of IP addresses in settings.php before querying the\n // database.\n $blocked_ips = variable_get('blocked_ips');\n $denied = FALSE;\n if (isset($blocked_ips) && is_array($blocked_ips)) {\n $denied = in_array($ip, $blocked_ips);\n }\n // Only check if database.inc is loaded already. If\n // $conf['page_cache_without_database'] = TRUE; is set in settings.php,\n // then the database won't be loaded here so the IPs in the database\n // won't be denied. However the user asked explicitly not to use the\n // database and also in this case it's quite likely that the user relies\n // on higher performance solutions like a firewall.\n elseif (class_exists('Database', FALSE)) {\n $denied = (bool)db_query(\"SELECT 1 FROM {blocked_ips} WHERE ip = :ip\", array(':ip' => $ip))->fetchField();\n }\n return $denied;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d27c390686", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_inactive_instances/7.x", "instruction": "I need the code for `field_ui_inactive_instances($entity_type, $bundle_name = NULL)` in Drupal 7 (modules/field_ui/field_ui.module). It must do this: Identifies inactive fields within a bundle.", "context": "File: modules/field_ui/field_ui.module", "response": "function field_ui_inactive_instances($entity_type, $bundle_name = NULL) {\n $params = array('entity_type' => $entity_type);\n\n if (empty($bundle_name)) {\n $active = field_info_instances($entity_type);\n $inactive = array();\n }\n else {\n // Restrict to the specified bundle. For consistency with the case where\n // $bundle_name is NULL, the $active and $inactive arrays are keyed by\n // bundle name first.\n $params['bundle'] = $bundle_name;\n $active = array($bundle_name => field_info_instances($entity_type, $bundle_name));\n $inactive = array($bundle_name => array());\n }\n\n // Iterate on existing definitions, and spot those that do not appear in the\n // $active list collected earlier.\n $all_instances = field_read_instances($params, array('include_inactive' => TRUE));\n foreach ($all_instances as $instance) {\n if (!isset($active[$instance['bundle']][$instance['field_name']])) {\n $inactive[$instance['bundle']][$instance['field_name']] = $instance;\n }\n }\n\n if (!empty($bundle_name)) {\n return $inactive[$bundle_name];\n }\n return $inactive;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d2d571cd8d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_get_type/7.x", "instruction": "In Drupal 7, write the function `node_type_get_type($node)` (file modules/node/node.module) so that it does the following: Returns the node type of the passed node or node type string.", "context": "Parameters:\n- $node: A node object or string that indicates the node type to return.\n\nReturns: A single node type, as an object, or FALSE if the node type is not found. The node type is an object containing fields from hook_node_info() return values, as well as the field 'type' (the machine-readable type) and other fields used internally and defined in _node_types_build(), hook_node_info(), and node_type_set_defaults().\n\nFile: modules/node/node.module", "response": "function node_type_get_type($node) {\n $type = _node_extract_type($node);\n $types = _node_types_build()->types;\n return isset($types[$type]) ? $types[$type] : FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d2d8a0849c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_generate_test_ua/7.x", "instruction": "In Drupal 7, write the function `drupal_generate_test_ua($prefix)` (file includes/bootstrap.inc) so that it does the following: Generates a user agent string with a HMAC and timestamp for simpletest.", "context": "File: includes/bootstrap.inc", "response": "function drupal_generate_test_ua($prefix) {\n static $key;\n\n if (!isset($key)) {\n // We use the salt from settings.php to make the HMAC key, since\n // the database is not yet initialized and we can't access any Drupal variables.\n // The file properties add more entropy not easily accessible to others.\n $key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__);\n }\n // Generate a moderately secure HMAC based on the database credentials.\n $salt = uniqid('', TRUE);\n $check_string = $prefix . ';' . time() . ';' . $salt;\n return $check_string . ';' . drupal_hmac_base64($check_string, $key);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d30f87e1d0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7034/7.x", "instruction": "I need the code for `system_update_7034()` in Drupal 7 (modules/system/system.install). It must do this: Migrate the file path settings and create the new {file_managed} table.", "context": "File: modules/system/system.install", "response": "function system_update_7034() {\n $files_directory = variable_get('file_directory_path', NULL);\n if (variable_get('file_downloads', 1) == 1) {\n // Our default is public, so we don't need to set anything.\n if (!empty($files_directory)) {\n variable_set('file_public_path', $files_directory);\n }\n }\n elseif (variable_get('file_downloads', 1) == 2) {\n variable_set('file_default_scheme', 'private');\n if (!empty($files_directory)) {\n variable_set('file_private_path', $files_directory);\n }\n }\n variable_del('file_downloads');\n\n $schema['file_managed'] = array(\n 'description' => 'Stores information for uploaded files.',\n 'fields' => array(\n 'fid' => array(\n 'description' => 'File ID.',\n 'type' => 'serial',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n ),\n 'uid' => array(\n 'description' => 'The {user}.uid of the user who is associated with the file.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'filename' => array(\n 'description' => 'Name of the file with no path components. This may differ from the basename of the filepath if the file is renamed to avoid overwriting an existing file.',\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'binary' => TRUE,\n ),\n 'uri' => array(\n 'description' => 'URI of file.',\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'binary' => TRUE,\n ),\n 'filemime' => array(\n 'description' => \"The file's MIME type.\",\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n ),\n 'filesize' => array(\n 'description' => 'The size of the file in bytes.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'status' => array(\n 'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'tiny',\n ),\n 'timestamp' => array(\n 'description' => 'UNIX timestamp for when the file was added.',\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n ),\n ),\n 'indexes' => array(\n 'uid' => array('uid'),\n 'status' => array('status'),\n 'timestamp' => array('timestamp'),\n ),\n 'unique keys' => array(\n 'uri' => array('uri'),\n ),\n 'primary key' => array('fid'),\n );\n\n db_create_table('file_managed', $schema['file_managed']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d33c5adec7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_vocabulary_delete/7.x", "instruction": "In Drupal 7, write the function `taxonomy_vocabulary_delete($vid)` (file modules/taxonomy/taxonomy.module) so that it does the following: Deletes a vocabulary.", "context": "This will update all Taxonomy fields so that they don't reference the deleted vocabulary. It also will delete fields that have no remaining vocabulary references. All taxonomy terms of the deleted vocabulary will be deleted as well.\n\nParameters:\n- $vid: A vocabulary ID.\n\nReturns: Constant indicating items were deleted.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_vocabulary_delete($vid) {\n $vocabulary = taxonomy_vocabulary_load($vid);\n\n $transaction = db_transaction();\n try {\n // Only load terms without a parent, child terms will get deleted too.\n $result = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid = :vid AND th.parent = 0', array(':vid' => $vid))->fetchCol();\n foreach ($result as $tid) {\n taxonomy_term_delete($tid);\n }\n db_delete('taxonomy_vocabulary')\n ->condition('vid', $vid)\n ->execute();\n\n field_attach_delete_bundle('taxonomy_term', $vocabulary->machine_name);\n module_invoke_all('taxonomy_vocabulary_delete', $vocabulary);\n module_invoke_all('entity_delete', $vocabulary, 'taxonomy_vocabulary');\n\n // Load all Taxonomy module fields and delete those which use only this\n // vocabulary.\n $taxonomy_fields = field_read_fields(array('module' => 'taxonomy'));\n foreach ($taxonomy_fields as $field_name => $taxonomy_field) {\n $modified_field = FALSE;\n // Term reference fields may reference terms from more than one\n // vocabulary.\n foreach ($taxonomy_field['settings']['allowed_values'] as $key => $allowed_value) {\n if ($allowed_value['vocabulary'] == $vocabulary->machine_name) {\n unset($taxonomy_field['settings']['allowed_values'][$key]);\n $modified_field = TRUE;\n }\n }\n if ($modified_field) {\n if (empty($taxonomy_field['settings']['allowed_values'])) {\n field_delete_field($field_name);\n }\n else {\n // Update the field definition with the new allowed values.\n field_update_field($taxonomy_field);\n }\n }\n }\n\n cache_clear_all();\n taxonomy_vocabulary_static_reset();\n\n return SAVED_DELETED;\n }\n catch (Exception $e) {\n $transaction->rollback();\n watchdog_exception('taxonomy', $e);\n throw $e;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d35f2f3374", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_crop/7.x", "instruction": "Implement `image_gd_crop(stdClass $image, $x, $y, $width, $height)` in PHP for Drupal 7. Required behavior: Crop an image using the GD toolkit.", "context": "Parameters:\n- $image: An image object. The $image->resource, $image->info['width'], and $image->info['height'] values will be modified by this call.\n- $x: The starting x offset at which to start the crop, in pixels.\n- $y: The starting y offset at which to start the crop, in pixels.\n- $width: The width of the cropped area, in pixels.\n- $height: The height of the cropped area, in pixels.\n\nReturns: TRUE or FALSE, based on success.\n\nFile: modules/system/image.gd.inc", "response": "function image_gd_crop(stdClass $image, $x, $y, $width, $height) {\n $width = (int) $width;\n $height = (int) $height;\n $res = image_gd_create_tmp($image, $width, $height);\n\n if (!imagecopyresampled($res, $image->resource, 0, 0, (int) $x, (int) $y, $width, $height, $width, $height)) {\n return FALSE;\n }\n\n // Destroy the original image and return the modified image.\n imagedestroy($image->resource);\n $image->resource = $res;\n $image->info['width'] = $width;\n $image->info['height'] = $height;\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d365012d87", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.pages.inc/function/forum_page/7.x", "instruction": "I need the code for `forum_page($forum_term = NULL)` in Drupal 7 (modules/forum/forum.pages.inc). It must do this: Page callback: Prints a forum listing.", "context": "Parameters:\n- $forum_term: A tree of all forums for a given taxonomy term ID. Defaults to NULL. See the return object of forum_forum_load() for a complete definition.\n\nReturns: A string containing HTML representing the themed forum listing.\n\nFile: modules/forum/forum.pages.inc", "response": "function forum_page($forum_term = NULL) {\n if (!isset($forum_term)) {\n // On the main page, display all the top-level forums.\n $forum_term = forum_forum_load(0);\n }\n\n $forum_per_page = variable_get('forum_per_page', 25);\n $sortby = variable_get('forum_order', 1);\n\n if (empty($forum_term->container)) {\n $topics = forum_get_topics($forum_term->tid, $sortby, $forum_per_page);\n }\n else {\n $topics = '';\n }\n\n return theme('forums', array('forums' => $forum_term->forums, 'topics' => $topics, 'parents' => $forum_term->parents, 'tid' => $forum_term->tid, 'sortby' => $sortby, 'forums_per_page' => $forum_per_page));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d366ac32e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.install/function/block_update_dependencies/7.x", "instruction": "In Drupal 7, write the function `block_update_dependencies()` (file modules/block/block.install) so that it does the following: Implements hook_update_dependencies().", "context": "File: modules/block/block.install", "response": "function block_update_dependencies() {\n // block_update_7005() needs to query the {filter_format} table to get a list\n // of existing text formats, so it must run after filter_update_7000(), which\n // creates that table.\n $dependencies['block'][7005] = array(\n 'filter' => 7000,\n );\n\n return $dependencies;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d36ff5779e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_node_type_delete/7.x", "instruction": "I need the code for `comment_node_type_delete($info)` in Drupal 7 (modules/comment/comment.module). It must do this: Implements hook_node_type_delete().", "context": "File: modules/comment/comment.module", "response": "function comment_node_type_delete($info) {\n field_attach_delete_bundle('comment', 'comment_node_' . $info->type);\n $settings = array(\n 'comment',\n 'comment_default_mode',\n 'comment_default_per_page',\n 'comment_anonymous',\n 'comment_subject_field',\n 'comment_preview',\n 'comment_form_location',\n );\n foreach ($settings as $setting) {\n variable_del($setting . '_' . $info->type);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d39d99fcf3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_view_alter/7.x", "instruction": "Give me the example code for `hook_field_attach_view_alter(&$output, $context)` in Drupal 7. Hook description: Perform alterations on field_attach_view() or field_view_field().", "context": "This hook is invoked after the field module has performed the operation.\n\nParameters:\n- $output: The structured content array tree for all of the entity's fields.\n- $context: An associative array containing: - entity_type: The type of $entity; for example, 'node' or 'user'. - entity: The entity with fields to render. - view_mode: View mode; for example, 'full' or 'teaser'. - display: Either a view mode string or an array of display settings. If this hook is being invoked from field_attach_view(), the 'display' element is set to the view mode string. If this hook is being invoked from field_view_field(), this element is set to the $display argument and the view_mode element is set to '_custom'. See field_view_field() for more information on what its $display argument contains. - language: The language code used for rendering.\n\nFile: modules/field/field.api.php", "response": "function hook_field_attach_view_alter(&$output, $context) {\n // Append RDF term mappings on displayed taxonomy links.\n foreach (element_children($output) as $field_name) {\n $element = &$output[$field_name];\n if ($element['#field_type'] == 'taxonomy_term_reference' && $element['#formatter'] == 'taxonomy_term_reference_link') {\n foreach ($element['#items'] as $delta => $item) {\n $term = $item['taxonomy_term'];\n if (!empty($term->rdf_mapping['rdftype'])) {\n $element[$delta]['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];\n }\n if (!empty($term->rdf_mapping['name']['predicates'])) {\n $element[$delta]['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d3af6b68aa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_remove_from_set/7.x", "instruction": "Implement `translation_remove_from_set($node)` in PHP for Drupal 7. Required behavior: Removes a node from its translation set and updates accordingly.", "context": "Parameters:\n- $node: A node object.\n\nFile: modules/translation/translation.module", "response": "function translation_remove_from_set($node) {\n if (isset($node->tnid) && $node->tnid) {\n $query = db_update('node')\n ->fields(array(\n 'tnid' => 0,\n 'translate' => 0,\n ));\n\n // Determine which nodes to apply the update to.\n $set_nids = db_query('SELECT nid FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchCol();\n if (count($set_nids) == 1) {\n // There is only one node left in the set: remove the set altogether.\n $query\n ->condition('tnid', $node->tnid)\n ->execute();\n\n $flush_set = TRUE;\n }\n else {\n $query\n ->condition('nid', $node->nid)\n ->execute();\n\n // If the node being removed was the source of the translation set,\n // we pick a new source - preferably one that is up to date.\n if ($node->tnid == $node->nid) {\n $new_tnid = db_query('SELECT nid FROM {node} WHERE tnid = :tnid ORDER BY translate ASC, nid ASC', array(':tnid' => $node->tnid))->fetchField();\n db_update('node')\n ->fields(array('tnid' => $new_tnid))\n ->condition('tnid', $node->tnid)\n ->execute();\n\n $flush_set = TRUE;\n }\n }\n\n // Flush the modified nodes from the load cache.\n $nids = !empty($flush_set) ? $set_nids : array($node->nid);\n entity_get_controller('node')->resetCache($nids);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d3b9c6e8fc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_set_title/7.x", "instruction": "Implement `drupal_set_title($title = NULL, $output = CHECK_PLAIN)` in PHP for Drupal 7. Required behavior: Sets the title of the current page.", "context": "The title is displayed on the page and in the title bar.\n\nParameters:\n- $title: Optional string value to assign to the page title; or if set to NULL (default), leaves the current title unchanged.\n- $output: Optional flag - normally should be left as CHECK_PLAIN. Only set to PASS_THROUGH if you have already removed any possibly dangerous code from $title using a function like check_plain() or filter_xss(). With this flag the string will be passed through unchanged.\n\nReturns: The updated title of the current page.\n\nFile: includes/bootstrap.inc", "response": "function drupal_set_title($title = NULL, $output = CHECK_PLAIN) {\n $stored_title = &drupal_static(__FUNCTION__);\n\n if (isset($title)) {\n $stored_title = ($output == PASS_THROUGH) ? $title : check_plain($title);\n }\n\n return $stored_title;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d3cbf1ed6d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_user_timezone/7.x", "instruction": "Implement `system_user_timezone(&$form, &$form_state)` in PHP for Drupal 7. Required behavior: Add the time zone field to the user edit and register forms.", "context": "File: modules/system/system.module", "response": "function system_user_timezone(&$form, &$form_state) {\n global $user;\n\n $account = $form['#user'];\n\n $form['timezone'] = array(\n '#type' => 'fieldset',\n '#title' => t('Locale settings'),\n '#weight' => 6,\n '#collapsible' => TRUE,\n );\n $form['timezone']['timezone'] = array(\n '#type' => 'select',\n '#title' => t('Time zone'),\n '#default_value' => isset($account->timezone) ? $account->timezone : ($account->uid == $user->uid ? variable_get('date_default_timezone', '') : ''),\n '#options' => system_time_zones($account->uid != $user->uid),\n '#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),\n );\n if (!isset($account->timezone) && $account->uid == $user->uid && empty($form_state['input']['timezone'])) {\n $form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect'));\n drupal_add_js('misc/timezone.js');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4021534ba", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_verify_profile/7.x", "instruction": "In Drupal 7, write the function `drupal_verify_profile($install_state)` (file includes/install.inc) so that it does the following: Verifies an installation profile for installation.", "context": "Parameters:\n- $install_state: An array of information about the current installation state.\n\nReturns: The list of modules to install.\n\nFile: includes/install.inc", "response": "function drupal_verify_profile($install_state) {\n $profile = $install_state['parameters']['profile'];\n $locale = $install_state['parameters']['locale'];\n\n include_once DRUPAL_ROOT . '/includes/file.inc';\n include_once DRUPAL_ROOT . '/includes/common.inc';\n\n $profile_file = DRUPAL_ROOT . \"/profiles/$profile/$profile.profile\";\n\n if (!isset($profile) || !file_exists($profile_file)) {\n throw new Exception(install_no_profile_error());\n }\n $info = $install_state['profile_info'];\n\n // Get a list of modules that exist in Drupal's assorted subdirectories.\n $present_modules = array();\n foreach (drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\\.module$/', 'modules', 'name', 0) as $present_module) {\n $present_modules[] = $present_module->name;\n }\n\n // The installation profile is also a module, which needs to be installed\n // after all the other dependencies have been installed.\n $present_modules[] = drupal_get_profile();\n\n // Verify that all of the profile's required modules are present.\n $missing_modules = array_diff($info['dependencies'], $present_modules);\n\n $requirements = array();\n\n if (count($missing_modules)) {\n $modules = array();\n foreach ($missing_modules as $module) {\n $modules[] = '' . drupal_ucfirst($module) . '';\n }\n $requirements['required_modules'] = array(\n 'title' => st('Required modules'),\n 'value' => st('Required modules not found.'),\n 'severity' => REQUIREMENT_ERROR,\n 'description' => st('The following modules are required but were not found. Move them into the appropriate modules subdirectory, such as sites/all/modules. Missing modules: !modules', array('!modules' => implode(', ', $modules))),\n );\n }\n return $requirements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d40ce63bf5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_settings_validate/7.x", "instruction": "I need the code for `book_admin_settings_validate($form, &$form_state)` in Drupal 7 (modules/book/book.admin.inc). It must do this: Form validation handler for book_admin_settings().", "context": "File: modules/book/book.admin.inc", "response": "function book_admin_settings_validate($form, &$form_state) {\n $child_type = $form_state['values']['book_child_type'];\n if (empty($form_state['values']['book_allowed_types'][$child_type])) {\n form_set_error('book_child_type', t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => t('Add child page'))));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d46628c2dc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_watchdog/7.x", "instruction": "Give me the example code for `hook_watchdog(array $log_entry)` in Drupal 7. Hook description: Log an event message.", "context": "This hook allows modules to route log events to custom destinations, such as SMS, Email, pager, syslog, ...etc.\n\nParameters:\n- $log_entry: An associative array containing the following keys: - type: The type of message for this entry. - user: The user object for the user who was logged in when the event happened. - uid: The user ID for the user who was logged in when the event happened. - request_uri: The request URI for the page the event happened in. - referer: The page that referred the user to the page where the event occurred. - ip: The IP address where the request for the page came from. - timestamp: The UNIX timestamp of the date/time the event occurred. - severity: The severity of the message; one of the following values as defined in @link http://www.faqs.org/rfcs/rfc3164.html RFC 3164: @endlink - WATCHDOG_EMERGENCY: Emergency, system is unusable. - WATCHDOG_ALERT: Alert, action must be taken immediately. - WATCHDOG_CRITICAL: Critical conditions. - WATCHDOG_ERROR: Error conditions. - WATCHDOG_WARNING: Warning conditions. - WATCHDOG_NOTICE: Normal but significant conditions. - WATCHDOG_INFO: Informational messages. - WATCHDOG_DEBUG: Debug-level messages. - link: An optional link provided by the module that called the watchdog() function. - message: The text of the message to be logged. Variables in the message are indicated by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how the message and variable parameters interact. - variables: An array of variables to be inserted into the message on display. Will be NULL or missing if a message is already translated or if the message is not possible to translate.\n\nFile: modules/system/system.api.php", "response": "function hook_watchdog(array $log_entry) {\n global $base_url, $language;\n\n $severity_list = array(\n WATCHDOG_EMERGENCY => t('Emergency'),\n WATCHDOG_ALERT => t('Alert'),\n WATCHDOG_CRITICAL => t('Critical'),\n WATCHDOG_ERROR => t('Error'),\n WATCHDOG_WARNING => t('Warning'),\n WATCHDOG_NOTICE => t('Notice'),\n WATCHDOG_INFO => t('Info'),\n WATCHDOG_DEBUG => t('Debug'),\n );\n\n $to = 'someone@example.com';\n $params = array();\n $params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array(\n '@site_name' => variable_get('site_name', 'Drupal'),\n '@severity_desc' => $severity_list[$log_entry['severity']],\n ));\n\n $params['message'] = \"\\nSite: @base_url\";\n $params['message'] .= \"\\nSeverity: (@severity) @severity_desc\";\n $params['message'] .= \"\\nTimestamp: @timestamp\";\n $params['message'] .= \"\\nType: @type\";\n $params['message'] .= \"\\nIP Address: @ip\";\n $params['message'] .= \"\\nRequest URI: @request_uri\";\n $params['message'] .= \"\\nReferrer URI: @referer_uri\";\n $params['message'] .= \"\\nUser: (@uid) @name\";\n $params['message'] .= \"\\nLink: @link\";\n $params['message'] .= \"\\nMessage: \\n\\n@message\";\n\n $params['message'] = t($params['message'], array(\n '@base_url' => $base_url,\n '@severity' => $log_entry['severity'],\n '@severity_desc' => $severity_list[$log_entry['severity']],\n '@timestamp' => format_date($log_entry['timestamp']),\n '@type' => $log_entry['type'],\n '@ip' => $log_entry['ip'],\n '@request_uri' => $log_entry['request_uri'],\n '@referer_uri' => $log_entry['referer'],\n '@uid' => $log_entry['uid'],\n '@name' => $log_entry['user']->name,\n '@link' => strip_tags($log_entry['link']),\n '@message' => strip_tags($log_entry['message']),\n ));\n\n drupal_mail('emaillog', 'entry', $to, $language, $params);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d46d7b64c5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_get_cached_available_releases/7.x", "instruction": "In Drupal 7, write the function `_update_get_cached_available_releases()` (file modules/update/update.module) so that it does the following: Returns all currently cached data about available releases for all projects.", "context": "Returns (Array): of data about available releases, keyed by project shortname.\n\nFile: modules/update/update.module", "response": "function _update_get_cached_available_releases() {\n $data = array();\n $cache_items = _update_get_cache_multiple('available_releases');\n foreach ($cache_items as $cid => $cache) {\n $cache->data['last_fetch'] = $cache->created;\n if ($cache->expire < REQUEST_TIME) {\n $cache->data['fetch_status'] = UPDATE_FETCH_PENDING;\n }\n // The project shortname is embedded in the cache ID, even if there's no\n // data for this project in the DB at all, so use that for the indexes in\n // the array.\n $parts = explode('::', $cid, 2);\n $data[$parts[1]] = $cache->data;\n }\n return $data;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d474e0fc5f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/_update_cron_notify/7.x", "instruction": "Implement `_update_cron_notify()` in PHP for Drupal 7. Required behavior: Performs any notifications that should be done once cron fetches new data.", "context": "This method checks the status of the site using the new data and, depending on the configuration of the site, notifies administrators via e-mail if there are new releases or missing security updates.\n\nFile: modules/update/update.fetch.inc", "response": "function _update_cron_notify() {\n module_load_install('update');\n $status = update_requirements('runtime');\n $params = array();\n $notify_all = (variable_get('update_notification_threshold', 'all') == 'all');\n foreach (array('core', 'contrib') as $report_type) {\n $type = 'update_' . $report_type;\n if (isset($status[$type]['severity'])\n && ($status[$type]['severity'] == REQUIREMENT_ERROR || ($notify_all && $status[$type]['reason'] == UPDATE_NOT_CURRENT))) {\n $params[$report_type] = $status[$type]['reason'];\n }\n }\n if (!empty($params)) {\n $notify_list = variable_get('update_notify_emails', '');\n if (!empty($notify_list)) {\n $default_language = language_default();\n foreach ($notify_list as $target) {\n if ($target_user = user_load_by_mail($target)) {\n $target_language = user_preferred_language($target_user);\n }\n else {\n $target_language = $default_language;\n }\n $message = drupal_mail('update', 'status_notify', $target, $target_language, $params);\n // Track when the last mail was successfully sent to avoid sending\n // too many e-mails.\n if ($message['result']) {\n variable_set('update_last_email_notification', REQUEST_TIME);\n }\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d47546d77b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_forms/7.x", "instruction": "I need the code for `search_forms()` in Drupal 7 (modules/search/search.module). It must do this: Implements hook_forms().", "context": "File: modules/search/search.module", "response": "function search_forms() {\n $forms['search_block_form']= array(\n 'callback' => 'search_box',\n 'callback arguments' => array('search_block_form'),\n );\n return $forms;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4838d3da7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_stream_wrappers/7.x", "instruction": "Give me the example code for `hook_stream_wrappers()` in Drupal 7. Hook description: Registers PHP stream wrapper implementations associated with a module.", "context": "Provide a facility for managing and querying user-defined stream wrappers in PHP. PHP's internal stream_get_wrappers() doesn't return the class registered to handle a stream, which we need to be able to find the handler for class instantiation.\n\nIf a module registers a scheme that is already registered with PHP, it will be unregistered and replaced with the specified class.\n\nReturns: A nested array, keyed first by scheme name (\"public\" for \"public://\"), then keyed by the following values: - 'name' A short string to name the wrapper. - 'class' A string specifying the PHP class that implements the DrupalStreamWrapperInterface interface. - 'description' A string with a short description of what the wrapper does. - 'type' (Optional) A bitmask of flags indicating what type of streams this wrapper will access - local or remote, readable and/or writeable, etc. Many shortcut constants are defined in stream_wrappers.inc. Defaults to STREAM_WRAPPERS_NORMAL which includes all of these bit flags: - STREAM_WRAPPERS_READ - STREAM_WRAPPERS_WRITE - STREAM_WRAPPERS_VISIBLE\n\nFile: modules/system/system.api.php", "response": "function hook_stream_wrappers() {\n return array(\n 'public' => array(\n 'name' => t('Public files'),\n 'class' => 'DrupalPublicStreamWrapper',\n 'description' => t('Public local files served by the webserver.'),\n 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,\n ),\n 'private' => array(\n 'name' => t('Private files'),\n 'class' => 'DrupalPrivateStreamWrapper',\n 'description' => t('Private local files served by Drupal.'),\n 'type' => STREAM_WRAPPERS_LOCAL_NORMAL,\n ),\n 'temp' => array(\n 'name' => t('Temporary files'),\n 'class' => 'DrupalTempStreamWrapper',\n 'description' => t('Temporary local files for upload and previews.'),\n 'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,\n ),\n 'cdn' => array(\n 'name' => t('Content delivery network files'),\n 'class' => 'MyModuleCDNStreamWrapper',\n 'description' => t('Files served by a content delivery network.'),\n // 'type' can be omitted to use the default of STREAM_WRAPPERS_NORMAL\n ),\n 'youtube' => array(\n 'name' => t('YouTube video'),\n 'class' => 'MyModuleYouTubeStreamWrapper',\n 'description' => t('Video streamed from YouTube.'),\n // A module implementing YouTube integration may decide to support using\n // the YouTube API for uploading video, but here, we assume that this\n // particular module only supports playing YouTube video.\n 'type' => STREAM_WRAPPERS_READ_VISIBLE,\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d48dee8972", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_active_help/7.x", "instruction": "In Drupal 7, write the function `menu_get_active_help()` (file includes/menu.inc) so that it does the following: Returns the help associated with the active menu item.", "context": "File: includes/menu.inc", "response": "function menu_get_active_help() {\n $output = '';\n $router_path = menu_tab_root_path();\n // We will always have a path unless we are on a 403 or 404.\n if (!$router_path) {\n return '';\n }\n\n $arg = drupal_help_arg(arg(NULL));\n\n foreach (module_implements('help') as $module) {\n $function = $module . '_help';\n // Lookup help for this path.\n if ($help = $function($router_path, $arg)) {\n $output .= $help . \"\\n\";\n }\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4afeadba4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7008/7.x", "instruction": "In Drupal 7, write the function `taxonomy_update_7008()` (file modules/taxonomy/taxonomy.install) so that it does the following: Change the weight columns to normal int.", "context": "File: modules/taxonomy/taxonomy.install", "response": "function taxonomy_update_7008() {\n db_drop_index('taxonomy_term_data', 'taxonomy_tree');\n db_change_field('taxonomy_term_data', 'weight', 'weight', array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The weight of this term in relation to other terms.',\n ), array(\n 'indexes' => array(\n 'taxonomy_tree' => array('vid', 'weight', 'name'),\n ),\n ));\n\n db_drop_index('taxonomy_vocabulary', 'list');\n db_change_field('taxonomy_vocabulary', 'weight', 'weight', array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The weight of this vocabulary in relation to other vocabularies.',\n ), array(\n 'indexes' => array(\n 'list' => array('weight', 'name'),\n ),\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4b719dc66", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_menu/7.x", "instruction": "I need the code for `statistics_menu()` in Drupal 7 (modules/statistics/statistics.module). It must do this: Implements hook_menu().", "context": "File: modules/statistics/statistics.module", "response": "function statistics_menu() {\n $items['admin/reports/hits'] = array(\n 'title' => 'Recent hits',\n 'description' => 'View pages that have recently been visited.',\n 'page callback' => 'statistics_recent_hits',\n 'access arguments' => array('access statistics'),\n 'file' => 'statistics.admin.inc',\n );\n $items['admin/reports/pages'] = array(\n 'title' => 'Top pages',\n 'description' => 'View pages that have been hit frequently.',\n 'page callback' => 'statistics_top_pages',\n 'access arguments' => array('access statistics'),\n 'weight' => 1,\n 'file' => 'statistics.admin.inc',\n );\n $items['admin/reports/visitors'] = array(\n 'title' => 'Top visitors',\n 'description' => 'View visitors that hit many pages.',\n 'page callback' => 'statistics_top_visitors',\n 'access arguments' => array('access statistics'),\n 'weight' => 2,\n 'file' => 'statistics.admin.inc',\n );\n $items['admin/reports/referrers'] = array(\n 'title' => 'Top referrers',\n 'description' => 'View top referrers.',\n 'page callback' => 'statistics_top_referrers',\n 'access arguments' => array('access statistics'),\n 'file' => 'statistics.admin.inc',\n );\n $items['admin/reports/access/%'] = array(\n 'title' => 'Details',\n 'description' => 'View access log.',\n 'page callback' => 'statistics_access_log',\n 'page arguments' => array(3),\n 'access arguments' => array('access statistics'),\n 'file' => 'statistics.admin.inc',\n );\n $items['admin/config/system/statistics'] = array(\n 'title' => 'Statistics',\n 'description' => 'Control details about what and how your site logs access statistics.',\n 'page callback' => 'drupal_get_form',\n 'page arguments' => array('statistics_settings_form'),\n 'access arguments' => array('administer statistics'),\n 'file' => 'statistics.admin.inc',\n 'weight' => -15,\n );\n $items['user/%user/track/navigation'] = array(\n 'title' => 'Track page visits',\n 'page callback' => 'statistics_user_tracker',\n 'access callback' => 'user_access',\n 'access arguments' => array('access statistics'),\n 'type' => MENU_LOCAL_TASK,\n 'weight' => 2,\n 'file' => 'statistics.pages.inc',\n );\n $items['node/%node/track'] = array(\n 'title' => 'Track',\n 'page callback' => 'statistics_node_tracker',\n 'access callback' => 'user_access',\n 'access arguments' => array('access statistics'),\n 'type' => MENU_LOCAL_TASK,\n 'weight' => 2,\n 'file' => 'statistics.pages.inc',\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4bd4ad4cf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.install/function/contact_uninstall/7.x", "instruction": "Implement `contact_uninstall()` in PHP for Drupal 7. Required behavior: Implements hook_uninstall().", "context": "File: modules/contact/contact.install", "response": "function contact_uninstall() {\n variable_del('contact_default_status');\n variable_del('contact_threshold_limit');\n variable_del('contact_threshold_window');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4c2df055b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.tokens.inc/function/poll_token_info/7.x", "instruction": "I need the code for `poll_token_info()` in Drupal 7 (modules/poll/poll.tokens.inc). It must do this: Implements hook_token_info().", "context": "File: modules/poll/poll.tokens.inc", "response": "function poll_token_info() {\n $node['poll-votes'] = array(\n 'name' => t(\"Poll votes\"),\n 'description' => t(\"The number of votes that have been cast on a poll.\"),\n );\n $node['poll-winner'] = array(\n 'name' => t(\"Poll winner\"),\n 'description' => t(\"The winning poll answer.\"),\n );\n $node['poll-winner-votes'] = array(\n 'name' => t(\"Poll winner votes\"),\n 'description' => t(\"The number of votes received by the winning poll answer.\"),\n );\n $node['poll-winner-percent'] = array(\n 'name' => t(\"Poll winner percent\"),\n 'description' => t(\"The percentage of votes received by the winning poll answer.\"),\n );\n $node['poll-duration'] = array(\n 'name' => t(\"Poll duration\"),\n 'description' => t(\"The length of time the poll is set to run.\"),\n );\n\n return array(\n 'tokens' => array('node' => $node),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4c36e6b38", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_get_info/7.x", "instruction": "Implement `image_gd_get_info(stdClass $image)` in PHP for Drupal 7. Required behavior: Get details about an image.", "context": "Parameters:\n- $image: An image object.\n\nReturns: FALSE, if the file could not be found or is not an image. Otherwise, a keyed array containing information about the image: - \"width\": Width, in pixels. - \"height\": Height, in pixels. - \"extension\": Commonly used file extension for the image. - \"mime_type\": MIME type ('image/jpeg', 'image/gif', 'image/png').\n\nFile: modules/system/image.gd.inc", "response": "function image_gd_get_info(stdClass $image) {\n $details = FALSE;\n $data = @getimagesize($image->source);\n\n if (isset($data) && is_array($data)) {\n $extensions = array('1' => 'gif', '2' => 'jpg', '3' => 'png');\n $extension = isset($extensions[$data[2]]) ? $extensions[$data[2]] : '';\n $details = array(\n 'width' => $data[0],\n 'height' => $data[1],\n 'extension' => $extension,\n 'mime_type' => $data['mime'],\n );\n }\n\n return $details;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4c8df7ed6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_allowed_values_string/7.x", "instruction": "I need the code for `list_allowed_values_string($values)` in Drupal 7 (modules/field/modules/list/list.module). It must do this: Generates a string representation of an array of 'allowed values'.", "context": "This string format is suitable for edition in a textarea.\n\nParameters:\n- $values: An array of values, where array keys are values and array values are labels.\n\nReturns: The string representation of the $values array: - Values are separated by a carriage return. - Each value is in the format \"value|label\" or \"value\".\n\nFile: modules/field/modules/list/list.module", "response": "function list_allowed_values_string($values) {\n $lines = array();\n foreach ($values as $key => $value) {\n $lines[] = \"$key|$value\";\n }\n return implode(\"\\n\", $lines);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4d27873f0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.install/function/text_update_7000/7.x", "instruction": "Implement `text_update_7000()` in PHP for Drupal 7. Required behavior: Change text field 'format' columns into varchar.", "context": "File: modules/field/modules/text/text.install", "response": "function text_update_7000() {\n $spec = array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n );\n $fields = _update_7000_field_read_fields(array(\n 'module' => 'text',\n 'storage_type' => 'field_sql_storage',\n ));\n foreach ($fields as $field) {\n if ($field['deleted']) {\n $table = \"field_deleted_data_{$field['id']}\";\n $revision_table = \"field_deleted_revision_{$field['id']}\";\n }\n else {\n $table = \"field_data_{$field['field_name']}\";\n $revision_table = \"field_revision_{$field['field_name']}\";\n }\n $column = $field['field_name'] . '_' . 'format';\n db_change_field($table, $column, $column, $spec);\n db_change_field($revision_table, $column, $column, $spec);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4d77c0d00", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/path_to_theme/7.x", "instruction": "I need the code for `path_to_theme()` in Drupal 7 (includes/theme.inc). It must do this: Returns the path to the current themed element.", "context": "It can point to the active theme or the module handling a themed implementation. For example, when invoked within the scope of a theming call it will depend on where the theming function is handled. If implemented from a module, it will point to the module. If implemented from the active theme, it will point to the active theme. When called outside the scope of a theming call, it will always point to the active theme.\n\nFile: includes/theme.inc", "response": "function path_to_theme() {\n global $theme_path;\n\n if (!isset($theme_path)) {\n drupal_theme_initialize();\n }\n\n return $theme_path;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d4e61be6d0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_assign_owner_action_validate/7.x", "instruction": "I need the code for `node_assign_owner_action_validate($form, $form_state)` in Drupal 7 (modules/node/node.module). It must do this: Validates settings form for node_assign_owner_action().", "context": "File: modules/node/node.module", "response": "function node_assign_owner_action_validate($form, $form_state) {\n $exists = (bool) db_query_range('SELECT 1 FROM {users} WHERE name = :name', 0, 1, array(':name' => $form_state['values']['owner_name']))->fetchField();\n if (!$exists) {\n form_set_error('owner_name', t('Enter a valid username.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d53ae170a3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_dashboard_regions/7.x", "instruction": "In Drupal 7, write the function `dashboard_dashboard_regions()` (file modules/dashboard/dashboard.module) so that it does the following: Implements hook_dashboard_regions().", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_dashboard_regions() {\n return array(\n 'dashboard_main' => 'Dashboard (main)',\n 'dashboard_sidebar' => 'Dashboard (sidebar)',\n 'dashboard_inactive' => 'Dashboard (inactive)',\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d546f6fc9f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_settings_form/7.x", "instruction": "In Drupal 7, write the function `number_field_settings_form($field, $instance, $has_data)` (file modules/field/modules/number/number.module) so that it does the following: Implements hook_field_settings_form().", "context": "File: modules/field/modules/number/number.module", "response": "function number_field_settings_form($field, $instance, $has_data) {\n $settings = $field['settings'];\n $form = array();\n\n if ($field['type'] == 'number_decimal') {\n $form['precision'] = array(\n '#type' => 'select',\n '#title' => t('Precision'),\n '#options' => drupal_map_assoc(range(10, 32)),\n '#default_value' => $settings['precision'],\n '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'),\n '#disabled' => $has_data,\n );\n $form['scale'] = array(\n '#type' => 'select',\n '#title' => t('Scale'),\n '#options' => drupal_map_assoc(range(0, 10)),\n '#default_value' => $settings['scale'],\n '#description' => t('The number of digits to the right of the decimal.'),\n '#disabled' => $has_data,\n );\n }\n if ($field['type'] == 'number_decimal' || $field['type'] == 'number_float') {\n $form['decimal_separator'] = array(\n '#type' => 'select',\n '#title' => t('Decimal marker'),\n '#options' => array('.' => t('Decimal point'), ',' => t('Comma')),\n '#default_value' => $settings['decimal_separator'],\n '#description' => t('The character users will input to mark the decimal point in forms.'),\n );\n }\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d559558e0f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_parse_dependency/7.x", "instruction": "I need the code for `drupal_parse_dependency($dependency)` in Drupal 7 (includes/common.inc). It must do this: Parses a dependency for comparison by drupal_check_incompatibility().", "context": "Parameters:\n- $dependency: A dependency string, which specifies a module dependency, and optionally the project it comes from and versions that are supported. Supported formats include: - 'module' - 'project:module' - 'project:module (>=version, version)'\n\nReturns: An associative array with three keys: - 'name' includes the name of the thing to depend on (e.g. 'foo'). - 'original_version' contains the original version string (which can be used in the UI for reporting incompatibilities). - 'versions' is a list of associative arrays, each containing the keys 'op' and 'version'. 'op' can be one of: '=', '==', '!=', '<>', '<', '<=', '>', or '>='. 'version' is one piece like '4.5-beta3'. Callers should pass this structure to drupal_check_incompatibility().\n\nFile: includes/common.inc", "response": "function drupal_parse_dependency($dependency) {\n $value = array();\n // Split out the optional project name.\n if (strpos($dependency, ':')) {\n list($project_name, $dependency) = explode(':', $dependency);\n $value['project'] = $project_name;\n }\n // We use named subpatterns and support every op that version_compare\n // supports. Also, op is optional and defaults to equals.\n $p_op = '(?P!=|==|=|<|<=|>|>=|<>)?';\n // Core version is always optional: 7.x-2.x and 2.x is treated the same.\n $p_core = '(?:' . preg_quote(DRUPAL_CORE_COMPATIBILITY) . '-)?';\n $p_major = '(?P\\d+)';\n // By setting the minor version to x, branches can be matched.\n $p_minor = '(?P(?:\\d+|x)(?:-[A-Za-z]+\\d+)?)';\n $parts = explode('(', $dependency, 2);\n $value['name'] = trim($parts[0]);\n if (isset($parts[1])) {\n $value['original_version'] = ' (' . $parts[1];\n foreach (explode(',', $parts[1]) as $version) {\n if (preg_match(\"/^\\s*$p_op\\s*$p_core$p_major\\.$p_minor/\", $version, $matches)) {\n $op = !empty($matches['operation']) ? $matches['operation'] : '=';\n if ($matches['minor'] == 'x') {\n // Drupal considers \"2.x\" to mean any version that begins with\n // \"2\" (e.g. 2.0, 2.9 are all \"2.x\"). PHP's version_compare(),\n // on the other hand, treats \"x\" as a string; so to\n // version_compare(), \"2.x\" is considered less than 2.0. This\n // means that >=2.x and <2.x are handled by version_compare()\n // as we need, but > and <= are not.\n if ($op == '>' || $op == '<=') {\n $matches['major']++;\n }\n // Equivalence can be checked by adding two restrictions.\n if ($op == '=' || $op == '==') {\n $value['versions'][] = array('op' => '<', 'version' => ($matches['major'] + 1) . '.x');\n $op = '>=';\n }\n }\n $value['versions'][] = array('op' => $op, 'version' => $matches['major'] . '.' . $matches['minor']);\n }\n }\n }\n return $value;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d59829c098", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/_statistics_format_item/7.x", "instruction": "In Drupal 7, write the function `_statistics_format_item($title, $path)` (file modules/statistics/statistics.module) so that it does the following: Formats an item for display, including both the item title and the link.", "context": "Parameters:\n- $title: The text to link to a path; will be truncated to a maximum width of 35.\n- $path: The path to link to; will default to '/'.\n\nReturns: An HTML string with $title linked to the $path.\n\nFile: modules/statistics/statistics.module", "response": "function _statistics_format_item($title, $path) {\n $path = ($path ? $path : '/');\n $output = ($title ? \"$title
              \" : '');\n $output .= _statistics_link($path);\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d5b70124dd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_settings_form/7.x", "instruction": "In Drupal 7, write the function `install_settings_form($form, &$form_state, &$install_state)` (file includes/install.core.inc) so that it does the following: Form constructor for a form to configure and rewrite settings.php.", "context": "Parameters:\n- $install_state: An array of information about the current installation state.\n\nFile: includes/install.core.inc", "response": "function install_settings_form($form, &$form_state, &$install_state) {\n global $databases;\n $profile = $install_state['parameters']['profile'];\n $install_locale = $install_state['parameters']['locale'];\n\n drupal_static_reset('conf_path');\n $conf_path = './' . conf_path(FALSE);\n $settings_file = $conf_path . '/settings.php';\n $database = isset($databases['default']['default']) ? $databases['default']['default'] : array();\n\n drupal_set_title(st('Database configuration'));\n\n $drivers = drupal_get_database_types();\n $drivers_keys = array_keys($drivers);\n\n $form['driver'] = array(\n '#type' => 'radios',\n '#title' => st('Database type'),\n '#required' => TRUE,\n '#default_value' => !empty($database['driver']) ? $database['driver'] : current($drivers_keys),\n '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_distribution_name())),\n );\n if (count($drivers) == 1) {\n $form['driver']['#disabled'] = TRUE;\n $form['driver']['#description'] .= ' ' . st('Your PHP configuration only supports a single database type, so it has been automatically selected.');\n }\n\n // Add driver specific configuration options.\n foreach ($drivers as $key => $driver) {\n $form['driver']['#options'][$key] = $driver->name();\n\n $form['settings'][$key] = $driver->getFormOptions($database);\n $form['settings'][$key]['#prefix'] = '

              ' . st('@driver_name settings', array('@driver_name' => $driver->name())) . '

              ';\n $form['settings'][$key]['#type'] = 'container';\n $form['settings'][$key]['#tree'] = TRUE;\n $form['settings'][$key]['advanced_options']['#parents'] = array($key);\n $form['settings'][$key]['#states'] = array(\n 'visible' => array(\n ':input[name=driver]' => array('value' => $key),\n )\n );\n }\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['save'] = array(\n '#type' => 'submit',\n '#value' => st('Save and continue'),\n '#limit_validation_errors' => array(\n array('driver'),\n array(isset($form_state['input']['driver']) ? $form_state['input']['driver'] : current($drivers_keys)),\n ),\n '#submit' => array('install_settings_form_submit'),\n );\n\n $form['errors'] = array();\n $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file);\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d5cb682108", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.install/function/statistics_update_7000/7.x", "instruction": "I need the code for `statistics_update_7000()` in Drupal 7 (modules/statistics/statistics.install). It must do this: Update the {accesslog}.sid column to match the length of {sessions}.sid", "context": "File: modules/statistics/statistics.install", "response": "function statistics_update_7000() {\n db_change_field('accesslog', 'sid', 'sid', array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Browser session ID of user that visited page.',\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d5d2ba2f4f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7.x", "instruction": "I need the code for `theme_table(array $variables)` in Drupal 7 (includes/theme.inc). It must do this: Returns HTML for a table.", "context": "Parameters:\n- $variables (array): An associative array containing: - header: An array containing the table headers. Each element of the array can be either a localized string or an associative array with the following keys: - \"data\": The localized title of the table column. - \"field\": The database field represented in the table column (required if user is to be able to sort on this column). - \"sort\": A default sort order for this column (\"asc\" or \"desc\"). Only one column should be given a default sort order because table sorting only applies to one column at a time. - Any HTML attributes, such as \"colspan\", to apply to the column header cell. - rows: An array of table rows. Every row is an array of cells, or an associative array with the following keys: - \"data\": an array of cells - Any HTML attributes, such as \"class\", to apply to the table row. - \"no_striping\": a boolean indicating that the row should receive no 'even / odd' styling. Defaults to FALSE. Each cell can be either a string or an associative array with the following keys: - \"data\": The string to display in the table cell. - \"header\": Indicates this cell is a header. - Any HTML attributes, such as \"colspan\", to apply to the table cell. Here's an example for $rows: @code $rows = array( // Simple row array( 'Cell 1', 'Cell 2', 'Cell 3' ), // Row with attributes on the row and some of its cells. array( 'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => array('funky') ) ); @endcode - footer: An array of table rows which will be printed within a tag, in the same format as the rows element (see above). The structure is the same the one defined for the \"rows\" key except that the no_striping boolean has no effect, there is no rows striping for the table footer. - attributes: An array of HTML attributes to apply to the table tag. - caption: A localized string to use for the tag. - colgroups: An array of column groups. Each element of the array can be either: - An array of columns, each of which is an associative array of HTML attributes applied to the COL element. - An array of attributes applied to the COLGROUP element, which must include a \"data\" attribute. To add attributes to COL elements, set the \"data\" attribute with an array of columns, each of which is an associative array of HTML attributes. Here's an example for $colgroup: @code $colgroup = array( // COLGROUP with one COL element. array( array( 'class' => array('funky'), // Attribute for the COL element. ), ), // Colgroup with attributes and inner COL elements. array( 'data' => array( array( 'class' => array('funky'), // Attribute for the COL element. ), ), 'class' => array('jazzy'), // Attribute for the COLGROUP element. ), ); @endcode These optional tags are used to group and set properties on columns within a table. For example, one may easily group three columns and apply same background style to all. - sticky: Use a \"sticky\" table header. - empty: The message to display in an extra row if table does not have any rows.\n\nReturns (string): The HTML output.\n\nFile: includes/theme.inc", "response": "function theme_table(array $variables) {\n $header = $variables['header'];\n $rows = $variables['rows'];\n $attributes = $variables['attributes'];\n $caption = $variables['caption'];\n $colgroups = $variables['colgroups'];\n $sticky = $variables['sticky'];\n $empty = $variables['empty'];\n\n // Add sticky headers, if applicable.\n if (!empty($header) && $sticky) {\n drupal_add_js('misc/tableheader.js');\n // Add 'sticky-enabled' class to the table to identify it for JS.\n // This is needed to target tables constructed by this function.\n $attributes['class'][] = 'sticky-enabled';\n }\n\n $output = '\\n\";\n\n if (isset($caption)) {\n $output .= '' . $caption . \"\\n\";\n }\n\n // Format the table columns:\n if (!empty($colgroups)) {\n foreach ($colgroups as $number => $colgroup) {\n $attributes = array();\n\n // Check if we're dealing with a simple or complex column\n if (isset($colgroup['data'])) {\n foreach ($colgroup as $key => $value) {\n if ($key == 'data') {\n $cols = $value;\n }\n else {\n $attributes[$key] = $value;\n }\n }\n }\n else {\n $cols = $colgroup;\n }\n\n // Build colgroup\n if (is_array($cols) && count($cols)) {\n $output .= ' ';\n $i = 0;\n foreach ($cols as $col) {\n $output .= ' ';\n }\n $output .= \" \\n\";\n }\n else {\n $output .= ' \\n\";\n }\n }\n }\n\n // Add the 'empty' row message if available.\n if (empty($rows) && $empty) {\n $header_count = 0;\n if (!empty($header)) {\n foreach ($header as $header_cell) {\n if (is_array($header_cell)) {\n $header_count += isset($header_cell['colspan']) ?\n $header_cell['colspan'] : 1;\n }\n else {\n $header_count++;\n }\n }\n }\n $rows[] = array(\n array(\n 'data' => $empty,\n 'colspan' => $header_count,\n 'class' => array(\n 'empty',\n 'message'\n ),\n ),\n );\n }\n\n // Format the table header.\n if (!empty($header)) {\n $ts = tablesort_init($header);\n // HTML requires that the thead tag has tr tags in it followed by tbody\n // tags. Using ternary operator to check and see if we have any rows.\n $output .= (!empty($rows) ? ' ' : ' ');\n foreach ($header as $cell) {\n $cell = tablesort_header($cell, $header, $ts);\n $output .= _theme_table_cell($cell, TRUE);\n }\n // Using ternary operator to close the tags based on whether\n // or not there are rows.\n $output .= (!empty($rows) ? \" \\n\" : \"\\n\");\n }\n else {\n $ts = array();\n }\n\n // Format the table and footer rows.\n $sections = array();\n\n if (!empty($rows)) {\n $sections['tbody'] = $rows;\n }\n\n if (!empty($variables['footer'])) {\n $sections['tfoot'] = $variables['footer'];\n }\n\n // tbody and tfoot have the same structure and are built using the same\n // procedure.\n foreach ($sections as $tag => $content) {\n $output .= \"<\" . $tag . \">\\n\";\n $flip = array('even' => 'odd', 'odd' => 'even');\n $class = 'even';\n $default_no_striping = ($tag === 'tfoot');\n\n foreach ($content as $number => $row) {\n // Check if we're dealing with a simple or complex row.\n if (isset($row['data'])) {\n $cells = $row['data'];\n $no_striping = isset($row['no_striping']) ?\n $row['no_striping'] : $default_no_striping;\n\n // Set the attributes array and exclude 'data' and 'no_striping'.\n $attributes = $row;\n unset($attributes['data']);\n unset($attributes['no_striping']);\n }\n else {\n $cells = $row;\n $attributes = array();\n $no_striping = $default_no_striping;\n }\n\n if (!empty($cells)) {\n // Add odd/even class.\n if (!$no_striping) {\n $class = $flip[$class];\n $attributes['class'][] = $class;\n }\n\n // Build row.\n $output .= ' ';\n $i = 0;\n foreach ($cells as $cell) {\n $cell = tablesort_cell($cell, $header, $ts, $i++);\n $output .= _theme_table_cell($cell);\n }\n $output .= \" \\n\";\n }\n }\n\n $output .= \"\\n\";\n }\n\n $output .= \"\\n\";\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d5d35b717c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_top/7.x", "instruction": "Implement `dblog_top($type)` in PHP for Drupal 7. Required behavior: Page callback: Shows the most frequent log messages of a given event type.", "context": "Messages are not truncated on this page because events detailed herein do not have links to a detailed view.\n\nParameters:\n- $type (string): Type of database log events to display (e.g., 'search').\n\nReturns (array): A build array in the format expected by drupal_render().\n\nFile: modules/dblog/dblog.admin.inc", "response": "function dblog_top($type) {\n\n $header = array(\n array('data' => t('Count'), 'field' => 'count', 'sort' => 'desc'),\n array('data' => t('Message'), 'field' => 'message')\n );\n $count_query = db_select('watchdog');\n $count_query->addExpression('COUNT(DISTINCT(message))');\n $count_query->condition('type', $type);\n\n $query = db_select('watchdog', 'w')->extend('PagerDefault')->extend('TableSort');\n $query->addExpression('COUNT(wid)', 'count');\n $query = $query\n ->fields('w', array('message', 'variables'))\n ->condition('w.type', $type)\n ->groupBy('message')\n ->groupBy('variables')\n ->limit(30)\n ->orderByHeader($header);\n $query->setCountQuery($count_query);\n $result = $query->execute();\n\n $rows = array();\n foreach ($result as $dblog) {\n $rows[] = array($dblog->count, theme('dblog_message', array('event' => $dblog)));\n }\n\n $build['dblog_top_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#empty' => t('No log messages available.'),\n );\n $build['dblog_top_pager'] = array('#theme' => 'pager');\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d5fc126d85", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_button/7.x", "instruction": "In Drupal 7, write the function `form_process_button($element, &$form_state)` (file includes/form.inc) so that it does the following: Processes a form button element.", "context": "Parameters:\n- $element: An associative array containing the properties and children of the form button.\n- $form_state: The $form_state array for the form this element belongs to.\n\nReturns: The processed element.\n\nFile: includes/form.inc", "response": "function form_process_button($element, &$form_state) {\n // We normally want to add drupal.form-single-submit so that the double submit\n // protection can be added to the site, however, with the addition of\n // javascript_always_use_jquery, this would make most pages with a login\n // block or a search form have jquery always added, changing what people who\n // set the javascript_always_use_jquery variable to FALSE would have expected.\n if (variable_get('javascript_always_use_jquery', TRUE) && variable_get('javascript_use_double_submit_protection', TRUE)) {\n $element['#attached']['library'][] = array('system', 'drupal.form-single-submit');\n }\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d601eb35cf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_append/7.x", "instruction": "Implement `ajax_command_append($selector, $html, $settings = NULL)` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'insert/append' command.", "context": "The 'insert/append' command instructs the client to use jQuery's append() method to append the given HTML content to the inside of each element matched by the given selector.\n\nThis command is implemented by Drupal.ajax.prototype.commands.insert() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n- $html: The data to use with the jQuery append() method.\n- $settings: An optional array of settings that will be used for this command only.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_append($selector, $html, $settings = NULL) {\n return array(\n 'command' => 'insert',\n 'method' => 'append',\n 'selector' => $selector,\n 'data' => $html,\n 'settings' => $settings,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d60401a2dd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_login_destination/7.x", "instruction": "I need the code for `user_login_destination()` in Drupal 7 (modules/user/user.module). It must do this: Helper function to rewrite the destination to avoid redirecting to login page after login.", "context": "Third-party authentication modules may use this function to determine the proper destination after a user has been properly logged in.\n\nFile: modules/user/user.module", "response": "function user_login_destination() {\n $destination = drupal_get_destination();\n if ($destination['destination'] == 'user/login') {\n $destination['destination'] = 'user';\n }\n return $destination;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d63ac82ec4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render_cache_get/7.x", "instruction": "Implement `drupal_render_cache_get($elements)` in PHP for Drupal 7. Required behavior: Gets the rendered output of a renderable element from the cache.", "context": "Parameters:\n- $elements: A renderable array.\n\nReturns: A markup string containing the rendered content of the element, or FALSE if no cached copy of the element is available.\n\nFile: includes/common.inc", "response": "function drupal_render_cache_get($elements) {\n if (!in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD')) || !$cid = drupal_render_cid_create($elements)) {\n return FALSE;\n }\n $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';\n\n if (!empty($cid) && $cache = cache_get($cid, $bin)) {\n // Add additional libraries, JavaScript, CSS and other data attached\n // to this element.\n if (isset($cache->data['#attached'])) {\n drupal_process_attached($cache->data);\n }\n // Return the rendered output.\n return $cache->data['#markup'];\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d64ac018e4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_block_configure/7.x", "instruction": "Implement `profile_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().", "context": "File: modules/profile/profile.module", "response": "function profile_block_configure($delta = '') {\n // Compile a list of fields to show\n $fields = array();\n $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));\n foreach ($result as $record) {\n $fields[$record->name] = check_plain($record->title);\n }\n $fields['user_profile'] = t('Link to full user profile');\n $form['profile_block_author_fields'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Profile fields to display'),\n '#default_value' => variable_get('profile_block_author_fields', array()),\n '#options' => $fields,\n '#description' => t('Select which profile fields you wish to display in the block. Only fields designated as public in the profile field configuration are available.', array('@profile-admin' => url('admin/config/people/profile'))),\n );\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d65679d2e4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/theme_poll_choices/7.x", "instruction": "I need the code for `theme_poll_choices($variables)` in Drupal 7 (modules/poll/poll.module). It must do this: Returns HTML for an admin poll form for choices.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/poll/poll.module", "response": "function theme_poll_choices($variables) {\n $form = $variables['form'];\n\n drupal_add_tabledrag('poll-choice-table', 'order', 'sibling', 'poll-weight');\n\n $is_admin= user_access('administer nodes');\n $delta = 0;\n $rows = array();\n $headers = array('', t('Choice'));\n if ($is_admin) {\n $headers[] = t('Vote count');\n }\n $headers[] = t('Weight');\n\n foreach (element_children($form) as $key) {\n $delta++;\n // Set special classes for drag and drop updating.\n $form[$key]['weight']['#attributes']['class'] = array('poll-weight');\n\n // Build the table row.\n $row = array(\n 'data' => array(\n array('class' => array('choice-flag')),\n drupal_render($form[$key]['chtext']),\n ),\n 'class' => array('draggable'),\n );\n if ($is_admin) {\n $row['data'][] = drupal_render($form[$key]['chvotes']);\n }\n $row['data'][] = drupal_render($form[$key]['weight']);\n\n // Add any additional classes set on the row.\n if (!empty($form[$key]['#attributes']['class'])) {\n $row['class'] = array_merge($row['class'], $form[$key]['#attributes']['class']);\n }\n\n $rows[] = $row;\n }\n\n $output = theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => 'poll-choice-table')));\n $output .= drupal_render_children($form);\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d688bbd73a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_widget_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_widget_info_alter(&$info)` (modules/field/field.api.php): Perform alterations on Field API widget types.", "context": "Parameters:\n- $info: Array of informations on widget types exposed by hook_field_widget_info() implementations.\n\nFile: modules/field/field.api.php", "response": "function hook_field_widget_info_alter(&$info) {\n // Add a setting to a widget type.\n $info['text_textfield']['settings'] += array(\n 'mymodule_additional_setting' => 'default value',\n );\n\n // Let a new field type re-use an existing widget.\n $info['options_select']['field types'][] = 'my_field_type';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d68d8b51bb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7080/7.x", "instruction": "I need the code for `system_update_7080()` in Drupal 7 (modules/system/system.install). It must do this: Convert the 'format' column in {date_format_locale} to case sensitive varchar.", "context": "File: modules/system/system.install", "response": "function system_update_7080() {\n $spec = array(\n 'description' => 'The date format string.',\n 'type' => 'varchar',\n 'length' => 100,\n 'not null' => TRUE,\n 'binary' => TRUE,\n );\n db_change_field('date_format_locale', 'format', 'format', $spec);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d6aa14aba9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.install/function/contact_update_7002/7.x", "instruction": "In Drupal 7, write the function `contact_update_7002()` (file modules/contact/contact.install) so that it does the following: Enable the 'access user contact forms' for registered users by default.", "context": "File: modules/contact/contact.install", "response": "function contact_update_7002() {\n // Do not use user_role_grant_permission() since it relies on\n // hook_permission(), which will not run for contact module if it is\n // disabled.\n db_merge('role_permission')\n ->key(array(\n 'rid' => DRUPAL_AUTHENTICATED_RID,\n 'permission' => 'access user contact forms',\n 'module' => 'contact',\n ))\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d6c3d086a0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21syslog%21syslog.module/function/syslog_facility_list/7.x", "instruction": "I need the code for `syslog_facility_list()` in Drupal 7 (modules/syslog/syslog.module). It must do this: Lists all possible syslog facilities for UNIX/Linux.", "context": "Returns (array): An array of syslog facilities for UNIX/Linux.\n\nFile: modules/syslog/syslog.module", "response": "function syslog_facility_list() {\n return array(\n LOG_LOCAL0 => 'LOG_LOCAL0',\n LOG_LOCAL1 => 'LOG_LOCAL1',\n LOG_LOCAL2 => 'LOG_LOCAL2',\n LOG_LOCAL3 => 'LOG_LOCAL3',\n LOG_LOCAL4 => 'LOG_LOCAL4',\n LOG_LOCAL5 => 'LOG_LOCAL5',\n LOG_LOCAL6 => 'LOG_LOCAL6',\n LOG_LOCAL7 => 'LOG_LOCAL7',\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d6cd99d283", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_valid_uri/7.x", "instruction": "In Drupal 7, write the function `file_valid_uri($uri)` (file includes/file.inc) so that it does the following: Determines whether the URI has a valid scheme for file API operations.", "context": "There must be a scheme and it must be a Drupal-provided scheme like 'public', 'private', 'temporary', or an extension provided with hook_stream_wrappers().\n\nParameters:\n- $uri: The URI to be tested.\n\nReturns: TRUE if the URI is allowed.\n\nFile: includes/file.inc", "response": "function file_valid_uri($uri) {\n // Assert that the URI has an allowed scheme. Barepaths are not allowed.\n $uri_scheme = file_uri_scheme($uri);\n if (empty($uri_scheme) || !file_stream_wrapper_valid_scheme($uri_scheme)) {\n return FALSE;\n }\n return TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d6e3ab20ca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_load/7.x", "instruction": "I need the code for `image_style_load($name = NULL, $isid = NULL, $include = NULL)` in Drupal 7 (modules/image/image.module). It must do this: Loads a style by style name or ID.", "context": "May be used as a loader for menu items.\n\nParameters:\n- $name: The name of the style.\n- $isid: Optional. The numeric id of a style if the name is not known.\n- $include: If set, this loader will restrict to a specific type of image style, may be one of the defined Image style storage constants.\n\nReturns: An image style array containing the following keys: - \"isid\": The unique image style ID. - \"name\": The unique image style name. - \"effects\": An array of image effects within this image style. If the image style name or ID is not valid, an empty array is returned.\n\nFile: modules/image/image.module", "response": "function image_style_load($name = NULL, $isid = NULL, $include = NULL) {\n $styles = image_styles();\n\n // If retrieving by name.\n if (isset($name) && isset($styles[$name])) {\n $style = $styles[$name];\n }\n\n // If retrieving by image style id.\n if (!isset($name) && isset($isid)) {\n foreach ($styles as $name => $database_style) {\n if (isset($database_style['isid']) && $database_style['isid'] == $isid) {\n $style = $database_style;\n break;\n }\n }\n }\n\n // Restrict to the specific type of flag. This bitwise operation basically\n // states \"if the storage is X, then allow\".\n if (isset($style) && (!isset($include) || ($style['storage'] & (int) $include))) {\n return $style;\n }\n\n // Otherwise the style was not found.\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d70eb23f71", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_page_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_page_alter(&$page)` (modules/system/system.api.php): Perform alterations before a page is rendered.", "context": "Use this hook when you want to remove or alter elements at the page level, or add elements at the page level that depend on an other module's elements (this hook runs after hook_page_build().\n\nIf you are making changes to entities such as forms, menus, or user profiles, use those objects' native alter hooks instead (hook_form_alter(), for example).\n\nThe $page array contains top level elements for each block region:\n\nParameters:\n- $page: Nested array of renderable elements that make up the page.\n\nFile: modules/system/system.api.php", "response": "function hook_page_alter(&$page) {\n // Add help text to the user login block.\n $page['sidebar_first']['user_login']['help'] = array(\n '#weight' => -10,\n '#markup' => t('To post comments or add new content, you first have to log in.'),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d737c78a4a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_system_info_alter/7.x", "instruction": "I need the code for `field_system_info_alter(&$info, $file, $type)` in Drupal 7 (modules/field/field.module). It must do this: Implements hook_system_info_alter().", "context": "Goes through a list of all modules that provide a field type, and makes them required if there are any active fields of that type.\n\nFile: modules/field/field.module", "response": "function field_system_info_alter(&$info, $file, $type) {\n if ($type == 'module' && module_hook($file->name, 'field_info')) {\n $fields = field_read_fields(array('module' => $file->name), array('include_deleted' => TRUE));\n if ($fields) {\n $info['required'] = TRUE;\n\n // Provide an explanation message (only mention pending deletions if there\n // remains no actual, non-deleted fields)\n $non_deleted = FALSE;\n foreach ($fields as $field) {\n if (empty($field['deleted'])) {\n $non_deleted = TRUE;\n break;\n }\n }\n if ($non_deleted) {\n if (module_exists('field_ui')) {\n $explanation = t('Field type(s) in use - see Field list', array('@fields-page' => url('admin/reports/fields')));\n }\n else {\n $explanation = t('Fields type(s) in use');\n }\n }\n else {\n $explanation = t('Fields pending deletion');\n }\n $info['explanation'] = $explanation;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d746e4113a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_block_view_alter/7.x", "instruction": "Implement `menu_block_view_alter(&$data, $block)` in PHP for Drupal 7. Required behavior: Implements hook_block_view_alter().", "context": "File: modules/menu/menu.module", "response": "function menu_block_view_alter(&$data, $block) {\n // Add contextual links for system menu blocks.\n if ($block->module == 'system' && !empty($data['content'])) {\n $system_menus = menu_list_system_menus();\n if (isset($system_menus[$block->delta])) {\n $data['content']['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($block->delta));\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d75be624b7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_autocomplete/7.x", "instruction": "I need the code for `user_autocomplete($string = '')` in Drupal 7 (modules/user/user.pages.inc). It must do this: Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing users.", "context": "File: modules/user/user.pages.inc", "response": "function user_autocomplete($string = '') {\n $matches = array();\n if ($string) {\n $result = db_select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute();\n foreach ($result as $user) {\n $matches[$user->name] = check_plain($user->name);\n }\n }\n\n drupal_json_output($matches);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d7763818ca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21bartik%21template.php/function/bartik_process_html/7.x", "instruction": "I need the code for `bartik_process_html(&$variables)` in Drupal 7 (themes/bartik/template.php). It must do this: Override or insert variables into the page template for HTML output.", "context": "File: themes/bartik/template.php", "response": "function bartik_process_html(&$variables) {\n // Hook into color.module.\n if (module_exists('color')) {\n _color_html_alter($variables);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d777e93fae", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21pager.inc/function/theme_pager_next/7.x", "instruction": "I need the code for `theme_pager_next($variables)` in Drupal 7 (includes/pager.inc). It must do this: Returns HTML for the \"next page\" link in a query pager.", "context": "Parameters:\n- $variables: An associative array containing: - text: The name (or image) of the link. - element: An optional integer to distinguish between multiple pagers on one page. - interval: The number of pages to move forward when the link is clicked. - parameters: An associative array of query string parameters to append to the pager links.\n\nFile: includes/pager.inc", "response": "function theme_pager_next($variables) {\n $text = $variables['text'];\n $element = $variables['element'];\n $interval = $variables['interval'];\n $parameters = $variables['parameters'];\n global $pager_page_array, $pager_total;\n $output = '';\n\n // Nothing to do if there is no pager.\n if (!isset($pager_page_array[$element]) || !isset($pager_total[$element])) {\n return;\n }\n\n // If we are anywhere but the last page\n if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {\n $page_new = pager_load_array($pager_page_array[$element] + $interval, $element, $pager_page_array);\n // If the next page is the last page, mark the link as such.\n if ($page_new[$element] == ($pager_total[$element] - 1)) {\n $output = theme('pager_last', array('text' => $text, 'element' => $element, 'parameters' => $parameters));\n }\n // The next page is not the last page.\n else {\n $output = theme('pager_link', array('text' => $text, 'page_new' => $page_new, 'element' => $element, 'parameters' => $parameters));\n }\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d7a04e4377", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_is_empty/7.x", "instruction": "Implement `text_field_is_empty($item, $field)` in PHP for Drupal 7. Required behavior: Implements hook_field_is_empty().", "context": "File: modules/field/modules/text/text.module", "response": "function text_field_is_empty($item, $field) {\n if (!isset($item['value']) || $item['value'] === '') {\n return !isset($item['summary']) || $item['summary'] === '';\n }\n return FALSE;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d7a8b172a0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_array_merge_deep/7.x", "instruction": "Implement `drupal_array_merge_deep()` in PHP for Drupal 7. Required behavior: Merges multiple arrays, recursively, and returns the merged array.", "context": "This function is similar to PHP's array_merge_recursive() function, but it handles non-array values differently. When merging values that are not both arrays, the latter value replaces the former rather than merging with it.\n\nExample:\n\nReturns: The merged array.\n\nFile: includes/bootstrap.inc", "response": "function drupal_array_merge_deep() {\n $args = func_get_args();\n return drupal_array_merge_deep_array($args);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d7b416186f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_view/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_user_view($account, $view_mode, $langcode)` (modules/user/user.api.php): The user's account information is being displayed.", "context": "The module should format its custom additions for display and add them to the $account->content array.\n\nParameters:\n- $account: The user object on which the operation is being performed.\n- $view_mode: View mode, e.g. 'full'.\n- $langcode: The language code used for rendering.\n\nFile: modules/user/user.api.php", "response": "function hook_user_view($account, $view_mode, $langcode) {\n if (user_access('create blog content', $account)) {\n $account->content['summary']['blog'] = array(\n '#type' => 'user_profile_item',\n '#title' => t('Blog'),\n '#markup' => l(t('View recent blog entries'), \"blog/$account->uid\", array('attributes' => array('title' => t(\"Read !username's latest blog entries.\", array('!username' => format_username($account)))))),\n '#attributes' => array('class' => array('blog')),\n );\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d7dc764ed2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_load_stylesheet_content/7.x", "instruction": "I need the code for `drupal_load_stylesheet_content($contents, $optimize = FALSE)` in Drupal 7 (includes/common.inc). It must do this: Processes the contents of a stylesheet for aggregation.", "context": "Parameters:\n- $contents: The contents of the stylesheet.\n- $optimize: (optional) Boolean whether CSS contents should be minified. Defaults to FALSE.\n\nReturns: Contents of the stylesheet including the imported stylesheets.\n\nFile: includes/common.inc", "response": "function drupal_load_stylesheet_content($contents, $optimize = FALSE) {\n // Remove multiple charset declarations for standards compliance (and fixing Safari problems).\n $contents = preg_replace('/^@charset\\s+[\\'\"](\\S*?)\\b[\\'\"];/i', '', $contents);\n\n if ($optimize) {\n // Perform some safe CSS optimizations.\n // Regexp to match comment blocks.\n $comment = '/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/';\n // Regexp to match double quoted strings.\n $double_quot = '\"[^\"\\\\\\\\]*(?:\\\\\\\\.[^\"\\\\\\\\]*)*\"';\n // Regexp to match single quoted strings.\n $single_quot = \"'[^'\\\\\\\\]*(?:\\\\\\\\.[^'\\\\\\\\]*)*'\";\n // Strip all comment blocks, but keep double/single quoted strings.\n $contents = preg_replace(\n \"<($double_quot|$single_quot)|$comment>Ss\",\n \"$1\",\n $contents\n );\n // Remove certain whitespace.\n // There are different conditions for removing leading and trailing\n // whitespace.\n // @see http://php.net/manual/regexp.reference.subpatterns.php\n $contents = preg_replace('<\n # Do not strip any space from within single or double quotes\n (' . $double_quot . '|' . $single_quot . ')\n # Strip leading and trailing whitespace.\n | \\s*([@{};,])\\s*\n # Strip only leading whitespace from:\n # - Closing parenthesis: Retain \"@media (bar) and foo\".\n | \\s+([\\)])\n # Strip only trailing whitespace from:\n # - Opening parenthesis: Retain \"@media (bar) and foo\".\n # - Colon: Retain :pseudo-selectors.\n | ([\\(:])\\s+\n >xSs',\n // Only one of the four capturing groups will match, so its reference\n // will contain the wanted value and the references for the\n // two non-matching groups will be replaced with empty strings.\n '$1$2$3$4',\n $contents\n );\n // End the file with a new line.\n $contents = trim($contents);\n $contents .= \"\\n\";\n }\n\n // Replaces @import commands with the actual stylesheet content.\n // This happens recursively but omits external files.\n $contents = preg_replace_callback('/@import\\s*(?:url\\(\\s*)?[\\'\"]?(?![a-z]+:)(?!\\/\\/)([^\\'\"\\()]+)[\\'\"]?\\s*\\)?\\s*;/', '_drupal_load_stylesheet', $contents);\n return $contents;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d7dee10c4e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate_size/7.x", "instruction": "In Drupal 7, write the function `file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0)` (file includes/file.inc) so that it does the following: Checks that the file's size is below certain limits.", "context": "Parameters:\n- $file: A Drupal file object.\n- $file_limit: An integer specifying the maximum file size in bytes. Zero indicates that no limit should be enforced.\n- $user_limit: An integer specifying the maximum number of bytes the user is allowed. Zero indicates that no limit should be enforced.\n\nReturns: An array. If the file size exceeds limits, it will contain an error message.\n\nFile: includes/file.inc", "response": "function file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0) {\n global $user;\n $errors = array();\n\n if ($file_limit && $file->filesize > $file_limit) {\n $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));\n }\n\n // Save a query by only calling file_space_used() when a limit is provided.\n if ($user_limit && (file_space_used($user->uid) + $file->filesize) > $user_limit) {\n $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));\n }\n\n return $errors;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d7f28fa101", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_rdf_mapping/7.x", "instruction": "I need the code for `taxonomy_rdf_mapping()` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_rdf_mapping().", "context": "Returns (array): The rdf mapping for vocabularies and terms.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_rdf_mapping() {\n return array(\n array(\n 'type' => 'taxonomy_term',\n 'bundle' => RDF_DEFAULT_BUNDLE,\n 'mapping' => array(\n 'rdftype' => array('skos:Concept'),\n 'name' => array(\n 'predicates' => array('rdfs:label', 'skos:prefLabel'),\n ),\n 'description' => array(\n 'predicates' => array('skos:definition'),\n ),\n 'vid' => array(\n 'predicates' => array('skos:inScheme'),\n 'type' => 'rel',\n ),\n 'parent' => array(\n 'predicates' => array('skos:broader'),\n 'type' => 'rel',\n ),\n ),\n ),\n array(\n 'type' => 'taxonomy_vocabulary',\n 'bundle' => RDF_DEFAULT_BUNDLE,\n 'mapping' => array(\n 'rdftype' => array('skos:ConceptScheme'),\n 'name' => array(\n 'predicates' => array('dc:title'),\n ),\n 'description' => array(\n 'predicates' => array('rdfs:comment'),\n ),\n ),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d802eb2ccf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_effects/7.x", "instruction": "Implement `image_effects()` in PHP for Drupal 7. Required behavior: Loads all image effects from the database.", "context": "Returns: An array of all image effects.\n\nFile: modules/image/image.module", "response": "function image_effects() {\n $effects = &drupal_static(__FUNCTION__);\n\n if (!isset($effects)) {\n $effects = array();\n\n // Add database image effects.\n $result = db_select('image_effects', NULL, array('fetch' => PDO::FETCH_ASSOC))\n ->fields('image_effects')\n ->orderBy('image_effects.weight', 'ASC')\n ->execute();\n foreach ($result as $effect) {\n $effect['data'] = unserialize($effect['data']);\n $definition = image_effect_definition_load($effect['name']);\n // Do not load image effects whose definition cannot be found.\n if ($definition) {\n $effect = array_merge($definition, $effect);\n $effects[$effect['ieid']] = $effect;\n }\n }\n }\n\n return $effects;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d80e51bc3b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21help%21help.module/function/help_menu/7.x", "instruction": "In Drupal 7, write the function `help_menu()` (file modules/help/help.module) so that it does the following: Implements hook_menu().", "context": "File: modules/help/help.module", "response": "function help_menu() {\n $items['admin/help'] = array(\n 'title' => 'Help',\n 'description' => 'Reference for usage, configuration, and modules.',\n 'page callback' => 'help_main',\n 'access arguments' => array('access administration pages'),\n 'weight' => 9,\n 'file' => 'help.admin.inc',\n );\n\n foreach (module_implements('help', TRUE) as $module) {\n $items['admin/help/' . $module] = array(\n 'title' => $module,\n 'page callback' => 'help_page',\n 'page arguments' => array(2),\n 'access arguments' => array('access administration pages'),\n 'type' => MENU_VISIBLE_IN_BREADCRUMB,\n 'file' => 'help.admin.inc',\n );\n }\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d8110ffa9c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/template_preprocess_user_profile/7.x", "instruction": "I need the code for `template_preprocess_user_profile(&$variables)` in Drupal 7 (modules/user/user.pages.inc). It must do this: Process variables for user-profile.tpl.php.", "context": "Parameters:\n- $variables (array): An associative array containing: - elements: An associative array containing the user information and any fields attached to the user. Properties used: - #account: The user account of the profile being viewed.\n\nFile: modules/user/user.pages.inc", "response": "function template_preprocess_user_profile(&$variables) {\n $account = $variables['elements']['#account'];\n\n // Helpful $user_profile variable for templates.\n foreach (element_children($variables['elements']) as $key) {\n $variables['user_profile'][$key] = $variables['elements'][$key];\n }\n\n // Preprocess fields.\n field_attach_preprocess('user', $account, $variables['elements'], $variables);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d8579a55b5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_preprocess/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_preprocess(&$variables, $hook)` (modules/system/theme.api.php): Preprocess theme variables for templates.", "context": "This hook allows modules to preprocess theme variables for theme templates. It is called for all theme hooks implemented as templates, but not for theme hooks implemented as functions. hook_preprocess_HOOK() can be used to preprocess variables for a specific theme hook, whether implemented as a template or function.\n\nFor more detailed information, see theme().\n\nParameters:\n- $variables: The variables array (modify in place).\n- $hook: The name of the theme hook.\n\nFile: modules/system/theme.api.php", "response": "function hook_preprocess(&$variables, $hook) {\n static $hooks;\n\n // Add contextual links to the variables, if the user has permission.\n\n if (!user_access('access contextual links')) {\n return;\n }\n\n if (!isset($hooks)) {\n $hooks = theme_get_registry();\n }\n\n // Determine the primary theme function argument.\n if (isset($hooks[$hook]['variables'])) {\n $keys = array_keys($hooks[$hook]['variables']);\n $key = $keys[0];\n }\n else {\n $key = $hooks[$hook]['render element'];\n }\n\n if (isset($variables[$key])) {\n $element = $variables[$key];\n }\n\n if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {\n $variables['title_suffix']['contextual_links'] = contextual_links_view($element);\n if (!empty($variables['title_suffix']['contextual_links'])) {\n $variables['classes_array'][] = 'contextual-links-region';\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d858523b1e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/install_goto/7.x", "instruction": "In Drupal 7, write the function `install_goto($path)` (file includes/install.inc) so that it does the following: Sends the user to a different installer page.", "context": "This issues an on-site HTTP redirect. Messages (and errors) are erased.\n\nParameters:\n- $path: An installer path.\n\nFile: includes/install.inc", "response": "function install_goto($path) {\n global $base_url;\n include_once DRUPAL_ROOT . '/includes/common.inc';\n header('Location: ' . $base_url . '/' . $path);\n header('Cache-Control: no-cache'); // Not a permanent redirect.\n drupal_exit();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d866d71d58", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_delete/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_delete($node)` (modules/node/node.api.php): Respond to node deletion.", "context": "This is a node-type-specific hook, which is invoked only for the node type being affected. See\n\nParameters:\n- $node: The node that is being deleted.\n\nFile: modules/node/node.api.php", "response": "function hook_delete($node) {\n db_delete('mytable')\n ->condition('nid', $node->nid)\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-d89822adca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.tokens.inc/function/taxonomy_tokens/7.x", "instruction": "Implement `taxonomy_tokens($type, $tokens, array $data = array(), array $options = array())` in PHP for Drupal 7. Required behavior: Implements hook_tokens().", "context": "File: modules/taxonomy/taxonomy.tokens.inc", "response": "function taxonomy_tokens($type, $tokens, array $data = array(), array $options = array()) {\n $replacements = array();\n $sanitize = !empty($options['sanitize']);\n\n if ($type == 'term' && !empty($data['term'])) {\n $term = $data['term'];\n\n foreach ($tokens as $name => $original) {\n switch ($name) {\n case 'tid':\n $replacements[$original] = $term->tid;\n break;\n\n case 'name':\n $replacements[$original] = $sanitize ? check_plain($term->name) : $term->name;\n break;\n\n case 'description':\n $replacements[$original] = $sanitize ? check_markup($term->description, $term->format, '', TRUE) : $term->description;\n break;\n\n case 'url':\n $uri = entity_uri('taxonomy_term', $term);\n $replacements[$original] = url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE)));\n break;\n\n case 'node-count':\n $query = db_select('taxonomy_index');\n $query->condition('tid', $term->tid);\n $query->addTag('term_node_count');\n $count = $query->countQuery()->execute()->fetchField();\n $replacements[$original] = $count;\n break;\n\n case 'vocabulary':\n $vocabulary = taxonomy_vocabulary_load($term->vid);\n $replacements[$original] = check_plain($vocabulary->name);\n break;\n\n case 'parent':\n if ($parents = taxonomy_get_parents($term->tid)) {\n $parent = array_pop($parents);\n $replacements[$original] = check_plain($parent->name);\n }\n break;\n }\n }\n\n if ($vocabulary_tokens = token_find_with_prefix($tokens, 'vocabulary')) {\n $vocabulary = taxonomy_vocabulary_load($term->vid);\n $replacements += token_generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options);\n }\n\n if (($vocabulary_tokens = token_find_with_prefix($tokens, 'parent')) && $parents = taxonomy_get_parents($term->tid)) {\n $parent = array_pop($parents);\n $replacements += token_generate('term', $vocabulary_tokens, array('term' => $parent), $options);\n }\n }\n\n elseif ($type == 'vocabulary' && !empty($data['vocabulary'])) {\n $vocabulary = $data['vocabulary'];\n\n foreach ($tokens as $name => $original) {\n switch ($name) {\n case 'vid':\n $replacements[$original] = $vocabulary->vid;\n break;\n\n case 'name':\n $replacements[$original] = $sanitize ? check_plain($vocabulary->name) : $vocabulary->name;\n break;\n\n case 'description':\n $replacements[$original] = $sanitize ? filter_xss($vocabulary->description) : $vocabulary->description;\n break;\n\n case 'term-count':\n $query = db_select('taxonomy_term_data');\n $query->condition('vid', $vocabulary->vid);\n $query->addTag('vocabulary_term_count');\n $count = $query->countQuery()->execute()->fetchField();\n $replacements[$original] = $count;\n break;\n\n case 'node-count':\n $query = db_select('taxonomy_index', 'ti');\n $query->addExpression('COUNT(DISTINCT ti.nid)');\n $query->leftJoin('taxonomy_term_data', 'td', 'ti.tid = td.tid');\n $query->condition('td.vid', $vocabulary->vid);\n $query->addTag('vocabulary_node_count');\n $count = $query->execute()->fetchField();\n $replacements[$original] = $count;\n break;\n }\n }\n }\n\n return $replacements;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d8c323096c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_comment_load/7.x", "instruction": "Implement `rdf_comment_load($comments)` in PHP for Drupal 7. Required behavior: Implements hook_comment_load().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_comment_load($comments) {\n foreach ($comments as $comment) {\n // Pages with many comments can show poor performance. This information\n // isn't needed until rdf_preprocess_comment() is called, but set it here\n // to optimize performance for websites that implement an entity cache.\n $comment->rdf_data['date'] = rdf_rdfa_attributes($comment->rdf_mapping['created'], $comment->created);\n $comment->rdf_data['nid_uri'] = url('node/' . $comment->nid);\n if ($comment->pid) {\n $comment->rdf_data['pid_uri'] = url('comment/' . $comment->pid, array('fragment' => 'comment-' . $comment->pid));\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d8e81dbee4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_batch_system_finished/7.x", "instruction": "In Drupal 7, write the function `_locale_batch_system_finished($success, $results)` (file includes/locale.inc) so that it does the following: Implements callback_batch_finished().", "context": "Finished callback of system page locale import batch. Inform the user of translation files imported.\n\nFile: includes/locale.inc", "response": "function _locale_batch_system_finished($success, $results) {\n if ($success) {\n drupal_set_message(format_plural(count($results), 'One translation file imported for the newly installed modules.', '@count translation files imported for the newly installed modules.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d8f0723b4b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_date_time_lookup/7.x", "instruction": "I need the code for `system_date_time_lookup()` in Drupal 7 (modules/system/system.admin.inc). It must do this: Return the date for a given format string via Ajax.", "context": "File: modules/system/system.admin.inc", "response": "function system_date_time_lookup() {\n // This callback is protected with a CSRF token because user input from the\n // query string is reflected in the output.\n if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'admin/config/regional/date-time/formats/lookup')) {\n return MENU_ACCESS_DENIED;\n }\n $result = format_date(REQUEST_TIME, 'custom', $_GET['format']);\n drupal_json_output($result);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d9073fe488", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_field_by_ids/7.x", "instruction": "In Drupal 7, write the function `field_info_field_by_ids()` (file modules/field/field.info.inc) so that it does the following: Returns the same data as field_info_field_by_id() for every field.", "context": "Use of this function should be avoided when possible, since it loads and statically caches a potentially large array of information.\n\nWhen iterating over the fields present in a given bundle after a call to field_info_instances($entity_type, $bundle), it is recommended to use field_info_field() on each individual field instead.\n\nReturns: An array, each key is a field ID and the values are field arrays as returned by field_read_fields(), with an additional element 'bundles', whose value is an array of all the bundle this field belongs to.\n\nFile: modules/field/field.info.inc", "response": "function field_info_field_by_ids() {\n $cache = _field_info_field_cache();\n return $cache->getFields();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d93a177cbe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_edit_form_submit/7.x", "instruction": "Implement `shortcut_set_edit_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Submit handler for shortcut_set_edit_form().", "context": "File: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_set_edit_form_submit($form, &$form_state) {\n $shortcut_set = $form_state['values']['shortcut_set'];\n $shortcut_set->title = $form_state['values']['title'];\n shortcut_set_save($shortcut_set);\n drupal_set_message(t('Updated set name to %set-name.', array('%set-name' => $shortcut_set->title)));\n $form_state['redirect'] = \"admin/config/user-interface/shortcut/$shortcut_set->set_name\";\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d955961330", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_form_override_submit/7.x", "instruction": "I need the code for `image_style_form_override_submit($form, &$form_state)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Submit handler for overriding a module-defined style.", "context": "File: modules/image/image.admin.inc", "response": "function image_style_form_override_submit($form, &$form_state) {\n drupal_set_message(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $form_state['image_style']['label'])));\n image_default_style_save($form_state['image_style']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d9809811fa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_textfield/7.x", "instruction": "Implement `theme_textfield($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a textfield form element.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #title, #value, #description, #size, #maxlength, #required, #attributes, #autocomplete_path.\n\nFile: includes/form.inc", "response": "function theme_textfield($variables) {\n $element = $variables['element'];\n $element['#attributes']['type'] = 'text';\n element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength'));\n _form_set_class($element, array('form-text'));\n\n $extra = '';\n if ($element['#autocomplete_path'] && !empty($element['#autocomplete_input'])) {\n drupal_add_library('system', 'drupal.autocomplete');\n $element['#attributes']['class'][] = 'form-autocomplete';\n\n $attributes = array();\n $attributes['type'] = 'hidden';\n $attributes['id'] = $element['#autocomplete_input']['#id'];\n $attributes['value'] = $element['#autocomplete_input']['#url_value'];\n $attributes['disabled'] = 'disabled';\n $attributes['class'][] = 'autocomplete';\n $extra = '';\n }\n\n $output = '';\n\n return $output . $extra;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d98e7b48ca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_theme/7.x", "instruction": "I need the code for `forum_theme()` in Drupal 7 (modules/forum/forum.module). It must do this: Implements hook_theme().", "context": "File: modules/forum/forum.module", "response": "function forum_theme() {\n return array(\n 'forums' => array(\n 'template' => 'forums',\n 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),\n ),\n 'forum_list' => array(\n 'template' => 'forum-list',\n 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),\n ),\n 'forum_topic_list' => array(\n 'template' => 'forum-topic-list',\n 'variables' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),\n ),\n 'forum_icon' => array(\n 'template' => 'forum-icon',\n 'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0, 'first_new' => FALSE),\n ),\n 'forum_submitted' => array(\n 'template' => 'forum-submitted',\n 'variables' => array('topic' => NULL),\n ),\n 'forum_form' => array(\n 'render element' => 'form',\n 'file' => 'forum.admin.inc',\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d9b050d397", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.install/function/block_update_7005/7.x", "instruction": "I need the code for `block_update_7005()` in Drupal 7 (modules/block/block.install). It must do this: Update the {block_custom}.format column.", "context": "File: modules/block/block.install", "response": "function block_update_7005() {\n // For an explanation of these updates, see the code comments in\n // user_update_7010().\n db_change_field('block_custom', 'format', 'format', array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => FALSE,\n 'description' => 'The {filter_format}.format of the block body.',\n ));\n db_update('block_custom')\n ->fields(array('format' => NULL))\n ->condition('body', '')\n ->condition('format', 0)\n ->execute();\n $existing_formats = db_query(\"SELECT format FROM {filter_format}\")->fetchCol();\n $default_format = variable_get('filter_default_format', 1);\n db_update('block_custom')\n ->fields(array('format' => $default_format))\n ->isNotNull('format')\n ->condition('format', $existing_formats, 'NOT IN')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-d9d311248f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/dblog_menu/7.x", "instruction": "In Drupal 7, write the function `dblog_menu()` (file modules/dblog/dblog.module) so that it does the following: Implements hook_menu().", "context": "File: modules/dblog/dblog.module", "response": "function dblog_menu() {\n $items['admin/reports/dblog'] = array(\n 'title' => 'Recent log messages',\n 'description' => 'View events that have recently been logged.',\n 'page callback' => 'dblog_overview',\n 'access arguments' => array('access site reports'),\n 'weight' => -1,\n 'file' => 'dblog.admin.inc',\n );\n $items['admin/reports/page-not-found'] = array(\n 'title' => \"Top 'page not found' errors\",\n 'description' => \"View 'page not found' errors (404s).\",\n 'page callback' => 'dblog_top',\n 'page arguments' => array('page not found'),\n 'access arguments' => array('access site reports'),\n 'file' => 'dblog.admin.inc',\n );\n $items['admin/reports/access-denied'] = array(\n 'title' => \"Top 'access denied' errors\",\n 'description' => \"View 'access denied' errors (403s).\",\n 'page callback' => 'dblog_top',\n 'page arguments' => array('access denied'),\n 'access arguments' => array('access site reports'),\n 'file' => 'dblog.admin.inc',\n );\n $items['admin/reports/event/%'] = array(\n 'title' => 'Details',\n 'page callback' => 'dblog_event',\n 'page arguments' => array(3),\n 'access arguments' => array('access site reports'),\n 'file' => 'dblog.admin.inc',\n );\n\n if (module_exists('search')) {\n $items['admin/reports/search'] = array(\n 'title' => 'Top search phrases',\n 'description' => 'View most popular search phrases.',\n 'page callback' => 'dblog_top',\n 'page arguments' => array('search'),\n 'access arguments' => array('access site reports'),\n 'file' => 'dblog.admin.inc',\n );\n }\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-d9f40991c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/_field_info_prepare_instance_widget/7.x", "instruction": "Implement `_field_info_prepare_instance_widget($field, $widget)` in PHP for Drupal 7. Required behavior: Prepares widget specifications for the current run-time context.", "context": "The functionality has moved to the FieldInfo class. This function is kept as a backwards-compatibility layer. See http://drupal.org/node/1915646.\n\nFile: modules/field/field.info.inc", "response": "function _field_info_prepare_instance_widget($field, $widget) {\n $cache = _field_info_field_cache();\n return $cache->prepareInstanceWidget($widget, $field['type']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-da00519d27", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_url_trim/7.x", "instruction": "Implement `_filter_url_trim($text, $length = NULL)` in PHP for Drupal 7. Required behavior: Shortens long URLs to http://www.example.com/long/url...", "context": "File: modules/filter/filter.module", "response": "function _filter_url_trim($text, $length = NULL) {\n static $_length;\n if ($length !== NULL) {\n $_length = $length;\n }\n\n // Use +3 for '...' string length.\n if ($_length && strlen((string) $text) > $_length + 3) {\n $text = substr($text, 0, $_length) . '...';\n }\n\n return $text;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-da7eef0f74", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_upload_max_size/7.x", "instruction": "Implement `file_upload_max_size()` in PHP for Drupal 7. Required behavior: Determines the maximum file upload size by querying the PHP settings.", "context": "Returns: A file size limit in bytes based on the PHP upload_max_filesize and post_max_size\n\nFile: includes/file.inc", "response": "function file_upload_max_size() {\n static $max_size = -1;\n\n if ($max_size < 0) {\n // Start with post_max_size.\n $max_size = parse_size(ini_get('post_max_size'));\n\n // If upload_max_size is less, then reduce. Except if upload_max_size is\n // zero, which indicates no limit.\n $upload_max = parse_size(ini_get('upload_max_filesize'));\n if ($upload_max > 0 && $upload_max < $max_size) {\n $max_size = $upload_max;\n }\n }\n return $max_size;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-da86f4545a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_help/7.x", "instruction": "In Drupal 7, write the function `options_help($path, $arg)` (file modules/field/modules/options/options.module) so that it does the following: Implements hook_help().", "context": "File: modules/field/modules/options/options.module", "response": "function options_help($path, $arg) {\n switch ($path) {\n case 'admin/help#options':\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The Options module defines checkbox, selection, and other input widgets for the Field module. See the Field module help page for more information about fields.', array('@field-help' => url('admin/help/field'))) . '

              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-da9e97c5ac", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_dirty/7.x", "instruction": "In Drupal 7, write the function `search_dirty($word = NULL)` (file modules/search/search.module) so that it does the following: Marks a word as \"dirty\" (changed), or retrieves the list of dirty words.", "context": "This is used during indexing (cron). Words that are dirty have outdated total counts in the search_total table, and need to be recounted.\n\nFile: modules/search/search.module", "response": "function search_dirty($word = NULL) {\n $dirty = &drupal_static(__FUNCTION__, array());\n if ($word !== NULL) {\n $dirty[$word] = TRUE;\n }\n else {\n return $dirty;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-daa0a73970", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_help/7.x", "instruction": "In Drupal 7, write the function `announcements_feed_help($path)` (file modules/announcements_feed/announcements_feed.module) so that it does the following: Implements hook_help().", "context": "File: modules/announcements_feed/announcements_feed.module", "response": "function announcements_feed_help($path) {\n if ($path == 'admin/help#announcements_feed') {\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The Announcements module displays announcements from the Drupal community. For more information, see the online documentation for the Announcements module.', array('@documentation' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/announcements-feed')) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ' . t('Accessing announcements') . '
              ';\n $output .= '
              ' . t('Users with the \"View drupal.org announcements\" permission may click on the \"Announcements\" item in the administration menu, or access Announcements, to see all announcements relevant to the Drupal version of your site.', array('@link' => url('admin/announcements_feed'))) . '
              ';\n $output .= '
              ';\n\n return $output;\n }\n\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dab03d5d8e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_bootstrap_variables/7.x", "instruction": "In Drupal 7, write the function `_drupal_bootstrap_variables()` (file includes/bootstrap.inc) so that it does the following: Loads system variables and all enabled bootstrap modules.", "context": "File: includes/bootstrap.inc", "response": "function _drupal_bootstrap_variables() {\n global $conf;\n\n // Initialize the lock system.\n require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc');\n lock_initialize();\n\n // Load variables from the database, but do not overwrite variables set in settings.php.\n $conf = variable_initialize(isset($conf) ? $conf : array());\n // Load bootstrap modules.\n require_once DRUPAL_ROOT . '/includes/module.inc';\n module_load_all(TRUE);\n\n // Sanitize the destination parameter (which is often used for redirects) to\n // prevent open redirect attacks leading to other domains. Sanitize both\n // $_GET['destination'] and $_REQUEST['destination'] to protect code that\n // relies on either, but do not sanitize $_POST to avoid interfering with\n // unrelated form submissions. The sanitization happens here because\n // url_is_external() requires the variable system to be available.\n if (isset($_GET['destination']) || isset($_REQUEST['destination'])) {\n require_once DRUPAL_ROOT . '/includes/common.inc';\n // If the destination is an external URL, remove it.\n if (isset($_GET['destination']) && url_is_external($_GET['destination'])) {\n unset($_GET['destination']);\n unset($_REQUEST['destination']);\n }\n // Use the DrupalRequestSanitizer to ensure that the destination's query\n // parameters are not dangerous.\n if (isset($_GET['destination'])) {\n DrupalRequestSanitizer::cleanDestination();\n }\n // If there's still something in $_REQUEST['destination'] that didn't come\n // from $_GET, check it too.\n if (isset($_REQUEST['destination']) && (!isset($_GET['destination']) || $_REQUEST['destination'] != $_GET['destination']) && url_is_external($_REQUEST['destination'])) {\n unset($_REQUEST['destination']);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dad76c2f02", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_disable_submit/7.x", "instruction": "Implement `filter_admin_disable_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for filter_admin_disable().", "context": "File: modules/filter/filter.admin.inc", "response": "function filter_admin_disable_submit($form, &$form_state) {\n $format = $form['#format'];\n filter_format_disable($format);\n drupal_set_message(t('Disabled text format %format.', array('%format' => $format->name)));\n\n $form_state['redirect'] = 'admin/config/content/formats';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dadace462f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_role_validate/7.x", "instruction": "Implement `user_admin_role_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for the user_admin_role() form.", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_role_validate($form, &$form_state) {\n if (!empty($form_state['values']['name'])) {\n if ($form_state['values']['op'] == t('Save role')) {\n $role = user_role_load_by_name($form_state['values']['name']);\n if ($role && $role->rid != $form_state['values']['rid']) {\n form_set_error('name', t('The role name %name already exists. Choose another role name.', array('%name' => $form_state['values']['name'])));\n }\n }\n elseif ($form_state['values']['op'] == t('Add role')) {\n if (user_role_load_by_name($form_state['values']['name'])) {\n form_set_error('name', t('The role name %name already exists. Choose another role name.', array('%name' => $form_state['values']['name'])));\n }\n }\n }\n else {\n form_set_error('name', t('You must specify a valid role name.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-daee37251e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_form_system_theme_settings_alter/7.x", "instruction": "Implement `color_form_system_theme_settings_alter(&$form, &$form_state)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter().", "context": "File: modules/color/color.module", "response": "function color_form_system_theme_settings_alter(&$form, &$form_state) {\n if (isset($form_state['build_info']['args'][0]) && ($theme = $form_state['build_info']['args'][0]) && color_get_info($theme) && function_exists('gd_info')) {\n $form['color'] = array(\n '#type' => 'fieldset',\n '#title' => t('Color scheme'),\n '#weight' => -1,\n '#attributes' => array('id' => 'color_scheme_form'),\n '#theme' => 'color_scheme_form',\n );\n $form['color'] += color_scheme_form($form, $form_state, $theme);\n $form['#validate'][] = 'color_scheme_form_validate';\n $form['#submit'][] = 'color_scheme_form_submit';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-daf3af9257", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_current_script_url/7.x", "instruction": "In Drupal 7, write the function `drupal_current_script_url($query = array())` (file includes/install.inc) so that it does the following: Returns the URL of the current script, with modified query parameters.", "context": "This function can be called by low-level scripts (such as install.php and update.php) and returns the URL of the current script. Existing query parameters are preserved by default, but new ones can optionally be merged in.\n\nThis function is used when the script must maintain certain query parameters over multiple page requests in order to work correctly. In such cases (for example, update.php, which requires the 'continue=1' parameter to remain in the URL throughout the update process if there are any requirement warnings that need to be bypassed), using this function to generate the URL for links to the next steps of the script ensures that the links will work correctly.\n\nParameters:\n- $query: (optional) An array of query parameters to merge in to the existing ones.\n\nReturns: The URL of the current script, with query parameters modified by the passed-in $query. The URL is not sanitized, so it still needs to be run through check_url() if it will be used as an HTML attribute value.\n\nFile: includes/install.inc", "response": "function drupal_current_script_url($query = array()) {\n $uri = $_SERVER['SCRIPT_NAME'];\n $query = array_merge(drupal_get_query_parameters(), $query);\n if (!empty($query)) {\n $uri .= '?' . drupal_http_build_query($query);\n }\n return $uri;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dafc31718a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_field_formatter_view/7.x", "instruction": "In Drupal 7, write the function `list_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` (file modules/field/modules/list/list.module) so that it does the following: Implements hook_field_formatter_view().", "context": "File: modules/field/modules/list/list.module", "response": "function list_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {\n $element = array();\n\n switch ($display['type']) {\n case 'list_default':\n $allowed_values = list_allowed_values($field, $instance, $entity_type, $entity);\n foreach ($items as $delta => $item) {\n if (isset($allowed_values[$item['value']])) {\n $output = field_filter_xss($allowed_values[$item['value']]);\n }\n else {\n // If no match was found in allowed values, fall back to the key.\n $output = field_filter_xss($item['value']);\n }\n $element[$delta] = array('#markup' => $output);\n }\n break;\n\n case 'list_key':\n foreach ($items as $delta => $item) {\n $element[$delta] = array('#markup' => field_filter_xss($item['value']));\n }\n break;\n }\n\n return $element;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dafef8bf25", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_element_info/7.x", "instruction": "Implement `filter_element_info()` in PHP for Drupal 7. Required behavior: Implements hook_element_info().", "context": "File: modules/filter/filter.module", "response": "function filter_element_info() {\n $type['text_format'] = array(\n '#process' => array('filter_process_format'),\n '#base_type' => 'textarea',\n '#theme_wrappers' => array('text_format_wrapper'),\n );\n return $type;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-db4009ec2f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_deliver/7.x", "instruction": "I need the code for `image_style_deliver($style, $scheme = NULL)` in Drupal 7 (modules/image/image.module). It must do this: Page callback: Generates a derivative, given a style and image path.", "context": "After generating an image, transfer it to the requesting agent.\n\nParameters:\n- $style: The image style\n- $scheme: The file scheme, for example 'public' for public files.\n\nFile: modules/image/image.module", "response": "function image_style_deliver($style, $scheme = NULL) {\n $args = func_get_args();\n array_shift($args);\n array_shift($args);\n $target = implode('/', $args);\n $image_uri = $scheme . '://' . $target;\n $image_uri = file_uri_normalize_dot_segments($image_uri);\n\n if (file_stream_wrapper_valid_scheme($scheme)) {\n $normalized_target = file_uri_target($image_uri);\n if ($normalized_target !== FALSE) {\n if (!in_array($scheme, variable_get('file_sa_core_2023_005_schemes', array()))) {\n $parts = explode('/', $normalized_target);\n if (array_intersect($parts, array('.', '..'))) {\n return MENU_NOT_FOUND;\n }\n }\n }\n }\n\n // Check that the style is defined, the scheme is valid.\n $valid = !empty($style) && !empty($scheme) && file_stream_wrapper_valid_scheme($scheme);\n\n // Also validate the derivative token. Sites which require image derivatives\n // to be generated without a token can set the 'image_allow_insecure_derivatives'\n // variable to TRUE to bypass the latter check, but this will increase the\n // site's vulnerability to denial-of-service attacks. To prevent this\n // variable from leaving the site vulnerable to the most serious attacks, a\n // token is always required when a derivative of a derivative is requested.)\n $token = isset($_GET[IMAGE_DERIVATIVE_TOKEN]) ? $_GET[IMAGE_DERIVATIVE_TOKEN] : '';\n $token_is_valid =\n $token === image_style_path_token($style['name'], $image_uri)\n || $token === image_style_path_token($style['name'], $scheme . '://' . $target);\n if (!variable_get('image_allow_insecure_derivatives', FALSE) || strpos(ltrim($target, '\\/'), 'styles/') === 0) {\n $valid = $valid && $token_is_valid;\n }\n if (!$valid) {\n return MENU_ACCESS_DENIED;\n }\n\n $derivative_uri = image_style_path($style['name'], $image_uri);\n $derivative_scheme = file_uri_scheme($derivative_uri);\n\n if ($token_is_valid) {\n $is_public = ($scheme !== 'private');\n }\n else {\n $core_schemes = array('public', 'private', 'temporary');\n $additional_public_schemes = array_diff(variable_get('file_additional_public_schemes', array()), $core_schemes);\n $public_schemes = array_merge(array('public'), $additional_public_schemes);\n $is_public = in_array($derivative_scheme, $public_schemes, TRUE);\n }\n\n if ($scheme == 'private' && file_exists($derivative_uri)) {\n file_download($scheme, file_uri_target($derivative_uri));\n }\n\n $headers = array();\n\n if (!$is_public) {\n $headers = file_download_headers($image_uri);\n if (empty($headers)) {\n return MENU_ACCESS_DENIED;\n }\n }\n\n // Confirm that the original source image exists before trying to process it.\n if (!_image_source_image_exists($image_uri, $token_is_valid)) {\n watchdog('image', 'Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.', array('%source_image_path' => $image_uri, '%derivative_path' => $derivative_uri));\n return MENU_NOT_FOUND;\n }\n\n // Don't start generating the image if the derivative already exists or if\n // generation is in progress in another thread.\n $lock_name = 'image_style_deliver:' . $style['name'] . ':' . drupal_hash_base64($image_uri);\n if (!file_exists($derivative_uri)) {\n $lock_acquired = lock_acquire($lock_name);\n if (!$lock_acquired) {\n // Tell client to retry again in 3 seconds. Currently no browsers are known\n // to support Retry-After.\n drupal_add_http_header('Status', '503 Service Unavailable');\n drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');\n drupal_add_http_header('Retry-After', 3);\n print t('Image generation in progress. Try again shortly.');\n drupal_exit();\n }\n }\n\n // Try to generate the image, unless another thread just did it while we were\n // acquiring the lock.\n $success = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);\n\n if (!empty($lock_acquired)) {\n lock_release($lock_name);\n }\n\n if ($success) {\n $image = image_load($derivative_uri);\n $headers['Content-Type'] = $image->info['mime_type'];\n $headers['Content-Length'] = $image->info['file_size'];\n file_transfer($image->source, $headers);\n }\n else {\n watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri));\n drupal_add_http_header('Status', '500 Internal Server Error');\n drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');\n print t('Error generating image.');\n drupal_exit();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-db4024b78f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_fields_list/7.x", "instruction": "I need the code for `field_ui_fields_list()` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Menu callback; lists all defined fields for quick reference.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_fields_list() {\n $instances = field_info_instances();\n $field_types = field_info_field_types();\n $bundles = field_info_bundles();\n\n $modules = system_rebuild_module_data();\n\n $header = array(t('Field name'), t('Field type'), t('Used in'));\n $rows = array();\n foreach ($instances as $entity_type => $type_bundles) {\n foreach ($type_bundles as $bundle => $bundle_instances) {\n foreach ($bundle_instances as $field_name => $instance) {\n $field = field_info_field($field_name);\n\n // Initialize the row if we encounter the field for the first time.\n if (!isset($rows[$field_name])) {\n $rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array('');\n $rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name;\n $module_name = $field_types[$field['type']]['module'];\n $rows[$field_name]['data'][1] = $field_types[$field['type']]['label'] . ' ' . t('(module: !module)', array('!module' => $modules[$module_name]->info['name']));\n }\n\n // Add the current instance.\n $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);\n $rows[$field_name]['data'][2][] = $admin_path ? l($bundles[$entity_type][$bundle]['label'], $admin_path . '/fields') : $bundles[$entity_type][$bundle]['label'];\n }\n }\n }\n foreach ($rows as $field_name => $cell) {\n $rows[$field_name]['data'][2] = implode(', ', $cell['data'][2]);\n }\n if (empty($rows)) {\n $output = t('No fields have been defined yet.');\n }\n else {\n // Sort rows by field name.\n ksort($rows);\n $output = theme('table', array('header' => $header, 'rows' => $rows));\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-db56e5b135", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.api.php/function/hook_comment_update/7.x", "instruction": "Give me the example code for `hook_comment_update($comment)` in Drupal 7. Hook description: The comment is being updated.", "context": "Parameters:\n- $comment: The comment object.\n\nFile: modules/comment/comment.api.php", "response": "function hook_comment_update($comment) {\n // Reindex the node when comments are updated.\n search_touch_node($comment->nid);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-db76495daf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_profile/7.x", "instruction": "Implement `drupal_get_profile()` in PHP for Drupal 7. Required behavior: Gets the name of the currently active installation profile.", "context": "When this function is called during Drupal's initial installation process, the name of the profile that's about to be installed is stored in the global installation state. At all other times, the standard Drupal systems variable table contains the name of the current profile, and we can call variable_get() to determine what one is active.\n\nReturns: $profile The name of the installation profile.\n\nFile: includes/common.inc", "response": "function drupal_get_profile() {\n global $install_state;\n\n if (isset($install_state['parameters']['profile'])) {\n $profile = $install_state['parameters']['profile'];\n }\n else {\n $profile = variable_get('install_profile', 'standard');\n }\n\n return $profile;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-db9abbdd2c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7013/7.x", "instruction": "I need the code for `user_update_7013(&$sandbox)` in Drupal 7 (modules/user/user.install). It must do this: Add user module file usage entries.", "context": "File: modules/user/user.install", "response": "function user_update_7013(&$sandbox) {\n if (!isset($sandbox['progress'])) {\n // Initialize batch update information.\n $sandbox['progress'] = 0;\n $sandbox['last_uid_processed'] = -1;\n $sandbox['max'] = db_query(\"SELECT COUNT(*) FROM {users} u WHERE u.picture <> 0\")->fetchField();\n }\n\n // Add usage entries for the user picture files.\n $limit = 500;\n $result = db_query_range('SELECT f.*, u.uid as user_uid FROM {users} u INNER JOIN {file_managed} f ON u.picture = f.fid WHERE u.picture <> 0 AND u.uid > :uid ORDER BY u.uid', 0, $limit, array(':uid' => $sandbox['last_uid_processed']))->fetchAllAssoc('fid', PDO::FETCH_ASSOC);\n foreach ($result as $row) {\n $uid = $row['user_uid'];\n $file = (object) $row;\n file_usage_add($file, 'user', 'user', $uid);\n\n // Update our progress information for the batch update.\n $sandbox['progress']++;\n $sandbox['last_uid_processed'] = $uid;\n }\n\n // Indicate our current progress to the batch update system.\n $sandbox['#finished'] = empty($sandbox['max']) || ($sandbox['progress'] / $sandbox['max']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dba83bb4d8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/_rdf_mapping_load_multiple/7.x", "instruction": "I need the code for `_rdf_mapping_load_multiple($type, array $bundles)` in Drupal 7 (modules/rdf/rdf.module). It must do this: Helper function to retrieve a set of RDF mappings from the database.", "context": "Parameters:\n- $type: The entity type of the mappings.\n- $bundles: The bundles the mappings refer to.\n\nReturns: An array of RDF mapping structures, or an empty array.\n\nFile: modules/rdf/rdf.module", "response": "function _rdf_mapping_load_multiple($type, array $bundles) {\n $mappings = db_select('rdf_mapping')\n ->fields(NULL, array('bundle', 'mapping'))\n ->condition('type', $type)\n ->condition('bundle', $bundles)\n ->execute()\n ->fetchAllKeyed();\n\n foreach ($mappings as $bundle => $mapping) {\n $mappings[$bundle] = unserialize($mapping);\n }\n return $mappings;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dbae49c9cb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/fix_gpc_magic/7.x", "instruction": "In Drupal 7, write the function `fix_gpc_magic()` (file includes/common.inc) so that it does the following: Fixes double-escaping caused by \"magic quotes\" in some PHP installations.", "context": "File: includes/common.inc", "response": "function fix_gpc_magic() {\n static $fixed = FALSE;\n if (!$fixed && ini_get('magic_quotes_gpc')) {\n array_walk($_GET, '_fix_gpc_magic');\n array_walk($_POST, '_fix_gpc_magic');\n array_walk($_COOKIE, '_fix_gpc_magic');\n array_walk($_REQUEST, '_fix_gpc_magic');\n array_walk($_FILES, '_fix_gpc_magic_files');\n }\n $fixed = TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dbca24b7a1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_pass_rehash/7.x", "instruction": "Implement `user_pass_rehash($password, $timestamp, $login, $uid, $mail = '')` in PHP for Drupal 7. Required behavior: Creates a unique hash value for use in time-dependent per-user URLs.", "context": "This hash is normally used to build a unique and secure URL that is sent to the user by email for purposes such as resetting the user's password. In order to validate the URL, the same hash can be generated again, from the same information, and compared to the hash value from the URL. The URL normally contains both the time stamp and the numeric user ID. The login timestamp and hashed password are retrieved from the database as necessary. For a usage example, see user_cancel_url() and user_cancel_confirm().\n\nParameters:\n- $password (string): The hashed user account password value.\n- $timestamp (int): A UNIX timestamp, typically REQUEST_TIME.\n- $login (int): The UNIX timestamp of the user's last login.\n- $uid (int): The user ID of the user account.\n- $mail (string): The e-mail address of the user.\n\nReturns: A string that is safe for use in URLs and SQL statements.\n\nFile: modules/user/user.module", "response": "function user_pass_rehash($password, $timestamp, $login, $uid, $mail = '') {\n // Backwards compatibility: Try to determine a $uid if one was not passed.\n // (Since $uid is a required parameter to this function, a PHP warning will\n // be generated if it's not provided, which is an indication that the calling\n // code should be updated. But the code below will try to generate a correct\n // hash in the meantime.)\n if (!isset($uid)) {\n $uids = db_query_range('SELECT uid FROM {users} WHERE pass = :password AND login = :login AND uid > 0', 0, 2, array(':password' => $password, ':login' => $login))->fetchCol();\n // If exactly one user account matches the provided password and login\n // timestamp, proceed with that $uid.\n if (count($uids) == 1) {\n $uid = reset($uids);\n }\n // Otherwise there is no safe hash to return, so return a random string\n // that will never be treated as a valid token.\n else {\n return drupal_random_key();\n }\n }\n\n // Backwards compatibility: If the $mail parameter is not provided, load it\n // from the user object.\n if (empty($mail)) {\n $account = user_load($uid);\n $mail = $account->mail;\n }\n\n return drupal_hmac_base64($timestamp . ':' . $login . ':' . $uid . ':' . $mail, drupal_get_hash_salt() . $password);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dbd18e31e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21content_types.inc/function/node_type_delete_confirm/7.x", "instruction": "In Drupal 7, write the function `node_type_delete_confirm($form, &$form_state, $type)` (file modules/node/content_types.inc) so that it does the following: Menu callback; delete a single content type.", "context": "File: modules/node/content_types.inc", "response": "function node_type_delete_confirm($form, &$form_state, $type) {\n $form['type'] = array('#type' => 'value', '#value' => $type->type);\n $form['name'] = array('#type' => 'value', '#value' => $type->name);\n\n $message = t('Are you sure you want to delete the content type %type?', array('%type' => $type->name));\n\n $num_nodes = db_query(\"SELECT COUNT(*) FROM {node} WHERE type = :type\", array(':type' => $type->type))->fetchField();\n if ($num_nodes) {\n drupal_set_title($message, PASS_THROUGH);\n $caption = '

              ' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. You cannot remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You cannot remove this content type until you have removed all of the %type content.', array('%type' => $type->name)) . '

              ';\n $form['description'] = array('#markup' => $caption);\n return $form;\n }\n\n $caption = '

              ' . t('This action cannot be undone.') . '

              ';\n\n return confirm_form($form, $message, 'admin/structure/types', $caption, t('Delete'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dbe15fd2c1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_managed_file_save_upload/7.x", "instruction": "In Drupal 7, write the function `file_managed_file_save_upload($element)` (file modules/file/file.module) so that it does the following: Saves any files that have been uploaded into a managed_file element.", "context": "Parameters:\n- $element: The FAPI element whose values are being saved.\n\nReturns: The file object representing the file that was saved, or FALSE if no file was saved.\n\nFile: modules/file/file.module", "response": "function file_managed_file_save_upload($element) {\n $upload_name = implode('_', $element['#parents']);\n if (empty($_FILES['files']['name'][$upload_name])) {\n return FALSE;\n }\n\n $destination = isset($element['#upload_location']) ? $element['#upload_location'] : NULL;\n if (isset($destination) && !file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {\n watchdog('file', 'The upload directory %directory for the file field !name could not be created or is not accessible. A newly uploaded file could not be saved in this directory as a consequence, and the upload was canceled.', array('%directory' => $destination, '!name' => $element['#field_name']));\n form_set_error($upload_name, t('The file could not be uploaded.'));\n return FALSE;\n }\n\n if (!$file = file_save_upload($upload_name, $element['#upload_validators'], $destination)) {\n watchdog('file', 'The file upload failed. %upload', array('%upload' => $upload_name));\n form_set_error($upload_name, t('The file in the !name field was unable to be uploaded.', array('!name' => $element['#title'])));\n return FALSE;\n }\n\n return $file;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dbf2190e7e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.install/function/trigger_schema/7.x", "instruction": "In Drupal 7, write the function `trigger_schema()` (file modules/trigger/trigger.install) so that it does the following: Implements hook_schema().", "context": "File: modules/trigger/trigger.install", "response": "function trigger_schema() {\n // The total index length (hook and aid) must be less than 333. Since the aid\n // field is 255 characters, the hook field can have a maximum length of 78.\n $schema['trigger_assignments'] = array(\n 'description' => 'Maps trigger to hook and operation assignments from trigger.module.',\n 'fields' => array(\n 'hook' => array(\n 'type' => 'varchar',\n 'length' => 78,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.',\n ),\n 'aid' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => \"Primary Key: Action's {actions}.aid.\",\n ),\n 'weight' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The weight of the trigger assignment in relation to other triggers.',\n ),\n ),\n 'primary key' => array('hook', 'aid'),\n 'foreign keys' => array(\n 'action' => array(\n 'table' => 'actions',\n 'columns' => array('aid' => 'aid'),\n ),\n ),\n );\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc1442f14f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_form_node_type_form_submit/7.x", "instruction": "In Drupal 7, write the function `field_ui_form_node_type_form_submit($form, &$form_state)` (file modules/field_ui/field_ui.module) so that it does the following: Form submission handler for the 'Save and add fields' button.", "context": "File: modules/field_ui/field_ui.module", "response": "function field_ui_form_node_type_form_submit($form, &$form_state) {\n if ($form_state['triggering_element']['#parents'][0] === 'save_continue') {\n $form_state['redirect'] = _field_ui_bundle_admin_path('node', $form_state['values']['type']) .'/fields';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc2036a503", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_view_value/7.x", "instruction": "Implement `field_view_value($entity_type, $entity, $field_name, $item, $display = array(), $langcode = NULL)` in PHP for Drupal 7. Required behavior: Returns a renderable array for a single field value.", "context": "Parameters:\n- $entity_type: The type of $entity; e.g., 'node' or 'user'.\n- $entity: The entity containing the field to display. Must at least contain the id key and the field data to display.\n- $field_name: The name of the field to display.\n- $item: The field value to display, as found in $entity->field_name[$langcode][$delta].\n- $display: Can be either the name of a view mode, or an array of display settings. See field_view_field() for more information.\n- $langcode: (Optional) The language of the value in $item. If not provided, the current language will be assumed.\n\nReturns: A renderable array for the field value.\n\nFile: modules/field/field.module", "response": "function field_view_value($entity_type, $entity, $field_name, $item, $display = array(), $langcode = NULL) {\n $output = array();\n\n if ($field = field_info_field($field_name)) {\n // Determine the langcode that will be used by language fallback.\n $langcode = field_language($entity_type, $entity, $field_name, $langcode);\n\n // Push the item as the single value for the field, and defer to\n // field_view_field() to build the render array for the whole field.\n $clone = clone $entity;\n $clone->{$field_name}[$langcode] = array($item);\n $elements = field_view_field($entity_type, $clone, $field_name, $display, $langcode);\n\n // Extract the part of the render array we need.\n $output = isset($elements[0]) ? $elements[0] : array();\n if (isset($elements['#access'])) {\n $output['#access'] = $elements['#access'];\n }\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc371eb372", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_modules_submit/7.x", "instruction": "I need the code for `system_modules_submit($form, &$form_state)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Submit callback; handles modules form submission.", "context": "File: modules/system/system.admin.inc", "response": "function system_modules_submit($form, &$form_state) {\n include_once DRUPAL_ROOT . '/includes/install.inc';\n\n // Builds list of modules.\n $modules = array();\n // If we're not coming from the confirmation form, build the list of modules.\n if (empty($form_state['storage'])) {\n // If we're not coming from the confirmation form, build the module list.\n foreach ($form_state['values']['modules'] as $group_name => $group) {\n foreach ($group as $module => $enabled) {\n $modules[$module] = array('group' => $group_name, 'enabled' => $enabled['enable']);\n }\n }\n }\n else {\n // If we are coming from the confirmation form, fetch\n // the modules out of $form_state.\n $modules = $form_state['storage']['modules'];\n }\n\n // Collect data for all modules to be able to determine dependencies.\n $files = system_rebuild_module_data();\n\n // Sorts modules by weight.\n $sort = array();\n foreach (array_keys($modules) as $module) {\n $sort[$module] = $files[$module]->sort;\n }\n array_multisort($sort, $modules);\n\n // Makes sure all required modules are set to be enabled.\n $more_required = array();\n $missing_modules = array();\n foreach ($modules as $name => $module) {\n if ($module['enabled']) {\n // Checks that all dependencies are set to be enabled. Stores the ones\n // that are not in $dependencies variable so that the user can be alerted\n // in the confirmation form that more modules need to be enabled.\n $dependencies = array();\n foreach (array_keys($files[$name]->requires) as $required) {\n if (empty($modules[$required]['enabled'])) {\n if (isset($files[$required])) {\n $dependencies[] = $files[$required]->info['name'];\n $modules[$required]['enabled'] = TRUE;\n }\n else {\n $missing_modules[$required]['depends'][] = $name;\n $modules[$name]['enabled'] = FALSE;\n }\n }\n }\n\n // Stores additional modules that need to be enabled in $more_required.\n if (!empty($dependencies)) {\n $more_required[$name] = array(\n 'name' => $files[$name]->info['name'],\n 'requires' => $dependencies,\n );\n }\n }\n }\n\n // Redirects to confirmation form if more modules need to be enabled.\n if ((!empty($more_required) || !empty($missing_modules)) && !isset($form_state['values']['confirm'])) {\n $form_state['storage'] = array(\n 'more_required' => $more_required,\n 'modules' => $modules,\n 'missing_modules' => $missing_modules,\n );\n $form_state['rebuild'] = TRUE;\n return;\n }\n\n // Invokes hook_requirements('install'). If failures are detected, makes sure\n // the dependent modules aren't installed either.\n foreach ($modules as $name => $module) {\n // Only invoke hook_requirements() on modules that are going to be installed.\n if ($module['enabled'] && drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {\n if (!drupal_check_module($name)) {\n $modules[$name]['enabled'] = FALSE;\n foreach (array_keys($files[$name]->required_by) as $required_by) {\n $modules[$required_by]['enabled'] = FALSE;\n }\n }\n }\n }\n\n // Initializes array of actions.\n $actions = array(\n 'enable' => array(),\n 'disable' => array(),\n 'install' => array(),\n );\n\n // Builds arrays of modules that need to be enabled, disabled, and installed.\n foreach ($modules as $name => $module) {\n if ($module['enabled']) {\n if (drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {\n $actions['install'][] = $name;\n $actions['enable'][] = $name;\n }\n elseif (!module_exists($name)) {\n $actions['enable'][] = $name;\n }\n }\n elseif (module_exists($name)) {\n $actions['disable'][] = $name;\n }\n }\n\n // Gets list of modules prior to install process, unsets $form_state['storage']\n // so we don't get redirected back to the confirmation form.\n $pre_install_list = module_list();\n unset($form_state['storage']);\n\n // Reverse the 'enable' list, to order dependencies before dependents.\n krsort($actions['enable']);\n\n // Installs, enables, and disables modules.\n module_enable($actions['enable'], FALSE);\n module_disable($actions['disable'], FALSE);\n\n // Gets module list after install process, flushes caches and displays a\n // message if there are changes.\n $post_install_list = module_list(TRUE);\n if ($pre_install_list != $post_install_list) {\n drupal_flush_all_caches();\n drupal_set_message(t('The configuration options have been saved.'));\n }\n\n $form_state['redirect'] = 'admin/modules';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc3fb3085f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_math_powmod/7.x", "instruction": "In Drupal 7, write the function `_openid_math_powmod($x, $y, $z)` (file modules/openid/openid.inc) so that it does the following: Calls the mul function from the available math library for OpenID.", "context": "File: modules/openid/openid.inc", "response": "function _openid_math_powmod($x, $y, $z) {\n $library = _openid_get_math_library();\n switch ($library) {\n case 'gmp':\n return gmp_powm($x, $y, $z);\n case 'bcmath':\n return bcpowmod($x, $y, $z);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc5e8614f0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_permission/7.x", "instruction": "I need the code for `comment_permission()` in Drupal 7 (modules/comment/comment.module). It must do this: Implements hook_permission().", "context": "File: modules/comment/comment.module", "response": "function comment_permission() {\n return array(\n 'administer comments' => array(\n 'title' => t('Administer comments and comment settings'),\n ),\n 'access comments' => array(\n 'title' => t('View comments'),\n ),\n 'post comments' => array(\n 'title' => t('Post comments'),\n ),\n 'skip comment approval' => array(\n 'title' => t('Skip comment approval'),\n ),\n 'edit own comments' => array(\n 'title' => t('Edit own comments'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc74c35b95", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_cron/7.x", "instruction": "Implement `system_cron()` in PHP for Drupal 7. Required behavior: Implements hook_cron().", "context": "Remove older rows from flood and batch table. Remove old temporary files.\n\nFile: modules/system/system.module", "response": "function system_cron() {\n // Cleanup the flood.\n db_delete('flood')\n ->condition('expiration', REQUEST_TIME, '<')\n ->execute();\n\n // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.\n // Use separate placeholders for the status to avoid a bug in some versions\n // of PHP. See http://drupal.org/node/352956.\n $result = db_query('SELECT fid FROM {file_managed} WHERE status <> :permanent AND timestamp < :timestamp', array(\n ':permanent' => FILE_STATUS_PERMANENT,\n ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE\n ));\n foreach ($result as $row) {\n if ($file = file_load($row->fid)) {\n $references = file_usage_list($file);\n if (empty($references)) {\n if (!file_delete($file)) {\n watchdog('file system', 'Could not delete temporary file \"%path\" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR);\n }\n }\n else {\n watchdog('file system', 'Did not delete temporary file \"%path\" during garbage collection, because it is in use by the following modules: %modules.', array('%path' => $file->uri, '%modules' => implode(', ', array_keys($references))), WATCHDOG_INFO);\n }\n }\n }\n\n // Delete expired cache entries.\n // Avoid invoking hook_flush_cashes() on every cron run because some modules\n // use this hook to perform expensive rebuilding operations (which are only\n // designed to happen on full cache clears), rather than just returning a\n // list of cache tables to be cleared.\n $cache_object = cache_get('system_cache_tables');\n if (empty($cache_object)) {\n $core = array('cache', 'cache_path', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');\n $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);\n cache_set('system_cache_tables', $cache_tables);\n }\n else {\n $cache_tables = $cache_object->data;\n }\n foreach ($cache_tables as $table) {\n cache_clear_all(NULL, $table);\n }\n\n // Cleanup the batch table and the queue for failed batches.\n db_delete('batch')\n ->condition('timestamp', REQUEST_TIME - 864000, '<')\n ->execute();\n db_delete('queue')\n ->condition('created', REQUEST_TIME - 864000, '<')\n ->condition('name', 'drupal_batch:%', 'LIKE')\n ->execute();\n\n // Reset expired items in the default queue implementation table. If that's\n // not used, this will simply be a no-op.\n db_update('queue')\n ->fields(array(\n 'expire' => 0,\n ))\n ->condition('expire', 0, '<>')\n ->condition('expire', REQUEST_TIME, '<')\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc76a68da9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_page_source/7.x", "instruction": "In Drupal 7, write the function `aggregator_page_source($feed)` (file modules/aggregator/aggregator.pages.inc) so that it does the following: Page callback: Displays all the items captured from the particular feed.", "context": "Parameters:\n- $feed: The feed for which to display all items.\n\nReturns: The rendered list of items for a feed.\n\nFile: modules/aggregator/aggregator.pages.inc", "response": "function aggregator_page_source($feed) {\n drupal_set_title($feed->title);\n $feed_source = theme('aggregator_feed_source', array('feed' => $feed));\n\n // It is safe to include the fid in the query because it's loaded from the\n // database by aggregator_feed_load.\n $items = aggregator_feed_items_load('source', $feed);\n\n return _aggregator_page_list($items, arg(3), $feed_source);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dc79f34f15", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_save/7.x", "instruction": "In Drupal 7, write the function `taxonomy_term_save($term)` (file modules/taxonomy/taxonomy.module) so that it does the following: Saves a term object to the database.", "context": "Parameters:\n- $term: The taxonomy term object with the following properties: - vid: The ID of the vocabulary the term is assigned to. - name: The name of the term. - tid: (optional) The unique ID for the term being saved. If $term->tid is empty or omitted, a new term will be inserted. - description: (optional) The term's description. - format: (optional) The text format for the term's description. - weight: (optional) The weight of this term in relation to other terms within the same vocabulary. - parent: (optional) The parent term(s) for this term. This can be a single term ID or an array of term IDs. A value of 0 means this term does not have any parents. When omitting this variable during an update, the existing hierarchy for the term remains unchanged. - vocabulary_machine_name: (optional) The machine name of the vocabulary the term is assigned to. If not given, this value will be set automatically by loading the vocabulary based on $term->vid. - original: (optional) The original taxonomy term object before any changes were applied. When omitted, the unchanged taxonomy term object is loaded from the database and stored in this property. Since a taxonomy term is an entity, any fields contained in the term object are saved alongside the term object.\n\nReturns: Status constant indicating whether term was inserted (SAVED_NEW) or updated (SAVED_UPDATED). When inserting a new term, $term->tid will contain the term ID of the newly created term.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_term_save($term) {\n // Prevent leading and trailing spaces in term names.\n $term->name = trim($term->name);\n if (!isset($term->vocabulary_machine_name)) {\n $vocabulary = taxonomy_vocabulary_load($term->vid);\n $term->vocabulary_machine_name = $vocabulary->machine_name;\n }\n\n // Load the stored entity, if any.\n if (!empty($term->tid) && !isset($term->original)) {\n $term->original = entity_load_unchanged('taxonomy_term', $term->tid);\n }\n\n field_attach_presave('taxonomy_term', $term);\n module_invoke_all('taxonomy_term_presave', $term);\n module_invoke_all('entity_presave', $term, 'taxonomy_term');\n\n if (empty($term->tid)) {\n $op = 'insert';\n $status = drupal_write_record('taxonomy_term_data', $term);\n field_attach_insert('taxonomy_term', $term);\n if (!isset($term->parent)) {\n $term->parent = array(0);\n }\n }\n else {\n $op = 'update';\n $status = drupal_write_record('taxonomy_term_data', $term, 'tid');\n field_attach_update('taxonomy_term', $term);\n if (isset($term->parent)) {\n db_delete('taxonomy_term_hierarchy')\n ->condition('tid', $term->tid)\n ->execute();\n }\n }\n\n if (isset($term->parent)) {\n if (!is_array($term->parent)) {\n $term->parent = array($term->parent);\n }\n $query = db_insert('taxonomy_term_hierarchy')\n ->fields(array('tid', 'parent'));\n foreach ($term->parent as $parent) {\n if (is_array($parent)) {\n foreach ($parent as $tid) {\n $query->values(array(\n 'tid' => $term->tid,\n 'parent' => $tid\n ));\n }\n }\n else {\n $query->values(array(\n 'tid' => $term->tid,\n 'parent' => $parent\n ));\n }\n }\n $query->execute();\n }\n\n // Reset the taxonomy term static variables.\n taxonomy_terms_static_reset();\n\n // Invoke the taxonomy hooks.\n module_invoke_all(\"taxonomy_term_$op\", $term);\n module_invoke_all(\"entity_$op\", $term, 'taxonomy_term');\n unset($term->original);\n\n return $status;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dcc70d0af7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7065/7.x", "instruction": "I need the code for `system_update_7065()` in Drupal 7 (modules/system/system.install). It must do this: Remove the default value for sid.", "context": "File: modules/system/system.install", "response": "function system_update_7065() {\n $spec = array(\n 'description' => \"A session ID. The value is generated by Drupal's session handlers.\",\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n );\n db_drop_primary_key('sessions');\n db_change_field('sessions', 'sid', 'sid', $spec, array('primary key' => array('sid', 'ssid')));\n // Delete any sessions with empty session ID.\n db_delete('sessions')->condition('sid', '')->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dcc7d26258", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_query/7.x", "instruction": "In Drupal 7, write the function `db_query($query, array $args = array(), array $options = array())` (file includes/database/database.inc) so that it does the following: Executes an arbitrary query string against the active database.", "context": "Use this function for SELECT queries if it is just a simple query string. If the caller or other modules need to change the query, use db_select() instead.\n\nDo not use this function for INSERT, UPDATE, or DELETE queries. Those should be handled via db_insert(), db_update() and db_delete() respectively.\n\nParameters:\n- $query: The prepared statement query to run. Although it will accept both named and unnamed placeholders, named placeholders are strongly preferred as they are more self-documenting.\n- $args: An array of values to substitute into the query. If the query uses named placeholders, this is an associative array in any order. If the query uses unnamed placeholders (?), this is an indexed array and the order must match the order of placeholders in the query string.\n- $options: An array of options to control how the query operates.\n\nReturns: DatabaseStatementInterface A prepared statement object, already executed.\n\nFile: includes/database/database.inc", "response": "function db_query($query, array $args = array(), array $options = array()) {\n if (empty($options['target'])) {\n $options['target'] = 'default';\n }\n\n return Database::getConnection($options['target'])->query($query, $args, $options);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dce2a767fc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_toggle_page/7.x", "instruction": "In Drupal 7, write the function `toolbar_toggle_page()` (file modules/toolbar/toolbar.module) so that it does the following: Menu callback; toggles the visibility of the toolbar drawer.", "context": "File: modules/toolbar/toolbar.module", "response": "function toolbar_toggle_page() {\n global $base_path;\n // Toggle the value in the cookie.\n drupal_setcookie('Drupal.toolbar.collapsed', !_toolbar_is_collapsed(),\n array(\n 'samesite' => 'Lax',\n 'path' => $base_path,\n )\n );\n // Redirect the user from where he used the toggle element.\n drupal_goto();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dce3e51f3a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.pages.inc/function/filter_tips_long/7.x", "instruction": "I need the code for `filter_tips_long($format = NULL)` in Drupal 7 (modules/filter/filter.pages.inc). It must do this: Page callback: Displays a page with long filter tips.", "context": "Returns (string): An HTML-formatted string.\n\nFile: modules/filter/filter.pages.inc", "response": "function filter_tips_long($format = NULL) {\n if (!empty($format)) {\n $output = theme('filter_tips', array('tips' => _filter_tips($format->format, TRUE), 'long' => TRUE));\n }\n else {\n $output = theme('filter_tips', array('tips' => _filter_tips(-1, TRUE), 'long' => TRUE));\n }\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dcf644f0a2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_date_time_formats/7.x", "instruction": "Implement `system_date_time_formats()` in PHP for Drupal 7. Required behavior: Displays the date format strings overview page.", "context": "File: modules/system/system.admin.inc", "response": "function system_date_time_formats() {\n $header = array(t('Format'), array('data' => t('Operations'), 'colspan' => '2'));\n $rows = array();\n\n drupal_static_reset('system_get_date_formats');\n $formats = system_get_date_formats('custom');\n if (!empty($formats)) {\n foreach ($formats as $format) {\n $row = array();\n $row[] = array('data' => format_date(REQUEST_TIME, 'custom', $format['format']));\n $row[] = array('data' => l(t('edit'), 'admin/config/regional/date-time/formats/' . $format['dfid'] . '/edit'));\n $row[] = array('data' => l(t('delete'), 'admin/config/regional/date-time/formats/' . $format['dfid'] . '/delete'));\n $rows[] = $row;\n }\n }\n\n $build['date_formats_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#empty' => t('No custom date formats available. Add date format.', array('@link' => url('admin/config/regional/date-time/formats/add'))),\n );\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd0288c830", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_updater_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_updater_info_alter(&$updaters)` (modules/system/system.api.php): Alter the Updater information array.", "context": "An Updater is a class that knows how to update various parts of the Drupal file system, for example to update modules that have newer releases, or to install a new theme.\n\nParameters:\n- $updaters (array): Associative array of updaters as defined through hook_updater_info(). Alter this array directly.\n\nFile: modules/system/system.api.php", "response": "function hook_updater_info_alter(&$updaters) {\n // Adjust weight so that the theme Updater gets a chance to handle a given\n // update task before module updaters.\n $updaters['theme']['weight'] = -1;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd098aa8dc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_form_validate/7.x", "instruction": "I need the code for `field_attach_form_validate($entity_type, $entity, $form, &$form_state, $options = array())` in Drupal 7 (modules/field/field.attach.inc). It must do this: Perform field validation against form-submitted field values.", "context": "There are two levels of validation for fields in forms: widget\nvalidation, and field validation.\n- Widget validation steps are specific to a given widget's own form\n structure and UI metaphors. They are executed through FAPI's\n #element_validate property during normal form validation.\n- Field validation steps are common to a given field type, independently of\n the specific widget being used in a given form. They are defined in the\n field type's implementation of hook_field_validate().\n\nThis function performs field validation in the context of a form submission. It converts field validation errors into form errors on the correct form elements. Fieldable entity types should call this function during their own form validation function.\n\nParameters:\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entity: The entity being submitted. The 'bundle', 'id' and (if applicable) 'revision' keys should be present. The actual field values will be read from $form_state['values'].\n- $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.\n- $form_state: An associative array containing the current state of the form.\n- $options (array): An associative array of additional options. See _field_invoke() for details.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_form_validate($entity_type, $entity, $form, &$form_state, $options = array()) {\n // Validate $options since this is a new parameter added after Drupal 7 was\n // released.\n $options = is_array($options) ? $options : array();\n\n // Extract field values from submitted values.\n _field_invoke_default('extract_form_values', $entity_type, $entity, $form, $form_state);\n\n // Perform field_level validation.\n try {\n field_attach_validate($entity_type, $entity, $options);\n }\n catch (FieldValidationException $e) {\n // Pass field-level validation errors back to widgets for accurate error\n // flagging.\n foreach ($e->errors as $field_name => $field_errors) {\n foreach ($field_errors as $langcode => $errors) {\n $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state);\n $field_state['errors'] = $errors;\n field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state);\n }\n }\n _field_invoke_default('form_errors', $entity_type, $entity, $form, $form_state, $options);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd0db49be4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.processor.inc/function/aggregator_expire/7.x", "instruction": "Implement `aggregator_expire($feed)` in PHP for Drupal 7. Required behavior: Expires items from a feed depending on expiration settings.", "context": "Parameters:\n- $feed: Object describing feed.\n\nFile: modules/aggregator/aggregator.processor.inc", "response": "function aggregator_expire($feed) {\n $aggregator_clear = variable_get('aggregator_clear', 9676800);\n\n if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {\n // Remove all items that are older than flush item timer.\n $age = REQUEST_TIME - $aggregator_clear;\n $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid AND timestamp < :timestamp', array(\n ':fid' => $feed->fid,\n ':timestamp' => $age,\n ))\n ->fetchCol();\n if ($iids) {\n db_delete('aggregator_category_item')\n ->condition('iid', $iids, 'IN')\n ->execute();\n db_delete('aggregator_item')\n ->condition('iid', $iids, 'IN')\n ->execute();\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd16d3d37a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21password.inc/function/user_hash_password/7.x", "instruction": "In Drupal 7, write the function `user_hash_password($password, $count_log2 = 0)` (file includes/password.inc) so that it does the following: Hash a password using a secure hash.", "context": "Parameters:\n- $password: A plain-text password.\n- $count_log2: Optional integer to specify the iteration count. Generally used only during mass operations where a value less than the default is needed for speed.\n\nReturns: A string containing the hashed password (and a salt), or FALSE on failure.\n\nFile: includes/password.inc", "response": "function user_hash_password($password, $count_log2 = 0) {\n if (empty($count_log2)) {\n // Use the standard iteration count.\n $count_log2 = variable_get('password_count_log2', DRUPAL_HASH_COUNT);\n }\n return _password_crypt('sha512', $password, _password_generate_salt($count_log2));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd305b6e6b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_form_set_state/7.x", "instruction": "I need the code for `field_form_set_state($parents, $field_name, $langcode, &$form_state, $field_state)` in Drupal 7 (modules/field/field.form.inc). It must do this: Stores processing information about a field in $form_state.", "context": "Parameters:\n- $parents: The array of #parents where the field lives in the form.\n- $field_name: The field name.\n- $langcode: The language in which the field values are entered.\n- $form_state: The form state.\n- $field_state: The array of data to store. See field_form_get_state() for the structure and content of the array.\n\nFile: modules/field/field.form.inc", "response": "function field_form_set_state($parents, $field_name, $langcode, &$form_state, $field_state) {\n $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode);\n drupal_array_set_nested_value($form_state, $form_state_parents, $field_state);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd33f701b4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_countries_alter/7.x", "instruction": "Give me the example code for `hook_countries_alter(&$countries)` in Drupal 7. Hook description: Alter the default country list.", "context": "Parameters:\n- $countries: The associative array of countries keyed by ISO 3166-1 country code.\n\nFile: modules/system/system.api.php", "response": "function hook_countries_alter(&$countries) {\n // Elbonia is now independent, so add it to the country list.\n $countries['EB'] = 'Elbonia';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd4c0bd991", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_build_tree/7.x", "instruction": "I need the code for `_menu_build_tree($menu_name, array $parameters = array())` in Drupal 7 (includes/menu.inc). It must do this: Builds a menu tree.", "context": "This function may be used build the data for a menu tree only, for example to further massage the data manually before further processing happens. menu_tree_check_access() needs to be invoked afterwards.\n\nFile: includes/menu.inc", "response": "function _menu_build_tree($menu_name, array $parameters = array()) {\n // Static cache of already built menu trees.\n $trees = &drupal_static(__FUNCTION__, array());\n\n // Build the cache id; sort parents to prevent duplicate storage and remove\n // default parameter values.\n if (isset($parameters['expanded'])) {\n sort($parameters['expanded']);\n }\n $tree_cid = 'links:' . $menu_name . ':tree-data:' . $GLOBALS['language']->language . ':' . hash('sha256', serialize($parameters));\n\n // If we do not have this tree in the static cache, check {cache_menu}.\n if (!isset($trees[$tree_cid])) {\n $cache = cache_get($tree_cid, 'cache_menu');\n if ($cache && isset($cache->data)) {\n $trees[$tree_cid] = $cache->data;\n }\n }\n\n if (!isset($trees[$tree_cid])) {\n // Select the links from the table, and recursively build the tree. We\n // LEFT JOIN since there is no match in {menu_router} for an external\n // link.\n $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));\n $query->addTag('translatable');\n $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');\n $query->fields('ml');\n $query->fields('m', array(\n 'load_functions',\n 'to_arg_functions',\n 'access_callback',\n 'access_arguments',\n 'page_callback',\n 'page_arguments',\n 'delivery_callback',\n 'tab_parent',\n 'tab_root',\n 'title',\n 'title_callback',\n 'title_arguments',\n 'theme_callback',\n 'theme_arguments',\n 'type',\n 'description',\n ));\n for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {\n $query->orderBy('p' . $i, 'ASC');\n }\n $query->condition('ml.menu_name', $menu_name);\n if (!empty($parameters['expanded'])) {\n $query->condition('ml.plid', $parameters['expanded'], 'IN');\n }\n elseif (!empty($parameters['only_active_trail'])) {\n $query->condition('ml.mlid', $parameters['active_trail'], 'IN');\n }\n $min_depth = (isset($parameters['min_depth']) ? $parameters['min_depth'] : 1);\n if ($min_depth != 1) {\n $query->condition('ml.depth', $min_depth, '>=');\n }\n if (isset($parameters['max_depth'])) {\n $query->condition('ml.depth', $parameters['max_depth'], '<=');\n }\n // Add custom query conditions, if any were passed.\n if (isset($parameters['conditions'])) {\n foreach ($parameters['conditions'] as $column => $value) {\n $query->condition($column, $value);\n }\n }\n\n // Build an ordered array of links using the query result object.\n $links = array();\n foreach ($query->execute() as $item) {\n $links[] = $item;\n }\n $active_trail = (isset($parameters['active_trail']) ? $parameters['active_trail'] : array());\n $data['tree'] = menu_tree_data($links, $active_trail, $min_depth);\n $data['node_links'] = array();\n menu_tree_collect_node_links($data['tree'], $data['node_links']);\n\n // Cache the data, if it is not already in the cache.\n cache_set($tree_cid, $data, 'cache_menu');\n $trees[$tree_cid] = $data;\n }\n\n return $trees[$tree_cid];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd68fe8279", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_block_info/7.x", "instruction": "Implement `search_block_info()` in PHP for Drupal 7. Required behavior: Implements hook_block_info().", "context": "File: modules/search/search.module", "response": "function search_block_info() {\n $blocks['form']['info'] = t('Search form');\n // Not worth caching.\n $blocks['form']['cache'] = DRUPAL_NO_CACHE;\n $blocks['form']['properties']['administrative'] = TRUE;\n return $blocks;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd83ce7901", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_output/7.x", "instruction": "I need the code for `menu_tree_output($tree)` in Drupal 7 (includes/menu.inc). It must do this: Returns an output structure for rendering a menu tree.", "context": "The menu item's LI element is given one of the following classes:\n- expanded: The menu item is showing its submenu.\n- collapsed: The menu item has a submenu which is not shown.\n- leaf: The menu item has no submenu.\n\nParameters:\n- $tree: A data structure representing the tree as returned from menu_tree_data.\n\nReturns: A structured array to be rendered by drupal_render().\n\nFile: includes/menu.inc", "response": "function menu_tree_output($tree) {\n $build = array();\n $items = array();\n\n // Pull out just the menu links we are going to render so that we\n // get an accurate count for the first/last classes.\n foreach ($tree as $data) {\n if ($data['link']['access'] && !$data['link']['hidden']) {\n $items[] = $data;\n }\n }\n\n $router_item = menu_get_item();\n $num_items = count($items);\n foreach ($items as $i => $data) {\n $class = array();\n if ($i == 0) {\n $class[] = 'first';\n }\n if ($i == $num_items - 1) {\n $class[] = 'last';\n }\n // Set a class for the
            • -tag. Since $data['below'] may contain local\n // tasks, only set 'expanded' class if the link also has children within\n // the current menu.\n if ($data['link']['has_children'] && $data['below']) {\n $class[] = 'expanded';\n }\n elseif ($data['link']['has_children']) {\n $class[] = 'collapsed';\n }\n else {\n $class[] = 'leaf';\n }\n // Set a class if the link is in the active trail.\n if ($data['link']['in_active_trail']) {\n $class[] = 'active-trail';\n $data['link']['localized_options']['attributes']['class'][] = 'active-trail';\n }\n // Normally, l() compares the href of every link with $_GET['q'] and sets\n // the active class accordingly. But local tasks do not appear in menu\n // trees, so if the current path is a local task, and this link is its\n // tab root, then we have to set the class manually.\n if ($router_item && $data['link']['href'] == $router_item['tab_root_href'] && $data['link']['href'] != $_GET['q']) {\n $data['link']['localized_options']['attributes']['class'][] = 'active';\n }\n\n // Allow menu-specific theme overrides.\n $element['#theme'] = 'menu_link__' . strtr($data['link']['menu_name'], '-', '_');\n $element['#attributes']['class'] = $class;\n $element['#title'] = $data['link']['title'];\n $element['#href'] = $data['link']['href'];\n $element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();\n $element['#below'] = $data['below'] ? menu_tree_output($data['below']) : $data['below'];\n $element['#original_link'] = $data['link'];\n // Index using the link's unique mlid.\n $build[$data['link']['mlid']] = $element;\n }\n if ($build) {\n // Make sure drupal_render() does not re-order the links.\n $build['#sorted'] = TRUE;\n // Add the theme wrapper for outer markup.\n // Allow menu-specific theme overrides.\n $build['#theme_wrappers'][] = 'menu_tree__' . strtr($data['link']['menu_name'], '-', '_');\n }\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd843083d8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_url_parse_partial_links/7.x", "instruction": "I need the code for `_filter_url_parse_partial_links($match)` in Drupal 7 (modules/filter/filter.module). It must do this: Makes links out of domain names starting with \"www.\"", "context": "Callback for preg_replace_callback() within _filter_url().\n\nFile: modules/filter/filter.module", "response": "function _filter_url_parse_partial_links($match) {\n // The $i:th parenthesis in the regexp contains the URL.\n $i = 1;\n\n $match[$i] = decode_entities($match[$i]);\n $caption = check_plain(_filter_url_trim($match[$i]));\n $match[$i] = check_plain($match[$i]);\n return '' . $caption . '' . $match[$i + 1];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd8b91848a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_entity_info/7.x", "instruction": "I need the code for `node_entity_info()` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_entity_info().", "context": "File: modules/node/node.module", "response": "function node_entity_info() {\n $return = array(\n 'node' => array(\n 'label' => t('Node'),\n 'controller class' => 'NodeController',\n 'base table' => 'node',\n 'revision table' => 'node_revision',\n 'uri callback' => 'node_uri',\n 'fieldable' => TRUE,\n 'entity keys' => array(\n 'id' => 'nid',\n 'revision' => 'vid',\n 'bundle' => 'type',\n 'label' => 'title',\n 'language' => 'language',\n ),\n 'bundle keys' => array(\n 'bundle' => 'type',\n ),\n 'bundles' => array(),\n 'view modes' => array(\n 'full' => array(\n 'label' => t('Full content'),\n 'custom settings' => FALSE,\n ),\n 'teaser' => array(\n 'label' => t('Teaser'),\n 'custom settings' => TRUE,\n ),\n 'rss' => array(\n 'label' => t('RSS'),\n 'custom settings' => FALSE,\n ),\n ),\n ),\n );\n\n // Search integration is provided by node.module, so search-related view modes\n // for nodes are defined here and not in search.module.\n if (module_exists('search')) {\n $return['node']['view modes'] += array(\n 'search_index' => array(\n 'label' => t('Search index'),\n 'custom settings' => FALSE,\n ),\n 'search_result' => array(\n 'label' => t('Search result highlighting input'),\n 'custom settings' => FALSE,\n ),\n );\n }\n\n // Bundles must provide a human readable name so we can create help and error\n // messages, and the path to attach Field admin pages to.\n foreach (node_type_get_names() as $type => $name) {\n $return['node']['bundles'][$type] = array(\n 'label' => $name,\n 'admin' => array(\n 'path' => 'admin/structure/types/manage/%node_type',\n 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type),\n 'bundle argument' => 4,\n 'access arguments' => array('administer content types'),\n ),\n );\n }\n\n return $return;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dd8c6cb161", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21password.inc/function/_password_base64_encode/7.x", "instruction": "In Drupal 7, write the function `_password_base64_encode($input, $count)` (file includes/password.inc) so that it does the following: Encodes bytes into printable base 64 using the *nix standard from crypt().", "context": "Parameters:\n- $input: The string containing bytes to encode.\n- $count: The number of characters (bytes) to encode.\n\nReturns: Encoded string\n\nFile: includes/password.inc", "response": "function _password_base64_encode($input, $count) {\n $output = '';\n $i = 0;\n $itoa64 = _password_itoa64();\n do {\n $value = ord($input[$i++]);\n $output .= $itoa64[$value & 0x3f];\n if ($i < $count) {\n $value |= ord($input[$i]) << 8;\n }\n $output .= $itoa64[($value >> 6) & 0x3f];\n if ($i++ >= $count) {\n break;\n }\n if ($i < $count) {\n $value |= ord($input[$i]) << 16;\n }\n $output .= $itoa64[($value >> 12) & 0x3f];\n if ($i++ >= $count) {\n break;\n }\n $output .= $itoa64[($value >> 18) & 0x3f];\n } while ($i < $count);\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ddb02142a0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_system_module/7.x", "instruction": "In Drupal 7, write the function `install_system_module(&$install_state)` (file includes/install.core.inc) so that it does the following: Installation task; install the Drupal system module.", "context": "Parameters:\n- $install_state: An array of information about the current installation state.\n\nFile: includes/install.core.inc", "response": "function install_system_module(&$install_state) {\n // Install system.module.\n drupal_install_system();\n\n // Call file_ensure_htaccess() to ensure that all of Drupal's standard\n // directories (e.g., the public and private files directories) have\n // appropriate .htaccess files. These directories will have already been\n // created by this point in the installer, since Drupal creates them during\n // the install_verify_requirements() task. Note that we cannot call\n // file_ensure_htaccess() any earlier than this, since it relies on\n // system.module in order to work.\n file_ensure_htaccess();\n\n // Enable the user module so that sessions can be recorded during the\n // upcoming bootstrap step.\n module_enable(array('user'), FALSE);\n\n // Save the list of other modules to install for the upcoming tasks.\n // variable_set() can be used now that system.module is installed.\n $modules = $install_state['profile_info']['dependencies'];\n\n // The installation profile is also a module, which needs to be installed\n // after all the dependencies have been installed.\n $modules[] = drupal_get_profile();\n\n variable_set('install_profile_modules', array_diff($modules, array('system')));\n $install_state['database_tables_exist'] = TRUE;\n\n // Prevent the hook_requirements() check from telling us to convert the\n // database to utf8mb4.\n $connection = Database::getConnection();\n if ($connection->utf8mb4IsConfigurable() && $connection->utf8mb4IsActive()) {\n variable_set('drupal_all_databases_are_utf8mb4', TRUE);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ddc1bea130", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_library_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_library_alter(&$libraries, $module)` (modules/system/system.api.php): Alters the JavaScript/CSS library registry.", "context": "Allows certain, contributed modules to update libraries to newer versions while ensuring backwards compatibility. In general, such manipulations should only be done by designated modules, since most modules that integrate with a certain library also depend on the API of a certain library version.\n\nParameters:\n- $libraries: The JavaScript/CSS libraries provided by $module. Keyed by internal library name and passed by reference.\n- $module: The name of the module that registered the libraries.\n\nFile: modules/system/system.api.php", "response": "function hook_library_alter(&$libraries, $module) {\n // Update Farbtastic to version 2.0.\n if ($module == 'system' && isset($libraries['farbtastic'])) {\n // Verify existing version is older than the one we are updating to.\n if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) {\n // Update the existing Farbtastic to version 2.0.\n $libraries['farbtastic']['version'] = '2.0';\n $libraries['farbtastic']['js'] = array(\n drupal_get_path('module', 'farbtastic_update') . '/farbtastic-2.0.js' => array(),\n );\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ddcb9e8eb3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_form_user_register_form_alter/7.x", "instruction": "In Drupal 7, write the function `openid_form_user_register_form_alter(&$form, &$form_state)` (file modules/openid/openid.module) so that it does the following: Implements hook_form_FORM_ID_alter().", "context": "Prefills the login form with values acquired via OpenID.\n\nFile: modules/openid/openid.module", "response": "function openid_form_user_register_form_alter(&$form, &$form_state) {\n if (isset($_SESSION['openid']['response'])) {\n module_load_include('inc', 'openid');\n\n $response = $_SESSION['openid']['response'];\n\n // Extract Simple Registration keys from the response. We only include\n // signed keys as required by OpenID Simple Registration Extension 1.0,\n // section 4.\n $sreg_values = openid_extract_namespace($response, OPENID_NS_SREG, 'sreg', TRUE);\n // Extract Attribute Exchanges keys from the response. We only include\n // signed keys. This is not required by the specification, but it is\n // recommended by Google, see\n // http://googlecode.blogspot.com/2011/05/security-advisory-to-websites-using.html\n $ax_values = openid_extract_namespace($response, OPENID_NS_AX, 'ax', TRUE);\n\n if (!empty($sreg_values['nickname'])) {\n // Use the nickname returned by Simple Registration if available.\n $form['account']['name']['#default_value'] = $sreg_values['nickname'];\n }\n elseif ($ax_name_values = openid_extract_ax_values($ax_values, array('http://axschema.org/namePerson/friendly', 'http://schema.openid.net/namePerson/friendly'))) {\n // Else, use the first nickname returned by AX if available.\n $form['account']['name']['#default_value'] = current($ax_name_values);\n }\n else {\n $form['account']['name']['#default_value'] = '';\n }\n\n if (!empty($sreg_values['email'])) {\n // Use the email returned by Simple Registration if available.\n $form['account']['mail']['#default_value'] = $sreg_values['email'];\n }\n elseif ($ax_mail_values = openid_extract_ax_values($ax_values, array('http://axschema.org/contact/email', 'http://schema.openid.net/contact/email'))) {\n // Else, use the first nickname returned by AX if available.\n $form['account']['mail']['#default_value'] = current($ax_mail_values);\n }\n\n // If user_email_verification is off, hide the password field and just fill\n // with random password to avoid confusion.\n if (!variable_get('user_email_verification', TRUE)) {\n $form['account']['pass']['#type'] = 'hidden';\n $form['account']['pass']['#value'] = user_password();\n }\n\n $form['openid_claimed_id'] = array(\n '#type' => 'value',\n '#default_value' => $response['openid.claimed_id'],\n );\n $form['openid_display'] = array(\n '#type' => 'item',\n '#title' => t('Your OpenID'),\n '#description' => t('This OpenID will be attached to your account after registration.'),\n '#markup' => check_plain($response['openid.claimed_id']),\n );\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dddfeac8c1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_cron/7.x", "instruction": "I need the code for `search_cron()` in Drupal 7 (modules/search/search.module). It must do this: Implements hook_cron().", "context": "Fires hook_update_index() in all modules and cleans up dirty words.\n\nFile: modules/search/search.module", "response": "function search_cron() {\n // We register a shutdown function to ensure that search_total is always up\n // to date.\n drupal_register_shutdown_function('search_update_totals');\n\n foreach (variable_get('search_active_modules', array('node', 'user')) as $module) {\n // Update word index\n module_invoke($module, 'update_index');\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-de173e24a3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.admin.inc/function/contact_category_edit_form/7.x", "instruction": "I need the code for `contact_category_edit_form($form, &$form_state, array $category = array())` in Drupal 7 (modules/contact/contact.admin.inc). It must do this: Form constructor for the category edit form.", "context": "Parameters:\n- $category: An array describing the category to be edited. May be empty for new categories. Recognized array keys are: - category: The name of the category. - recipients: A comma-separated list of recipients. - reply: (optional) The body of the auto-reply message. - weight: The weight of the category. - selected: Boolean indicating whether the category should be selected by default. - cid: The category ID for which the form is to be displayed.\n\nFile: modules/contact/contact.admin.inc", "response": "function contact_category_edit_form($form, &$form_state, array $category = array()) {\n // If this is a new category, add the default values.\n $category += array(\n 'category' => '',\n 'recipients' => '',\n 'reply' => '',\n 'weight' => 0,\n 'selected' => 0,\n 'cid' => NULL,\n );\n\n $form['category'] = array(\n '#type' => 'textfield',\n '#title' => t('Category'),\n '#maxlength' => 255,\n '#default_value' => $category['category'],\n '#description' => t(\"Example: 'website feedback' or 'product information'.\"),\n '#required' => TRUE,\n );\n $form['recipients'] = array(\n '#type' => 'textarea',\n '#title' => t('Recipients'),\n '#default_value' => $category['recipients'],\n '#description' => t(\"Example: 'webmaster@example.com' or 'sales@example.com,support@example.com' . To specify multiple recipients, separate each e-mail address with a comma.\"),\n '#required' => TRUE,\n );\n $form['reply'] = array(\n '#type' => 'textarea',\n '#title' => t('Auto-reply'),\n '#default_value' => $category['reply'],\n '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),\n );\n $form['weight'] = array(\n '#type' => 'weight',\n '#title' => t('Weight'),\n '#default_value' => $category['weight'],\n '#description' => t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'),\n );\n $form['selected'] = array(\n '#type' => 'select',\n '#title' => t('Selected'),\n '#options' => array(\n 0 => t('No'),\n 1 => t('Yes'),\n ),\n '#default_value' => $category['selected'],\n '#description' => t('Set this to Yes if you would like this category to be selected by default.'),\n );\n $form['cid'] = array(\n '#type' => 'value',\n '#value' => $category['cid'],\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-de42862d0e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/l/7.x", "instruction": "In Drupal 7, write the function `l($text, $path, array $options = array())` (file includes/common.inc) so that it does the following: Formats an internal or external URL link as an HTML anchor tag.", "context": "This function correctly handles aliased paths and adds an 'active' class attribute to links that point to the current page (for theming), so all internal links output by modules should be generated by this function if possible.\n\nHowever, for links enclosed in translatable text you should use t() and embed the HTML anchor tag directly in the translated string. For example:\n\nParameters:\n- $text (string): The translated link text for the anchor tag.\n- $path (string): The internal path or external URL being linked to, such as \"node/34\" or \"http://example.com/foo\". After the url() function is called to construct the URL from $path and $options, the resulting URL is passed through check_plain() before it is inserted into the HTML anchor tag, to ensure well-formed HTML. See url() for more information and notes.\n- $options (array): An associative array of additional options. Defaults to an empty array. It may contain the following elements. - 'attributes': An associative array of HTML attributes to apply to the anchor tag. If element 'class' is included, it must be an array; 'title' must be a string; other elements are more flexible, as they just need to work in a call to drupal_attributes($options['attributes']). - 'html' (default FALSE): Whether $text is HTML or just plain-text. For example, to make an image tag into a link, this must be set to TRUE, or you will see the escaped HTML image tag. $text is not sanitized if 'html' is TRUE. The calling function must ensure that $text is already safe. - 'language': An optional language object. If the path being linked to is internal to the site, $options['language'] is used to determine whether the link is \"active\", or pointing to the current page (the language as well as the path must match). This element is also used by url(). - Additional $options elements used by the url() function.\n\nReturns (string): An HTML string containing a link to the given path.\n\nFile: includes/common.inc", "response": "function l($text, $path, array $options = array()) {\n global $language_url;\n static $use_theme = NULL;\n\n // Merge in defaults.\n $options += array(\n 'attributes' => array(),\n 'html' => FALSE,\n );\n\n // Append active class.\n if (($path == $_GET['q'] || ($path == '' && drupal_is_front_page())) &&\n (empty($options['language']) || $options['language']->language == $language_url->language)) {\n $options['attributes']['class'][] = 'active';\n }\n\n // Remove all HTML and PHP tags from a tooltip. For best performance, we act only\n // if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).\n if (isset($options['attributes']['title']) && strpos($options['attributes']['title'], '<') !== FALSE) {\n $options['attributes']['title'] = strip_tags($options['attributes']['title']);\n }\n\n // Determine if rendering of the link is to be done with a theme function\n // or the inline default. Inline is faster, but if the theme system has been\n // loaded and a module or theme implements a preprocess or process function\n // or overrides the theme_link() function, then invoke theme(). Preliminary\n // benchmarks indicate that invoking theme() can slow down the l() function\n // by 20% or more, and that some of the link-heavy Drupal pages spend more\n // than 10% of the total page request time in the l() function.\n if (!isset($use_theme) && function_exists('theme')) {\n // Allow edge cases to prevent theme initialization and force inline link\n // rendering.\n if (variable_get('theme_link', TRUE)) {\n drupal_theme_initialize();\n $registry = theme_get_registry(FALSE);\n // We don't want to duplicate functionality that's in theme(), so any\n // hint of a module or theme doing anything at all special with the 'link'\n // theme hook should simply result in theme() being called. This includes\n // the overriding of theme_link() with an alternate function or template,\n // the presence of preprocess or process functions, or the presence of\n // include files.\n $use_theme = !isset($registry['link']['function']) || ($registry['link']['function'] != 'theme_link');\n $use_theme = $use_theme || !empty($registry['link']['preprocess functions']) || !empty($registry['link']['process functions']) || !empty($registry['link']['includes']);\n }\n else {\n $use_theme = FALSE;\n }\n }\n $path = (string) $path;\n // For backwards compatibility, do not strip a couple of specific javascript\n // paths that are harmless.\n // @see https://www.drupal.org/project/drupal/issues/3310081\n $skip_js_paths = array('javascript:void()', 'javascript:void();', 'javascript:void(0)', 'javascript:void(0);');\n if (!in_array(strtolower($path), $skip_js_paths)) {\n $path = drupal_strip_dangerous_protocols($path);\n }\n if ($use_theme) {\n return theme('link', array('text' => $text, 'path' => $path, 'options' => $options));\n }\n // The result of url() is a plain-text URL. Because we are using it here\n // in an HTML argument context, we need to encode it properly.\n return '' . ($options['html'] ? $text : check_plain($text)) . '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-de5387d723", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_settings/7.x", "instruction": "I need the code for `ajax_command_settings($argument, $merge = FALSE)` in Drupal 7 (includes/ajax.inc). It must do this: Creates a Drupal Ajax 'settings' command.", "context": "The 'settings' command instructs the client either to use the given array as the settings for ajax-loaded content or to extend Drupal.settings with the given array, depending on the value of the $merge parameter.\n\nThis command is implemented by Drupal.ajax.prototype.commands.settings() defined in misc/ajax.js.\n\nParameters:\n- $argument: An array of key/value pairs to add to the settings. This will be utilized for all commands after this if they do not include their own settings array.\n- $merge: Whether or not the passed settings in $argument should be merged into the global Drupal.settings on the page. By default (FALSE), the settings that are passed to Drupal.attachBehaviors will not include the global Drupal.settings.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_settings($argument, $merge = FALSE) {\n return array(\n 'command' => 'settings',\n 'settings' => $argument,\n 'merge' => $merge,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-de7869be9a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_role/7.x", "instruction": "In Drupal 7, write the function `user_admin_role($form, $form_state, $role)` (file modules/user/user.admin.inc) so that it does the following: Form to configure a single role.", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_role($form, $form_state, $role) {\n if ($role->rid == DRUPAL_ANONYMOUS_RID || $role->rid == DRUPAL_AUTHENTICATED_RID) {\n drupal_goto('admin/people/permissions/roles');\n }\n\n // Display the edit role form.\n $form['name'] = array(\n '#type' => 'textfield',\n '#title' => t('Role name'),\n '#default_value' => $role->name,\n '#size' => 30,\n '#required' => TRUE,\n '#maxlength' => 64,\n '#description' => t('The name for this role. Example: \"moderator\", \"editorial board\", \"site architect\".'),\n );\n $form['rid'] = array(\n '#type' => 'value',\n '#value' => $role->rid,\n );\n $form['weight'] = array(\n '#type' => 'value',\n '#value' => $role->weight,\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save role'),\n );\n $form['actions']['delete'] = array(\n '#type' => 'submit',\n '#value' => t('Delete role'),\n '#submit' => array('user_admin_role_delete_submit'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dea9ebe7d9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/path_delete/7.x", "instruction": "Implement `path_delete($criteria)` in PHP for Drupal 7. Required behavior: Delete a URL alias.", "context": "Parameters:\n- $criteria: A number representing the pid or an array of criteria.\n\nFile: includes/path.inc", "response": "function path_delete($criteria) {\n if (!is_array($criteria)) {\n $criteria = array('pid' => $criteria);\n }\n $path = path_load($criteria);\n if (isset($path['source'])) {\n $query = db_delete('url_alias');\n foreach ($criteria as $field => $value) {\n $query->condition($field, $value);\n }\n $query->execute();\n module_invoke_all('path_delete', $path);\n drupal_clear_path_cache($path['source']);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-debe054f15", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_check_profile/7.x", "instruction": "Implement `drupal_check_profile($profile)` in PHP for Drupal 7. Required behavior: Checks an installation profile's requirements.", "context": "Parameters:\n- $profile: Name of installation profile to check.\n\nReturns (Array): of the installation profile's requirements.\n\nFile: includes/install.inc", "response": "function drupal_check_profile($profile) {\n include_once DRUPAL_ROOT . '/includes/file.inc';\n\n $profile_file = DRUPAL_ROOT . \"/profiles/$profile/$profile.profile\";\n\n if (!isset($profile) || !file_exists($profile_file)) {\n throw new Exception(install_no_profile_error());\n }\n\n $info = install_profile_info($profile);\n\n // Collect requirement testing results.\n $requirements = array();\n foreach ($info['dependencies'] as $module) {\n module_load_install($module);\n $function = $module . '_requirements';\n if (function_exists($function)) {\n $requirements = array_merge($requirements, $function('install'));\n }\n }\n return $requirements;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dec1d52ed0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_modules_enabled/7.x", "instruction": "I need the code for `field_modules_enabled($modules)` in Drupal 7 (modules/field/field.module). It must do this: Implements hook_modules_enabled().", "context": "File: modules/field/field.module", "response": "function field_modules_enabled($modules) {\n // Refresh the 'active' status of fields.\n field_sync_field_status();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ded020e08f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_breadcrumb/7.x", "instruction": "Implement `garland_breadcrumb($variables)` in PHP for Drupal 7. Required behavior: Override of theme_breadcrumb().", "context": "File: themes/garland/template.php", "response": "function garland_breadcrumb($variables) {\n $breadcrumb = $variables['breadcrumb'];\n\n if (!empty($breadcrumb)) {\n // Provide a navigational heading to give context for breadcrumb links to\n // screen-reader users. Make the heading invisible with .element-invisible.\n $output = '

              ' . t('You are here') . '

              ';\n\n $output .= '
              ' . implode(' › ', $breadcrumb) . '
              ';\n return $output;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dee485d46e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.api.php/function/hook_aggregator_process_info/7.x", "instruction": "Give me the example code for `hook_aggregator_process_info()` in Drupal 7. Hook description: Specify the title and short description of your processor.", "context": "The title and the description provided are shown within the configuration page. Use as title the natural name of the processor and as description a brief (40 to 80 characters) explanation of the functionality.\n\nThis hook is only called if your module implements hook_aggregator_process(). If this hook is not implemented aggregator will use your module's file name as title and there will be no description.\n\nReturns: An associative array defining a title and a description string.\n\nFile: modules/aggregator/aggregator.api.php", "response": "function hook_aggregator_process_info() {\n return array(\n 'title' => t('Default processor'),\n 'description' => t('Creates lightweight records of feed items.'),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-dee68caaef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_block_configure/7.x", "instruction": "Implement `aggregator_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().", "context": "File: modules/aggregator/aggregator.module", "response": "function aggregator_block_configure($delta = '') {\n list($type, $id) = explode('-', $delta);\n if ($type == 'category') {\n $value = db_query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchField();\n $form['block'] = array(\n '#type' => 'select',\n '#title' => t('Number of news items in block'),\n '#default_value' => $value,\n '#options' => drupal_map_assoc(range(2, 20)),\n );\n return $form;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-def5260564", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_export_po_form_submit/7.x", "instruction": "In Drupal 7, write the function `locale_translate_export_po_form_submit($form, &$form_state)` (file modules/locale/locale.admin.inc) so that it does the following: Process a translation (or template) export form submission.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_translate_export_po_form_submit($form, &$form_state) {\n // If template is required, language code is not given.\n $language = NULL;\n if (isset($form_state['values']['langcode'])) {\n $languages = language_list();\n $language = $languages[$form_state['values']['langcode']];\n }\n _locale_export_po($language, _locale_export_po_generate($language, _locale_export_get_strings($language, $form_state['values']['group'])));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df0cecd307", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_permission/7.x", "instruction": "I need the code for `shortcut_permission()` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Implements hook_permission().", "context": "File: modules/shortcut/shortcut.module", "response": "function shortcut_permission() {\n return array(\n 'administer shortcuts' => array(\n 'title' => t('Administer shortcuts'),\n ),\n 'customize shortcut links' => array(\n 'title' => t('Edit current shortcut set'),\n 'description' => t('Editing the current shortcut set will affect other users if that set has been assigned to or selected by other users. Granting \"Select any shortcut set\" permission along with this permission will grant permission to edit any shortcut set.'),\n ),\n 'switch shortcut sets' => array(\n 'title' => t('Select any shortcut set'),\n 'description' => t('From all shortcut sets, select one to be own active set. Without this permission, an administrator selects shortcut sets for users.'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-df1ba606c0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21token.inc/function/token_replace/7.x", "instruction": "I need the code for `token_replace($text, array $data = array(), array $options = array())` in Drupal 7 (includes/token.inc). It must do this: Replaces all tokens in a given string with appropriate values.", "context": "Parameters:\n- $text: A string potentially containing replaceable tokens.\n- $data: (optional) An array of keyed objects. For simple replacement scenarios 'node', 'user', and others are common keys, with an accompanying node or user object being the value. Some token types, like 'site', do not require any explicit information from $data and can be replaced even if it is empty.\n- $options: (optional) A keyed array of settings and flags to control the token replacement process. Supported options are: - language: A language object to be used when generating locale-sensitive tokens. - callback: A callback function that will be used to post-process the array of token replacements after they are generated. For example, a module using tokens in a text-only email might provide a callback to strip HTML entities from token values before they are inserted into the final text. - clear: A boolean flag indicating that tokens should be removed from the final text if no replacement value can be generated. - sanitize: A boolean flag indicating that tokens should be sanitized for display to a web browser. Defaults to TRUE. Developers who set this option to FALSE assume responsibility for running filter_xss(), check_plain() or other appropriate scrubbing functions before displaying data to users.\n\nReturns: Text with tokens replaced.\n\nFile: includes/token.inc", "response": "function token_replace($text, array $data = array(), array $options = array()) {\n $text_tokens = token_scan($text);\n if (empty($text_tokens)) {\n return $text;\n }\n\n $replacements = array();\n foreach ($text_tokens as $type => $tokens) {\n $replacements += token_generate($type, $tokens, $data, $options);\n if (!empty($options['clear'])) {\n $replacements += array_fill_keys($tokens, '');\n }\n }\n\n // Optionally alter the list of replacement values.\n if (!empty($options['callback']) && function_exists($options['callback'])) {\n $function = $options['callback'];\n $function($replacements, $data, $options);\n }\n\n $tokens = array_keys($replacements);\n $values = array_values($replacements);\n\n return str_replace($tokens, $values, $text);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df22b1e08d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_match_path/7.x", "instruction": "Implement `drupal_match_path($path, $patterns)` in PHP for Drupal 7. Required behavior: Check if a path matches any pattern in a set of patterns.", "context": "Parameters:\n- $path: The path to match.\n- $patterns: String containing a set of patterns separated by \\n, \\r or \\r\\n.\n\nReturns (Boolean): value: TRUE if the path matches a pattern, FALSE otherwise.\n\nFile: includes/path.inc", "response": "function drupal_match_path($path, $patterns) {\n $regexps = &drupal_static(__FUNCTION__);\n\n if (!isset($regexps[$patterns])) {\n // Convert path settings to a regular expression.\n // Therefore replace newlines with a logical or, /* with asterisks and the with the frontpage.\n $to_replace = array(\n '/(\\r\\n?|\\n)/', // newlines\n '/\\\\\\\\\\*/', // asterisks\n '/(^|\\|)\\\\\\\\($|\\|)/' // \n );\n $replacements = array(\n '|',\n '.*',\n '\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2'\n );\n $patterns_quoted = preg_quote($patterns, '/');\n $regexps[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';\n }\n return (bool)preg_match($regexps[$patterns], $path);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df22eb2849", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_view_alter/7.x", "instruction": "Give me the example code for `hook_entity_view_alter(&$build, $type)` in Drupal 7. Hook description: Alter the results of ENTITY_view().", "context": "This hook is called after the content has been assembled in a structured array and may be used for doing processing which requires that the complete entity content structure has been built.\n\nIf a module wishes to act on the rendered HTML of the entity rather than the structured content array, it may use this hook to add a #post_render callback. Alternatively, it could also implement hook_preprocess_ENTITY(). See drupal_render() and theme() for details.\n\nParameters:\n- $build: A renderable array representing the entity content.\n- $type: The type of entity being rendered (i.e. node, user, comment).\n\nFile: modules/system/system.api.php", "response": "function hook_entity_view_alter(&$build, $type) {\n if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {\n // Change its weight.\n $build['an_additional_field']['#weight'] = -10;\n\n // Add a #post_render callback to act on the rendered HTML of the entity.\n $build['#post_render'][] = 'my_module_node_post_render';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-df2d4a9939", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_form_access_denied/7.x", "instruction": "I need the code for `filter_form_access_denied($element)` in Drupal 7 (modules/filter/filter.module). It must do this: Render API callback: Hides the field value of 'text_format' elements.", "context": "To not break form processing and previews if a user does not have access to a stored text format, the expanded form elements in filter_process_format() are forced to take over the stored #default_values for 'value' and 'format'. However, to prevent the unfiltered, original #value from being displayed to the user, we replace it with a friendly notice here.\n\nFile: modules/filter/filter.module", "response": "function filter_form_access_denied($element) {\n $element['#value'] = t('This field has been disabled because you do not have sufficient permissions to edit it.');\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df40fecfa2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_fields/7.x", "instruction": "I need the code for `field_info_fields()` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns all field definitions.", "context": "Use of this function should be avoided when possible, since it loads and statically caches a potentially large array of information. Use field_info_field_map() instead.\n\nWhen iterating over the fields present in a given bundle after a call to field_info_instances($entity_type, $bundle), it is recommended to use field_info_field() on each individual field instead.\n\nReturns: An array of field definitions, keyed by field name. Each field has an additional property, 'bundles', which is an array of all the bundles to which this field belongs keyed by entity type.\n\nFile: modules/field/field.info.inc", "response": "function field_info_fields() {\n $cache = _field_info_field_cache();\n $info = $cache->getFields();\n\n $fields = array();\n foreach ($info as $key => $field) {\n if (!$field['deleted']) {\n $fields[$field['field_name']] = $field;\n }\n }\n\n return $fields;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df700f0426", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_block_info/7.x", "instruction": "Implement `profile_block_info()` in PHP for Drupal 7. Required behavior: Implements hook_block_info().", "context": "File: modules/profile/profile.module", "response": "function profile_block_info() {\n $blocks['author-information']['info'] = t('Author information');\n $blocks['author-information']['cache'] = DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE;\n return $blocks;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-df75f7f155", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.pages.inc/function/poll_results/7.x", "instruction": "Implement `poll_results($node)` in PHP for Drupal 7. Required behavior: Callback for the 'results' tab for polls you can vote on", "context": "File: modules/poll/poll.pages.inc", "response": "function poll_results($node) {\n drupal_set_title($node->title);\n $node->show_results = TRUE;\n return node_show($node);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df7e1be768", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_file_scan_write_cache/7.x", "instruction": "In Drupal 7, write the function `drupal_file_scan_write_cache()` (file includes/bootstrap.inc) so that it does the following: Writes the file scan cache to the persistent cache.", "context": "This cache stores all files marked as missing or moved after a file scan to prevent unnecessary file scans in subsequent requests. This cache is cleared in system_list_reset() (i.e. after a module/theme rebuild).\n\nFile: includes/bootstrap.inc", "response": "function drupal_file_scan_write_cache() {\n // Only write to the persistent cache if requested, and if we know that any\n // data previously in the cache was successfully loaded and merged in by\n // _drupal_file_scan_cache().\n $file_scans = &_drupal_file_scan_cache();\n if (isset($file_scans['#write_cache']) && isset($file_scans['#cache_merge_done'])) {\n unset($file_scans['#write_cache']);\n cache_set('_drupal_file_scan_cache', $file_scans, 'cache_bootstrap');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df7f4e5a85", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_path_initialize/7.x", "instruction": "Implement `drupal_path_initialize()` in PHP for Drupal 7. Required behavior: Initialize the $_GET['q'] variable to the proper normal path.", "context": "File: includes/path.inc", "response": "function drupal_path_initialize() {\n // Ensure $_GET['q'] is set before calling drupal_normal_path(), to support\n // path caching with hook_url_inbound_alter().\n if (empty($_GET['q'])) {\n $_GET['q'] = variable_get('site_frontpage', 'node');\n }\n $_GET['q'] = drupal_get_normal_path($_GET['q']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df8ddbb7bd", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_export_pot_form/7.x", "instruction": "In Drupal 7, write the function `locale_translate_export_pot_form()` (file modules/locale/locale.admin.inc) so that it does the following: Translation template export form.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_translate_export_pot_form() {\n // Complete template export of the strings\n $form['export_title'] = array('#type' => 'item',\n '#title' => t('Export template'),\n '#description' => t('Generate a Gettext Portable Object Template (.pot) file with all strings from the Drupal locale database.'),\n );\n $form['group'] = array('#type' => 'radios',\n '#title' => t('Text group'),\n '#default_value' => 'default',\n '#options' => module_invoke_all('locale', 'groups'),\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Export'));\n // Reuse PO export submission callback.\n $form['#submit'][] = 'locale_translate_export_po_form_submit';\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-df926e68e7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_permission/7.x", "instruction": "Implement `dashboard_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_permission() {\n return array(\n 'access dashboard' => array(\n 'title' => t('View the administrative dashboard'),\n // Note: We translate the 'Administer blocks' permission string here with\n // a separate t() call, to make sure it gets the same translation as when\n // it's in block_permission().\n 'description' => t('Customizing the dashboard requires the !permission-name permission.', array(\n '!permission-name' => l(t('Administer blocks'), 'admin/people/permissions', array('fragment' => 'module-block')),\n )),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-dfda5c180f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21update.inc/function/update_retrieve_dependencies/7.x", "instruction": "I need the code for `update_retrieve_dependencies()` in Drupal 7 (includes/update.inc). It must do this: Invokes hook_update_dependencies() in all installed modules.", "context": "This function is similar to module_invoke_all(), with the main difference that it does not require that a module be enabled to invoke its hook, only that it be installed. This allows the update system to properly perform updates even on modules that are currently disabled.\n\nReturns: An array of return values obtained by merging the results of the hook_update_dependencies() implementations in all installed modules.\n\nFile: includes/update.inc", "response": "function update_retrieve_dependencies() {\n $return = array();\n // Get a list of installed modules, arranged so that we invoke their hooks in\n // the same order that module_invoke_all() does.\n $modules = db_query(\"SELECT name FROM {system} WHERE type = 'module' AND schema_version <> :schema ORDER BY weight ASC, name ASC\", array(':schema' => SCHEMA_UNINSTALLED))->fetchCol();\n foreach ($modules as $module) {\n $function = $module . '_update_dependencies';\n if (function_exists($function)) {\n $result = $function();\n // Each implementation of hook_update_dependencies() returns a\n // multidimensional, associative array containing some keys that\n // represent module names (which are strings) and other keys that\n // represent update function numbers (which are integers). We cannot use\n // array_merge_recursive() to properly merge these results, since it\n // treats strings and integers differently. Therefore, we have to\n // explicitly loop through the expected array structure here and perform\n // the merge manually.\n if (isset($result) && is_array($result)) {\n foreach ($result as $module => $module_data) {\n foreach ($module_data as $update => $update_data) {\n foreach ($update_data as $module_dependency => $update_dependency) {\n // If there are redundant dependencies declared for the same\n // update function (so that it is declared to depend on more than\n // one update from a particular module), record the dependency on\n // the highest numbered update here, since that automatically\n // implies the previous ones. For example, if one module's\n // implementation of hook_update_dependencies() required this\n // ordering:\n //\n // system_update_7001 ---> user_update_7000\n //\n // but another module's implementation of the hook required this\n // one:\n //\n // system_update_7002 ---> user_update_7000\n //\n // we record the second one, since system_update_7001() is always\n // guaranteed to run before system_update_7002() anyway (within\n // an individual module, updates are always run in numerical\n // order).\n if (!isset($return[$module][$update][$module_dependency]) || $update_dependency > $return[$module][$update][$module_dependency]) {\n $return[$module][$update][$module_dependency] = $update_dependency;\n }\n }\n }\n }\n }\n }\n }\n\n return $return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dfe743e113", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.install/function/profile_update_7001/7.x", "instruction": "In Drupal 7, write the function `profile_update_7001()` (file modules/profile/profile.install) so that it does the following: Rename {profile_fields} table to {profile_field} and {profile_values} to {profile_value}.", "context": "File: modules/profile/profile.install", "response": "function profile_update_7001() {\n db_rename_table('profile_fields', 'profile_field');\n db_rename_table('profile_values', 'profile_value');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-dff0b52f01", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/theme_shortcut_set_customize/7.x", "instruction": "In Drupal 7, write the function `theme_shortcut_set_customize($variables)` (file modules/shortcut/shortcut.admin.inc) so that it does the following: Returns HTML for a shortcut set customization form.", "context": "Parameters:\n- $variables: An associative array containing: - form: A render element representing the form.\n\nFile: modules/shortcut/shortcut.admin.inc", "response": "function theme_shortcut_set_customize($variables) {\n $form = $variables['form'];\n $map = array('disabled' => t('Disabled'), 'enabled' => t('Enabled'));\n $shortcuts_by_status = array(\n 'enabled' => element_children($form['shortcuts']['enabled']),\n 'disabled' => element_children($form['shortcuts']['disabled']),\n );\n // Do not add any rows to the table if there are no shortcuts to display.\n $statuses = empty($shortcuts_by_status['enabled']) && empty($shortcuts_by_status['disabled']) ? array() : array_keys($shortcuts_by_status);\n\n $rows = array();\n foreach ($statuses as $status) {\n drupal_add_tabledrag('shortcuts', 'match', 'sibling', 'shortcut-status-select');\n drupal_add_tabledrag('shortcuts', 'order', 'sibling', 'shortcut-weight');\n $rows[] = array(\n 'data' => array(array(\n 'colspan' => 5,\n 'data' => '' . $map[$status] . '',\n )),\n 'class' => array('shortcut-status', 'shortcut-status-' . $status),\n );\n\n foreach ($shortcuts_by_status[$status] as $key) {\n $shortcut = &$form['shortcuts'][$status][$key];\n $row = array();\n $row[] = drupal_render($shortcut['name']);\n $row[] = drupal_render($shortcut['weight']);\n $row[] = drupal_render($shortcut['status']);\n $row[] = drupal_render($shortcut['edit']);\n $row[] = drupal_render($shortcut['delete']);\n $rows[] = array(\n 'data' => $row,\n 'class' => array('draggable'),\n );\n }\n\n if ($status == 'enabled') {\n for ($i = 0; $i < shortcut_max_slots(); $i++) {\n $rows['empty-' . $i] = array(\n 'data' => array(array(\n 'colspan' => 5,\n 'data' => '' . t('Empty') . '',\n )),\n 'class' => array('shortcut-slot-empty'),\n );\n }\n $count_shortcuts = count($shortcuts_by_status[$status]);\n if (!empty($count_shortcuts)) {\n for ($i = 0; $i < min($count_shortcuts, shortcut_max_slots()); $i++) {\n $rows['empty-' . $i]['class'][] = 'shortcut-slot-hidden';\n }\n }\n }\n }\n\n $header = array(t('Name'), t('Weight'), t('Status'), array('data' => t('Operations'), 'colspan' => 2));\n $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'shortcuts'), 'empty' => t('No shortcuts available. Add a shortcut.', array('@link' => url('admin/config/user-interface/shortcut/' . $form['#shortcut_set_name'] . '/add-link')))));\n $output .= drupal_render($form['actions']);\n $output = drupal_render_children($form) . $output;\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e016ae846b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.api.php/function/hook_path_insert/7.x", "instruction": "Give me the example code for `hook_path_insert($path)` in Drupal 7. Hook description: Respond to a path being inserted.", "context": "Parameters:\n- $path: An associative array containing the following keys: - source: The internal system path. - alias: The URL alias. - pid: Unique path alias identifier. - language: The language of the alias.\n\nFile: modules/path/path.api.php", "response": "function hook_path_insert($path) {\n db_insert('mytable')\n ->fields(array(\n 'alias' => $path['alias'],\n 'pid' => $path['pid'],\n ))\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e01b20b96a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_box/7.x", "instruction": "I need the code for `search_box($form, &$form_state, $form_id)` in Drupal 7 (modules/search/search.module). It must do this: Form builder; Output a search form for the search block's search box.", "context": "File: modules/search/search.module", "response": "function search_box($form, &$form_state, $form_id) {\n $form[$form_id] = array(\n '#type' => 'textfield',\n '#title' => t('Search'),\n '#title_display' => 'invisible',\n '#size' => 15,\n '#default_value' => '',\n '#attributes' => array('title' => t('Enter the terms you wish to search for.')),\n );\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search'));\n $form['#submit'][] = 'search_box_form_submit';\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e027433d21", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/dblog_init/7.x", "instruction": "In Drupal 7, write the function `dblog_init()` (file modules/dblog/dblog.module) so that it does the following: Implements hook_init().", "context": "File: modules/dblog/dblog.module", "response": "function dblog_init() {\n if (arg(0) == 'admin' && arg(1) == 'reports') {\n // Add the CSS for this module\n drupal_add_css(drupal_get_path('module', 'dblog') . '/dblog.css');\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e029606de0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_get_filename_fallback/7.x", "instruction": "I need the code for `_drupal_get_filename_fallback($type, $name, $trigger_error, $database_unavailable)` in Drupal 7 (includes/bootstrap.inc). It must do this: Performs a cached file system scan as a fallback when searching for a file.", "context": "This function looks for the requested file by triggering a file scan, caching the new location if the file has moved and caching the miss if the file is missing. If a file had been marked as missing in a previous file scan, or if it has been marked as moved and is still in the last known location, no new file scan will be performed.\n\nParameters:\n- $type (string): The type of the item (theme, theme_engine, module, profile).\n- $name (string): The name of the item for which the filename is requested.\n- $trigger_error (bool): Whether to trigger an error when a file is missing or has unexpectedly moved.\n- $database_unavailable (bool): Whether this function is being called because the Drupal database could not be queried for the file's location.\n\nReturns: The filename of the requested item or NULL if the item is not found.\n\nFile: includes/bootstrap.inc", "response": "function _drupal_get_filename_fallback($type, $name, $trigger_error, $database_unavailable) {\n $file_scans = &_drupal_file_scan_cache();\n $filename = NULL;\n\n // If the cache indicates that the item is missing, or we can verify that the\n // item exists in the location the cache says it exists in, use that.\n if (isset($file_scans[$type][$name]) && ($file_scans[$type][$name] === FALSE || file_exists($file_scans[$type][$name]))) {\n $filename = $file_scans[$type][$name];\n }\n // Otherwise, perform a new file scan to find the item.\n else {\n $filename = _drupal_get_filename_perform_file_scan($type, $name);\n // Update the static cache, and mark the persistent cache for updating at\n // the end of the page request. See drupal_file_scan_write_cache().\n $file_scans[$type][$name] = $filename;\n $file_scans['#write_cache'] = TRUE;\n }\n\n // If requested, trigger a user-level warning about the missing or\n // unexpectedly moved file. If the database was unavailable, do not trigger a\n // warning in the latter case, though, since if the {system} table could not\n // be queried there is no way to know if the location found here was\n // \"unexpected\" or not.\n if ($trigger_error) {\n $error_type = $filename === FALSE ? 'missing' : 'moved';\n if ($error_type == 'missing' || !$database_unavailable) {\n _drupal_get_filename_fallback_trigger_error($type, $name, $error_type);\n }\n }\n\n // The cache stores FALSE for files that aren't found (to be able to\n // distinguish them from files that have not yet been searched for), but\n // drupal_get_filename() expects NULL for these instead, so convert to NULL\n // before returning.\n if ($filename === FALSE) {\n $filename = NULL;\n }\n return $filename;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e04046e2e0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_details/7.x", "instruction": "Give me the example code for `hook_field_storage_details($field)` in Drupal 7. Hook description: Reveal the internal details about the storage for a field.", "context": "For example, an SQL storage module might return the Schema API structure for the table. A key/value storage module might return the server name, authentication credentials, and bin name.\n\nField storage modules are not obligated to implement this hook. Modules that rely on these details must only use them for read operations.\n\nParameters:\n- $field: A field structure.\n\nReturns: An array of details. - The first dimension is a store type (sql, solr, etc). - The second dimension indicates the age of the values in the store FIELD_LOAD_CURRENT or FIELD_LOAD_REVISION. - Other dimensions are specific to the field storage module.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_details($field) {\n $details = array();\n\n // Add field columns.\n foreach ((array) $field['columns'] as $column_name => $attributes) {\n $real_name = _field_sql_storage_columnname($field['field_name'], $column_name);\n $columns[$column_name] = $real_name;\n }\n return array(\n 'sql' => array(\n FIELD_LOAD_CURRENT => array(\n _field_sql_storage_tablename($field) => $columns,\n ),\n FIELD_LOAD_REVISION => array(\n _field_sql_storage_revision_tablename($field) => $columns,\n ),\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e0641063ee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_html/7.x", "instruction": "Implement `ajax_command_html($selector, $html, $settings = NULL)` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'insert/html' command.", "context": "The 'insert/html' command instructs the client to use jQuery's html() method to set the HTML content of each element matched by the given selector while leaving the outer tags intact.\n\nThis command is implemented by Drupal.ajax.prototype.commands.insert() defined in misc/ajax.js.\n\nParameters:\n- $selector: A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL.\n- $html: The data to use with the jQuery html() method.\n- $settings: An optional array of settings that will be used for this command only.\n\nReturns: An array suitable for use with the ajax_render() function.\n\nFile: includes/ajax.inc", "response": "function ajax_command_html($selector, $html, $settings = NULL) {\n return array(\n 'command' => 'insert',\n 'method' => 'html',\n 'selector' => $selector,\n 'data' => $html,\n 'settings' => $settings,\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e078162c9d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/update_parse_xml/7.x", "instruction": "I need the code for `update_parse_xml($raw_xml)` in Drupal 7 (modules/update/update.fetch.inc). It must do this: Parses the XML of the Drupal release history info files.", "context": "Parameters:\n- $raw_xml: A raw XML string of available release data for a given project.\n\nReturns (Array): of parsed data about releases for a given project, or NULL if there was an error parsing the string.\n\nFile: modules/update/update.fetch.inc", "response": "function update_parse_xml($raw_xml) {\n try {\n $xml = new SimpleXMLElement($raw_xml);\n }\n catch (Exception $e) {\n // SimpleXMLElement::__construct produces an E_WARNING error message for\n // each error found in the XML data and throws an exception if errors\n // were detected. Catch any exception and return failure (NULL).\n return;\n }\n // If there is no valid project data, the XML is invalid, so return failure.\n if (!isset($xml->short_name)) {\n return;\n }\n $short_name = (string) $xml->short_name;\n $data = array();\n foreach ($xml as $k => $v) {\n $data[$k] = (string) $v;\n }\n $data['releases'] = array();\n if (isset($xml->releases)) {\n foreach ($xml->releases->children() as $release) {\n $version = (string) $release->version;\n $data['releases'][$version] = array();\n foreach ($release->children() as $k => $v) {\n $data['releases'][$version][$k] = (string) $v;\n }\n $data['releases'][$version]['terms'] = array();\n if ($release->terms) {\n foreach ($release->terms->children() as $term) {\n if (!isset($data['releases'][$version]['terms'][(string) $term->name])) {\n $data['releases'][$version]['terms'][(string) $term->name] = array();\n }\n $data['releases'][$version]['terms'][(string) $term->name][] = (string) $term->value;\n }\n }\n }\n }\n return $data;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e08173295e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_view_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_node_view_alter(&$build)` (modules/node/node.api.php): Alter the results of node_view().", "context": "This hook is called after the content has been assembled in a structured array and may be used for doing processing which requires that the complete node content structure has been built.\n\nIf the module wishes to act on the rendered HTML of the node rather than the structured content array, it may use this hook to add a #post_render callback. Alternatively, it could also implement hook_preprocess_node(). See drupal_render() and theme() documentation respectively for details.\n\nParameters:\n- $build: A renderable array representing the node content.\n\nFile: modules/node/node.api.php", "response": "function hook_node_view_alter(&$build) {\n if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {\n // Change its weight.\n $build['an_additional_field']['#weight'] = -10;\n }\n\n // Add a #post_render callback to act on the rendered HTML of the node.\n $build['#post_render'][] = 'my_module_node_post_render';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e0821465d5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_delete_field/7.x", "instruction": "Implement `field_delete_field($field_name)` in PHP for Drupal 7. Required behavior: Marks a field and its instances and data for deletion.", "context": "Parameters:\n- $field_name: The field name to delete.\n\nFile: modules/field/field.crud.inc", "response": "function field_delete_field($field_name) {\n // Delete all non-deleted instances.\n $field = field_info_field($field_name);\n if (isset($field['bundles'])) {\n foreach ($field['bundles'] as $entity_type => $bundles) {\n foreach ($bundles as $bundle) {\n $instance = field_info_instance($entity_type, $field_name, $bundle);\n field_delete_instance($instance, FALSE);\n }\n }\n }\n\n // Mark field data for deletion.\n module_invoke($field['storage']['module'], 'field_storage_delete_field', $field);\n\n // Mark the field for deletion.\n db_update('field_config')\n ->fields(array('deleted' => 1))\n ->condition('field_name', $field_name)\n ->execute();\n\n // Clear the cache.\n field_cache_clear();\n\n module_invoke_all('field_delete_field', $field);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e0d10dfdfe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_is_anonymous/7.x", "instruction": "In Drupal 7, write the function `user_is_anonymous()` (file modules/user/user.module) so that it does the following: Determines if the current user is anonymous.", "context": "Returns (bool): TRUE if the user is anonymous, FALSE if the user is authenticated.\n\nFile: modules/user/user.module", "response": "function user_is_anonymous() {\n // Menu administrators can see items for anonymous when administering.\n return !$GLOBALS['user']->uid || !empty($GLOBALS['menu_admin']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e0d47a94a7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_field_extra_fields/7.x", "instruction": "Implement `user_field_extra_fields()` in PHP for Drupal 7. Required behavior: Implements hook_field_extra_fields().", "context": "File: modules/user/user.module", "response": "function user_field_extra_fields() {\n $return['user']['user'] = array(\n 'form' => array(\n 'account' => array(\n 'label' => t('User name and password'),\n 'description' => t('User module account form elements.'),\n 'weight' => -10,\n ),\n 'timezone' => array(\n 'label' => t('Timezone'),\n 'description' => t('User module timezone form element.'),\n 'weight' => 6,\n ),\n ),\n 'display' => array(\n 'summary' => array(\n 'label' => t('History'),\n 'description' => t('User module history view element.'),\n 'weight' => 5,\n ),\n ),\n );\n\n return $return;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e0d8be60bb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_rmdir/7.x", "instruction": "I need the code for `drupal_rmdir($uri, $context = NULL)` in Drupal 7 (includes/file.inc). It must do this: Removes a directory.", "context": "PHP's rmdir() is broken on Windows, as it can fail to remove a directory when it has a read-only flag set.\n\nParameters:\n- $uri: A URI or pathname.\n- $context: Refer to http://php.net/manual/ref.stream.php\n\nReturns (Boolean): TRUE on success, or FALSE on failure.\n\nFile: includes/file.inc", "response": "function drupal_rmdir($uri, $context = NULL) {\n $scheme = file_uri_scheme($uri);\n if ((!$scheme || !file_stream_wrapper_valid_scheme($scheme)) && (substr(PHP_OS, 0, 3) == 'WIN')) {\n chmod($uri, 0700);\n }\n if ($context) {\n return rmdir($uri, $context);\n }\n else {\n return rmdir($uri);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e0d94aa3a1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/flood_clear_event/7.x", "instruction": "I need the code for `flood_clear_event($name, $identifier = NULL)` in Drupal 7 (includes/common.inc). It must do this: Makes the flood control mechanism forget an event for the current visitor.", "context": "Parameters:\n- $name: The name of an event.\n- $identifier: Optional identifier (defaults to the current user's IP address).\n\nFile: includes/common.inc", "response": "function flood_clear_event($name, $identifier = NULL) {\n if (!isset($identifier)) {\n $identifier = ip_address();\n }\n db_delete('flood')\n ->condition('event', $name)\n ->condition('identifier', $identifier)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e0e95c7721", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7005/7.x", "instruction": "Implement `user_update_7005(&$sandbox)` in PHP for Drupal 7. Required behavior: Changes the users table to allow longer e-mail addresses.", "context": "File: modules/user/user.install", "response": "function user_update_7005(&$sandbox) {\n $mail_field = array(\n 'type' => 'varchar',\n 'length' => 254,\n 'not null' => FALSE,\n 'default' => '',\n 'description' => \"User's e-mail address.\",\n );\n $init_field = array(\n 'type' => 'varchar',\n 'length' => 254,\n 'not null' => FALSE,\n 'default' => '',\n 'description' => 'E-mail address used for initial account creation.',\n );\n db_drop_index('users', 'mail');\n db_change_field('users', 'mail', 'mail', $mail_field, array('indexes' => array('mail' => array('mail'))));\n db_change_field('users', 'init', 'init', $init_field);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e13b12a068", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_validate/7.x", "instruction": "In Drupal 7, write the function `forum_node_validate($node, $form)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_validate().", "context": "Checks in particular that the node is assigned only a \"leaf\" term in the forum taxonomy.\n\nFile: modules/forum/forum.module", "response": "function forum_node_validate($node, $form) {\n if (_forum_node_check_node_type($node)) {\n $langcode = $form['taxonomy_forums']['#language'];\n // vocabulary is selected, not a \"container\" term.\n if (!empty($node->taxonomy_forums[$langcode])) {\n // Extract the node's proper topic ID.\n $containers = variable_get('forum_containers', array());\n foreach ($node->taxonomy_forums[$langcode] as $delta => $item) {\n // If no term was selected (e.g. when no terms exist yet), remove the\n // item.\n if (empty($item['tid'])) {\n unset($node->taxonomy_forums[$langcode][$delta]);\n continue;\n }\n $term = taxonomy_term_load($item['tid']);\n if (!$term) {\n form_set_error('taxonomy_forums', t('Select a forum.'));\n continue;\n }\n $used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid',0 , 1, array(\n ':tid' => $term->tid,\n ':vid' => $term->vid,\n ))->fetchField();\n if ($used && in_array($term->tid, $containers)) {\n form_set_error('taxonomy_forums', t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->name)));\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e13fc1d779", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_taxonomy_vocabulary_update/7.x", "instruction": "In Drupal 7, write the function `taxonomy_taxonomy_vocabulary_update($vocabulary)` (file modules/taxonomy/taxonomy.module) so that it does the following: Implements hook_taxonomy_vocabulary_update().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_taxonomy_vocabulary_update($vocabulary) {\n // Reflect machine name changes in the definitions of existing 'taxonomy'\n // fields.\n if (!empty($vocabulary->old_machine_name) && $vocabulary->old_machine_name != $vocabulary->machine_name) {\n $fields = field_read_fields();\n foreach ($fields as $field_name => $field) {\n $update = FALSE;\n if ($field['type'] == 'taxonomy_term_reference') {\n foreach ($field['settings']['allowed_values'] as $key => &$value) {\n if ($value['vocabulary'] == $vocabulary->old_machine_name) {\n $value['vocabulary'] = $vocabulary->machine_name;\n $update = TRUE;\n }\n }\n if ($update) {\n field_update_field($field);\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e15cb448e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21pager.inc/function/theme_pager/7.x", "instruction": "Implement `theme_pager($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a query pager.", "context": "Menu callbacks that display paged query results should call theme('pager') to retrieve a pager control so that users can view other results. Format a list of nearby pages with additional query results.\n\nParameters:\n- $variables: An associative array containing: - tags: An array of labels for the controls in the pager. - element: An optional integer to distinguish between multiple pagers on one page. - parameters: An associative array of query string parameters to append to the pager links. - quantity: The number of pages in the list.\n\nFile: includes/pager.inc", "response": "function theme_pager($variables) {\n $tags = $variables['tags'];\n $element = $variables['element'];\n $parameters = $variables['parameters'];\n $quantity = empty($variables['quantity']) ? 0 : $variables['quantity'];\n global $pager_page_array, $pager_total;\n\n // Nothing to do if there is no pager.\n if (!isset($pager_page_array[$element]) || !isset($pager_total[$element])) {\n return;\n }\n\n // Nothing to do if there is only one page.\n if ($pager_total[$element] <= 1) {\n return;\n }\n\n // Calculate various markers within this pager piece:\n // Middle is used to \"center\" pages around the current page.\n $pager_middle = ceil($quantity / 2);\n // current is the page we are currently paged to\n $pager_current = $pager_page_array[$element] + 1;\n // first is the first page listed by this pager piece (re quantity)\n $pager_first = $pager_current - $pager_middle + 1;\n // last is the last page listed by this pager piece (re quantity)\n $pager_last = $pager_current + $quantity - $pager_middle;\n // max is the maximum page number\n $pager_max = $pager_total[$element];\n // End of marker calculations.\n\n // Prepare for generation loop.\n $i = $pager_first;\n if ($pager_last > $pager_max) {\n // Adjust \"center\" if at end of query.\n $i = $i + ($pager_max - $pager_last);\n $pager_last = $pager_max;\n }\n if ($i <= 0) {\n // Adjust \"center\" if at start of query.\n $pager_last = $pager_last + (1 - $i);\n $i = 1;\n }\n // End of generation loop preparation.\n\n $li_first = theme('pager_first', array('text' => (isset($tags[0]) ? $tags[0] : t('« first')), 'element' => $element, 'parameters' => $parameters));\n $li_previous = theme('pager_previous', array('text' => (isset($tags[1]) ? $tags[1] : t('‹ previous')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));\n $li_next = theme('pager_next', array('text' => (isset($tags[3]) ? $tags[3] : t('next ›')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));\n $li_last = theme('pager_last', array('text' => (isset($tags[4]) ? $tags[4] : t('last »')), 'element' => $element, 'parameters' => $parameters));\n\n if ($pager_total[$element] > 1) {\n if ($li_first) {\n $items[] = array(\n 'class' => array('pager-first'),\n 'data' => $li_first,\n );\n }\n if ($li_previous) {\n $items[] = array(\n 'class' => array('pager-previous'),\n 'data' => $li_previous,\n );\n }\n\n // When there is more than one page, create the pager list.\n if ($i != $pager_max) {\n if ($i > 1) {\n $items[] = array(\n 'class' => array('pager-ellipsis'),\n 'data' => '…',\n );\n }\n // Now generate the actual pager piece.\n for (; $i <= $pager_last && $i <= $pager_max; $i++) {\n if ($i < $pager_current) {\n $items[] = array(\n 'class' => array('pager-item'),\n 'data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => ($pager_current - $i), 'parameters' => $parameters)),\n );\n }\n if ($i == $pager_current) {\n $items[] = array(\n 'class' => array('pager-current'),\n 'data' => $i,\n );\n }\n if ($i > $pager_current) {\n $items[] = array(\n 'class' => array('pager-item'),\n 'data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => ($i - $pager_current), 'parameters' => $parameters)),\n );\n }\n }\n if ($i < $pager_max) {\n $items[] = array(\n 'class' => array('pager-ellipsis'),\n 'data' => '…',\n );\n }\n }\n // End generation.\n if ($li_next) {\n $items[] = array(\n 'class' => array('pager-next'),\n 'data' => $li_next,\n );\n }\n if ($li_last) {\n $items[] = array(\n 'class' => array('pager-last'),\n 'data' => $li_last,\n );\n }\n return '

              ' . t('Pages') . '

              ' . theme('item_list', array(\n 'items' => $items,\n 'attributes' => array('class' => array('pager')),\n ));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e16eb96763", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.pages.inc/function/profile_browse/7.x", "instruction": "I need the code for `profile_browse()` in Drupal 7 (modules/profile/profile.pages.inc). It must do this: Menu callback; display a list of user information.", "context": "File: modules/profile/profile.pages.inc", "response": "function profile_browse() {\n // Ensure that the path is converted to 3 levels always.\n list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');\n\n $field = db_query(\"SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_field} WHERE name = :name\", array(':name' => $name))->fetchObject();\n\n if ($name && $field->fid) {\n // Only allow browsing of fields that have a page title set.\n if (empty($field->page)) {\n return MENU_NOT_FOUND;\n }\n // Do not allow browsing of private and hidden fields by non-admins.\n if (!user_access('administer users') && ($field->visibility == PROFILE_PRIVATE || $field->visibility == PROFILE_HIDDEN)) {\n return MENU_ACCESS_DENIED;\n }\n\n // Compile a list of fields to show.\n $fields = db_query('SELECT name, title, type, weight, page, visibility FROM {profile_field} WHERE fid <> :fid AND visibility = :visibility ORDER BY weight', array(\n ':fid' => $field->fid,\n ':visibility' => PROFILE_PUBLIC_LISTINGS,\n ))->fetchAll();\n\n $query = db_select('users', 'u')->extend('PagerDefault');\n $query->join('profile_value', 'v', 'u.uid = v.uid');\n $query\n ->fields('u', array('uid', 'access'))\n ->condition('v.fid', $field->fid)\n ->condition('u.status', 0, '<>')\n ->orderBy('u.access', 'DESC');\n\n // Determine what query to use:\n $arguments = array($field->fid);\n switch ($field->type) {\n case 'checkbox':\n $query->condition('v.value', 1);\n break;\n case 'textfield':\n case 'selection':\n $query->condition('v.value', $value);\n break;\n case 'list':\n $query->condition('v.value', '%' . db_like($value) . '%', 'LIKE');\n break;\n default:\n return MENU_NOT_FOUND;\n }\n\n $uids = $query\n ->limit(20)\n ->execute()\n ->fetchCol();\n\n // Load the users.\n $users = user_load_multiple($uids);\n\n $content = '';\n foreach ($users as $account) {\n $profile = _profile_update_user_fields($fields, $account);\n $content .= theme('profile_listing', array('account' => $account, 'fields' => $profile));\n }\n $output = theme('profile_wrapper', array('content' => $content));\n $output .= theme('pager');\n\n if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {\n $title = strtr(check_plain($field->page), array('%value' => drupal_placeholder($value)));\n }\n else {\n $title = check_plain($field->page);\n }\n\n drupal_set_title($title, PASS_THROUGH);\n return $output;\n }\n elseif ($name && !$field->fid) {\n return MENU_NOT_FOUND;\n }\n else {\n // Compile a list of fields to show.\n $fields = db_query('SELECT name, title, type, weight, page, visibility FROM {profile_field} WHERE visibility = :visibility ORDER BY category, weight', array(':visibility' => PROFILE_PUBLIC_LISTINGS))->fetchAll();\n\n // Extract the affected users:\n $query = db_select('users', 'u')->extend('PagerDefault');\n $uids = $query\n ->fields('u', array('uid', 'access'))\n ->condition('u.uid', 0, '>')\n ->condition('u.status', 0, '>')\n ->orderBy('u.access', 'DESC')\n ->limit(20)\n ->execute()\n ->fetchCol();\n $users = user_load_multiple($uids);\n $content = '';\n foreach ($users as $account) {\n $profile = _profile_update_user_fields($fields, $account);\n $content .= theme('profile_listing', array('account' => $account, 'fields' => $profile));\n }\n $output = theme('profile_wrapper', array('content' => $content));\n $output .= theme('pager');\n\n drupal_set_title(t('User list'));\n return $output;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e18f2a03a6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_form_element_label/7.x", "instruction": "Implement `theme_form_element_label($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a form element label and required marker.", "context": "Form element labels include the #title and a #required marker. The label is associated with the element itself by the element #id. Labels may appear before or after elements, depending on theme_form_element() and #title_display.\n\nThis function will not be called for elements with no labels, depending on #title_display. For elements that have an empty #title and are not required, this function will output no label (''). For required elements that have an empty #title, this will output the required marker alone within the label. The label will use the #id to associate the marker with the field that is required. That is especially important for screenreader users to know which field is required.\n\nTo associate the label with a different field, set the #label_for property to the ID of the desired field.\n\nParameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #required, #title, #id, #value, #description, #label_for.\n\nFile: includes/form.inc", "response": "function theme_form_element_label($variables) {\n $element = $variables['element'];\n // This is also used in the installer, pre-database setup.\n $t = get_t();\n\n // If title and required marker are both empty, output no label.\n if ((!isset($element['#title']) || $element['#title'] === '') && empty($element['#required'])) {\n return '';\n }\n\n // If the element is required, a required marker is appended to the label.\n $required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : '';\n\n $title = filter_xss_admin($element['#title']);\n\n $attributes = array();\n // Style the label as class option to display inline with the element.\n if ($element['#title_display'] == 'after') {\n $attributes['class'] = 'option';\n }\n // Show label only to screen readers to avoid disruption in visual flows.\n elseif ($element['#title_display'] == 'invisible') {\n $attributes['class'] = 'element-invisible';\n }\n\n // Use the element's ID as the default value of the \"for\" attribute (to\n // associate the label with this form element), but allow this to be\n // overridden in order to associate the label with a different form element\n // instead.\n if (!empty($element['#label_for'])) {\n $attributes['for'] = $element['#label_for'];\n }\n elseif (!empty($element['#id'])) {\n $attributes['for'] = $element['#id'];\n }\n\n // The leading whitespace helps visually separate fields from inline labels.\n return ' ' . $t('!title !required', array('!title' => $title, '!required' => $required)) . \"\\n\";\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e19e30cc6f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_state_keys_no_cache/7.x", "instruction": "I need the code for `form_state_keys_no_cache()` in Drupal 7 (includes/form.inc). It must do this: Returns an array of $form_state keys that shouldn't be cached.", "context": "File: includes/form.inc", "response": "function form_state_keys_no_cache() {\n return array(\n // Public properties defined by form constructors and form handlers.\n 'always_process',\n 'must_validate',\n 'rebuild',\n 'rebuild_info',\n 'redirect',\n 'no_redirect',\n 'temporary',\n // Internal properties defined by form processing.\n 'buttons',\n 'triggering_element',\n 'clicked_button',\n 'complete form',\n 'groups',\n 'input',\n 'method',\n 'submit_handlers',\n 'submitted',\n 'executed',\n 'validate_handlers',\n 'values',\n );\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e1b9121aef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_node_insert/7.x", "instruction": "I need the code for `taxonomy_node_insert($node)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_node_insert().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_node_insert($node) {\n // Add taxonomy index entries for the node.\n taxonomy_build_node_index($node);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e1c24754fb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_feed_validate/7.x", "instruction": "I need the code for `aggregator_form_feed_validate($form, &$form_state)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Form validation handler for aggregator_form_feed().", "context": "File: modules/aggregator/aggregator.admin.inc", "response": "function aggregator_form_feed_validate($form, &$form_state) {\n if ($form_state['values']['op'] == t('Save')) {\n // Ensure URL is valid.\n if (!valid_url($form_state['values']['url'], TRUE)) {\n form_set_error('url', t('The URL %url is invalid. Enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array('%url' => $form_state['values']['url'])));\n }\n // Check for duplicate titles.\n if (isset($form_state['values']['fid'])) {\n $result = db_query(\"SELECT title, url FROM {aggregator_feed} WHERE (title = :title OR url = :url) AND fid <> :fid\", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url'], ':fid' => $form_state['values']['fid']));\n }\n else {\n $result = db_query(\"SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url\", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url']));\n }\n foreach ($result as $feed) {\n if (strcasecmp($feed->title, $form_state['values']['title']) == 0) {\n form_set_error('title', t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $form_state['values']['title'])));\n }\n if (strcasecmp($feed->url, $form_state['values']['url']) == 0) {\n form_set_error('url', t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $form_state['values']['url'])));\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e1c55dcbd5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_add_default_view_mode_settings/7.x", "instruction": "I need the code for `_field_ui_add_default_view_mode_settings($entity_type, $bundle, $view_mode, &$settings)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Populates display settings for a new view mode from the default view mode.", "context": "When an administrator decides to use custom display settings for a view mode, that view mode needs to be initialized with the display settings for the 'default' view mode, which it was previously using. This helper function adds the new custom display settings to this bundle's instances, and saves them. It also modifies the passed-in $settings array, which the caller can then save using field_bundle_settings().\n\nParameters:\n- $entity_type: The bundle's entity type.\n- $bundle: The bundle whose view mode is being customized.\n- $view_mode: The view mode that the administrator has set to use custom settings.\n- $settings: An associative array of bundle settings, as expected by field_bundle_settings().\n\nFile: modules/field_ui/field_ui.admin.inc", "response": "function _field_ui_add_default_view_mode_settings($entity_type, $bundle, $view_mode, &$settings) {\n // Update display settings for field instances.\n $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle));\n foreach ($instances as $instance) {\n // If this field instance has display settings defined for this view mode,\n // respect those settings.\n if (!isset($instance['display'][$view_mode])) {\n // The instance doesn't specify anything for this view mode, so use the\n // default display settings.\n $instance['display'][$view_mode] = $instance['display']['default'];\n field_update_instance($instance);\n }\n }\n\n // Update display settings for 'extra fields'.\n foreach (array_keys($settings['extra_fields']['display']) as $name) {\n if (!isset($settings['extra_fields']['display'][$name][$view_mode])) {\n $settings['extra_fields']['display'][$name][$view_mode] = $settings['extra_fields']['display'][$name]['default'];\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e1ca305772", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_registry_files_alter/7.x", "instruction": "Implement `simpletest_registry_files_alter(&$files, $modules)` in PHP for Drupal 7. Required behavior: Implements hook_registry_files_alter().", "context": "Add the test files for disabled modules so that we get a list containing all the available tests.\n\nFile: modules/simpletest/simpletest.module", "response": "function simpletest_registry_files_alter(&$files, $modules) {\n foreach ($modules as $module) {\n // Only add test files for disabled modules, as enabled modules should\n // already include any test files they provide.\n if (!$module->status) {\n $dir = $module->dir;\n if (!empty($module->info['files'])) {\n foreach ($module->info['files'] as $file) {\n if (substr($file, -5) == '.test') {\n $files[\"$dir/$file\"] = array('module' => $module->name, 'weight' => $module->weight);\n }\n }\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e1cd09db71", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_node_submit/7.x", "instruction": "Implement `menu_node_submit($node, $form, $form_state)` in PHP for Drupal 7. Required behavior: Implements hook_node_submit().", "context": "File: modules/menu/menu.module", "response": "function menu_node_submit($node, $form, $form_state) {\n // Decompose the selected menu parent option into 'menu_name' and 'plid', if\n // the form used the default parent selection widget.\n if (!empty($form_state['values']['menu']['parent'])) {\n list($node->menu['menu_name'], $node->menu['plid']) = explode(':', $form_state['values']['menu']['parent']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e1dcb1970c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_modules_uninstall_submit/7.x", "instruction": "I need the code for `system_modules_uninstall_submit($form, &$form_state)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Processes the submitted uninstall form.", "context": "File: modules/system/system.admin.inc", "response": "function system_modules_uninstall_submit($form, &$form_state) {\n // Make sure the install API is available.\n include_once DRUPAL_ROOT . '/includes/install.inc';\n\n if (!empty($form['#confirmed'])) {\n // Call the uninstall routine for each selected module.\n $modules = array_keys($form_state['values']['uninstall']);\n drupal_uninstall_modules($modules);\n drupal_set_message(t('The selected modules have been uninstalled.'));\n\n $form_state['redirect'] = 'admin/modules/uninstall';\n }\n else {\n $form_state['storage'] = $form_state['values'];\n $form_state['rebuild'] = TRUE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e1e5f31d28", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/list_themes/7.x", "instruction": "In Drupal 7, write the function `list_themes($refresh = FALSE)` (file includes/theme.inc) so that it does the following: Returns a list of all currently available themes.", "context": "Retrieved from the database, if available and the site is not in maintenance mode; otherwise compiled freshly from the filesystem.\n\nParameters:\n- $refresh: Whether to reload the list of themes from the database. Defaults to FALSE.\n\nReturns: An associative array of the currently available themes. The keys are the themes' machine names and the values are objects having the following properties: - filename: The filepath and name of the .info file. - name: The machine name of the theme. - status: 1 for enabled, 0 for disabled themes. - info: The contents of the .info file. - stylesheets: A two dimensional array, using the first key for the media attribute (e.g. 'all'), the second for the name of the file (e.g. style.css). The value is a complete filepath (e.g. themes/bartik/style.css). Not set if no stylesheets are defined in the .info file. - scripts: An associative array of JavaScripts, using the filename as key and the complete filepath as value. Not set if no scripts are defined in the .info file. - prefix: The base theme engine prefix. - engine: The machine name of the theme engine. - base_theme: If this is a sub-theme, the machine name of the base theme defined in the .info file. Otherwise, the element is not set. - base_themes: If this is a sub-theme, an associative array of the base-theme ancestors of this theme, starting with this theme's base theme, then the base theme's own base theme, etc. Each entry has an array key equal to the theme's machine name, and a value equal to the human-readable theme name; if a theme with matching machine name does not exist in the system, the value will instead be NULL (and since the system would not know whether that theme itself has a base theme, that will end the array of base themes). This is not set if the theme is not a sub-theme. - sub_themes: An associative array of themes on the system that are either direct sub-themes (that is, they declare this theme to be their base theme), direct sub-themes of sub-themes, etc. The keys are the themes' machine names, and the values are the themes' human-readable names. This element is not set if there are no themes on the system that declare this theme as their base theme.\n\nFile: includes/theme.inc", "response": "function list_themes($refresh = FALSE) {\n $list = &drupal_static(__FUNCTION__, array());\n\n if ($refresh) {\n $list = array();\n system_list_reset();\n }\n\n if (empty($list)) {\n $list = array();\n $themes = array();\n // Extract from the database only when it is available.\n // Also check that the site is not in the middle of an install or update.\n if (!defined('MAINTENANCE_MODE')) {\n try {\n $themes = system_list('theme');\n }\n catch (Exception $e) {\n // If the database is not available, rebuild the theme data.\n $themes = _system_rebuild_theme_data();\n }\n }\n else {\n // Scan the installation when the database should not be read.\n $themes = _system_rebuild_theme_data();\n }\n\n foreach ($themes as $theme) {\n foreach ($theme->info['stylesheets'] as $media => $stylesheets) {\n foreach ($stylesheets as $stylesheet => $path) {\n $theme->stylesheets[$media][$stylesheet] = $path;\n }\n }\n foreach ($theme->info['scripts'] as $script => $path) {\n $theme->scripts[$script] = $path;\n }\n if (isset($theme->info['engine'])) {\n $theme->engine = $theme->info['engine'];\n }\n if (isset($theme->info['base theme'])) {\n $theme->base_theme = $theme->info['base theme'];\n }\n // Status is normally retrieved from the database. Add zero values when\n // read from the installation directory to prevent notices.\n if (!isset($theme->status)) {\n $theme->status = 0;\n }\n $list[$theme->name] = $theme;\n }\n }\n\n return $list;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e21fce0fb9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_user_profile/7.x", "instruction": "Implement `rdf_preprocess_user_profile(&$variables)` in PHP for Drupal 7. Required behavior: Implements MODULE_preprocess_HOOK().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_preprocess_user_profile(&$variables) {\n $account = $variables['elements']['#account'];\n $uri = entity_uri('user', $account);\n\n // Adds RDFa markup to the user profile page. Fields displayed in this page\n // will automatically describe the user.\n if (!empty($account->rdf_mapping['rdftype'])) {\n $variables['attributes_array']['typeof'] = $account->rdf_mapping['rdftype'];\n $variables['attributes_array']['about'] = url($uri['path'], $uri['options']);\n }\n // Adds the relationship between the sioc:UserAccount and the foaf:Person who\n // holds the account.\n $account_holder_meta = array(\n '#tag' => 'meta',\n '#attributes' => array(\n 'about' => url($uri['path'], array_merge($uri['options'], array('fragment' => 'me'))),\n 'typeof' => array('foaf:Person'),\n 'rel' => array('foaf:account'),\n 'resource' => url($uri['path'], $uri['options']),\n ),\n );\n // Adds the markup for username.\n $username_meta = array(\n '#tag' => 'meta',\n '#attributes' => array(\n 'about' => url($uri['path'], $uri['options']),\n 'property' => $account->rdf_mapping['name']['predicates'],\n 'content' => $account->name,\n )\n );\n drupal_add_html_head($account_holder_meta, 'rdf_user_account_holder');\n drupal_add_html_head($username_meta, 'rdf_user_username');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e22c85eae5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.admin.inc/function/path_admin_edit/7.x", "instruction": "In Drupal 7, write the function `path_admin_edit($path = array())` (file modules/path/path.admin.inc) so that it does the following: Page callback: Returns a form creating or editing a path alias.", "context": "Parameters:\n- $path: An array containing the path ID, source, alias, and language code.\n\nReturns: A form for adding or editing a URL alias.\n\nFile: modules/path/path.admin.inc", "response": "function path_admin_edit($path = array()) {\n if ($path) {\n drupal_set_title($path['alias']);\n $output = drupal_get_form('path_admin_form', $path);\n }\n else {\n $output = drupal_get_form('path_admin_form');\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e2379cd5f6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21unicode.inc/function/mime_header_encode/7.x", "instruction": "In Drupal 7, write the function `mime_header_encode($string)` (file includes/unicode.inc) so that it does the following: Encodes MIME/HTTP header values that contain incorrectly encoded characters.", "context": "For example, mime_header_encode('tést.txt') returns \"=?UTF-8?B?dMOpc3QudHh0?=\".\n\nSee http://www.rfc-editor.org/rfc/rfc2047.txt for more information.\n\nNotes:\n- Only encode strings that contain non-ASCII characters.\n- We progressively cut-off a chunk with truncate_utf8(). This is to ensure\n each chunk starts and ends on a character boundary.\n- Using \\n as the chunk separator may cause problems on some systems and may\n have to be changed to \\r\\n or \\r.\n\nParameters:\n- $string: The header to encode.\n\nReturns (string): The mime-encoded header.\n\nFile: includes/unicode.inc", "response": "function mime_header_encode($string) {\n if (preg_match('/[^\\x20-\\x7E]/', $string)) {\n $chunk_size = 47; // floor((75 - strlen(\"=?UTF-8?B??=\")) * 0.75);\n $len = strlen($string);\n $output = '';\n while ($len > 0) {\n $chunk = drupal_truncate_bytes($string, $chunk_size);\n $output .= ' =?UTF-8?B?' . base64_encode($chunk) . \"?=\\n\";\n $c = strlen($chunk);\n $string = substr($string, $c);\n $len -= $c;\n }\n return trim($output);\n }\n return $string;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e25e586e3c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_display_overview_multistep_js/7.x", "instruction": "I need the code for `field_ui_display_overview_multistep_js($form, &$form_state)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Ajax handler for multistep buttons on the 'Manage display' screen.", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_display_overview_multistep_js($form, &$form_state) {\n $trigger = $form_state['triggering_element'];\n $op = $trigger['#op'];\n\n // Pick the elements that need to receive the ajax-new-content effect.\n switch ($op) {\n case 'edit':\n $updated_rows = array($trigger['#field_name']);\n $updated_columns = array('format');\n break;\n\n case 'update':\n case 'cancel':\n $updated_rows = array($trigger['#field_name']);\n $updated_columns = array('format', 'settings_summary', 'settings_edit');\n break;\n\n case 'refresh_table':\n $updated_rows = array_values(explode(' ', $form_state['values']['refresh_rows']));\n $updated_columns = array('settings_summary', 'settings_edit');\n break;\n }\n\n foreach ($updated_rows as $name) {\n foreach ($updated_columns as $key) {\n $element = &$form['fields'][$name][$key];\n $element['#prefix'] = '
              ' . (isset($element['#prefix']) ? $element['#prefix'] : '');\n $element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] : '') . '
              ';\n }\n }\n\n // Return the whole table.\n return $form['fields'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e2601d05aa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_page_build/7.x", "instruction": "Give me the example code for `hook_page_build(&$page)` in Drupal 7. Hook description: Add elements to a page before it is rendered.", "context": "Use this hook when you want to add elements at the page level. For your additions to be printed, they have to be placed below a top level array key of the $page array that has the name of a region of the active theme.\n\nBy default, valid region keys are 'page_top', 'header', 'sidebar_first', 'content', 'sidebar_second' and 'page_bottom'. To get a list of all regions of the active theme, use system_region_list($theme). Note that $theme is a global variable.\n\nIf you want to alter the elements added by other modules or if your module depends on the elements of other modules, use hook_page_alter() instead which runs after this hook.\n\nParameters:\n- $page: Nested array of renderable elements that make up the page.\n\nFile: modules/system/system.api.php", "response": "function hook_page_build(&$page) {\n if (menu_get_object('node', 1)) {\n // We are on a node detail page. Append a standard disclaimer to the\n // content region.\n $page['content']['disclaimer'] = array(\n '#markup' => t('Acme, Inc. is not responsible for the contents of this sample code.'),\n '#weight' => 25,\n );\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e2631a7d1a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/_rdf_mapping_load/7.x", "instruction": "I need the code for `_rdf_mapping_load($type, $bundle)` in Drupal 7 (modules/rdf/rdf.module). It must do this: Helper function to retrieve an RDF mapping from the database.", "context": "Parameters:\n- $type: The entity type the mapping refers to.\n- $bundle: The bundle the mapping refers to.\n\nReturns: An RDF mapping structure or an empty array if no record was found.\n\nFile: modules/rdf/rdf.module", "response": "function _rdf_mapping_load($type, $bundle) {\n $mappings = _rdf_mapping_load_multiple($type, array($bundle));\n return $mappings ? reset($mappings) : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e270a6cca6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_update_field/7.x", "instruction": "Give me the example code for `hook_field_update_field($field, $prior_field, $has_data)` in Drupal 7. Hook description: Act on a field being updated.", "context": "This hook is invoked just after field is updated in field_update_field().\n\nParameters:\n- $field: The field as it is post-update.\n- $prior_field: The field as it was pre-update.\n- $has_data: Whether any data already exists for this field.\n\nFile: modules/field/field.api.php", "response": "function hook_field_update_field($field, $prior_field, $has_data) {\n // Reset the static value that keeps track of allowed values for list fields.\n drupal_static_reset('list_allowed_values');\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e2d84de5b2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_widget_info/7.x", "instruction": "I need the code for `text_field_widget_info()` in Drupal 7 (modules/field/modules/text/text.module). It must do this: Implements hook_field_widget_info().", "context": "File: modules/field/modules/text/text.module", "response": "function text_field_widget_info() {\n return array(\n 'text_textfield' => array(\n 'label' => t('Text field'),\n 'field types' => array('text'),\n 'settings' => array('size' => 60),\n ),\n 'text_textarea' => array(\n 'label' => t('Text area (multiple rows)'),\n 'field types' => array('text_long'),\n 'settings' => array('rows' => 5),\n ),\n 'text_textarea_with_summary' => array(\n 'label' => t('Text area with a summary'),\n 'field types' => array('text_with_summary'),\n 'settings' => array('rows' => 20, 'summary_rows' => 5),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e2eb58416c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_info_alter(&$info)` (modules/field/field.api.php): Perform alterations on Field API field types.", "context": "Parameters:\n- $info: Array of information on field types exposed by hook_field_info() implementations.\n\nFile: modules/field/field.api.php", "response": "function hook_field_info_alter(&$info) {\n // Add a setting to all field types.\n foreach ($info as $field_type => $field_type_info) {\n $info[$field_type]['settings'] += array(\n 'mymodule_additional_setting' => 'default value',\n );\n }\n\n // Change the default widget for fields of type 'foo'.\n if (isset($info['foo'])) {\n $info['foo']['default widget'] = 'mymodule_widget';\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e323244a06", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_cron/7.x", "instruction": "Implement `openid_cron()` in PHP for Drupal 7. Required behavior: Remove expired nonces from the database.", "context": "Implements hook_cron().\n\nFile: modules/openid/openid.module", "response": "function openid_cron() {\n db_delete('openid_nonce')\n ->condition('expires', REQUEST_TIME, '<')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e329f734d1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x", "instruction": "Give me the example code for `hook_menu()` in Drupal 7. Hook description: Define menu items and page callbacks.", "context": "This hook enables modules to register paths in order to define how URL requests are handled. Paths may be registered for URL handling only, or they can register a link to be placed in a menu (usually the Navigation menu). A path and its associated information is commonly called a \"menu router item\". This hook is rarely called (for example, when modules are enabled), and its results are cached in the database.\n\nhook_menu() implementations return an associative array whose keys define paths and whose values are an associative array of properties for each path. (The complete list of properties is in the return value section below.)\n\nReturns: An array of menu items. Each menu item has a key corresponding to the Drupal path being registered. The corresponding array value is an associative array that may contain the following key-value pairs: - \"title\": Required. The untranslated title of the menu item. - \"title callback\": Function to generate the title; defaults to t(). If you require only the raw string to be output, set this to FALSE. - \"title arguments\": Arguments to send to t() or your custom callback, with path component substitution as described above. - \"description\": The untranslated description of the menu item. - \"page callback\": The function to call to display a web page when the user visits the path. If omitted, the parent menu item's callback will be used instead. - \"page arguments\": An array of arguments to pass to the page callback function, with path component substitution as described above. - \"delivery callback\": The function to call to package the result of the page callback function and send it to the browser. Defaults to drupal_deliver_html_page() unless a value is inherited from a parent menu item. Note that this function is called even if the access checks fail, so any custom delivery callback function should take that into account. See drupal_deliver_html_page() for an example. - \"access callback\": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user_access() unless a value is inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks. To use the user_access() default callback, you must specify the permission to check as 'access arguments' (see below). - \"access arguments\": An array of arguments to pass to the access callback function, with path component substitution as described above. If the access callback is inherited (see above), the access arguments will be inherited with it, unless overridden in the child menu item. - \"theme callback\": (optional) A function returning the machine-readable name of the theme that will be used to render the page. If not provided, the value will be inherited from a parent menu item. If there is no theme callback, or if the function does not return the name of a current active theme on the site, the theme for this page will be determined by either hook_custom_theme() or the default theme instead. As a general rule, the use of theme callback functions should be limited to pages whose functionality is very closely tied to a particular theme, since they can only be overridden by modules which specifically target those pages in hook_menu_alter(). Modules implementing more generic theme switching functionality (for example, a module which allows the theme to be set dynamically based on the current user's role) should use hook_custom_theme() instead. - \"theme arguments\": An array of arguments to pass to the theme callback function, with path component substitution as described above. - \"file\": A file that will be included before the page callback is called; this allows page callback functions to be in separate files. The file should be relative to the implementing module's directory unless otherwise specified by the \"file path\" option. Does not apply to other callbacks (only page callback). - \"file path\": The path to the directory containing the file specified in \"file\". This defaults to the path to the module implementing the hook. - \"load arguments\": An array of arguments to be passed to each of the wildcard object loaders in the path, after the path argument itself. For example, if a module registers path node/%node/revisions/%/view with load arguments set to array(3), the '%node' in the path indicates that the loader function node_load() will be called with the second path component as the first argument. The 3 in the load arguments indicates that the fourth path component will also be passed to node_load() (numbering of path components starts at zero). So, if path node/12/revisions/29/view is requested, node_load(12, 29) will be called. There are also two \"magic\" values that can be used in load arguments. \"%index\" indicates the index of the wildcard path component. \"%map\" indicates the path components as an array. For example, if a module registers for several paths of the form 'user/%user_category/edit/*', all of them can use the same load function user_category_load(), by setting the load arguments to array('%map', '%index'). For instance, if the user is editing category 'foo' by requesting path 'user/32/edit/foo', the load function user_category_load() will be called with 32 as its first argument, the array ('user', 32, 'edit', 'foo') as the map argument, and 1 as the index argument (because %user_category is the second path component and numbering starts at zero). user_category_load() can then use these values to extract the information that 'foo' is the category being requested. - \"weight\": An integer that determines the relative position of items in the menu; higher-weighted items sink. Defaults to 0. Menu items with the same weight are ordered alphabetically. - \"menu_name\": Optional. Set this to a custom menu if you don't want your item to be placed in Navigation. - \"expanded\": Optional. If set to TRUE, and if a menu link is provided for this menu item (as a result of other properties), then the menu link is always expanded, equivalent to its 'always expanded' checkbox being set in the UI. - \"context\": (optional) Defines the context a tab may appear in. By default, all tabs are only displayed as local tasks when being rendered in a page context. All tabs that should be accessible as contextual links in page region containers outside of the parent menu item's primary page context should be registered using one of the following contexts: - MENU_CONTEXT_PAGE: (default) The tab is displayed as local task for the page context only. - MENU_CONTEXT_INLINE: The tab is displayed as contextual link outside of the primary page context only. Contexts can be combined. For example, to display a tab both on a page and inline, a menu router item may specify: @code 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, @endcode - \"tab_parent\": For local task menu items, the path of the task's parent item; defaults to the same path without the last component (e.g., the default parent for 'admin/people/create' is 'admin/people'). - \"tab_root\": For local task menu items, the path of the closest non-tab item; same default as \"tab_parent\". - \"position\": Position of the block ('left' or 'right') on the system administration page for this item. - \"type\": A bitmask of flags describing properties of the menu item. Many shortcut bitmasks are provided as constants in menu.inc: - MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be moved/hidden by the administrator. - MENU_CALLBACK: Callbacks simply register a path so that the correct information is generated when the path is accessed. - MENU_SUGGESTED_ITEM: Modules may \"suggest\" menu items that the administrator may enable. - MENU_LOCAL_ACTION: Local actions are menu items that describe actions on the parent item such as adding a new user or block, and are rendered in the action-links list in your theme. - MENU_LOCAL_TASK: Local tasks are menu items that describe different displays of data, and are generally rendered as tabs. - MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one \"default\" task, which should display the same page as the parent item. If the \"type\" element is omitted, MENU_NORMAL_ITEM is assumed. - \"options\": An array of options to be passed to l() when generating a link from this menu item. Note that the \"options\" parameter has no effect on MENU_LOCAL_TASK, MENU_DEFAULT_LOCAL_TASK, and MENU_LOCAL_ACTION items. For a detailed usage example, see page_example.module. For comprehensive documentation on the menu system, see http://drupal.org/node/102338.\n\nFile: modules/system/system.api.php", "response": "function hook_menu() {\n $items['example'] = array(\n 'title' => 'Example Page',\n 'page callback' => 'example_page',\n 'access arguments' => array('access content'),\n 'type' => MENU_SUGGESTED_ITEM,\n );\n $items['example/feed'] = array(\n 'title' => 'Example RSS feed',\n 'page callback' => 'example_feed',\n 'access arguments' => array('access content'),\n 'type' => MENU_CALLBACK,\n );\n\n return $items;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e32ce9fc1b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_custom_block_delete_submit/7.x", "instruction": "In Drupal 7, write the function `block_custom_block_delete_submit($form, &$form_state)` (file modules/block/block.admin.inc) so that it does the following: Form submission handler for block_custom_block_delete().", "context": "File: modules/block/block.admin.inc", "response": "function block_custom_block_delete_submit($form, &$form_state) {\n db_delete('block_custom')\n ->condition('bid', $form_state['values']['bid'])\n ->execute();\n db_delete('block')\n ->condition('module', 'block')\n ->condition('delta', $form_state['values']['bid'])\n ->execute();\n db_delete('block_role')\n ->condition('module', 'block')\n ->condition('delta', $form_state['values']['bid'])\n ->execute();\n drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['info'])));\n cache_clear_all();\n $form_state['redirect'] = 'admin/structure/block';\n return;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e33367d348", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_link_translate/7.x", "instruction": "In Drupal 7, write the function `_menu_link_translate(&$item, $translate = FALSE)` (file includes/menu.inc) so that it does the following: Provides menu link access control, translation, and argument handling.", "context": "This function is similar to _menu_translate(), but it also does link-specific preparation (such as always calling to_arg() functions).\n\nParameters:\n- $item: A menu link.\n- $translate: (optional) Whether to try to translate a link containing dynamic path argument placeholders (%) based on the menu router item of the current path. Defaults to FALSE. Internally used for breadcrumbs.\n\nReturns: Returns the map of path arguments with objects loaded as defined in the $item['load_functions']. $item['access'] becomes TRUE if the item is accessible, FALSE otherwise. $item['href'] is generated from link_path, possibly by to_arg functions. $item['title'] is generated from link_title, and may be localized. $item['options'] is unserialized; it is also changed within the call here to $item['localized_options'] by _menu_item_localize().\n\nFile: includes/menu.inc", "response": "function _menu_link_translate(&$item, $translate = FALSE) {\n if (!is_array($item['options'])) {\n $item['options'] = unserialize($item['options']);\n }\n if ($item['external']) {\n $item['access'] = 1;\n $map = array();\n $item['href'] = $item['link_path'];\n $item['title'] = $item['link_title'];\n $item['localized_options'] = $item['options'];\n }\n else {\n // Complete the path of the menu link with elements from the current path,\n // if it contains dynamic placeholders (%).\n $map = explode('/', $item['link_path']);\n if (strpos($item['link_path'], '%') !== FALSE) {\n // Invoke registered to_arg callbacks.\n if (!empty($item['to_arg_functions'])) {\n _menu_link_map_translate($map, $item['to_arg_functions']);\n }\n // Or try to derive the path argument map from the current router item,\n // if this $item's path is within the router item's path. This means\n // that if we are on the current path 'foo/%/bar/%/baz', then\n // menu_get_item() will have translated the menu router item for the\n // current path, and we can take over the argument map for a link like\n // 'foo/%/bar'. This inheritance is only valid for breadcrumb links.\n // @see _menu_tree_check_access()\n // @see menu_get_active_breadcrumb()\n elseif ($translate && ($current_router_item = menu_get_item())) {\n // If $translate is TRUE, then this link is in the active trail.\n // Only translate paths within the current path.\n if (strpos($current_router_item['path'], $item['link_path']) === 0) {\n $count = count($map);\n $map = array_slice($current_router_item['original_map'], 0, $count);\n $item['original_map'] = $map;\n if (isset($current_router_item['map'])) {\n $item['map'] = array_slice($current_router_item['map'], 0, $count);\n }\n // Reset access to check it (for the first time).\n unset($item['access']);\n }\n }\n }\n $item['href'] = implode('/', $map);\n\n // Skip links containing untranslated arguments.\n if (strpos($item['href'], '%') !== FALSE) {\n $item['access'] = FALSE;\n return FALSE;\n }\n // menu_tree_check_access() may set this ahead of time for links to nodes.\n if (!isset($item['access'])) {\n if (!empty($item['load_functions']) && !_menu_load_objects($item, $map)) {\n // An error occurred loading an object.\n $item['access'] = FALSE;\n return FALSE;\n }\n _menu_check_access($item, $map);\n }\n // For performance, don't localize a link the user can't access.\n if ($item['access']) {\n _menu_item_localize($item, $map, TRUE);\n }\n }\n\n // Allow other customizations - e.g. adding a page-specific query string to the\n // options array. For performance reasons we only invoke this hook if the link\n // has the 'alter' flag set in the options array.\n if (!empty($item['options']['alter'])) {\n drupal_alter('translated_menu_link', $item, $map);\n }\n\n return $map;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e345815027", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_release/7.x", "instruction": "Implement `lock_release($name)` in PHP for Drupal 7. Required behavior: Release a lock previously acquired by lock_acquire().", "context": "This will release the named lock if it is still held by the current request.\n\nParameters:\n- $name: The name of the lock.\n\nFile: includes/lock.inc", "response": "function lock_release($name) {\n global $locks;\n\n unset($locks[$name]);\n db_delete('semaphore')\n ->condition('name', $name)\n ->condition('value', _lock_id())\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e353c29960", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_forum_load/7.x", "instruction": "I need the code for `forum_forum_load($tid = NULL)` in Drupal 7 (modules/forum/forum.module). It must do this: Returns a tree of all forums for a given taxonomy term ID.", "context": "Parameters:\n- $tid: (optional) Taxonomy term ID of the forum. If not given all forums will be returned.\n\nReturns: A tree of taxonomy objects, with the following additional properties: - num_topics: Number of topics in the forum. - num_posts: Total number of posts in all topics. - last_post: Most recent post for the forum. - forums: An array of child forums.\n\nFile: modules/forum/forum.module", "response": "function forum_forum_load($tid = NULL) {\n $cache = &drupal_static(__FUNCTION__, array());\n\n // Return a cached forum tree if available.\n if (!isset($tid)) {\n $tid = 0;\n }\n if (isset($cache[$tid])) {\n return $cache[$tid];\n }\n\n $vid = variable_get('forum_nav_vocabulary', 0);\n\n // Load and validate the parent term.\n if ($tid) {\n $forum_term = taxonomy_term_load($tid);\n if (!$forum_term || ($forum_term->vid != $vid)) {\n return $cache[$tid] = FALSE;\n }\n }\n // If $tid is 0, create an empty object to hold the child terms.\n elseif ($tid === 0) {\n $forum_term = (object) array(\n 'tid' => 0,\n );\n }\n\n // Determine if the requested term is a container.\n if (!$forum_term->tid || in_array($forum_term->tid, variable_get('forum_containers', array()))) {\n $forum_term->container = 1;\n }\n\n // Load parent terms.\n $forum_term->parents = taxonomy_get_parents_all($forum_term->tid);\n\n // Load the tree below.\n $forums = array();\n $_forums = taxonomy_get_tree($vid, $tid);\n\n if (count($_forums)) {\n $query = db_select('node', 'n');\n $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');\n $query->join('forum', 'f', 'n.vid = f.vid');\n $query->addExpression('COUNT(n.nid)', 'topic_count');\n $query->addExpression('SUM(ncs.comment_count)', 'comment_count');\n $counts = $query\n ->fields('f', array('tid'))\n ->condition('n.status', 1)\n ->groupBy('tid')\n ->addTag('node_access')\n ->execute()\n ->fetchAllAssoc('tid');\n }\n\n foreach ($_forums as $forum) {\n // Determine if the child term is a container.\n if (in_array($forum->tid, variable_get('forum_containers', array()))) {\n $forum->container = 1;\n }\n\n // Merge in the topic and post counters.\n if (!empty($counts[$forum->tid])) {\n $forum->num_topics = $counts[$forum->tid]->topic_count;\n $forum->num_posts = $counts[$forum->tid]->topic_count + $counts[$forum->tid]->comment_count;\n }\n else {\n $forum->num_topics = 0;\n $forum->num_posts = 0;\n }\n\n // Query \"Last Post\" information for this forum.\n $query = db_select('node', 'n');\n $query->join('users', 'u1', 'n.uid = u1.uid');\n $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $forum->tid));\n $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');\n $query->join('users', 'u2', 'ncs.last_comment_uid = u2.uid');\n $query->addExpression('CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u2.name END', 'last_comment_name');\n\n $topic = $query\n ->fields('ncs', array('last_comment_timestamp', 'last_comment_uid'))\n ->condition('n.status', 1)\n ->orderBy('last_comment_timestamp', 'DESC')\n ->range(0, 1)\n ->addTag('node_access')\n ->execute()\n ->fetchObject();\n\n // Merge in the \"Last Post\" information.\n $last_post = new stdClass();\n if (!empty($topic->last_comment_timestamp)) {\n $last_post->created = $topic->last_comment_timestamp;\n $last_post->name = $topic->last_comment_name;\n $last_post->uid = $topic->last_comment_uid;\n }\n $forum->last_post = $last_post;\n\n $forums[$forum->tid] = $forum;\n }\n\n // Cache the result, and return the tree.\n $forum_term->forums = $forums;\n $cache[$tid] = $forum_term;\n return $forum_term;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e3a3550a1b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.admin.inc/function/contact_category_edit_form_validate/7.x", "instruction": "I need the code for `contact_category_edit_form_validate($form, &$form_state)` in Drupal 7 (modules/contact/contact.admin.inc). It must do this: Form validation handler for contact_category_edit_form().", "context": "File: modules/contact/contact.admin.inc", "response": "function contact_category_edit_form_validate($form, &$form_state) {\n // Validate and each e-mail recipient.\n $recipients = explode(',', $form_state['values']['recipients']);\n\n // When creating a new contact form, or renaming the category on an existing\n // contact form, make sure that the given category is unique.\n $category = $form_state['values']['category'];\n $query = db_select('contact', 'c')->condition('c.category', $category, '=');\n if (!empty($form_state['values']['cid'])) {\n $query->condition('c.cid', $form_state['values']['cid'], '<>');\n }\n if ($query->countQuery()->execute()->fetchField()) {\n form_set_error('category', t('A contact form with category %category already exists.', array('%category' => $category)));\n }\n\n foreach ($recipients as &$recipient) {\n $recipient = trim($recipient);\n if (!valid_email_address($recipient)) {\n form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient)));\n }\n }\n $form_state['values']['recipients'] = implode(',', $recipients);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e3b94afc34", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_discovery_method_info/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_openid_discovery_method_info()` (modules/openid/openid.api.php): Allow modules to declare OpenID discovery methods.", "context": "The discovery function callbacks will be called in turn with an unique\nparameter, the claimed identifier. They have to return an associative array\nwith array of services and claimed identifier in the same form as returned by\nopenid_discover(). The resulting array must contain following keys:\n - 'services' (required) an array of discovered services (including OpenID\n version, endpoint URI, etc).\n - 'claimed_id' (optional) new claimed identifer, found by following HTTP\n redirects during the services discovery.\n\nThe first discovery method that succeed (return at least one services) will stop the discovery process.\n\nReturns: An associative array which keys are the name of the discovery methods and values are function callbacks.\n\nFile: modules/openid/openid.api.php", "response": "function hook_openid_discovery_method_info() {\n return array(\n 'new_discovery_idea' => '_my_discovery_method',\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e40558eb14", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_get_form/7.x", "instruction": "In Drupal 7, write the function `drupal_get_form($form_id)` (file includes/form.inc) so that it does the following: Returns a renderable form array for a given form ID.", "context": "This function should be used instead of drupal_build_form() when $form_state is not needed (i.e., when initially rendering the form) and is often used as a menu callback.\n\nParameters:\n- $form_id: The unique string identifying the desired form. If a function with that name exists, it is called to build the form array. Modules that need to generate the same form (or very similar forms) using different $form_ids can implement hook_forms(), which maps different $form_id values to the proper form constructor function. Examples may be found in node_forms(), and search_forms(). hook_forms() can also be used to define forms in classes.\n\nReturns: The form array.\n\nFile: includes/form.inc", "response": "function drupal_get_form($form_id) {\n $form_state = array();\n\n $args = func_get_args();\n // Remove $form_id from the arguments.\n array_shift($args);\n $form_state['build_info']['args'] = $args;\n\n return drupal_build_form($form_id, $form_state);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e40ca20c6b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_formatter_view/7.x", "instruction": "Implement `file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_view().", "context": "File: modules/file/file.field.inc", "response": "function file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {\n $element = array();\n\n switch ($display['type']) {\n case 'file_default':\n foreach ($items as $delta => $item) {\n $element[$delta] = array(\n '#theme' => 'file_link',\n '#file' => (object) $item,\n );\n }\n break;\n\n case 'file_url_plain':\n foreach ($items as $delta => $item) {\n $element[$delta] = array('#markup' => empty($item['uri']) ? '' : file_create_url($item['uri']));\n }\n break;\n\n case 'file_table':\n if (!empty($items)) {\n // Display all values in a single element..\n $element[0] = array(\n '#theme' => 'file_formatter_table',\n '#items' => $items,\n );\n }\n break;\n }\n\n return $element;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e45592ee90", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_run_tests/7.x", "instruction": "I need the code for `simpletest_run_tests($test_list, $reporter = 'drupal')` in Drupal 7 (modules/simpletest/simpletest.module). It must do this: Actually runs tests.", "context": "Parameters:\n- $test_list: List of tests to run.\n- $reporter: Which reporter to use. Allowed values are: text, xml, html and drupal, drupal being the default.\n\nFile: modules/simpletest/simpletest.module", "response": "function simpletest_run_tests($test_list, $reporter = 'drupal') {\n $test_id = db_insert('simpletest_test_id')\n ->useDefaults(array('test_id'))\n ->execute();\n\n // Clear out the previous verbose files.\n file_unmanaged_delete_recursive('public://simpletest/verbose');\n\n // Get the info for the first test being run.\n $first_test = array_shift($test_list);\n $first_instance = new $first_test();\n array_unshift($test_list, $first_test);\n $info = $first_instance->getInfo();\n\n $batch = array(\n 'title' => t('Running tests'),\n 'operations' => array(\n array('_simpletest_batch_operation', array($test_list, $test_id)),\n ),\n 'finished' => '_simpletest_batch_finished',\n 'progress_message' => '',\n 'css' => array(drupal_get_path('module', 'simpletest') . '/simpletest.css'),\n 'init_message' => t('Processing test @num of @max - %test.', array('%test' => $info['name'], '@num' => '1', '@max' => count($test_list))),\n );\n batch_set($batch);\n\n module_invoke_all('test_group_started');\n\n return $test_id;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e459774e70", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_help/7.x", "instruction": "I need the code for `profile_help($path, $arg)` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_help().", "context": "File: modules/profile/profile.module", "response": "function profile_help($path, $arg) {\n switch ($path) {\n case 'admin/help#profile':\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The Profile module allows site administrators to define custom fields (such as country, full name, or age) for user profiles, which are then displayed in the My Account section. This permits users of a site to share more information about themselves, and can help community-based sites organize users around specific information. For more information, see the online handbook entry for Profile module.', array('@user' => url('user'), '@profile' => 'http://drupal.org/documentation/modules/profile/')) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Adding fields to the default profile') . '
              ';\n $output .= '
              ' . t('To provide the ability for users to enter more information about themselves, the Profile module allows additional fields to be added to the default user profile. Examples of common additions would be Location, Company, Age, or About me.') . '
              ';\n $output .= '
              ' . t('User information pages') . '
              ';\n $output .= '
              ' . t('The Profile module enables links to see further information about site users. You can view both a main User list page, and more specified pages by clicking on linked fields in any profile. For example, the People who live in Canada listing on Drupal.org displays all users who have entered Canada in the Country field on their user profile.', array('@profile' => url('profile'), '@profile-country' => 'http://drupal.org/profile/country/Canada')) . '
              ';\n $output .= '
              ' . t('Author information block') . '
              ';\n $output .= '
              ' . t('The Author information block is a default block created by the Profile module that can be enabled on the Blocks administration page. It shows visitors of your website information about the author of the page they are reading.', array('@blocks' => url('admin/structure/block'))) . '
              ';\n $output .= '
              ';\n return $output;\n case 'admin/config/people/profile':\n return '

              ' . t(\"This page displays a list of the existing custom profile fields to be displayed on a user's My account page. To provide structure, similar or related fields may be placed inside a category. To add a new category (or edit an existing one), edit a profile field and provide a new category name.\") . '

              ';\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e45ddf1455", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21module.inc/function/module_list/7.x", "instruction": "In Drupal 7, write the function `module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL)` (file includes/module.inc) so that it does the following: Returns a list of currently active modules.", "context": "Usually, this returns a list of all enabled modules. When called early on in the bootstrap, it will return a list of vital modules only (those needed to generate cached pages).\n\nAll parameters to this function are optional and should generally not be changed from their defaults.\n\nParameters:\n- $refresh: (optional) Whether to force the module list to be regenerated (such as after the administrator has changed the system settings). Defaults to FALSE.\n- $bootstrap_refresh: (optional) When $refresh is TRUE, setting $bootstrap_refresh to TRUE forces the module list to be regenerated using the reduced set of modules loaded in \"bootstrap mode\" for cached pages. Otherwise, setting $refresh to TRUE generates the complete list of enabled modules.\n- $sort: (optional) By default, modules are ordered by weight and module name. Set this option to TRUE to return a module list ordered only by module name.\n- $fixed_list: (optional) If an array of module names is provided, this will override the module list with the given set of modules. This will persist until the next call with $refresh set to TRUE or with a new $fixed_list passed in. This parameter is primarily intended for internal use (e.g., in install.php and update.php).\n\nReturns: An associative array whose keys and values are the names of the modules in the list.\n\nFile: includes/module.inc", "response": "function module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL) {\n static $list = array(), $sorted_list;\n\n if (empty($list) || $refresh || $fixed_list) {\n $list = array();\n $sorted_list = NULL;\n if ($fixed_list) {\n foreach ($fixed_list as $name => $module) {\n drupal_get_filename('module', $name, $module['filename']);\n $list[$name] = $name;\n }\n }\n else {\n if ($refresh) {\n // For the $refresh case, make sure that system_list() returns fresh\n // data.\n drupal_static_reset('system_list');\n }\n if ($bootstrap_refresh) {\n $list = system_list('bootstrap');\n }\n else {\n // Not using drupal_map_assoc() here as that requires common.inc.\n $list = array_keys(system_list('module_enabled'));\n $list = (!empty($list) ? array_combine($list, $list) : array());\n }\n }\n }\n if ($sort) {\n if (!isset($sorted_list)) {\n $sorted_list = $list;\n ksort($sorted_list);\n }\n return $sorted_list;\n }\n return $list;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e463d11e9b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_mail_alter/7.x", "instruction": "I need the code for `simpletest_mail_alter(&$message)` in Drupal 7 (modules/simpletest/simpletest.module). It must do this: Implements hook_mail_alter().", "context": "Aborts sending of messages with ID 'simpletest_cancel_test'.\n\nFile: modules/simpletest/simpletest.module", "response": "function simpletest_mail_alter(&$message) {\n if ($message['id'] == 'simpletest_cancel_test') {\n $message['send'] = FALSE;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e46e730a03", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_field_attach_rename_bundle/7.x", "instruction": "I need the code for `field_ui_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new)` in Drupal 7 (modules/field_ui/field_ui.module). It must do this: Implements hook_field_attach_rename_bundle().", "context": "File: modules/field_ui/field_ui.module", "response": "function field_ui_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {\n // The Field UI relies on entity_get_info() to build menu items for entity\n // field administration pages. Clear the entity info cache and ensure that\n // the menu is rebuilt.\n entity_info_cache_clear();\n menu_rebuild();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e475211129", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_update/7.x", "instruction": "In Drupal 7, write the function `forum_node_update($node)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_update().", "context": "File: modules/forum/forum.module", "response": "function forum_node_update($node) {\n if (_forum_node_check_node_type($node)) {\n if (empty($node->revision) && db_query('SELECT tid FROM {forum} WHERE nid=:nid', array(':nid' => $node->nid))->fetchField()) {\n if (!empty($node->forum_tid)) {\n db_update('forum')\n ->fields(array('tid' => $node->forum_tid))\n ->condition('vid', $node->vid)\n ->execute();\n }\n // The node is removed from the forum.\n else {\n db_delete('forum')\n ->condition('nid', $node->nid)\n ->execute();\n }\n }\n else {\n if (!empty($node->forum_tid)) {\n db_insert('forum')\n ->fields(array(\n 'tid' => $node->forum_tid,\n 'vid' => $node->vid,\n 'nid' => $node->nid,\n ))\n ->execute();\n }\n }\n // If the node has a shadow forum topic, update the record for this\n // revision.\n if (!empty($node->shadow)) {\n db_delete('forum')\n ->condition('nid', $node->nid)\n ->condition('vid', $node->vid)\n ->execute();\n db_insert('forum')\n ->fields(array(\n 'nid' => $node->nid,\n 'vid' => $node->vid,\n 'tid' => $node->forum_tid,\n ))\n ->execute();\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e48500a2e0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_query/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_storage_query($query)` (modules/field/field.api.php): Execute an EntityFieldQuery.", "context": "This hook is called to find the entities having certain entity and field conditions and sort them in the given field order. If the field storage engine also handles property sorts and orders, it should unset those properties in the called object to signal that those have been handled.\n\nParameters:\n- $query (EntityFieldQuery): An EntityFieldQuery.\n\nReturns: See EntityFieldQuery::execute() for the return values.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_query($query) {\n $groups = array();\n if ($query->age == FIELD_LOAD_CURRENT) {\n $tablename_function = '_field_sql_storage_tablename';\n $id_key = 'entity_id';\n }\n else {\n $tablename_function = '_field_sql_storage_revision_tablename';\n $id_key = 'revision_id';\n }\n $table_aliases = array();\n // Add tables for the fields used.\n foreach ($query->fields as $key => $field) {\n $tablename = $tablename_function($field);\n // Every field needs a new table.\n $table_alias = $tablename . $key;\n $table_aliases[$key] = $table_alias;\n if ($key) {\n $select_query->join($tablename, $table_alias, \"$table_alias.entity_type = $field_base_table.entity_type AND $table_alias.$id_key = $field_base_table.$id_key\");\n }\n else {\n $select_query = db_select($tablename, $table_alias);\n $select_query->addTag('entity_field_access');\n $select_query->addMetaData('base_table', $tablename);\n $select_query->fields($table_alias, array('entity_type', 'entity_id', 'revision_id', 'bundle'));\n $field_base_table = $table_alias;\n }\n if ($field['cardinality'] != 1) {\n $select_query->distinct();\n }\n }\n\n // Add field conditions.\n foreach ($query->fieldConditions as $key => $condition) {\n $table_alias = $table_aliases[$key];\n $field = $condition['field'];\n // Add the specified condition.\n $sql_field = \"$table_alias.\" . _field_sql_storage_columnname($field['field_name'], $condition['column']);\n $query->addCondition($select_query, $sql_field, $condition);\n // Add delta / language group conditions.\n foreach (array('delta', 'language') as $column) {\n if (isset($condition[$column . '_group'])) {\n $group_name = $condition[$column . '_group'];\n if (!isset($groups[$column][$group_name])) {\n $groups[$column][$group_name] = $table_alias;\n }\n else {\n $select_query->where(\"$table_alias.$column = \" . $groups[$column][$group_name] . \".$column\");\n }\n }\n }\n }\n\n if (isset($query->deleted)) {\n $select_query->condition(\"$field_base_table.deleted\", (int) $query->deleted);\n }\n\n // Is there a need to sort the query by property?\n $has_property_order = FALSE;\n foreach ($query->order as $order) {\n if ($order['type'] == 'property') {\n $has_property_order = TRUE;\n }\n }\n\n if ($query->propertyConditions || $has_property_order) {\n if (empty($query->entityConditions['entity_type']['value'])) {\n throw new EntityFieldQueryException('Property conditions and orders must have an entity type defined.');\n }\n $entity_type = $query->entityConditions['entity_type']['value'];\n $entity_base_table = _field_sql_storage_query_join_entity($select_query, $entity_type, $field_base_table);\n $query->entityConditions['entity_type']['operator'] = '=';\n foreach ($query->propertyConditions as $property_condition) {\n $query->addCondition($select_query, \"$entity_base_table.\" . $property_condition['column'], $property_condition);\n }\n }\n foreach ($query->entityConditions as $key => $condition) {\n $query->addCondition($select_query, \"$field_base_table.$key\", $condition);\n }\n\n // Order the query.\n foreach ($query->order as $order) {\n if ($order['type'] == 'entity') {\n $key = $order['specifier'];\n $select_query->orderBy(\"$field_base_table.$key\", $order['direction']);\n }\n elseif ($order['type'] == 'field') {\n $specifier = $order['specifier'];\n $field = $specifier['field'];\n $table_alias = $table_aliases[$specifier['index']];\n $sql_field = \"$table_alias.\" . _field_sql_storage_columnname($field['field_name'], $specifier['column']);\n $select_query->orderBy($sql_field, $order['direction']);\n }\n elseif ($order['type'] == 'property') {\n $select_query->orderBy(\"$entity_base_table.\" . $order['specifier'], $order['direction']);\n }\n }\n\n return $query->finishQuery($select_query, $id_key);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e4d30b16cf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_create_field/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_field_storage_create_field($field)` (modules/field/field.api.php): Act on creation of a new field.", "context": "This hook is invoked from field_create_field() to ask the field storage module to save field information and prepare for storing field instances. If there is a problem, the field storage module should throw an exception.\n\nParameters:\n- $field: The field structure being created.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_create_field($field) {\n $schema = _field_sql_storage_schema($field);\n foreach ($schema as $name => $table) {\n db_create_table($name, $table);\n }\n drupal_get_schema(NULL, TRUE);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e4d71d4fa5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_assign/7.x", "instruction": "I need the code for `trigger_assign($module_to_display = NULL)` in Drupal 7 (modules/trigger/trigger.admin.inc). It must do this: Builds a form that allows users to assign actions to triggers.", "context": "Parameters:\n- $module_to_display: Which tab of triggers to display. E.g., 'node' for all node-related triggers.\n\nReturns: HTML form.\n\nFile: modules/trigger/trigger.admin.inc", "response": "function trigger_assign($module_to_display = NULL) {\n // If no type is specified we default to node actions, since they\n // are the most common.\n if (!isset($module_to_display)) {\n drupal_goto('admin/structure/trigger/node');\n }\n\n $build = array();\n $trigger_info = module_invoke_all('trigger_info');\n drupal_alter('trigger_info', $trigger_info);\n foreach ($trigger_info as $module => $hooks) {\n if ($module == $module_to_display) {\n foreach ($hooks as $hook => $description) {\n $form_id = 'trigger_' . $hook . '_assign_form';\n $build[$form_id] = drupal_get_form($form_id, $module, $hook, $description['label']);\n }\n }\n }\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e4ee52d96e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_delete/7.x", "instruction": "Implement `field_attach_delete($entity_type, $entity)` in PHP for Drupal 7. Required behavior: Delete field data for an existing entity. This deletes all revisions of field data for the entity.", "context": "Parameters:\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entity: The entity whose field data to delete.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_delete($entity_type, $entity) {\n _field_invoke('delete', $entity_type, $entity);\n\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n // Collect the storage backends used by the fields in the entities.\n $storages = array();\n foreach (field_info_instances($entity_type, $bundle) as $instance) {\n $field = field_info_field_by_id($instance['field_id']);\n $field_id = $field['id'];\n $storages[$field['storage']['type']][$field_id] = $field_id;\n }\n\n // Field storage backends delete their data.\n foreach ($storages as $storage => $fields) {\n $storage_info = field_info_storage_types($storage);\n module_invoke($storage_info['module'], 'field_storage_delete', $entity_type, $entity, $fields);\n }\n\n // Let other modules act on deleting the entity.\n module_invoke_all('field_attach_delete', $entity_type, $entity);\n\n $entity_info = entity_get_info($entity_type);\n if ($entity_info['field cache']) {\n cache_clear_all(\"field:$entity_type:$id\", 'cache_field');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e4eec8d079", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_local_actions/7.x", "instruction": "I need the code for `menu_local_actions()` in Drupal 7 (includes/menu.inc). It must do this: Returns the rendered local actions at the current level.", "context": "File: includes/menu.inc", "response": "function menu_local_actions() {\n $links = menu_local_tasks();\n return $links['actions']['output'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e545e3d38f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_menu/7.x", "instruction": "In Drupal 7, write the function `overlay_menu()` (file modules/overlay/overlay.module) so that it does the following: Implements hook_menu().", "context": "File: modules/overlay/overlay.module", "response": "function overlay_menu() {\n $items['overlay-ajax/%'] = array(\n 'title' => '',\n 'page callback' => 'overlay_ajax_render_region',\n 'page arguments' => array(1),\n 'access arguments' => array('access overlay'),\n 'type' => MENU_CALLBACK,\n );\n $items['overlay/dismiss-message'] = array(\n 'title' => '',\n 'page callback' => 'overlay_user_dismiss_message',\n 'access arguments' => array('access overlay'),\n 'type' => MENU_CALLBACK,\n );\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e54c407db5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_update/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_update($node)` (modules/node/node.api.php): Respond to updates to a node.", "context": "This is a node-type-specific hook, which is invoked only for the node type being affected. See\n\nParameters:\n- $node: The node that is being updated.\n\nFile: modules/node/node.api.php", "response": "function hook_update($node) {\n db_update('mytable')\n ->fields(array('extra' => $node->extra))\n ->condition('nid', $node->nid)\n ->execute();\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e54f87d8ec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/watchdog/7.x", "instruction": "I need the code for `watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL)` in Drupal 7 (includes/bootstrap.inc). It must do this: Logs a system message.", "context": "Parameters:\n- $type: The category to which this message belongs. Can be any string, but the general practice is to use the name of the module calling watchdog().\n- $message: The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.\n- $variables: Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.\n- $severity: The severity of the message; one of the following values as defined in @link http://www.faqs.org/rfcs/rfc3164.html RFC 3164: @endlink - WATCHDOG_EMERGENCY: Emergency, system is unusable. - WATCHDOG_ALERT: Alert, action must be taken immediately. - WATCHDOG_CRITICAL: Critical conditions. - WATCHDOG_ERROR: Error conditions. - WATCHDOG_WARNING: Warning conditions. - WATCHDOG_NOTICE: (default) Normal but significant conditions. - WATCHDOG_INFO: Informational messages. - WATCHDOG_DEBUG: Debug-level messages.\n- $link: A link to associate with the message. SECURITY NOTE: Make sure your link is properly sanitized. Use the l() function to generate secure links.\n\nFile: includes/bootstrap.inc", "response": "function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {\n global $user, $base_root;\n\n static $in_error_state = FALSE;\n\n // It is possible that the error handling will itself trigger an error. In that case, we could\n // end up in an infinite loop. To avoid that, we implement a simple static semaphore.\n if (!$in_error_state && function_exists('module_invoke_all')) {\n $in_error_state = TRUE;\n\n // The user object may not exist in all conditions, so 0 is substituted if needed.\n $user_uid = isset($user->uid) ? $user->uid : 0;\n\n // Prepare the fields to be logged\n $log_entry = array(\n 'type' => $type,\n 'message' => $message,\n 'variables' => $variables,\n 'severity' => $severity,\n 'link' => $link,\n 'user' => $user,\n 'uid' => $user_uid,\n 'request_uri' => $base_root . request_uri(),\n 'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',\n 'ip' => ip_address(),\n // Request time isn't accurate for long processes, use time() instead.\n 'timestamp' => time(),\n );\n\n // Call the logging hooks to log/process the message\n module_invoke_all('watchdog', $log_entry);\n\n // It is critical that the semaphore is only cleared here, in the parent\n // watchdog() call (not outside the loop), to prevent recursive execution.\n $in_error_state = FALSE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e576034d8f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_theme/7.x", "instruction": "Implement `rdf_theme()` in PHP for Drupal 7. Required behavior: Implements hook_theme().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_theme() {\n return array(\n 'rdf_template_variable_wrapper' => array(\n 'variables' => array('content' => NULL, 'attributes' => array(), 'context' => array(), 'inline' => TRUE),\n ),\n 'rdf_metadata' => array(\n 'variables' => array('metadata' => array()),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e57f2e01ff", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_tree_check_access/7.x", "instruction": "Implement `_menu_tree_check_access(&$tree)` in PHP for Drupal 7. Required behavior: Sorts the menu tree and recursively checks access for each item.", "context": "File: includes/menu.inc", "response": "function _menu_tree_check_access(&$tree) {\n $new_tree = array();\n foreach ($tree as $key => $v) {\n $item = &$tree[$key]['link'];\n _menu_link_translate($item);\n if ($item['access'] || ($item['in_active_trail'] && strpos($item['href'], '%') !== FALSE)) {\n if ($tree[$key]['below']) {\n _menu_tree_check_access($tree[$key]['below']);\n }\n // The weights are made a uniform 5 digits by adding 50000 as an offset.\n // After _menu_link_translate(), $item['title'] has the localized link title.\n // Adding the mlid to the end of the index insures that it is unique.\n $new_tree[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $tree[$key];\n }\n }\n // Sort siblings in the tree based on the weights and localized titles.\n ksort($new_tree);\n $tree = $new_tree;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5a1cd1bcb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_help/7.x", "instruction": "Implement `update_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/update/update.module", "response": "function update_help($path, $arg) {\n switch ($path) {\n case 'admin/reports/updates':\n return '

              ' . t('Here you can find information about available updates for your installed modules and themes. Note that each module or theme is part of a \"project\", which may or may not have the same name, and might include multiple modules or themes within it.') . '

              ';\n\n case 'admin/help#update':\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t(\"The Update manager module periodically checks for new versions of your site's software (including contributed modules and themes), and alerts administrators to available updates. In order to provide update information, anonymous usage statistics are sent to Drupal.org. If desired, you may disable the Update manager module from the Module administration page. For more information, see the online handbook entry for Update manager module.\", array('@update' => 'http://drupal.org/documentation/modules/update', '@modules' => url('admin/modules'))) . '

              ';\n // Only explain the Update manager if it has not been disabled.\n if (update_manager_access()) {\n $output .= '

              ' . t('The Update manager also allows administrators to update and install modules and themes through the administration interface.') . '

              ';\n }\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Checking for available updates') . '
              ';\n $output .= '
              ' . t('A report of available updates will alert you when new releases are available for download. You may configure options for the frequency for checking updates (which are performed during cron runs) and e-mail notifications at the Update manager settings page.', array('@update-report' => url('admin/reports/updates'), '@cron' => 'http://drupal.org/cron', '@update-settings' => url('admin/reports/updates/settings'))) . '
              ';\n // Only explain the Update manager if it has not been disabled.\n if (update_manager_access()) {\n $output .= '
              ' . t('Performing updates through the user interface') . '
              ';\n $output .= '
              ' . t('The Update manager module allows administrators to perform updates directly through the administration interface. At the top of the modules and themes pages you will see a link to update to new releases. This will direct you to the update page where you see a listing of all the missing updates and confirm which ones you want to upgrade. From there, you are prompted for your FTP/SSH password, which then transfers the files into your Drupal installation, overwriting your old files. More detailed instructions can be found in the online handbook.', array('@modules_page' => url('admin/modules'), '@themes_page' => url('admin/appearance'), '@update-page' => url('admin/reports/updates/update'), '@update' => 'http://drupal.org/documentation/modules/update')) . '
              ';\n $output .= '
              ' . t('Installing new modules and themes through the user interface') . '
              ';\n $output .= '
              ' . t('You can also install new modules and themes in the same fashion, through the install page, or by clicking the Install new module/theme link at the top of the modules and themes pages. In this case, you are prompted to provide either the URL to the download, or to upload a packaged release file from your local computer.', array('@modules_page' => url('admin/modules'), '@themes_page' => url('admin/appearance'), '@install' => url('admin/reports/updates/install'))) . '
              ';\n }\n $output .= '
              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5b73c3ce6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.install/function/locale_update_7001/7.x", "instruction": "I need the code for `locale_update_7001()` in Drupal 7 (modules/locale/locale.install). It must do this: Upgrade language negotiation settings.", "context": "File: modules/locale/locale.install", "response": "function locale_update_7001() {\n require_once DRUPAL_ROOT . '/includes/language.inc';\n require_once DRUPAL_ROOT . '/includes/locale.inc';\n require_once DRUPAL_ROOT . '/modules/locale/locale.module';\n\n switch (variable_get('language_negotiation', 0)) {\n // LANGUAGE_NEGOTIATION_NONE.\n case 0:\n $negotiation = array();\n break;\n\n // LANGUAGE_NEGOTIATION_PATH_DEFAULT.\n case 1:\n $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);\n // In Drupal 6 path prefixes are shown for the default language only when\n // language negotiation is set to LANGUAGE_NEGOTIATION_PATH, while in\n // Drupal 7 path prefixes are always shown if not empty. Hence we need to\n // ensure that the default language has an empty prefix to avoid breaking\n // the site URLs with a prefix that previously was missing.\n $default = language_default();\n $default->prefix = '';\n variable_set('language_default', $default);\n db_update('languages')\n ->fields(array('prefix' => $default->prefix))\n ->condition('language', $default->language)\n ->execute();\n break;\n\n // LANGUAGE_NEGOTIATION_PATH.\n case 2:\n $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL, LOCALE_LANGUAGE_NEGOTIATION_USER, LOCALE_LANGUAGE_NEGOTIATION_BROWSER);\n break;\n\n // LANGUAGE_NEGOTIATION_DOMAIN.\n case 3:\n variable_set('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN);\n $negotiation = array(LOCALE_LANGUAGE_NEGOTIATION_URL);\n break;\n }\n\n // Save the new language negotiation options.\n language_negotiation_set(LANGUAGE_TYPE_INTERFACE, array_flip($negotiation));\n language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LOCALE_LANGUAGE_NEGOTIATION_INTERFACE => 0));\n language_negotiation_set(LANGUAGE_TYPE_URL, array(LOCALE_LANGUAGE_NEGOTIATION_URL => 0));\n\n // Save admininstration UI settings.\n $type = LANGUAGE_TYPE_INTERFACE;\n $provider_weights = array_flip(array_keys(locale_language_negotiation_info()));\n variable_set(\"locale_language_providers_weight_$type\", $provider_weights);\n\n // Unset the old language negotiation system variable.\n variable_del('language_negotiation');\n\n return array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5cc627f63", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21options%21options.module/function/options_field_widget_settings_form/7.x", "instruction": "I need the code for `options_field_widget_settings_form($field, $instance)` in Drupal 7 (modules/field/modules/options/options.module). It must do this: Implements hook_field_widget_settings_form().", "context": "File: modules/field/modules/options/options.module", "response": "function options_field_widget_settings_form($field, $instance) {\n $form = array();\n if ($instance['widget']['type'] == 'options_onoff') {\n $form['display_label'] = array(\n '#type' => 'checkbox',\n '#title' => t('Use field label instead of the \"On value\" as label'),\n '#default_value' => $instance['widget']['settings']['display_label'],\n '#weight' => -1,\n );\n }\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5cfac36f0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_from_user/7.x", "instruction": "Implement `locale_language_from_user($languages)` in PHP for Drupal 7. Required behavior: Identify language from the user preferences.", "context": "Parameters:\n- $languages: An array of valid language objects.\n\nReturns: A valid language code on success, FALSE otherwise.\n\nFile: includes/locale.inc", "response": "function locale_language_from_user($languages) {\n // User preference (only for logged users).\n global $user;\n\n if ($user->uid) {\n return $user->language;\n }\n\n // No language preference from the user.\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5d2ca4b7a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_presave/7.x", "instruction": "Implement `number_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items)` in PHP for Drupal 7. Required behavior: Implements hook_field_presave().", "context": "File: modules/field/modules/number/number.module", "response": "function number_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {\n if ($field['type'] == 'number_decimal') {\n // Let PHP round the value to ensure consistent behavior across storage\n // backends.\n foreach ($items as $delta => $item) {\n if (isset($item['value'])) {\n $items[$delta]['value'] = round($item['value'], $field['settings']['scale']);\n }\n }\n }\n if ($field['type'] == 'number_float') {\n // Remove the decimal point from float values with decimal\n // point but no decimal numbers.\n foreach ($items as $delta => $item) {\n if (isset($item['value'])) {\n $items[$delta]['value'] = floatval($item['value']);\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5d3d31459", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_install_form_submit/7.x", "instruction": "I need the code for `update_manager_install_form_submit($form, &$form_state)` in Drupal 7 (modules/update/update.manager.inc). It must do this: Form submission handler for update_manager_install_form().", "context": "Either downloads the file specified in the URL to a temporary cache, or uploads the file attached to the form, then attempts to extract the archive into a temporary location and verify it. Instantiate the appropriate Updater class for this project and make sure it is not already installed in the live webroot. If everything is successful, setup an operation to run via authorize.php which will copy the extracted files from the temporary location into the live site.\n\nFile: modules/update/update.manager.inc", "response": "function update_manager_install_form_submit($form, &$form_state) {\n if ($form_state['values']['project_url']) {\n $field = 'project_url';\n $local_cache = update_manager_file_get($form_state['values']['project_url']);\n if (!$local_cache) {\n form_set_error($field, t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state['values']['project_url'])));\n return;\n }\n }\n elseif ($_FILES['files']['name']['project_upload']) {\n $validators = array('file_validate_extensions' => array(archiver_get_extensions()));\n $field = 'project_upload';\n if (!($finfo = file_save_upload($field, $validators, NULL, FILE_EXISTS_REPLACE))) {\n // Failed to upload the file. file_save_upload() calls form_set_error() on\n // failure.\n return;\n }\n $local_cache = $finfo->uri;\n }\n\n $directory = _update_manager_extract_directory();\n try {\n $archive = update_manager_archive_extract($local_cache, $directory);\n }\n catch (Exception $e) {\n form_set_error($field, $e->getMessage());\n return;\n }\n\n $files = $archive->listContents();\n if (!$files) {\n form_set_error($field, t('Provided archive contains no files.'));\n return;\n }\n\n // Unfortunately, we can only use the directory name to determine the project\n // name. Some archivers list the first file as the directory (i.e., MODULE/)\n // and others list an actual file (i.e., MODULE/README.TXT).\n $project = strtok($files[0], '/\\\\');\n\n $archive_errors = update_manager_archive_verify($project, $local_cache, $directory);\n if (!empty($archive_errors)) {\n form_set_error($field, array_shift($archive_errors));\n // @todo: Fix me in D8: We need a way to set multiple errors on the same\n // form element and have all of them appear!\n if (!empty($archive_errors)) {\n foreach ($archive_errors as $error) {\n drupal_set_message($error, 'error');\n }\n }\n return;\n }\n\n // Make sure the Updater registry is loaded.\n drupal_get_updaters();\n\n $project_location = $directory . '/' . $project;\n try {\n $updater = Updater::factory($project_location);\n }\n catch (Exception $e) {\n form_set_error($field, $e->getMessage());\n return;\n }\n\n try {\n $project_title = Updater::getProjectTitle($project_location);\n }\n catch (Exception $e) {\n form_set_error($field, $e->getMessage());\n return;\n }\n\n if (!$project_title) {\n form_set_error($field, t('Unable to determine %project name.', array('%project' => $project)));\n }\n\n if ($updater->isInstalled()) {\n form_set_error($field, t('%project is already installed.', array('%project' => $project_title)));\n return;\n }\n\n $project_real_location = drupal_realpath($project_location);\n $arguments = array(\n 'project' => $project,\n 'updater_name' => get_class($updater),\n 'local_url' => $project_real_location,\n );\n\n // If the owner of the directory we extracted is the same as the\n // owner of our configuration directory (e.g. sites/default) where we're\n // trying to install the code, there's no need to prompt for FTP/SSH\n // credentials. Instead, we instantiate a FileTransferLocal and invoke\n // update_authorize_run_install() directly.\n if (fileowner($project_real_location) == fileowner(conf_path())) {\n module_load_include('inc', 'update', 'update.authorize');\n $filetransfer = new FileTransferLocal(DRUPAL_ROOT);\n call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments));\n }\n // Otherwise, go through the regular workflow to prompt for FTP/SSH\n // credentials and invoke update_authorize_run_install() indirectly with\n // whatever FileTransfer object authorize.php creates for us.\n else {\n system_authorized_init('update_authorize_run_install', drupal_get_path('module', 'update') . '/update.authorize.inc', $arguments, t('Update manager'));\n $form_state['redirect'] = system_authorized_get_url();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5e06b97a4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_formatter_info/7.x", "instruction": "In Drupal 7, write the function `file_field_formatter_info()` (file modules/file/file.field.inc) so that it does the following: Implements hook_field_formatter_info().", "context": "File: modules/file/file.field.inc", "response": "function file_field_formatter_info() {\n return array(\n 'file_default' => array(\n 'label' => t('Generic file'),\n 'field types' => array('file'),\n ),\n 'file_table' => array(\n 'label' => t('Table of files'),\n 'field types' => array('file'),\n ),\n 'file_url_plain' => array(\n 'label' => t('URL to file'),\n 'field types' => array('file'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e5ed192669", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_begin/7.x", "instruction": "I need the code for `openid_begin($claimed_id, $return_to = '', $form_values = array())` in Drupal 7 (modules/openid/openid.module). It must do this: The initial step of OpenID authentication responsible for the following: - Perform discovery on the claimed OpenID. - If possible, create an association with the Provider's endpoint. - Create the authentication request. - Perform the appropriate redirect.", "context": "Parameters:\n- $claimed_id: The OpenID to authenticate\n- $return_to: The endpoint to return to from the OpenID Provider\n\nFile: modules/openid/openid.module", "response": "function openid_begin($claimed_id, $return_to = '', $form_values = array()) {\n module_load_include('inc', 'openid');\n\n $service = NULL;\n $claimed_id = openid_normalize($claimed_id);\n $discovery = openid_discovery($claimed_id);\n\n if (!empty($discovery['services'])) {\n $service = _openid_select_service($discovery['services']);\n }\n\n // Quit if the discovery result was empty or if we can't select any service.\n if (!$discovery || !$service) {\n form_set_error('openid_identifier', t('Sorry, that is not a valid OpenID. Ensure you have spelled your ID correctly.'));\n return;\n }\n\n // Set claimed id from discovery.\n if (!empty($discovery['claimed_id'])) {\n $claimed_id = $discovery['claimed_id'];\n }\n\n // Store discovered information in the users' session so we don't have to rediscover.\n $_SESSION['openid']['service'] = $service;\n // Store the claimed id\n $_SESSION['openid']['claimed_id'] = $claimed_id;\n // Store the login form values so we can pass them to\n // user_exteral_login later.\n $_SESSION['openid']['user_login_values'] = $form_values;\n\n // If a supported math library is present, then create an association.\n $assoc_handle = '';\n if (_openid_get_math_library()) {\n $assoc_handle = openid_association($service['uri']);\n }\n\n if (in_array('http://specs.openid.net/auth/2.0/server', $service['types'])) {\n // User entered an OP Identifier.\n $claimed_id = $identity = 'http://specs.openid.net/auth/2.0/identifier_select';\n }\n else {\n // Use Claimed ID and/or OP-Local Identifier from service description, if\n // available.\n if (!empty($service['claimed_id'])) {\n $claimed_id = $service['claimed_id'];\n }\n $identity = !empty($service['identity']) ? $service['identity'] : $claimed_id;\n }\n $request = openid_authentication_request($claimed_id, $identity, $return_to, $assoc_handle, $service);\n\n if ($service['version'] == 2) {\n openid_redirect($service['uri'], $request);\n }\n else {\n openid_redirect_http($service['uri'], $request);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6130d4aa4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_time_zones/7.x", "instruction": "I need the code for `system_time_zones($blank = NULL)` in Drupal 7 (modules/system/system.module). It must do this: Generate an array of time zones and their local time&date.", "context": "Parameters:\n- $blank: If evaluates true, prepend an empty time zone option to the array.\n\nFile: modules/system/system.module", "response": "function system_time_zones($blank = NULL) {\n $zonelist = timezone_identifiers_list();\n $zones = $blank ? array('' => t('- None selected -')) : array();\n foreach ($zonelist as $zone) {\n // Because many time zones exist in PHP only for backward compatibility\n // reasons and should not be used, the list is filtered by a regular\n // expression.\n if (preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone)) {\n $zones[$zone] = t('@zone: @date', array('@zone' => t(str_replace('_', ' ', $zone)), '@date' => format_date(REQUEST_TIME, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone)));\n }\n }\n // Sort the translated time zones alphabetically.\n asort($zones);\n return $zones;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e615a8e583", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.parser.inc/function/aggregator_element_data/7.x", "instruction": "In Drupal 7, write the function `aggregator_element_data($parser, $data)` (file modules/aggregator/aggregator.parser.inc) so that it does the following: Performs an action when data is encountered.", "context": "Callback function used by xml_parse() within aggregator_parse_feed().\n\nFile: modules/aggregator/aggregator.parser.inc", "response": "function aggregator_element_data($parser, $data) {\n global $channel, $element, $items, $item, $image, $tag;\n $items += array($item => array());\n switch ($element) {\n case 'item':\n $items[$item] += array($tag => '');\n $items[$item][$tag] .= $data;\n break;\n case 'image':\n case 'logo':\n $image += array($tag => '');\n $image[$tag] .= $data;\n break;\n case 'link':\n if ($data) {\n $items[$item] += array($tag => '');\n $items[$item][$tag] .= $data;\n }\n break;\n case 'content':\n $items[$item] += array('content' => '');\n $items[$item]['content'] .= $data;\n break;\n case 'summary':\n $items[$item] += array('summary' => '');\n $items[$item]['summary'] .= $data;\n break;\n case 'tagline':\n case 'subtitle':\n $channel += array('description' => '');\n $channel['description'] .= $data;\n break;\n case 'info':\n case 'id':\n case 'textinput':\n // The sub-element is not supported. However, we must recognize\n // it or its contents will end up in the item array.\n break;\n default:\n $channel += array($tag => '');\n $channel[$tag] .= $data;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e617012572", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_cron/7.x", "instruction": "I need the code for `aggregator_cron()` in Drupal 7 (modules/aggregator/aggregator.module). It must do this: Implements hook_cron().", "context": "Queues news feeds for updates once their refresh interval has elapsed.\n\nFile: modules/aggregator/aggregator.module", "response": "function aggregator_cron() {\n $result = db_query('SELECT * FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', array(\n ':time' => REQUEST_TIME,\n ':never' => AGGREGATOR_CLEAR_NEVER\n ));\n $queue = DrupalQueue::get('aggregator_feeds');\n foreach ($result as $feed) {\n if ($queue->createItem($feed)) {\n // Add timestamp to avoid queueing item more than once.\n db_update('aggregator_feed')\n ->fields(array('queued' => REQUEST_TIME))\n ->condition('fid', $feed->fid)\n ->execute();\n }\n }\n\n // Remove queued timestamp after 6 hours assuming the update has failed.\n db_update('aggregator_feed')\n ->fields(array('queued' => 0))\n ->condition('queued', REQUEST_TIME - (3600 * 6), '<')\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6256da525", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.install/function/forum_update_7000/7.x", "instruction": "In Drupal 7, write the function `forum_update_7000()` (file modules/forum/forum.install) so that it does the following: Add new index to forum table.", "context": "File: modules/forum/forum.install", "response": "function forum_update_7000() {\n db_drop_index('forum', 'nid');\n db_add_index('forum', 'forum_topic', array('nid', 'tid'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e629cba757", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_delete_file_if_stale/7.x", "instruction": "In Drupal 7, write the function `update_delete_file_if_stale($path)` (file modules/update/update.module) so that it does the following: Deletes stale files and directories from the update manager disk cache.", "context": "Files and directories older than 6 hours and development snapshots older than 5 minutes are considered stale. We only cache development snapshots for 5 minutes since otherwise updated snapshots might not be downloaded as expected.\n\nWhen checking file ages, we need to use the ctime, not the mtime (modification time) since many (all?) tar implementations go out of their way to set the mtime on the files they create to the timestamps recorded in the tarball. We want to see the last time the file was changed on disk, which is left alone by tar and correctly set to the time the archive file was unpacked.\n\nParameters:\n- $path: A string containing a file path or (streamwrapper) URI.\n\nFile: modules/update/update.module", "response": "function update_delete_file_if_stale($path) {\n if (file_exists($path)) {\n $filectime = filectime($path);\n if (REQUEST_TIME - $filectime > DRUPAL_MAXIMUM_TEMP_FILE_AGE || (preg_match('/.*-dev\\.(tar\\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) {\n file_unmanaged_delete_recursive($path);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e62c381220", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_account_submit/7.x", "instruction": "I need the code for `user_admin_account_submit($form, &$form_state)` in Drupal 7 (modules/user/user.admin.inc). It must do this: Submit the user administration update form.", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_account_submit($form, &$form_state) {\n $operations = module_invoke_all('user_operations', $form, $form_state);\n $operation = $operations[$form_state['values']['operation']];\n // Filter out unchecked accounts.\n $accounts = array_filter($form_state['values']['accounts']);\n if ($function = $operation['callback']) {\n // Add in callback arguments if present.\n if (isset($operation['callback arguments'])) {\n $args = array_merge(array($accounts), $operation['callback arguments']);\n }\n else {\n $args = array($accounts);\n }\n call_user_func_array($function, $args);\n\n drupal_set_message(t('The update has been performed.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6458e14de", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21module.inc/function/module_hook_info/7.x", "instruction": "Implement `module_hook_info()` in PHP for Drupal 7. Required behavior: Retrieves a list of hooks that are declared through hook_hook_info().", "context": "Returns: An associative array whose keys are hook names and whose values are an associative array containing a group name. The structure of the array is the same as the return value of hook_hook_info().\n\nFile: includes/module.inc", "response": "function module_hook_info() {\n // This function is indirectly invoked from bootstrap_invoke_all(), in which\n // case common.inc, subsystems, and modules are not loaded yet, so it does not\n // make sense to support hook groups resp. lazy-loaded include files prior to\n // full bootstrap.\n if (drupal_bootstrap(NULL, FALSE) != DRUPAL_BOOTSTRAP_FULL) {\n return array();\n }\n $hook_info = &drupal_static(__FUNCTION__);\n\n if (!isset($hook_info)) {\n $hook_info = array();\n $cache = cache_get('hook_info', 'cache_bootstrap');\n if ($cache === FALSE) {\n // Rebuild the cache and save it.\n // We can't use module_invoke_all() here or it would cause an infinite\n // loop.\n foreach (module_list() as $module) {\n $function = $module . '_hook_info';\n if (function_exists($function)) {\n $result = $function();\n if (isset($result) && is_array($result)) {\n $hook_info = array_merge_recursive($hook_info, $result);\n }\n }\n }\n // We can't use drupal_alter() for the same reason as above.\n foreach (module_list() as $module) {\n $function = $module . '_hook_info_alter';\n if (function_exists($function)) {\n $function($hook_info);\n }\n }\n cache_set('hook_info', $hook_info, 'cache_bootstrap');\n }\n else {\n $hook_info = $cache->data;\n }\n }\n\n return $hook_info;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e64cf0a217", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_list/7.x", "instruction": "I need the code for `block_list($region)` in Drupal 7 (modules/block/block.module). It must do this: Returns all blocks in the specified region for the current user.", "context": "Parameters:\n- $region: The name of a region.\n\nReturns: An array of block objects, indexed with the module name and block delta concatenated with an underscore, thus: MODULE_DELTA. If you are displaying your blocks in one or two sidebars, you may check whether this array is empty to see how many columns are going to be displayed.\n\nFile: modules/block/block.module", "response": "function block_list($region) {\n $blocks = &drupal_static(__FUNCTION__);\n\n if (!isset($blocks)) {\n $blocks = _block_load_blocks();\n }\n\n // Create an empty array if there are no entries.\n if (!isset($blocks[$region])) {\n $blocks[$region] = array();\n }\n else {\n $blocks[$region] = _block_render_blocks($blocks[$region]);\n }\n\n return $blocks[$region];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e65d3527f0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_language_alter/7.x", "instruction": "Give me the example code for `hook_field_language_alter(&$display_language, $context)` in Drupal 7. Hook description: Perform alterations on field_language() values.", "context": "This hook is invoked to alter the array of display languages for the given entity.\n\nParameters:\n- $display_language: A reference to an array of language codes keyed by field name.\n- $context: An associative array containing: - entity_type: The type of the entity to be displayed. - entity: The entity with fields to render. - langcode: The language code $entity has to be displayed in.\n\nFile: modules/field/field.api.php", "response": "function hook_field_language_alter(&$display_language, $context) {\n // Do not apply core language fallback rules if they are disabled or if Locale\n // is not registered as a translation handler.\n if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'locale')) {\n locale_field_language_fallback($display_language, $context['entity'], $context['language']);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e66824442f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/theme_aggregator_page_opml/7.x", "instruction": "I need the code for `theme_aggregator_page_opml($variables)` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Prints the OPML page for the feed.", "context": "Parameters:\n- $variables: An associative array containing: - feeds: An array of the feeds to theme.\n\nFile: modules/aggregator/aggregator.pages.inc", "response": "function theme_aggregator_page_opml($variables) {\n $feeds = $variables['feeds'];\n\n drupal_add_http_header('Content-Type', 'text/xml; charset=utf-8');\n\n $output = \"\\n\";\n $output .= \"\\n\";\n $output .= \"\\n\";\n $output .= '' . check_plain(variable_get('site_name', 'Drupal')) . \"\\n\";\n $output .= '' . gmdate(DATE_RFC2822, REQUEST_TIME) . \"\\n\";\n $output .= \"\\n\";\n $output .= \"\\n\";\n foreach ($feeds as $feed) {\n $output .= 'title) . '\" xmlUrl=\"' . check_url($feed->url) . \"\\\" />\\n\";\n }\n $output .= \"\\n\";\n $output .= \"\\n\";\n\n print $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e686bb9ce3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/update_filter_project_info/7.x", "instruction": "I need the code for `update_filter_project_info($info)` in Drupal 7 (modules/update/update.compare.inc). It must do this: Filters the project .info data to only save attributes we need.", "context": "Parameters:\n- $info (array): Array of .info file data as returned by drupal_parse_info_file().\n\nReturns (Array): of .info file data we need for the update manager.\n\nFile: modules/update/update.compare.inc", "response": "function update_filter_project_info($info) {\n $whitelist = array(\n '_info_file_ctime',\n 'datestamp',\n 'major',\n 'name',\n 'package',\n 'project',\n 'project status url',\n 'version',\n );\n return array_intersect_key($info, drupal_map_assoc($whitelist));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6a11340e2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_invalidate_js/7.x", "instruction": "Implement `_locale_invalidate_js($langcode = NULL)` in PHP for Drupal 7. Required behavior: Force the JavaScript translation file(s) to be refreshed.", "context": "This function sets a refresh flag for a specified language, or all languages except English, if none specified. JavaScript translation files are rebuilt (with locale_update_js_files()) the next time a request is served in that language.\n\nParameters:\n- $langcode: The language code for which the file needs to be refreshed.\n\nReturns: New content of the 'javascript_parsed' variable.\n\nFile: includes/locale.inc", "response": "function _locale_invalidate_js($langcode = NULL) {\n $parsed = variable_get('javascript_parsed', array());\n\n if (empty($langcode)) {\n // Invalidate all languages.\n $languages = language_list();\n unset($languages['en']);\n foreach ($languages as $lcode => $data) {\n $parsed['refresh:' . $lcode] = 'waiting';\n }\n }\n else {\n // Invalidate single language.\n $parsed['refresh:' . $langcode] = 'waiting';\n }\n\n variable_set('javascript_parsed', $parsed);\n return $parsed;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6bd7e6029", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_clear_js_cache/7.x", "instruction": "In Drupal 7, write the function `drupal_clear_js_cache()` (file includes/common.inc) so that it does the following: Deletes old cached JavaScript files and variables.", "context": "File: includes/common.inc", "response": "function drupal_clear_js_cache() {\n variable_del('javascript_parsed');\n variable_del('drupal_js_cache_files');\n file_scan_directory('public://js', '/.*/', array('callback' => 'drupal_delete_file_if_stale'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6bf7d5acb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_node_delete/7.x", "instruction": "Implement `translation_node_delete($node)` in PHP for Drupal 7. Required behavior: Implements hook_node_delete().", "context": "File: modules/translation/translation.module", "response": "function translation_node_delete($node) {\n // Only act if we are dealing with a content type supporting translations.\n if (translation_supported_type($node->type)) {\n translation_remove_from_set($node);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6d5b5734d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/variable_del/7.x", "instruction": "Implement `variable_del($name)` in PHP for Drupal 7. Required behavior: Unsets a persistent variable.", "context": "Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.\n\nParameters:\n- $name: The name of the variable to undefine.\n\nFile: includes/bootstrap.inc", "response": "function variable_del($name) {\n global $conf;\n\n db_delete('variable')\n ->condition('name', $name)\n ->execute();\n cache_clear_all('variables', 'cache_bootstrap');\n\n unset($conf[$name]);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e6e74eac75", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.install/function/search_uninstall/7.x", "instruction": "I need the code for `search_uninstall()` in Drupal 7 (modules/search/search.install). It must do this: Implements hook_uninstall().", "context": "File: modules/search/search.install", "response": "function search_uninstall() {\n variable_del('minimum_word_size');\n variable_del('overlap_cjk');\n variable_del('search_cron_limit');\n variable_del('search_logging');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e71ba689de", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/update.php/function/update_task_list/7.x", "instruction": "In Drupal 7, write the function `update_task_list($active = NULL)` (file update.php) so that it does the following: Adds the update task list to the current page.", "context": "File: update.php", "response": "function update_task_list($active = NULL) {\n // Default list of tasks.\n $tasks = array(\n 'requirements' => 'Verify requirements',\n 'info' => 'Overview',\n 'select' => 'Review updates',\n 'run' => 'Run updates',\n 'finished' => 'Review log',\n );\n\n drupal_add_region_content('sidebar_first', theme('task_list', array('items' => $tasks, 'active' => $active)));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e725aa087b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_view_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_user_view_alter(&$build)` (modules/user/user.api.php): The user was built; the module may modify the structured content.", "context": "This hook is called after the content has been assembled in a structured array and may be used for doing processing which requires that the complete user content structure has been built.\n\nIf the module wishes to act on the rendered HTML of the user rather than the structured content array, it may use this hook to add a #post_render callback. Alternatively, it could also implement hook_preprocess_user_profile(). See drupal_render() and theme() documentation respectively for details.\n\nParameters:\n- $build: A renderable array representing the user.\n\nFile: modules/user/user.api.php", "response": "function hook_user_view_alter(&$build) {\n // Check for the existence of a field added by another module.\n if (isset($build['an_additional_field'])) {\n // Change its weight.\n $build['an_additional_field']['#weight'] = -10;\n }\n\n // Add a #post_render callback to act on the rendered HTML of the user.\n $build['#post_render'][] = 'my_module_user_post_render';\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e72d30fcf7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_rdfa_attributes/7.x", "instruction": "I need the code for `rdf_rdfa_attributes($mapping, $data = NULL)` in Drupal 7 (modules/rdf/rdf.module). It must do this: Builds an array of RDFa attributes for a given mapping. This array will typically be passed through drupal_attributes() to create the attributes variables that are available to template files. These include $attributes, $title_attributes, $content_attributes and the field-specific $item_attributes variables. For more information, see theme_rdf_template_variable_wrapper().", "context": "Parameters:\n- $mapping: An array containing a mandatory 'predicates' key and optional 'datatype', 'callback' and 'type' keys. For example: @code array( 'predicates' => array('dc:created'), 'datatype' => 'xsd:dateTime', 'callback' => 'date_iso8601', ), ); @endcode\n- $data: A value that needs to be converted by the provided callback function.\n\nReturns: An array containing RDFa attributes suitable for drupal_attributes().\n\nFile: modules/rdf/rdf.module", "response": "function rdf_rdfa_attributes($mapping, $data = NULL) {\n // The type of mapping defaults to 'property'.\n $type = isset($mapping['type']) ? $mapping['type'] : 'property';\n\n switch ($type) {\n // The mapping expresses the relationship between two resources.\n case 'rel':\n case 'rev':\n $attributes[$type] = $mapping['predicates'];\n break;\n\n // The mapping expresses the relationship between a resource and some\n // literal text.\n case 'property':\n $attributes['property'] = $mapping['predicates'];\n // Convert $data to a specific format as per the callback function.\n if (isset($data) && isset($mapping['callback']) && function_exists($mapping['callback'])) {\n $callback = $mapping['callback'];\n $attributes['content'] = $callback($data);\n }\n if (isset($mapping['datatype'])) {\n $attributes['datatype'] = $mapping['datatype'];\n }\n break;\n }\n\n return $attributes;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e7715d5ec4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_load/7.x", "instruction": "I need the code for `poll_load($nodes)` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_load().", "context": "File: modules/poll/poll.module", "response": "function poll_load($nodes) {\n global $user;\n foreach ($nodes as $node) {\n $poll = db_query(\"SELECT runtime, active FROM {poll} WHERE nid = :nid\", array(':nid' => $node->nid))->fetchObject();\n\n if (empty($poll)) {\n $poll = new stdClass();\n }\n\n // Load the appropriate choices into the $poll object.\n $poll->choice = db_select('poll_choice', 'c')\n ->addTag('translatable')\n ->fields('c', array('chid', 'chtext', 'chvotes', 'weight'))\n ->condition('c.nid', $node->nid)\n ->orderBy('weight')\n ->execute()->fetchAllAssoc('chid', PDO::FETCH_ASSOC);\n\n // Determine whether or not this user is allowed to vote.\n $poll->allowvotes = FALSE;\n if (user_access('vote on polls') && $poll->active) {\n if ($user->uid) {\n // If authenticated, find existing vote based on uid.\n $poll->vote = db_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchField();\n if (empty($poll->vote)) {\n $poll->vote = -1;\n $poll->allowvotes = TRUE;\n }\n }\n elseif (!empty($_SESSION['poll_vote'][$node->nid])) {\n // Otherwise the user is anonymous. Look for an existing vote in the\n // user's session.\n $poll->vote = $_SESSION['poll_vote'][$node->nid];\n }\n else {\n // Finally, query the database for an existing vote based on anonymous\n // user's hostname.\n $poll->allowvotes = !db_query(\"SELECT 1 FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname AND uid = 0\", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchField();\n }\n }\n foreach ($poll as $key => $value) {\n $nodes[$node->nid]->$key = $value;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e771c46b10", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_view/7.x", "instruction": "In Drupal 7, write the function `forum_node_view($node, $view_mode)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_view().", "context": "File: modules/forum/forum.module", "response": "function forum_node_view($node, $view_mode) {\n if (!empty($node->forum_tid) && _forum_node_check_node_type($node)) {\n if ($view_mode == 'full' && node_is_page($node)) {\n $vid = variable_get('forum_nav_vocabulary', 0);\n $vocabulary = taxonomy_vocabulary_load($vid);\n // Breadcrumb navigation\n $breadcrumb[] = l(t('Home'), NULL);\n $breadcrumb[] = l($vocabulary->name, 'forum');\n if ($parents = taxonomy_get_parents_all($node->forum_tid)) {\n $parents = array_reverse($parents);\n foreach ($parents as $parent) {\n $breadcrumb[] = l($parent->name, 'forum/' . $parent->tid);\n }\n }\n drupal_set_breadcrumb($breadcrumb);\n\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e7742fc69b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_prepare_form/7.x", "instruction": "Implement `drupal_prepare_form($form_id, &$form, &$form_state)` in PHP for Drupal 7. Required behavior: Prepares a structured form array.", "context": "Adds required elements, executes any hook_form_alter functions, and optionally inserts a validation token to prevent tampering.\n\nParameters:\n- $form_id: A unique string identifying the form for validation, submission, theming, and hook_form_alter functions.\n- $form: An associative array containing the structure of the form.\n- $form_state: A keyed array containing the current state of the form. Passed in here so that hook_form_alter() calls can use it, as well.\n\nFile: includes/form.inc", "response": "function drupal_prepare_form($form_id, &$form, &$form_state) {\n global $user;\n\n $form['#type'] = 'form';\n $form_state['programmed'] = isset($form_state['programmed']) ? $form_state['programmed'] : FALSE;\n\n // Fix the form method, if it is 'get' in $form_state, but not in $form.\n if ($form_state['method'] == 'get' && !isset($form['#method'])) {\n $form['#method'] = 'get';\n }\n\n // Generate a new #build_id for this form, if none has been set already. The\n // form_build_id is used as key to cache a particular build of the form. For\n // multi-step forms, this allows the user to go back to an earlier build, make\n // changes, and re-submit.\n // @see drupal_build_form()\n // @see drupal_rebuild_form()\n if (!isset($form['#build_id'])) {\n $form['#build_id'] = 'form-' . drupal_random_key();\n }\n $form['form_build_id'] = array(\n '#type' => 'hidden',\n '#value' => $form['#build_id'],\n '#id' => $form['#build_id'],\n '#name' => 'form_build_id',\n // Form processing and validation requires this value, so ensure the\n // submitted form value appears literally, regardless of custom #tree\n // and #parents being set elsewhere.\n '#parents' => array('form_build_id'),\n );\n\n // Add a token, based on either #token or form_id, to any form displayed to\n // authenticated users. This ensures that any submitted form was actually\n // requested previously by the user and protects against cross site request\n // forgeries.\n // This does not apply to programmatically submitted forms. Furthermore, since\n // tokens are session-bound and forms displayed to anonymous users are very\n // likely cached, we cannot assign a token for them.\n // During installation, there is no $user yet.\n if (!empty($user->uid) && !$form_state['programmed']) {\n // Form constructors may explicitly set #token to FALSE when cross site\n // request forgery is irrelevant to the form, such as search forms.\n if (isset($form['#token']) && $form['#token'] === FALSE) {\n unset($form['#token']);\n }\n // Otherwise, generate a public token based on the form id.\n else {\n $form['#token'] = $form_id;\n $form['form_token'] = array(\n '#id' => drupal_html_id('edit-' . $form_id . '-form-token'),\n '#type' => 'token',\n '#default_value' => drupal_get_token($form['#token']),\n // Form processing and validation requires this value, so ensure the\n // submitted form value appears literally, regardless of custom #tree\n // and #parents being set elsewhere.\n '#parents' => array('form_token'),\n );\n }\n }\n\n if (isset($form_id)) {\n $form['form_id'] = array(\n '#type' => 'hidden',\n '#value' => $form_id,\n '#id' => drupal_html_id(\"edit-$form_id\"),\n // Form processing and validation requires this value, so ensure the\n // submitted form value appears literally, regardless of custom #tree\n // and #parents being set elsewhere.\n '#parents' => array('form_id'),\n );\n }\n if (!isset($form['#id'])) {\n $form['#id'] = drupal_html_id($form_id);\n }\n\n $form += element_info('form');\n $form += array('#tree' => FALSE, '#parents' => array());\n\n if (!isset($form['#validate'])) {\n // Ensure that modules can rely on #validate being set.\n $form['#validate'] = array();\n // Check for a handler specific to $form_id.\n if (function_exists($form_id . '_validate')) {\n $form['#validate'][] = $form_id . '_validate';\n }\n // Otherwise check whether this is a shared form and whether there is a\n // handler for the shared $form_id.\n elseif (isset($form_state['build_info']['base_form_id']) && function_exists($form_state['build_info']['base_form_id'] . '_validate')) {\n $form['#validate'][] = $form_state['build_info']['base_form_id'] . '_validate';\n }\n }\n\n if (!isset($form['#submit'])) {\n // Ensure that modules can rely on #submit being set.\n $form['#submit'] = array();\n // Check for a handler specific to $form_id.\n if (function_exists($form_id . '_submit')) {\n $form['#submit'][] = $form_id . '_submit';\n }\n // Otherwise check whether this is a shared form and whether there is a\n // handler for the shared $form_id.\n elseif (isset($form_state['build_info']['base_form_id']) && function_exists($form_state['build_info']['base_form_id'] . '_submit')) {\n $form['#submit'][] = $form_state['build_info']['base_form_id'] . '_submit';\n }\n }\n\n // If no #theme has been set, automatically apply theme suggestions.\n // theme_form() itself is in #theme_wrappers and not #theme. Therefore, the\n // #theme function only has to care for rendering the inner form elements,\n // not the form itself.\n if (!isset($form['#theme'])) {\n $form['#theme'] = array($form_id);\n if (isset($form_state['build_info']['base_form_id'])) {\n $form['#theme'][] = $form_state['build_info']['base_form_id'];\n }\n }\n\n // Invoke hook_form_alter(), hook_form_BASE_FORM_ID_alter(), and\n // hook_form_FORM_ID_alter() implementations.\n $hooks = array('form');\n if (isset($form_state['build_info']['base_form_id'])) {\n $hooks[] = 'form_' . $form_state['build_info']['base_form_id'];\n }\n $hooks[] = 'form_' . $form_id;\n drupal_alter($hooks, $form, $form_state, $form_id);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e7b76dc361", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_form_system_theme_settings_alter/7.x", "instruction": "Give me the example code for `hook_form_system_theme_settings_alter(&$form, &$form_state)` in Drupal 7. Hook description: Allow themes to alter the theme-specific settings form.", "context": "With this hook, themes can alter the theme-specific settings form in any way allowable by Drupal's Form API, such as adding form elements, changing default values and removing form elements. See the Form API documentation on api.drupal.org for detailed information.\n\nNote that the base theme's form alterations will be run before any sub-theme alterations.\n\nParameters:\n- $form: Nested array of form elements that comprise the form.\n- $form_state: A keyed array containing the current state of the form.\n\nFile: modules/system/theme.api.php", "response": "function hook_form_system_theme_settings_alter(&$form, &$form_state) {\n // Add a checkbox to toggle the breadcrumb trail.\n $form['toggle_breadcrumb'] = array(\n '#type' => 'checkbox',\n '#title' => t('Display the breadcrumb'),\n '#default_value' => theme_get_setting('toggle_breadcrumb'),\n '#description' => t('Show a trail of links from the homepage to the current page.'),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e7dbcedf44", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_delete_menu_page/7.x", "instruction": "I need the code for `menu_delete_menu_page($menu)` in Drupal 7 (modules/menu/menu.admin.inc). It must do this: Menu callback; check access and get a confirm form for deletion of a custom menu.", "context": "File: modules/menu/menu.admin.inc", "response": "function menu_delete_menu_page($menu) {\n // System-defined menus may not be deleted.\n $system_menus = menu_list_system_menus();\n if (isset($system_menus[$menu['menu_name']])) {\n return MENU_ACCESS_DENIED;\n }\n return drupal_get_form('menu_delete_menu_confirm', $menu);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e7ed59a2a4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_last_test_get/7.x", "instruction": "Implement `simpletest_last_test_get($test_id)` in PHP for Drupal 7. Required behavior: Get information about the last test that ran given a test ID.", "context": "Parameters:\n- $test_id: The test ID to get the last test from.\n\nReturns (Array): containing the last database prefix used and the last test class that ran.\n\nFile: modules/simpletest/simpletest.module", "response": "function simpletest_last_test_get($test_id) {\n $last_prefix = db_query_range('SELECT last_prefix FROM {simpletest_test_id} WHERE test_id = :test_id', 0, 1, array(':test_id' => $test_id))->fetchField();\n $last_test_class = db_query_range('SELECT test_class FROM {simpletest} WHERE test_id = :test_id ORDER BY message_id DESC', 0, 1, array(':test_id' => $test_id))->fetchField();\n return array($last_prefix, $last_test_class);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e7fccb7132", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_process_page/7.x", "instruction": "Implement `garland_process_page(&$variables)` in PHP for Drupal 7. Required behavior: Override or insert variables into the page template.", "context": "File: themes/garland/template.php", "response": "function garland_process_page(&$variables) {\n // Hook into color.module\n if (module_exists('color')) {\n _color_page_alter($variables);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8099c23ae", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21syslog%21syslog.module/function/syslog_help/7.x", "instruction": "I need the code for `syslog_help($path, $arg)` in Drupal 7 (modules/syslog/syslog.module). It must do this: Implements hook_help().", "context": "File: modules/syslog/syslog.module", "response": "function syslog_help($path, $arg) {\n switch ($path) {\n case 'admin/help#syslog':\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t(\"The Syslog module logs events by sending messages to the logging facility of your web server's operating system. Syslog is an operating system administrative logging tool that provides valuable information for use in system management and security auditing. Most suited to medium and large sites, Syslog provides filtering tools that allow messages to be routed by type and severity. For more information, see the online handbook entry for Syslog module and PHP's openlog and syslog functions.\", array('@syslog' => 'http://drupal.org/documentation/modules/syslog', '@php_openlog' => 'http://www.php.net/manual/function.openlog.php', '@php_syslog' => 'http://www.php.net/manual/function.syslog.php')) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Logging for UNIX, Linux, and Mac OS X') . '
              ';\n $output .= '
              ' . t('On UNIX, Linux, and Mac OS X, the file /etc/syslog.conf defines the routing configuration. Messages can be flagged with the codes LOG_LOCAL0 through LOG_LOCAL7. For information on Syslog facilities, severity levels, and how to set up syslog.conf, see the syslog.conf manual page on your command line.') . '
              ';\n $output .= '
              ' . t('Logging for Microsoft Windows') . '
              ';\n $output .= '
              ' . t('On Microsoft Windows, messages are always sent to the Event Log using the code LOG_USER.') . '
              ';\n $output .= '
              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8195f0c58", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_format_page/7.x", "instruction": "In Drupal 7, write the function `filter_admin_format_page($format = NULL)` (file modules/filter/filter.admin.inc) so that it does the following: Page callback: Displays the text format add/edit form.", "context": "Parameters:\n- $format (object|null): (optional) An object representing a format, with the following properties: - format: A machine-readable name representing the ID of the text format to save. If this corresponds to an existing text format, that format will be updated; otherwise, a new format will be created. - name: The title of the text format. - cache: (optional) An integer indicating whether the text format is cacheable (1) or not (0). Defaults to 1. - status: (optional) An integer indicating whether the text format is enabled (1) or not (0). Defaults to 1. - weight: (optional) The weight of the text format, which controls its placement in text format lists. If omitted, the weight is set to 0. Defaults to NULL.\n\nReturns: A form array.\n\nFile: modules/filter/filter.admin.inc", "response": "function filter_admin_format_page($format = NULL) {\n if (!isset($format->name)) {\n drupal_set_title(t('Add text format'));\n $format = (object) array(\n 'format' => NULL,\n 'name' => '',\n );\n }\n return drupal_get_form('filter_admin_format_form', $format);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e81fa73c93", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_widget_info/7.x", "instruction": "I need the code for `image_field_widget_info()` in Drupal 7 (modules/image/image.field.inc). It must do this: Implements hook_field_widget_info().", "context": "File: modules/image/image.field.inc", "response": "function image_field_widget_info() {\n return array(\n 'image_image' => array(\n 'label' => t('Image'),\n 'field types' => array('image'),\n 'settings' => array(\n 'progress_indicator' => 'throbber',\n 'preview_image_style' => 'thumbnail',\n ),\n 'behaviors' => array(\n 'multiple values' => FIELD_BEHAVIOR_CUSTOM,\n 'default value' => FIELD_BEHAVIOR_NONE,\n ),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e828a41d22", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/_block_compare/7.x", "instruction": "I need the code for `_block_compare($a, $b)` in Drupal 7 (modules/block/block.admin.inc). It must do this: Sorts active blocks by region, then by weight; sorts inactive blocks by name.", "context": "Callback for usort() in block_admin_display_prepare_blocks().\n\nFile: modules/block/block.admin.inc", "response": "function _block_compare($a, $b) {\n global $theme_key;\n\n // Theme should be set before calling this function, or the current theme\n // is being used.\n $theme = &drupal_static(__FUNCTION__ . ':theme');\n if (!isset($theme)) {\n $theme = $theme_key;\n }\n\n $regions = &drupal_static(__FUNCTION__ . ':regions');\n // We need the region list to correctly order by region.\n if (!isset($regions)) {\n $regions = array_flip(array_keys(system_region_list($theme)));\n $regions[BLOCK_REGION_NONE] = count($regions);\n }\n\n // Separate enabled from disabled.\n $status = $b['status'] - $a['status'];\n if ($status) {\n return $status;\n }\n // Sort by region (in the order defined by theme .info file).\n if ((!empty($a['region']) && !empty($b['region'])) && ($place = ($regions[$a['region']] - $regions[$b['region']]))) {\n return $place;\n }\n // Sort by weight, unless disabled.\n if ($a['region'] != BLOCK_REGION_NONE) {\n $weight = $a['weight'] - $b['weight'];\n if ($weight) {\n return $weight;\n }\n }\n // Sort by title.\n return strcmp($a['info'], $b['info']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e82ac46c32", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_box_form_submit/7.x", "instruction": "I need the code for `search_box_form_submit($form, &$form_state)` in Drupal 7 (modules/search/search.module). It must do this: Process a block search form submission.", "context": "File: modules/search/search.module", "response": "function search_box_form_submit($form, &$form_state) {\n // The search form relies on control of the redirect destination for its\n // functionality, so we override any static destination set in the request,\n // for example by drupal_access_denied() or drupal_not_found()\n // (see http://drupal.org/node/292565).\n if (isset($_GET['destination'])) {\n unset($_GET['destination']);\n }\n\n // Check to see if the form was submitted empty.\n // If it is empty, display an error message.\n // (This method is used instead of setting #required to TRUE for this field\n // because that results in a confusing error message. It would say a plain\n // \"field is required\" because the search keywords field has no title.\n // The error message would also complain about a missing #title field.)\n if ($form_state['values']['search_block_form'] == '') {\n form_set_error('keys', t('Please enter some keywords.'));\n }\n\n $form_id = $form['form_id']['#value'];\n $info = search_get_default_module_info();\n if ($info) {\n $form_state['redirect'] = 'search/' . $info['path'] . '/' . trim($form_state['values'][$form_id]);\n }\n else {\n form_set_error(NULL, t('Search is currently disabled.'), 'error');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e832dcb133", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_form_add_submit/7.x", "instruction": "Implement `image_style_form_add_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Submit handler for adding a new image effect to an image style.", "context": "File: modules/image/image.admin.inc", "response": "function image_style_form_add_submit($form, &$form_state) {\n $style = $form_state['image_style'];\n // Check if this field has any configuration options.\n $effect = image_effect_definition_load($form_state['values']['new']);\n\n // Load the configuration form for this option.\n if (isset($effect['form callback'])) {\n $path = 'admin/config/media/image-styles/edit/' . $form_state['image_style']['name'] . '/add/' . $form_state['values']['new'];\n $form_state['redirect'] = array($path, array('query' => array('weight' => $form_state['values']['weight'])));\n }\n // If there's no form, immediately add the image effect.\n else {\n $effect['isid'] = $style['isid'];\n $effect['weight'] = $form_state['values']['weight'];\n image_effect_save($effect);\n drupal_set_message(t('The image effect was successfully applied.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e83afe9ac5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7060/7.x", "instruction": "Implement `system_update_7060()` in PHP for Drupal 7. Required behavior: Create fields in preparation for migrating upload.module to file.module.", "context": "File: modules/system/system.install", "response": "function system_update_7060() {\n if (!db_table_exists('upload')) {\n return;\n }\n\n if (!db_query_range('SELECT 1 FROM {upload}', 0, 1)->fetchField()) {\n // There is nothing to migrate. Delete variables and the empty table. There\n // is no need to create fields that are not going to be used.\n foreach (_update_7000_node_get_types() as $node_type) {\n variable_del('upload_' . $node_type->type);\n }\n db_drop_table('upload');\n return;\n }\n\n // Check which node types have upload.module attachments enabled.\n $context['types'] = array();\n foreach (_update_7000_node_get_types() as $node_type) {\n if (variable_get('upload_' . $node_type->type, 0)) {\n $context['types'][$node_type->type] = $node_type->type;\n }\n }\n\n // The {upload} table will be deleted when this update is complete so we\n // want to be careful to migrate all the data, even for node types that\n // may have had attachments disabled after files were uploaded. Look for\n // any other node types referenced by the upload records and add those to\n // the list. The admin can always remove the field later.\n $results = db_query('SELECT DISTINCT type FROM {node} n INNER JOIN {node_revision} nr ON n.nid = nr.nid INNER JOIN {upload} u ON nr.vid = u.vid');\n foreach ($results as $row) {\n if (!isset($context['types'][$row->type])) {\n drupal_set_message(t('The content type %rowtype had uploads disabled but contained uploaded file data. Uploads have been re-enabled to migrate the existing data. You may delete the \"File attachments\" field in the %rowtype type if this data is not necessary.', array('%rowtype' => $row->type)));\n $context['types'][$row->type] = $row->type;\n }\n }\n\n // Create a single \"upload\" field on all the content types that have uploads\n // enabled, then add an instance to each enabled type.\n if (count($context['types']) > 0) {\n module_enable(array('file'));\n $field = array(\n 'field_name' => 'upload',\n 'type' => 'file',\n 'module' => 'file',\n 'locked' => FALSE,\n 'cardinality' => FIELD_CARDINALITY_UNLIMITED,\n 'translatable' => FALSE,\n 'settings' => array(\n 'display_field' => 1,\n 'display_default' => variable_get('upload_list_default', 1),\n 'uri_scheme' => file_default_scheme(),\n 'default_file' => 0,\n ),\n );\n\n $upload_size = variable_get('upload_uploadsize_default', 1);\n $instance = array(\n 'field_name' => 'upload',\n 'entity_type' => 'node',\n 'bundle' => NULL,\n 'label' => 'File attachments',\n 'required' => 0,\n 'description' => '',\n 'widget' => array(\n 'weight' => '1',\n 'settings' => array(\n 'progress_indicator' => 'throbber',\n ),\n 'type' => 'file_generic',\n ),\n 'settings' => array(\n 'max_filesize' => $upload_size ? ($upload_size . ' MB') : '',\n 'file_extensions' => variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'),\n 'file_directory' => '',\n 'description_field' => 1,\n ),\n 'display' => array(\n 'default' => array(\n 'label' => 'hidden',\n 'type' => 'file_table',\n 'settings' => array(),\n 'weight' => 0,\n 'module' => 'file',\n ),\n 'full' => array(\n 'label' => 'hidden',\n 'type' => 'file_table',\n 'settings' => array(),\n 'weight' => 0,\n 'module' => 'file',\n ),\n 'teaser' => array(\n 'label' => 'hidden',\n 'type' => 'hidden',\n 'settings' => array(),\n 'weight' => 0,\n 'module' => NULL,\n ),\n 'rss' => array(\n 'label' => 'hidden',\n 'type' => 'file_table',\n 'settings' => array(),\n 'weight' => 0,\n 'module' => 'file',\n ),\n ),\n );\n\n // Create the field.\n _update_7000_field_create_field($field);\n\n // Create the instances.\n foreach ($context['types'] as $bundle) {\n $instance['bundle'] = $bundle;\n _update_7000_field_create_instance($field, $instance);\n // Now that the instance is created, we can safely delete any legacy\n // node type information.\n variable_del('upload_' . $bundle);\n }\n }\n else {\n // No uploads or content types with uploads enabled.\n db_drop_table('upload');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8863048ec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_help/7.x", "instruction": "In Drupal 7, write the function `toolbar_help($path, $arg)` (file modules/toolbar/toolbar.module) so that it does the following: Implements hook_help().", "context": "File: modules/toolbar/toolbar.module", "response": "function toolbar_help($path, $arg) {\n switch ($path) {\n case 'admin/help#toolbar':\n $output = '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The Toolbar module displays links to top-level administration menu items and links from other modules at the top of the screen. For more information, see the online handbook entry for Toolbar module.', array('@toolbar' => 'http://drupal.org/documentation/modules/toolbar/')) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Displaying administrative links') . '
              ';\n $output .= '
              ' . t('The Toolbar module displays a bar containing top-level administrative links across the top of the screen. Below that, the Toolbar module has a drawer section where it displays links provided by other modules, such as the core Shortcut module. The drawer can be hidden/shown by using the show/hide shortcuts link at the end of the toolbar.', array('@shortcuts-help' => url('admin/help/shortcut'))) . '
              ';\n $output .= '
              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e88e6611d2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_shorten_comments/7.x", "instruction": "In Drupal 7, write the function `_locale_import_shorten_comments($comment)` (file includes/locale.inc) so that it does the following: Generate a short, one string version of the passed comment array", "context": "Parameters:\n- $comment: An array of strings containing a comment.\n\nReturns: Short one string version of the comment.\n\nFile: includes/locale.inc", "response": "function _locale_import_shorten_comments($comment) {\n $comm = '';\n while (count($comment)) {\n $test = $comm . substr(array_shift($comment), 1) . ', ';\n if (strlen($comm) < 130) {\n $comm = $test;\n }\n else {\n break;\n }\n }\n return trim(substr($comm, 0, -2));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8abb7fad5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_breadcrumb/7.x", "instruction": "I need the code for `theme_breadcrumb($variables)` in Drupal 7 (includes/theme.inc). It must do this: Returns HTML for a breadcrumb trail.", "context": "Parameters:\n- $variables: An associative array containing: - breadcrumb: An array containing the breadcrumb links.\n\nFile: includes/theme.inc", "response": "function theme_breadcrumb($variables) {\n $breadcrumb = $variables['breadcrumb'];\n\n if (!empty($breadcrumb)) {\n // Provide a navigational heading to give context for breadcrumb links to\n // screen-reader users. Make the heading invisible with .element-invisible.\n $output = '

              ' . t('You are here') . '

              ';\n\n $output .= '
              ' . implode(' » ', $breadcrumb) . '
              ';\n return $output;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8aff8c8e7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_refresh/7.x", "instruction": "I need the code for `update_refresh()` in Drupal 7 (modules/update/update.module). It must do this: Refreshes the release data after loading the necessary include file.", "context": "File: modules/update/update.module", "response": "function update_refresh() {\n module_load_include('inc', 'update', 'update.fetch');\n return _update_refresh();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8cb1c5555", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21session.inc/function/drupal_session_commit/7.x", "instruction": "In Drupal 7, write the function `drupal_session_commit()` (file includes/session.inc) so that it does the following: Commits the current session, if necessary.", "context": "If an anonymous user already have an empty session, destroy it.\n\nFile: includes/session.inc", "response": "function drupal_session_commit() {\n global $user, $is_https;\n\n if (!drupal_save_session()) {\n // We don't have anything to do if we are not allowed to save the session.\n return;\n }\n\n if (empty($user->uid) && empty($_SESSION)) {\n // There is no session data to store, destroy the session if it was\n // previously started.\n if (drupal_session_started()) {\n session_destroy();\n }\n }\n else {\n // There is session data to store. Start the session if it is not already\n // started.\n if (!drupal_session_started()) {\n drupal_session_start();\n if ($is_https && variable_get('https', FALSE)) {\n $insecure_session_name = substr(session_name(), 1);\n $params = session_get_cookie_params();\n $expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;\n $options = array(\n 'expires' => $expire,\n 'path' => $params['path'],\n 'domain' => $params['domain'],\n 'secure' => FALSE,\n 'httponly' => $params['httponly'],\n );\n drupal_setcookie($insecure_session_name, $_COOKIE[$insecure_session_name], $options);\n }\n }\n // Write the session data.\n session_write_close();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8e2f5cd15", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_unmanaged_move/7.x", "instruction": "In Drupal 7, write the function `file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXISTS_RENAME)` (file includes/file.inc) so that it does the following: Moves a file to a new location without database changes or hook invocation.", "context": "Parameters:\n- $source: A string specifying the filepath or URI of the original file.\n- $destination: A string containing the destination that $source should be moved to. This must be a stream wrapper URI. If this value is omitted, Drupal's default files scheme will be used, usually \"public://\".\n- $replace: Replace behavior when the destination file already exists: - FILE_EXISTS_REPLACE - Replace the existing file. - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique. - FILE_EXISTS_ERROR - Do nothing and return FALSE.\n\nReturns: The URI of the moved file, or FALSE in the event of an error.\n\nFile: includes/file.inc", "response": "function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {\n $filepath = file_unmanaged_copy($source, $destination, $replace);\n if ($filepath == FALSE || file_unmanaged_delete($source) == FALSE) {\n return FALSE;\n }\n return $filepath;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8e47d479e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/valid_email_address/7.x", "instruction": "I need the code for `valid_email_address($mail)` in Drupal 7 (includes/common.inc). It must do this: Verifies the syntax of the given e-mail address.", "context": "This uses the\n\nParameters:\n- $mail: A string containing an e-mail address.\n\nReturns: TRUE if the address is in a valid format.\n\nFile: includes/common.inc", "response": "function valid_email_address($mail) {\n $valid = (bool) filter_var($mail, FILTER_VALIDATE_EMAIL);\n drupal_alter('valid_email_address', $valid, $mail);\n return $valid;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e8f68a0352", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.api.php/function/hook_update_status_alter/7.x", "instruction": "Give me the example code for `hook_update_status_alter(&$projects)` in Drupal 7. Hook description: Alter the information about available updates for projects.", "context": "Parameters:\n- $projects: Reference to an array of information about available updates to each project installed on the system.\n\nFile: modules/update/update.api.php", "response": "function hook_update_status_alter(&$projects) {\n $settings = variable_get('update_advanced_project_settings', array());\n foreach ($projects as $project => $project_info) {\n if (isset($settings[$project]) && isset($settings[$project]['check']) &&\n ($settings[$project]['check'] == 'never' ||\n (isset($project_info['recommended']) &&\n $settings[$project]['check'] === $project_info['recommended']))) {\n $projects[$project]['status'] = UPDATE_NOT_CHECKED;\n $projects[$project]['reason'] = t('Ignored from settings');\n if (!empty($settings[$project]['notes'])) {\n $projects[$project]['extra'][] = array(\n 'class' => array('admin-note'),\n 'label' => t('Administrator note'),\n 'data' => $settings[$project]['notes'],\n );\n }\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9348567f0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_unmanaged_delete/7.x", "instruction": "In Drupal 7, write the function `file_unmanaged_delete($path)` (file includes/file.inc) so that it does the following: Deletes a file without database changes or hook invocations.", "context": "This function should be used when the file to be deleted does not have an entry recorded in the files table.\n\nParameters:\n- $path: A string containing a file path or (streamwrapper) URI.\n\nReturns: TRUE for success or path does not exist, or FALSE in the event of an error.\n\nFile: includes/file.inc", "response": "function file_unmanaged_delete($path) {\n if (is_dir($path)) {\n watchdog('file', '%path is a directory and cannot be removed using file_unmanaged_delete().', array('%path' => $path), WATCHDOG_ERROR);\n return FALSE;\n }\n if (is_file($path)) {\n return drupal_unlink($path);\n }\n // Return TRUE for non-existent file, but log that nothing was actually\n // deleted, as the current state is the intended result.\n if (!file_exists($path)) {\n watchdog('file', 'The file %path was not deleted, because it does not exist.', array('%path' => $path), WATCHDOG_NOTICE);\n return TRUE;\n }\n // We cannot handle anything other than files and directories. Log an error\n // for everything else (sockets, symbolic links, etc).\n watchdog('file', 'The file %path is not of a recognized type so it was not deleted.', array('%path' => $path), WATCHDOG_ERROR);\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e94cf22b56", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.module/function/list_allowed_values_setting_validate/7.x", "instruction": "Implement `list_allowed_values_setting_validate($element, &$form_state)` in PHP for Drupal 7. Required behavior: Element validate callback; check that the entered values are valid.", "context": "File: modules/field/modules/list/list.module", "response": "function list_allowed_values_setting_validate($element, &$form_state) {\n $field = $element['#field'];\n $has_data = $element['#field_has_data'];\n $field_type = $field['type'];\n $generate_keys = ($field_type == 'list_integer' || $field_type == 'list_float') && !$has_data;\n\n $values = list_extract_allowed_values($element['#value'], $field['type'], $generate_keys);\n\n if (!is_array($values)) {\n form_error($element, t('Allowed values list: invalid input.'));\n }\n else {\n // Check that keys are valid for the field type.\n foreach ($values as $key => $value) {\n if ($field_type == 'list_integer' && !preg_match('/^-?\\d+$/', $key)) {\n form_error($element, t('Allowed values list: keys must be integers.'));\n break;\n }\n if ($field_type == 'list_float' && !is_numeric($key)) {\n form_error($element, t('Allowed values list: each key must be a valid integer or decimal.'));\n break;\n }\n elseif ($field_type == 'list_text' && drupal_strlen($key) > 255) {\n form_error($element, t('Allowed values list: each key must be a string at most 255 characters long.'));\n break;\n }\n }\n\n // Prevent removing values currently in use.\n if ($has_data) {\n $lost_keys = array_diff(array_keys($field['settings']['allowed_values']), array_keys($values));\n if (_list_values_in_use($field, $lost_keys)) {\n form_error($element, t('Allowed values list: some values are being removed while currently in use.'));\n }\n }\n\n form_set_value($element, $values, $form_state);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9518fff95", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_login_submit/7.x", "instruction": "In Drupal 7, write the function `user_login_submit($form, &$form_state)` (file modules/user/user.module) so that it does the following: Submit handler for the login form. Load $user object and perform standard login tasks. The user is then redirected to the My Account page. Setting the destination in the query string overrides the redirect.", "context": "File: modules/user/user.module", "response": "function user_login_submit($form, &$form_state) {\n global $user;\n $user = user_load($form_state['uid']);\n $form_state['redirect'] = 'user/' . $user->uid;\n\n user_login_finalize($form_state);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9650a100e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_get_file_references/7.x", "instruction": "I need the code for `file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file', $check_access = TRUE)` in Drupal 7 (modules/file/file.module). It must do this: Retrieves a list of references to a file.", "context": "Parameters:\n- $file: A file object.\n- $field: (optional) A field array to be used for this check. If given, limits the reference check to the given field.\n- $age: (optional) A constant that specifies which references to count. Use FIELD_LOAD_REVISION to retrieve all references within all revisions or FIELD_LOAD_CURRENT to retrieve references only in the current revisions.\n- $field_type: (optional) The name of a field type. If given, limits the reference check to fields of the given type.\n- $check_access: (optional) A boolean that specifies whether the permissions of the current user should be checked when retrieving references. If FALSE, all references to the file are returned. If TRUE, only references from entities that the current user has access to are returned. Defaults to TRUE for backwards compatibility reasons, but FALSE is recommended for most situations.\n\nReturns: An integer value.\n\nFile: modules/file/file.module", "response": "function file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file', $check_access = TRUE) {\n $references = drupal_static(__FUNCTION__, array());\n $fields = isset($field) ? array($field['field_name'] => $field) : field_info_fields();\n\n foreach ($fields as $field_name => $file_field) {\n if ((empty($field_type) || $file_field['type'] == $field_type) && !isset($references[$field_name])) {\n // Get each time this file is used within a field.\n $query = new EntityFieldQuery();\n $query\n ->fieldCondition($file_field, 'fid', $file->fid)\n ->age($age);\n if (!$check_access) {\n // Neutralize the 'entity_field_access' query tag added by\n // field_sql_storage_field_storage_query().\n $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');\n }\n $references[$field_name] = $query->execute();\n }\n }\n\n return isset($field) ? $references[$field['field_name']] : array_filter($references);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e96a9d890e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_http_header_attributes/7.x", "instruction": "In Drupal 7, write the function `drupal_http_header_attributes(array $attributes = array())` (file includes/common.inc) so that it does the following: Formats an attribute string for an HTTP header.", "context": "Parameters:\n- $attributes: An associative array of attributes such as 'rel'.\n\nReturns: A ; separated string ready for insertion in a HTTP header. No escaping is performed for HTML entities, so this string is not safe to be printed.\n\nFile: includes/common.inc", "response": "function drupal_http_header_attributes(array $attributes = array()) {\n foreach ($attributes as $attribute => &$data) {\n if (is_array($data)) {\n $data = implode(' ', $data);\n }\n $data = $attribute . '=\"' . $data . '\"';\n }\n return $attributes ? ' ' . implode('; ', $attributes) : '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9a51e285b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_active_breadcrumb/7.x", "instruction": "Implement `menu_get_active_breadcrumb()` in PHP for Drupal 7. Required behavior: Gets the breadcrumb for the current page, as determined by the active trail.", "context": "File: includes/menu.inc", "response": "function menu_get_active_breadcrumb() {\n $breadcrumb = array();\n\n // No breadcrumb for the front page.\n if (drupal_is_front_page()) {\n return $breadcrumb;\n }\n\n $item = menu_get_item();\n if (!empty($item['access'])) {\n $active_trail = menu_get_active_trail();\n\n // Allow modules to alter the breadcrumb, if possible, as that is much\n // faster than rebuilding an entirely new active trail.\n drupal_alter('menu_breadcrumb', $active_trail, $item);\n\n // Don't show a link to the current page in the breadcrumb trail.\n $end = end($active_trail);\n if (is_array($end) && $item['href'] == $end['href']) {\n array_pop($active_trail);\n }\n\n // Remove the tab root (parent) if the current path links to its parent.\n // Normally, the tab root link is included in the breadcrumb, as soon as we\n // are on a local task or any other child link. However, if we are on a\n // default local task (e.g., node/%/view), then we do not want the tab root\n // link (e.g., node/%) to appear, as it would be identical to the current\n // page. Since this behavior also needs to work recursively (i.e., on\n // default local tasks of default local tasks), and since the last non-task\n // link in the trail is used as page title (see menu_get_active_title()),\n // this condition cannot be cleanly integrated into menu_get_active_trail().\n // menu_get_active_trail() already skips all links that link to their parent\n // (commonly MENU_DEFAULT_LOCAL_TASK). In order to also hide the parent link\n // itself, we always remove the last link in the trail, if the current\n // router item links to its parent.\n if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) {\n array_pop($active_trail);\n }\n\n foreach ($active_trail as $parent) {\n $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);\n }\n }\n return $breadcrumb;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9aef457b5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21errors.inc/function/_drupal_log_error/7.x", "instruction": "Implement `_drupal_log_error($error, $fatal = FALSE)` in PHP for Drupal 7. Required behavior: Logs a PHP error or exception and displays an error page in fatal cases.", "context": "Parameters:\n- $error: An array with the following keys: %type, !message, %function, %file, %line and severity_level. All the parameters are plain-text, with the exception of !message, which needs to be a safe HTML string.\n- $fatal: TRUE if the error is fatal.\n\nFile: includes/errors.inc", "response": "function _drupal_log_error($error, $fatal = FALSE) {\n // Initialize a maintenance theme if the bootstrap was not complete.\n // Do it early because drupal_set_message() triggers a drupal_theme_initialize().\n if ($fatal && (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL)) {\n unset($GLOBALS['theme']);\n if (!defined('MAINTENANCE_MODE')) {\n define('MAINTENANCE_MODE', 'error');\n }\n drupal_maintenance_theme();\n }\n\n // When running inside the testing framework, we relay the errors\n // to the tested site by the way of HTTP headers.\n $test_info = &$GLOBALS['drupal_test_info'];\n if (!empty($test_info['in_child_site']) && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {\n // $number does not use drupal_static as it should not be reset\n // as it uniquely identifies each PHP error.\n static $number = 0;\n $assertion = array(\n $error['!message'],\n $error['%type'],\n array(\n 'function' => $error['%function'],\n 'file' => $error['%file'],\n 'line' => $error['%line'],\n ),\n );\n header('X-Drupal-Assertion-' . $number . ': ' . rawurlencode(serialize($assertion)));\n $number++;\n }\n\n // Log the error immediately, unless this is a non-fatal error which has been\n // triggered via drupal_trigger_error_with_delayed_logging(); in that case\n // trigger it in a shutdown function. Fatal errors are always triggered\n // immediately since for a fatal error the page request will end here anyway.\n if (!$fatal && drupal_static('_drupal_trigger_error_with_delayed_logging')) {\n drupal_register_shutdown_function('watchdog', 'php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);\n }\n else {\n watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);\n }\n\n if ($fatal) {\n drupal_add_http_header('Status', '500 Service unavailable (with message)');\n }\n\n if (drupal_is_cli()) {\n if ($fatal) {\n // When called from CLI, simply output a plain text message.\n print html_entity_decode(strip_tags(t('%type: !message in %function (line %line of %file).', $error))). \"\\n\";\n exit(1);\n }\n }\n\n if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {\n if ($fatal) {\n if (error_displayable($error)) {\n // When called from JavaScript, simply output the error message.\n print t('%type: !message in %function (line %line of %file).', _drupal_strip_error_file_path($error));\n }\n exit;\n }\n }\n else {\n // Display the message if the current error reporting level allows this type\n // of message to be displayed, and unconditionally in update.php.\n if (error_displayable($error)) {\n $class = 'error';\n\n // If error type is 'User notice' then treat it as debug information\n // instead of an error message, see dd().\n if ($error['%type'] == 'User notice') {\n $error['%type'] = 'Debug';\n $class = 'status';\n }\n\n drupal_set_message(t('%type: !message in %function (line %line of %file).', _drupal_strip_error_file_path($error)), $class);\n }\n\n if ($fatal) {\n drupal_set_title(t('Error'));\n // We fallback to a maintenance page at this point, because the page generation\n // itself can generate errors.\n print theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.')));\n exit;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9c4207f16", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_textarea_value/7.x", "instruction": "I need the code for `form_type_textarea_value($element, $input = FALSE)` in Drupal 7 (includes/form.inc). It must do this: Determines the value for a textarea form element.", "context": "Parameters:\n- $element (array): The form element whose value is being populated.\n- $input (mixed): The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.\n\nReturns (string): The data that will appear in $form_state['values'] for this element, or nothing to use the default.\n\nFile: includes/form.inc", "response": "function form_type_textarea_value($element, $input = FALSE) {\n if ($input !== FALSE && $input !== NULL) {\n // This should be a string, but allow other scalars since they might be\n // valid input in programmatic form submissions.\n return is_scalar($input) ? (string) $input : '';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9d6f7e237", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_theme/7.x", "instruction": "In Drupal 7, write the function `node_theme()` (file modules/node/node.module) so that it does the following: Implements hook_theme().", "context": "File: modules/node/node.module", "response": "function node_theme() {\n return array(\n 'node' => array(\n 'render element' => 'elements',\n 'template' => 'node',\n ),\n 'node_search_admin' => array(\n 'render element' => 'form',\n ),\n 'node_add_list' => array(\n 'variables' => array('content' => NULL),\n 'file' => 'node.pages.inc',\n ),\n 'node_preview' => array(\n 'variables' => array('node' => NULL),\n 'file' => 'node.pages.inc',\n ),\n 'node_admin_overview' => array(\n 'variables' => array('name' => NULL, 'type' => NULL),\n 'file' => 'content_types.inc',\n ),\n 'node_recent_block' => array(\n 'variables' => array('nodes' => NULL),\n ),\n 'node_recent_content' => array(\n 'variables' => array('node' => NULL),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9eb714d2a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_info/7.x", "instruction": "Give me the example code for `hook_field_storage_info()` in Drupal 7. Hook description: Expose Field API storage backends.", "context": "Returns: An array describing the storage backends implemented by the module. The keys are storage backend names. To avoid name clashes, storage backend names should be prefixed with the name of the module that exposes them. The values are arrays describing the storage backend, with the following key/value pairs: - label: The human-readable name of the storage backend. - description: A short description for the storage backend. - settings: An array whose keys are the names of the settings available for the storage backend, and whose values are the default values for those settings.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_info() {\n return array(\n 'field_sql_storage' => array(\n 'label' => t('Default SQL storage'),\n 'description' => t('Stores fields in the local SQL database, using per-field tables.'),\n 'settings' => array(),\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9f1bd3df6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/simpletest_result_form_submit/7.x", "instruction": "Implement `simpletest_result_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Re-run the tests that match the filter.", "context": "File: modules/simpletest/simpletest.pages.inc", "response": "function simpletest_result_form_submit($form, &$form_state) {\n $pass = $form_state['values']['filter_pass'] ? explode(',', $form_state['values']['filter_pass']) : array();\n $fail = $form_state['values']['filter_fail'] ? explode(',', $form_state['values']['filter_fail']) : array();\n\n if ($form_state['values']['filter'] == 'all') {\n $classes = array_merge($pass, $fail);\n }\n elseif ($form_state['values']['filter'] == 'pass') {\n $classes = $pass;\n }\n else {\n $classes = $fail;\n }\n\n if (!$classes) {\n $form_state['redirect'] = 'admin/config/development/testing';\n return;\n }\n\n $form_state_execute = array('values' => array());\n foreach ($classes as $class) {\n $form_state_execute['values'][$class] = 1;\n }\n\n simpletest_test_form_submit(array(), $form_state_execute);\n $form_state['redirect'] = $form_state_execute['redirect'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9f65c882b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_update_7006/7.x", "instruction": "In Drupal 7, write the function `comment_update_7006(&$sandbox)` (file modules/comment/comment.install) so that it does the following: Migrate data from the comment field to field storage.", "context": "File: modules/comment/comment.install", "response": "function comment_update_7006(&$sandbox) {\n // This is a multipass update. First set up some comment variables.\n if (empty($sandbox['total'])) {\n $comments = (bool) db_query_range('SELECT 1 FROM {comment}', 0, 1)->fetchField();\n $sandbox['types'] = array();\n if ($comments) {\n $sandbox['types'] = array_keys(_update_7000_node_get_types());\n }\n $sandbox['total'] = count($sandbox['types']);\n }\n\n if (!empty($sandbox['types'])) {\n $type = array_shift($sandbox['types']);\n\n $query = db_select('comment', 'c');\n $query->innerJoin('node', 'n', 'c.nid = n.nid AND n.type = :type', array(':type' => $type));\n $query->addField('c', 'cid', 'entity_id');\n $query->addExpression(\"'comment_node_$type'\", 'bundle');\n $query->addExpression(\"'comment'\", 'entity_type');\n $query->addExpression('0', 'deleted');\n $query->addExpression(\"'\" . LANGUAGE_NONE . \"'\", 'language');\n $query->addExpression('0', 'delta');\n $query->addField('c', 'comment', 'comment_body_value');\n $query->addField('c', 'format', 'comment_body_format');\n\n db_insert('field_data_comment_body')\n ->from($query)\n ->execute();\n\n $sandbox['#finished'] = 1 - count($sandbox['types']) / $sandbox['total'];\n }\n\n // On the last pass of the update, $sandbox['types'] will be empty.\n if (empty($sandbox['types'])) {\n // Update the comment body text formats. For an explanation of these\n // updates, see the code comments in user_update_7010().\n db_update('field_data_comment_body')\n ->fields(array('comment_body_format' => NULL))\n ->condition('comment_body_value', '')\n ->condition('comment_body_format', 0)\n ->execute();\n $existing_formats = db_query(\"SELECT format FROM {filter_format}\")->fetchCol();\n $default_format = variable_get('filter_default_format', 1);\n db_update('field_data_comment_body')\n ->fields(array('comment_body_format' => $default_format))\n ->isNotNull('comment_body_format')\n ->condition('comment_body_format', $existing_formats, 'NOT IN')\n ->execute();\n\n // Finally, remove the old comment data.\n db_drop_field('comment', 'comment');\n db_drop_field('comment', 'format');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-e9f74fde7f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_pick_book_nojs_submit/7.x", "instruction": "I need the code for `book_pick_book_nojs_submit($form, &$form_state)` in Drupal 7 (modules/book/book.module). It must do this: Form submission handler for node_form().", "context": "This handler is run when JavaScript is disabled. It triggers the form to rebuild so that the \"Parent item\" options are changed to reflect the newly selected book. When JavaScript is enabled, the submit button that triggers this handler is hidden, and the \"Book\" dropdown directly triggers the book_form_update() Ajax callback instead.\n\nFile: modules/book/book.module", "response": "function book_pick_book_nojs_submit($form, &$form_state) {\n $form_state['node']->book = $form_state['values']['book'];\n $form_state['rebuild'] = TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea04688fec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/theme_field_ui_table/7.x", "instruction": "In Drupal 7, write the function `theme_field_ui_table($variables)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Returns HTML for Field UI overview tables.", "context": "Parameters:\n- $variables: An associative array containing: - elements: An associative array containing a Form API structure to be rendered as a table.\n\nFile: modules/field_ui/field_ui.admin.inc", "response": "function theme_field_ui_table($variables) {\n $elements = $variables['elements'];\n $table = array();\n $js_settings = array();\n\n // Add table headers and attributes.\n foreach (array('header', 'attributes') as $key) {\n if (isset($elements[\"#$key\"])) {\n $table[$key] = $elements[\"#$key\"];\n }\n }\n\n // Determine the colspan to use for region rows, by checking the number of\n // columns in the headers.\n $columns_count = 0;\n foreach ($table['header'] as $header) {\n $columns_count += (is_array($header) && isset($header['colspan']) ? $header['colspan'] : 1);\n }\n\n // Render rows, region by region.\n foreach ($elements['#regions'] as $region_name => $region) {\n $region_name_class = drupal_html_class($region_name);\n\n // Add region rows.\n if (isset($region['title'])) {\n $table['rows'][] = array(\n 'class' => array('region-title', 'region-' . $region_name_class . '-title'),\n 'no_striping' => TRUE,\n 'data' => array(\n array('data' => $region['title'], 'colspan' => $columns_count),\n ),\n );\n }\n if (isset($region['message'])) {\n $class = (empty($region['rows_order']) ? 'region-empty' : 'region-populated');\n $table['rows'][] = array(\n 'class' => array('region-message', 'region-' . $region_name_class . '-message', $class),\n 'no_striping' => TRUE,\n 'data' => array(\n array('data' => $region['message'], 'colspan' => $columns_count),\n ),\n );\n }\n\n // Add form rows, in the order determined at pre-render time.\n foreach ($region['rows_order'] as $name) {\n $element = $elements[$name];\n\n $row = array('data' => array());\n if (isset($element['#attributes'])) {\n $row += $element['#attributes'];\n }\n\n // Render children as table cells.\n foreach (element_children($element) as $cell_key) {\n $child = &$element[$cell_key];\n // Do not render a cell for children of #type 'value'.\n if (!(isset($child['#type']) && $child['#type'] == 'value')) {\n $cell = array('data' => drupal_render($child));\n if (isset($child['#cell_attributes'])) {\n $cell += $child['#cell_attributes'];\n }\n $row['data'][] = $cell;\n }\n }\n $table['rows'][] = $row;\n }\n }\n\n return theme('table', $table);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea2038105d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.pages.inc/function/simpletest_settings_form/7.x", "instruction": "I need the code for `simpletest_settings_form($form, &$form_state)` in Drupal 7 (modules/simpletest/simpletest.pages.inc). It must do this: Provides settings form for SimpleTest variables.", "context": "File: modules/simpletest/simpletest.pages.inc", "response": "function simpletest_settings_form($form, &$form_state) {\n $form['general'] = array(\n '#type' => 'fieldset',\n '#title' => t('General'),\n );\n $form['general']['simpletest_clear_results'] = array(\n '#type' => 'checkbox',\n '#title' => t('Clear results after each complete test suite run'),\n '#description' => t('By default SimpleTest will clear the results after they have been viewed on the results page, but in some cases it may be useful to leave the results in the database. The results can then be viewed at admin/config/development/testing/results/[test_id]. The test ID can be found in the database, simpletest table, or kept track of when viewing the results the first time. Additionally, some modules may provide more analysis or features that require this setting to be disabled.'),\n '#default_value' => variable_get('simpletest_clear_results', TRUE),\n );\n $form['general']['simpletest_verbose'] = array(\n '#type' => 'checkbox',\n '#title' => t('Provide verbose information when running tests'),\n '#description' => t('The verbose data will be printed along with the standard assertions and is useful for debugging. The verbose data will be erased between each test suite run. The verbose data output is very detailed and should only be used when debugging.'),\n '#default_value' => variable_get('simpletest_verbose', TRUE),\n );\n\n $form['httpauth'] = array(\n '#type' => 'fieldset',\n '#title' => t('HTTP authentication'),\n '#description' => t('HTTP auth settings to be used by the SimpleTest browser during testing. Useful when the site requires basic HTTP authentication.'),\n '#collapsible' => TRUE,\n '#collapsed' => TRUE,\n );\n $form['httpauth']['simpletest_httpauth_method'] = array(\n '#type' => 'select',\n '#title' => t('Method'),\n '#options' => array(\n CURLAUTH_BASIC => t('Basic'),\n CURLAUTH_DIGEST => t('Digest'),\n CURLAUTH_GSSNEGOTIATE => t('GSS negotiate'),\n CURLAUTH_NTLM => t('NTLM'),\n CURLAUTH_ANY => t('Any'),\n CURLAUTH_ANYSAFE => t('Any safe'),\n ),\n '#default_value' => variable_get('simpletest_httpauth_method', CURLAUTH_BASIC),\n );\n $username = variable_get('simpletest_httpauth_username');\n $password = variable_get('simpletest_httpauth_password');\n $form['httpauth']['simpletest_httpauth_username'] = array(\n '#type' => 'textfield',\n '#title' => t('Username'),\n '#default_value' => $username,\n );\n if ($username && $password) {\n $form['httpauth']['simpletest_httpauth_username']['#description'] = t('Leave this blank to delete both the existing username and password.');\n }\n $form['httpauth']['simpletest_httpauth_password'] = array(\n '#type' => 'password',\n '#title' => t('Password'),\n );\n if ($password) {\n $form['httpauth']['simpletest_httpauth_password']['#description'] = t('To change the password, enter the new password here.');\n }\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea30426bdf", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_theme_initialize/7.x", "instruction": "I need the code for `block_theme_initialize($theme)` in Drupal 7 (modules/block/block.module). It must do this: Assigns an initial, default set of blocks for a theme.", "context": "This function is called the first time a new theme is enabled. The new theme gets a copy of the default theme's blocks, with the difference that if a particular region isn't available in the new theme, the block is assigned to the new theme's default region.\n\nParameters:\n- $theme: The name of a theme.\n\nFile: modules/block/block.module", "response": "function block_theme_initialize($theme) {\n // Initialize theme's blocks if none already registered.\n $has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchField();\n if (!$has_blocks) {\n $default_theme = variable_get('theme_default', 'bartik');\n // Apply only to new theme's visible regions.\n $regions = system_region_list($theme, REGIONS_VISIBLE);\n $result = db_query(\"SELECT * FROM {block} WHERE theme = :theme\", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC));\n foreach ($result as $block) {\n // If the region isn't supported by the theme, assign the block to the\n // theme's default region.\n if ($block['status'] && !isset($regions[$block['region']])) {\n $block['region'] = system_default_region($theme);\n }\n $block['theme'] = $theme;\n unset($block['bid']);\n drupal_write_record('block', $block);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea30c4dd16", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7008/7.x", "instruction": "Implement `node_update_7008()` in PHP for Drupal 7. Required behavior: Split the 'administer nodes' permission from 'access content overview'.", "context": "File: modules/node/node.install", "response": "function node_update_7008() {\n $roles = user_roles(FALSE, 'administer nodes');\n foreach ($roles as $rid => $role) {\n _update_7000_user_role_grant_permissions($rid, array('access content overview'), 'node');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea4b40a2c2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/request_path/7.x", "instruction": "Implement `request_path()` in PHP for Drupal 7. Required behavior: Returns the requested URL path of the page being viewed.", "context": "Examples:\n- http://example.com/node/306 returns \"node/306\".\n- http://example.com/drupalfolder/node/306 returns \"node/306\" while\n base_path() returns \"/drupalfolder/\".\n- http://example.com/path/alias (which is a path alias for node/306) returns\n \"path/alias\" as opposed to the internal path.\n- http://example.com/index.php returns an empty string (meaning: front page).\n- http://example.com/index.php?page=1 returns an empty string.\n\nReturns: The requested Drupal URL path.\n\nFile: includes/bootstrap.inc", "response": "function request_path() {\n static $path;\n\n if (isset($path)) {\n return $path;\n }\n\n if (isset($_GET['q']) && is_string($_GET['q'])) {\n // This is a request with a ?q=foo/bar query string. $_GET['q'] is\n // overwritten in drupal_path_initialize(), but request_path() is called\n // very early in the bootstrap process, so the original value is saved in\n // $path and returned in later calls.\n $path = $_GET['q'];\n }\n elseif (isset($_SERVER['REQUEST_URI'])) {\n // This request is either a clean URL, or 'index.php', or nonsense.\n // Extract the path from REQUEST_URI.\n $request_path = strtok($_SERVER['REQUEST_URI'], '?');\n $base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/'));\n // Unescape and strip $base_path prefix, leaving q without a leading slash.\n $path = substr(urldecode($request_path), $base_path_len + 1);\n // If the path equals the script filename, either because 'index.php' was\n // explicitly provided in the URL, or because the server added it to\n // $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some\n // versions of Microsoft IIS do this), the front page should be served.\n if ($path == basename($_SERVER['PHP_SELF'])) {\n $path = '';\n }\n }\n else {\n // This is the front page.\n $path = '';\n }\n\n // Under certain conditions Apache's RewriteRule directive prepends the value\n // assigned to $_GET['q'] with a slash. Moreover we can always have a trailing\n // slash in place, hence we need to normalize $_GET['q'].\n $path = trim($path, '/');\n\n return $path;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea59247fc0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_page_footer/7.x", "instruction": "Implement `drupal_page_footer()` in PHP for Drupal 7. Required behavior: Performs end-of-request tasks.", "context": "This function sets the page cache if appropriate, and allows modules to react to the closing of the page by calling hook_exit().\n\nFile: includes/common.inc", "response": "function drupal_page_footer() {\n global $user;\n\n module_invoke_all('exit');\n\n // Commit the user session, if needed.\n drupal_session_commit();\n\n if (variable_get('cache', 0) && ($cache = drupal_page_set_cache())) {\n drupal_serve_page_from_cache($cache);\n }\n else {\n ob_flush();\n }\n\n _registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE);\n drupal_cache_system_paths();\n module_implements_write_cache();\n drupal_file_scan_write_cache();\n system_run_automated_cron();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea6e511e27", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_menu/7.x", "instruction": "Implement `dashboard_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu().", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_menu() {\n $items['admin/dashboard'] = array(\n 'title' => 'Dashboard',\n 'description' => 'View and customize your dashboard.',\n 'page callback' => 'dashboard_admin',\n 'access arguments' => array('access dashboard'),\n // Make this appear first, so for example, in admin menus, it shows up on\n // the top corner of the window as a convenient \"home link\".\n 'weight' => -15,\n );\n $items['admin/dashboard/configure'] = array(\n 'title' => 'Configure available dashboard blocks',\n 'description' => 'Configure which blocks can be shown on the dashboard.',\n 'page callback' => 'dashboard_admin_blocks',\n 'access arguments' => array('administer blocks'),\n 'type' => MENU_VISIBLE_IN_BREADCRUMB,\n );\n $items['admin/dashboard/customize'] = array(\n 'title' => 'Customize dashboard',\n 'description' => 'Customize your dashboard.',\n 'page callback' => 'dashboard_admin',\n 'page arguments' => array(TRUE),\n 'access arguments' => array('access dashboard'),\n 'type' => MENU_VISIBLE_IN_BREADCRUMB,\n );\n $items['admin/dashboard/drawer'] = array(\n 'page callback' => 'dashboard_show_disabled',\n 'access arguments' => array('administer blocks'),\n 'type' => MENU_CALLBACK,\n );\n $items['admin/dashboard/block-content/%/%'] = array(\n 'page callback' => 'dashboard_show_block_content',\n 'page arguments' => array(3, 4),\n 'access arguments' => array('administer blocks'),\n 'type' => MENU_CALLBACK,\n );\n $items['admin/dashboard/update'] = array(\n 'page callback' => 'dashboard_update',\n 'access arguments' => array('administer blocks'),\n 'type' => MENU_CALLBACK,\n );\n\n return $items;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea769344ea", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_no_profile_error/7.x", "instruction": "I need the code for `install_no_profile_error()` in Drupal 7 (includes/install.core.inc). It must do this: Indicates that there are no profiles available.", "context": "File: includes/install.core.inc", "response": "function install_no_profile_error() {\n drupal_set_title(st('No profiles available'));\n return st('We were unable to find any installation profiles. Installation profiles tell us what modules to enable and what schema to install in the database. A profile is necessary to continue with the installation process.');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea7e55370c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_load/7.x", "instruction": "Implement `menu_link_load($mlid)` in PHP for Drupal 7. Required behavior: Gets a translated, access-checked menu link that is ready for rendering.", "context": "This function should never be called from within node_load() or any other function used as a menu object load function since an infinite recursion may occur.\n\nParameters:\n- $mlid: The mlid of the menu item.\n\nReturns: A menu link, with $item['access'] filled and link translated for rendering.\n\nFile: includes/menu.inc", "response": "function menu_link_load($mlid) {\n if (is_numeric($mlid)) {\n $query = db_select('menu_links', 'ml');\n $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');\n $query->fields('ml');\n // Weight should be taken from {menu_links}, not {menu_router}.\n $query->addField('ml', 'weight', 'link_weight');\n $query->fields('m');\n $query->condition('ml.mlid', $mlid);\n if ($item = $query->execute()->fetchAssoc()) {\n $item['weight'] = $item['link_weight'];\n _menu_link_translate($item);\n return $item;\n }\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea97860173", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_prepare_translation/7.x", "instruction": "Implement `text_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode)` in PHP for Drupal 7. Required behavior: Implements hook_field_prepare_translation().", "context": "File: modules/field/modules/text/text.module", "response": "function text_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode) {\n // If the translating user is not permitted to use the assigned text format,\n // we must not expose the source values.\n $field_name = $field['field_name'];\n if (!empty($source_entity->{$field_name}[$source_langcode])) {\n $formats = filter_formats();\n foreach ($source_entity->{$field_name}[$source_langcode] as $delta => $item) {\n $format_id = $item['format'];\n if (!empty($format_id) && !filter_access($formats[$format_id])) {\n unset($items[$delta]);\n }\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ea9a00efab", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/callback_entity_info_uri/7.x", "instruction": "Give me the example code for `callback_entity_info_uri($entity)` in Drupal 7. Hook description: Return the URI for an entity.", "context": "Callback for hook_entity_info().\n\nParameters:\n- $entity: The entity to return the URI for.\n\nReturns: An associative array with the following elements: - 'path': The URL path for the entity. - 'options': (optional) An array of options for the url() function. The actual entity URI can be constructed by passing these elements to url().\n\nFile: modules/system/system.api.php", "response": "function callback_entity_info_uri($entity) {\n return array(\n 'path' => 'node/' . $entity->nid,\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-eaa791c489", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_form_dashboard_admin_display_form_alter/7.x", "instruction": "In Drupal 7, write the function `dashboard_form_dashboard_admin_display_form_alter(&$form, &$form_state)` (file modules/dashboard/dashboard.module) so that it does the following: Implements hook_form_FORM_ID_alter().", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_form_dashboard_admin_display_form_alter(&$form, &$form_state) {\n // Redirect the 'configure' and 'delete' links on each block back to the\n // dashboard blocks administration page.\n foreach ($form['blocks'] as &$block) {\n if (isset($block['configure']['#href'])) {\n $block['configure']['#options']['query']['destination'] = 'admin/dashboard/configure';\n }\n if (isset($block['delete']['#href'])) {\n $block['delete']['#options']['query']['destination'] = 'admin/dashboard/configure';\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-eaaf9ccc39", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_clean_database/7.x", "instruction": "In Drupal 7, write the function `simpletest_clean_database()` (file modules/simpletest/simpletest.module) so that it does the following: Removed prefixed tables from the database that are left over from crashed tests.", "context": "File: modules/simpletest/simpletest.module", "response": "function simpletest_clean_database() {\n $tables = db_find_tables_d8(Database::getConnection()->prefixTables('{simpletest}') . '%');\n $schema = drupal_get_schema_unprocessed('simpletest');\n $count = 0;\n foreach (array_diff_key($tables, $schema) as $table) {\n // Strip the prefix and skip tables without digits following \"simpletest\",\n // e.g. {simpletest_test_id}.\n if (preg_match('/simpletest\\d+.*/', $table, $matches)) {\n db_drop_table($matches[0]);\n $count++;\n }\n }\n\n if ($count > 0) {\n drupal_set_message(format_plural($count, 'Removed 1 leftover table.', 'Removed @count leftover tables.'));\n }\n else {\n drupal_set_message(t('No leftover tables to remove.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eabdf23817", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_get_math_library/7.x", "instruction": "I need the code for `_openid_get_math_library()` in Drupal 7 (modules/openid/openid.inc). It must do this: Determine the available math library GMP vs. BCMath, favouring GMP for performance.", "context": "File: modules/openid/openid.inc", "response": "function _openid_get_math_library() {\n // Not drupal_static(), because a function is not going to disappear and\n // change the output of this under any circumstances.\n static $library;\n\n if (empty($library)) {\n if (function_exists('gmp_add')) {\n $library = 'gmp';\n }\n elseif (function_exists('bcadd')) {\n $library = 'bcmath';\n }\n }\n\n return $library;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eacdff60ac", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.module/function/statistics_exit/7.x", "instruction": "In Drupal 7, write the function `statistics_exit()` (file modules/statistics/statistics.module) so that it does the following: Implements hook_exit().", "context": "Gathers statistics for page accesses.\n\nFile: modules/statistics/statistics.module", "response": "function statistics_exit() {\n global $user;\n\n // When serving cached pages with the 'page_cache_without_database'\n // configuration, system variables need to be loaded. This is a major\n // performance decrease for non-database page caches, but with Statistics\n // module, it is likely to also have 'statistics_enable_access_log' enabled,\n // in which case we need to bootstrap to the session phase anyway.\n drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);\n\n if (variable_get('statistics_count_content_views', 0) && !variable_get('statistics_count_content_views_ajax', 0)) {\n // We are counting content views.\n if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == NULL) {\n // A node has been viewed, so update the node's counters.\n db_merge('node_counter')\n ->key(array('nid' => arg(1)))\n ->fields(array(\n 'daycount' => 1,\n 'totalcount' => 1,\n 'timestamp' => REQUEST_TIME,\n ))\n ->expression('daycount', 'daycount + 1')\n ->expression('totalcount', 'totalcount + 1')\n ->execute();\n }\n }\n if (variable_get('statistics_enable_access_log', 0)) {\n // For anonymous users unicode.inc will not have been loaded.\n include_once DRUPAL_ROOT . '/includes/unicode.inc';\n // Log this page access.\n db_insert('accesslog')\n ->fields(array(\n 'title' => truncate_utf8(strip_tags(drupal_get_title()), 255),\n 'path' => truncate_utf8($_GET['q'], 255),\n 'url' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',\n 'hostname' => ip_address(),\n 'uid' => $user->uid,\n 'sid' => session_id(),\n 'timer' => (int) timer_read('page'),\n 'timestamp' => REQUEST_TIME,\n ))\n ->execute();\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-eadd6b1e13", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_settings/7.x", "instruction": "Implement `book_admin_settings()` in PHP for Drupal 7. Required behavior: Form constructor for the book settings form.", "context": "File: modules/book/book.admin.inc", "response": "function book_admin_settings() {\n $types = node_type_get_names();\n $form['book_allowed_types'] = array(\n '#type' => 'checkboxes',\n '#title' => t('Content types allowed in book outlines'),\n '#default_value' => variable_get('book_allowed_types', array('book')),\n '#options' => $types,\n '#description' => t('Users with the %outline-perm permission can add all content types.', array('%outline-perm' => t('Administer book outlines'))),\n '#required' => TRUE,\n );\n $form['book_child_type'] = array(\n '#type' => 'radios',\n '#title' => t('Content type for child pages'),\n '#default_value' => variable_get('book_child_type', 'book'),\n '#options' => $types,\n '#required' => TRUE,\n );\n $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);\n $form['#validate'][] = 'book_admin_settings_validate';\n\n return system_settings_form($form);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eaf53ee58e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/theme_comment_block/7.x", "instruction": "I need the code for `theme_comment_block()` in Drupal 7 (modules/comment/comment.module). It must do this: Returns HTML for a list of recent comments to be displayed in the comment block.", "context": "File: modules/comment/comment.module", "response": "function theme_comment_block() {\n $items = array();\n $number = variable_get('comment_block_count', 10);\n foreach (comment_get_recent($number) as $comment) {\n $items[] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)) . ' ' . t('@time ago', array('@time' => format_interval(REQUEST_TIME - $comment->changed))) . '';\n }\n\n if ($items) {\n return theme('item_list', array('items' => $items));\n }\n else {\n return t('No comments available.');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eb213bdf68", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_page_alter/7.x", "instruction": "In Drupal 7, write the function `system_page_alter(&$page)` (file modules/system/system.module) so that it does the following: Implements hook_page_alter().", "context": "File: modules/system/system.module", "response": "function system_page_alter(&$page) {\n // Find all non-empty page regions, and add a theme wrapper function that\n // allows them to be consistently themed.\n foreach (system_region_list($GLOBALS['theme'], REGIONS_ALL, FALSE) as $region) {\n if (!empty($page[$region])) {\n $page[$region]['#theme_wrappers'][] = 'region';\n $page[$region]['#region'] = $region;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-eb3c13dd98", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_send_email_action_validate/7.x", "instruction": "In Drupal 7, write the function `system_send_email_action_validate($form, $form_state)` (file modules/system/system.module) so that it does the following: Validate system_send_email_action form submissions.", "context": "File: modules/system/system.module", "response": "function system_send_email_action_validate($form, $form_state) {\n $form_values = $form_state['values'];\n // Validate the configuration form.\n if (!valid_email_address($form_values['recipient']) && strpos($form_values['recipient'], ':mail') === FALSE) {\n // We want the literal %author placeholder to be emphasized in the error message.\n form_set_error('recipient', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eb61d9482f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_admin_refresh_feed/7.x", "instruction": "In Drupal 7, write the function `aggregator_admin_refresh_feed($feed)` (file modules/aggregator/aggregator.admin.inc) so that it does the following: Page callback: Refreshes a feed, then redirects to the overview page.", "context": "Parameters:\n- $feed: An object describing the feed to be refreshed.\n\nFile: modules/aggregator/aggregator.admin.inc", "response": "function aggregator_admin_refresh_feed($feed) {\n if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'aggregator/update/' . $feed->fid)) {\n return MENU_ACCESS_DENIED;\n }\n aggregator_refresh($feed);\n drupal_goto('admin/config/services/aggregator');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eb8700901d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_page/7.x", "instruction": "In Drupal 7, write the function `user_page()` (file modules/user/user.pages.inc) so that it does the following: Page callback: Displays the user page.", "context": "Displays user profile if user is logged in, or login form for anonymous users.\n\nReturns: A render array for either a user profile or a login form.\n\nFile: modules/user/user.pages.inc", "response": "function user_page() {\n global $user;\n if ($user->uid) {\n menu_set_active_item('user/' . $user->uid);\n return menu_execute_active_handler(NULL, FALSE);\n }\n else {\n return drupal_get_form('user_login');\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eb9b780ae6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_tabledrag/7.x", "instruction": "Implement `drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgroup = NULL, $source = NULL, $hidden = TRUE, $limit = 0)` in PHP for Drupal 7. Required behavior: Assists in adding the tableDrag JavaScript behavior to a themed table.", "context": "Draggable tables should be used wherever an outline or list of sortable items needs to be arranged by an end-user. Draggable tables are very flexible and can manipulate the value of form elements placed within individual columns.\n\nTo set up a table to use drag and drop in place of weight select-lists or in place of a form that contains parent relationships, the form must be themed into a table. The table must have an ID attribute set. If using theme_table(), the ID may be set as follows:\n\nParameters:\n- $table_id: String containing the target table's id attribute. If the table does not have an id, one will need to be set, such as .\n- $action: String describing the action to be done on the form item. Either 'match' 'depth', or 'order'. Match is typically used for parent relationships. Order is typically used to set weights on other form elements with the same group. Depth updates the target element with the current indentation.\n- $relationship: String describing where the $action variable should be performed. Either 'parent', 'sibling', 'group', or 'self'. Parent will only look for fields up the tree. Sibling will look for fields in the same group in rows above and below it. Self affects the dragged row itself. Group affects the dragged row, plus any children below it (the entire dragged group).\n- $group: A class name applied on all related form elements for this action.\n- $subgroup: (optional) If the group has several subgroups within it, this string should contain the class name identifying fields in the same subgroup.\n- $source: (optional) If the $action is 'match', this string should contain the class name identifying what field will be used as the source value when matching the value in $subgroup.\n- $hidden: (optional) The column containing the field elements may be entirely hidden from view dynamically when the JavaScript is loaded. Set to FALSE if the column should not be hidden.\n- $limit: (optional) Limit the maximum amount of parenting in this table.\n\nFile: includes/common.inc", "response": "function drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgroup = NULL, $source = NULL, $hidden = TRUE, $limit = 0) {\n $js_added = &drupal_static(__FUNCTION__, FALSE);\n if (!$js_added) {\n // Add the table drag JavaScript to the page before the module JavaScript\n // to ensure that table drag behaviors are registered before any module\n // uses it.\n drupal_add_library('system', 'jquery.cookie');\n drupal_add_js('misc/tabledrag.js', array('weight' => -1));\n $js_added = TRUE;\n }\n\n // If a subgroup or source isn't set, assume it is the same as the group.\n $target = isset($subgroup) ? $subgroup : $group;\n $source = isset($source) ? $source : $target;\n $settings['tableDrag'][$table_id][$group][] = array(\n 'target' => $target,\n 'source' => $source,\n 'relationship' => $relationship,\n 'action' => $action,\n 'hidden' => $hidden,\n 'limit' => $limit,\n );\n drupal_add_js($settings, 'setting');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ebaa4ad18b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_storage_write/7.x", "instruction": "Implement `field_sql_storage_field_storage_write($entity_type, $entity, $op, $fields)` in PHP for Drupal 7. Required behavior: Implements hook_field_storage_write().", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fields) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n if (!isset($vid)) {\n $vid = $id;\n }\n\n // Check if the given entity is a new revision or not. In case of a new\n // revision creation, we cannot skip any field.\n if (!empty($vid) && !empty($entity->original)) {\n list(, $original_vid) = entity_extract_ids($entity_type, $entity->original);\n if (NULL === $original_vid) {\n $original_vid = $id;\n }\n $is_new_revision = $original_vid != $vid;\n }\n else {\n $is_new_revision = FALSE;\n }\n\n // Allow this optimization to be optional.\n $skip_unchanged_fields = variable_get('field_sql_storage_skip_writing_unchanged_fields', FALSE);\n\n foreach ($fields as $field_id) {\n $field = field_info_field_by_id($field_id);\n\n if ($skip_unchanged_fields && !$is_new_revision && !empty($entity->original) && !_field_sql_storage_write_compare($field, $entity, $entity->original)) {\n continue;\n }\n\n $field_name = $field['field_name'];\n $table_name = _field_sql_storage_tablename($field);\n $revision_name = _field_sql_storage_revision_tablename($field);\n\n $all_languages = field_available_languages($entity_type, $field);\n $field_languages = array_intersect($all_languages, array_keys((array) $entity->$field_name));\n\n // Delete and insert, rather than update, in case a value was added.\n if ($op == FIELD_STORAGE_UPDATE) {\n // Delete languages present in the incoming $entity->$field_name.\n // Delete all languages if $entity->$field_name is empty.\n $languages = !empty($entity->$field_name) ? $field_languages : $all_languages;\n if ($languages) {\n db_delete($table_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $id)\n ->condition('language', $languages, 'IN')\n ->execute();\n db_delete($revision_name)\n ->condition('entity_type', $entity_type)\n ->condition('entity_id', $id)\n ->condition('revision_id', $vid)\n ->condition('language', $languages, 'IN')\n ->execute();\n }\n }\n\n // Prepare the multi-insert query.\n $do_insert = FALSE;\n $columns = array('entity_type', 'entity_id', 'revision_id', 'bundle', 'delta', 'language');\n foreach ($field['columns'] as $column => $attributes) {\n $columns[] = _field_sql_storage_columnname($field_name, $column);\n }\n $query = db_insert($table_name)->fields($columns);\n $revision_query = db_insert($revision_name)->fields($columns);\n\n foreach ($field_languages as $langcode) {\n $items = (array) $entity->{$field_name}[$langcode];\n $delta_count = 0;\n foreach ($items as $delta => $item) {\n // We now know we have something to insert.\n $do_insert = TRUE;\n $record = array(\n 'entity_type' => $entity_type,\n 'entity_id' => $id,\n 'revision_id' => $vid,\n 'bundle' => $bundle,\n 'delta' => $delta,\n 'language' => $langcode,\n );\n foreach ($field['columns'] as $column => $attributes) {\n $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;\n }\n $query->values($record);\n if (isset($vid)) {\n $revision_query->values($record);\n }\n\n if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) {\n break;\n }\n }\n }\n\n // Execute the query if we have values to insert.\n if ($do_insert) {\n $query->execute();\n $revision_query->execute();\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ebb7d6b8db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_set_mode/7.x", "instruction": "I need the code for `overlay_set_mode($mode = NULL)` in Drupal 7 (modules/overlay/overlay.module). It must do this: Sets the overlay mode and adds proper JavaScript and styles to the page.", "context": "Note that since setting the overlay mode triggers a variety of behaviors (including hooks being invoked), it can only be done once per page request. Therefore, the first call to this function which passes along a value of the $mode parameter controls the overlay mode that will be used.\n\nParameters:\n- $mode: To set the mode, pass in one of the following values: - 'parent': This is used in the context of a parent window (a regular browser window). If set, JavaScript is added so that administrative links in the parent window will open in an overlay. - 'child': This is used in the context of the child overlay window (the page actually appearing within the overlay iframe). If set, JavaScript and CSS are added so that Drupal behaves nicely from within the overlay. - 'none': This is used to avoid adding any overlay-related code to the page at all. Modules can set this to explicitly prevent the overlay from being used. For example, since the overlay module itself sets the mode to 'parent' or 'child' in overlay_init() when certain conditions are met, other modules which want to override that behavior can do so by setting the mode to 'none' earlier in the page request - e.g., in their own hook_init() implementations, if they have a lower weight. This parameter is optional, and if omitted, the current mode will be returned with no action taken.\n\nReturns: The current mode, if any has been set, or NULL if no mode has been set.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_set_mode($mode = NULL) {\n global $base_path;\n $overlay_mode = &drupal_static(__FUNCTION__);\n\n // Make sure external resources are not included more than once. Also return\n // the current mode, if no mode was specified.\n if (isset($overlay_mode) || !isset($mode)) {\n return $overlay_mode;\n }\n $overlay_mode = $mode;\n\n switch ($overlay_mode) {\n case 'parent':\n drupal_add_library('overlay', 'parent');\n\n // Allow modules to act upon overlay events.\n module_invoke_all('overlay_parent_initialize');\n break;\n\n case 'child':\n drupal_add_library('overlay', 'child');\n\n // Allow modules to act upon overlay events.\n module_invoke_all('overlay_child_initialize');\n break;\n }\n return $overlay_mode;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ebe5be40eb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_chmod/7.x", "instruction": "Implement `drupal_chmod($uri, $mode = NULL)` in PHP for Drupal 7. Required behavior: Sets the permissions on a file or directory.", "context": "This function will use the 'file_chmod_directory' and 'file_chmod_file' variables for the default modes for directories and uploaded/generated files. By default these will give everyone read access so that users accessing the files with a user account without the webserver group (e.g. via FTP) can read these files, and give group write permissions so webserver group members (e.g. a vhost account) can alter files uploaded and owned by the webserver.\n\nPHP's chmod does not support stream wrappers so we use our wrapper implementation which interfaces with chmod() by default. Contrib wrappers may override this behavior in their implementations as needed.\n\nParameters:\n- $uri: A string containing a URI file, or directory path.\n- $mode: Integer value for the permissions. Consult PHP chmod() documentation for more information.\n\nReturns: TRUE for success, FALSE in the event of an error.\n\nFile: includes/file.inc", "response": "function drupal_chmod($uri, $mode = NULL) {\n if (!isset($mode)) {\n if (is_dir($uri)) {\n $mode = variable_get('file_chmod_directory', 0775);\n }\n else {\n $mode = variable_get('file_chmod_file', 0664);\n }\n }\n\n // If this URI is a stream, pass it off to the appropriate stream wrapper.\n // Otherwise, attempt PHP's chmod. This allows use of drupal_chmod even\n // for unmanaged files outside of the stream wrapper interface.\n if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) {\n if ($wrapper->chmod($mode)) {\n return TRUE;\n }\n }\n else {\n if (@chmod($uri, $mode)) {\n return TRUE;\n }\n }\n\n watchdog('file', 'The file permissions could not be set on %uri.', array('%uri' => $uri), WATCHDOG_ERROR);\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ebf1256881", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_set/7.x", "instruction": "Implement `language_negotiation_set($type, $language_providers)` in PHP for Drupal 7. Required behavior: Saves a list of language negotiation providers.", "context": "Parameters:\n- $type: The language negotiation type.\n- $language_providers: An array of language negotiation provider weights keyed by provider ID. @see language_provider_weight()\n\nFile: includes/language.inc", "response": "function language_negotiation_set($type, $language_providers) {\n // Save only the necessary fields.\n $provider_fields = array('callbacks', 'file', 'cache');\n\n $negotiation = array();\n $providers_weight = array();\n $defined_providers = language_negotiation_info();\n $default_types = language_types_configurable(FALSE);\n\n // Initialize the providers weight list.\n foreach ($language_providers as $id => $provider) {\n $providers_weight[$id] = language_provider_weight($provider);\n }\n\n // Order providers list by weight.\n asort($providers_weight);\n\n foreach ($providers_weight as $id => $weight) {\n if (isset($defined_providers[$id])) {\n $provider = $defined_providers[$id];\n // If the provider does not express any preference about types, make it\n // available for any configurable type.\n $types = array_flip(isset($provider['types']) ? $provider['types'] : $default_types);\n // Check whether the provider is defined and has the right type.\n if (isset($types[$type])) {\n $provider_data = array();\n foreach ($provider_fields as $field) {\n if (isset($provider[$field])) {\n $provider_data[$field] = $provider[$field];\n }\n }\n $negotiation[$id] = $provider_data;\n }\n }\n }\n\n variable_set(\"language_negotiation_$type\", $negotiation);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec18330bc4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_style_flush/7.x", "instruction": "Give me the example code for `hook_image_style_flush($style)` in Drupal 7. Hook description: Respond to image style flushing.", "context": "This hook enables modules to take effect when a style is being flushed (all images are being deleted from the server and regenerated). Any module-specific caches that contain information related to the style should be cleared using this hook. This hook is called whenever a style is updated, deleted, or any effect associated with the style is update or deleted.\n\nParameters:\n- $style: The image style array that is being flushed.\n\nFile: modules/image/image.api.php", "response": "function hook_image_style_flush($style) {\n // Empty cached data that contains information about the style.\n cache_clear_all('*', 'cache_mymodule', TRUE);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec1e128b69", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_widget_instance/7.x", "instruction": "Implement `field_widget_instance($element, $form_state)` in PHP for Drupal 7. Required behavior: Retrieves the instance definition array for a widget's helper callbacks.", "context": "Widgets helper element callbacks (such as #process, #element_validate, #value_callback, ...) should use field_widget_field() and field_widget_instance() instead of field_info_field() and field_info_instance() when they need to access field or instance properties. See hook_field_widget_form() for more details.\n\nParameters:\n- $element: The structured array for the widget.\n- $form_state: The form state.\n\nReturns: The $instance definition array for the current widget.\n\nFile: modules/field/field.form.inc", "response": "function field_widget_instance($element, $form_state) {\n $field_state = field_form_get_state($element['#field_parents'], $element['#field_name'], $element['#language'], $form_state);\n return $field_state['instance'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec33b2de10", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_field_storage_delete_instance/7.x", "instruction": "Implement `field_sql_storage_field_storage_delete_instance($instance)` in PHP for Drupal 7. Required behavior: Implements hook_field_storage_delete_instance().", "context": "This function simply marks for deletion all data associated with the field.\n\nFile: modules/field/modules/field_sql_storage/field_sql_storage.module", "response": "function field_sql_storage_field_storage_delete_instance($instance) {\n $field = field_info_field($instance['field_name']);\n $table_name = _field_sql_storage_tablename($field);\n $revision_name = _field_sql_storage_revision_tablename($field);\n db_update($table_name)\n ->fields(array('deleted' => 1))\n ->condition('entity_type', $instance['entity_type'])\n ->condition('bundle', $instance['bundle'])\n ->execute();\n db_update($revision_name)\n ->fields(array('deleted' => 1))\n ->condition('entity_type', $instance['entity_type'])\n ->condition('bundle', $instance['bundle'])\n ->execute();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec3f71430a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_delete_node_index/7.x", "instruction": "In Drupal 7, write the function `taxonomy_delete_node_index($node)` (file modules/taxonomy/taxonomy.module) so that it does the following: Deletes taxonomy index entries for a given node.", "context": "Parameters:\n- $node: The node object.\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_delete_node_index($node) {\n if (variable_get('taxonomy_maintain_index_table', TRUE)) {\n db_delete('taxonomy_index')->condition('nid', $node->nid)->execute();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec40a1587b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_opml_submit/7.x", "instruction": "I need the code for `aggregator_form_opml_submit($form, &$form_state)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Form submission handler for aggregator_form_opml().", "context": "File: modules/aggregator/aggregator.admin.inc", "response": "function aggregator_form_opml_submit($form, &$form_state) {\n $data = '';\n $validators = array('file_validate_extensions' => array('opml xml'));\n if ($file = file_save_upload('upload', $validators)) {\n $data = file_get_contents($file->uri);\n }\n else {\n $response = drupal_http_request($form_state['values']['remote']);\n if (!isset($response->error)) {\n $data = $response->data;\n }\n }\n\n $feeds = _aggregator_parse_opml($data);\n if (empty($feeds)) {\n drupal_set_message(t('No new feed has been added.'));\n return;\n }\n\n $form_state['values']['op'] = t('Save');\n\n foreach ($feeds as $feed) {\n // Ensure URL is valid.\n if (!valid_url($feed['url'], TRUE)) {\n drupal_set_message(t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');\n continue;\n }\n\n // Check for duplicate titles or URLs.\n $result = db_query(\"SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url\", array(':title' => $feed['title'], ':url' => $feed['url']));\n foreach ($result as $old) {\n if (strcasecmp($old->title, $feed['title']) == 0) {\n drupal_set_message(t('A feed named %title already exists.', array('%title' => $old->title)), 'warning');\n continue 2;\n }\n if (strcasecmp($old->url, $feed['url']) == 0) {\n drupal_set_message(t('A feed with the URL %url already exists.', array('%url' => $old->url)), 'warning');\n continue 2;\n }\n }\n\n $form_state['values']['title'] = $feed['title'];\n $form_state['values']['url'] = $feed['url'];\n drupal_form_submit('aggregator_form_feed', $form_state);\n }\n\n $form_state['redirect'] = 'admin/config/services/aggregator';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec4208eeed", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_theme/7.x", "instruction": "Implement `system_theme()` in PHP for Drupal 7. Required behavior: Implements hook_theme().", "context": "File: modules/system/system.module", "response": "function system_theme() {\n return array_merge(drupal_common_theme(), array(\n 'system_themes_page' => array(\n 'variables' => array('theme_groups' => NULL),\n 'file' => 'system.admin.inc',\n ),\n 'system_settings_form' => array(\n 'render element' => 'form',\n ),\n 'confirm_form' => array(\n 'render element' => 'form',\n ),\n 'system_modules_fieldset' => array(\n 'render element' => 'form',\n 'file' => 'system.admin.inc',\n ),\n 'system_modules_incompatible' => array(\n 'variables' => array('message' => NULL),\n 'file' => 'system.admin.inc',\n ),\n 'system_modules_uninstall' => array(\n 'render element' => 'form',\n 'file' => 'system.admin.inc',\n ),\n 'status_report' => array(\n 'render element' => 'requirements',\n 'file' => 'system.admin.inc',\n ),\n 'admin_page' => array(\n 'variables' => array('blocks' => NULL),\n 'file' => 'system.admin.inc',\n ),\n 'admin_block' => array(\n 'variables' => array('block' => NULL),\n 'file' => 'system.admin.inc',\n ),\n 'admin_block_content' => array(\n 'variables' => array('content' => NULL),\n 'file' => 'system.admin.inc',\n ),\n 'system_admin_index' => array(\n 'variables' => array('menu_items' => NULL),\n 'file' => 'system.admin.inc',\n ),\n 'system_powered_by' => array(\n 'variables' => array(),\n ),\n 'system_compact_link' => array(\n 'variables' => array(),\n ),\n 'system_date_time_settings' => array(\n 'render element' => 'form',\n 'file' => 'system.admin.inc',\n ),\n ));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec669da590", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.install/function/field_sql_storage_update_7001/7.x", "instruction": "In Drupal 7, write the function `field_sql_storage_update_7001(&$sandbox)` (file modules/field/modules/field_sql_storage/field_sql_storage.install) so that it does the following: Remove the field_config_entity_type table and store 'entity_type' strings.", "context": "File: modules/field/modules/field_sql_storage/field_sql_storage.install", "response": "function field_sql_storage_update_7001(&$sandbox) {\n if (!isset($sandbox['progress'])) {\n // Collect current etids.\n $sandbox['etids'] = db_query('SELECT etid, type FROM {field_config_entity_type}')->fetchAllKeyed();\n\n // Collect affected tables: field data, field revision data, 'deleted'\n // tables.\n $sandbox['tables'] = array();\n $results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))\n ->fields('fc')\n ->condition('storage_module', 'field_sql_storage')\n ->execute();\n foreach ($results as $field) {\n if ($field['deleted']) {\n $sandbox['tables'][\"field_deleted_data_{$field['id']}\"] = 'data';\n $sandbox['tables'][\"field_deleted_revision_{$field['id']}\"] = 'revision';\n }\n else {\n $sandbox['tables'][\"field_data_{$field['field_name']}\"] = 'data';\n $sandbox['tables'][\"field_revision_{$field['field_name']}\"] = 'revision';\n }\n }\n reset($sandbox['tables']);\n\n $sandbox['total'] = count($sandbox['tables']);\n $sandbox['progress'] = 0;\n }\n\n if ($sandbox['tables']) {\n // Grab the next table to process.\n $table = key($sandbox['tables']);\n $type = array_shift($sandbox['tables']);\n\n if (db_table_exists($table)) {\n // Add the 'entity_type' column.\n if (!db_field_exists($table, 'entity_type')) {\n $column = array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The entity type this data is attached to.',\n );\n db_add_field($table, 'entity_type', $column);\n\n // Populate the 'entity_type' column based on the 'etid' column.\n foreach ($sandbox['etids'] as $etid => $entity_type) {\n db_update($table)\n ->fields(array('entity_type' => $entity_type))\n ->condition('etid', $etid)\n ->execute();\n }\n\n // Index the new column.\n db_add_index($table, 'entity_type', array('entity_type'));\n }\n\n // Use the 'entity_type' column in the primary key.\n db_drop_primary_key($table);\n $primary_keys = array(\n 'data' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),\n 'revision' => array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'),\n );\n db_add_primary_key($table, $primary_keys[$type]);\n\n // Drop the 'etid' column.\n if (db_field_exists($table, 'etid')) {\n db_drop_field($table, 'etid');\n }\n }\n\n // Report progress.\n $sandbox['progress']++;\n $sandbox['#finished'] = min(0.99, $sandbox['progress'] / $sandbox['total']);\n }\n else {\n // No more tables left: drop the field_config_entity_type table.\n db_drop_table('field_config_entity_type');\n\n // Drop the previous 'field_sql_storage_ENTITYTYPE_etid' system variables.\n foreach ($sandbox['etids'] as $etid => $entity_type) {\n variable_del('field_sql_storage_' . $entity_type . '_etid');\n }\n\n // We're done.\n $sandbox['#finished'] = 1;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec68d2ccbe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_rebuild_js/7.x", "instruction": "In Drupal 7, write the function `_locale_rebuild_js($langcode = NULL)` (file includes/locale.inc) so that it does the following: (Re-)Creates the JavaScript translation file for a language.", "context": "Parameters:\n- $language: The language, the translation file should be (re)created for.\n\nFile: includes/locale.inc", "response": "function _locale_rebuild_js($langcode = NULL) {\n if (!isset($langcode)) {\n global $language;\n }\n else {\n // Get information about the locale.\n $languages = language_list();\n $language = $languages[$langcode];\n }\n\n // Construct the array for JavaScript translations.\n // Only add strings with a translation to the translations array.\n $result = db_query(\"SELECT s.lid, s.source, s.context, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.location LIKE '%.js%' AND s.textgroup = :textgroup\", array(':language' => $language->language, ':textgroup' => 'default'));\n\n $translations = array();\n foreach ($result as $data) {\n $translations[$data->context][$data->source] = $data->translation;\n }\n\n // Include custom string overrides.\n $custom_strings = variable_get('locale_custom_strings_' . $language->language, array());\n foreach ($custom_strings as $context => $strings) {\n foreach ($strings as $source => $translation) {\n $translations[$context][$source] = $translation;\n }\n }\n\n // Construct the JavaScript file, if there are translations.\n $data_hash = NULL;\n $data = $status = '';\n if (!empty($translations)) {\n\n $data = \"Drupal.locale = { \";\n\n if (!empty($language->formula)) {\n $data .= \"'pluralFormula': function (\\$n) { return Number({$language->formula}); }, \";\n }\n\n $data .= \"'strings': \" . drupal_json_encode($translations) . \" };\";\n $data_hash = drupal_hash_base64($data);\n }\n\n // Construct the filepath where JS translation files are stored.\n // There is (on purpose) no front end to edit that variable.\n $dir = 'public://' . variable_get('locale_js_directory', 'languages');\n\n // Delete old file, if we have no translations anymore, or a different file to be saved.\n $changed_hash = $language->javascript != $data_hash;\n if (!empty($language->javascript) && (!$data || $changed_hash)) {\n file_unmanaged_delete($dir . '/' . $language->language . '_' . $language->javascript . '.js');\n $language->javascript = '';\n $status = 'deleted';\n }\n\n // Only create a new file if the content has changed or the original file got\n // lost.\n $dest = $dir . '/' . $language->language . '_' . $data_hash . '.js';\n if ($data && ($changed_hash || !file_exists($dest))) {\n // Ensure that the directory exists and is writable, if possible.\n file_prepare_directory($dir, FILE_CREATE_DIRECTORY);\n\n // Save the file.\n if (file_unmanaged_save_data($data, $dest)) {\n $language->javascript = $data_hash;\n // If we deleted a previous version of the file and we replace it with a\n // new one we have an update.\n if ($status == 'deleted') {\n $status = 'updated';\n }\n // If the file did not exist previously and the data has changed we have\n // a fresh creation.\n elseif ($changed_hash) {\n $status = 'created';\n }\n // If the data hash is unchanged the translation was lost and has to be\n // rebuilt.\n else {\n $status = 'rebuilt';\n }\n }\n else {\n $language->javascript = '';\n $status = 'error';\n }\n }\n\n // Save the new JavaScript hash (or an empty value if the file just got\n // deleted). Act only if some operation was executed that changed the hash\n // code.\n if ($status && $changed_hash) {\n db_update('languages')\n ->fields(array(\n 'javascript' => $language->javascript,\n ))\n ->condition('language', $language->language)\n ->execute();\n\n // Update the default language variable if the default language has been altered.\n // This is necessary to keep the variable consistent with the database\n // version of the language and to prevent checking against an outdated hash.\n $default_langcode = language_default('language');\n if ($default_langcode == $language->language) {\n $default = db_query(\"SELECT * FROM {languages} WHERE language = :language\", array(':language' => $default_langcode))->fetchObject();\n variable_set('language_default', $default);\n }\n }\n\n // Log the operation and return success flag.\n switch ($status) {\n case 'updated':\n watchdog('locale', 'Updated JavaScript translation file for the language %language.', array('%language' => t($language->name)));\n return TRUE;\n case 'rebuilt':\n watchdog('locale', 'JavaScript translation file %file.js was lost.', array('%file' => $language->javascript), WATCHDOG_WARNING);\n // Proceed to the 'created' case as the JavaScript translation file has\n // been created again.\n case 'created':\n watchdog('locale', 'Created JavaScript translation file for the language %language.', array('%language' => t($language->name)));\n return TRUE;\n case 'deleted':\n watchdog('locale', 'Removed JavaScript translation file for the language %language, because no translations currently exist for that language.', array('%language' => t($language->name)));\n return TRUE;\n case 'error':\n watchdog('locale', 'An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => t($language->name)), WATCHDOG_ERROR);\n return FALSE;\n default:\n // No operation needed.\n return TRUE;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec7e3240f0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.pages.inc/function/poll_votes/7.x", "instruction": "In Drupal 7, write the function `poll_votes($node)` (file modules/poll/poll.pages.inc) so that it does the following: Callback for the 'votes' tab for polls you can see other votes on", "context": "File: modules/poll/poll.pages.inc", "response": "function poll_votes($node) {\n $votes_per_page = 20;\n drupal_set_title($node->title);\n\n $header[] = array('data' => t('Visitor'), 'field' => 'u.name');\n $header[] = array('data' => t('Vote'), 'field' => 'pc.chtext');\n $header[] = array('data' => t('Timestamp'), 'field' => 'pv.timestamp', 'sort' => 'desc');\n\n $select = db_select('poll_vote', 'pv')->extend('PagerDefault')->extend('TableSort');\n $select->join('poll_choice', 'pc', 'pv.chid = pc.chid');\n $select->join('users', 'u', 'pv.uid = u.uid');\n $queried_votes = $select\n ->addTag('translatable')\n ->fields('pv', array('chid', 'uid', 'hostname', 'timestamp', 'nid'))\n ->fields('pc', array('chtext'))\n ->fields('u', array('name'))\n ->condition('pv.nid', $node->nid)\n ->limit($votes_per_page)\n ->orderByHeader($header)\n ->execute();\n\n $rows = array();\n foreach ($queried_votes as $vote) {\n $rows[] = array(\n $vote->name ? theme('username', array('account' => $vote)) : check_plain($vote->hostname),\n check_plain($vote->chtext),\n format_date($vote->timestamp),\n );\n }\n $build['poll_votes_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#prefix' => t('This table lists all the recorded votes for this poll. If anonymous users are allowed to vote, they will be identified by the IP address of the computer they used when they voted.'),\n );\n $build['poll_votes_pager'] = array('#theme' => 'pager');\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec8564ec51", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_taxonomy_term/7.x", "instruction": "I need the code for `rdf_preprocess_taxonomy_term(&$variables)` in Drupal 7 (modules/rdf/rdf.module). It must do this: Implements MODULE_preprocess_HOOK().", "context": "File: modules/rdf/rdf.module", "response": "function rdf_preprocess_taxonomy_term(&$variables) {\n // Adds the RDF type of the term and the term name in a tag.\n $term = $variables['term'];\n $term_label_meta = array(\n '#tag' => 'meta',\n '#attributes' => array(\n 'about' => url('taxonomy/term/' . $term->tid),\n 'typeof' => $term->rdf_mapping['rdftype'],\n 'property' => $term->rdf_mapping['name']['predicates'],\n 'content' => $term->name,\n ),\n );\n drupal_add_html_head($term_label_meta, 'rdf_term_label');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ec98941ab1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_sets/7.x", "instruction": "In Drupal 7, write the function `shortcut_sets()` (file modules/shortcut/shortcut.module) so that it does the following: Returns an array of all shortcut sets, keyed by the set name.", "context": "Returns: An array of shortcut sets. Note that only the basic shortcut set properties (name and title) are returned by this function, not the list of menu links that belong to the set.\n\nFile: modules/shortcut/shortcut.module", "response": "function shortcut_sets() {\n return db_select('shortcut_set', 'ss')\n ->fields('ss')\n ->execute()\n ->fetchAllAssoc('set_name');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ecb0ab2f04", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.install/function/color_update_7001/7.x", "instruction": "Implement `color_update_7001()` in PHP for Drupal 7. Required behavior: Warn site administrator if unsafe CSS color codes are found in the database.", "context": "File: modules/color/color.install", "response": "function color_update_7001() {\n $theme_palettes = db_query(\"SELECT name FROM {variable} WHERE name LIKE 'color_%_palette'\")->fetchCol();\n foreach ($theme_palettes as $name) {\n $palette = variable_get($name, array());\n foreach ($palette as $key => $color) {\n if (!preg_match('/^#([a-f0-9]{3}){1,2}$/iD', $color)) {\n drupal_set_message('Some of the custom CSS color codes specified via the color module are invalid. Please examine the themes which are making use of the color module at the Appearance settings page to verify their CSS color values.', 'warning');\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ecb8a4f4f4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_theme/7.x", "instruction": "Implement `taxonomy_theme()` in PHP for Drupal 7. Required behavior: Implements hook_theme().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_theme() {\n return array(\n 'taxonomy_overview_vocabularies' => array(\n 'render element' => 'form',\n ),\n 'taxonomy_overview_terms' => array(\n 'render element' => 'form',\n ),\n 'taxonomy_term' => array(\n 'render element' => 'elements',\n 'template' => 'taxonomy-term',\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ecbecda44e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_truncate/7.x", "instruction": "I need the code for `db_truncate($table, array $options = array())` in Drupal 7 (includes/database/database.inc). It must do this: Returns a new TruncateQuery object for the active database.", "context": "Parameters:\n- $table: The table from which to delete.\n- $options: An array of options to control how the query operates.\n\nReturns: TruncateQuery A new TruncateQuery object for this connection.\n\nFile: includes/database/database.inc", "response": "function db_truncate($table, array $options = array()) {\n if (empty($options['target']) || $options['target'] == 'slave') {\n $options['target'] = 'default';\n }\n return Database::getConnection($options['target'])->truncate($table, $options);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ecc1ead190", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_role_delete/7.x", "instruction": "Implement `user_role_delete($role)` in PHP for Drupal 7. Required behavior: Delete a user role from database.", "context": "Parameters:\n- $role: A string with the role name, or an integer with the role ID.\n\nFile: modules/user/user.module", "response": "function user_role_delete($role) {\n if (is_int($role)) {\n $role = user_role_load($role);\n }\n else {\n $role = user_role_load_by_name($role);\n }\n\n // If this is the administrator role, delete the user_admin_role variable.\n if ($role->rid == variable_get('user_admin_role')) {\n variable_del('user_admin_role');\n }\n\n db_delete('role')\n ->condition('rid', $role->rid)\n ->execute();\n db_delete('role_permission')\n ->condition('rid', $role->rid)\n ->execute();\n // Update the users who have this role set:\n db_delete('users_roles')\n ->condition('rid', $role->rid)\n ->execute();\n\n module_invoke_all('user_role_delete', $role);\n\n // Clear the user access cache.\n drupal_static_reset('user_access');\n drupal_static_reset('user_role_permissions');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ecc4a56728", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_file_get/7.x", "instruction": "I need the code for `update_manager_file_get($url)` in Drupal 7 (modules/update/update.manager.inc). It must do this: Copies a file from the specified URL to the temporary directory for updates.", "context": "Returns the local path if the file has already been downloaded.\n\nParameters:\n- $url: The URL of the file on the server.\n\nReturns (string): Path to local file.\n\nFile: modules/update/update.manager.inc", "response": "function update_manager_file_get($url) {\n $parsed_url = parse_url($url);\n $remote_schemes = array('http', 'https', 'ftp', 'ftps', 'smb', 'nfs');\n if (!in_array($parsed_url['scheme'], $remote_schemes)) {\n // This is a local file, just return the path.\n return drupal_realpath($url);\n }\n\n // Check the cache and download the file if needed.\n $cache_directory = _update_manager_cache_directory();\n $local = $cache_directory . '/' . drupal_basename($parsed_url['path']);\n\n if (!file_exists($local) || update_delete_file_if_stale($local)) {\n return system_retrieve_file($url, $local, FALSE, FILE_EXISTS_REPLACE);\n }\n else {\n return $local;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ecf6828dad", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_make_unsticky_action/7.x", "instruction": "I need the code for `node_make_unsticky_action($node, $context = array())` in Drupal 7 (modules/node/node.module). It must do this: Sets the sticky-at-top-of-list property of a node to 0.", "context": "Parameters:\n- $node: A node object.\n- $context: (optional) Array of additional information about what triggered the action. Not used for this action.\n\nFile: modules/node/node.module", "response": "function node_make_unsticky_action($node, $context = array()) {\n $node->sticky = NODE_NOT_STICKY;\n watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_type_get_name($node), '%title' => $node->title));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ed081e90be", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_add_date_formats_form_validate/7.x", "instruction": "I need the code for `system_add_date_formats_form_validate($form, &$form_state)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Validate new date format string submission.", "context": "File: modules/system/system.admin.inc", "response": "function system_add_date_formats_form_validate($form, &$form_state) {\n $formats = system_get_date_formats('custom');\n $format = trim($form_state['values']['date_format']);\n if (!empty($formats) && in_array($format, array_keys($formats)) && (!isset($form_state['values']['dfid']) || $form_state['values']['dfid'] != $formats[$format]['dfid'])) {\n form_set_error('date_format', t('This format already exists. Enter a unique format string.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ed3f809cad", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21image.inc/function/image_crop/7.x", "instruction": "In Drupal 7, write the function `image_crop(stdClass $image, $x, $y, $width, $height)` (file includes/image.inc) so that it does the following: Crops an image to a rectangle specified by the given dimensions.", "context": "Parameters:\n- $image: An image object returned by image_load().\n- $x: The top left coordinate, in pixels, of the crop area (x axis value).\n- $y: The top left coordinate, in pixels, of the crop area (y axis value).\n- $width: The target width, in pixels.\n- $height: The target height, in pixels.\n\nReturns: TRUE on success, FALSE on failure.\n\nFile: includes/image.inc", "response": "function image_crop(stdClass $image, $x, $y, $width, $height) {\n $aspect = $image->info['height'] / $image->info['width'];\n if (empty($height)) $height = $width / $aspect;\n if (empty($width)) $width = $height * $aspect;\n\n $width = (int) round($width);\n $height = (int) round($height);\n\n return image_toolkit_invoke('crop', $image, array($x, $y, $width, $height));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ed71a260b6", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_load_all/7.x", "instruction": "Implement `menu_load_all()` in PHP for Drupal 7. Required behavior: Load all custom menu data.", "context": "Returns (Array): of custom menu data.\n\nFile: modules/menu/menu.module", "response": "function menu_load_all() {\n $custom_menus = &drupal_static(__FUNCTION__);\n if (!isset($custom_menus)) {\n if ($cached = cache_get('menu_custom', 'cache_menu')) {\n $custom_menus = $cached->data;\n }\n else {\n $custom_menus = db_query('SELECT * FROM {menu_custom}')->fetchAllAssoc('menu_name', PDO::FETCH_ASSOC);\n cache_set('menu_custom', $custom_menus, 'cache_menu');\n }\n }\n return $custom_menus;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ed80a6380d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_tokens/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_tokens($type, $tokens, array $data = array(), array $options = array())` (modules/system/system.api.php): Provide replacement values for placeholder tokens.", "context": "This hook is invoked when someone calls token_replace(). That function first scans the text for [type:token] patterns, and splits the needed tokens into groups by type. Then hook_tokens() is invoked on each token-type group, allowing your module to respond by providing replacement text for any of the tokens in the group that your module knows how to process.\n\nA module implementing this hook should also implement hook_token_info() in order to list its available tokens on editing screens.\n\nParameters:\n- $type: The machine-readable name of the type (group) of token being replaced, such as 'node', 'user', or another type defined by a hook_token_info() implementation.\n- $tokens: An array of tokens to be replaced. The keys are the machine-readable token names, and the values are the raw [type:token] strings that appeared in the original text.\n- $data: (optional) An associative array of data objects to be used when generating replacement values, as supplied in the $data parameter to token_replace().\n- $options: (optional) An associative array of options for token replacement; see token_replace() for possible values.\n\nReturns: An associative array of replacement values, keyed by the raw [type:token] strings from the original text.\n\nFile: modules/system/system.api.php", "response": "function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {\n $url_options = array('absolute' => TRUE);\n if (isset($options['language'])) {\n $url_options['language'] = $options['language'];\n $language_code = $options['language']->language;\n }\n else {\n $language_code = NULL;\n }\n $sanitize = !empty($options['sanitize']);\n\n $replacements = array();\n\n if ($type == 'node' && !empty($data['node'])) {\n $node = $data['node'];\n\n foreach ($tokens as $name => $original) {\n switch ($name) {\n // Simple key values on the node.\n case 'nid':\n $replacements[$original] = $node->nid;\n break;\n\n case 'title':\n $replacements[$original] = $sanitize ? check_plain($node->title) : $node->title;\n break;\n\n case 'edit-url':\n $replacements[$original] = url('node/' . $node->nid . '/edit', $url_options);\n break;\n\n // Default values for the chained tokens handled below.\n case 'author':\n $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;\n $replacements[$original] = $sanitize ? filter_xss($name) : $name;\n break;\n\n case 'created':\n $replacements[$original] = format_date($node->created, 'medium', '', NULL, $language_code);\n break;\n }\n }\n\n if ($author_tokens = token_find_with_prefix($tokens, 'author')) {\n $author = user_load($node->uid);\n $replacements += token_generate('user', $author_tokens, array('user' => $author), $options);\n }\n\n if ($created_tokens = token_find_with_prefix($tokens, 'created')) {\n $replacements += token_generate('date', $created_tokens, array('date' => $node->created), $options);\n }\n }\n\n return $replacements;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-edadc1e5be", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_delete_form_submit/7.x", "instruction": "Implement `field_ui_field_delete_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for field_ui_field_delete_form().", "context": "Removes a field instance from a bundle. If the field has no more instances, it will be marked as deleted too.\n\nFile: modules/field_ui/field_ui.admin.inc", "response": "function field_ui_field_delete_form_submit($form, &$form_state) {\n $form_values = $form_state['values'];\n $field_name = $form_values['field_name'];\n $bundle = $form_values['bundle'];\n $entity_type = $form_values['entity_type'];\n\n $field = field_info_field($field_name);\n $instance = field_info_instance($entity_type, $field_name, $bundle);\n $bundles = field_info_bundles();\n $bundle_label = $bundles[$entity_type][$bundle]['label'];\n\n if (!empty($bundle) && $field && !$field['locked'] && $form_values['confirm']) {\n field_delete_instance($instance);\n drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label)));\n }\n else {\n drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label)), 'error');\n }\n\n $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);\n $form_state['redirect'] = field_ui_get_destinations(array($admin_path . '/fields'));\n\n // Fields are purged on cron. However field module prevents disabling modules\n // when field types they provided are used in a field until it is fully\n // purged. In the case that a field has minimal or no content, a single call\n // to field_purge_batch() will remove it from the system. Call this with a\n // low batch limit to avoid administrators having to wait for cron runs when\n // removing instances that meet this criteria.\n field_purge_batch(10);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-edb020db49", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_module_implements_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_module_implements_alter(&$implementations, $hook)` (modules/system/system.api.php): Alter the registry of modules implementing a hook.", "context": "This hook is invoked during module_implements(). A module may implement this hook in order to reorder the implementing modules, which are otherwise ordered by the module's system weight.\n\nNote that hooks invoked using drupal_alter() can have multiple variations (such as hook_form_alter() and hook_form_FORM_ID_alter()). drupal_alter() will call all such variants defined by a single module in turn. For the purposes of hook_module_implements_alter(), these variants are treated as a single hook. Thus, to ensure that your implementation of hook_form_FORM_ID_alter() is called at the right time, you will have to change the order of hook_form_alter() implementation in hook_module_implements_alter().\n\nParameters:\n- $implementations: An array keyed by the module's name. The value of each item corresponds to a $group, which is usually FALSE, unless the implementation is in a file named $module.$group.inc.\n- $hook: The name of the module hook being implemented.\n\nFile: modules/system/system.api.php", "response": "function hook_module_implements_alter(&$implementations, $hook) {\n if ($hook == 'rdf_mapping') {\n // Move my_module_rdf_mapping() to the end of the list. module_implements()\n // iterates through $implementations with a foreach loop which PHP iterates\n // in the order that the items were added, so to move an item to the end of\n // the array, we remove it and then add it.\n $group = $implementations['my_module'];\n unset($implementations['my_module']);\n $implementations['my_module'] = $group;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-edb3afbf88", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_block_configure/7.x", "instruction": "I need the code for `block_block_configure($delta = 0)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_block_configure().", "context": "File: modules/block/block.module", "response": "function block_block_configure($delta = 0) {\n if ($delta) {\n $custom_block = block_custom_block_get($delta);\n }\n else {\n $custom_block = array();\n }\n return block_custom_block_form($custom_block);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-edb583a4da", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.install/function/profile_schema/7.x", "instruction": "In Drupal 7, write the function `profile_schema()` (file modules/profile/profile.install) so that it does the following: Implements hook_schema().", "context": "File: modules/profile/profile.install", "response": "function profile_schema() {\n $schema['profile_field'] = array(\n 'description' => 'Stores profile field information.',\n 'fields' => array(\n 'fid' => array(\n 'type' => 'serial',\n 'not null' => TRUE,\n 'description' => 'Primary Key: Unique profile field ID.',\n ),\n 'title' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n 'description' => 'Title of the field shown to the end user.',\n ),\n 'name' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'Internal name of the field used in the form HTML and URLs.',\n ),\n 'explanation' => array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'description' => 'Explanation of the field to end users.',\n ),\n 'category' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n 'description' => 'Profile category that the field will be grouped under.',\n ),\n 'page' => array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => FALSE,\n 'description' => \"Title of page used for browsing by the field's value\",\n ),\n 'type' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => FALSE,\n 'description' => 'Type of form field.',\n ),\n 'weight' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Weight of field in relation to other profile fields.',\n ),\n 'required' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'tiny',\n 'description' => 'Whether the user is required to enter a value. (0 = no, 1 = yes)',\n ),\n 'register' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'tiny',\n 'description' => 'Whether the field is visible in the user registration form. (1 = yes, 0 = no)',\n ),\n 'visibility' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'tiny',\n 'description' => 'The level of visibility for the field. (0 = hidden, 1 = private, 2 = public on profile but not member list pages, 3 = public on profile and list pages)',\n ),\n 'autocomplete' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'size' => 'tiny',\n 'description' => 'Whether form auto-completion is enabled. (0 = disabled, 1 = enabled)',\n ),\n 'options' => array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'description' => 'List of options to be used in a list selection field.',\n ),\n ),\n 'indexes' => array(\n 'category' => array('category'),\n ),\n 'unique keys' => array(\n 'name' => array('name'),\n ),\n 'primary key' => array('fid'),\n );\n\n $schema['profile_value'] = array(\n 'description' => 'Stores values for profile fields.',\n 'fields' => array(\n 'fid' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The {profile_field}.fid of the field.',\n ),\n 'uid' => array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'The {users}.uid of the profile user.',\n ),\n 'value' => array(\n 'type' => 'text',\n 'not null' => FALSE,\n 'description' => 'The value for the field.',\n ),\n ),\n 'primary key' => array('uid', 'fid'),\n 'indexes' => array(\n 'fid' => array('fid'),\n ),\n 'foreign keys' => array(\n 'profile_field' => array(\n 'table' => 'profile_field',\n 'columns' => array('fid' => 'fid'),\n ),\n 'profile_user' => array(\n 'table' => 'users',\n 'columns' => array('uid' => 'uid'),\n ),\n ),\n );\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-edbeaa4e14", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21errors.inc/function/_drupal_get_last_caller/7.x", "instruction": "In Drupal 7, write the function `_drupal_get_last_caller($backtrace)` (file includes/errors.inc) so that it does the following: Gets the last caller from a backtrace.", "context": "Parameters:\n- $backtrace: A standard PHP backtrace.\n\nReturns: An associative array with keys 'file', 'line' and 'function'.\n\nFile: includes/errors.inc", "response": "function _drupal_get_last_caller($backtrace) {\n // Errors that occur inside PHP internal functions do not generate\n // information about file and line. Ignore black listed functions.\n $blacklist = array('debug', '_drupal_error_handler', '_drupal_exception_handler', 'drupal_trigger_fatal_error');\n while (($backtrace && !isset($backtrace[0]['line'])) ||\n (isset($backtrace[1]['function']) && in_array($backtrace[1]['function'], $blacklist))) {\n array_shift($backtrace);\n }\n\n // The first trace is the call itself.\n // It gives us the line and the file of the last call.\n $call = $backtrace[0];\n\n // The second call give us the function where the call originated.\n if (isset($backtrace[1])) {\n if (isset($backtrace[1]['class'])) {\n $call['function'] = $backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . '()';\n }\n else {\n $call['function'] = $backtrace[1]['function'] . '()';\n }\n }\n else {\n $call['function'] = 'main()';\n }\n return $call;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ede554d207", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21authorize.inc/function/_authorize_filetransfer_connection_settings/7.x", "instruction": "I need the code for `_authorize_filetransfer_connection_settings($backend)` in Drupal 7 (includes/authorize.inc). It must do this: Generates the Form API array for a given connection backend's settings.", "context": "Parameters:\n- $backend: The name of the backend (e.g. 'ftp', 'ssh', etc).\n\nReturns: Form API array of connection settings for the given backend.\n\nFile: includes/authorize.inc", "response": "function _authorize_filetransfer_connection_settings($backend) {\n $defaults = variable_get('authorize_filetransfer_connection_settings_' . $backend, array());\n $form = array();\n\n // Create an instance of the file transfer class to get its settings form.\n $filetransfer = authorize_get_filetransfer($backend);\n if ($filetransfer) {\n $form = $filetransfer->getSettingsForm();\n }\n // Fill in the defaults based on the saved settings, if any.\n _authorize_filetransfer_connection_settings_set_defaults($form, NULL, $defaults);\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-edf4be0153", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_form_comment_form_alter/7.x", "instruction": "I need the code for `locale_form_comment_form_alter(&$form, &$form_state, $form_id)` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_form_FORM_ID_alter().", "context": "File: modules/locale/locale.module", "response": "function locale_form_comment_form_alter(&$form, &$form_state, $form_id) {\n // If a content type has multilingual support we set the content language as\n // comment language.\n if ($form['language']['#value'] == LANGUAGE_NONE && locale_multilingual_node_type($form['#node']->type)) {\n global $language_content;\n $form['language']['#value'] = $language_content->language;\n $submit_callback = 'locale_field_comment_form_submit';\n array_unshift($form['actions']['preview']['#submit'], $submit_callback);\n array_unshift($form['#submit'], $submit_callback);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-edf6b8debe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_element_info_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_element_info_alter(&$type)` (modules/system/system.api.php): Alter the element type information returned from modules.", "context": "A module may implement this hook in order to alter the element type defaults defined by a module.\n\nParameters:\n- $type: All element type defaults as collected by hook_element_info().\n\nFile: modules/system/system.api.php", "response": "function hook_element_info_alter(&$type) {\n // Decrease the default size of textfields.\n if (isset($type['textfield']['#size'])) {\n $type['textfield']['#size'] = 40;\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee0119d366", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_prepare_view/7.x", "instruction": "I need the code for `field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL, $options = array())` in Drupal 7 (modules/field/field.attach.inc). It must do this: Prepare field data prior to display.", "context": "This function lets field types and formatters load additional data needed for display that is not automatically loaded during field_attach_load(). It accepts an array of entities to allow query optimisation when displaying lists of entities.\n\nfield_attach_prepare_view() and field_attach_view() are two halves of the same operation. It is safe to call field_attach_prepare_view() multiple times on the same entity before calling field_attach_view() on it, but calling any Field API operation on an entity between passing that entity to these two functions may yield incorrect results.\n\nParameters:\n- $entity_type: The type of $entities; e.g. 'node' or 'user'.\n- $entities: An array of entities, keyed by entity id.\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $langcode: (Optional) The language the field values are to be shown in. If no language is provided the current language is used.\n- $options (array): An associative array of additional options. See _field_invoke() for details.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL, $options = array()) {\n // Validate $options since this is a new parameter added after Drupal 7 was\n // released.\n $options = is_array($options) ? $options : array();\n\n $options['language'] = array();\n\n // To ensure hooks are only run once per entity, only process items without\n // the _field_view_prepared flag.\n // @todo: resolve this more generally for both entity and field level hooks.\n $prepare = array();\n foreach ($entities as $id => $entity) {\n if (empty($entity->_field_view_prepared)) {\n // Add this entity to the items to be prepared.\n $prepare[$id] = $entity;\n\n // Determine the actual language to display for each field, given the\n // languages available in the field data.\n $options['language'][$id] = field_language($entity_type, $entity, NULL, $langcode);\n\n // Mark this item as prepared.\n $entity->_field_view_prepared = TRUE;\n }\n }\n\n $null = NULL;\n // First let the field types do their preparation.\n _field_invoke_multiple('prepare_view', $entity_type, $prepare, $null, $null, $options);\n // Then let the formatters do their own specific massaging.\n // field_default_prepare_view() takes care of dispatching to the correct\n // formatters according to the display settings for the view mode.\n _field_invoke_multiple_default('prepare_view', $entity_type, $prepare, $view_mode, $null, $options);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee05967434", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_vertical_tabs/7.x", "instruction": "I need the code for `form_process_vertical_tabs($element, &$form_state)` in Drupal 7 (includes/form.inc). It must do this: Creates a group formatted as vertical tabs.", "context": "Parameters:\n- $element: An associative array containing the properties and children of the fieldset.\n- $form_state: The $form_state array for the form this vertical tab widget belongs to.\n\nReturns: The processed element.\n\nFile: includes/form.inc", "response": "function form_process_vertical_tabs($element, &$form_state) {\n // Inject a new fieldset as child, so that form_process_fieldset() processes\n // this fieldset like any other fieldset.\n $element['group'] = array(\n '#type' => 'fieldset',\n '#theme_wrappers' => array(),\n '#parents' => $element['#parents'],\n );\n\n // The JavaScript stores the currently selected tab in this hidden\n // field so that the active tab can be restored the next time the\n // form is rendered, e.g. on preview pages or when form validation\n // fails.\n $name = implode('__', $element['#parents']);\n if (isset($form_state['values'][$name . '__active_tab'])) {\n $element['#default_tab'] = $form_state['values'][$name . '__active_tab'];\n }\n $element[$name . '__active_tab'] = array(\n '#type' => 'hidden',\n '#default_value' => $element['#default_tab'],\n '#attributes' => array('class' => array('vertical-tabs-active-tab')),\n );\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee24e3b6f2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_delete/7.x", "instruction": "In Drupal 7, write the function `forum_node_delete($node)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_delete().", "context": "File: modules/forum/forum.module", "response": "function forum_node_delete($node) {\n if (_forum_node_check_node_type($node)) {\n db_delete('forum')\n ->condition('nid', $node->nid)\n ->execute();\n db_delete('forum_index')\n ->condition('nid', $node->nid)\n ->execute();\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee6ec12a29", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_field_attach_prepare_translation_alter/7.x", "instruction": "In Drupal 7, write the function `poll_field_attach_prepare_translation_alter(&$entity, $context)` (file modules/poll/poll.module) so that it does the following: Implements hook_field_attach_prepare_translation_alter().", "context": "File: modules/poll/poll.module", "response": "function poll_field_attach_prepare_translation_alter(&$entity, $context) {\n if ($context['entity_type'] == 'node' && $entity->type == 'poll') {\n $entity->choice = $context['source_entity']->choice;\n foreach ($entity->choice as $i => $options) {\n $entity->choice[$i]['chvotes'] = 0;\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee7c4df6f9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_login_name_validate/7.x", "instruction": "Implement `user_login_name_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: A FAPI validate handler. Sets an error if supplied username has been blocked.", "context": "File: modules/user/user.module", "response": "function user_login_name_validate($form, &$form_state) {\n if (!empty($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) {\n // Blocked in user administration.\n form_set_error('name', t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name'])));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee7d34b560", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_view/7.x", "instruction": "I need the code for `node_view($node, $view_mode = 'full', $langcode = NULL)` in Drupal 7 (modules/node/node.module). It must do this: Generates an array for rendering the given node.", "context": "Parameters:\n- $node: A node object.\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nReturns: An array as expected by drupal_render().\n\nFile: modules/node/node.module", "response": "function node_view($node, $view_mode = 'full', $langcode = NULL) {\n if (!isset($langcode)) {\n $langcode = $GLOBALS['language_content']->language;\n }\n\n // Populate $node->content with a render() array.\n node_build_content($node, $view_mode, $langcode);\n\n $build = $node->content;\n // We don't need duplicate rendering info in node->content.\n unset($node->content);\n\n $build += array(\n '#theme' => 'node',\n '#node' => $node,\n '#view_mode' => $view_mode,\n '#language' => $langcode,\n );\n\n // Add contextual links for this node, except when the node is already being\n // displayed on its own page. Modules may alter this behavior (for example,\n // to restrict contextual links to certain view modes) by implementing\n // hook_node_view_alter().\n if (!empty($node->nid) && !($view_mode == 'full' && node_is_page($node))) {\n $build['#contextual_links']['node'] = array('node', array($node->nid));\n }\n\n // Allow modules to modify the structured node.\n $type = 'node';\n drupal_alter(array('node_view', 'entity_view'), $build, $type);\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee901e530d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_cache_clear/7.x", "instruction": "Implement `_update_cache_clear($cid = NULL, $wildcard = FALSE)` in PHP for Drupal 7. Required behavior: Invalidates cached data relating to update status.", "context": "Parameters:\n- $cid: (optional) Cache ID of the record to clear from the private update module cache. If empty, all records will be cleared from the table except fetch tasks. Defaults to NULL.\n- $wildcard: (optional) If TRUE, cache IDs starting with $cid are deleted in addition to the exact cache ID specified by $cid. Defaults to FALSE.\n\nFile: modules/update/update.module", "response": "function _update_cache_clear($cid = NULL, $wildcard = FALSE) {\n if (empty($cid)) {\n db_delete('cache_update')\n // Clear everything except fetch task information because these are used\n // to ensure that the fetch task queue items are not added multiple times.\n ->condition('cid', 'fetch_task::%', 'NOT LIKE')\n ->execute();\n }\n else {\n $query = db_delete('cache_update');\n if ($wildcard) {\n $query->condition('cid', $cid . '%', 'LIKE');\n }\n else {\n $query->condition('cid', $cid);\n }\n $query->execute();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ee9d1b658e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_add_form_validate/7.x", "instruction": "In Drupal 7, write the function `shortcut_set_add_form_validate($form, &$form_state)` (file modules/shortcut/shortcut.admin.inc) so that it does the following: Validation handler for shortcut_set_add_form().", "context": "File: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_set_add_form_validate($form, &$form_state) {\n // Check to prevent a duplicate title.\n if (shortcut_set_title_exists($form_state['values']['new'])) {\n form_set_error('new', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['new'])));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eea6e2c752", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.install/function/file_requirements/7.x", "instruction": "Implement `file_requirements($phase)` in PHP for Drupal 7. Required behavior: Implements hook_requirements().", "context": "Display information about getting upload progress bars working.\n\nFile: modules/file/file.install", "response": "function file_requirements($phase) {\n $requirements = array();\n\n // Check the server's ability to indicate upload progress.\n if ($phase == 'runtime') {\n $description = NULL;\n $implementation = file_progress_implementation();\n // Test the web server identity.\n $server_software = $_SERVER['SERVER_SOFTWARE'];\n if (preg_match(\"/Nginx/i\", $server_software)) {\n $is_nginx = TRUE;\n $is_apache = FALSE;\n $fastcgi = FALSE;\n }\n elseif (preg_match(\"/Apache/i\", $server_software)) {\n $is_nginx = FALSE;\n $is_apache = TRUE;\n $fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE;\n }\n else {\n $is_nginx = FALSE;\n $is_apache = FALSE;\n $fastcgi = FALSE;\n }\n\n if (!$is_apache && !$is_nginx) {\n $value = t('Not enabled');\n $description = t('Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php or Nginx with PHP-FPM.');\n $severity = REQUIREMENT_INFO;\n }\n elseif ($fastcgi) {\n $value = t('Not enabled');\n $description = t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php or PHP-FPM and not as FastCGI.');\n $severity = REQUIREMENT_INFO;\n }\n elseif (!$implementation && extension_loaded('apc')) {\n $value = t('Not enabled');\n $description = t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add apc.rfc1867 = 1 to your php.ini configuration. Alternatively, it is recommended to use PECL uploadprogress, which supports more than one simultaneous upload.');\n $severity = REQUIREMENT_INFO;\n }\n elseif (!$implementation) {\n $value = t('Not enabled');\n $description = t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the PECL uploadprogress library (preferred) or to install APC.');\n $severity = REQUIREMENT_INFO;\n }\n elseif ($implementation == 'apc') {\n $value = t('Enabled (APC RFC1867)');\n $description = t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the PECL uploadprogress library if possible.');\n $severity = REQUIREMENT_OK;\n }\n elseif ($implementation == 'uploadprogress') {\n $value = t('Enabled (PECL uploadprogress)');\n $severity = REQUIREMENT_OK;\n }\n $requirements['file_progress'] = array(\n 'title' => t('Upload progress'),\n 'value' => $value,\n 'severity' => $severity,\n 'description' => $description,\n );\n }\n\n return $requirements;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-eeacd9e251", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_display_output/7.x", "instruction": "I need the code for `install_display_output($output, $install_state)` in Drupal 7 (includes/install.core.inc). It must do this: Displays themed installer output and ends the page request.", "context": "Installation tasks should use drupal_set_title() to set the desired page title, but otherwise this function takes care of theming the overall page output during every step of the installation.\n\nParameters:\n- $output: The content to display on the main part of the page.\n- $install_state: An array of information about the current installation state.\n\nFile: includes/install.core.inc", "response": "function install_display_output($output, $install_state) {\n drupal_page_header();\n\n // Prevent install.php from being indexed when installed in a sub folder.\n // robots.txt rules are not read if the site is within domain.com/subfolder\n // resulting in /subfolder/install.php being found through search engines.\n // When settings.php is writeable this can be used via an external database\n // leading a malicious user to gain php access to the server.\n $noindex_meta_tag = array(\n '#tag' => 'meta',\n '#attributes' => array(\n 'name' => 'robots',\n 'content' => 'noindex, nofollow',\n ),\n );\n drupal_add_html_head($noindex_meta_tag, 'install_meta_robots');\n\n // Only show the task list if there is an active task; otherwise, the page\n // request has ended before tasks have even been started, so there is nothing\n // meaningful to show.\n if (isset($install_state['active_task'])) {\n // Let the theming function know when every step of the installation has\n // been completed.\n $active_task = $install_state['installation_finished'] ? NULL : $install_state['active_task'];\n drupal_add_region_content('sidebar_first', theme('task_list', array('items' => install_tasks_to_display($install_state), 'active' => $active_task)));\n }\n print theme('install_page', array('content' => $output));\n exit;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eeb2d180d2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_permission/7.x", "instruction": "Give me the example code for `hook_permission()` in Drupal 7. Hook description: Define user permissions.", "context": "This hook can supply permissions that the module defines, so that they can be selected on the user permissions page and used to grant or restrict access to actions the module performs.\n\nPermissions are checked using user_access().\n\nFor a detailed usage example, see page_example.module.\n\nReturns: An array whose keys are permission names and whose corresponding values are arrays containing the following key-value pairs: - title: The human-readable name of the permission, to be shown on the permission administration page. This should be wrapped in the t() function so it can be translated. - description: (optional) A description of what the permission does. This should be wrapped in the t() function so it can be translated. - restrict access: (optional) A boolean which can be set to TRUE to indicate that site administrators should restrict access to this permission to trusted users. This should be used for permissions that have inherent security risks across a variety of potential use cases (for example, the \"administer filters\" and \"bypass node access\" permissions provided by Drupal core). When set to TRUE, a standard warning message defined in user_admin_permissions() and output via theme_user_permission_description() will be associated with the permission and displayed with it on the permission administration page. Defaults to FALSE. - warning: (optional) A translated warning message to display for this permission on the permission administration page. This warning overrides the automatic warning generated by 'restrict access' being set to TRUE. This should rarely be used, since it is important for all permissions to have a clear, consistent security warning that is the same across the site. Use the 'description' key instead to provide any information that is specific to the permission you are defining.\n\nFile: modules/system/system.api.php", "response": "function hook_permission() {\n return array(\n 'administer my module' => array(\n 'title' => t('Administer my module'),\n 'description' => t('Perform administration tasks for my module.'),\n ),\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-eeee1303ee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21pager.inc/function/theme_pager_previous/7.x", "instruction": "Implement `theme_pager_previous($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the \"previous page\" link in a query pager.", "context": "Parameters:\n- $variables: An associative array containing: - text: The name (or image) of the link. - element: An optional integer to distinguish between multiple pagers on one page. - interval: The number of pages to move backward when the link is clicked. - parameters: An associative array of query string parameters to append to the pager links.\n\nFile: includes/pager.inc", "response": "function theme_pager_previous($variables) {\n $text = $variables['text'];\n $element = $variables['element'];\n $interval = $variables['interval'];\n $parameters = $variables['parameters'];\n global $pager_page_array;\n $output = '';\n\n // Nothing to do if there is no pager.\n if (!isset($pager_page_array[$element])) {\n return;\n }\n\n // If we are anywhere but the first page\n if ($pager_page_array[$element] > 0) {\n $page_new = pager_load_array($pager_page_array[$element] - $interval, $element, $pager_page_array);\n\n // If the previous page is the first page, mark the link as such.\n if ($page_new[$element] == 0) {\n $output = theme('pager_first', array('text' => $text, 'element' => $element, 'parameters' => $parameters));\n }\n // The previous page is not the first page.\n else {\n $output = theme('pager_link', array('text' => $text, 'page_new' => $page_new, 'element' => $element, 'parameters' => $parameters));\n }\n }\n\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef0d51e424", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_load_include/7.x", "instruction": "In Drupal 7, write the function `form_load_include(&$form_state, $type, $module, $name = NULL)` (file includes/form.inc) so that it does the following: Ensures an include file is loaded whenever the form is processed.", "context": "Example:\n\nParameters:\n- $form_state: The current state of the form.\n- $type: The include file's type (file extension).\n- $module: The module to which the include file belongs.\n- $name: (optional) The base file name (without the $type extension). If omitted, $module is used; i.e., resulting in \"$module.$type\" by default.\n\nReturns: The filepath of the loaded include file, or FALSE if the include file was not found or has been loaded already.\n\nFile: includes/form.inc", "response": "function form_load_include(&$form_state, $type, $module, $name = NULL) {\n if (!isset($name)) {\n $name = $module;\n }\n if (!isset($form_state['build_info']['files'][\"$module:$name.$type\"])) {\n // Only add successfully included files to the form state.\n if ($result = module_load_include($type, $module, $name)) {\n $form_state['build_info']['files'][\"$module:$name.$type\"] = array(\n 'type' => $type,\n 'module' => $module,\n 'name' => $name,\n );\n return $result;\n }\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef3df3b187", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_vocabulary_confirm_delete_submit/7.x", "instruction": "I need the code for `taxonomy_vocabulary_confirm_delete_submit($form, &$form_state)` in Drupal 7 (modules/taxonomy/taxonomy.admin.inc). It must do this: Submit handler to delete a vocabulary after confirmation.", "context": "File: modules/taxonomy/taxonomy.admin.inc", "response": "function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) {\n $status = taxonomy_vocabulary_delete($form_state['values']['vid']);\n drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_state['values']['name'])));\n watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);\n $form_state['redirect'] = 'admin/structure/taxonomy';\n cache_clear_all();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef43ab4807", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_permission/7.x", "instruction": "Implement `taxonomy_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().", "context": "File: modules/taxonomy/taxonomy.module", "response": "function taxonomy_permission() {\n $permissions = array(\n 'administer taxonomy' => array(\n 'title' => t('Administer vocabularies and terms'),\n ),\n );\n foreach (taxonomy_get_vocabularies() as $vocabulary) {\n $permissions += array(\n 'edit terms in ' . $vocabulary->vid => array(\n 'title' => t('Edit terms in %vocabulary', array('%vocabulary' => $vocabulary->name)),\n ),\n );\n $permissions += array(\n 'delete terms in ' . $vocabulary->vid => array(\n 'title' => t('Delete terms from %vocabulary', array('%vocabulary' => $vocabulary->name)),\n ),\n );\n }\n return $permissions;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef493ed410", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/batch_process/7.x", "instruction": "Implement `batch_process($redirect = NULL, $url = 'batch', $redirect_callback = 'drupal_goto')` in PHP for Drupal 7. Required behavior: Processes the batch.", "context": "Unless the batch has been marked with 'progressive' = FALSE, the function issues a drupal_goto and thus ends page execution.\n\nThis function is generally not needed in form submit handlers; Form API takes care of batches that were set during form submission.\n\nParameters:\n- $redirect: (optional) Path to redirect to when the batch has finished processing.\n- $url: (optional - should only be used for separate scripts like update.php) URL of the batch processing page.\n- $redirect_callback: (optional) Specify a function to be called to redirect to the progressive processing page. By default drupal_goto() will be used to redirect to a page which will do the progressive page. Specifying another function will allow the progressive processing to be processed differently.\n\nFile: includes/form.inc", "response": "function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = 'drupal_goto') {\n $batch =& batch_get();\n\n drupal_theme_initialize();\n\n if (isset($batch)) {\n // Add process information\n $process_info = array(\n 'current_set' => 0,\n 'progressive' => TRUE,\n 'url' => $url,\n 'url_options' => array(),\n 'source_url' => $_GET['q'],\n 'redirect' => $redirect,\n 'theme' => $GLOBALS['theme_key'],\n 'redirect_callback' => $redirect_callback,\n );\n $batch += $process_info;\n\n // The batch is now completely built. Allow other modules to make changes\n // to the batch so that it is easier to reuse batch processes in other\n // environments.\n drupal_alter('batch', $batch);\n\n // Assign an arbitrary id: don't rely on a serial column in the 'batch'\n // table, since non-progressive batches skip database storage completely.\n $batch['id'] = db_next_id();\n\n // Move operations to a job queue. Non-progressive batches will use a\n // memory-based queue.\n foreach ($batch['sets'] as $key => $batch_set) {\n _batch_populate_queue($batch, $key);\n }\n\n // Initiate processing.\n if ($batch['progressive']) {\n // Now that we have a batch id, we can generate the redirection link in\n // the generic error message.\n $t = get_t();\n $batch['error_message'] = $t('Please continue to the error page', array('@error_url' => url($url, array('query' => array('id' => $batch['id'], 'op' => 'finished')))));\n\n // Clear the way for the drupal_goto() redirection to the batch processing\n // page, by saving and unsetting the 'destination', if there is any.\n if (isset($_GET['destination'])) {\n $batch['destination'] = $_GET['destination'];\n unset($_GET['destination']);\n }\n\n // Store the batch.\n db_insert('batch')\n ->fields(array(\n 'bid' => $batch['id'],\n 'timestamp' => REQUEST_TIME,\n 'token' => drupal_get_token($batch['id']),\n 'batch' => serialize($batch),\n ))\n ->execute();\n\n // Set the batch number in the session to guarantee that it will stay alive.\n $_SESSION['batches'][$batch['id']] = TRUE;\n\n // Redirect for processing.\n $function = $batch['redirect_callback'];\n if (function_exists($function)) {\n $function($batch['url'], array('query' => array('op' => 'start', 'id' => $batch['id'])));\n }\n }\n else {\n // Non-progressive execution: bypass the whole progressbar workflow\n // and execute the batch in one pass.\n require_once DRUPAL_ROOT . '/includes/batch.inc';\n _batch_process();\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef50cd66ae", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21profile%21profile.admin.inc/function/profile_field_form_validate/7.x", "instruction": "In Drupal 7, write the function `profile_field_form_validate($form, &$form_state)` (file modules/profile/profile.admin.inc) so that it does the following: Validate profile_field_form submissions.", "context": "File: modules/profile/profile.admin.inc", "response": "function profile_field_form_validate($form, &$form_state) {\n // Validate the 'field name':\n if (preg_match('/[^a-zA-Z0-9_-]/', $form_state['values']['name'])) {\n form_set_error('name', t('The specified form name contains one or more illegal characters. Spaces or any other special characters except dash (-) and underscore (_) are not allowed.'));\n }\n\n $users_table = drupal_get_schema('users');\n if (!empty($users_table['fields'][$form_state['values']['name']])) {\n form_set_error('name', t('The specified form name is reserved for use by Drupal.'));\n }\n // Validate the category:\n if (!$form_state['values']['category']) {\n form_set_error('category', t('You must enter a category.'));\n }\n if (strtolower($form_state['values']['category']) == 'account') {\n form_set_error('category', t('The specified category name is reserved for use by Drupal.'));\n }\n $query = db_select('profile_field');\n $query->fields('profile_field', array('fid'));\n\n if (isset($form_state['values']['fid'])) {\n $query->condition('fid', $form_state['values']['fid'], '<>');\n }\n $query_name = clone $query;\n\n $title = $query\n ->condition('title', $form_state['values']['title'])\n ->condition('category', $form_state['values']['category'])\n ->execute()\n ->fetchField();\n if ($title) {\n form_set_error('title', t('The specified title is already in use.'));\n }\n $name = $query_name\n ->condition('name', $form_state['values']['name'])\n ->execute()\n ->fetchField();\n if ($name) {\n form_set_error('name', t('The specified name is already in use.'));\n }\n if ($form_state['values']['visibility'] == PROFILE_HIDDEN) {\n if ($form_state['values']['required']) {\n form_set_error('required', t('A hidden field cannot be required.'));\n }\n if ($form_state['values']['register']) {\n form_set_error('register', t('A hidden field cannot be set to visible on the user registration form.'));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef6160b107", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_link_find_parent/7.x", "instruction": "Implement `_menu_link_find_parent($menu_link, $parent_candidates = array())` in PHP for Drupal 7. Required behavior: Finds a possible parent for a given menu link.", "context": "Because the parent of a given link might not exist anymore in the database, we apply a set of heuristics to determine a proper parent:\n\n- use the passed parent link if specified and existing.\n - else, use the first existing link down the previous link hierarchy\n - else, for system menu links (derived from hook_menu()), reparent\n based on the path hierarchy.\n\nParameters:\n- $menu_link: A menu link.\n- $parent_candidates: An array of menu links keyed by mlid.\n\nReturns: A menu link structure of the possible parent or FALSE if no valid parent has been found.\n\nFile: includes/menu.inc", "response": "function _menu_link_find_parent($menu_link, $parent_candidates = array()) {\n $parent = FALSE;\n\n // This item is explicitely top-level, skip the rest of the parenting.\n if (isset($menu_link['plid']) && empty($menu_link['plid'])) {\n return $parent;\n }\n\n // If we have a parent link ID, try to use that.\n $candidates = array();\n if (isset($menu_link['plid'])) {\n $candidates[] = $menu_link['plid'];\n }\n\n // Else, if we have a link hierarchy try to find a valid parent in there.\n if (!empty($menu_link['depth']) && $menu_link['depth'] > 1) {\n for ($depth = $menu_link['depth'] - 1; $depth >= 1; $depth--) {\n $candidates[] = $menu_link['p' . $depth];\n }\n }\n\n foreach ($candidates as $mlid) {\n if (isset($parent_candidates[$mlid])) {\n $parent = $parent_candidates[$mlid];\n }\n else {\n $parent = db_query(\"SELECT * FROM {menu_links} WHERE mlid = :mlid\", array(':mlid' => $mlid))->fetchAssoc();\n }\n if ($parent) {\n return $parent;\n }\n }\n\n // If everything else failed, try to derive the parent from the path\n // hierarchy. This only makes sense for links derived from menu router\n // items (ie. from hook_menu()).\n if ($menu_link['module'] == 'system') {\n $query = db_select('menu_links');\n $query->condition('module', 'system');\n // We always respect the link's 'menu_name'; inheritance for router items is\n // ensured in _menu_router_build().\n $query->condition('menu_name', $menu_link['menu_name']);\n\n // Find the parent - it must be unique.\n $parent_path = $menu_link['link_path'];\n do {\n $parent = FALSE;\n $parent_path = substr($parent_path, 0, strrpos($parent_path, '/'));\n $new_query = clone $query;\n $new_query->condition('link_path', $parent_path);\n // Only valid if we get a unique result.\n if ($new_query->countQuery()->execute()->fetchField() == 1) {\n $parent = $new_query->fields('menu_links')->execute()->fetchAssoc();\n }\n } while ($parent === FALSE && $parent_path);\n }\n\n return $parent;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef619a764d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/_tracker_calculate_changed/7.x", "instruction": "Implement `_tracker_calculate_changed($nid)` in PHP for Drupal 7. Required behavior: Determines the max timestamp between $node->changed and the last comment.", "context": "Parameters:\n- $nid: A node ID.\n\nReturns: The $node->changed timestamp, or most recent comment timestamp, whichever is the greatest.\n\nFile: modules/tracker/tracker.module", "response": "function _tracker_calculate_changed($nid) {\n $changed = db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchField();\n $latest_comment = db_query_range('SELECT cid, changed FROM {comment} WHERE nid = :nid AND status = :status ORDER BY changed DESC', 0, 1, array(\n ':nid' => $nid,\n ':status' => COMMENT_PUBLISHED,\n ), array('target' => 'slave'))->fetchObject();\n if ($latest_comment && $latest_comment->changed > $changed) {\n $changed = $latest_comment->changed;\n }\n return $changed;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef7a27a55d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_preprocess_page/7.x", "instruction": "In Drupal 7, write the function `garland_preprocess_page(&$variables)` (file themes/garland/template.php) so that it does the following: Override or insert variables into the page template.", "context": "File: themes/garland/template.php", "response": "function garland_preprocess_page(&$variables) {\n // Move secondary tabs into a separate variable.\n $variables['tabs2'] = array(\n '#theme' => 'menu_local_tasks',\n '#secondary' => $variables['tabs']['#secondary'],\n );\n unset($variables['tabs']['#secondary']);\n\n if (isset($variables['main_menu'])) {\n $variables['primary_nav'] = theme('links__system_main_menu', array(\n 'links' => $variables['main_menu'],\n 'attributes' => array(\n 'class' => array('links', 'inline', 'main-menu'),\n ),\n 'heading' => array(\n 'text' => t('Main menu'),\n 'level' => 'h2',\n 'class' => array('element-invisible'),\n )\n ));\n }\n else {\n $variables['primary_nav'] = FALSE;\n }\n if (isset($variables['secondary_menu'])) {\n $variables['secondary_nav'] = theme('links__system_secondary_menu', array(\n 'links' => $variables['secondary_menu'],\n 'attributes' => array(\n 'class' => array('links', 'inline', 'secondary-menu'),\n ),\n 'heading' => array(\n 'text' => t('Secondary menu'),\n 'level' => 'h2',\n 'class' => array('element-invisible'),\n )\n ));\n }\n else {\n $variables['secondary_nav'] = FALSE;\n }\n\n // Prepare header.\n $site_fields = array();\n if (!empty($variables['site_name'])) {\n $site_fields[] = $variables['site_name'];\n }\n if (!empty($variables['site_slogan'])) {\n $site_fields[] = $variables['site_slogan'];\n }\n $variables['site_title'] = implode(' ', $site_fields);\n if (!empty($site_fields)) {\n $site_fields[0] = '' . $site_fields[0] . '';\n }\n $variables['site_html'] = implode(' ', $site_fields);\n\n // Set a variable for the site name title and logo alt attributes text.\n $slogan_text = $variables['site_slogan'];\n $site_name_text = $variables['site_name'];\n $variables['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef9e5cfa71", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.install/function/_update_7000_field_delete_field/7.x", "instruction": "Implement `_update_7000_field_delete_field($field_name)` in PHP for Drupal 7. Required behavior: Utility function: delete a field stored in SQL storage directly from the database.", "context": "To protect user data, this function can only be used to delete fields once all information it stored is gone. Delete all data from the field_data_$field_name table before calling by either manually issuing delete queries against it or using _update_7000_field_delete_instance().\n\nThis function can be used for databases whose schema is at field module version 7000 or higher.\n\nParameters:\n- $field_name: The field name to delete.\n\nFile: modules/field/field.install", "response": "function _update_7000_field_delete_field($field_name) {\n $table_name = 'field_data_' . $field_name;\n if (db_select($table_name)->range(0, 1)->countQuery()->execute()->fetchField()) {\n $t = get_t();\n throw new Exception($t('This function can only be used to delete fields without data'));\n }\n // Delete all instances.\n db_delete('field_config_instance')\n ->condition('field_name', $field_name)\n ->execute();\n\n // Nuke field data and revision tables.\n db_drop_table($table_name);\n db_drop_table('field_revision_' . $field_name);\n\n // Delete the field.\n db_delete('field_config')\n ->condition('field_name', $field_name)\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-ef9eeb7134", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_modules_disabled/7.x", "instruction": "In Drupal 7, write the function `field_modules_disabled($modules)` (file modules/field/field.module) so that it does the following: Implements hook_modules_disabled().", "context": "File: modules/field/field.module", "response": "function field_modules_disabled($modules) {\n // Refresh the 'active' status of fields.\n field_sync_field_status();\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-efa94438e8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.install/function/filter_update_7000/7.x", "instruction": "I need the code for `filter_update_7000()` in Drupal 7 (modules/filter/filter.install). It must do this: Upgrade the {filter_formats} table and rename it to {filter_format}.", "context": "File: modules/filter/filter.install", "response": "function filter_update_7000() {\n db_rename_table('filter_formats', 'filter_format');\n\n // Add the new {filter_format}.status and {filter_format}.weight column.\n db_add_field('filter_format', 'status', array(\n 'type' => 'int',\n 'unsigned' => TRUE,\n 'not null' => TRUE,\n 'default' => 1,\n 'size' => 'tiny',\n 'description' => 'The status of the text format. (1 = enabled, 0 = disabled)',\n ));\n db_add_field('filter_format', 'weight', array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Weight of text format to use when listing.',\n ), array(\n 'indexes' => array(\n 'status_weight' => array('status', 'weight'),\n ),\n ));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efbb76fc0c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7.x", "instruction": "In Drupal 7, write the function `field_get_items($entity_type, $entity, $field_name, $langcode = NULL)` (file modules/field/field.module) so that it does the following: Returns the field items in the language they currently would be displayed.", "context": "Parameters:\n- $entity_type: The type of $entity; e.g., 'node' or 'user'.\n- $entity: The entity containing the data to be displayed.\n- $field_name: The field to be displayed.\n- $langcode: (optional) The language code $entity->{$field_name} has to be displayed in. Defaults to the current language.\n\nReturns: An array of field items keyed by delta if available, FALSE otherwise.\n\nFile: modules/field/field.module", "response": "function field_get_items($entity_type, $entity, $field_name, $langcode = NULL) {\n $langcode = field_language($entity_type, $entity, $field_name, $langcode);\n return isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efc961d306", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_logout_current_user/7.x", "instruction": "Implement `user_logout_current_user()` in PHP for Drupal 7. Required behavior: Logs the current user out.", "context": "File: modules/user/user.pages.inc", "response": "function user_logout_current_user() {\n global $user;\n\n watchdog('user', 'Session closed for %name.', array('%name' => $user->name));\n\n module_invoke_all('user_logout', $user);\n\n // Destroy the current session, and reset $user to the anonymous user.\n session_destroy();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efceef5cf8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21unicode.inc/function/_unicode_check/7.x", "instruction": "I need the code for `_unicode_check()` in Drupal 7 (includes/unicode.inc). It must do this: Perform checks about Unicode support in PHP, and set the right settings if needed.", "context": "Because Drupal needs to be able to handle text in various encodings, we do not support mbstring function overloading. HTTP input/output conversion must be disabled for similar reasons.\n\nParameters:\n- $errors: Whether to report any fatal errors with form_set_error().\n\nFile: includes/unicode.inc", "response": "function _unicode_check() {\n // Ensure translations don't break during installation.\n $t = get_t();\n\n // Check for mbstring extension\n if (!function_exists('mb_strlen')) {\n return array(UNICODE_SINGLEBYTE, $t('Operations on Unicode strings are emulated on a best-effort basis. Install the PHP mbstring extension for improved Unicode support.', array('@url' => 'http://www.php.net/mbstring')));\n }\n\n // Check mbstring configuration\n if (ini_get('mbstring.func_overload') != 0) {\n return array(UNICODE_ERROR, $t('Multibyte string function overloading in PHP is active and must be disabled. Check the php.ini mbstring.func_overload setting. Please refer to the PHP mbstring documentation for more information.', array('@url' => 'http://www.php.net/mbstring')));\n }\n if (ini_get('mbstring.encoding_translation') != 0) {\n return array(UNICODE_ERROR, $t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini mbstring.encoding_translation setting. Please refer to the PHP mbstring documentation for more information.', array('@url' => 'http://www.php.net/mbstring')));\n }\n // mbstring.http_input and mbstring.http_output are deprecated and empty by\n // default in PHP 5.6.\n if (version_compare(PHP_VERSION, '5.6.0') == -1) {\n if (ini_get('mbstring.http_input') != 'pass') {\n return array(UNICODE_ERROR, $t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini mbstring.http_input setting. Please refer to the PHP mbstring documentation for more information.', array('@url' => 'http://www.php.net/mbstring')));\n }\n if (ini_get('mbstring.http_output') != 'pass') {\n return array(UNICODE_ERROR, $t('Multibyte string output conversion in PHP is active and must be disabled. Check the php.ini mbstring.http_output setting. Please refer to the PHP mbstring documentation for more information.', array('@url' => 'http://www.php.net/mbstring')));\n }\n }\n\n // Set appropriate configuration\n mb_internal_encoding('utf-8');\n mb_language('uni');\n return array(UNICODE_MULTIBYTE, '');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efd33c078d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_cache_get/7.x", "instruction": "Implement `_update_cache_get($cid)` in PHP for Drupal 7. Required behavior: Retrieves data from the private update status cache table.", "context": "Parameters:\n- $cid: The cache ID to retrieve.\n\nReturns: An array of data for the given cache ID, or NULL if the ID was not found.\n\nFile: modules/update/update.module", "response": "function _update_cache_get($cid) {\n $cache = db_query(\"SELECT data, created, expire, serialized FROM {cache_update} WHERE cid = :cid\", array(':cid' => $cid))->fetchObject();\n if (isset($cache->data)) {\n if ($cache->serialized) {\n $cache->data = unserialize($cache->data);\n }\n }\n return $cache;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efd4de6f52", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_field_overview_form_validate_add_new/7.x", "instruction": "Implement `_field_ui_field_overview_form_validate_add_new($form, &$form_state)` in PHP for Drupal 7. Required behavior: Validates the 'add new field' row of field_ui_field_overview_form().", "context": "File: modules/field_ui/field_ui.admin.inc", "response": "function _field_ui_field_overview_form_validate_add_new($form, &$form_state) {\n $field = $form_state['values']['fields']['_add_new_field'];\n\n // Validate if any information was provided in the 'add new field' row.\n if (array_filter(array($field['label'], $field['field_name'], $field['type'], $field['widget_type']))) {\n // Missing label.\n if (!$field['label']) {\n form_set_error('fields][_add_new_field][label', t('Add new field: you need to provide a label.'));\n }\n\n // Missing field name.\n if (!$field['field_name']) {\n form_set_error('fields][_add_new_field][field_name', t('Add new field: you need to provide a field name.'));\n }\n // Field name validation.\n else {\n $field_name = $field['field_name'];\n\n // Add the 'field_' prefix.\n $field_name = 'field_' . $field_name;\n form_set_value($form['fields']['_add_new_field']['field_name'], $field_name, $form_state);\n }\n\n // Missing field type.\n if (!$field['type']) {\n form_set_error('fields][_add_new_field][type', t('Add new field: you need to select a field type.'));\n }\n\n // Missing widget type.\n if (!$field['widget_type']) {\n form_set_error('fields][_add_new_field][widget_type', t('Add new field: you need to select a widget.'));\n }\n // Wrong widget type.\n elseif ($field['type']) {\n $widget_types = field_ui_widget_type_options($field['type']);\n if (!isset($widget_types[$field['widget_type']])) {\n form_set_error('fields][_add_new_field][widget_type', t('Add new field: invalid widget.'));\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efdba5b901", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_validate_machine_name/7.x", "instruction": "In Drupal 7, write the function `form_validate_machine_name(&$element, &$form_state)` (file includes/form.inc) so that it does the following: Form element validation handler for machine_name elements.", "context": "Note that #maxlength is validated by _form_validate() already.\n\nFile: includes/form.inc", "response": "function form_validate_machine_name(&$element, &$form_state) {\n // Verify that the machine name not only consists of replacement tokens.\n if (preg_match('@^' . $element['#machine_name']['replace'] . '+$@', $element['#value'])) {\n form_error($element, t('The machine-readable name must contain unique characters.'));\n }\n\n // Verify that the machine name contains no disallowed characters.\n if (preg_match('@' . $element['#machine_name']['replace_pattern'] . '@', $element['#value'])) {\n if (!isset($element['#machine_name']['error'])) {\n // Since a hyphen is the most common alternative replacement character,\n // a corresponding validation error message is supported here.\n if ($element['#machine_name']['replace'] == '-') {\n form_error($element, t('The machine-readable name must contain only lowercase letters, numbers, and hyphens.'));\n }\n // Otherwise, we assume the default (underscore).\n else {\n form_error($element, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));\n }\n }\n else {\n form_error($element, $element['#machine_name']['error']);\n }\n }\n\n // Verify that the machine name is unique.\n if ($element['#default_value'] !== $element['#value']) {\n $function = $element['#machine_name']['exists'];\n if ($function($element['#value'], $element, $form_state)) {\n form_error($element, t('The machine-readable name is already in use. It must be unique.'));\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efe51e7fef", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/element_sort_by_title/7.x", "instruction": "In Drupal 7, write the function `element_sort_by_title($a, $b)` (file includes/common.inc) so that it does the following: Array sorting callback; sorts elements by title.", "context": "File: includes/common.inc", "response": "function element_sort_by_title($a, $b) {\n $a_title = (is_array($a) && isset($a['#title'])) ? $a['#title'] : '';\n $b_title = (is_array($b) && isset($b['#title'])) ? $b['#title'] : '';\n return strnatcasecmp($a_title, $b_title);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-efeced151e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_process_attached/7.x", "instruction": "Implement `drupal_process_attached($elements, $group = JS_DEFAULT, $dependency_check = FALSE, $every_page = NULL)` in PHP for Drupal 7. Required behavior: Adds attachments to a render() structure.", "context": "Libraries, JavaScript, CSS and other types of custom structures are attached to elements using the #attached property. The #attached property is an associative array, where the keys are the attachment types and the values are the attached data. For example:\n\nParameters:\n- $elements: The structured array describing the data being rendered.\n- $group: The default group of JavaScript and CSS being added. This is only applied to the stylesheets and JavaScript items that don't have an explicit group assigned to them.\n- $dependency_check: When TRUE, will exit if a given library's dependencies are missing. When set to FALSE, will continue to add the libraries, even though one or more dependencies are missing. Defaults to FALSE.\n- $every_page: Set to TRUE to indicate that the attachments are added to every page on the site. Only attachments with the every_page flag set to TRUE can participate in JavaScript/CSS aggregation.\n\nReturns: FALSE if there were any missing library dependencies; TRUE if all library dependencies were met.\n\nFile: includes/common.inc", "response": "function drupal_process_attached($elements, $group = JS_DEFAULT, $dependency_check = FALSE, $every_page = NULL) {\n // Add defaults to the special attached structures that should be processed differently.\n $elements['#attached'] += array(\n 'library' => array(),\n 'js' => array(),\n 'css' => array(),\n );\n\n // Add the libraries first.\n $success = TRUE;\n foreach ($elements['#attached']['library'] as $library) {\n if (drupal_add_library($library[0], $library[1], $every_page) === FALSE) {\n $success = FALSE;\n // Exit if the dependency is missing.\n if ($dependency_check) {\n return $success;\n }\n }\n }\n unset($elements['#attached']['library']);\n\n // Add both the JavaScript and the CSS.\n // The parameters for drupal_add_js() and drupal_add_css() require special\n // handling.\n foreach (array('js', 'css') as $type) {\n foreach ($elements['#attached'][$type] as $data => $options) {\n // If the value is not an array, it's a filename and passed as first\n // (and only) argument.\n if (!is_array($options)) {\n $data = $options;\n $options = NULL;\n }\n // In some cases, the first parameter ($data) is an array. Arrays can't be\n // passed as keys in PHP, so we have to get $data from the value array.\n if (is_numeric($data)) {\n $data = $options['data'];\n unset($options['data']);\n }\n // Apply the default group if it isn't explicitly given.\n if (!isset($options['group'])) {\n $options['group'] = $group;\n }\n // Set the every_page flag if one was passed.\n if (isset($every_page)) {\n $options['every_page'] = $every_page;\n }\n call_user_func('drupal_add_' . $type, $data, $options);\n }\n unset($elements['#attached'][$type]);\n }\n\n // Add additional types of attachments specified in the render() structure.\n // Libraries, JavaScript and CSS have been added already, as they require\n // special handling.\n foreach ($elements['#attached'] as $callback => $options) {\n if (function_exists($callback)) {\n foreach ($elements['#attached'][$callback] as $args) {\n call_user_func_array($callback, $args);\n }\n }\n }\n\n return $success;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eff546e17e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_html_settings/7.x", "instruction": "Implement `_filter_html_settings($form, &$form_state, $filter, $format, $defaults)` in PHP for Drupal 7. Required behavior: Implements callback_filter_settings().", "context": "Filter settings callback for the HTML content filter.\n\nFile: modules/filter/filter.module", "response": "function _filter_html_settings($form, &$form_state, $filter, $format, $defaults) {\n $filter->settings += $defaults;\n\n $settings['allowed_html'] = array(\n '#type' => 'textfield',\n '#title' => t('Allowed HTML tags'),\n '#default_value' => $filter->settings['allowed_html'],\n '#maxlength' => 1024,\n '#description' => t('A list of HTML tags that can be used. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'),\n );\n $settings['filter_html_help'] = array(\n '#type' => 'checkbox',\n '#title' => t('Display basic HTML help in long filter tips'),\n '#default_value' => $filter->settings['filter_html_help'],\n );\n $settings['filter_html_nofollow'] = array(\n '#type' => 'checkbox',\n '#title' => t('Add rel=\"nofollow\" to all links'),\n '#default_value' => $filter->settings['filter_html_nofollow'],\n );\n return $settings;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-eff7dd5950", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_array_get_nested_value/7.x", "instruction": "I need the code for `&drupal_array_get_nested_value(array &$array, array $parents, &$key_exists = NULL)` in Drupal 7 (includes/common.inc). It must do this: Retrieves a value from a nested array with variable depth.", "context": "This helper function should be used when the depth of the array element being retrieved may vary (that is, the number of parent keys is variable). It is primarily used for form structures and renderable arrays.\n\nWithout this helper function the only way to get a nested array value with variable depth in one line would be using eval(), which should be avoided:\n\nParameters:\n- $array: The array from which to get the value.\n- $parents: An array of parent keys of the value, starting with the outermost key.\n- $key_exists: (optional) If given, an already defined variable that is altered by reference.\n\nReturns: The requested nested value. Possibly NULL if the value is NULL or not all nested parent keys exist. $key_exists is altered by reference and is a Boolean that indicates whether all nested parent keys exist (TRUE) or not (FALSE). This allows to distinguish between the two possibilities when NULL is returned.\n\nFile: includes/common.inc", "response": "function &drupal_array_get_nested_value(array &$array, array $parents, &$key_exists = NULL) {\n $ref = &$array;\n foreach ($parents as $parent) {\n if (is_array($ref) && (isset($ref[$parent]) || array_key_exists($parent, $ref))) {\n $ref = &$ref[$parent];\n }\n else {\n $key_exists = FALSE;\n $null = NULL;\n return $null;\n }\n }\n $key_exists = TRUE;\n return $ref;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-effbfca09b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_date_delete_format_form_submit/7.x", "instruction": "In Drupal 7, write the function `system_date_delete_format_form_submit($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Delete a configured date format.", "context": "File: modules/system/system.admin.inc", "response": "function system_date_delete_format_form_submit($form, &$form_state) {\n if ($form_state['values']['confirm']) {\n $format = system_get_date_format($form_state['values']['dfid']);\n system_date_format_delete($form_state['values']['dfid']);\n drupal_set_message(t('Removed date format %format.', array('%format' => format_date(REQUEST_TIME, 'custom', $format->format))));\n $form_state['redirect'] = 'admin/config/regional/date-time/formats';\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f00cc5b3db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_help/7.x", "instruction": "In Drupal 7, write the function `dashboard_help($path, $arg)` (file modules/dashboard/dashboard.module) so that it does the following: Implements hook_help().", "context": "File: modules/dashboard/dashboard.module", "response": "function dashboard_help($path, $arg) {\n switch ($path) {\n case 'admin/help#dashboard':\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The Dashboard module provides a Dashboard page in the administrative interface for organizing administrative tasks and navigation, and tracking information within your site. The Dashboard page contains blocks, which you can add to and arrange using the drag-and-drop interface that appears when you click on the Customize dashboard link. Within this interface, blocks that are not primarily used for site administration do not appear by default, but can be added via the Add other blocks link. For more information, see the online handbook entry for Dashboard module.', array('@handbook' => 'http://drupal.org/documentation/modules/dashboard', '@dashboard' => url('admin/dashboard'))) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Tracking user activity') . '
              ';\n $output .= '
              ' . t(\"By enabling blocks such as Who's online and Who's new, site users can track who is logged in and new user signups at a centralized location.\") . '
              ';\n $output .= '
              ' . t('Tracking content activity') . '
              ';\n $output .= '
              ' . t('By enabling blocks such as Recent blog posts, New forum topics and Recent comments, site users can view newly added site content at a glance.') . '
              ';\n $output .= '
              ';\n return $output;\n\n case 'admin/dashboard/configure':\n // @todo This assumes the current page is being displayed using the same\n // theme that the dashboard is displayed in.\n $output = '

              ' . t('Rearrange blocks for display on the Dashboard page. Blocks placed in the Dashboard (inactive) region are not displayed when viewing the Dashboard page, but are available within its Customize dashboard interface. Removing a block from active dashboard display makes it available on the main blocks administration page.', array('@dashboard-url' => url('admin/dashboard'), '@blocks-url' => url(\"admin/structure/block/list/{$GLOBALS['theme_key']}\"))) . '

              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f00daea13d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_disable_message/7.x", "instruction": "In Drupal 7, write the function `overlay_disable_message()` (file modules/overlay/overlay.module) so that it does the following: Returns a renderable array representing a message for disabling the overlay.", "context": "If the current user can access the overlay and has not previously indicated that this message should be dismissed, this function returns a message containing a link to disable the overlay. Nothing is returned for anonymous users, because the links control per-user settings. Because some screen readers are unable to properly read overlay contents, site builders are discouraged from granting the \"access overlay\" permission to the anonymous role.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_disable_message() {\n global $user;\n\n if (!empty($user->uid) && empty($user->data['overlay_message_dismissed']) && (!isset($user->data['overlay']) || $user->data['overlay']) && user_access('access overlay')) {\n $build = array(\n '#theme' => 'overlay_disable_message',\n '#weight' => -99,\n // Link to the user's profile page, where the overlay can be disabled.\n 'profile_link' => array(\n '#type' => 'link',\n '#title' => t('If you have problems accessing administrative pages on this site, disable the overlay on your profile page.'),\n '#href' => 'user/' . $user->uid . '/edit',\n '#options' => array(\n 'query' => drupal_get_destination(),\n 'fragment' => 'edit-overlay-control',\n 'attributes' => array(\n 'id' => 'overlay-profile-link',\n // Prevent the target page from being opened in the overlay.\n 'class' => array('overlay-exclude'),\n ),\n ),\n ),\n // Link to a menu callback that allows this message to be permanently\n // dismissed for the current user.\n 'dismiss_message_link' => array(\n '#type' => 'link',\n '#title' => t('Dismiss this message.'),\n '#href' => 'overlay/dismiss-message',\n '#options' => array(\n 'query' => drupal_get_destination() + array(\n // Add a token to protect against cross-site request forgeries.\n 'token' => drupal_get_token('overlay'),\n ),\n 'attributes' => array(\n 'id' => 'overlay-dismiss-message',\n // If this message is being displayed outside the overlay, prevent\n // this link from opening the overlay.\n 'class' => (overlay_get_mode() == 'parent') ? array('overlay-exclude') : array(),\n ),\n ),\n )\n );\n }\n else {\n $build = array();\n }\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f0278a8e07", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/flood_is_allowed/7.x", "instruction": "In Drupal 7, write the function `flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)` (file includes/common.inc) so that it does the following: Checks whether a user is allowed to proceed with the specified event.", "context": "Events can have thresholds saying that each user can only do that event a certain number of times in a time window. This function verifies that the current user has not exceeded this threshold.\n\nParameters:\n- $name: The unique name of the event.\n- $threshold: The maximum number of times each user can do this event per time window.\n- $window: Number of seconds in the time window for this event (default is 3600 seconds, or 1 hour).\n- $identifier: Unique identifier of the current user. Defaults to their IP address.\n\nReturns: TRUE if the user is allowed to proceed. FALSE if they have exceeded the threshold and should not be allowed to proceed.\n\nFile: includes/common.inc", "response": "function flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL) {\n if (!isset($identifier)) {\n $identifier = ip_address();\n }\n $number = db_query(\"SELECT COUNT(*) FROM {flood} WHERE event = :event AND identifier = :identifier AND timestamp > :timestamp\", array(\n ':event' => $name,\n ':identifier' => $identifier,\n ':timestamp' => REQUEST_TIME - $window))\n ->fetchField();\n return ($number < $threshold);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f0644b8a22", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_get_hash_salt/7.x", "instruction": "I need the code for `drupal_get_hash_salt()` in Drupal 7 (includes/bootstrap.inc). It must do this: Gets a salt useful for hardening against SQL injection.", "context": "Returns: A salt based on information in settings.php, not in the database.\n\nFile: includes/bootstrap.inc", "response": "function drupal_get_hash_salt() {\n global $drupal_hash_salt, $databases;\n // If the $drupal_hash_salt variable is empty, a hash of the serialized\n // database credentials is used as a fallback salt.\n return empty($drupal_hash_salt) ? hash('sha256', serialize($databases)) : $drupal_hash_salt;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f07bb9987f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_edit_validate/7.x", "instruction": "I need the code for `shortcut_link_edit_validate($form, &$form_state)` in Drupal 7 (modules/shortcut/shortcut.admin.inc). It must do this: Validation handler for the shortcut link add and edit forms.", "context": "File: modules/shortcut/shortcut.admin.inc", "response": "function shortcut_link_edit_validate($form, &$form_state) {\n if (!shortcut_valid_link($form_state['values']['shortcut_link']['link_path'])) {\n form_set_error('shortcut_link][link_path', t('The link must correspond to a valid path on the site.'));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f0a0c794ba", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_validate/7.x", "instruction": "Implement `node_validate($node, $form, &$form_state)` in PHP for Drupal 7. Required behavior: Implements hook_validate().", "context": "Performs validation checks on the given node.\n\nFile: modules/node/node.module", "response": "function node_validate($node, $form, &$form_state) {\n if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {\n form_set_error('changed', t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));\n }\n\n // Validate the \"authored by\" field.\n if (!empty($node->name) && !($account = user_load_by_name($node->name))) {\n // The use of empty() is mandatory in the context of usernames\n // as the empty string denotes the anonymous user. In case we\n // are dealing with an anonymous user we set the user ID to 0.\n form_set_error('name', t('The username %name does not exist.', array('%name' => $node->name)));\n }\n\n // Validate the \"authored on\" field.\n if (!empty($node->date) && strtotime($node->date) === FALSE) {\n form_set_error('date', t('You have to specify a valid date.'));\n }\n\n // Invoke hook_validate() for node type specific validation and\n // hook_node_validate() for miscellaneous validation needed by modules. Can't\n // use node_invoke() or module_invoke_all(), because $form_state must be\n // receivable by reference.\n $function = node_type_get_base($node) . '_validate';\n if (function_exists($function)) {\n $function($node, $form, $form_state);\n }\n foreach (module_implements('node_validate') as $module) {\n $function = $module . '_node_validate';\n $function($node, $form, $form_state);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f0d38093df", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_get_info/7.x", "instruction": "In Drupal 7, write the function `search_get_info($all = FALSE)` (file modules/search/search.module) so that it does the following: Returns information about available search modules.", "context": "Parameters:\n- $all: If TRUE, information about all enabled modules implementing hook_search_info() will be returned. If FALSE (default), only modules that have been set to active on the search settings page will be returned.\n\nReturns (Array): of hook_search_info() return values, keyed by module name. The 'title' and 'path' array elements will be set to defaults for each module if not supplied by hook_search_info(), and an additional array element of 'module' will be added (set to the module name).\n\nFile: modules/search/search.module", "response": "function search_get_info($all = FALSE) {\n $search_hooks = &drupal_static(__FUNCTION__);\n\n if (!isset($search_hooks)) {\n foreach (module_implements('search_info') as $module) {\n $search_hooks[$module] = call_user_func($module . '_search_info');\n // Use module name as the default value.\n $search_hooks[$module] += array('title' => $module, 'path' => $module);\n // Include the module name itself in the array.\n $search_hooks[$module]['module'] = $module;\n }\n }\n\n if ($all) {\n return $search_hooks;\n }\n\n $active = variable_get('search_active_modules', array('node', 'user'));\n return array_intersect_key($search_hooks, array_flip($active));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f0e85e4290", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.api.php/function/hook_file_download_access/7.x", "instruction": "Give me the example code for `hook_file_download_access($file_item, $entity_type, $entity)` in Drupal 7. Hook description: Control download access to files.", "context": "The hook is typically implemented to limit access based on the entity the file is referenced, e.g., only users with access to a node should be allowed to download files attached to that node.\n\nParameters:\n- $file_item (array): The array of information about the file to check access for.\n- $entity_type: The type of $entity; for example, 'node' or 'user'.\n- $entity: The $entity to which $file is referenced.\n\nReturns: TRUE is access should be allowed by this entity or FALSE if denied. Note that denial may be overridden by another entity controller, making this grant permissive rather than restrictive.\n\nFile: modules/file/file.api.php", "response": "function hook_file_download_access($file_item, $entity_type, $entity) {\n if ($entity_type == 'node') {\n return node_access('view', $entity);\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f10bbf5b43", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_validate_name/7.x", "instruction": "In Drupal 7, write the function `user_validate_name($name)` (file modules/user/user.module) so that it does the following: Verify the syntax of the given name.", "context": "File: modules/user/user.module", "response": "function user_validate_name($name) {\n if (!$name) {\n return t('You must enter a username.');\n }\n if (substr($name, 0, 1) == ' ') {\n return t('The username cannot begin with a space.');\n }\n if (substr($name, -1) == ' ') {\n return t('The username cannot end with a space.');\n }\n if (strpos($name, ' ') !== FALSE) {\n return t('The username cannot contain multiple spaces in a row.');\n }\n if (preg_match('/[^\\x{80}-\\x{F7} a-z0-9@+_.\\'-]/i', $name)) {\n return t('The username contains an illegal character.');\n }\n if (preg_match('/[\\x{80}-\\x{A0}' . // Non-printable ISO-8859-1 + NBSP\n '\\x{AD}' . // Soft-hyphen\n '\\x{2000}-\\x{200F}' . // Various space characters\n '\\x{2028}-\\x{202F}' . // Bidirectional text overrides\n '\\x{205F}-\\x{206F}' . // Various text hinting characters\n '\\x{FEFF}' . // Byte order mark\n '\\x{FF01}-\\x{FF60}' . // Full-width latin\n '\\x{FFF9}-\\x{FFFD}' . // Replacement characters\n '\\x{0}-\\x{1F}]/u', // NULL byte and control characters\n $name)) {\n return t('The username contains an illegal character.');\n }\n if (drupal_strlen($name) > USERNAME_MAX_LENGTH) {\n return t('The username %name is too long: it must be %max characters or less.', array('%name' => $name, '%max' => USERNAME_MAX_LENGTH));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f1167dffb9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.default.inc/function/field_default_view/7.x", "instruction": "I need the code for `field_default_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` in Drupal 7 (modules/field/field.default.inc). It must do this: Builds a renderable array for one field on one entity instance.", "context": "Parameters:\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entity: A single object of type $entity_type.\n- $field: The field structure for the operation.\n- $instance: An array containing each field on $entity's bundle.\n- $langcode: The language associated to $items.\n- $items: Array of field values already loaded for the entities, keyed by entity id.\n- $display: Can be either: - the name of a view mode; - or an array of custom display settings, as found in the 'display' entry of $instance definitions.\n\nFile: modules/field/field.default.inc", "response": "function field_default_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n $addition = array();\n\n // Prepare incoming display specifications.\n if (is_string($display)) {\n $view_mode = $display;\n $display = field_get_display($instance, $view_mode, $entity);\n }\n else {\n $view_mode = '_custom_display';\n }\n\n if ($display['type'] !== 'hidden') {\n // Calling the formatter function through module_invoke() can have a\n // performance impact on pages with many fields and values.\n $function = $display['module'] . '_field_formatter_view';\n if (function_exists($function)) {\n $elements = $function($entity_type, $entity, $field, $instance, $langcode, $items, $display);\n\n if ($elements) {\n $info = array(\n '#theme' => 'field',\n '#weight' => $display['weight'],\n '#title' => $instance['label'],\n '#access' => field_access('view', $field, $entity_type, $entity),\n '#label_display' => $display['label'],\n '#view_mode' => $view_mode,\n '#language' => $langcode,\n '#field_name' => $field['field_name'],\n '#field_type' => $field['type'],\n '#field_translatable' => $field['translatable'],\n '#entity_type' => $entity_type,\n '#bundle' => $bundle,\n '#object' => $entity,\n '#items' => $items,\n '#formatter' => $display['type']\n );\n\n $addition[$field['field_name']] = array_merge($info, $elements);\n }\n }\n }\n\n return $addition;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f1294e01ca", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_samesite_cookie/7.x", "instruction": "Implement `_drupal_samesite_cookie($options)` in PHP for Drupal 7. Required behavior: Determine the value for the samesite cookie attribute, in the following order of precedence:", "context": "1) A value explicitly passed to drupal_setcookie() 2) A value set in $conf['samesite_cookie_value'] 3) The setting from php ini 4) The default of None, or FALSE (no attribute) if the cookie is not Secure\n\nParameters:\n- $options: An associative array as passed to drupal_setcookie().\n\nReturns: The value for the samesite cookie attribute.\n\nFile: includes/bootstrap.inc", "response": "function _drupal_samesite_cookie($options) {\n if (isset($options['samesite'])) {\n return $options['samesite'];\n }\n $override = variable_get('samesite_cookie_value', NULL);\n if ($override !== NULL) {\n return $override;\n }\n $ini_options = session_get_cookie_params();\n if (isset($ini_options['samesite'])) {\n return $ini_options['samesite'];\n }\n return empty($options['secure']) ? FALSE : 'None';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f1342b2f08", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_role_delete_confirm/7.x", "instruction": "I need the code for `user_admin_role_delete_confirm($form, &$form_state, $role)` in Drupal 7 (modules/user/user.admin.inc). It must do this: Form to confirm role delete operation.", "context": "File: modules/user/user.admin.inc", "response": "function user_admin_role_delete_confirm($form, &$form_state, $role) {\n $form['rid'] = array(\n '#type' => 'value',\n '#value' => $role->rid,\n );\n return confirm_form($form, t('Are you sure you want to delete the role %name ?', array('%name' => $role->name)), 'admin/people/permissions/roles', t('This action cannot be undone.'), t('Delete'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f150df2862", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/path_is_admin/7.x", "instruction": "I need the code for `path_is_admin($path)` in Drupal 7 (includes/path.inc). It must do this: Determines whether a path is in the administrative section of the site.", "context": "By default, paths are considered to be non-administrative. If a path does not match any of the patterns in path_get_admin_paths(), or if it matches both administrative and non-administrative patterns, it is considered non-administrative.\n\nParameters:\n- $path: A Drupal path.\n\nReturns: TRUE if the path is administrative, FALSE otherwise.\n\nFile: includes/path.inc", "response": "function path_is_admin($path) {\n $path_map = &drupal_static(__FUNCTION__);\n if (!isset($path_map['admin'][$path])) {\n $patterns = path_get_admin_paths();\n $path_map['admin'][$path] = drupal_match_path($path, $patterns['admin']);\n $path_map['non_admin'][$path] = drupal_match_path($path, $patterns['non_admin']);\n }\n return $path_map['admin'][$path] && !$path_map['non_admin'][$path];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f166314338", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_get_localized_date_format/7.x", "instruction": "Implement `locale_get_localized_date_format($languages)` in PHP for Drupal 7. Required behavior: Select locale date format details from database.", "context": "Parameters:\n- $languages: An array of language codes.\n\nReturns: An array of date formats.\n\nFile: includes/locale.inc", "response": "function locale_get_localized_date_format($languages) {\n $formats = array();\n\n // Get list of different format types.\n $format_types = system_get_date_types();\n $short_default = variable_get('date_format_short', 'm/d/Y - H:i');\n\n // Loop through each language until we find one with some date formats\n // configured.\n foreach ($languages as $language) {\n $date_formats = system_date_format_locale($language);\n if (!empty($date_formats)) {\n // We have locale-specific date formats, so check for their types. If\n // we're missing a type, use the default setting instead.\n foreach ($format_types as $type => $type_info) {\n // If format exists for this language, use it.\n if (!empty($date_formats[$type])) {\n $formats['date_format_' . $type] = $date_formats[$type];\n }\n // Otherwise get default variable setting. If this is not set, default\n // to the short format.\n else {\n $formats['date_format_' . $type] = variable_get('date_format_' . $type, $short_default);\n }\n }\n\n // Return on the first match.\n return $formats;\n }\n }\n\n // No locale specific formats found, so use defaults.\n $system_types = array('short', 'medium', 'long');\n // Handle system types separately as they have defaults if no variable exists.\n $formats['date_format_short'] = $short_default;\n $formats['date_format_medium'] = variable_get('date_format_medium', 'D, m/d/Y - H:i');\n $formats['date_format_long'] = variable_get('date_format_long', 'l, F j, Y - H:i');\n\n // For non-system types, get the default setting, otherwise use the short\n // format.\n foreach ($format_types as $type => $type_info) {\n if (!in_array($type, $system_types)) {\n $formats['date_format_' . $type] = variable_get('date_format_' . $type, $short_default);\n }\n }\n\n return $formats;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f16807c54d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_add_form_submit/7.x", "instruction": "Implement `image_style_add_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Submit handler for adding a new image style.", "context": "File: modules/image/image.admin.inc", "response": "function image_style_add_form_submit($form, &$form_state) {\n $style = array(\n 'name' => $form_state['values']['name'],\n 'label' => $form_state['values']['label'],\n );\n $style = image_style_save($style);\n drupal_set_message(t('Style %name was created.', array('%name' => $style['label'])));\n $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f175c39f5c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.admin.inc/function/search_reindex_confirm/7.x", "instruction": "Implement `search_reindex_confirm()` in PHP for Drupal 7. Required behavior: Menu callback: confirm wiping of the index.", "context": "File: modules/search/search.admin.inc", "response": "function search_reindex_confirm() {\n return confirm_form(array(), t('Are you sure you want to re-index the site?'),\n 'admin/config/search/settings', t('The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\\'t be indexed until all existing content has been re-indexed. This action cannot be undone.'), t('Re-index site'), t('Cancel'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f1829ed696", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_contextual_links/7.x", "instruction": "Implement `menu_contextual_links($module, $parent_path, $args)` in PHP for Drupal 7. Required behavior: Retrieves contextual links for a path based on registered local tasks.", "context": "This leverages the menu system to retrieve the first layer of registered local tasks for a given system path. All local tasks of the tab type MENU_CONTEXT_INLINE are taken into account.\n\nFor example, when considering the following registered local tasks:\n- node/%node/view (default local task) with no 'context' defined\n- node/%node/edit with context: MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE\n- node/%node/revisions with context: MENU_CONTEXT_PAGE\n- node/%node/report-as-spam with context: MENU_CONTEXT_INLINE\n\nIf the path \"node/123\" is passed to this function, then it will return the links for 'edit' and 'report-as-spam'.\n\nParameters:\n- $module: The name of the implementing module. This is used to prefix the key for each contextual link, which is transformed into a CSS class during rendering by theme_links(). For example, if $module is 'block' and the retrieved local task path argument is 'edit', then the resulting CSS class will be 'block-edit'.\n- $parent_path: The static menu router path of the object to retrieve local tasks for, for example 'node' or 'admin/structure/block/manage'.\n- $args: A list of dynamic path arguments to append to $parent_path to form the fully-qualified menu router path; for example, array(123) for a certain node or array('system', 'navigation') for a certain block.\n\nReturns: A list of menu router items that are local tasks for the passed-in path.\n\nFile: includes/menu.inc", "response": "function menu_contextual_links($module, $parent_path, $args) {\n static $path_empty = array();\n\n $links = array();\n // Performance: In case a previous invocation for the same parent path did not\n // return any links, we immediately return here.\n if (isset($path_empty[$parent_path]) && strpos($parent_path, '%') !== FALSE) {\n return $links;\n }\n // Construct the item-specific parent path.\n $path = $parent_path . '/' . implode('/', $args);\n\n // Get the router item for the given parent link path.\n $router_item = menu_get_item($path);\n if (!$router_item || !$router_item['access']) {\n $path_empty[$parent_path] = TRUE;\n return $links;\n }\n $data = &drupal_static(__FUNCTION__, array());\n $root_path = $router_item['path'];\n\n // Performance: For a single, normalized path (such as 'node/%') we only query\n // available tasks once per request.\n if (!isset($data[$root_path])) {\n // Get all contextual links that are direct children of the router item and\n // not of the tab type 'view'.\n $data[$root_path] = db_select('menu_router', 'm')\n ->fields('m')\n ->condition('tab_parent', $router_item['tab_root'])\n ->condition('context', MENU_CONTEXT_NONE, '<>')\n ->condition('context', MENU_CONTEXT_PAGE, '<>')\n ->orderBy('weight')\n ->orderBy('title')\n ->execute()\n ->fetchAllAssoc('path', PDO::FETCH_ASSOC);\n }\n $parent_length = drupal_strlen($root_path) + 1;\n $map = $router_item['original_map'];\n foreach ($data[$root_path] as $item) {\n // Extract the actual \"task\" string from the path argument.\n $key = drupal_substr($item['path'], $parent_length);\n\n // Denormalize and translate the contextual link.\n _menu_translate($item, $map, TRUE);\n if (!$item['access']) {\n continue;\n }\n // All contextual links are keyed by the actual \"task\" path argument,\n // prefixed with the name of the implementing module.\n $links[$module . '-' . $key] = $item;\n }\n\n // Allow modules to alter contextual links.\n drupal_alter('menu_contextual_links', $links, $router_item, $root_path);\n\n // Performance: If the current user does not have access to any links for this\n // router path and no other module added further links, we assign FALSE here\n // to skip the entire process the next time the same router path is requested.\n if (empty($links)) {\n $path_empty[$parent_path] = TRUE;\n }\n\n return $links;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f185c2f5d1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_import_form/7.x", "instruction": "I need the code for `locale_translate_import_form($form)` in Drupal 7 (modules/locale/locale.admin.inc). It must do this: User interface for the translation import screen.", "context": "File: modules/locale/locale.admin.inc", "response": "function locale_translate_import_form($form) {\n // Get all languages, except English\n drupal_static_reset('language_list');\n $names = locale_language_list('name');\n unset($names['en']);\n\n if (!count($names)) {\n $languages = _locale_prepare_predefined_list();\n $default = key($languages);\n }\n else {\n $languages = array(\n t('Already added languages') => $names,\n t('Languages not yet added') => _locale_prepare_predefined_list()\n );\n $default = key($names);\n }\n\n $form['import'] = array('#type' => 'fieldset',\n '#title' => t('Import translation'),\n );\n $form['import']['file'] = array('#type' => 'file',\n '#title' => t('Language file'),\n '#size' => 50,\n '#description' => t('A Gettext Portable Object (.po) file.'),\n );\n $form['import']['langcode'] = array('#type' => 'select',\n '#title' => t('Import into'),\n '#options' => $languages,\n '#default_value' => $default,\n '#description' => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, it will be added.'),\n );\n $form['import']['group'] = array('#type' => 'radios',\n '#title' => t('Text group'),\n '#default_value' => 'default',\n '#options' => module_invoke_all('locale', 'groups'),\n '#description' => t('Imported translations will be added to this text group.'),\n );\n $form['import']['mode'] = array('#type' => 'radios',\n '#title' => t('Mode'),\n '#default_value' => LOCALE_IMPORT_KEEP,\n '#options' => array(\n LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added. The plural format is updated.'),\n LOCALE_IMPORT_KEEP => t('Existing strings and the plural format are kept, only new strings are added.')\n ),\n );\n $form['import']['submit'] = array('#type' => 'submit', '#value' => t('Import'));\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f18c55e602", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_node_view/7.x", "instruction": "I need the code for `blog_node_view($node, $view_mode)` in Drupal 7 (modules/blog/blog.module). It must do this: Implements hook_node_view().", "context": "File: modules/blog/blog.module", "response": "function blog_node_view($node, $view_mode) {\n if ($view_mode != 'rss') {\n if ($node->type == 'blog' && (arg(0) != 'blog' || arg(1) != $node->uid)) {\n // This goes to l(), which escapes !username in both title and attributes.\n $links['blog_usernames_blog'] = array(\n 'title' => t(\"!username's blog\", array('!username' => format_username($node))),\n 'href' => \"blog/$node->uid\",\n 'attributes' => array('title' => t(\"Read !username's latest blog entries.\", array('!username' => format_username($node)))),\n );\n $node->content['links']['blog'] = array(\n '#theme' => 'links__node__blog',\n '#links' => $links,\n '#attributes' => array('class' => array('links', 'inline')),\n );\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f19bdd3c46", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/function/user_pass/7.x", "instruction": "Implement `user_pass()` in PHP for Drupal 7. Required behavior: Form builder; Request a password reset.", "context": "File: modules/user/user.pages.inc", "response": "function user_pass() {\n global $user;\n\n $form['name'] = array(\n '#type' => 'textfield',\n '#title' => t('Username or e-mail address'),\n '#size' => 60,\n '#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH),\n '#required' => TRUE,\n '#default_value' => isset($_GET['name']) ? $_GET['name'] : '',\n );\n // Allow logged in users to request this also.\n if ($user->uid > 0) {\n $form['name']['#type'] = 'value';\n $form['name']['#value'] = $user->mail;\n $form['mail'] = array(\n '#prefix' => '

              ',\n // As of https://www.drupal.org/node/889772 the user no longer must log\n // out (if they are still logged in when using the password reset link,\n // they will be logged out automatically then), but this text is kept as\n // is to avoid breaking translations as well as to encourage the user to\n // log out manually at a time of their own choosing (when it will not\n // interrupt anything else they may have been in the middle of doing).\n '#markup' => t('Password reset instructions will be mailed to %email. You must log out to use the password reset link in the e-mail.', array('%email' => $user->mail)),\n '#suffix' => '

              ',\n );\n }\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('E-mail new password'));\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f1b62ff951", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_local_transfers_allowed/7.x", "instruction": "In Drupal 7, write the function `update_manager_local_transfers_allowed()` (file modules/update/update.manager.inc) so that it does the following: Determines if file transfers will be performed locally.", "context": "If the server is configured such that webserver-created files have the same owner as the configuration directory (e.g., sites/default) where new code will eventually be installed, the update manager can transfer files entirely locally, without changing their ownership (in other words, without prompting the user for FTP, SSH or other credentials).\n\nThis server configuration is an inherent security weakness because it allows a malicious webserver process to append arbitrary PHP code and then execute it. However, it is supported here because it is a common configuration on shared hosting, and there is nothing Drupal can do to prevent it.\n\nReturns: TRUE if local file transfers are allowed on this server, or FALSE if not.\n\nFile: modules/update/update.manager.inc", "response": "function update_manager_local_transfers_allowed() {\n // Compare the owner of a webserver-created temporary file to the owner of\n // the configuration directory to determine if local transfers will be\n // allowed.\n $temporary_file = drupal_tempnam('temporary://', 'update_');\n $local_transfers_allowed = fileowner($temporary_file) === fileowner(conf_path());\n\n // Clean up. If this fails, we can ignore it (since this is just a temporary\n // file anyway).\n @drupal_unlink($temporary_file);\n\n return $local_transfers_allowed;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f1b99cda96", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_radios/7.x", "instruction": "I need the code for `theme_radios($variables)` in Drupal 7 (includes/form.inc). It must do this: Returns HTML for a set of radio button form elements.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #title, #value, #options, #description, #required, #attributes, #children.\n\nFile: includes/form.inc", "response": "function theme_radios($variables) {\n $element = $variables['element'];\n $attributes = array();\n if (isset($element['#id'])) {\n $attributes['id'] = $element['#id'];\n }\n $attributes['class'] = 'form-radios';\n if (!empty($element['#attributes']['class'])) {\n $attributes['class'] .= ' ' . implode(' ', $element['#attributes']['class']);\n }\n if (isset($element['#attributes']['title'])) {\n $attributes['title'] = $element['#attributes']['title'];\n }\n return '' . (!empty($element['#children']) ? $element['#children'] : '') . '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f1d7dc1646", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_rdf_namespaces/7.x", "instruction": "I need the code for `drupal_get_rdf_namespaces()` in Drupal 7 (includes/common.inc). It must do this: Returns a string containing RDF namespace declarations for use in XML and XHTML output.", "context": "File: includes/common.inc", "response": "function drupal_get_rdf_namespaces() {\n $xml_rdf_namespaces = array();\n\n // Serializes the RDF namespaces in XML namespace syntax.\n if (function_exists('rdf_get_namespaces')) {\n foreach (rdf_get_namespaces() as $prefix => $uri) {\n $xml_rdf_namespaces[] = 'xmlns:' . $prefix . '=\"' . $uri . '\"';\n }\n }\n return count($xml_rdf_namespaces) ? \"\\n \" . implode(\"\\n \", $xml_rdf_namespaces) : '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2297d121f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_form/7.x", "instruction": "I need the code for `poll_form($node, &$form_state)` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_form().", "context": "File: modules/poll/poll.module", "response": "function poll_form($node, &$form_state) {\n global $user;\n\n $admin = user_access('bypass node access') || user_access('edit any poll content') || (user_access('edit own poll content') && $user->uid == $node->uid);\n\n $type = node_type_get_type($node);\n\n // The submit handlers to add more poll choices require that this form is\n // cached, regardless of whether Ajax is used.\n $form_state['cache'] = TRUE;\n\n $form['title'] = array(\n '#type' => 'textfield',\n '#title' => check_plain($type->title_label),\n '#required' => TRUE,\n '#default_value' => $node->title,\n '#maxlength' => 255,\n '#weight' => -5,\n );\n\n if (isset($form_state['choice_count'])) {\n $choice_count = $form_state['choice_count'];\n }\n else {\n $choice_count = max(2, empty($node->choice) ? 2 : count($node->choice));\n }\n\n // Add a wrapper for the choices and more button.\n $form['choice_wrapper'] = array(\n '#tree' => FALSE,\n '#weight' => -4,\n '#prefix' => '
              ',\n '#suffix' => '
              ',\n );\n\n // Container for just the poll choices.\n $form['choice_wrapper']['choice'] = array(\n '#prefix' => '
              ',\n '#suffix' => '
              ',\n '#theme' => 'poll_choices',\n );\n\n // Add the current choices to the form.\n $delta = 0;\n $weight = 0;\n if (isset($node->choice)) {\n $delta = count($node->choice);\n foreach ($node->choice as $chid => $choice) {\n $key = 'chid:' . $chid;\n $form['choice_wrapper']['choice'][$key] = _poll_choice_form($key, $choice['chid'], $choice['chtext'], $choice['chvotes'], $choice['weight'], $choice_count);\n $weight = max($choice['weight'], $weight);\n }\n }\n\n // Add initial or additional choices.\n $existing_delta = $delta;\n for ($delta; $delta < $choice_count; $delta++) {\n $key = 'new:' . ($delta - $existing_delta);\n // Increase the weight of each new choice.\n $weight++;\n $form['choice_wrapper']['choice'][$key] = _poll_choice_form($key, NULL, '', 0, $weight, $choice_count);\n }\n\n // We name our button 'poll_more' to avoid conflicts with other modules using\n // Ajax-enabled buttons with the id 'more'.\n $form['choice_wrapper']['poll_more'] = array(\n '#type' => 'submit',\n '#value' => t('More choices'),\n '#attributes' => array(\n 'title' => t(\"If the amount of boxes above isn't enough, click here to add more choices.\"),\n ),\n '#weight' => 1,\n '#limit_validation_errors' => array(array('choice')),\n '#submit' => array('poll_more_choices_submit'),\n '#ajax' => array(\n 'callback' => 'poll_choice_js',\n 'wrapper' => 'poll-choices',\n 'effect' => 'fade',\n ),\n );\n\n // Poll attributes\n $duration = array(\n // 1-6 days.\n 86400, 2 * 86400, 3 * 86400, 4 * 86400, 5 * 86400, 6 * 86400,\n // 1-3 weeks (7 days).\n 604800, 2 * 604800, 3 * 604800,\n // 1-3,6,9 months (30 days).\n 2592000, 2 * 2592000, 3 * 2592000, 6 * 2592000, 9 * 2592000,\n // 1 year (365 days).\n 31536000,\n );\n $duration = array(0 => t('Unlimited')) + drupal_map_assoc($duration, 'format_interval');\n $active = array(0 => t('Closed'), 1 => t('Active'));\n\n $form['settings'] = array(\n '#type' => 'fieldset',\n '#collapsible' => TRUE,\n '#title' => t('Poll settings'),\n '#weight' => -3,\n '#access' => $admin,\n );\n\n $form['settings']['active'] = array(\n '#type' => 'radios',\n '#title' => t('Poll status'),\n '#default_value' => isset($node->active) ? $node->active : 1,\n '#options' => $active,\n '#description' => t('When a poll is closed, visitors can no longer vote for it.'),\n '#access' => $admin,\n );\n $form['settings']['runtime'] = array(\n '#type' => 'select',\n '#title' => t('Poll duration'),\n '#default_value' => isset($node->runtime) ? $node->runtime : 0,\n '#options' => $duration,\n '#description' => t('After this period, the poll will be closed automatically.'),\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f22aabf0ac", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_pre_render/7.x", "instruction": "I need the code for `toolbar_pre_render($toolbar)` in Drupal 7 (modules/toolbar/toolbar.module). It must do this: Prerender function for the toolbar.", "context": "Since building the toolbar takes some time, it is done just prior to rendering to ensure that it is built only if it will be displayed.\n\nFile: modules/toolbar/toolbar.module", "response": "function toolbar_pre_render($toolbar) {\n $toolbar = array_merge($toolbar, toolbar_view());\n return $toolbar;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f242b4e291", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_sanitize_configuration/7.x", "instruction": "In Drupal 7, write the function `aggregator_sanitize_configuration()` (file modules/aggregator/aggregator.module) so that it does the following: Checks and sanitizes the aggregator configuration.", "context": "Goes through all fetchers, parsers and processors and checks whether they are available. If one is missing, resets to standard configuration.\n\nReturns: TRUE if this function resets the configuration; FALSE if not.\n\nFile: modules/aggregator/aggregator.module", "response": "function aggregator_sanitize_configuration() {\n $reset = FALSE;\n list($fetcher, $parser, $processors) = _aggregator_get_variables();\n if (!module_exists($fetcher)) {\n $reset = TRUE;\n }\n if (!module_exists($parser)) {\n $reset = TRUE;\n }\n foreach ($processors as $processor) {\n if (!module_exists($processor)) {\n $reset = TRUE;\n break;\n }\n }\n if ($reset) {\n variable_del('aggregator_fetcher');\n variable_del('aggregator_parser');\n variable_del('aggregator_processors');\n return TRUE;\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2583f260c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_term_view/7.x", "instruction": "In Drupal 7, write the function `taxonomy_term_view($term, $view_mode = 'full', $langcode = NULL)` (file modules/taxonomy/taxonomy.module) so that it does the following: Generate an array for rendering the given term.", "context": "Parameters:\n- $term: A term object.\n- $view_mode: View mode, e.g. 'full', 'teaser'...\n- $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.\n\nReturns: An array as expected by drupal_render().\n\nFile: modules/taxonomy/taxonomy.module", "response": "function taxonomy_term_view($term, $view_mode = 'full', $langcode = NULL) {\n if (!isset($langcode)) {\n $langcode = $GLOBALS['language_content']->language;\n }\n\n // Populate $term->content with a render() array.\n taxonomy_term_build_content($term, $view_mode, $langcode);\n $build = $term->content;\n\n // We don't need duplicate rendering info in $term->content.\n unset($term->content);\n\n $build += array(\n '#theme' => 'taxonomy_term',\n '#term' => $term,\n '#view_mode' => $view_mode,\n '#language' => $langcode,\n );\n\n $build['#attached']['css'][] = drupal_get_path('module', 'taxonomy') . '/taxonomy.css';\n\n // Allow modules to modify the structured taxonomy term.\n $type = 'taxonomy_term';\n drupal_alter(array('taxonomy_term_view', 'entity_view'), $build, $type);\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2837249aa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_add_date_format_type_form/7.x", "instruction": "In Drupal 7, write the function `system_add_date_format_type_form($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Add new date type.", "context": "File: modules/system/system.admin.inc", "response": "function system_add_date_format_type_form($form, &$form_state) {\n $form['date_type'] = array(\n '#title' => t('Date type'),\n '#type' => 'textfield',\n '#required' => TRUE,\n );\n $form['machine_name'] = array(\n '#type' => 'machine_name',\n '#machine_name' => array(\n 'exists' => 'system_get_date_types',\n 'source' => array('date_type'),\n ),\n );\n\n // Get list of all available date formats.\n $formats = array();\n drupal_static_reset('system_get_date_formats');\n $date_formats = system_get_date_formats(); // Call this to rebuild the list, and to have default list.\n foreach ($date_formats as $type => $format_info) {\n $formats = array_merge($formats, $format_info);\n }\n $custom_formats = system_get_date_formats('custom');\n if (!empty($custom_formats)) {\n $formats = array_merge($formats, $custom_formats);\n }\n $choices = array();\n foreach ($formats as $f => $format) {\n $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);\n }\n // Show date format select list.\n $form['date_format'] = array(\n '#type' => 'select',\n '#title' => t('Date format'),\n '#attributes' => array('class' => array('date-format')),\n '#options' => $choices,\n '#required' => TRUE,\n );\n\n $form['actions'] = array('#type' => 'actions');\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Add date type'),\n );\n\n $form['#validate'][] = 'system_add_date_format_type_form_validate';\n $form['#submit'][] = 'system_add_date_format_type_form_submit';\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f296c2d879", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_nonce/7.x", "instruction": "Implement `_openid_nonce()` in PHP for Drupal 7. Required behavior: Return a nonce value - formatted per OpenID spec.", "context": "NOTE: This nonce is not cryptographically secure and only suitable for use by the test framework.\n\nFile: modules/openid/openid.inc", "response": "function _openid_nonce() {\n // YYYY-MM-DDThh:mm:ssZ, plus some optional extra unique characters.\n return gmdate('Y-m-d\\TH:i:s\\Z') .\n chr(mt_rand(0, 25) + 65) .\n chr(mt_rand(0, 25) + 65) .\n chr(mt_rand(0, 25) + 65) .\n chr(mt_rand(0, 25) + 65);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f29afd929a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_info/7.x", "instruction": "In Drupal 7, write the function `file_field_info()` (file modules/file/file.field.inc) so that it does the following: Implements hook_field_info().", "context": "File: modules/file/file.field.inc", "response": "function file_field_info() {\n return array(\n 'file' => array(\n 'label' => t('File'),\n 'description' => t('This field stores the ID of a file as an integer value.'),\n 'settings' => array(\n 'display_field' => 0,\n 'display_default' => 0,\n 'uri_scheme' => variable_get('file_default_scheme', 'public'),\n ),\n 'instance_settings' => array(\n 'file_extensions' => 'txt',\n 'file_directory' => '[date:custom:Y]-[date:custom:m]',\n 'max_filesize' => '',\n 'description_field' => 0,\n ),\n 'default_widget' => 'file_generic',\n 'default_formatter' => 'file_default',\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2a2286261", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7021/7.x", "instruction": "I need the code for `system_update_7021()` in Drupal 7 (modules/system/system.install). It must do this: Change the PHP for settings permission.", "context": "File: modules/system/system.install", "response": "function system_update_7021() {\n db_update('role_permission')\n ->fields(array('permission' => 'use PHP for settings'))\n ->condition('permission', 'use PHP for block visibility')\n ->execute();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2afb96214", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_import_parse_quoted/7.x", "instruction": "Implement `_locale_import_parse_quoted($string)` in PHP for Drupal 7. Required behavior: Parses a string in quotes", "context": "Parameters:\n- $string: A string specified with enclosing quotes.\n\nReturns: The string parsed from inside the quotes.\n\nFile: includes/locale.inc", "response": "function _locale_import_parse_quoted($string) {\n if (substr($string, 0, 1) != substr($string, -1, 1)) {\n return FALSE; // Start and end quotes must be the same\n }\n $quote = substr($string, 0, 1);\n $string = substr($string, 1, -1);\n if ($quote == '\"') { // Double quotes: strip slashes\n return stripcslashes($string);\n }\n elseif ($quote == \"'\") { // Simple quote: return as-is\n return $string;\n }\n else {\n return FALSE; // Unrecognized quote\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2bc70d41e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_cache_clear/7.x", "instruction": "I need the code for `field_info_cache_clear()` in Drupal 7 (modules/field/field.info.inc). It must do this: Clears the field info cache without clearing the field data cache.", "context": "This is useful when deleted fields or instances are purged. We need to remove the purged records, but no actual field data items are affected.\n\nFile: modules/field/field.info.inc", "response": "function field_info_cache_clear() {\n drupal_static_reset('field_view_mode_settings');\n drupal_static_reset('field_available_languages');\n\n // @todo: Remove this when field_attach_*_bundle() bundle management\n // functions are moved to the entity API.\n entity_info_cache_clear();\n\n _field_info_collate_types(TRUE);\n _field_info_field_cache()->flush();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2e87622e5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_ajax_render_alter/7.x", "instruction": "Give me the example code for `hook_ajax_render_alter(&$commands)` in Drupal 7. Hook description: Alter the commands that are sent to the user through the Ajax framework.", "context": "Parameters:\n- $commands: An array of all commands that will be sent to the user.\n\nFile: modules/system/system.api.php", "response": "function hook_ajax_render_alter(&$commands) {\n // Inject any new status messages into the content area.\n $commands[] = ajax_command_prepend('#block-system-main .content', theme('status_messages'));\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2f44a34e9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.processor.inc/function/aggregator_aggregator_remove/7.x", "instruction": "In Drupal 7, write the function `aggregator_aggregator_remove($feed)` (file modules/aggregator/aggregator.processor.inc) so that it does the following: Implements hook_aggregator_remove().", "context": "File: modules/aggregator/aggregator.processor.inc", "response": "function aggregator_aggregator_remove($feed) {\n $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchCol();\n if ($iids) {\n db_delete('aggregator_category_item')\n ->condition('iid', $iids, 'IN')\n ->execute();\n }\n db_delete('aggregator_item')\n ->condition('fid', $feed->fid)\n ->execute();\n\n drupal_set_message(t('The news items from %site have been removed.', array('%site' => $feed->title)));\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f2f9fbd9db", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.install/function/field_update_7000/7.x", "instruction": "I need the code for `field_update_7000()` in Drupal 7 (modules/field/field.install). It must do this: Field update version placeholder.", "context": "File: modules/field/field.install", "response": "function field_update_7000() {\n // Some update helper functions (such as _update_7000_field_create_field())\n // modify the database directly. They can be used safely only if the database\n // schema matches the field module schema established for Drupal 7.0 (i.e.\n // version 7000). This function exists solely to set the schema version to\n // 7000, so that update functions calling those helpers can do so safely\n // by declaring a dependency on field_update_7000().\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f3193edf74", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_password_confirm/7.x", "instruction": "Implement `form_process_password_confirm($element)` in PHP for Drupal 7. Required behavior: Expand a password_confirm field into two text boxes.", "context": "File: includes/form.inc", "response": "function form_process_password_confirm($element) {\n $element['pass1'] = array(\n '#type' => 'password',\n '#title' => t('Password'),\n '#value' => empty($element['#value']) ? NULL : $element['#value']['pass1'],\n '#required' => $element['#required'],\n '#attributes' => array('class' => array('password-field')),\n );\n $element['pass2'] = array(\n '#type' => 'password',\n '#title' => t('Confirm password'),\n '#value' => empty($element['#value']) ? NULL : $element['#value']['pass2'],\n '#required' => $element['#required'],\n '#attributes' => array('class' => array('password-confirm')),\n );\n $element['#element_validate'] = array('password_confirm_validate');\n $element['#tree'] = TRUE;\n\n if (isset($element['#size'])) {\n $element['pass1']['#size'] = $element['pass2']['#size'] = $element['#size'];\n }\n\n return $element;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f32239f546", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_admin_display/7.x", "instruction": "Implement `block_admin_display($theme = NULL)` in PHP for Drupal 7. Required behavior: Menu callback for admin/structure/block.", "context": "Parameters:\n- $theme: The theme to display the administration page for. If not provided, defaults to the currently used theme.\n\nFile: modules/block/block.admin.inc", "response": "function block_admin_display($theme = NULL) {\n global $theme_key;\n\n drupal_theme_initialize();\n\n if (!isset($theme)) {\n // If theme is not specifically set, rehash for the current theme.\n $theme = $theme_key;\n }\n\n // Fetch and sort blocks.\n $blocks = block_admin_display_prepare_blocks($theme);\n\n return drupal_get_form('block_admin_display_form', $blocks, $theme);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f35770c3fb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21modules%21number%21number.module/function/number_field_widget_info/7.x", "instruction": "In Drupal 7, write the function `number_field_widget_info()` (file modules/field/modules/number/number.module) so that it does the following: Implements hook_field_widget_info().", "context": "File: modules/field/modules/number/number.module", "response": "function number_field_widget_info() {\n return array(\n 'number' => array(\n 'label' => t('Text field'),\n 'field types' => array('number_integer', 'number_decimal', 'number_float'),\n ),\n );\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f3586e9415", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21language.api.php/function/hook_language_switch_links_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_language_switch_links_alter(array &$links, $type, $path)` (modules/system/language.api.php): Perform alterations on language switcher links.", "context": "A language switcher link may need to point to a different path or use a translated link text before going through l(), which will just handle the path aliases.\n\nParameters:\n- $links: Nested array of links keyed by language code.\n- $type: The language type the links will switch.\n- $path: The current path.\n\nFile: modules/system/language.api.php", "response": "function hook_language_switch_links_alter(array &$links, $type, $path) {\n global $language;\n\n if ($type == LANGUAGE_TYPE_CONTENT && isset($links[$language->language])) {\n foreach ($links[$language->language] as $link) {\n $link['attributes']['class'][] = 'active-language';\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f387ef1676", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/watchdog_exception/7.x", "instruction": "I need the code for `watchdog_exception($type, Exception $exception, $message = NULL, $variables = array(), $severity = WATCHDOG_ERROR, $link = NULL)` in Drupal 7 (includes/bootstrap.inc). It must do this: Logs an exception.", "context": "This is a wrapper function for watchdog() which automatically decodes an exception.\n\nParameters:\n- $type: The category to which this message belongs.\n- $exception: The exception that is going to be logged.\n- $message: The message to store in the log. If empty, a text that contains all useful information about the passed-in exception is used.\n- $variables: Array of variables to replace in the message on display. Defaults to the return value of _drupal_decode_exception().\n- $severity: The severity of the message, as per RFC 3164.\n- $link: A link to associate with the message.\n\nFile: includes/bootstrap.inc", "response": "function watchdog_exception($type, Exception $exception, $message = NULL, $variables = array(), $severity = WATCHDOG_ERROR, $link = NULL) {\n\n // Use a default value if $message is not set.\n if (empty($message)) {\n // The exception message is run through check_plain() by _drupal_decode_exception().\n $message = '%type: !message in %function (line %line of %file).';\n }\n // $variables must be an array so that we can add the exception information.\n if (!is_array($variables)) {\n $variables = array();\n }\n\n require_once DRUPAL_ROOT . '/includes/errors.inc';\n $variables += _drupal_decode_exception($exception);\n watchdog($type, $message, $variables, $severity, $link);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f3aac1c291", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_user_presave/7.x", "instruction": "Implement `overlay_user_presave(&$edit, $account, $category)` in PHP for Drupal 7. Required behavior: Implements hook_user_presave().", "context": "File: modules/overlay/overlay.module", "response": "function overlay_user_presave(&$edit, $account, $category) {\n if (isset($edit['overlay'])) {\n $edit['data']['overlay'] = $edit['overlay'];\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f3b1a52567", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_reduce_order/7.x", "instruction": "Implement `_field_ui_reduce_order($array, $a)` in PHP for Drupal 7. Required behavior: Determines the rendering order of an array representing a tree.", "context": "Callback for array_reduce() within field_ui_table_pre_render().\n\nFile: modules/field_ui/field_ui.admin.inc", "response": "function _field_ui_reduce_order($array, $a) {\n $array = !isset($array) ? array() : $array;\n if ($a['name']) {\n $array[] = $a['name'];\n }\n if (!empty($a['children'])) {\n uasort($a['children'], 'drupal_sort_weight');\n $array = array_merge($array, array_reduce($a['children'], '_field_ui_reduce_order'));\n }\n return $array;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f3e9151201", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_role_revoke_permissions/7.x", "instruction": "I need the code for `user_role_revoke_permissions($rid, array $permissions = array())` in Drupal 7 (modules/user/user.module). It must do this: Revoke permissions from a user role.", "context": "Parameters:\n- $rid: The ID of a user role to alter.\n- $permissions: A list of permission names to revoke.\n\nFile: modules/user/user.module", "response": "function user_role_revoke_permissions($rid, array $permissions = array()) {\n // Revoke permissions for the role.\n db_delete('role_permission')\n ->condition('rid', $rid)\n ->condition('permission', $permissions, 'IN')\n ->execute();\n\n // Clear the user access cache.\n drupal_static_reset('user_access');\n drupal_static_reset('user_role_permissions');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f3f490a0ab", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21color%21color.module/function/_color_blend/7.x", "instruction": "In Drupal 7, write the function `_color_blend($img, $hex1, $hex2, $alpha)` (file modules/color/color.module) so that it does the following: Blends two hex colors and returns the GD color.", "context": "File: modules/color/color.module", "response": "function _color_blend($img, $hex1, $hex2, $alpha) {\n $in1 = _color_unpack($hex1);\n $in2 = _color_unpack($hex2);\n $out = array($img);\n for ($i = 0; $i < 3; ++$i) {\n $out[] = (int) ($in1[$i] + ($in2[$i] - $in1[$i]) * $alpha);\n }\n\n return call_user_func_array('imagecolorallocate', $out);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f3ffbddb75", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_taxonomy_term_update/7.x", "instruction": "Implement `path_taxonomy_term_update($term)` in PHP for Drupal 7. Required behavior: Implements hook_taxonomy_term_update().", "context": "File: modules/path/path.module", "response": "function path_taxonomy_term_update($term) {\n if (isset($term->path)) {\n $path = $term->path;\n $path['alias'] = trim($path['alias']);\n // Delete old alias if user erased it.\n if (!empty($path['pid']) && empty($path['alias'])) {\n path_delete($path['pid']);\n }\n // Only save a non-empty alias.\n if (!empty($path['alias'])) {\n // Ensure fields for programmatic executions.\n $path['source'] = 'taxonomy/term/' . $term->tid;\n // Core does not provide a way to store the term language but contrib\n // modules can do it so we need to take this into account.\n $langcode = entity_language('taxonomy_term', $term);\n $path['language'] = !empty($langcode) ? $langcode : LANGUAGE_NONE;\n path_save($path);\n }\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f420173823", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_admin_paths_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_admin_paths_alter(&$paths)` (modules/system/system.api.php): Redefine administrative paths defined by other modules.", "context": "Parameters:\n- $paths: An associative array of administrative paths, as defined by implementations of hook_admin_paths().\n\nFile: modules/system/system.api.php", "response": "function hook_admin_paths_alter(&$paths) {\n // Treat all user pages as administrative.\n $paths['user'] = TRUE;\n $paths['user/*'] = TRUE;\n // Treat the forum topic node form as a non-administrative page.\n $paths['node/add/forum'] = FALSE;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f431595869", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_get/7.x", "instruction": "Implement `language_negotiation_get($type, $provider_id = NULL)` in PHP for Drupal 7. Required behavior: Checks whether a language negotiation provider is enabled for a language type.", "context": "This has two possible behaviors:\n - If $provider_id is given return its ID if enabled, FALSE otherwise.\n - If no ID is passed the first enabled language negotiation provider is\n returned.\n\nParameters:\n- $type: The language negotiation provider type.\n- $provider_id: The language negotiation provider ID.\n\nReturns: The provider ID if it is enabled, FALSE otherwise.\n\nFile: includes/language.inc", "response": "function language_negotiation_get($type, $provider_id = NULL) {\n $negotiation = variable_get(\"language_negotiation_$type\", array());\n\n if (empty($negotiation)) {\n return empty($provider_id) ? LANGUAGE_NEGOTIATION_DEFAULT : FALSE;\n }\n\n if (empty($provider_id)) {\n return key($negotiation);\n }\n\n if (isset($negotiation[$provider_id])) {\n return $provider_id;\n }\n\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f44fd74bdc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_html_head_link/7.x", "instruction": "Implement `drupal_add_html_head_link($attributes, $header = FALSE)` in PHP for Drupal 7. Required behavior: Adds a LINK tag with distinct attributes to the page's HEAD.", "context": "This function can be called as long the HTML header hasn't been sent, which on normal pages is up through the preprocess step of theme('html'). Adding a link will overwrite a prior link with the exact same 'rel', 'href' and 'hreflang' attributes.\n\nParameters:\n- $attributes: Associative array of element attributes including 'href' and 'rel'.\n- $header: Optional flag to determine if a HTTP 'Link:' header should be sent.\n\nFile: includes/common.inc", "response": "function drupal_add_html_head_link($attributes, $header = FALSE) {\n $element = array(\n '#tag' => 'link',\n '#attributes' => $attributes,\n );\n $href = $attributes['href'];\n\n if ($header) {\n // Also add a HTTP header \"Link:\".\n $href = '<' . $attributes['href'] . '>;';\n unset($attributes['href']);\n $element['#attached']['drupal_add_http_header'][] = array('Link', $href . drupal_http_header_attributes($attributes), TRUE);\n }\n\n drupal_add_html_head($element, 'drupal_add_html_head_link:' . $attributes['rel'] . ':' . (isset($attributes['hreflang']) ? \"{$attributes['hreflang']}:\" : '') . $href);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f45bf08f92", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_block_info/7.x", "instruction": "I need the code for `user_block_info()` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_block_info().", "context": "File: modules/user/user.module", "response": "function user_block_info() {\n global $user;\n\n $blocks['login']['info'] = t('User login');\n // Not worth caching.\n $blocks['login']['cache'] = DRUPAL_NO_CACHE;\n\n $blocks['new']['info'] = t('Who\\'s new');\n $blocks['new']['properties']['administrative'] = TRUE;\n\n // Too dynamic to cache.\n $blocks['online']['info'] = t('Who\\'s online');\n $blocks['online']['cache'] = DRUPAL_NO_CACHE;\n $blocks['online']['properties']['administrative'] = TRUE;\n\n return $blocks;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f46de7616b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_update_instance/7.x", "instruction": "Implement `field_update_instance($instance)` in PHP for Drupal 7. Required behavior: Updates an instance of a field.", "context": "Parameters:\n- $instance: An associative array representing an instance structure. The following required array elements specify which field instance is being updated: - entity_type: The type of the entity the field is attached to. - bundle: The bundle this field belongs to. - field_name: The name of an existing field. The other array elements represent properties of the instance, and all properties must be specified or their default values will be used (except internal-use properties, which are assigned automatically). To avoid losing the previously stored properties of the instance when making a change, first load the instance with field_info_instance(), then override the values you want to override, and finally save using this function. Example: @code // Fetch an instance info array. $instance_info = field_info_instance($entity_type, $field_name, $bundle_name); // Change a single property in the instance definition. $instance_info['required'] = TRUE; // Write the changed definition back. field_update_instance($instance_info); @endcode\n\nFile: modules/field/field.crud.inc", "response": "function field_update_instance($instance) {\n // Check that the specified field exists.\n $field = field_read_field($instance['field_name']);\n if (empty($field)) {\n throw new FieldException(t('Attempt to update an instance of a nonexistent field @field.', array('@field' => $instance['field_name'])));\n }\n\n // Check that the field instance exists (even if it is inactive, since we\n // want to be able to replace inactive widgets with new ones).\n $prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));\n if (empty($prior_instance)) {\n throw new FieldException(t(\"Attempt to update an instance of field @field on bundle @bundle that doesn't exist.\", array('@field' => $instance['field_name'], '@bundle' => $instance['bundle'])));\n }\n\n $instance['id'] = $prior_instance['id'];\n $instance['field_id'] = $prior_instance['field_id'];\n\n _field_write_instance($instance, TRUE);\n\n // Clear caches.\n field_cache_clear();\n\n module_invoke_all('field_update_instance', $instance, $prior_instance);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f46e006062", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/_menu_get_options/7.x", "instruction": "I need the code for `_menu_get_options($menus, $available_menus, $item)` in Drupal 7 (modules/menu/menu.module). It must do this: Helper function to get the items of the given menu.", "context": "File: modules/menu/menu.module", "response": "function _menu_get_options($menus, $available_menus, $item) {\n global $menu_admin;\n $menu_admin = TRUE;\n\n // If the item has children, there is an added limit to the depth of valid parents.\n if (isset($item['parent_depth_limit'])) {\n $limit = $item['parent_depth_limit'];\n }\n else {\n $limit = _menu_parent_depth_limit($item);\n }\n\n $options = array();\n foreach ($menus as $menu_name => $title) {\n if (isset($available_menus[$menu_name])) {\n $tree = menu_tree_all_data($menu_name, NULL);\n $options[$menu_name . ':0'] = '<' . $title . '>';\n _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid'], $limit);\n }\n }\n\n $menu_admin = FALSE;\n return $options;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f48658b896", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21php%21php.module/function/php_help/7.x", "instruction": "Implement `php_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help().", "context": "File: modules/php/php.module", "response": "function php_help($path, $arg) {\n switch ($path) {\n case 'admin/help#php':\n $output = '';\n $output .= '

              ' . t('About') . '

              ';\n $output .= '

              ' . t('The PHP filter module adds a PHP filter to your site, for use with text formats. This filter adds the ability to execute PHP code in any text field that uses a text format (such as the body of a content item or the text of a comment). PHP is a general-purpose scripting language widely-used for web development, and is the language with which Drupal has been developed. For more information, see the online handbook entry for the PHP filter module.', array('@filter' => url('admin/help/filter'), '@php-net' => 'http://www.php.net', '@php' => 'http://drupal.org/documentation/modules/php/')) . '

              ';\n $output .= '

              ' . t('Uses') . '

              ';\n $output .= '
              ';\n $output .= '
              ' . t('Enabling execution of PHP in text fields') . '
              ';\n $output .= '
              ' . t('The PHP filter module allows users with the proper permissions to include custom PHP code that will get executed when pages of your site are processed. While this is a powerful and flexible feature if used by a trusted user with PHP experience, it is a significant and dangerous security risk in the hands of a malicious or inexperienced user. Even a trusted user may accidentally compromise the site by entering malformed or incorrect PHP code. Only the most trusted users should be granted permission to use the PHP filter, and all PHP code added through the PHP filter should be carefully examined before use. Example PHP snippets can be found on Drupal.org.', array('@php-snippets' => url('http://drupal.org/documentation/customization/php-snippets'))) . '
              ';\n $output .= '
              ';\n return $output;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f4b8056108", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7002/7.x", "instruction": "Implement `taxonomy_update_7002()` in PHP for Drupal 7. Required behavior: Add {vocabulary}.machine_name column.", "context": "File: modules/taxonomy/taxonomy.install", "response": "function taxonomy_update_7002() {\n $field = array(\n 'type' => 'varchar',\n 'length' => 255,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The vocabulary machine name.',\n );\n\n db_add_field('taxonomy_vocabulary', 'machine_name', $field);\n\n // Do a direct query here, rather than calling taxonomy_get_vocabularies(),\n // in case Taxonomy module is disabled.\n $vids = db_query('SELECT vid FROM {taxonomy_vocabulary}')->fetchCol();\n foreach ($vids as $vid) {\n $machine_name = 'vocabulary_' . $vid;\n db_update('taxonomy_vocabulary')\n ->fields(array('machine_name' => $machine_name))\n ->condition('vid', $vid)\n ->execute();\n }\n\n // The machine_name unique key can only be added after we ensure the\n // machine_name column contains unique values.\n db_add_unique_key('taxonomy_vocabulary', 'machine_name', array('machine_name'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f4c9518b69", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_feed/7.x", "instruction": "In Drupal 7, write the function `node_feed($nids = FALSE, $channel = array())` (file modules/node/node.module) so that it does the following: Generates and prints an RSS feed.", "context": "Generates an RSS feed from an array of node IDs, and prints it with an HTTP header, with Content Type set to RSS/XML.\n\nParameters:\n- $nids: An array of node IDs (nid). Defaults to FALSE so empty feeds can be generated with passing an empty array, if no items are to be added to the feed.\n- $channel: An associative array containing title, link, description and other keys, to be parsed by format_rss_channel() and format_xml_elements(). A list of channel elements can be found at the @link http://cyber.law.harvard.edu/rss/rss.html RSS 2.0 Specification. @endlink The link should be an absolute URL.\n\nFile: modules/node/node.module", "response": "function node_feed($nids = FALSE, $channel = array()) {\n global $base_url, $language_content;\n\n if ($nids === FALSE) {\n $nids = db_select('node', 'n')\n ->fields('n', array('nid', 'created'))\n ->condition('n.promote', 1)\n ->condition('n.status', 1)\n ->orderBy('n.created', 'DESC')\n ->range(0, variable_get('feed_default_items', 10))\n ->addTag('node_access')\n ->execute()\n ->fetchCol();\n }\n\n $item_length = variable_get('feed_item_length', 'fulltext');\n $namespaces = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/');\n\n // Load all nodes to be rendered.\n $nodes = node_load_multiple($nids);\n $items = '';\n foreach ($nodes as $node) {\n $item_text = '';\n\n $node->link = url(\"node/$node->nid\", array('absolute' => TRUE));\n $node->rss_namespaces = array();\n $account = user_load($node->uid);\n $node->rss_elements = array(\n array('key' => 'pubDate', 'value' => gmdate('r', $node->created)),\n array('key' => 'dc:creator', 'value' => format_username($account)),\n array('key' => 'guid', 'value' => $node->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false'))\n );\n\n // The node gets built and modules add to or modify $node->rss_elements\n // and $node->rss_namespaces.\n $build = node_view($node, 'rss');\n unset($build['#theme']);\n\n if (!empty($node->rss_namespaces)) {\n $namespaces = array_merge($namespaces, $node->rss_namespaces);\n }\n\n if ($item_length != 'title') {\n // We render node contents and force links to be last.\n $build['links']['#weight'] = 1000;\n $item_text .= drupal_render($build);\n }\n\n $items .= format_rss_item($node->title, $node->link, $item_text, $node->rss_elements);\n }\n\n $channel_defaults = array(\n 'version' => '2.0',\n 'title' => variable_get('site_name', 'Drupal'),\n 'link' => $base_url,\n 'description' => variable_get('feed_description', ''),\n 'language' => $language_content->language\n );\n $channel_extras = array_diff_key($channel, $channel_defaults);\n $channel = array_merge($channel_defaults, $channel);\n\n $output = \"\\n\";\n $output .= \"\\n\";\n $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language'], $channel_extras);\n $output .= \"\\n\";\n\n drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');\n print $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f4d3dd06ee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_modules_confirm_form/7.x", "instruction": "In Drupal 7, write the function `system_modules_confirm_form($modules, $storage)` (file modules/system/system.admin.inc) so that it does the following: Display confirmation form for required modules.", "context": "Parameters:\n- $modules: Array of module file objects as returned from system_rebuild_module_data().\n- $storage: The contents of $form_state['storage']; an array with two elements: the list of required modules and the list of status form field values from the previous screen.\n\nFile: modules/system/system.admin.inc", "response": "function system_modules_confirm_form($modules, $storage) {\n $items = array();\n\n $form['validation_modules'] = array('#type' => 'value', '#value' => $modules);\n $form['status']['#tree'] = TRUE;\n\n foreach ($storage['more_required'] as $info) {\n $t_argument = array(\n '@module' => $info['name'],\n '@required' => implode(', ', $info['requires']),\n );\n $items[] = format_plural(count($info['requires']), 'You must enable the @required module to install @module.', 'You must enable the @required modules to install @module.', $t_argument);\n }\n\n foreach ($storage['missing_modules'] as $name => $info) {\n $t_argument = array(\n '@module' => $name,\n '@depends' => implode(', ', $info['depends']),\n );\n $items[] = format_plural(count($info['depends']), 'The @module module is missing, so the following module will be disabled: @depends.', 'The @module module is missing, so the following modules will be disabled: @depends.', $t_argument);\n }\n\n $form['text'] = array('#markup' => theme('item_list', array('items' => $items)));\n\n if ($form) {\n // Set some default form values\n $form = confirm_form(\n $form,\n t('Some required modules must be enabled'),\n 'admin/modules',\n t('Would you like to continue with the above?'),\n t('Continue'),\n t('Cancel'));\n return $form;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f4e2fdc477", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_field_storage_pre_insert/7.x", "instruction": "Implement `forum_field_storage_pre_insert($entity_type, $entity, &$skip_fields)` in PHP for Drupal 7. Required behavior: Implements hook_field_storage_pre_insert().", "context": "File: modules/forum/forum.module", "response": "function forum_field_storage_pre_insert($entity_type, $entity, &$skip_fields) {\n if ($entity_type == 'node' && $entity->status && _forum_node_check_node_type($entity)) {\n $query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));\n foreach ($entity->taxonomy_forums as $language) {\n foreach ($language as $item) {\n $query->values(array(\n 'nid' => $entity->nid,\n 'title' => $entity->title,\n 'tid' => $item['tid'],\n 'sticky' => $entity->sticky,\n 'created' => $entity->created,\n 'comment_count' => 0,\n 'last_comment_timestamp' => $entity->created,\n ));\n }\n }\n $query->execute();\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f4e7eec212", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_dependencies/7.x", "instruction": "In Drupal 7, write the function `system_update_dependencies()` (file modules/system/system.install) so that it does the following: Implements hook_update_dependencies().", "context": "File: modules/system/system.install", "response": "function system_update_dependencies() {\n // system_update_7053() queries the {block} table, so it must run after\n // block_update_7002(), which creates that table.\n $dependencies['system'][7053] = array(\n 'block' => 7002,\n );\n\n // system_update_7061() queries the {node_revision} table, so it must run\n // after node_update_7001(), which renames the {node_revisions} table.\n $dependencies['system'][7061] = array(\n 'node' => 7001,\n );\n\n // system_update_7067() migrates role permissions and therefore must run\n // after the {role} and {role_permission} tables are properly set up, which\n // happens in user_update_7007().\n $dependencies['system'][7067] = array(\n 'user' => 7007,\n );\n\n return $dependencies;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f4f4e42a0e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/_update_process_info_list/7.x", "instruction": "In Drupal 7, write the function `_update_process_info_list(&$projects, $list, $project_type, $status)` (file modules/update/update.compare.inc) so that it does the following: Populates an array of project data.", "context": "This iterates over a list of the installed modules or themes and groups them by project and status. A few parts of this function assume that enabled modules and themes are always processed first, and if disabled modules or themes are being processed (there is a setting to control if disabled code should be included or not in the 'Available updates' report), those are only processed after $projects has been populated with information about the enabled code. Modules and themes set as hidden are always ignored. This function also records the latest change time on the .info files for each module or theme, which is important data which is used when deciding if the cached available update data should be invalidated.\n\nParameters:\n- $projects: Reference to the array of project data of what's installed on this site.\n- $list: Array of data to process to add the relevant info to the $projects array.\n- $project_type: The kind of data in the list. Can be 'module' or 'theme'.\n- $status: Boolean that controls what status (enabled or disabled) to process out of the $list and add to the $projects array.\n\nFile: modules/update/update.compare.inc", "response": "function _update_process_info_list(&$projects, $list, $project_type, $status) {\n $admin_theme = variable_get('admin_theme', 'seven');\n foreach ($list as $file) {\n // The admin theme is a special case. It should always be considered enabled\n // for the purposes of update checking.\n if ($file->name === $admin_theme) {\n $file->status = TRUE;\n }\n // A disabled base theme of an enabled sub-theme still has all of its code\n // run by the sub-theme, so we include it in our \"enabled\" projects list.\n if ($status && !$file->status && !empty($file->sub_themes)) {\n foreach ($file->sub_themes as $key => $name) {\n // Build a list of enabled sub-themes.\n if ($list[$key]->status) {\n $file->enabled_sub_themes[$key] = $name;\n }\n }\n // If there are no enabled subthemes, we should ignore this base theme\n // for the enabled case. If the site is trying to display disabled\n // themes, we'll catch it then.\n if (empty($file->enabled_sub_themes)) {\n continue;\n }\n }\n // Otherwise, just add projects of the proper status to our list.\n elseif ($file->status != $status) {\n continue;\n }\n\n // Skip if the .info file is broken.\n if (empty($file->info)) {\n continue;\n }\n\n // Skip if it's a hidden module or theme.\n if (!empty($file->info['hidden'])) {\n continue;\n }\n\n // If the .info doesn't define the 'project', try to figure it out.\n if (!isset($file->info['project'])) {\n $file->info['project'] = update_get_project_name($file);\n }\n\n // If we still don't know the 'project', give up.\n if (empty($file->info['project'])) {\n continue;\n }\n\n // If we don't already know it, grab the change time on the .info file\n // itself. Note: we need to use the ctime, not the mtime (modification\n // time) since many (all?) tar implementations will go out of their way to\n // set the mtime on the files it creates to the timestamps recorded in the\n // tarball. We want to see the last time the file was changed on disk,\n // which is left alone by tar and correctly set to the time the .info file\n // was unpacked.\n if (!isset($file->info['_info_file_ctime'])) {\n $info_filename = dirname($file->uri) . '/' . $file->name . '.info';\n $file->info['_info_file_ctime'] = filectime($info_filename);\n }\n\n if (!isset($file->info['datestamp'])) {\n $file->info['datestamp'] = 0;\n }\n\n $project_name = $file->info['project'];\n\n // Figure out what project type we're going to use to display this module\n // or theme. If the project name is 'drupal', we don't want it to show up\n // under the usual \"Modules\" section, we put it at a special \"Drupal Core\"\n // section at the top of the report.\n if ($project_name == 'drupal') {\n $project_display_type = 'core';\n }\n else {\n $project_display_type = $project_type;\n }\n if (empty($status) && empty($file->enabled_sub_themes)) {\n // If we're processing disabled modules or themes, append a suffix.\n // However, we don't do this to a a base theme with enabled\n // subthemes, since we treat that case as if it is enabled.\n $project_display_type .= '-disabled';\n }\n // Add a list of sub-themes that \"depend on\" the project and a list of base\n // themes that are \"required by\" the project.\n if ($project_name == 'drupal') {\n // Drupal core is always required, so this extra info would be noise.\n $sub_themes = array();\n $base_themes = array();\n }\n else {\n // Add list of enabled sub-themes.\n $sub_themes = !empty($file->enabled_sub_themes) ? $file->enabled_sub_themes : array();\n // Add list of base themes.\n $base_themes = !empty($file->base_themes) ? $file->base_themes : array();\n }\n if (!isset($projects[$project_name])) {\n // Only process this if we haven't done this project, since a single\n // project can have multiple modules or themes.\n $projects[$project_name] = array(\n 'name' => $project_name,\n // Only save attributes from the .info file we care about so we do not\n // bloat our RAM usage needlessly.\n 'info' => update_filter_project_info($file->info),\n 'datestamp' => $file->info['datestamp'],\n 'includes' => array($file->name => $file->info['name']),\n 'project_type' => $project_display_type,\n 'project_status' => $status,\n 'sub_themes' => $sub_themes,\n 'base_themes' => $base_themes,\n );\n }\n elseif ($projects[$project_name]['project_type'] == $project_display_type) {\n // Only add the file we're processing to the 'includes' array for this\n // project if it is of the same type and status (which is encoded in the\n // $project_display_type). This prevents listing all the disabled\n // modules included with an enabled project if we happen to be checking\n // for disabled modules, too.\n $projects[$project_name]['includes'][$file->name] = $file->info['name'];\n $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']);\n $projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']);\n if (!empty($sub_themes)) {\n $projects[$project_name]['sub_themes'] += $sub_themes;\n }\n if (!empty($base_themes)) {\n $projects[$project_name]['base_themes'] += $base_themes;\n }\n }\n elseif (empty($status)) {\n // If we have a project_name that matches, but the project_display_type\n // does not, it means we're processing a disabled module or theme that\n // belongs to a project that has some enabled code. In this case, we add\n // the disabled thing into a separate array for separate display.\n $projects[$project_name]['disabled'][$file->name] = $file->info['name'];\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f4fa7d6f88", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.api.php/function/hook_update_projects_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_update_projects_alter(&$projects)` (modules/update/update.api.php): Alter the list of projects before fetching data and comparing versions.", "context": "Most modules will never need to implement this hook. It is for advanced interaction with the Update Manager module. The primary use-case for this hook is to add projects to the list; for example, to provide update status data on disabled modules and themes. A contributed module might want to hide projects from the list; for example, if there is a site-specific module that doesn't have any official releases, that module could remove itself from this list to avoid \"No available releases found\" warnings on the available updates report. In rare cases, a module might want to alter the data associated with a project already in the list.\n\nParameters:\n- $projects: Reference to an array of the projects installed on the system. This includes all the metadata documented in the comments below for each project (either module or theme) that is currently enabled. The array is initially populated inside update_get_projects() with the help of _update_process_info_list(), so look there for examples of how to populate the array with real values.\n\nFile: modules/update/update.api.php", "response": "function hook_update_projects_alter(&$projects) {\n // Hide a site-specific module from the list.\n unset($projects['site_specific_module']);\n\n // Add a disabled module to the list.\n // The key for the array should be the machine-readable project \"short name\".\n $projects['disabled_project_name'] = array(\n // Machine-readable project short name (same as the array key above).\n 'name' => 'disabled_project_name',\n // Array of values from the main .info file for this project.\n 'info' => array(\n 'name' => 'Some disabled module',\n 'description' => 'A module not enabled on the site that you want to see in the available updates report.',\n 'version' => '7.x-1.0',\n 'core' => '7.x',\n // The maximum file change time (the \"ctime\" returned by the filectime()\n // PHP method) for all of the .info files included in this project.\n '_info_file_ctime' => 1243888165,\n ),\n // The date stamp when the project was released, if known. If the disabled\n // project was an officially packaged release from drupal.org, this will\n // be included in the .info file as the 'datestamp' field. This only\n // really matters for development snapshot releases that are regenerated,\n // so it can be left undefined or set to 0 in most cases.\n 'datestamp' => 1243888185,\n // Any modules (or themes) included in this project. Keyed by machine-\n // readable \"short name\", value is the human-readable project name printed\n // in the UI.\n 'includes' => array(\n 'disabled_project' => 'Disabled module',\n 'disabled_project_helper' => 'Disabled module helper module',\n 'disabled_project_foo' => 'Disabled module foo add-on module',\n ),\n // Does this project contain a 'module', 'theme', 'disabled-module', or\n // 'disabled-theme'?\n 'project_type' => 'disabled-module',\n );\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f52d66711a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_instance_settings_form/7.x", "instruction": "Implement `image_field_instance_settings_form($field, $instance)` in PHP for Drupal 7. Required behavior: Implements hook_field_instance_settings_form().", "context": "File: modules/image/image.field.inc", "response": "function image_field_instance_settings_form($field, $instance) {\n $settings = $instance['settings'];\n\n // Use the file field instance settings form as a basis.\n $form = file_field_instance_settings_form($field, $instance);\n\n // Add maximum and minimum resolution settings.\n $max_resolution = explode('x', $settings['max_resolution']) + array('', '');\n $form['max_resolution'] = array(\n '#type' => 'item',\n '#title' => t('Maximum image resolution'),\n '#element_validate' => array('_image_field_resolution_validate'),\n '#weight' => 4.1,\n '#field_prefix' => '
              ',\n '#field_suffix' => '
              ',\n '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of EXIF data in the image.'),\n );\n $form['max_resolution']['x'] = array(\n '#type' => 'textfield',\n '#title' => t('Maximum width'),\n '#title_display' => 'invisible',\n '#default_value' => $max_resolution[0],\n '#size' => 5,\n '#maxlength' => 5,\n '#field_suffix' => ' x ',\n );\n $form['max_resolution']['y'] = array(\n '#type' => 'textfield',\n '#title' => t('Maximum height'),\n '#title_display' => 'invisible',\n '#default_value' => $max_resolution[1],\n '#size' => 5,\n '#maxlength' => 5,\n '#field_suffix' => ' ' . t('pixels'),\n );\n\n $min_resolution = explode('x', $settings['min_resolution']) + array('', '');\n $form['min_resolution'] = array(\n '#type' => 'item',\n '#title' => t('Minimum image resolution'),\n '#element_validate' => array('_image_field_resolution_validate'),\n '#weight' => 4.2,\n '#field_prefix' => '
              ',\n '#field_suffix' => '
              ',\n '#description' => t('The minimum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'),\n );\n $form['min_resolution']['x'] = array(\n '#type' => 'textfield',\n '#title' => t('Minimum width'),\n '#title_display' => 'invisible',\n '#default_value' => $min_resolution[0],\n '#size' => 5,\n '#maxlength' => 5,\n '#field_suffix' => ' x ',\n );\n $form['min_resolution']['y'] = array(\n '#type' => 'textfield',\n '#title' => t('Minimum height'),\n '#title_display' => 'invisible',\n '#default_value' => $min_resolution[1],\n '#size' => 5,\n '#maxlength' => 5,\n '#field_suffix' => ' ' . t('pixels'),\n );\n\n // Remove the description option.\n unset($form['description_field']);\n\n // Add title and alt configuration options.\n $form['alt_field'] = array(\n '#type' => 'checkbox',\n '#title' => t('Enable Alt field'),\n '#default_value' => $settings['alt_field'],\n '#description' => t('The alt attribute may be used by search engines, screen readers, and when the image cannot be loaded.'),\n '#weight' => 10,\n );\n $form['title_field'] = array(\n '#type' => 'checkbox',\n '#title' => t('Enable Title field'),\n '#default_value' => $settings['title_field'],\n '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image.'),\n '#weight' => 11,\n );\n\n // Add the default image to the instance.\n $form['default_image'] = array(\n '#title' => t('Default image'),\n '#type' => 'managed_file',\n '#description' => t(\"If no image is uploaded, this image will be shown on display and will override the field's default image.\"),\n '#default_value' => $settings['default_image'],\n '#upload_location' => $field['settings']['uri_scheme'] . '://default_images/',\n );\n\n return $form;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f54d8a1464", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.tokens.inc/function/user_tokens/7.x", "instruction": "In Drupal 7, write the function `user_tokens($type, $tokens, array $data = array(), array $options = array())` (file modules/user/user.tokens.inc) so that it does the following: Implements hook_tokens().", "context": "File: modules/user/user.tokens.inc", "response": "function user_tokens($type, $tokens, array $data = array(), array $options = array()) {\n $url_options = array('absolute' => TRUE);\n if (isset($options['language'])) {\n $url_options['language'] = $options['language'];\n $language_code = $options['language']->language;\n }\n else {\n $language_code = NULL;\n }\n $sanitize = !empty($options['sanitize']);\n\n $replacements = array();\n\n if ($type == 'user' && !empty($data['user'])) {\n $account = $data['user'];\n foreach ($tokens as $name => $original) {\n switch ($name) {\n // Basic user account information.\n case 'uid':\n // In the case of hook user_presave uid is not set yet.\n $replacements[$original] = !empty($account->uid) ? $account->uid : t('not yet assigned');\n break;\n\n case 'name':\n $name = format_username($account);\n $replacements[$original] = $sanitize ? check_plain($name) : $name;\n break;\n\n case 'mail':\n if (empty($account->mail)) {\n $replacements[$original] = '';\n }\n else {\n $replacements[$original] = $sanitize ? check_plain($account->mail) : $account->mail;\n }\n break;\n\n case 'url':\n $replacements[$original] = !empty($account->uid) ? url(\"user/$account->uid\", $url_options) : t('not yet assigned');\n break;\n\n case 'edit-url':\n $replacements[$original] = !empty($account->uid) ? url(\"user/$account->uid/edit\", $url_options) : t('not yet assigned');\n break;\n\n // These tokens are default variations on the chained tokens handled below.\n case 'last-login':\n $replacements[$original] = !empty($account->login) ? format_date($account->login, 'medium', '', NULL, $language_code) : t('never');\n break;\n\n case 'created':\n // In the case of user_presave the created date may not yet be set.\n $replacements[$original] = !empty($account->created) ? format_date($account->created, 'medium', '', NULL, $language_code) : t('not yet created');\n break;\n\n case 'changed':\n // In the case of user_presave the created date may not yet be set.\n $replacements[$original] = !empty($account->changed) ? format_date($account->changed, 'medium', '', NULL, $language_code) : t('not yet created');\n break;\n }\n }\n\n if ($login_tokens = token_find_with_prefix($tokens, 'last-login')) {\n $replacements += token_generate('date', $login_tokens, array('date' => $account->login), $options);\n }\n\n if ($registered_tokens = token_find_with_prefix($tokens, 'created')) {\n $replacements += token_generate('date', $registered_tokens, array('date' => $account->created), $options);\n }\n\n if ($changed_tokens = token_find_with_prefix($tokens, 'changed')) {\n $replacements += token_generate('date', $changed_tokens, array('date' => $account->changed), $options);\n }\n }\n\n if ($type == 'current-user') {\n $account = user_load($GLOBALS['user']->uid);\n $replacements += token_generate('user', $tokens, array('user' => $account), $options);\n }\n\n return $replacements;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f558dfaefe", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_block_info/7.x", "instruction": "I need the code for `menu_block_info()` in Drupal 7 (modules/menu/menu.module). It must do this: Implements hook_block_info().", "context": "File: modules/menu/menu.module", "response": "function menu_block_info() {\n $menus = menu_get_menus(FALSE);\n\n $blocks = array();\n foreach ($menus as $name => $title) {\n $blocks[$name]['info'] = check_plain($title);\n // Menu blocks can't be cached because each menu item can have\n // a custom access callback. menu.inc manages its own caching.\n $blocks[$name]['cache'] = DRUPAL_NO_CACHE;\n }\n return $blocks;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f57e0b80b8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_menu_unassign_access/7.x", "instruction": "I need the code for `trigger_menu_unassign_access()` in Drupal 7 (modules/trigger/trigger.module). It must do this: Access callback: Determines if triggers can be unassigned.", "context": "Returns (bool): TRUE if there are triggers that the user can unassign, FALSE otherwise.\n\nFile: modules/trigger/trigger.module", "response": "function trigger_menu_unassign_access() {\n if (!user_access('administer actions')) {\n return FALSE;\n }\n $count = db_select('trigger_assignments')\n ->countQuery()\n ->execute()\n ->fetchField();\n return $count > 0;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f5a7e93442", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_already_done_error/7.x", "instruction": "In Drupal 7, write the function `install_already_done_error()` (file includes/install.core.inc) so that it does the following: Indicates that Drupal has already been installed.", "context": "File: includes/install.core.inc", "response": "function install_already_done_error() {\n global $base_url;\n\n drupal_set_title(st('Drupal already installed'));\n return st('
              • To start over, you must empty your existing database.
              • To install to a different database, edit the appropriate settings.php file in the sites folder.
              • To upgrade an existing installation, proceed to the update script.
              • View your existing site.
              ', array('@base-url' => $base_url));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f5af3289d2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate_name_length/7.x", "instruction": "I need the code for `file_validate_name_length(stdClass $file)` in Drupal 7 (includes/file.inc). It must do this: Checks for files with names longer than we can store in the database.", "context": "Parameters:\n- $file: A Drupal file object.\n\nReturns: An array. If the file name is too long, it will contain an error message.\n\nFile: includes/file.inc", "response": "function file_validate_name_length(stdClass $file) {\n $errors = array();\n\n if (empty($file->filename)) {\n $errors[] = t(\"The file's name is empty. Please give a name to the file.\");\n }\n if (strlen($file->filename) > 240) {\n $errors[] = t(\"The file's name exceeds the 240 characters limit. Please rename the file and try again.\");\n }\n return $errors;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f5d1f39fe1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7011/7.x", "instruction": "Implement `taxonomy_update_7011(&$sandbox)` in PHP for Drupal 7. Required behavior: Drop unpublished nodes from the index.", "context": "File: modules/taxonomy/taxonomy.install", "response": "function taxonomy_update_7011(&$sandbox) {\n // Initialize information needed by the batch update system.\n if (!isset($sandbox['progress'])) {\n $sandbox['progress'] = 0;\n $sandbox['max'] = db_query('SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {taxonomy_index} t ON n.nid = t.nid WHERE n.status = :status', array(':status' => NODE_NOT_PUBLISHED))->fetchField();\n // If there's no data, don't bother with the extra work.\n if (empty($sandbox['max'])) {\n return;\n }\n }\n\n // Process records in groups of 5000.\n $limit = 5000;\n $nids = db_query_range('SELECT DISTINCT n.nid FROM {node} n INNER JOIN {taxonomy_index} t ON n.nid = t.nid WHERE n.status = :status', 0, $limit, array(':status' => NODE_NOT_PUBLISHED))->fetchCol();\n if (!empty($nids)) {\n db_delete('taxonomy_index')\n ->condition('nid', $nids)\n ->execute();\n }\n\n // Update our progress information for the batch update.\n $sandbox['progress'] += $limit;\n\n // Indicate our current progress to the batch update system, if the update is\n // not yet complete.\n if ($sandbox['progress'] < $sandbox['max']) {\n $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f5d9edccdb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_overview_submit/7.x", "instruction": "In Drupal 7, write the function `filter_admin_overview_submit($form, &$form_state)` (file modules/filter/filter.admin.inc) so that it does the following: Form submission handler for filter_admin_overview().", "context": "File: modules/filter/filter.admin.inc", "response": "function filter_admin_overview_submit($form, &$form_state) {\n foreach ($form_state['values']['formats'] as $id => $data) {\n if (is_array($data) && isset($data['weight'])) {\n // Only update if this is a form element with weight.\n db_update('filter_format')\n ->fields(array('weight' => $data['weight']))\n ->condition('format', $id)\n ->execute();\n }\n }\n filter_formats_reset();\n drupal_set_message(t('The text format ordering has been saved.'));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f5e379f079", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_goto_action_form/7.x", "instruction": "In Drupal 7, write the function `system_goto_action_form($context)` (file modules/system/system.module) so that it does the following: Settings form for system_goto_action().", "context": "File: modules/system/system.module", "response": "function system_goto_action_form($context) {\n $form['url'] = array(\n '#type' => 'textfield',\n '#title' => t('URL'),\n '#description' => t('The URL to which the user should be redirected. This can be an internal path like node/1234 or an external URL like http://example.com.'),\n '#default_value' => isset($context['url']) ? $context['url'] : '',\n '#required' => TRUE,\n );\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f5fffa99a2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_insert/7.x", "instruction": "I need the code for `field_attach_insert($entity_type, $entity)` in Drupal 7 (modules/field/field.attach.inc). It must do this: Save field data for a new entity.", "context": "The passed-in entity must already contain its id and (if applicable) revision id attributes. Default values (if any) will be saved for fields not present in the $entity.\n\nParameters:\n- $entity_type: The type of $entity; e.g. 'node' or 'user'.\n- $entity: The entity with fields to save.\n\nReturns: Default values (if any) will be added to the $entity parameter for fields it leaves unspecified.\n\nFile: modules/field/field.attach.inc", "response": "function field_attach_insert($entity_type, $entity) {\n _field_invoke_default('insert', $entity_type, $entity);\n _field_invoke('insert', $entity_type, $entity);\n\n list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);\n\n // Let any module insert field data before the storage engine, accumulating\n // saved fields along the way.\n $skip_fields = array();\n foreach (module_implements('field_storage_pre_insert') as $module) {\n $function = $module . '_field_storage_pre_insert';\n $function($entity_type, $entity, $skip_fields);\n }\n\n // Collect the storage backends used by the remaining fields in the entities.\n $storages = array();\n foreach (field_info_instances($entity_type, $bundle) as $instance) {\n $field = field_info_field_by_id($instance['field_id']);\n $field_id = $field['id'];\n $field_name = $field['field_name'];\n if (!empty($entity->$field_name)) {\n // Collect the storage backend if the field has not been written yet.\n if (!isset($skip_fields[$field_id])) {\n $storages[$field['storage']['type']][$field_id] = $field_id;\n }\n }\n }\n\n // Field storage backends save any remaining unsaved fields.\n foreach ($storages as $storage => $fields) {\n $storage_info = field_info_storage_types($storage);\n module_invoke($storage_info['module'], 'field_storage_write', $entity_type, $entity, FIELD_STORAGE_INSERT, $fields);\n }\n\n // Let other modules act on inserting the entity.\n module_invoke_all('field_attach_insert', $entity_type, $entity);\n\n $entity_info = entity_get_info($entity_type);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f617deeff5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_field_language_alter/7.x", "instruction": "In Drupal 7, write the function `locale_field_language_alter(&$display_language, $context)` (file modules/locale/locale.module) so that it does the following: Implements hook_field_language_alter().", "context": "File: modules/locale/locale.module", "response": "function locale_field_language_alter(&$display_language, $context) {\n // Do not apply core language fallback rules if they are disabled or if Locale\n // is not registered as a translation handler.\n if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'locale')) {\n locale_field_language_fallback($display_language, $context['entity'], $context['language']);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f62caf2cee", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_unpublish_by_keyword_action_form/7.x", "instruction": "Implement `node_unpublish_by_keyword_action_form($context)` in PHP for Drupal 7. Required behavior: Generates settings form for node_unpublish_by_keyword_action().", "context": "Parameters:\n- $context (array): Array of additional information about what triggered this action.\n\nReturns (array): A form array.\n\nFile: modules/node/node.module", "response": "function node_unpublish_by_keyword_action_form($context) {\n $form['keywords'] = array(\n '#title' => t('Keywords'),\n '#type' => 'textarea',\n '#description' => t('The content will be unpublished if it contains any of the phrases above. Use a case-sensitive, comma-separated list of phrases. Example: funny, bungee jumping, \"Company, Inc.\"'),\n '#default_value' => isset($context['keywords']) ? drupal_implode_tags($context['keywords']) : '',\n );\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f641235022", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_checkboxes/7.x", "instruction": "Implement `theme_checkboxes($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a set of checkbox form elements.", "context": "Parameters:\n- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #children, #attributes.\n\nFile: includes/form.inc", "response": "function theme_checkboxes($variables) {\n $element = $variables['element'];\n $attributes = array();\n if (isset($element['#id'])) {\n $attributes['id'] = $element['#id'];\n }\n $attributes['class'][] = 'form-checkboxes';\n if (!empty($element['#attributes']['class'])) {\n $attributes['class'] = array_merge($attributes['class'], $element['#attributes']['class']);\n }\n if (isset($element['#attributes']['title'])) {\n $attributes['title'] = $element['#attributes']['title'];\n }\n return '' . (!empty($element['#children']) ? $element['#children'] : '') . '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f65ef42eec", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_save/7.x", "instruction": "In Drupal 7, write the function `image_gd_save(stdClass $image, $destination)` (file modules/system/image.gd.inc) so that it does the following: GD helper to write an image resource to a destination file.", "context": "Parameters:\n- $image: An image object.\n- $destination: A string file URI or path where the image should be saved.\n\nReturns: TRUE or FALSE, based on success.\n\nFile: modules/system/image.gd.inc", "response": "function image_gd_save(stdClass $image, $destination) {\n $scheme = file_uri_scheme($destination);\n // Work around lack of stream wrapper support in imagejpeg() and imagepng().\n if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {\n // If destination is not local, save image to temporary local file.\n $local_wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL);\n if (!isset($local_wrappers[$scheme])) {\n $permanent_destination = $destination;\n $destination = drupal_tempnam('temporary://', 'gd_');\n }\n // Convert stream wrapper URI to normal path.\n $destination = drupal_realpath($destination);\n }\n\n $extension = str_replace('jpg', 'jpeg', $image->info['extension']);\n $function = 'image' . $extension;\n if (!function_exists($function)) {\n return FALSE;\n }\n if ($extension == 'jpeg') {\n $success = $function($image->resource, $destination, variable_get('image_jpeg_quality', 75));\n }\n else {\n // Always save PNG images with full transparency.\n if ($extension == 'png') {\n imagealphablending($image->resource, FALSE);\n imagesavealpha($image->resource, TRUE);\n }\n $success = $function($image->resource, $destination);\n }\n // Move temporary local file to remote destination.\n if (isset($permanent_destination) && $success) {\n return (bool) file_unmanaged_move($destination, $permanent_destination, FILE_EXISTS_REPLACE);\n }\n return $success;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f67de9a30e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_html_to_text/7.x", "instruction": "I need the code for `drupal_html_to_text($string, $allowed_tags = NULL)` in Drupal 7 (includes/mail.inc). It must do this: Transforms an HTML string into plain text, preserving its structure.", "context": "The output will be suitable for use as 'format=flowed; delsp=yes' text (RFC 3676) and can be passed directly to drupal_mail() for sending.\n\nWe deliberately use LF rather than CRLF, see drupal_mail().\n\nThis function provides suitable alternatives for the following tags:


                1. \n\nParameters:\n- $string: The string to be transformed.\n- $allowed_tags: (optional) If supplied, a list of tags that will be transformed. If omitted, all all supported tags are transformed.\n\nReturns: The transformed string.\n\nFile: includes/mail.inc", "response": "function drupal_html_to_text($string, $allowed_tags = NULL) {\n // Cache list of supported tags.\n static $supported_tags;\n if (empty($supported_tags)) {\n $supported_tags = array('a', 'em', 'i', 'strong', 'b', 'br', 'p', 'blockquote', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr');\n }\n\n // Make sure only supported tags are kept.\n $allowed_tags = isset($allowed_tags) ? array_intersect($supported_tags, $allowed_tags) : $supported_tags;\n\n // Make sure tags, entities and attributes are well-formed and properly nested.\n $string = _filter_htmlcorrector(filter_xss($string, $allowed_tags));\n\n // Apply inline styles.\n $string = preg_replace('! +)[^>]*)?>!i', '/', $string);\n $string = preg_replace('! +)[^>]*)?>!i', '*', $string);\n\n // Replace inline
                  tags with the text of link and a footnote.\n // 'See the Drupal site' becomes\n // 'See the Drupal site [1]' with the URL included as a footnote.\n _drupal_html_to_mail_urls(NULL, TRUE);\n $pattern = '@(]+?href=\"([^\"]*)\"[^>]*?>(.+?))@i';\n $string = preg_replace_callback($pattern, '_drupal_html_to_mail_urls', $string);\n $urls = _drupal_html_to_mail_urls();\n $footnotes = '';\n if (count($urls)) {\n $footnotes .= \"\\n\";\n for ($i = 0, $max = count($urls); $i < $max; $i++) {\n $footnotes .= '[' . ($i + 1) . '] ' . $urls[$i] . \"\\n\";\n }\n }\n\n // Split tags from text.\n $split = preg_split('/<([^>]+?)>/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);\n // Note: PHP ensures the array consists of alternating delimiters and literals\n // and begins and ends with a literal (inserting $null as required).\n\n $tag = FALSE; // Odd/even counter (tag or no tag)\n $casing = NULL; // Case conversion function\n $output = '';\n $indent = array(); // All current indentation string chunks\n $lists = array(); // Array of counters for opened lists\n foreach ($split as $value) {\n $chunk = NULL; // Holds a string ready to be formatted and output.\n\n // Process HTML tags (but don't output any literally).\n if ($tag) {\n list($tagname) = explode(' ', strtolower($value), 2);\n switch ($tagname) {\n // List counters\n case 'ul':\n array_unshift($lists, '*');\n break;\n case 'ol':\n array_unshift($lists, 1);\n break;\n case '/ul':\n case '/ol':\n array_shift($lists);\n $chunk = ''; // Ensure blank new-line.\n break;\n\n // Quotation/list markers, non-fancy headers\n case 'blockquote':\n // Format=flowed indentation cannot be mixed with lists.\n $indent[] = count($lists) ? ' \"' : '>';\n break;\n case 'li':\n $indent[] = isset($lists[0]) && is_numeric($lists[0]) ? ' ' . $lists[0]++ . ') ' : ' * ';\n break;\n case 'dd':\n $indent[] = ' ';\n break;\n case 'h3':\n $indent[] = '.... ';\n break;\n case 'h4':\n $indent[] = '.. ';\n break;\n case '/blockquote':\n if (count($lists)) {\n // Append closing quote for inline quotes (immediately).\n $output = rtrim($output, \"> \\n\") . \"\\\"\\n\";\n $chunk = ''; // Ensure blank new-line.\n }\n // Fall-through\n case '/li':\n case '/dd':\n array_pop($indent);\n break;\n case '/h3':\n case '/h4':\n array_pop($indent);\n case '/h5':\n case '/h6':\n $chunk = ''; // Ensure blank new-line.\n break;\n\n // Fancy headers\n case 'h1':\n $indent[] = '======== ';\n $casing = 'drupal_strtoupper';\n break;\n case 'h2':\n $indent[] = '-------- ';\n $casing = 'drupal_strtoupper';\n break;\n case '/h1':\n case '/h2':\n $casing = NULL;\n // Pad the line with dashes.\n $output = _drupal_html_to_text_pad($output, ($tagname == '/h1') ? '=' : '-', ' ');\n array_pop($indent);\n $chunk = ''; // Ensure blank new-line.\n break;\n\n // Horizontal rulers\n case 'hr':\n // Insert immediately.\n $output .= drupal_wrap_mail('', implode('', $indent)) . \"\\n\";\n $output = _drupal_html_to_text_pad($output, '-');\n break;\n\n // Paragraphs and definition lists\n case '/p':\n case '/dl':\n $chunk = ''; // Ensure blank new-line.\n break;\n }\n }\n // Process blocks of text.\n else {\n // Convert inline HTML text to plain text; not removing line-breaks or\n // white-space, since that breaks newlines when sanitizing plain-text.\n $value = trim(decode_entities($value));\n if (drupal_strlen($value)) {\n $chunk = $value;\n }\n }\n\n // See if there is something waiting to be output.\n if (isset($chunk)) {\n // Apply any necessary case conversion.\n if (isset($casing)) {\n $chunk = $casing($chunk);\n }\n // Format it and apply the current indentation.\n $output .= drupal_wrap_mail($chunk, implode('', $indent)) . MAIL_LINE_ENDINGS;\n // Remove non-quotation markers from indentation.\n $indent = array_map('_drupal_html_to_text_clean', $indent);\n }\n\n $tag = !$tag;\n }\n\n return $output . $footnotes;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f6948ec6ba", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_block_info/7.x", "instruction": "In Drupal 7, write the function `comment_block_info()` (file modules/comment/comment.module) so that it does the following: Implements hook_block_info().", "context": "File: modules/comment/comment.module", "response": "function comment_block_info() {\n $blocks['recent']['info'] = t('Recent comments');\n $blocks['recent']['properties']['administrative'] = TRUE;\n\n return $blocks;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f6a2f7ac0f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_links_clone/7.x", "instruction": "I need the code for `menu_links_clone($links, $menu_name = NULL)` in Drupal 7 (includes/menu.inc). It must do this: Clones an array of menu links.", "context": "Parameters:\n- $links: An array of menu links to clone.\n- $menu_name: (optional) The name of a menu that the links will be cloned for. If not set, the cloned links will be in the same menu as the original set of links that were passed in.\n\nReturns: An array of menu links with the same properties as the passed-in array, but with the link identifiers removed so that a new link will be created when any of them is passed in to menu_link_save().\n\nFile: includes/menu.inc", "response": "function menu_links_clone($links, $menu_name = NULL) {\n foreach ($links as &$link) {\n unset($link['mlid']);\n unset($link['plid']);\n if (isset($menu_name)) {\n $link['menu_name'] = $menu_name;\n }\n }\n return $links;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f6df349cd4", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_date_format_save/7.x", "instruction": "In Drupal 7, write the function `system_date_format_save($date_format, $dfid = 0)` (file modules/system/system.module) so that it does the following: Saves a date format to the database.", "context": "Parameters:\n- $date_format: A date format array containing the following keys: - type: The name of the date type this format is associated with. - format: The PHP date format string. - locked: A boolean indicating whether or not this format should be configurable from the user interface.\n- $dfid: If set, replace the existing date format having this ID with the information specified in $date_format.\n\nFile: modules/system/system.module", "response": "function system_date_format_save($date_format, $dfid = 0) {\n $info = array();\n $info['dfid'] = $dfid;\n $info['type'] = $date_format['type'];\n $info['format'] = $date_format['format'];\n $info['locked'] = $date_format['locked'];\n\n // Update date_format table.\n if (!empty($date_format['is_new'])) {\n drupal_write_record('date_formats', $info);\n }\n else {\n $keys = ($dfid ? array('dfid') : array('format', 'type'));\n drupal_write_record('date_formats', $info, $keys);\n }\n\n // Retrieve an array of language objects for enabled languages.\n $languages = language_list('enabled');\n // This list is keyed off the value of $language->enabled; we want the ones\n // that are enabled (value of 1).\n $languages = $languages[1];\n\n $locale_format = array();\n $locale_format['type'] = $date_format['type'];\n $locale_format['format'] = $date_format['format'];\n\n // Check if the suggested language codes are configured and enabled.\n if (!empty($date_format['locales'])) {\n foreach ($date_format['locales'] as $langcode) {\n // Only proceed if language is enabled.\n if (isset($languages[$langcode])) {\n $is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE type = :type AND language = :language', 0, 1, array(':type' => $date_format['type'], ':language' => $langcode))->fetchField();\n if (!$is_existing) {\n $locale_format['language'] = $langcode;\n drupal_write_record('date_format_locale', $locale_format);\n }\n }\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f6e2c34230", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21update%21update.authorize.inc/function/update_authorize_run_update/7.x", "instruction": "In Drupal 7, write the function `update_authorize_run_update($filetransfer, $projects)` (file modules/update/update.authorize.inc) so that it does the following: Updates existing projects when invoked by authorize.php.", "context": "Callback for system_authorized_init() in update_manager_update_ready_form_submit().\n\nParameters:\n- $filetransfer: The FileTransfer object created by authorize.php for use during this operation.\n- $projects: A nested array of projects to install into the live webroot, keyed by project name. Each subarray contains the following keys: - project: The canonical project short name. - updater_name: The name of the Updater class to use for this project. - local_url: The locally installed location of new code to update with.\n\nFile: modules/update/update.authorize.inc", "response": "function update_authorize_run_update($filetransfer, $projects) {\n $operations = array();\n foreach ($projects as $project => $project_info) {\n $operations[] = array(\n 'update_authorize_batch_copy_project',\n array(\n $project_info['project'],\n $project_info['updater_name'],\n $project_info['local_url'],\n $filetransfer,\n ),\n );\n }\n\n $batch = array(\n 'title' => t('Installing updates'),\n 'init_message' => t('Preparing to update your site'),\n 'operations' => $operations,\n 'finished' => 'update_authorize_update_batch_finished',\n 'file' => drupal_get_path('module', 'update') . '/update.authorize.inc',\n );\n\n batch_set($batch);\n // Invoke the batch via authorize.php.\n system_authorized_batch_process();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7088cca6c", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_delete_field/7.x", "instruction": "Give me the example code for `hook_field_storage_delete_field($field)` in Drupal 7. Hook description: Act on deletion of a field.", "context": "This hook is invoked from field_delete_field() to ask the field storage module to mark all information stored in the field for deletion.\n\nParameters:\n- $field: The field being deleted.\n\nFile: modules/field/field.api.php", "response": "function hook_field_storage_delete_field($field) {\n // Mark all data associated with the field for deletion.\n $field['deleted'] = 0;\n $table = _field_sql_storage_tablename($field);\n $revision_table = _field_sql_storage_revision_tablename($field);\n db_update($table)\n ->fields(array('deleted' => 1))\n ->execute();\n\n // Move the table to a unique name while the table contents are being deleted.\n $field['deleted'] = 1;\n $new_table = _field_sql_storage_tablename($field);\n $revision_new_table = _field_sql_storage_revision_tablename($field);\n db_rename_table($table, $new_table);\n db_rename_table($revision_table, $revision_new_table);\n drupal_get_schema(NULL, TRUE);\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f70b4a6ab9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_alter/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_menu_alter(&$items)` (modules/system/system.api.php): Alter the data being saved to the {menu_router} table after hook_menu is invoked.", "context": "This hook is invoked by menu_router_build(). The menu definitions are passed in by reference. Each element of the $items array is one item returned by a module from hook_menu. Additional items may be added, or existing items altered.\n\nParameters:\n- $items: Associative array of menu router definitions returned from hook_menu().\n\nFile: modules/system/system.api.php", "response": "function hook_menu_alter(&$items) {\n // Example - disable the page at node/add\n $items['node/add']['access callback'] = FALSE;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f70bafc803", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_menu_subtree_data/7.x", "instruction": "I need the code for `book_menu_subtree_data($link)` in Drupal 7 (modules/book/book.module). It must do this: Gets the data representing a subtree of the book hierarchy.", "context": "The root of the subtree will be the link passed as a parameter, so the returned tree will contain this item and all its descendents in the menu tree.\n\nParameters:\n- $link: A fully loaded menu link.\n\nReturns: A subtree of menu links in an array, in the order they should be rendered.\n\nFile: modules/book/book.module", "response": "function book_menu_subtree_data($link) {\n $tree = &drupal_static(__FUNCTION__, array());\n\n // Generate a cache ID (cid) specific for this $menu_name and $link.\n $cid = 'links:' . $link['menu_name'] . ':subtree-cid:' . $link['mlid'];\n\n if (!isset($tree[$cid])) {\n $cache = cache_get($cid, 'cache_menu');\n\n if ($cache && isset($cache->data)) {\n // If the cache entry exists, it will just be the cid for the actual data.\n // This avoids duplication of large amounts of data.\n $cache = cache_get($cache->data, 'cache_menu');\n\n if ($cache && isset($cache->data)) {\n $data = $cache->data;\n }\n }\n\n // If the subtree data was not in the cache, $data will be NULL.\n if (!isset($data)) {\n $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));\n $query->join('menu_router', 'm', 'm.path = ml.router_path');\n $query->join('book', 'b', 'ml.mlid = b.mlid');\n $query->fields('b');\n $query->fields('m', array('load_functions', 'to_arg_functions', 'access_callback', 'access_arguments', 'page_callback', 'page_arguments', 'delivery_callback', 'title', 'title_callback', 'title_arguments', 'type'));\n $query->fields('ml');\n $query->condition('menu_name', $link['menu_name']);\n for ($i = 1; $i <= MENU_MAX_DEPTH && $link[\"p$i\"]; ++$i) {\n $query->condition(\"p$i\", $link[\"p$i\"]);\n }\n for ($i = 1; $i <= MENU_MAX_DEPTH; ++$i) {\n $query->orderBy(\"p$i\");\n }\n $links = array();\n foreach ($query->execute() as $item) {\n $links[] = $item;\n }\n $data['tree'] = menu_tree_data($links, array(), $link['depth']);\n $data['node_links'] = array();\n menu_tree_collect_node_links($data['tree'], $data['node_links']);\n // Compute the real cid for book subtree data.\n $tree_cid = 'links:' . $item['menu_name'] . ':subtree-data:' . hash('sha256', serialize($data));\n // Cache the data, if it is not already in the cache.\n\n if (!cache_get($tree_cid, 'cache_menu')) {\n cache_set($tree_cid, $data, 'cache_menu');\n }\n // Cache the cid of the (shared) data using the menu and item-specific cid.\n cache_set($cid, $tree_cid, 'cache_menu');\n }\n // Check access for the current user to each item in the tree.\n menu_tree_check_access($data['tree'], $data['node_links']);\n $tree[$cid] = $data['tree'];\n }\n\n return $tree[$cid];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f70d2bc999", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_form_build_preview/7.x", "instruction": "Implement `node_form_build_preview($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for node_form().", "context": "Handles the 'Preview' button on the node form.\n\nFile: modules/node/node.pages.inc", "response": "function node_form_build_preview($form, &$form_state) {\n $node = node_form_submit_build_node($form, $form_state);\n $form_state['node_preview'] = node_preview($node);\n $form_state['rebuild'] = TRUE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f70f24e221", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/_overlay_region_list/7.x", "instruction": "In Drupal 7, write the function `_overlay_region_list($type)` (file modules/overlay/overlay.module) so that it does the following: Returns a list of page regions related to the overlay.", "context": "Parameters:\n- $type: The type of regions to return. This can either be 'overlay_regions' or 'overlay_supplemental_regions'.\n\nReturns: An array of region names of the given type, within the theme that is being used to display the current page.\n\nFile: modules/overlay/overlay.module", "response": "function _overlay_region_list($type) {\n // Obtain the current theme. We need to first make sure the theme system is\n // initialized, since this function can be called early in the page request.\n drupal_theme_initialize();\n $themes = list_themes();\n $theme = $themes[$GLOBALS['theme']];\n // Return the list of regions stored within the theme's info array, or an\n // empty array if no regions of the appropriate type are defined.\n return !empty($theme->info[$type]) ? $theme->info[$type] : array();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7187d0224", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_unpublish_action/7.x", "instruction": "I need the code for `comment_unpublish_action($comment, $context = array())` in Drupal 7 (modules/comment/comment.module). It must do this: Unpublishes a comment.", "context": "Parameters:\n- $comment: An optional comment object.\n- $context (array): Array with components: - 'cid': Comment ID. Required if $comment is not given.\n\nFile: modules/comment/comment.module", "response": "function comment_unpublish_action($comment, $context = array()) {\n if (isset($comment->subject)) {\n $subject = $comment->subject;\n $comment->status = COMMENT_NOT_PUBLISHED;\n }\n else {\n $cid = $context['cid'];\n $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();\n db_update('comment')\n ->fields(array('status' => COMMENT_NOT_PUBLISHED))\n ->condition('cid', $cid)\n ->execute();\n }\n watchdog('action', 'Unpublished comment %subject.', array('%subject' => $subject));\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f739acd020", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21actions.inc/function/actions_list/7.x", "instruction": "Implement `actions_list($reset = FALSE)` in PHP for Drupal 7. Required behavior: Discovers all available actions by invoking hook_action_info().", "context": "This function contrasts with actions_get_all_actions(); see the documentation of actions_get_all_actions() for an explanation.\n\nParameters:\n- $reset: Reset the action info static cache.\n\nReturns: An associative array keyed on action function name, with the same format as the return value of hook_action_info(), containing all modules' hook_action_info() return values as modified by any hook_action_info_alter() implementations.\n\nFile: includes/actions.inc", "response": "function actions_list($reset = FALSE) {\n $actions = &drupal_static(__FUNCTION__);\n if (!isset($actions) || $reset) {\n $actions = module_invoke_all('action_info');\n drupal_alter('action_info', $actions);\n }\n\n // See module_implements() for an explanation of this cast.\n return (array) $actions;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f746766017", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_path_token/7.x", "instruction": "Implement `image_style_path_token($style_name, $uri)` in PHP for Drupal 7. Required behavior: Generates a token to protect an image style derivative.", "context": "This prevents unauthorized generation of an image style derivative, which can be costly both in CPU time and disk space.\n\nParameters:\n- $style_name: The name of the image style.\n- $uri: The URI of the image for this style, for example as returned by image_style_path().\n\nReturns: An eight-character token which can be used to protect image style derivatives against denial-of-service attacks.\n\nFile: modules/image/image.module", "response": "function image_style_path_token($style_name, $uri) {\n // Return the first eight characters.\n return substr(drupal_hmac_base64($style_name . ':' . $uri, drupal_get_private_key() . drupal_get_hash_salt()), 0, 8);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7494ff4f7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.install/function/shortcut_install/7.x", "instruction": "In Drupal 7, write the function `shortcut_install()` (file modules/shortcut/shortcut.install) so that it does the following: Implements hook_install().", "context": "File: modules/shortcut/shortcut.install", "response": "function shortcut_install() {\n $t = get_t();\n // Create an initial default shortcut set.\n $shortcut_set = new stdClass();\n $shortcut_set->title = $t('Default');\n $shortcut_set->links = array(\n array(\n 'link_path' => 'node/add',\n 'link_title' => $t('Add content'),\n 'weight' => -20,\n ),\n array(\n 'link_path' => 'admin/content',\n 'link_title' => $t('Find content'),\n 'weight' => -19,\n ),\n );\n // If Drupal is being installed, rebuild the menu before saving the shortcut\n // set, to make sure the links defined above can be correctly saved. (During\n // installation, the menu might not have been built at all yet, or it might\n // have been built but without the node module's links in it.)\n if (drupal_installation_attempted()) {\n menu_rebuild();\n }\n shortcut_set_save($shortcut_set);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f75871286e", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_html_head_alter/7.x", "instruction": "Give me the example code for `hook_html_head_alter(&$head_elements)` in Drupal 7. Hook description: Alter XHTML HEAD tags before they are rendered by drupal_get_html_head().", "context": "Elements available to be altered are only those added using drupal_add_html_head_link() or drupal_add_html_head(). CSS and JS files are handled using drupal_add_css() and drupal_add_js(), so the head links for those files will not appear in the $head_elements array.\n\nParameters:\n- $head_elements: An array of renderable elements. Generally the values of the #attributes array will be the most likely target for changes.\n\nFile: modules/system/system.api.php", "response": "function hook_html_head_alter(&$head_elements) {\n foreach ($head_elements as $key => $element) {\n if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {\n // I want a custom canonical URL.\n $head_elements[$key]['#attributes']['href'] = mymodule_canonical_url();\n }\n }\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f779b7f016", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_validate_current_pass/7.x", "instruction": "In Drupal 7, write the function `user_validate_current_pass(&$form, &$form_state)` (file modules/user/user.module) so that it does the following: Form validation handler for the current password on the user_account_form().", "context": "File: modules/user/user.module", "response": "function user_validate_current_pass(&$form, &$form_state) {\n $account = $form['#user'];\n foreach ($form_state['values']['current_pass_required_values'] as $key => $name) {\n // This validation only works for required textfields (like mail) or\n // form values like password_confirm that have their own validation\n // that prevent them from being empty if they are changed.\n if ((strlen(trim($form_state['values'][$key])) > 0) && ($form_state['values'][$key] != $account->$key)) {\n require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');\n $current_pass_failed = strlen(trim($form_state['values']['current_pass'])) == 0 || !user_check_password($form_state['values']['current_pass'], $account);\n if ($current_pass_failed) {\n form_set_error('current_pass', t(\"Your current password is missing or incorrect; it's required to change the %name.\", array('%name' => $name)));\n form_set_error($key);\n }\n // We only need to check the password once.\n break;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f79203c511", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21path.inc/function/path_save/7.x", "instruction": "In Drupal 7, write the function `path_save(&$path)` (file includes/path.inc) so that it does the following: Save a path alias to the database.", "context": "Parameters:\n- $path: An associative array containing the following keys: - source: The internal system path. - alias: The URL alias. - pid: (optional) Unique path alias identifier. - language: (optional) The language of the alias.\n\nFile: includes/path.inc", "response": "function path_save(&$path) {\n $path += array('language' => LANGUAGE_NONE);\n\n // Load the stored alias, if any.\n if (!empty($path['pid']) && !isset($path['original'])) {\n $path['original'] = path_load($path['pid']);\n }\n\n if (empty($path['pid'])) {\n drupal_write_record('url_alias', $path);\n module_invoke_all('path_insert', $path);\n }\n else {\n drupal_write_record('url_alias', $path, array('pid'));\n module_invoke_all('path_update', $path);\n }\n\n // Clear internal properties.\n unset($path['original']);\n\n // Clear the static alias cache.\n drupal_clear_path_cache($path['source']);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7a1aa2b30", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21batch.inc/function/_batch_process/7.x", "instruction": "In Drupal 7, write the function `_batch_process()` (file includes/batch.inc) so that it does the following: Processes sets in a batch.", "context": "If the batch was marked for progressive execution (default), this executes as many operations in batch sets until an execution time of 1 second has been exceeded. It will continue with the next operation of the same batch set in the next request.\n\nReturns: An array containing a completion value (in percent) and a status message.\n\nFile: includes/batch.inc", "response": "function _batch_process() {\n $batch = &batch_get();\n $current_set = &_batch_current_set();\n // Indicate that this batch set needs to be initialized.\n $set_changed = TRUE;\n\n // If this batch was marked for progressive execution (e.g. forms submitted by\n // drupal_form_submit()), initialize a timer to determine whether we need to\n // proceed with the same batch phase when a processing time of 1 second has\n // been exceeded.\n if ($batch['progressive']) {\n timer_start('batch_processing');\n }\n\n if (empty($current_set['start'])) {\n $current_set['start'] = microtime(TRUE);\n }\n\n $queue = _batch_queue($current_set);\n\n while (!$current_set['success']) {\n // If this is the first time we iterate this batch set in the current\n // request, we check if it requires an additional file for functions\n // definitions.\n if ($set_changed && isset($current_set['file']) && is_file($current_set['file'])) {\n include_once DRUPAL_ROOT . '/' . $current_set['file'];\n }\n\n $task_message = '';\n // Assume a single pass operation and set the completion level to 1 by\n // default.\n $finished = 1;\n\n if ($item = $queue->claimItem()) {\n list($function, $args) = $item->data;\n\n // Build the 'context' array and execute the function call.\n $batch_context = array(\n 'sandbox' => &$current_set['sandbox'],\n 'results' => &$current_set['results'],\n 'finished' => &$finished,\n 'message' => &$task_message,\n );\n call_user_func_array($function, array_merge($args, array(&$batch_context)));\n\n if ($finished >= 1) {\n // Make sure this step is not counted twice when computing $current.\n $finished = 0;\n // Remove the processed operation and clear the sandbox.\n $queue->deleteItem($item);\n $current_set['count']--;\n $current_set['sandbox'] = array();\n }\n }\n\n // When all operations in the current batch set are completed, browse\n // through the remaining sets, marking them 'successfully processed'\n // along the way, until we find a set that contains operations.\n // _batch_next_set() executes form submit handlers stored in 'control'\n // sets (see form_execute_handlers()), which can in turn add new sets to\n // the batch.\n $set_changed = FALSE;\n $old_set = $current_set;\n while (empty($current_set['count']) && ($current_set['success'] = TRUE) && _batch_next_set()) {\n $current_set = &_batch_current_set();\n $current_set['start'] = microtime(TRUE);\n $set_changed = TRUE;\n }\n\n // At this point, either $current_set contains operations that need to be\n // processed or all sets have been completed.\n $queue = _batch_queue($current_set);\n\n // If we are in progressive mode, break processing after 1 second.\n if ($batch['progressive'] && timer_read('batch_processing') > 1000) {\n // Record elapsed wall clock time.\n $current_set['elapsed'] = round((microtime(TRUE) - $current_set['start']) * 1000, 2);\n break;\n }\n }\n\n if ($batch['progressive']) {\n // Gather progress information.\n\n // Reporting 100% progress will cause the whole batch to be considered\n // processed. If processing was paused right after moving to a new set,\n // we have to use the info from the new (unprocessed) set.\n if ($set_changed && isset($current_set['queue'])) {\n // Processing will continue with a fresh batch set.\n $remaining = $current_set['count'];\n $total = $current_set['total'];\n $progress_message = $current_set['init_message'];\n $task_message = '';\n }\n else {\n // Processing will continue with the current batch set.\n $remaining = $old_set['count'];\n $total = $old_set['total'];\n $progress_message = $old_set['progress_message'];\n }\n\n // Total progress is the number of operations that have fully run plus the\n // completion level of the current operation.\n $current = $total - $remaining + $finished;\n $percentage = _batch_api_percentage($total, $current);\n $elapsed = isset($current_set['elapsed']) ? $current_set['elapsed'] : 0;\n $values = array(\n '@remaining' => $remaining,\n '@total' => $total,\n '@current' => floor($current),\n '@percentage' => $percentage,\n '@elapsed' => format_interval($elapsed / 1000),\n // If possible, estimate remaining processing time.\n '@estimate' => ($current > 0) ? format_interval(($elapsed * ($total - $current) / $current) / 1000) : '-',\n );\n $message = strtr($progress_message, $values);\n if (!empty($message)) {\n $message .= '
                  ';\n }\n if (!empty($task_message)) {\n $message .= $task_message;\n }\n\n return array($percentage, $message);\n }\n else {\n // If we are not in progressive mode, the entire batch has been processed.\n return _batch_finished();\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7af53b266", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_add_http_header/7.x", "instruction": "Implement `drupal_add_http_header($name, $value, $append = FALSE)` in PHP for Drupal 7. Required behavior: Sets an HTTP response header for the current page.", "context": "Note: When sending a Content-Type header, always include a 'charset' type, too. This is necessary to avoid security bugs (e.g. UTF-7 XSS).\n\nParameters:\n- $name: The HTTP header name, or the special 'Status' header name.\n- $value: The HTTP header value; if equal to FALSE, the specified header is unset. If $name is 'Status', this is expected to be a status code followed by a reason phrase, e.g. \"404 Not Found\".\n- $append: Whether to append the value to an existing header or to replace it.\n\nFile: includes/bootstrap.inc", "response": "function drupal_add_http_header($name, $value, $append = FALSE) {\n // The headers as name/value pairs.\n $headers = &drupal_static('drupal_http_headers', array());\n\n $name_lower = strtolower($name);\n _drupal_set_preferred_header_name($name);\n\n if ($value === FALSE) {\n $headers[$name_lower] = FALSE;\n }\n elseif (isset($headers[$name_lower]) && $append) {\n // Multiple headers with identical names may be combined using comma (RFC\n // 2616, section 4.2).\n $headers[$name_lower] .= ',' . $value;\n }\n else {\n $headers[$name_lower] = $value;\n }\n drupal_send_headers(array($name => $headers[$name_lower]), TRUE);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7cfcd8d08", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21module.inc/function/module_hook/7.x", "instruction": "In Drupal 7, write the function `module_hook($module, $hook)` (file includes/module.inc) so that it does the following: Determines whether a module implements a hook.", "context": "Parameters:\n- $module: The name of the module (without the .module extension).\n- $hook: The name of the hook (e.g. \"help\" or \"menu\").\n\nReturns: TRUE if the module is both installed and enabled, and the hook is implemented in that module.\n\nFile: includes/module.inc", "response": "function module_hook($module, $hook) {\n $function = $module . '_' . $hook;\n if (function_exists($function)) {\n return TRUE;\n }\n // If the hook implementation does not exist, check whether it may live in an\n // optional include file registered via hook_hook_info().\n $hook_info = module_hook_info();\n if (isset($hook_info[$hook]['group'])) {\n module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);\n if (function_exists($function)) {\n return TRUE;\n }\n }\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7d959c2a7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_get_display_page/7.x", "instruction": "Implement `comment_get_display_page($cid, $node_type)` in PHP for Drupal 7. Required behavior: Return the page number for a comment.", "context": "Finds the correct page number for a comment taking into account display and paging settings.\n\nParameters:\n- $cid: The comment ID.\n- $node_type: The node type the comment is attached to.\n\nReturns: The page number.\n\nFile: modules/comment/comment.module", "response": "function comment_get_display_page($cid, $node_type) {\n $ordinal = comment_get_display_ordinal($cid, $node_type);\n $comments_per_page = variable_get('comment_default_per_page_' . $node_type, 50);\n return floor($ordinal / $comments_per_page);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7d9f7ebf5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_insert/7.x", "instruction": "I need the code for `db_insert($table, array $options = array())` in Drupal 7 (includes/database/database.inc). It must do this: Returns a new InsertQuery object for the active database.", "context": "Parameters:\n- $table: The table into which to insert.\n- $options: An array of options to control how the query operates.\n\nReturns: InsertQuery A new InsertQuery object for this connection.\n\nFile: includes/database/database.inc", "response": "function db_insert($table, array $options = array()) {\n if (empty($options['target']) || $options['target'] == 'slave') {\n $options['target'] = 'default';\n }\n return Database::getConnection($options['target'])->insert($table, $options);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f7fb3688c9", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_update_files_database/7.x", "instruction": "In Drupal 7, write the function `system_update_files_database(&$files, $type)` (file modules/system/system.module) so that it does the following: Updates the records in the system table based on the files array.", "context": "Parameters:\n- $files: An array of files.\n- $type: The type of the files.\n\nFile: modules/system/system.module", "response": "function system_update_files_database(&$files, $type) {\n $result = db_query(\"SELECT * FROM {system} WHERE type = :type\", array(':type' => $type));\n\n // Add all files that need to be deleted to a DatabaseCondition.\n $delete = db_or();\n foreach ($result as $file) {\n if (isset($files[$file->name]) && is_object($files[$file->name])) {\n // Keep the old filename from the database in case the file has moved.\n $old_filename = $file->filename;\n\n $updated_fields = array();\n\n // Handle info specially, compare the serialized value.\n $serialized_info = serialize($files[$file->name]->info);\n if ($serialized_info != $file->info) {\n $updated_fields['info'] = $serialized_info;\n }\n unset($file->info);\n\n // Scan remaining fields to find only the updated values.\n foreach ($file as $key => $value) {\n if (isset($files[$file->name]->$key) && $files[$file->name]->$key != $value) {\n $updated_fields[$key] = $files[$file->name]->$key;\n }\n }\n\n // Update the record.\n if (count($updated_fields)) {\n db_update('system')\n ->fields($updated_fields)\n ->condition('filename', $old_filename)\n ->execute();\n }\n\n // Indicate that the file exists already.\n $files[$file->name]->exists = TRUE;\n }\n else {\n // File is not found in file system, so delete record from the system table.\n $delete->condition('filename', $file->filename);\n }\n }\n\n if (count($delete) > 0) {\n // Delete all missing files from the system table, but only if the plugin\n // has never been installed.\n db_delete('system')\n ->condition($delete)\n ->condition('schema_version', -1)\n ->execute();\n }\n\n // All remaining files are not in the system table, so we need to add them.\n $query = db_insert('system')->fields(array('filename', 'name', 'type', 'owner', 'info'));\n foreach ($files as &$file) {\n if (isset($file->exists)) {\n unset($file->exists);\n }\n else {\n $query->values(array(\n 'filename' => $file->uri,\n 'name' => $file->name,\n 'type' => $type,\n 'owner' => isset($file->owner) ? $file->owner : '',\n 'info' => serialize($file->info),\n ));\n $file->type = $type;\n $file->status = 0;\n $file->schema_version = -1;\n }\n }\n $query->execute();\n\n // If any module or theme was moved to a new location, we need to reset the\n // system_list() cache or we will continue to load the old copy, look for\n // schema updates in the wrong place, etc.\n system_list_reset();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f809eb26f2", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_trigger_fatal_error/7.x", "instruction": "I need the code for `drupal_trigger_fatal_error($error_msg)` in Drupal 7 (includes/bootstrap.inc). It must do this: Invoke trigger_error() using a fatal error that will terminate the request.", "context": "Normally, Drupal's error handler does not terminate script execution on user-level errors, even if the error is of type E_USER_ERROR. This function triggers an error of type E_USER_ERROR that is explicitly forced to be a fatal error which terminates script execution.\n\nParameters:\n- $error_msg (string): The error message to trigger. As with trigger_error() itself, this is limited to 1024 bytes; additional characters beyond that will be removed.\n\nFile: includes/bootstrap.inc", "response": "function drupal_trigger_fatal_error($error_msg) {\n $fatal_error = &drupal_static(__FUNCTION__, FALSE);\n $fatal_error = TRUE;\n trigger_error($error_msg, E_USER_ERROR);\n $fatal_error = FALSE;\n // The standard Drupal error handler should have treated this as a fatal\n // error and already ended the page request. But in case another error\n // handler is being used, terminate execution explicitly here also.\n exit;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f818b1600d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_trigger_refresh/7.x", "instruction": "Implement `overlay_trigger_refresh()` in PHP for Drupal 7. Required behavior: Checks if the parent window needs to be refreshed on this page load.", "context": "If the previous page load requested that any page regions be refreshed, or if it requested that the entire page be refreshed when the overlay closes, pass that request via JavaScript to the child window, so it can in turn pass the request to the parent window.\n\nFile: modules/overlay/overlay.module", "response": "function overlay_trigger_refresh() {\n if (!empty($_SESSION['overlay_regions_to_refresh'])) {\n $settings = array(\n 'overlayChild' => array(\n 'refreshRegions' => $_SESSION['overlay_regions_to_refresh'],\n ),\n );\n drupal_add_js($settings, array('type' => 'setting'));\n unset($_SESSION['overlay_regions_to_refresh']);\n }\n if (!empty($_SESSION['overlay_refresh_parent'])) {\n drupal_add_js(array('overlayChild' => array('refreshPage' => TRUE)), array('type' => 'setting'));\n unset($_SESSION['overlay_refresh_parent']);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f81909496a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_load/7.x", "instruction": "In Drupal 7, write the function `contact_load($cid)` (file modules/contact/contact.module) so that it does the following: Loads a contact category.", "context": "Parameters:\n- $cid: The contact category ID.\n\nReturns: An array with the contact category's data.\n\nFile: modules/contact/contact.module", "response": "function contact_load($cid) {\n return db_select('contact', 'c')\n ->addTag('translatable')\n ->fields('c')\n ->condition('cid', $cid)\n ->execute()\n ->fetchAssoc();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f824e14252", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_valid_link/7.x", "instruction": "I need the code for `shortcut_valid_link($path)` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Determines if a path corresponds to a valid shortcut link.", "context": "Parameters:\n- $path: The path to the link.\n\nReturns: TRUE if the shortcut link is valid, FALSE otherwise. Valid links are ones that correspond to actual paths on the site.\n\nFile: modules/shortcut/shortcut.module", "response": "function shortcut_valid_link($path) {\n // Do not use URL aliases.\n $normal_path = drupal_get_normal_path($path);\n if ($path != $normal_path) {\n $path = $normal_path;\n }\n // An empty path is valid too and will be converted to .\n return (!url_is_external($path) && menu_get_item($path)) || empty($path) || $path == '';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f82f45002f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.multilingual.inc/function/field_available_languages/7.x", "instruction": "I need the code for `field_available_languages($entity_type, $field)` in Drupal 7 (modules/field/field.multilingual.inc). It must do this: Collects the available languages for the given entity type and field.", "context": "If the given field has language support enabled, an array of available languages will be returned, otherwise only LANGUAGE_NONE will be returned. Since the default value for a 'translatable' entity property is FALSE, we ensure that only entities that are able to handle translations actually get translatable fields.\n\nParameters:\n- $entity_type: The type of the entity the field is attached to, e.g. 'node' or 'user'.\n- $field: A field structure.\n\nReturns: An array of valid language codes.\n\nFile: modules/field/field.multilingual.inc", "response": "function field_available_languages($entity_type, $field) {\n static $drupal_static_fast;\n if (!isset($drupal_static_fast)) {\n $drupal_static_fast['field_languages'] = &drupal_static(__FUNCTION__);\n }\n $field_languages = &$drupal_static_fast['field_languages'];\n $field_name = $field['field_name'];\n\n if (!isset($field_languages[$entity_type][$field_name])) {\n // If the field has language support enabled we retrieve an (alterable) list\n // of enabled languages, otherwise we return just LANGUAGE_NONE.\n if (field_is_translatable($entity_type, $field)) {\n $languages = field_content_languages();\n // Let other modules alter the available languages.\n $context = array('entity_type' => $entity_type, 'field' => $field);\n drupal_alter('field_available_languages', $languages, $context);\n $field_languages[$entity_type][$field_name] = $languages;\n }\n else {\n $field_languages[$entity_type][$field_name] = array(LANGUAGE_NONE);\n }\n }\n\n return $field_languages[$entity_type][$field_name];\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f838d20675", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_user_cancel/7.x", "instruction": "I need the code for `poll_user_cancel($edit, $account, $method)` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_user_cancel().", "context": "File: modules/poll/poll.module", "response": "function poll_user_cancel($edit, $account, $method) {\n switch ($method) {\n case 'user_cancel_reassign':\n db_update('poll_vote')\n ->fields(array('uid' => 0))\n ->condition('uid', $account->uid)\n ->execute();\n break;\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f8539ff2cc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.module/function/theme_exposed_filters/7.x", "instruction": "In Drupal 7, write the function `theme_exposed_filters($variables)` (file modules/system/system.module) so that it does the following: Returns HTML for an exposed filter form.", "context": "Parameters:\n- $variables: An associative array containing: - form: An associative array containing the structure of the form.\n\nReturns: A string containing an HTML-formatted form.\n\nFile: modules/system/system.module", "response": "function theme_exposed_filters($variables) {\n $form = $variables['form'];\n $output = '';\n\n if (isset($form['current'])) {\n $items = array();\n foreach (element_children($form['current']) as $key) {\n $items[] = drupal_render($form['current'][$key]);\n }\n $output .= theme('item_list', array('items' => $items, 'attributes' => array('class' => array('clearfix', 'current-filters'))));\n }\n\n $output .= drupal_render_children($form);\n\n return '
                  ' . $output . '
                  ';\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f85b9d3eb3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7042/7.x", "instruction": "I need the code for `system_update_7042()` in Drupal 7 (modules/system/system.install). It must do this: Upgrade the {url_alias} table and create a cache bin for path aliases.", "context": "File: modules/system/system.install", "response": "function system_update_7042() {\n // update_fix_d7_requirements() adds 'fake' source and alias columns to\n // allow bootstrap to run without fatal errors. Remove those columns now\n // so that we can rename properly.\n db_drop_field('url_alias', 'source');\n db_drop_field('url_alias', 'alias');\n\n // Drop indexes.\n db_drop_index('url_alias', 'src_language_pid');\n db_drop_unique_key('url_alias', 'dst_language_pid');\n // Rename the fields, and increase their length to 255 characters.\n db_change_field('url_alias', 'src', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));\n db_change_field('url_alias', 'dst', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));\n // Add indexes back. We replace the unique key with an index since it never\n // provided any meaningful unique constraint ('pid' is a primary key).\n db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid'));\n db_add_index('url_alias', 'alias_language_pid', array('alias', 'language', 'pid'));\n\n // Now that the URL aliases are correct, we can rebuild the whitelist.\n drupal_path_alias_whitelist_rebuild();\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f865669056", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_role_grant_permissions/7.x", "instruction": "Implement `user_role_grant_permissions($rid, array $permissions = array())` in PHP for Drupal 7. Required behavior: Grant permissions to a user role.", "context": "Parameters:\n- $rid: The ID of a user role to alter.\n- $permissions: A list of permission names to grant.\n\nFile: modules/user/user.module", "response": "function user_role_grant_permissions($rid, array $permissions = array()) {\n $modules = user_permission_get_modules();\n // Grant new permissions for the role.\n foreach ($permissions as $name) {\n db_merge('role_permission')\n ->key(array(\n 'rid' => $rid,\n 'permission' => $name,\n ))\n ->fields(array(\n 'module' => $modules[$name],\n ))\n ->execute();\n }\n\n // Clear the user access cache.\n drupal_static_reset('user_access');\n drupal_static_reset('user_role_permissions');\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f8bba9aa57", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_redirect_form/7.x", "instruction": "I need the code for `drupal_redirect_form($form_state)` in Drupal 7 (includes/form.inc). It must do this: Redirects the user to a URL after a form has been processed.", "context": "After a form is submitted and processed, normally the user should be redirected to a new destination page. This function figures out what that destination should be, based on the $form_state array and the 'destination' query string in the request URL, and redirects the user there.\n\nUsually (for exceptions, see below) $form_state['redirect'] determines where to redirect the user. This can be set either to a string (the path to redirect to), or an array of arguments for drupal_goto(). If $form_state['redirect'] is missing, the user is usually (again, see below for exceptions) redirected back to the page they came from, where they should see a fresh, unpopulated copy of the form.\n\nHere is an example of how to set up a form to redirect to the path 'node':\n\nParameters:\n- $form_state: An associative array containing the current state of the form.\n\nFile: includes/form.inc", "response": "function drupal_redirect_form($form_state) {\n // Skip redirection for form submissions invoked via drupal_form_submit().\n if (!empty($form_state['programmed'])) {\n return;\n }\n // Skip redirection if rebuild is activated.\n if (!empty($form_state['rebuild'])) {\n return;\n }\n // Skip redirection if it was explicitly disallowed.\n if (!empty($form_state['no_redirect'])) {\n return;\n }\n // Only invoke drupal_goto() if redirect value was not set to FALSE.\n if (!isset($form_state['redirect']) || $form_state['redirect'] !== FALSE) {\n if (isset($form_state['redirect'])) {\n if (is_array($form_state['redirect'])) {\n call_user_func_array('drupal_goto', $form_state['redirect']);\n }\n else {\n // This function can be called from the installer, which guarantees\n // that $redirect will always be a string, so catch that case here\n // and use the appropriate redirect function.\n $function = drupal_installation_attempted() ? 'install_goto' : 'drupal_goto';\n $function($form_state['redirect']);\n }\n }\n drupal_goto(current_path(), array('query' => drupal_get_query_parameters()));\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f8e5447df8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_query_array/7.x", "instruction": "Implement `drupal_get_query_array($query)` in PHP for Drupal 7. Required behavior: Splits a URL-encoded query string into an array.", "context": "Parameters:\n- $query: The query string to split.\n\nReturns: An array of URL decoded couples $param_name => $value.\n\nFile: includes/common.inc", "response": "function drupal_get_query_array($query) {\n $result = array();\n if (!empty($query)) {\n foreach (explode('&', $query) as $param) {\n $param = explode('=', $param, 2);\n $result[$param[0]] = isset($param[1]) ? rawurldecode($param[1]) : '';\n }\n }\n return $result;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f8eb09cfad", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_unpublish_by_keyword_action/7.x", "instruction": "In Drupal 7, write the function `comment_unpublish_by_keyword_action($comment, $context)` (file modules/comment/comment.module) so that it does the following: Unpublishes a comment if it contains certain keywords.", "context": "Parameters:\n- $comment (object): Comment object to modify.\n- $context (array): Array with components: - 'keywords': Keywords to look for. If the comment contains at least one of the keywords, it is unpublished.\n\nFile: modules/comment/comment.module", "response": "function comment_unpublish_by_keyword_action($comment, $context) {\n $node = node_load($comment->nid);\n $build = comment_view($comment, $node);\n $text = drupal_render($build);\n foreach ($context['keywords'] as $keyword) {\n if (strpos($text, $keyword) !== FALSE) {\n $comment->status = COMMENT_NOT_PUBLISHED;\n comment_save($comment);\n watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject));\n break;\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9049d197d", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_get_announcements/7.x", "instruction": "I need the code for `announcements_feed_get_announcements()` in Drupal 7 (modules/announcements_feed/announcements_feed.inc). It must do this: Returns the list of announcements.", "context": "Returns (array): A build array with announcements.\n\nFile: modules/announcements_feed/announcements_feed.inc", "response": "function announcements_feed_get_announcements() {\n drupal_set_title(t('Community announcements'));\n drupal_add_css(drupal_get_path('module', 'announcements_feed')\n . '/announcements_feed.css', array(\n 'group' => CSS_DEFAULT,\n 'every_page' => TRUE,\n ));\n try {\n $announcements = announcements_feed_get_all_announcements();\n }\n catch (Exception $e) {\n drupal_set_message(t('An error occurred while parsing the announcements feed, check the logs for more information.'), 'error');\n return array();\n }\n $build = array();\n foreach ($announcements as $announcement) {\n $key = $announcement['featured'] ? '#featured' : '#standard';\n $build[$key][] = $announcement;\n }\n $build = array_merge($build, array(\n '#theme' => 'announcements_feed',\n '#count' => count($announcements),\n '#feed_link' => variable_get('announcements_feed_link', ANNOUNCEMENTS_FEED_DEFAULT_LINK),\n ));\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f92561c6dc", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_admin_display_form/7.x", "instruction": "Implement `block_admin_display_form($form, &$form_state, $blocks, $theme, $block_regions = NULL)` in PHP for Drupal 7. Required behavior: Form constructor for the main block administration form.", "context": "Parameters:\n- $blocks: An array of blocks, as returned by block_admin_display_prepare_blocks().\n- $theme: A string representing the name of the theme to edit blocks for.\n- $block_regions: (optional) An array of regions in which the blocks will be allowed to be placed. Defaults to all visible regions for the theme whose blocks are being configured. In all cases, a dummy region for disabled blocks will also be displayed.\n\nReturns: An array representing the form definition.\n\nFile: modules/block/block.admin.inc", "response": "function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_regions = NULL) {\n\n $form['#attached']['css'] = array(drupal_get_path('module', 'block') . '/block.css');\n\n // Get a list of block regions if one was not provided.\n if (!isset($block_regions)) {\n $block_regions = system_region_list($theme, REGIONS_VISIBLE);\n }\n\n // Weights range from -delta to +delta, so delta should be at least half\n // of the amount of blocks present. This makes sure all blocks in the same\n // region get an unique weight.\n $weight_delta = round(count($blocks) / 2);\n\n // Build the form tree.\n $form['edited_theme'] = array(\n '#type' => 'value',\n '#value' => $theme,\n );\n $form['block_regions'] = array(\n '#type' => 'value',\n // Add a last region for disabled blocks.\n '#value' => $block_regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE),\n );\n $form['blocks'] = array();\n $form['#tree'] = TRUE;\n\n foreach ($blocks as $i => $block) {\n $key = $block['module'] . '_' . $block['delta'];\n $form['blocks'][$key]['module'] = array(\n '#type' => 'value',\n '#value' => $block['module'],\n );\n $form['blocks'][$key]['delta'] = array(\n '#type' => 'value',\n '#value' => $block['delta'],\n );\n $form['blocks'][$key]['info'] = array(\n '#markup' => check_plain($block['info']),\n );\n $form['blocks'][$key]['theme'] = array(\n '#type' => 'hidden',\n '#value' => $theme,\n );\n $form['blocks'][$key]['weight'] = array(\n '#type' => 'weight',\n '#default_value' => $block['weight'],\n '#delta' => $weight_delta,\n '#title_display' => 'invisible',\n '#title' => t('Weight for @block block', array('@block' => $block['info'])),\n );\n $form['blocks'][$key]['region'] = array(\n '#type' => 'select',\n '#default_value' => $block['region'] != BLOCK_REGION_NONE ? $block['region'] : NULL,\n '#empty_value' => BLOCK_REGION_NONE,\n '#title_display' => 'invisible',\n '#title' => t('Region for @block block', array('@block' => $block['info'])),\n '#options' => $block_regions,\n );\n $form['blocks'][$key]['configure'] = array(\n '#type' => 'link',\n '#title' => t('configure'),\n '#href' => 'admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure',\n );\n if ($block['module'] == 'block') {\n $form['blocks'][$key]['delete'] = array(\n '#type' => 'link',\n '#title' => t('delete'),\n '#href' => 'admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/delete',\n );\n }\n }\n // Do not allow disabling the main system content block when it is present.\n if (isset($form['blocks']['system_main']['region'])) {\n $form['blocks']['system_main']['region']['#required'] = TRUE;\n }\n\n $form['actions'] = array(\n '#tree' => FALSE,\n '#type' => 'actions',\n );\n $form['actions']['submit'] = array(\n '#type' => 'submit',\n '#value' => t('Save blocks'),\n );\n\n return $form;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9272f4cfb", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_permalink/7.x", "instruction": "I need the code for `comment_permalink($cid)` in Drupal 7 (modules/comment/comment.module). It must do this: Redirects comment links to the correct page depending on comment settings.", "context": "Since comments are paged there is no way to guarantee which page a comment appears on. Comment paging and threading settings may be changed at any time. With threaded comments, an individual comment may move between pages as comments can be added either before or after it in the overall discussion. Therefore we use a central routing function for comment links, which calculates the page number based on current comment settings and returns the full comment view with the pager set dynamically.\n\nParameters:\n- $cid: A comment identifier.\n\nReturns: The comment listing set to the page on which the comment appears.\n\nFile: modules/comment/comment.module", "response": "function comment_permalink($cid) {\n if (($comment = comment_load($cid)) && ($node = node_load($comment->nid))) {\n\n // Find the current display page for this comment.\n $page = comment_get_display_page($comment->cid, $node->type);\n\n // Set $_GET['q'] and $_GET['page'] ourselves so that the node callback\n // behaves as it would when visiting the page directly.\n $_GET['q'] = 'node/' . $node->nid;\n $_GET['page'] = $page;\n\n // Return the node view, this will show the correct comment in context.\n return menu_execute_active_handler('node/' . $node->nid, FALSE);\n }\n return MENU_NOT_FOUND;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f930448069", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_dependencies/7.x", "instruction": "Implement `user_update_dependencies()` in PHP for Drupal 7. Required behavior: Implements hook_update_dependencies().", "context": "File: modules/user/user.install", "response": "function user_update_dependencies() {\n // user_update_7006() updates data in the {role_permission} table, so it must\n // run after system_update_7007(), which populates that table.\n $dependencies['user'][7006] = array(\n 'system' => 7007,\n );\n\n // user_update_7010() needs to query the {filter_format} table to get a list\n // of existing text formats, so it must run after filter_update_7000(), which\n // creates that table.\n $dependencies['user'][7010] = array(\n 'filter' => 7000,\n );\n\n // user_update_7012() uses the file API and inserts records into the\n // {file_managed} table, so it therefore must run after system_update_7061(),\n // which inserts files with specific IDs into the table and therefore relies\n // on the table being empty (otherwise it would accidentally overwrite\n // existing records).\n $dependencies['user'][7012] = array(\n 'system' => 7061,\n );\n\n // user_update_7013() uses the file usage API, which relies on the\n // {file_usage} table, so it must run after system_update_7059(), which\n // creates that table.\n $dependencies['user'][7013] = array(\n 'system' => 7059,\n );\n\n return $dependencies;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9305ee793", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_import_locales/7.x", "instruction": "In Drupal 7, write the function `install_import_locales(&$install_state)` (file includes/install.core.inc) so that it does the following: Imports languages via a batch process during installation.", "context": "Parameters:\n- $install_state: An array of information about the current installation state.\n\nReturns: The batch definition, if there are language files to import.\n\nFile: includes/install.core.inc", "response": "function install_import_locales(&$install_state) {\n include_once DRUPAL_ROOT . '/includes/locale.inc';\n $install_locale = $install_state['parameters']['locale'];\n\n include_once DRUPAL_ROOT . '/includes/iso.inc';\n $predefined = _locale_get_predefined_list();\n if (!isset($predefined[$install_locale])) {\n // Drupal does not know about this language, so we prefill its values with\n // our best guess. The user will be able to edit afterwards.\n locale_add_language($install_locale, $install_locale, $install_locale, LANGUAGE_LTR, '', '', TRUE, TRUE);\n }\n else {\n // A known predefined language, details will be filled in properly.\n locale_add_language($install_locale, NULL, NULL, NULL, '', '', TRUE, TRUE);\n }\n\n // Collect files to import for this language.\n $batch = locale_batch_by_language($install_locale, NULL);\n if (!empty($batch)) {\n // Remember components we cover in this batch set.\n variable_set('install_locale_batch_components', $batch['#components']);\n return $batch;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f942aed720", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21block%21block.install/function/block_update_7006/7.x", "instruction": "I need the code for `block_update_7006()` in Drupal 7 (modules/block/block.install). It must do this: Recreates cache_block table.", "context": "Converts fields that hold serialized variables from text to blob. Removes 'headers' column.\n\nFile: modules/block/block.install", "response": "function block_update_7006() {\n $schema = system_schema_cache_7054();\n\n db_drop_table('cache_block');\n db_create_table('cache_block', $schema);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f95fca383f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_send_headers/7.x", "instruction": "Implement `drupal_send_headers($default_headers = array(), $only_default = FALSE)` in PHP for Drupal 7. Required behavior: Sends the HTTP response headers that were previously set, adding defaults.", "context": "Headers are set in drupal_add_http_header(). Default headers are not set if they have been replaced or unset using drupal_add_http_header().\n\nParameters:\n- $default_headers (array): (optional) An array of headers as name/value pairs.\n- $only_default (bool): (optional) If TRUE and headers have already been sent, send only the specified headers.\n\nFile: includes/bootstrap.inc", "response": "function drupal_send_headers($default_headers = array(), $only_default = FALSE) {\n $headers_sent = &drupal_static(__FUNCTION__, FALSE);\n $headers = drupal_get_http_header();\n if ($only_default && $headers_sent) {\n $headers = array();\n }\n $headers_sent = TRUE;\n\n $header_names = _drupal_set_preferred_header_name();\n foreach ($default_headers as $name => $value) {\n $name_lower = strtolower($name);\n if (!isset($headers[$name_lower])) {\n $headers[$name_lower] = $value;\n $header_names[$name_lower] = $name;\n }\n }\n foreach ($headers as $name_lower => $value) {\n if ($name_lower == 'status') {\n header($_SERVER['SERVER_PROTOCOL'] . ' ' . $value);\n }\n // Skip headers that have been unset.\n elseif ($value !== FALSE) {\n header($header_names[$name_lower] . ': ' . $value);\n }\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f967bad34f", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_disable/7.x", "instruction": "I need the code for `theme_disable($theme_list)` in Drupal 7 (includes/theme.inc). It must do this: Disables a given list of themes.", "context": "Parameters:\n- $theme_list: An array of theme names.\n\nFile: includes/theme.inc", "response": "function theme_disable($theme_list) {\n // Don't disable the default theme.\n if ($pos = array_search(variable_get('theme_default', 'bartik'), $theme_list) !== FALSE) {\n unset($theme_list[$pos]);\n if (empty($theme_list)) {\n return;\n }\n }\n\n drupal_clear_css_cache();\n\n foreach ($theme_list as $key) {\n db_update('system')\n ->fields(array('status' => 0))\n ->condition('type', 'theme')\n ->condition('name', $key)\n ->execute();\n }\n\n list_themes(TRUE);\n menu_rebuild();\n drupal_theme_rebuild();\n\n // Invoke hook_themes_disabled after the themes have been disabled.\n module_invoke_all('themes_disabled', $theme_list);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f96bff9ce7", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21book%21book.module/function/_book_update_outline/7.x", "instruction": "I need the code for `_book_update_outline($node)` in Drupal 7 (modules/book/book.module). It must do this: Handles additions and updates to the book outline.", "context": "This common helper function performs all additions and updates to the book outline through node addition, node editing, node deletion, or the outline tab.\n\nParameters:\n- $node: The node that is being saved, added, deleted, or moved.\n\nReturns: TRUE if the menu link was saved; FALSE otherwise.\n\nFile: modules/book/book.module", "response": "function _book_update_outline($node) {\n if (empty($node->book['bid'])) {\n return FALSE;\n }\n $new = empty($node->book['mlid']);\n\n $node->book['link_path'] = 'node/' . $node->nid;\n $node->book['link_title'] = $node->title;\n $node->book['parent_mismatch'] = FALSE; // The normal case.\n\n if ($node->book['bid'] == $node->nid) {\n $node->book['plid'] = 0;\n $node->book['menu_name'] = book_menu_name($node->nid);\n }\n else {\n // Check in case the parent is not is this book; the book takes precedence.\n if (!empty($node->book['plid'])) {\n $parent = db_query(\"SELECT * FROM {book} WHERE mlid = :mlid\", array(\n ':mlid' => $node->book['plid'],\n ))->fetchAssoc();\n }\n if (empty($node->book['plid']) || !$parent || $parent['bid'] != $node->book['bid']) {\n $node->book['plid'] = db_query(\"SELECT mlid FROM {book} WHERE nid = :nid\", array(\n ':nid' => $node->book['bid'],\n ))->fetchField();\n $node->book['parent_mismatch'] = TRUE; // Likely when JS is disabled.\n }\n }\n\n if (menu_link_save($node->book)) {\n if ($new) {\n // Insert new.\n db_insert('book')\n ->fields(array(\n 'nid' => $node->nid,\n 'mlid' => $node->book['mlid'],\n 'bid' => $node->book['bid'],\n ))\n ->execute();\n // Reset the cache of stored books.\n drupal_static_reset('book_get_books');\n }\n else {\n if ($node->book['bid'] != db_query(\"SELECT bid FROM {book} WHERE nid = :nid\", array(\n ':nid' => $node->nid,\n ))->fetchField()) {\n // Update the bid for this page and all children.\n book_update_bid($node->book);\n // Reset the cache of stored books.\n drupal_static_reset('book_get_books');\n }\n }\n\n return TRUE;\n }\n\n // Failed to save the menu link.\n return FALSE;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f97ac1d7c5", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_search_admin/7.x", "instruction": "In Drupal 7, show an example implementation for `hook_search_admin()` (modules/search/search.api.php): Add elements to the search settings form.", "context": "Returns: Form array for the Search settings page at admin/config/search/settings.\n\nFile: modules/search/search.api.php", "response": "function hook_search_admin() {\n // Output form for defining rank factor weights.\n $form['content_ranking'] = array(\n '#type' => 'fieldset',\n '#title' => t('Content ranking'),\n );\n $form['content_ranking']['#theme'] = 'node_search_admin';\n $form['content_ranking']['info'] = array(\n '#value' => '' . t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . ''\n );\n\n // Note: reversed to reflect that higher number = higher ranking.\n $options = drupal_map_assoc(range(0, 10));\n foreach (module_invoke_all('ranking') as $var => $values) {\n $form['content_ranking']['factors']['node_rank_' . $var] = array(\n '#title' => $values['title'],\n '#type' => 'select',\n '#options' => $options,\n '#default_value' => variable_get('node_rank_' . $var, 0),\n );\n }\n return $form;\n}", "tags": ["code-task", "hook-definition"], "created_at": "2026-09-30"} {"id": "api-drupal7-f97b91cbc8", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/theme_dashboard_disabled_blocks/7.x", "instruction": "Implement `theme_dashboard_disabled_blocks($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for disabled blocks, for use in dashboard customization mode.", "context": "Parameters:\n- $variables: An associative array containing: - blocks: An array of block objects from _block_rehash().\n\nFile: modules/dashboard/dashboard.module", "response": "function theme_dashboard_disabled_blocks($variables) {\n extract($variables);\n $output = '

                  ' . t('Drag and drop these blocks to the columns below. Changes are automatically saved. More options are available on the configuration page.', array('@dashboard-url' => url('admin/dashboard/configure'))) . '

                  ';\n $output .= '
                  ';\n foreach ($blocks as $block) {\n $output .= theme('dashboard_disabled_block', array('block' => $block));\n }\n $output .= '
                  ';\n $output .= '

                  ' . l(t('Add other blocks'), 'admin/dashboard/configure') . '

                  ';\n $output .= '
                  ';\n return $output;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f97db1663a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/template_preprocess_announcements_feed/7.x", "instruction": "I need the code for `template_preprocess_announcements_feed(&$variables)` in Drupal 7 (modules/announcements_feed/announcements_feed.module). It must do this: Processes variables for announcements-feed.tpl.php.", "context": "File: modules/announcements_feed/announcements_feed.module", "response": "function template_preprocess_announcements_feed(&$variables) {\n if (!empty($variables['featured'])) {\n foreach($variables['featured'] as &$announcement) {\n _announcements_feed_preprocess_item($announcement);\n }\n }\n if (!empty($variables['standard'])) {\n foreach($variables['standard'] as &$announcement) {\n _announcements_feed_preprocess_item($announcement);\n }\n }\n if (isset($variables['feed_link'])) {\n $variables['feed_link'] = check_url($variables['feed_link']);\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9cc1ec5b3", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_uninstall/7.x", "instruction": "I need the code for `image_uninstall()` in Drupal 7 (modules/image/image.install). It must do this: Implements hook_uninstall().", "context": "File: modules/image/image.install", "response": "function image_uninstall() {\n // Remove the styles directory and generated images.\n file_unmanaged_delete_recursive(file_default_scheme() . '://styles');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9d06e2283", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21openid%21openid.install/function/openid_requirements/7.x", "instruction": "Implement `openid_requirements($phase)` in PHP for Drupal 7. Required behavior: Implements hook_requirements().", "context": "File: modules/openid/openid.install", "response": "function openid_requirements($phase) {\n $requirements = array();\n\n if ($phase == 'runtime') {\n // Check for the PHP BC Math library.\n if (!function_exists('bcadd') && !function_exists('gmp_add')) {\n $requirements['openid_math'] = array(\n 'value' => t('Not installed'),\n 'severity' => REQUIREMENT_ERROR,\n 'description' => t('OpenID suggests the use of either the GMP Math (recommended for performance) or BC Math libraries to enable OpenID associations.', array('@gmp' => 'http://php.net/manual/en/book.gmp.php', '@bc' => 'http://www.php.net/manual/en/book.bc.php')),\n );\n }\n elseif (!function_exists('gmp_add')) {\n $requirements['openid_math'] = array(\n 'value' => t('Not optimized'),\n 'severity' => REQUIREMENT_WARNING,\n 'description' => t('OpenID suggests the use of the GMP Math library for PHP for optimal performance. Check the GMP Math Library documentation for installation instructions.', array('@url' => 'http://www.php.net/manual/en/book.gmp.php')),\n );\n }\n else {\n $requirements['openid_math'] = array(\n 'value' => t('Installed'),\n 'severity' => REQUIREMENT_OK,\n );\n }\n $requirements['openid_math']['title'] = t('OpenID Math library');\n }\n\n return $requirements;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9e2410425", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21statistics%21statistics.install/function/statistics_uninstall/7.x", "instruction": "Implement `statistics_uninstall()` in PHP for Drupal 7. Required behavior: Implements hook_uninstall().", "context": "File: modules/statistics/statistics.install", "response": "function statistics_uninstall() {\n // Remove variables.\n variable_del('statistics_count_content_views');\n variable_del('statistics_count_content_views_ajax');\n variable_del('statistics_enable_access_log');\n variable_del('statistics_flush_accesslog_timer');\n variable_del('statistics_day_timestamp');\n variable_del('statistics_block_top_day_num');\n variable_del('statistics_block_top_all_num');\n variable_del('statistics_block_top_last_num');\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9e35bc1b1", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_uninstall/7.x", "instruction": "Implement `comment_uninstall()` in PHP for Drupal 7. Required behavior: Implements hook_uninstall().", "context": "File: modules/comment/comment.install", "response": "function comment_uninstall() {\n // Remove variables.\n variable_del('comment_block_count');\n $node_types = array_keys(node_type_get_types());\n foreach ($node_types as $node_type) {\n field_attach_delete_bundle('comment', 'comment_node_' . $node_type);\n variable_del('comment_' . $node_type);\n variable_del('comment_anonymous_' . $node_type);\n variable_del('comment_controls_' . $node_type);\n variable_del('comment_default_mode_' . $node_type);\n variable_del('comment_default_order_' . $node_type);\n variable_del('comment_default_per_page_' . $node_type);\n variable_del('comment_form_location_' . $node_type);\n variable_del('comment_preview_' . $node_type);\n variable_del('comment_subject_field_' . $node_type);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9eac9f781", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/tracker_comment_update/7.x", "instruction": "Implement `tracker_comment_update($comment)` in PHP for Drupal 7. Required behavior: Implements hook_comment_update().", "context": "Comment module doesn't call hook_comment_unpublish() when saving individual comments so we need to check for those here.\n\nFile: modules/tracker/tracker.module", "response": "function tracker_comment_update($comment) {\n // comment_save() calls hook_comment_publish() for all published comments\n // so we need to handle all other values here.\n if ($comment->status != COMMENT_PUBLISHED) {\n _tracker_remove($comment->nid, $comment->uid, $comment->changed);\n }\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-f9f00d3e56", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_overview/7.x", "instruction": "I need the code for `dblog_overview()` in Drupal 7 (modules/dblog/dblog.admin.inc). It must do this: Page callback: Displays a listing of database log messages.", "context": "Messages are truncated at 56 chars. Full-length messages can be viewed on the message details page.\n\nFile: modules/dblog/dblog.admin.inc", "response": "function dblog_overview() {\n $filter = dblog_build_filter_query();\n $rows = array();\n $classes = array(\n WATCHDOG_DEBUG => 'dblog-debug',\n WATCHDOG_INFO => 'dblog-info',\n WATCHDOG_NOTICE => 'dblog-notice',\n WATCHDOG_WARNING => 'dblog-warning',\n WATCHDOG_ERROR => 'dblog-error',\n WATCHDOG_CRITICAL => 'dblog-critical',\n WATCHDOG_ALERT => 'dblog-alert',\n WATCHDOG_EMERGENCY => 'dblog-emerg',\n );\n\n $build['dblog_filter_form'] = drupal_get_form('dblog_filter_form');\n $build['dblog_clear_log_form'] = drupal_get_form('dblog_clear_log_form');\n\n $header = array(\n '', // Icon column.\n array('data' => t('Type'), 'field' => 'w.type'),\n array('data' => t('Date'), 'field' => 'w.wid', 'sort' => 'desc'),\n t('Message'),\n array('data' => t('User'), 'field' => 'u.name'),\n array('data' => t('Operations')),\n );\n\n $query = db_select('watchdog', 'w')->extend('PagerDefault')->extend('TableSort');\n $query->leftJoin('users', 'u', 'w.uid = u.uid');\n $query\n ->fields('w', array('wid', 'uid', 'severity', 'type', 'timestamp', 'message', 'variables', 'link'))\n ->addField('u', 'name');\n if (!empty($filter['where'])) {\n $query->where($filter['where'], $filter['args']);\n }\n $result = $query\n ->limit(50)\n ->orderByHeader($header)\n ->execute();\n\n foreach ($result as $dblog) {\n $rows[] = array('data' =>\n array(\n // Cells\n array('class' => 'icon'),\n t($dblog->type),\n format_date($dblog->timestamp, 'short'),\n theme('dblog_message', array('event' => $dblog, 'link' => TRUE)),\n theme('username', array('account' => $dblog)),\n filter_xss($dblog->link),\n ),\n // Attributes for tr\n 'class' => array(drupal_html_class('dblog-' . $dblog->type), $classes[$dblog->severity]),\n );\n }\n\n $build['dblog_table'] = array(\n '#theme' => 'table',\n '#header' => $header,\n '#rows' => $rows,\n '#attributes' => array('id' => 'admin-dblog'),\n '#empty' => t('No log messages available.'),\n );\n $build['dblog_pager'] = array('#theme' => 'pager');\n\n return $build;\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-fa11e13b3b", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21unicode.inc/function/drupal_strtolower/7.x", "instruction": "Implement `drupal_strtolower($text)` in PHP for Drupal 7. Required behavior: Lowercase a UTF-8 string.", "context": "Parameters:\n- $text: The string to run the operation on.\n\nReturns (string): The string in lowercase.\n\nFile: includes/unicode.inc", "response": "function drupal_strtolower($text) {\n global $multibyte;\n if ($multibyte == UNICODE_MULTIBYTE) {\n return mb_strtolower($text);\n }\n else {\n // Use C-locale for ASCII-only lowercase\n $text = strtolower($text);\n // Case flip Latin-1 accented letters\n $text = preg_replace_callback('/\\xC3[\\x80-\\x96\\x98-\\x9E]/', '_unicode_caseflip', $text);\n return $text;\n }\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-fa2a60aa78", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_validate_url/7.x", "instruction": "Implement `announcements_feed_validate_url($url)` in PHP for Drupal 7. Required behavior: Check whether a link is controlled by drupal.org.", "context": "Parameters:\n- $url (string): URL to check.\n\nReturns (bool): Return TRUE if the URL is controlled by drupal.org.\n\nFile: modules/announcements_feed/announcements_feed.inc", "response": "function announcements_feed_validate_url($url) {\n if (empty($url)) {\n return FALSE;\n }\n $host = parse_url($url, PHP_URL_HOST);\n\n // First character can only be a letter or a digit.\n // @see https://www.rfc-editor.org/rfc/rfc1123#page-13\n return $host && preg_match('/^([a-zA-Z0-9][a-zA-Z0-9\\-_]*\\.)?drupal\\.org$/', $host);\n}", "tags": ["code-task", "function"], "created_at": "2026-09-30"} {"id": "api-drupal7-fa3fd138b0", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21field%21field.install/function/field_schema/7.x", "instruction": "Implement `field_schema()` in PHP for Drupal 7. Required behavior: Implements hook_schema().", "context": "File: modules/field/field.install", "response": "function field_schema() {\n // Static (meta) tables.\n $schema['field_config'] = array(\n 'fields' => array(\n 'id' => array(\n 'type' => 'serial',\n 'not null' => TRUE,\n 'description' => 'The primary identifier for a field',\n ),\n 'field_name' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'description' => 'The name of this field. Non-deleted field names are unique, but multiple deleted fields can have the same name.',\n ),\n 'type' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'description' => 'The type of this field.',\n ),\n 'module' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The module that implements the field type.',\n ),\n 'active' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Boolean indicating whether the module that implements the field type is enabled.',\n ),\n 'storage_type' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'description' => 'The storage backend for the field.',\n ),\n 'storage_module' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => '',\n 'description' => 'The module that implements the storage backend.',\n ),\n 'storage_active' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => 'Boolean indicating whether the module that implements the storage backend is enabled.',\n ),\n 'locked' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n 'description' => '@TODO',\n ),\n 'data' => array(\n 'type' => 'blob',\n 'size' => 'big',\n 'not null' => TRUE,\n 'serialize' => TRUE,\n 'description' => 'Serialized data containing the field properties that do not warrant a dedicated column.',\n ),\n 'cardinality' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'translatable' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n ),\n 'deleted' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n ),\n ),\n 'primary key' => array('id'),\n 'indexes' => array(\n 'field_name' => array('field_name'),\n // Used by field_sync_field_status().\n 'active' => array('active'),\n 'storage_active' => array('storage_active'),\n 'deleted' => array('deleted'),\n // Used by field_modules_disabled().\n 'module' => array('module'),\n 'storage_module' => array('storage_module'),\n 'type' => array('type'),\n 'storage_type' => array('storage_type'),\n ),\n );\n $schema['field_config_instance'] = array(\n 'fields' => array(\n 'id' => array(\n 'type' => 'serial',\n 'not null' => TRUE,\n 'description' => 'The primary identifier for a field instance',\n ),\n 'field_id' => array(\n 'type' => 'int',\n 'not null' => TRUE,\n 'description' => 'The identifier of the field attached by this instance',\n ),\n 'field_name' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => ''\n ),\n 'entity_type' => array(\n 'type' => 'varchar',\n 'length' => 32,\n 'not null' => TRUE,\n 'default' => ''\n ),\n 'bundle' => array(\n 'type' => 'varchar',\n 'length' => 128,\n 'not null' => TRUE,\n 'default' => ''\n ),\n 'data' => array(\n 'type' => 'blob',\n 'size' => 'big',\n 'not null' => TRUE,\n 'serialize' => TRUE,\n ),\n 'deleted' => array(\n 'type' => 'int',\n 'size' => 'tiny',\n 'not null' => TRUE,\n 'default' => 0,\n ),\n ),\n 'primary key' => array('id'),\n 'indexes' => array(\n // Used by field_delete_instance().\n 'field_name_bundle' => array('field_name', 'entity_type', 'bundle'),\n // Used by field_read_instances().\n 'deleted' => array('deleted'),\n ),\n );\n $schema['cache_field'] = drupal_get_schema_unprocessed('system', 'cache');\n $schema['cache_field']['description'] = 'Cache table for the Field module to store already built field information.';\n\n return $schema;\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-fa41bec6fa", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_formatter_settings_summary/7.x", "instruction": "Implement `image_field_formatter_settings_summary($field, $instance, $view_mode)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_settings_summary().", "context": "File: modules/image/image.field.inc", "response": "function image_field_formatter_settings_summary($field, $instance, $view_mode) {\n $display = $instance['display'][$view_mode];\n $settings = $display['settings'];\n\n $summary = array();\n\n $image_styles = image_style_options(FALSE, PASS_THROUGH);\n // Unset possible 'No defined styles' option.\n unset($image_styles['']);\n // Styles could be lost because of enabled/disabled modules that defines\n // their styles in code.\n if (isset($image_styles[$settings['image_style']])) {\n $summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));\n }\n else {\n $summary[] = t('Original image');\n }\n\n $link_types = array(\n 'content' => t('Linked to content'),\n 'file' => t('Linked to file'),\n );\n // Display this setting only if image is linked.\n if (isset($link_types[$settings['image_link']])) {\n $summary[] = $link_types[$settings['image_link']];\n }\n\n return implode('
                  ', $summary);\n}", "tags": ["code-task", "hook-implementation"], "created_at": "2026-09-30"} {"id": "api-drupal7-fa5e4e433a", "drupal_version": "7", "source_type": "drupal_api_code", "source_url": "https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7.x", "instruction": "I need the code for `drupal_add_js($data = NULL, $options = NULL)` in Drupal 7 (includes/common.inc). It must do this: Adds a JavaScript file, setting, or inline code to the page.", "context": "The behavior of this function depends on the parameters it is called with.\nGenerally, it handles the addition of JavaScript to the page, either as\nreference to an existing file or as inline code. The following actions can be\nperformed using this function:\n- Add a file ('file'): Adds a reference to a JavaScript file to the page.\n- Add inline JavaScript code ('inline'): Executes a piece of JavaScript code\n on the current page by placing the code directly in the page (for example,\n to tell the user that a new message arrived, by opening a pop up, alert\n box, etc.). This should only be used for JavaScript that cannot be executed\n from a file. When adding inline code, make sure that you are not relying on\n $() being the jQuery function. Wrap your code in\n @code (function ($) {... })(jQuery); @endcode\n or use jQuery() instead of $().\n- Add external JavaScript ('external'): Allows the inclusion of external\n JavaScript files that are not hosted on the local server. Note that these\n external JavaScript references do not get aggregated when preprocessing is\n on.\n- Add settings ('setting'): Adds settings to Drupal's global storage of\n JavaScript settings. Per-page settings are required by some modules to\n function properly. All settings will be accessible at Drupal.settings.\n\nExamples:\n\nParameters:\n- $data: (optional) If given, the value depends on the $options parameter, or $options['type'] if $options is passed as an associative array: - 'file': Path to the file relative to base_path(). - 'inline': The JavaScript code that should be placed in the given scope. - 'external': The absolute path to an external JavaScript file that is not hosted on the local server. These files will not be aggregated if JavaScript aggregation is enabled. - 'setting': An associative array with configuration options. The array is merged directly into Drupal.settings. All modules should wrap their actual configuration settings in another variable to prevent conflicts in the Drupal.settings namespace. Items added with a string key will replace existing settings with that key; items with numeric array keys will be added to the existing settings array.\n- $options: (optional) A string defining the type of JavaScript that is being added in the $data parameter ('file'/'setting'/'inline'/'external'), or an associative array. JavaScript settings should always pass the string 'setting' only. Other types can have the following elements in the array: - type: The type of JavaScript that is to be added to the page. Allowed values are 'file', 'inline', 'external' or 'setting'. Defaults to 'file'. - scope: The location in which you want to place the script. Possible values are 'header' or 'footer'. If your theme implements different regions, you can also use these. Defaults to 'header'. - group: A number identifying the group in which to add the JavaScript. Available constants are: - JS_LIBRARY: Any libraries, settings, or jQuery plugins. - JS_DEFAULT: Any module-layer JavaScript. - JS_THEME: Any theme-layer JavaScript. The group number serves as a weight: JavaScript within a lower weight group is presented on the page before JavaScript within a higher weight group. - every_page: For optimal front-end performance when aggregation is enabled, this should be set to TRUE if the JavaScript is present on every page of the website for users for whom it is present at all. This defaults to FALSE. It is set to TRUE for JavaScript files that are added via module and theme .info files. Modules that add JavaScript within hook_init() implementations, or from other code that ensures that the JavaScript is added to all website pages, should also set this flag to TRUE. All JavaScript files within the same group and that have the 'every_page' flag set to TRUE and do not have 'preprocess' set to FALSE are aggregated together into a single aggregate file, and that aggregate file can be reused across a user's entire site visit, leading to faster navigation between pages. However, JavaScript that is only needed on pages less frequently visited, can be added by code that only runs for those particular pages, and that code should not set the 'every_page' flag. This minimizes the size of the aggregate file that the user needs to download when first visiting the website. JavaScript without the 'every_page' flag is aggregated into a separate aggregate file. This other aggregate file is likely to change from page to page, and each new aggregate file needs to be downloaded when first encountered, so it should be kept relatively small by ensuring that most commonly needed JavaScript is added to every page. - weight: A number defining the order in which the JavaScript is added to the page relative to other JavaScript with the same 'scope', 'group', and 'every_page' value. In some cases, the order in which the JavaScript is presented on the page is very important. jQuery, for example, must be added to the page before any jQuery code is run, so jquery.js uses the JS_LIBRARY group and a weight of -20, jquery.once.js (a library drupal.js depends on) uses the JS_LIBRARY group and a weight of -19, drupal.js uses the JS_LIBRARY group and a weight of -1, other libraries use the JS_LIBRARY group and a weight of 0 or higher, and all other scripts use one of the other group constants. The exact ordering of JavaScript is as follows: - First by scope, with 'header' first, 'footer' last, and any other scopes provided by a custom theme coming in between, as determined by the theme. - Then by group. - Then by the 'every_page' flag, with TRUE coming before FALSE. - Then by weight. - Then by the order in which the JavaScript was added. For example, all else being the same, JavaScript added by a call to drupal_add_js() that happened later in the page request gets added to the page after one for which drupal_add_js() happened earlier in the page request. - requires_jquery: Set this to FALSE if the JavaScript you are adding does not have a dependency on jQuery. Defaults to TRUE, except for JavaScript settings where it defaults to FALSE. This is used on sites that have the 'javascript_always_use_jquery' variable set to FALSE; on those sites, if all the JavaScript added to the page by drupal_add_js() does not have a dependency on jQuery, then for improved front-end performance Drupal will not add jQuery and related libraries and settings to the page. - defer: If set to TRUE, the defer attribute is set on the