id stringlengths 22 22 | drupal_version stringclasses 1
value | source_type stringclasses 1
value | source_url stringlengths 70 167 | instruction stringlengths 87 500 | context stringlengths 16 10.7k | response stringlengths 68 5.97k | tags listlengths 2 2 | created_at timestamp[s]date 2026-09-30 00:00:00 2026-09-30 00:00:00 |
|---|---|---|---|---|---|---|---|---|
api-drupal7-5bba94730b | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_bootstrap_configuration/7.x | In Drupal 7, write the function `_drupal_bootstrap_configuration()` (file includes/bootstrap.inc) so that it does the following: Sets up the script environment and loads settings.php. | File: includes/bootstrap.inc | function _drupal_bootstrap_configuration() {
// Set the Drupal custom error handler.
set_error_handler('_drupal_error_handler');
set_exception_handler('_drupal_exception_handler');
drupal_environment_initialize();
// Start a page timer:
timer_start('page');
// Initialize the configuration, including vari... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5bbfa4d3c4 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_xri_normalize/7.x | In Drupal 7, write the function `_openid_xri_normalize($identifier)` (file modules/openid/openid.inc) so that it does the following: OpenID normalization method: normalize XRI identifiers. | File: modules/openid/openid.inc | function _openid_xri_normalize($identifier) {
if (_openid_is_xri($identifier)) {
if (stristr($identifier, 'xri://') !== FALSE) {
$identifier = substr($identifier, 6);
}
return $identifier;
}
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5bce8beaa3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_private_key/7.x | Implement `drupal_get_private_key()` in PHP for Drupal 7. Required behavior: Ensures the private key variable used to generate tokens is set. | Returns: The private key.
File: includes/common.inc | function drupal_get_private_key() {
if (!($key = variable_get('drupal_private_key', 0))) {
$key = drupal_random_key();
variable_set('drupal_private_key', $key);
}
return $key;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5bd1ae2ab2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_get_display_ordinal/7.x | In Drupal 7, write the function `comment_get_display_ordinal($cid, $node_type)` (file modules/comment/comment.module) so that it does the following: Get the display ordinal for a comment, starting from 0. | Count the number of comments which appear before the comment we want to display, taking into account display settings and threading.
Parameters:
- $cid: The comment ID.
- $node_type: The node type of the comment's parent.
Returns: The display ordinal for the comment.
File: modules/comment/comment.module | function comment_get_display_ordinal($cid, $node_type) {
// Count how many comments (c1) are before $cid (c2) in display order. This is
// the 0-based display ordinal.
$query = db_select('comment', 'c1');
$query->innerJoin('comment', 'c2', 'c2.nid = c1.nid');
$query->addExpression('COUNT(*)', 'count');
$que... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5be5f3206a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_process_username/7.x | In Drupal 7, write the function `template_process_username(&$variables)` (file includes/theme.inc) so that it does the following: Processes variables for theme_username(). | File: includes/theme.inc | function template_process_username(&$variables) {
// Finalize the link_options array for passing to the l() function.
// This is done in the process phase so that attributes may be added by
// modules or the theme during the preprocess phase.
if (isset($variables['link_path'])) {
// $variables['attributes_a... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5bed06fb8e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/dblog_help/7.x | Implement `dblog_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help(). | File: modules/dblog/dblog.module | function dblog_help($path, $arg) {
switch ($path) {
case 'admin/help#dblog':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Database logging module logs system events in the Drupal database. For more information, see the online handbook entry for the <a href="@... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5bed29a961 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_username_alter/7.x | Give me the example code for `hook_username_alter(&$name, $account)` in Drupal 7. Hook description: Alter the username that is displayed for a user. | Called by format_username() to allow modules to alter the username that's displayed. Can be used to ensure user privacy in situations where $account->name is too revealing.
Parameters:
- $name: The string that format_username() will return.
- $account: The account object passed to format_username().
File: modules/sys... | function hook_username_alter(&$name, $account) {
// Display the user's uid instead of name.
if (isset($account->uid)) {
$name = t('User !uid', array('!uid' => $account->uid));
}
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5c16fe7c12 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_admin_paths/7.x | I need the code for `block_admin_paths()` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_admin_paths(). | File: modules/block/block.module | function block_admin_paths() {
$paths = array(
// Exclude the block demonstration page from admin (overlay) treatment.
// This allows us to present this page in its true form, full page.
'admin/structure/block/demo/*' => FALSE,
);
return $paths;
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5c54ff0f98 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_update_index/7.x | I need the code for `node_update_index()` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_update_index(). | File: modules/node/node.module | function node_update_index() {
$limit = (int)variable_get('search_cron_limit', 100);
$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, array(), array('target' =>... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5c5b91afd5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/_update_process_fetch_task/7.x | I need the code for `_update_process_fetch_task($project)` in Drupal 7 (modules/update/update.fetch.inc). It must do this: Processes a task to fetch available update data for a single project. | Once the release history XML data is downloaded, it is parsed and saved into the {cache_update} table in an entry just for that project.
Parameters:
- $project: Associative array of information about the project to fetch data for.
Returns: TRUE if we fetched parsable XML, otherwise FALSE.
File: modules/update/update... | function _update_process_fetch_task($project) {
global $base_url;
$fail = &drupal_static(__FUNCTION__, array());
// This can be in the middle of a long-running batch, so REQUEST_TIME won't
// necessarily be valid.
$now = time();
if (empty($fail)) {
// If we have valid data about release history XML serv... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5c611e7ea0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21filter%21filter.install/function/filter_schema/7.x | In Drupal 7, write the function `filter_schema()` (file modules/filter/filter.install) so that it does the following: Implements hook_schema(). | File: modules/filter/filter.install | function filter_schema() {
$schema['filter'] = array(
'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',
'fields' => array(
'format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Foreign ke... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5c6e3deaeb | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21session.inc/function/_drupal_session_regenerate_existing/7.x | I need the code for `_drupal_session_regenerate_existing()` in Drupal 7 (includes/session.inc). It must do this: Regenerates an existing session. | File: includes/session.inc | function _drupal_session_regenerate_existing() {
global $user;
// Preserve existing settings for the saving of sessions.
$original_save_session_status = drupal_save_session();
// Turn off saving of sessions.
drupal_save_session(FALSE);
session_write_close();
drupal_session_started(FALSE);
// Preserve th... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5c7175ae70 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_refresh/7.x | In Drupal 7, write the function `aggregator_refresh($feed)` (file modules/aggregator/aggregator.module) so that it does the following: Checks a news feed for new items. | Parameters:
- $feed: An object describing the feed to be refreshed.
File: modules/aggregator/aggregator.module | function aggregator_refresh($feed) {
// Store feed URL to track changes.
$feed_url = $feed->url;
// Fetch the feed.
list($fetcher, $parser, $processors) = _aggregator_get_variables();
$success = module_invoke($fetcher, 'aggregator_fetch', $feed);
// We store the hash of feed data in the database. When ref... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5c7435ce8d | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_download/7.x | In Drupal 7, show an example implementation for `hook_file_download($uri)` (modules/system/system.api.php): Control access to private file downloads and specify HTTP headers. | This hook allows modules enforce permissions on file downloads when the private file download method is selected. Modules can also provide headers to specify information like the file's name or MIME type.
Parameters:
- $uri: The URI of the file.
Returns: If the user does not have permission to access the file, return... | function hook_file_download($uri) {
// Check if the file is controlled by the current module.
if (!file_prepare_directory($uri)) {
$uri = FALSE;
}
if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
if (!user_access('access user profiles')) {
// ... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5c74d65aa0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_move/7.x | In Drupal 7, show an example implementation for `hook_file_move($file, $source)` (modules/system/system.api.php): Respond to a file that has been moved. | Parameters:
- $file: The updated file object after the move.
- $source: The original file object before the move.
File: modules/system/system.api.php | function hook_file_move($file, $source) {
$file_user = user_load($file->uid);
// Make sure that the file name starts with the owner's user name.
if (strpos($file->filename, $file_user->name) !== 0) {
$file->filename = $file_user->name . '_' . $file->filename;
$file->save();
watchdog('file', 'Moved fi... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5c78e9ab2a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.api.php/function/hook_aggregator_fetch_info/7.x | In Drupal 7, show an example implementation for `hook_aggregator_fetch_info()` (modules/aggregator/aggregator.api.php): Specify the title and short description of your fetcher. | The title and the description provided are shown within the configuration page. Use as title the human readable name of the fetcher and as description a brief (40 to 80 characters) explanation of the fetcher's functionality.
This hook is only called if your module implements hook_aggregator_fetch(). If this hook is no... | function hook_aggregator_fetch_info() {
return array(
'title' => t('Default fetcher'),
'description' => t('Default fetcher for resources available by URL.'),
);
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5c855080c2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_validate/7.x | In Drupal 7, show an example implementation for `hook_field_attach_validate($entity_type, $entity, &$errors)` (modules/field/field.api.php): Act on field_attach_validate(). | This hook is invoked after the field module has performed the operation.
See field_attach_validate() for details and arguments.
Parameters:
- $entity_type: The type of $entity; e.g., 'node' or 'user'.
- $entity: The entity with fields to validate.
- $errors (array): The array of errors (keyed by field name, language ... | function hook_field_attach_validate($entity_type, $entity, &$errors) {
// Make sure any images in article nodes have an alt text.
if ($entity_type == 'node' && $entity->type == 'article' && !empty($entity->field_image)) {
foreach ($entity->field_image as $langcode => $items) {
foreach ($items as $delta =>... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5c8cef405b | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_reset_static_cache/7.x | I need the code for `menu_reset_static_cache()` in Drupal 7 (includes/menu.inc). It must do this: Resets the menu system static cache. | File: includes/menu.inc | function menu_reset_static_cache() {
drupal_static_reset('_menu_build_tree');
drupal_static_reset('menu_tree');
drupal_static_reset('menu_tree_all_data');
drupal_static_reset('menu_tree_page_data');
drupal_static_reset('menu_load_all');
drupal_static_reset('menu_link_get_preferred');
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5c98b40404 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_process/7.x | Implement `rdf_process(&$variables, $hook)` in PHP for Drupal 7. Required behavior: Template process function for adding extra tags to hold RDFa attributes. | Since template files already have built-in support for $attributes, $title_attributes, and $content_attributes, and field templates have support for $item_attributes, we try to leverage those as much as possible. However, in some cases additional attributes are needed not covered by these. We deal with those here.
Fil... | function rdf_process(&$variables, $hook) {
// Handles attributes needed for content not covered by title, content,
// and field items. It does this by adjusting the variable sent to the
// template so that the template doesn't have to worry about it. See
// theme_rdf_template_variable_wrapper().
if (!empty($v... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5cb31c99e8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_image_toolkits/7.x | I need the code for `system_image_toolkits()` in Drupal 7 (modules/system/system.module). It must do this: Implements hook_image_toolkits(). | File: modules/system/system.module | function system_image_toolkits() {
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'system') . '/' . 'image.gd.inc';
return array(
'gd' => array(
'title' => t('GD2 image manipulation toolkit'),
'available' => function_exists('image_gd_check_settings') && image_gd_check_settings(),
),
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5ccbda3729 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_user_delete/7.x | Implement `profile_user_delete($account)` in PHP for Drupal 7. Required behavior: Implements hook_user_delete(). | File: modules/profile/profile.module | function profile_user_delete($account) {
db_delete('profile_value')
->condition('uid', $account->uid)
->execute();
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5cd11f3b76 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_set_time_limit/7.x | In Drupal 7, write the function `drupal_set_time_limit($time_limit)` (file includes/common.inc) so that it does the following: Attempts to set the PHP maximum execution time. | This function is a wrapper around the PHP function set_time_limit(). When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 secon... | function drupal_set_time_limit($time_limit) {
if (function_exists('set_time_limit')) {
$current = ini_get('max_execution_time');
// Do not set time limit if it is currently unlimited.
if ($current != 0) {
@set_time_limit($time_limit);
}
}
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5cd362d343 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21token.inc/function/token_scan/7.x | In Drupal 7, write the function `token_scan($text)` (file includes/token.inc) so that it does the following: Builds a list of all token-like patterns that appear in the text. | Parameters:
- $text: The text to be scanned for possible tokens.
Returns: An associative array of discovered tokens, grouped by type.
File: includes/token.inc | function token_scan($text) {
// Matches tokens with the following pattern: [$type:$name]
// $type and $name may not contain [ ] characters.
// $type may not contain : or whitespace characters, but $name may.
preg_match_all('/
\[ # [ - pattern start
([^\s\[\]:]*) # match $type not containin... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5cf6f6eecc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_node_prepare/7.x | I need the code for `menu_node_prepare($node)` in Drupal 7 (modules/menu/menu.module). It must do this: Implements hook_node_prepare(). | File: modules/menu/menu.module | function menu_node_prepare($node) {
if (empty($node->menu)) {
// Prepare the node for the edit form so that $node->menu always exists.
$menu_name = strtok(variable_get('menu_parent_' . $node->type, 'main-menu:0'), ':');
$item = array();
if (isset($node->nid)) {
$mlid = FALSE;
// Give prior... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5d05ef6c07 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_format_disable/7.x | In Drupal 7, write the function `filter_format_disable($format)` (file modules/filter/filter.module) so that it does the following: Disables a text format. | There is no core facility to re-enable a disabled format. It is not deleted to keep information for contrib and to make sure the format ID is never reused. As there might be content using the disabled format, this would lead to data corruption.
Parameters:
- $format: The text format object to be disabled.
File: modul... | function filter_format_disable($format) {
db_update('filter_format')
->fields(array('status' => 0))
->condition('format', $format->format)
->execute();
// Allow modules to react on text format deletion.
module_invoke_all('filter_format_disable', $format);
// Clear the filter cache whenever a text ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5d3fea10dd | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_delete/7.x | Implement `menu_delete($menu)` in PHP for Drupal 7. Required behavior: Delete a custom menu and all contained links. | Note that this function deletes all menu links in a custom menu. While menu links derived from router paths may be restored by rebuilding the menu, all customized and custom links will be irreversibly gone. Therefore, this function should usually be called from a user interface (form submit) handler only, which allows ... | function menu_delete($menu) {
// Delete all links from the menu.
menu_delete_links($menu['menu_name']);
// Remove menu from active menus variable.
$active_menus = variable_get('menu_default_active_menus', array_keys(menu_get_menus()));
foreach ($active_menus as $i => $menu_name) {
if ($menu['menu_name'] ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5d457531bc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/form_get_errors/7.x | In Drupal 7, write the function `form_get_errors()` (file includes/form.inc) so that it does the following: Returns an associative array of all errors if any. | Returns (array|null): The form errors if any, NULL otherwise.
File: includes/form.inc | function form_get_errors() {
$form = form_set_error();
if (!empty($form)) {
return $form;
}
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5d45fd7bca | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.default.inc/function/field_default_prepare_view/7.x | In Drupal 7, write the function `field_default_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $display)` (file modules/field/field.default.inc) so that it does the following: Invokes hook_field_formatter_prepare_view() on the relevant formatters. | Parameters:
- $entity_type: The type of $entity; e.g. 'node' or 'user'.
- $entities: An array of entities being displayed, keyed by entity id.
- $field: The field structure for the operation.
- $instances: Array of instance structures for $field for each entity, keyed by entity id.
- $langcode: The language associated ... | function field_default_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $display) {
// Group entities, instances and items by formatter module.
$modules = array();
foreach ($instances as $id => $instance) {
if (is_string($display)) {
$view_mode = $display;
$instance_di... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5d4d36541c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_available_languages_alter/7.x | Give me the example code for `hook_field_available_languages_alter(&$languages, $context)` in Drupal 7. Hook description: Alter field_available_languages() values. | This hook is invoked from field_available_languages() to allow modules to alter the array of available languages for the given field.
Parameters:
- $languages: A reference to an array of language codes to be made available.
- $context: An associative array containing: - entity_type: The type of the entity the field is... | function hook_field_available_languages_alter(&$languages, $context) {
// Add an unavailable language.
$languages[] = 'xx';
// Remove an available language.
$index = array_search('yy', $languages);
unset($languages[$index]);
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5d6d3df763 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_assign_owner_action/7.x | I need the code for `node_assign_owner_action($node, $context)` in Drupal 7 (modules/node/node.module). It must do this: Assigns ownership of a node to a user. | Parameters:
- $node: A node object to modify.
- $context: Array with the following elements: - 'owner_uid': User ID to assign to the node.
File: modules/node/node.module | function node_assign_owner_action($node, $context) {
$node->uid = $context['owner_uid'];
$owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchField();
watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_type_get_name... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5d78e006aa | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_update_ready_form_submit/7.x | Implement `update_manager_update_ready_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for update_manager_update_ready_form(). | If the site administrator requested that the site is put offline during the update, do so now. Otherwise, pull information about all the required updates out of the SESSION, figure out what Drupal\Core\Updater\Updater class is needed for each one, generate an array of update operations to perform, and hand it all off t... | function update_manager_update_ready_form_submit($form, &$form_state) {
// Store maintenance_mode setting so we can restore it when done.
$_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE);
if ($form_state['values']['maintenance_mode'] == TRUE) {
variable_set('maintenance_mode', TRUE);
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5d915947ff | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.api.php/function/hook_aggregator_process/7.x | Give me the example code for `hook_aggregator_process($feed)` in Drupal 7. Hook description: Create a processor for aggregator.module. | A processor acts on parsed feed data. Active processors are called at the third and last of the aggregation stages: first, data is downloaded by the active fetcher; second, it is converted to a common format by the active parser; and finally, it is passed to all active processors that manipulate or store the data.
Mod... | function hook_aggregator_process($feed) {
foreach ($feed->items as $item) {
mymodule_save($item);
}
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5da2a47b79 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_overview_screen/7.x | In Drupal 7, write the function `locale_translate_overview_screen()` (file modules/locale/locale.admin.inc) so that it does the following: Overview screen for translations. | File: modules/locale/locale.admin.inc | function locale_translate_overview_screen() {
drupal_static_reset('language_list');
$languages = language_list('language');
$groups = module_invoke_all('locale', 'groups');
// Build headers with all groups in order.
$headers = array_merge(array(t('Language')), array_values($groups));
// Collect summaries ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5de8f82616 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.api.php/function/hook_verify_update_archive/7.x | Give me the example code for `hook_verify_update_archive($project, $archive_file, $directory)` in Drupal 7. Hook description: Verify an archive after it has been downloaded and extracted. | Parameters:
- $project (string): The short name of the project that has been downloaded.
- $archive_file (string): The filename of the unextracted archive.
- $directory (string): The directory that the archive was extracted into.
Returns: If there are any problems, return an array of error messages. If there are no pr... | function hook_verify_update_archive($project, $archive_file, $directory) {
$errors = array();
if (!file_exists($directory)) {
$errors[] = t('The %directory does not exist.', array('%directory' => $directory));
}
// Add other checks on the archive integrity here.
return $errors;
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5df1c3fe10 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.install/function/_image_update_7002_populate_dimensions/7.x | I need the code for `_image_update_7002_populate_dimensions($table, $field_name, &$last_fid)` in Drupal 7 (modules/image/image.install). It must do this: Populate image dimensions in a specific table. | Parameters:
- $table: The name of the database table to be updated.
- $columns: Keyed array of columns this table is supposed to have.
- $last_fid: The fid of the last image to have been processed.
Returns: The number of images that were processed.
File: modules/image/image.install | function _image_update_7002_populate_dimensions($table, $field_name, &$last_fid) {
// Define how many images to process per pass.
$images_per_pass = 100;
// Query the database for fid / URI pairs.
$query = db_select($table, NULL, array('fetch' => PDO::FETCH_ASSOC));
$query->join('file_managed', NULL, $table ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5e051e5720 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_extra_fields/7.x | Give me the example code for `hook_field_extra_fields()` in Drupal 7. Hook description: Exposes "pseudo-field" components on fieldable entities. | Field UI's "Manage fields" and "Manage display" pages let users re-order fields, but also non-field components. For nodes, these include the title, poll choices, and other elements exposed by modules through hook_form() or hook_form_alter().
Fieldable entities or modules that want to have their components supported sh... | function hook_field_extra_fields() {
$extra['node']['poll'] = array(
'form' => array(
'choice_wrapper' => array(
'label' => t('Poll choices'),
'description' => t('Poll choices'),
'weight' => -4,
),
'settings' => array(
'label' => t('Poll settings'),
'descr... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5e14114530 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_page_rss/7.x | I need the code for `aggregator_page_rss()` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Page callback: Generates an RSS 0.92 feed of aggregator items or categories. | Returns (string): An HTML formatted string.
File: modules/aggregator/aggregator.pages.inc | function aggregator_page_rss() {
$result = NULL;
// arg(2) is the passed cid, only select for that category.
if (arg(2)) {
$category = db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => arg(2)))->fetchObject();
$result = db_query_range('SELECT i.*, f.title AS ftitle,... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5e4b9648d2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_block_configure/7.x | I need the code for `forum_block_configure($delta = '')` in Drupal 7 (modules/forum/forum.module). It must do this: Implements hook_block_configure(). | File: modules/forum/forum.module | function forum_block_configure($delta = '') {
$form['forum_block_num_' . $delta] = array(
'#type' => 'select',
'#title' => t('Number of topics'),
'#default_value' => variable_get('forum_block_num_' . $delta, '5'),
'#options' => drupal_map_assoc(range(2, 20))
);
return $form;
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5e5087a807 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_field_settings_form/7.x | I need the code for `taxonomy_field_settings_form($field, $instance, $has_data)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_field_settings_form(). | File: modules/taxonomy/taxonomy.module | function taxonomy_field_settings_form($field, $instance, $has_data) {
// Get proper values for 'allowed_values_function', which is a core setting.
$vocabularies = taxonomy_get_vocabularies();
$options = array();
foreach ($vocabularies as $vocabulary) {
$options[$vocabulary->machine_name] = $vocabulary->name... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5e6f09c123 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_permission/7.x | In Drupal 7, write the function `path_permission()` (file modules/path/path.module) so that it does the following: Implements hook_permission(). | File: modules/path/path.module | function path_permission() {
return array(
'administer url aliases' => array(
'title' => t('Administer URL aliases'),
'restrict access' => TRUE,
),
'create url aliases' => array(
'title' => t('Create and edit URL aliases'),
),
);
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5e7a2de4f7 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_set_edit_form/7.x | Implement `shortcut_set_edit_form($form, &$form_state, $shortcut_set)` in PHP for Drupal 7. Required behavior: Form callback: builds the form for editing the shortcut set name. | Parameters:
- $form: An associative array containing the structure of the form.
- $form_state: An associative array containing the current state of the form.
- $shortcut_set (object): An object representing the shortcut set, as returned from shortcut_set_load().
Returns: An array representing the form definition.
Fil... | function shortcut_set_edit_form($form, &$form_state, $shortcut_set) {
$form['shortcut_set'] = array(
'#type' => 'value',
'#value' => $shortcut_set,
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Set name'),
'#default_value' => $shortcut_set->title,
'#maxlength' => 255,
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5e8f5f871c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_site_information_settings_validate/7.x | In Drupal 7, write the function `system_site_information_settings_validate($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Validates the submitted site-information form. | File: modules/system/system.admin.inc | function system_site_information_settings_validate($form, &$form_state) {
// Validate the e-mail address.
if ($error = user_validate_mail($form_state['values']['site_mail'])) {
form_set_error('site_mail', $error);
}
// Check for empty front page path.
if (empty($form_state['values']['site_frontpage'])) {
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5e8f6e7d0f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21toolbar%21toolbar.module/function/toolbar_menu/7.x | I need the code for `toolbar_menu()` in Drupal 7 (modules/toolbar/toolbar.module). It must do this: Implements hook_menu(). | File: modules/toolbar/toolbar.module | function toolbar_menu() {
$items['toolbar/toggle'] = array(
'title' => 'Toggle drawer visibility',
'type' => MENU_CALLBACK,
'page callback' => 'toolbar_toggle_page',
'access arguments' => array('access toolbar'),
);
return $items;
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5eaf06d84a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_grants_alter/7.x | Give me the example code for `hook_node_grants_alter(&$grants, $account, $op)` in Drupal 7. Hook description: Alter user access rules when trying to view, edit or delete a node. | Node access modules establish rules for user access to content. hook_node_grants() defines permissions for a user to view, edit or delete nodes by building a $grants array that indicates the permissions assigned to the user by each node access module. This hook is called to allow modules to modify the $grants array by ... | function hook_node_grants_alter(&$grants, $account, $op) {
// Our sample module never allows certain roles to edit or delete
// content. Since some other node access modules might allow this
// permission, we expressly remove it by returning an empty $grants
// array for roles specified in our variable setting.... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-5eb5031ddd | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_num_new/7.x | Implement `comment_num_new($nid, $timestamp = 0)` in PHP for Drupal 7. Required behavior: Get number of new comments for current user and specified node. | Parameters:
- $nid: Node-id to count comments for.
- $timestamp: Time to count from (defaults to time of last user access to node).
Returns: The result or FALSE on error.
File: modules/comment/comment.module | function comment_num_new($nid, $timestamp = 0) {
global $user;
if ($user->uid) {
// Retrieve the timestamp at which the current user last viewed this node.
if (!$timestamp) {
$timestamp = node_last_viewed($nid);
}
$timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT);
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5ec343c781 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_select_profile_form/7.x | I need the code for `install_select_profile_form($form, &$form_state, $profile_files)` in Drupal 7 (includes/install.core.inc). It must do this: Form constructor for the profile selection form. | Parameters:
- $form_state: Array of metadata about state of form processing.
- $profile_files: Array of .profile files, as returned from file_scan_directory().
File: includes/install.core.inc | function install_select_profile_form($form, &$form_state, $profile_files) {
$profiles = array();
$names = array();
foreach ($profile_files as $profile) {
// TODO: is this right?
include_once DRUPAL_ROOT . '/' . $profile->uri;
$details = install_profile_info($profile->name);
// Don't show hidden ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5ec9a69ebf | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21install.inc/function/db_run_tasks/7.x | In Drupal 7, write the function `db_run_tasks($driver)` (file includes/install.inc) so that it does the following: Ensures the environment for a Drupal database on a predefined connection. | This will run tasks that check that Drupal can perform all of the functions on a database, that Drupal needs. Tasks include simple checks like CREATE TABLE to database specific functions like stored procedures and client encoding.
File: includes/install.inc | function db_run_tasks($driver) {
db_installer_object($driver)->runTasks();
return TRUE;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5ecc8e33c2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_add_form/7.x | Implement `image_style_add_form($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form builder; Form for adding a new image style. | File: modules/image/image.admin.inc | function image_style_add_form($form, &$form_state) {
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Style name'),
'#default_value' => '',
'#required' => TRUE,
);
$form['name'] = array(
'#type' => 'machine_name',
'#description' => t('The name is used in URLs for generated im... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5ed7e23605 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.tokens.inc/function/user_token_info/7.x | In Drupal 7, write the function `user_token_info()` (file modules/user/user.tokens.inc) so that it does the following: Implements hook_token_info(). | File: modules/user/user.tokens.inc | function user_token_info() {
$types['user'] = array(
'name' => t('Users'),
'description' => t('Tokens related to individual user accounts.'),
'needs-data' => 'user',
);
$types['current-user'] = array(
'name' => t('Current user'),
'description' => t('Tokens related to the currently logged in us... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5ef4794a8c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/_aggregator_page_list/7.x | I need the code for `_aggregator_page_list($items, $op, $feed_source = '')` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Prints an aggregator page listing a number of feed items. | Various menu callbacks use this function to print their feeds.
Parameters:
- $items: The items to be listed.
- $op: Which form should be added to the items. Only 'categorize' is now recognized.
- $feed_source: The feed source URL.
Returns: The rendered list of items for the feed.
File: modules/aggregator/aggregator.... | function _aggregator_page_list($items, $op, $feed_source = '') {
if (user_access('administer news feeds') && ($op == 'categorize')) {
// Get form data.
$output = aggregator_categorize_items($items, $feed_source);
}
else {
// Assemble themed output.
$output = $feed_source;
foreach ($items as $i... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5f04da613c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_formatter_settings/7.x | In Drupal 7, write the function `field_info_formatter_settings($type)` (file modules/field/field.info.inc) so that it does the following: Returns a field formatter's default settings. | Parameters:
- $type: A field formatter type name.
Returns: The formatter type's default settings, as provided by hook_field_formatter_info(), or an empty array if type or settings are undefined.
File: modules/field/field.info.inc | function field_info_formatter_settings($type) {
$info = field_info_formatter_types($type);
return isset($info['settings']) ? $info['settings'] : array();
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5f2c25e6bb | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_data/7.x | In Drupal 7, write the function `menu_tree_data(array $links, array $parents = array(), $depth = 1)` (file includes/menu.inc) so that it does the following: Sorts and returns the built data representing a menu tree. | Parameters:
- $links: A flat array of menu links that are part of the menu. Each array element is an associative array of information about the menu link, containing the fields from the {menu_links} table, and optionally additional information from the {menu_router} table, if the menu item appears in both tables. This ... | function menu_tree_data(array $links, array $parents = array(), $depth = 1) {
// Reverse the array so we can use the more efficient array_pop() function.
$links = array_reverse($links);
return _menu_tree_data($links, $parents, $depth);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5f6ebb2428 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_site_maintenance_mode/7.x | In Drupal 7, write the function `system_site_maintenance_mode()` (file modules/system/system.admin.inc) so that it does the following: Form builder; Configure the site's maintenance status. | File: modules/system/system.admin.inc | function system_site_maintenance_mode() {
$form['maintenance_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Put site into maintenance mode'),
'#default_value' => variable_get('maintenance_mode', 0),
'#description' => t('When enabled, only users with the "Use the site in maintenance mode" <a hre... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5f85f1f644 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_cron_run/7.x | Implement `drupal_cron_run()` in PHP for Drupal 7. Required behavior: Executes a cron run when called. | Do not call this function from a test. Use $this->cronRun() instead.
Returns (bool): TRUE if cron ran successfully and FALSE if cron is already running.
File: includes/common.inc | function drupal_cron_run() {
// Allow execution to continue even if the request gets canceled.
@ignore_user_abort(TRUE);
// Prevent session information from being saved while cron is running.
$original_session_saving = drupal_save_session();
drupal_save_session(FALSE);
// Force the current user to anonymo... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5f91e6b6d6 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_help/7.x | In Drupal 7, write the function `simpletest_help($path, $arg)` (file modules/simpletest/simpletest.module) so that it does the following: Implements hook_help(). | File: modules/simpletest/simpletest.module | function simpletest_help($path, $arg) {
switch ($path) {
case 'admin/help#simpletest':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Testing module provides a framework for running automated unit tests. It can be used to verify a working state of Drupal before... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5f9b7ac4e5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_checkboxes_value/7.x | In Drupal 7, write the function `form_type_checkboxes_value($element, $input = FALSE)` (file includes/form.inc) so that it does the following: Determines the value for a checkboxes form element. | Parameters:
- $element: The form element whose value is being populated.
- $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.
Returns: The data that will appear in $form_state['values'] for this element, or nothing to use the default.
File: inclu... | function form_type_checkboxes_value($element, $input = FALSE) {
if ($input === FALSE) {
$value = array();
$element += array('#default_value' => array());
foreach ($element['#default_value'] as $key) {
$value[$key] = $key;
}
return $value;
}
elseif (is_array($input)) {
// Programmatic... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5fb434c138 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.processor.inc/function/aggregator_save_item/7.x | Implement `aggregator_save_item($edit)` in PHP for Drupal 7. Required behavior: Adds/edits/deletes an aggregator item. | Parameters:
- $edit: An associative array describing the item to be added/edited/deleted.
File: modules/aggregator/aggregator.processor.inc | function aggregator_save_item($edit) {
if ($edit['title'] && empty($edit['iid'])) {
$edit['iid'] = db_insert('aggregator_item')
->fields(array(
'title' => $edit['title'],
'link' => $edit['link'],
'author' => $edit['author'],
'description' => $edit['description'],
'gui... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5fc17e2ec2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/form_process_autocomplete/7.x | Implement `form_process_autocomplete($element)` in PHP for Drupal 7. Required behavior: Process function to prepare autocomplete data. | Parameters:
- $element: A textfield or other element with a #autocomplete_path.
Returns (array): The processed form element.
File: includes/form.inc | function form_process_autocomplete($element) {
$element['#autocomplete_input'] = array();
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
$element['#autocomplete_input']['#id'] = $element['#id'] .'-autocomplete';
// Force autocomplete to use non-clean URLs since th... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5fea7e80b8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_install_mkdir/7.x | Implement `drupal_install_mkdir($file, $mask, $message = TRUE)` in PHP for Drupal 7. Required behavior: Creates a directory with the specified permissions. | Parameters:
- $file: The name of the directory to create;
- $mask: The permissions of the directory to create.
- $message: (optional) Whether to output messages. Defaults to TRUE.
Returns: TRUE/FALSE whether or not the directory was successfully created.
File: includes/install.inc | function drupal_install_mkdir($file, $mask, $message = TRUE) {
$mod = 0;
$masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
foreach ($masks as $m) {
if ($mask & $m) {
switch ($m) {
case FILE_READABLE:
$mod |= 0444;
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-5feee35685 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_entity_info/7.x | Implement `user_entity_info()` in PHP for Drupal 7. Required behavior: Implements hook_entity_info(). | File: modules/user/user.module | function user_entity_info() {
$return = array(
'user' => array(
'label' => t('User'),
'controller class' => 'UserController',
'base table' => 'users',
'uri callback' => 'user_uri',
'label callback' => 'format_username',
'fieldable' => TRUE,
// $user->language is only the ... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-5ffd561528 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_validate_form/7.x | In Drupal 7, write the function `drupal_validate_form($form_id, &$form, &$form_state)` (file includes/form.inc) so that it does the following: Validates user-submitted form data in the $form_state array. | Parameters:
- $form_id: A unique string identifying the form for validation, submission, theming, and hook_form_alter functions.
- $form: An associative array containing the structure of the form, which is passed by reference. Form validation handlers are able to alter the form structure (like #process and #after_build... | function drupal_validate_form($form_id, &$form, &$form_state) {
$validated_forms = &drupal_static(__FUNCTION__, array());
if (isset($validated_forms[$form_id]) && empty($form_state['must_validate'])) {
return;
}
// If the session token was set by drupal_prepare_form(), ensure that it
// matches the curr... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-600cdacf24 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21xmlrpc.inc/function/xmlrpc_error_msg/7.x | Implement `xmlrpc_error_msg()` in PHP for Drupal 7. Required behavior: Returns the last XML-RPC client error message. | File: includes/xmlrpc.inc | function xmlrpc_error_msg() {
$error = xmlrpc_error();
return ($error != NULL ? $error->message : NULL);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-600ed4dda1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21file.inc/function/file_create_filename/7.x | In Drupal 7, write the function `file_create_filename($basename, $directory)` (file includes/file.inc) so that it does the following: Creates a full file path from a directory and filename. | If a file with the specified name already exists, an alternative will be used.
Parameters:
- $basename: String filename
- $directory: String containing the directory or parent URI.
Returns: File path consisting of $directory and a unique filename based off of $basename.
File: includes/file.inc | function file_create_filename($basename, $directory) {
$original = $basename;
// Strip control characters (ASCII value < 32). Though these are allowed in
// some filesystems, not many applications handle them well.
$basename = preg_replace('/[\x00-\x1F]/u', '_', $basename);
if (preg_last_error() !== PREG_NO_E... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-600fb18134 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/_profile_update_user_fields/7.x | In Drupal 7, write the function `_profile_update_user_fields($fields, $account)` (file modules/profile/profile.module) so that it does the following: Helper function: update an array of user fields by calling profile_view_field | File: modules/profile/profile.module | function _profile_update_user_fields($fields, $account) {
foreach ($fields as $key => $field) {
$fields[$key]->value = profile_view_field($account, $field);
}
return $fields;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-60447221f3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_search_result/7.x | Give me the example code for `hook_node_search_result($node)` in Drupal 7. Hook description: Act on a node being displayed as a search result. | This hook is invoked from node_search_execute(), after node_load() and node_view() have been called.
Parameters:
- $node: The node being displayed in a search result.
Returns (array): Extra information to be displayed with search result. This information should be presented as an associative array. It will be concate... | function hook_node_search_result($node) {
$comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
return array('comment' => format_plural($comments, '1 comment', '@count comments'));
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-604909533a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/_update_build_fetch_url/7.x | Implement `_update_build_fetch_url($project, $site_key = '')` in PHP for Drupal 7. Required behavior: Generates the URL to fetch information about project updates. | This figures out the right URL to use, based on the project's .info file and the global defaults. Appends optional query arguments when the site is configured to report usage stats.
Parameters:
- $project: The array of project information from update_get_projects().
- $site_key: (optional) The anonymous site key hash.... | function _update_build_fetch_url($project, $site_key = '') {
$name = $project['name'];
$url = _update_get_fetch_url_base($project);
$url .= '/' . $name . '/' . DRUPAL_CORE_COMPATIBILITY;
// Only append usage information if we have a site key and the project is
// enabled. We do not want to record usage stati... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-605ced07b9 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21search%21search.pages.inc/function/template_preprocess_search_result/7.x | In Drupal 7, write the function `template_preprocess_search_result(&$variables)` (file modules/search/search.pages.inc) so that it does the following: Process variables for search-result.tpl.php. | The $variables array contains the following arguments:
- $result
- $module
File: modules/search/search.pages.inc | function template_preprocess_search_result(&$variables) {
global $language;
$result = $variables['result'];
$variables['url'] = check_url($result['link']);
$variables['title'] = check_plain($result['title']);
if (isset($result['language']) && $result['language'] != $language->language && $result['language'] ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-606fc8af85 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translation_filter_form_validate/7.x | In Drupal 7, write the function `locale_translation_filter_form_validate($form, &$form_state)` (file modules/locale/locale.admin.inc) so that it does the following: Validate result from locale translation filter form. | File: modules/locale/locale.admin.inc | function locale_translation_filter_form_validate($form, &$form_state) {
if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['language']) && empty($form_state['values']['group'])) {
form_set_error('type', t('You must select something to filter by.'));
}
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-607ee0ff37 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/_forum_update_forum_index/7.x | Implement `_forum_update_forum_index($nid)` in PHP for Drupal 7. Required behavior: Updates the taxonomy index for a given node. | Parameters:
- $nid: The ID of the node to update.
File: modules/forum/forum.module | function _forum_update_forum_index($nid) {
$count = db_query('SELECT COUNT(cid) FROM {comment} c INNER JOIN {forum_index} i ON c.nid = i.nid WHERE c.nid = :nid AND c.status = :status', array(
':nid' => $nid,
':status' => COMMENT_PUBLISHED,
))->fetchField();
if ($count > 0) {
// Comments exist.
$l... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-60852ae7d2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21translation%21translation.module/function/translation_permission/7.x | In Drupal 7, write the function `translation_permission()` (file modules/translation/translation.module) so that it does the following: Implements hook_permission(). | File: modules/translation/translation.module | function translation_permission() {
return array(
'translate content' => array(
'title' => t('Translate content'),
),
);
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-6089d13638 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_7000/7.x | In Drupal 7, write the function `image_update_7000()` (file modules/image/image.install) so that it does the following: Install the schema for users upgrading from the contributed module. | File: modules/image/image.install | function image_update_7000() {
if (!db_table_exists('image_styles')) {
$schema = array();
$schema['cache_image'] = system_schema_cache_7054();
$schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.';
$schema['image_styles'] = ar... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-60936689ff | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/_node_save_revision/7.x | Implement `_node_save_revision($node, $uid, $update = NULL)` in PHP for Drupal 7. Required behavior: Helper function to save a revision with the uid of the current user. | The resulting revision ID is available afterward in $node->vid.
Parameters:
- $node: A node object.
- $uid: The current user's UID.
- $update: (optional) An array of primary keys' field names to update.
File: modules/node/node.module | function _node_save_revision($node, $uid, $update = NULL) {
$temp_uid = $node->uid;
$node->uid = $uid;
if (isset($update)) {
drupal_write_record('node_revision', $node, $update);
}
else {
drupal_write_record('node_revision', $node);
}
// Have node object still show node owner's uid, not revision a... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-609c177428 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_menu/7.x | Implement `simpletest_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu(). | File: modules/simpletest/simpletest.module | function simpletest_menu() {
$items['admin/config/development/testing'] = array(
'title' => 'Testing',
'page callback' => 'drupal_get_form',
'page arguments' => array('simpletest_test_form'),
'description' => 'Run tests against Drupal core and your active modules. These tests help assure that your sit... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-609f507777 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/entity_prepare_view/7.x | Implement `entity_prepare_view($entity_type, $entities, $langcode = NULL)` in PHP for Drupal 7. Required behavior: Invoke hook_entity_prepare_view(). | If adding a new entity similar to nodes, comments or users, you should invoke this function during the ENTITY_build_content() or ENTITY_view_multiple() phases of rendering to allow other modules to alter the objects during this phase. This is needed for situations where information needs to be loaded outside of ENTITY_... | function entity_prepare_view($entity_type, $entities, $langcode = NULL) {
if (!isset($langcode)) {
$langcode = $GLOBALS['language_content']->language;
}
// To ensure hooks are only run once per entity, check for an
// entity_view_prepared flag and only process items without it.
// @todo: resolve this mor... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-60a143e96a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_xmlrpc/7.x | In Drupal 7, show an example implementation for `hook_xmlrpc()` (modules/system/system.api.php): Register XML-RPC callbacks. | This hook lets a module register callback functions to be called when particular XML-RPC methods are invoked by a client.
Returns: An array which maps XML-RPC methods to Drupal functions. Each array element is either a pair of method => function or an array with four entries: - The XML-RPC method name (for example, mo... | function hook_xmlrpc() {
return array(
'drupal.login' => 'drupal_login',
array(
'drupal.site.ping',
'drupal_directory_ping',
array('boolean', 'string', 'string', 'string', 'string', 'string'),
t('Handling ping request'))
);
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-60a7d4136d | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.pages.inc/function/taxonomy_term_page/7.x | I need the code for `taxonomy_term_page($term)` in Drupal 7 (modules/taxonomy/taxonomy.pages.inc). It must do this: Menu callback; displays all nodes associated with a term. | Parameters:
- $term: The taxonomy term.
Returns: The page content.
File: modules/taxonomy/taxonomy.pages.inc | function taxonomy_term_page($term) {
// If there is a menu link to this term, the link becomes the last part of
// the active trail, and the link name becomes the page title. Thus, we must
// explicitly set the page title to be the term title.
drupal_set_title($term->name);
// Build breadcrumb based on the h... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-60af327f07 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_load/7.x | Give me the example code for `hook_entity_load($entities, $type)` in Drupal 7. Hook description: Act on entities when loaded. | This is a generic load hook called for all entity types loaded via the entity API.
Parameters:
- $entities: The entities keyed by entity ID.
- $type: The type of entities being loaded (i.e. node, user, comment).
File: modules/system/system.api.php | function hook_entity_load($entities, $type) {
foreach ($entities as $entity) {
$entity->foo = mymodule_add_something($entity, $type);
}
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-60b8d04e4e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.tokens.inc/function/node_tokens/7.x | I need the code for `node_tokens($type, $tokens, array $data = array(), array $options = array())` in Drupal 7 (modules/node/node.tokens.inc). It must do this: Implements hook_tokens(). | File: modules/node/node.tokens.inc | function node_tokens($type, $tokens, array $data = array(), array $options = array()) {
$url_options = array('absolute' => TRUE);
if (isset($options['language'])) {
$url_options['language'] = $options['language'];
$language_code = $options['language']->language;
}
else {
$language_code = NULL;
}
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-60bc68e419 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_themes_admin_form_submit/7.x | Implement `system_themes_admin_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Process system_themes_admin_form form submissions. | File: modules/system/system.admin.inc | function system_themes_admin_form_submit($form, &$form_state) {
drupal_set_message(t('The configuration options have been saved.'));
variable_set('admin_theme', $form_state['values']['admin_theme']);
variable_set('node_admin_theme', $form_state['values']['node_admin_theme']);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-60c27dba68 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_update_totals/7.x | In Drupal 7, write the function `search_update_totals()` (file modules/search/search.module) so that it does the following: Updates the {search_total} database table. | This function is called on shutdown to ensure that {search_total} is always up to date (even if cron times out or otherwise fails).
File: modules/search/search.module | function search_update_totals() {
// Update word IDF (Inverse Document Frequency) counts for new/changed words.
foreach (search_dirty() as $word => $dummy) {
// Get total count
$total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'slave'))-... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-60e598c90e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_node_access/7.x | I need the code for `node_node_access($node, $op, $account)` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_node_access(). | File: modules/node/node.module | function node_node_access($node, $op, $account) {
$type = is_string($node) ? $node : $node->type;
if (in_array($type, node_permissions_get_configured_types())) {
if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {
return NODE_ACCESS_ALLOW;
}
if ($op == 'update') {
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-6121aa05f0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.admin.inc/function/taxonomy_form_term_validate/7.x | In Drupal 7, write the function `taxonomy_form_term_validate($form, &$form_state)` (file modules/taxonomy/taxonomy.admin.inc) so that it does the following: Validation handler for the term form. | File: modules/taxonomy/taxonomy.admin.inc | function taxonomy_form_term_validate($form, &$form_state) {
entity_form_field_validate('taxonomy_term', $form, $form_state);
// Ensure numeric values.
if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) {
form_set_error('weight', t('Weight value must be numeric.'));
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-612cf89b51 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_list_permissions/7.x | Implement `node_list_permissions($type)` in PHP for Drupal 7. Required behavior: Helper function to generate standard node permission list for a given type. | Parameters:
- $type: The machine-readable name of the node type.
Returns (array): An array of permission names and descriptions.
File: modules/node/node.module | function node_list_permissions($type) {
$info = node_type_get_type($type);
// Build standard list of node permissions for this type.
$perms = array(
"create $type content" => array(
'title' => t('%type_name: Create new content', array('%type_name' => $info->name)),
),
"edit own $type content" =... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-6142a7f183 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_actions_manage_form/7.x | Implement `system_actions_manage_form($form, &$form_state, $options = array())` in PHP for Drupal 7. Required behavior: Define the form for the actions overview page. | Parameters:
- $form_state: An associative array containing the current state of the form; not used.
- $options: An array of configurable actions.
Returns: Form definition.
File: modules/system/system.admin.inc | function system_actions_manage_form($form, &$form_state, $options = array()) {
$form['parent'] = array(
'#type' => 'fieldset',
'#title' => t('Create an advanced action'),
'#attributes' => array('class' => array('container-inline')),
);
$form['parent']['action'] = array(
'#type' => 'select',
'#... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-614beb0402 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/announcements_feed_cron/7.x | In Drupal 7, write the function `announcements_feed_cron()` (file modules/announcements_feed/announcements_feed.module) so that it does the following: Implements hook_cron(). | File: modules/announcements_feed/announcements_feed.module | function announcements_feed_cron() {
module_load_include('inc', 'announcements_feed', 'announcements_feed');
$cron_interval = variable_get('announcements_feed_cron_interval', ANNOUNCEMENTS_FEED_DEFAULT_CRON_INTERVAL);
$last_check = variable_get('announcements_feed_last_fetch', 0);
$time = time();
if (($time -... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-6163ebfd39 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_admin_menu_block_page/7.x | Implement `system_admin_menu_block_page()` in PHP for Drupal 7. Required behavior: Provide a single block from the administration menu as a page. | This function is often a destination for these blocks. For example, 'admin/structure/types' needs to have a destination to be valid in the Drupal menu system, but too much information there might be hidden, so we supply the contents of the block.
Returns: The output HTML.
File: modules/system/system.admin.inc | function system_admin_menu_block_page() {
$item = menu_get_item();
if ($content = system_admin_menu_block($item)) {
$output = theme('admin_block_content', array('content' => $content));
}
else {
$output = t('You do not have any administrative items.');
}
return $output;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-616642ea26 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_reset_item/7.x | I need the code for `menu_reset_item($link)` in Drupal 7 (modules/menu/menu.module). It must do this: Reset a system-defined menu link. | File: modules/menu/menu.module | function menu_reset_item($link) {
// To reset the link to its original values, we need to retrieve its
// definition from hook_menu(). Otherwise, for example, the link's menu would
// not be reset, because properties like the original 'menu_name' are not
// stored anywhere else. Since resetting a link happens r... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-6174a95c97 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21modules%21list%21list.install/function/_list_update_7001_extract_allowed_values/7.x | In Drupal 7, write the function `_list_update_7001_extract_allowed_values($string, $position_keys)` (file modules/field/modules/list/list.install) so that it does the following: Helper function for list_update_7001: extract allowed values from a string. | This reproduces the parsing logic in use before D7 RC2.
File: modules/field/modules/list/list.install | function _list_update_7001_extract_allowed_values($string, $position_keys) {
$values = array();
$list = explode("\n", $string);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
foreach ($list as $key => $value) {
// Check for a manually specified key.
if (strpos($value, '|') ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-617d33d196 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_navigation_links/7.x | Implement `menu_navigation_links($menu_name, $level = 0)` in PHP for Drupal 7. Required behavior: Returns an array of links for a navigation menu. | Parameters:
- $menu_name: The name of the menu.
- $level: Optional, the depth of the menu to be returned.
Returns: An array of links of the specified menu and level.
File: includes/menu.inc | function menu_navigation_links($menu_name, $level = 0) {
// Don't even bother querying the menu table if no menu is specified.
if (empty($menu_name)) {
return array();
}
// Get the menu hierarchy for the current page.
$tree = menu_tree_page_data($menu_name, $level + 1);
// Go down the active trail unt... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-618cb1ca8a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/_node_mass_update_batch_finished/7.x | I need the code for `_node_mass_update_batch_finished($success, $results, $operations)` in Drupal 7 (modules/node/node.admin.inc). It must do this: Implements callback_batch_finished(). | Reports the status of batch operation for node_mass_update().
Parameters:
- $success (bool): A boolean indicating whether the batch mass update operation successfully concluded.
- $results (int): The number of nodes updated via the batch mode process.
- $operations (array): An array of function calls (not used in this... | function _node_mass_update_batch_finished($success, $results, $operations) {
if ($success) {
drupal_set_message(t('The update has been performed.'));
}
else {
drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
$message = format_plural(count($results), '1 item success... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-619856da72 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/_system_rebuild_theme_data/7.x | In Drupal 7, write the function `_system_rebuild_theme_data()` (file modules/system/system.module) so that it does the following: Helper function to scan and collect theme .info data and their engines. | Returns: An associative array of themes information.
File: modules/system/system.module | function _system_rebuild_theme_data() {
// Find themes
$themes = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'themes');
// Allow modules to add further themes.
if ($module_themes = module_invoke_all('system_theme_info')) {
foreach ($module_themes as $name => $uri) {
// @see ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-61c51c00f0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_html_tag/7.x | I need the code for `theme_html_tag($variables)` in Drupal 7 (includes/theme.inc). It must do this: Returns HTML for a generic HTML tag with attributes. | Parameters:
- $variables: An associative array containing: - element: An associative array describing the tag: - #tag: The tag name to output. Typical tags added to the HTML HEAD: - meta: To provide meta information, such as a page refresh. - link: To refer to stylesheets and other contextual information. - script: To ... | function theme_html_tag($variables) {
$element = $variables['element'];
$attributes = isset($element['#attributes']) ? drupal_attributes($element['#attributes']) : '';
if (!isset($element['#value'])) {
return '<' . $element['#tag'] . $attributes . " />\n";
}
else {
$output = '<' . $element['#tag'] . $... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-61ce142bee | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/form_options_flatten/7.x | Implement `form_options_flatten($array)` in PHP for Drupal 7. Required behavior: Allows PHP array processing of multiple select options with the same value. | Used for form select elements which need to validate HTML option groups and multiple options which may return the same value. Associative PHP arrays cannot handle these structures, since they share a common key.
Parameters:
- $array: The form options array to process.
Returns: An array with all hierarchical elements ... | function form_options_flatten($array) {
// Always reset static var when first entering the recursion.
drupal_static_reset('_form_options_flatten');
return _form_options_flatten($array);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-62045cd4fb | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_save/7.x | In Drupal 7, write the function `menu_save($menu)` (file modules/menu/menu.module) so that it does the following: Save a custom menu. | Parameters:
- $menu: An array representing a custom menu: - menu_name: The unique name of the custom menu (composed of lowercase letters, numbers, and hyphens). - title: The human readable menu title. - description: The custom menu description. Modules should always pass a fully populated $menu when saving a custom men... | function menu_save($menu) {
$status = db_merge('menu_custom')
->key(array('menu_name' => $menu['menu_name']))
->fields(array(
'title' => $menu['title'],
'description' => $menu['description'],
))
->execute();
menu_cache_clear_all();
switch ($status) {
case SAVED_NEW:
// Make ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-62188cb2a3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_form_path_admin_form_alter/7.x | I need the code for `locale_form_path_admin_form_alter(&$form, &$form_state)` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_form_FORM_ID_alter(). | File: modules/locale/locale.module | function locale_form_path_admin_form_alter(&$form, &$form_state) {
$form['language'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#options' => array(LANGUAGE_NONE => t('All languages')) + locale_language_list('name'),
'#default_value' => $form['language']['#value'],
'#weight' => -10,
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-6221a0b74c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.manager.inc/function/update_manager_install_form_validate/7.x | Implement `update_manager_install_form_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form validation handler for update_manager_install_form(). | File: modules/update/update.manager.inc | function update_manager_install_form_validate($form, &$form_state) {
if (!($form_state['values']['project_url'] XOR !empty($_FILES['files']['name']['project_upload']))) {
form_set_error('project_url', t('You must either provide a URL or upload an archive file to install.'));
}
if ($form_state['values']['proj... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-6242c38f7d | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_node_load/7.x | Implement `user_node_load($nodes, $types)` in PHP for Drupal 7. Required behavior: Implements hook_node_load(). | File: modules/user/user.module | function user_node_load($nodes, $types) {
// Build an array of all uids for node authors, keyed by nid.
$uids = array();
foreach ($nodes as $nid => $node) {
$uids[$nid] = $node->uid;
}
// Fetch name, picture, and data for these users.
$user_fields = db_query("SELECT uid, name, picture, data FROM {users... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-6258f834de | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_verify_update_archive/7.x | Implement `update_verify_update_archive($project, $archive_file, $directory)` in PHP for Drupal 7. Required behavior: Implements hook_verify_update_archive(). | First, we ensure that the archive isn't a copy of Drupal core, which the update manager does not yet support. See http://drupal.org/node/606592
Then, we make sure that at least one module included in the archive file has an .info file which claims that the code is compatible with the current version of Drupal core.
F... | function update_verify_update_archive($project, $archive_file, $directory) {
$errors = array();
// Make sure this isn't a tarball of Drupal core.
if (
file_exists("$directory/$project/index.php")
&& file_exists("$directory/$project/update.php")
&& file_exists("$directory/$project/includes/bootstrap.i... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-6283a85d49 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/date_iso8601/7.x | I need the code for `date_iso8601($date)` in Drupal 7 (includes/common.inc). It must do this: Returns an ISO8601 formatted date based on the given date. | Callback for use within hook_rdf_mapping() implementations.
Parameters:
- $date: A UNIX timestamp.
Returns (string): An ISO8601 formatted date.
File: includes/common.inc | function date_iso8601($date) {
// The DATE_ISO8601 constant cannot be used here because it does not match
// date('c') and produces invalid RDF markup.
return date('c', $date);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-628dc81da5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_operations/7.x | Give me the example code for `hook_node_operations()` in Drupal 7. Hook description: Add mass node operations. | This hook enables modules to inject custom operations into the mass operations dropdown found at admin/content, by associating a callback function with the operation, which is called when the form is submitted. The callback function receives one initial argument, which is an array of the checked nodes.
Returns: An arr... | function hook_node_operations() {
$operations = array(
'publish' => array(
'label' => t('Publish selected content'),
'callback' => 'node_mass_update',
'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED)),
),
'unpublish' => array(
'label' => t('Unpublish sel... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.