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-f3ffbddb75 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21path%21path.module/function/path_taxonomy_term_update/7.x | Implement `path_taxonomy_term_update($term)` in PHP for Drupal 7. Required behavior: Implements hook_taxonomy_term_update(). | File: modules/path/path.module | function path_taxonomy_term_update($term) {
if (isset($term->path)) {
$path = $term->path;
$path['alias'] = trim($path['alias']);
// Delete old alias if user erased it.
if (!empty($path['pid']) && empty($path['alias'])) {
path_delete($path['pid']);
}
// Only save a non-empty alias.
i... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f420173823 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_admin_paths_alter/7.x | 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. | Parameters:
- $paths: An associative array of administrative paths, as defined by implementations of hook_admin_paths().
File: modules/system/system.api.php | function hook_admin_paths_alter(&$paths) {
// Treat all user pages as administrative.
$paths['user'] = TRUE;
$paths['user/*'] = TRUE;
// Treat the forum topic node form as a non-administrative page.
$paths['node/add/forum'] = FALSE;
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-f431595869 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21language.inc/function/language_negotiation_get/7.x | 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. | This has two possible behaviors:
- If $provider_id is given return its ID if enabled, FALSE otherwise.
- If no ID is passed the first enabled language negotiation provider is
returned.
Parameters:
- $type: The language negotiation provider type.
- $provider_id: The language negotiation provider ID.
Returns: The ... | function language_negotiation_get($type, $provider_id = NULL) {
$negotiation = variable_get("language_negotiation_$type", array());
if (empty($negotiation)) {
return empty($provider_id) ? LANGUAGE_NEGOTIATION_DEFAULT : FALSE;
}
if (empty($provider_id)) {
return key($negotiation);
}
if (isset($neg... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f44fd74bdc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_html_head_link/7.x | 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. | 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.
Parameters:
- $attributes: Associative array of element attributes inclu... | function drupal_add_html_head_link($attributes, $header = FALSE) {
$element = array(
'#tag' => 'link',
'#attributes' => $attributes,
);
$href = $attributes['href'];
if ($header) {
// Also add a HTTP header "Link:".
$href = '<' . $attributes['href'] . '>;';
unset($attributes['href']);
$e... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f45bf08f92 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_block_info/7.x | I need the code for `user_block_info()` in Drupal 7 (modules/user/user.module). It must do this: Implements hook_block_info(). | File: modules/user/user.module | function user_block_info() {
global $user;
$blocks['login']['info'] = t('User login');
// Not worth caching.
$blocks['login']['cache'] = DRUPAL_NO_CACHE;
$blocks['new']['info'] = t('Who\'s new');
$blocks['new']['properties']['administrative'] = TRUE;
// Too dynamic to cache.
$blocks['online']['info']... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f46de7616b | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_update_instance/7.x | Implement `field_update_instance($instance)` in PHP for Drupal 7. Required behavior: Updates an instance of a field. | Parameters:
- $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. ... | function field_update_instance($instance) {
// Check that the specified field exists.
$field = field_read_field($instance['field_name']);
if (empty($field)) {
throw new FieldException(t('Attempt to update an instance of a nonexistent field @field.', array('@field' => $instance['field_name'])));
}
// Chec... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f46e006062 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/_menu_get_options/7.x | 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. | File: modules/menu/menu.module | function _menu_get_options($menus, $available_menus, $item) {
global $menu_admin;
$menu_admin = TRUE;
// If the item has children, there is an added limit to the depth of valid parents.
if (isset($item['parent_depth_limit'])) {
$limit = $item['parent_depth_limit'];
}
else {
$limit = _menu_parent_de... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f48658b896 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21php%21php.module/function/php_help/7.x | Implement `php_help($path, $arg)` in PHP for Drupal 7. Required behavior: Implements hook_help(). | File: modules/php/php.module | function php_help($path, $arg) {
switch ($path) {
case 'admin/help#php':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The PHP filter module adds a PHP filter to your site, for use with <a href="@filter">text formats</a>. This filter adds the ability to execute PH... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f4b8056108 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7002/7.x | Implement `taxonomy_update_7002()` in PHP for Drupal 7. Required behavior: Add {vocabulary}.machine_name column. | File: modules/taxonomy/taxonomy.install | function taxonomy_update_7002() {
$field = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The vocabulary machine name.',
);
db_add_field('taxonomy_vocabulary', 'machine_name', $field);
// Do a direct query here, rather than calling taxon... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f4c9518b69 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_feed/7.x | 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. | Generates an RSS feed from an array of node IDs, and prints it with an HTTP header, with Content Type set to RSS/XML.
Parameters:
- $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.
- $channel: An associative array... | function node_feed($nids = FALSE, $channel = array()) {
global $base_url, $language_content;
if ($nids === FALSE) {
$nids = db_select('node', 'n')
->fields('n', array('nid', 'created'))
->condition('n.promote', 1)
->condition('n.status', 1)
->orderBy('n.created', 'DESC')
->range(0... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f4d3dd06ee | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_modules_confirm_form/7.x | 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. | Parameters:
- $modules: Array of module file objects as returned from system_rebuild_module_data().
- $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.
File: modules/system/system.admin.inc | function system_modules_confirm_form($modules, $storage) {
$items = array();
$form['validation_modules'] = array('#type' => 'value', '#value' => $modules);
$form['status']['#tree'] = TRUE;
foreach ($storage['more_required'] as $info) {
$t_argument = array(
'@module' => $info['name'],
'@require... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f4e2fdc477 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_field_storage_pre_insert/7.x | Implement `forum_field_storage_pre_insert($entity_type, $entity, &$skip_fields)` in PHP for Drupal 7. Required behavior: Implements hook_field_storage_pre_insert(). | File: modules/forum/forum.module | function forum_field_storage_pre_insert($entity_type, $entity, &$skip_fields) {
if ($entity_type == 'node' && $entity->status && _forum_node_check_node_type($entity)) {
$query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
fore... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f4e7eec212 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_dependencies/7.x | In Drupal 7, write the function `system_update_dependencies()` (file modules/system/system.install) so that it does the following: Implements hook_update_dependencies(). | File: modules/system/system.install | function system_update_dependencies() {
// system_update_7053() queries the {block} table, so it must run after
// block_update_7002(), which creates that table.
$dependencies['system'][7053] = array(
'block' => 7002,
);
// system_update_7061() queries the {node_revision} table, so it must run
// after... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f4f4e42a0e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.compare.inc/function/_update_process_info_list/7.x | 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. | 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 ... | function _update_process_info_list(&$projects, $list, $project_type, $status) {
$admin_theme = variable_get('admin_theme', 'seven');
foreach ($list as $file) {
// The admin theme is a special case. It should always be considered enabled
// for the purposes of update checking.
if ($file->name === $admin_... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f4fa7d6f88 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.api.php/function/hook_update_projects_alter/7.x | 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. | 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... | function hook_update_projects_alter(&$projects) {
// Hide a site-specific module from the list.
unset($projects['site_specific_module']);
// Add a disabled module to the list.
// The key for the array should be the machine-readable project "short name".
$projects['disabled_project_name'] = array(
// Mach... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-f52d66711a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_instance_settings_form/7.x | Implement `image_field_instance_settings_form($field, $instance)` in PHP for Drupal 7. Required behavior: Implements hook_field_instance_settings_form(). | File: modules/image/image.field.inc | function image_field_instance_settings_form($field, $instance) {
$settings = $instance['settings'];
// Use the file field instance settings form as a basis.
$form = file_field_instance_settings_form($field, $instance);
// Add maximum and minimum resolution settings.
$max_resolution = explode('x', $settings[... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f54d8a1464 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.tokens.inc/function/user_tokens/7.x | 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(). | File: modules/user/user.tokens.inc | function user_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-f558dfaefe | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_block_info/7.x | I need the code for `menu_block_info()` in Drupal 7 (modules/menu/menu.module). It must do this: Implements hook_block_info(). | File: modules/menu/menu.module | function menu_block_info() {
$menus = menu_get_menus(FALSE);
$blocks = array();
foreach ($menus as $name => $title) {
$blocks[$name]['info'] = check_plain($title);
// Menu blocks can't be cached because each menu item can have
// a custom access callback. menu.inc manages its own caching.
$blocks... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f57e0b80b8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_menu_unassign_access/7.x | 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. | Returns (bool): TRUE if there are triggers that the user can unassign, FALSE otherwise.
File: modules/trigger/trigger.module | function trigger_menu_unassign_access() {
if (!user_access('administer actions')) {
return FALSE;
}
$count = db_select('trigger_assignments')
->countQuery()
->execute()
->fetchField();
return $count > 0;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f5a7e93442 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_already_done_error/7.x | 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. | File: includes/install.core.inc | function install_already_done_error() {
global $base_url;
drupal_set_title(st('Drupal already installed'));
return st('<ul><li>To start over, you must empty your existing database.</li><li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f5af3289d2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21file.inc/function/file_validate_name_length/7.x | 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. | Parameters:
- $file: A Drupal file object.
Returns: An array. If the file name is too long, it will contain an error message.
File: includes/file.inc | function file_validate_name_length(stdClass $file) {
$errors = array();
if (empty($file->filename)) {
$errors[] = t("The file's name is empty. Please give a name to the file.");
}
if (strlen($file->filename) > 240) {
$errors[] = t("The file's name exceeds the 240 characters limit. Please rename the fil... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f5d1f39fe1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_update_7011/7.x | Implement `taxonomy_update_7011(&$sandbox)` in PHP for Drupal 7. Required behavior: Drop unpublished nodes from the index. | File: modules/taxonomy/taxonomy.install | function taxonomy_update_7011(&$sandbox) {
// Initialize information needed by the batch update system.
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$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... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f5d9edccdb | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_overview_submit/7.x | 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(). | File: modules/filter/filter.admin.inc | function filter_admin_overview_submit($form, &$form_state) {
foreach ($form_state['values']['formats'] as $id => $data) {
if (is_array($data) && isset($data['weight'])) {
// Only update if this is a form element with weight.
db_update('filter_format')
->fields(array('weight' => $data['weight']... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f5e379f079 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_goto_action_form/7.x | 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(). | File: modules/system/system.module | function system_goto_action_form($context) {
$form['url'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#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.'),
'#default_value' => isset($co... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f5fffa99a2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_insert/7.x | 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. | 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.
Parameters:
- $entity_type: The type of $entity; e.g. 'node' or 'user'.
- $entity: The entity with fields to save.
Returns: Default values (if any) ... | function field_attach_insert($entity_type, $entity) {
_field_invoke_default('insert', $entity_type, $entity);
_field_invoke('insert', $entity_type, $entity);
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
// Let any module insert field data before the storage engine, accumulating
// s... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f617deeff5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_field_language_alter/7.x | 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(). | File: modules/locale/locale.module | function locale_field_language_alter(&$display_language, $context) {
// Do not apply core language fallback rules if they are disabled or if Locale
// is not registered as a translation handler.
if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'loc... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f62caf2cee | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_unpublish_by_keyword_action_form/7.x | Implement `node_unpublish_by_keyword_action_form($context)` in PHP for Drupal 7. Required behavior: Generates settings form for node_unpublish_by_keyword_action(). | Parameters:
- $context (array): Array of additional information about what triggered this action.
Returns (array): A form array.
File: modules/node/node.module | function node_unpublish_by_keyword_action_form($context) {
$form['keywords'] = array(
'#title' => t('Keywords'),
'#type' => 'textarea',
'#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, bunge... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f641235022 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_checkboxes/7.x | Implement `theme_checkboxes($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a set of checkbox form elements. | Parameters:
- $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #children, #attributes.
File: includes/form.inc | function theme_checkboxes($variables) {
$element = $variables['element'];
$attributes = array();
if (isset($element['#id'])) {
$attributes['id'] = $element['#id'];
}
$attributes['class'][] = 'form-checkboxes';
if (!empty($element['#attributes']['class'])) {
$attributes['class'] = array_merge($attrib... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f65ef42eec | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_save/7.x | 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. | Parameters:
- $image: An image object.
- $destination: A string file URI or path where the image should be saved.
Returns: TRUE or FALSE, based on success.
File: modules/system/image.gd.inc | function image_gd_save(stdClass $image, $destination) {
$scheme = file_uri_scheme($destination);
// Work around lack of stream wrapper support in imagejpeg() and imagepng().
if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
// If destination is not local, save image to temporary local file.
$loc... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f67de9a30e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_html_to_text/7.x | 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. | 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.
We deliberately use LF rather than CRLF, see drupal_mail().
This function provides suitable alternatives for the following tags: <a> <em> <i> <strong> <b> <br> <p> <blockquote> <u... | function drupal_html_to_text($string, $allowed_tags = NULL) {
// Cache list of supported tags.
static $supported_tags;
if (empty($supported_tags)) {
$supported_tags = array('a', 'em', 'i', 'strong', 'b', 'br', 'p', 'blockquote', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr');
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f6948ec6ba | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_block_info/7.x | In Drupal 7, write the function `comment_block_info()` (file modules/comment/comment.module) so that it does the following: Implements hook_block_info(). | File: modules/comment/comment.module | function comment_block_info() {
$blocks['recent']['info'] = t('Recent comments');
$blocks['recent']['properties']['administrative'] = TRUE;
return $blocks;
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f6a2f7ac0f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_links_clone/7.x | 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. | Parameters:
- $links: An array of menu links to clone.
- $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.
Returns: An array of menu links with the same properties as the passed-in array, ... | function menu_links_clone($links, $menu_name = NULL) {
foreach ($links as &$link) {
unset($link['mlid']);
unset($link['plid']);
if (isset($menu_name)) {
$link['menu_name'] = $menu_name;
}
}
return $links;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f6df349cd4 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_date_format_save/7.x | 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. | Parameters:
- $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.
- $dfid: If set, replace the ex... | function system_date_format_save($date_format, $dfid = 0) {
$info = array();
$info['dfid'] = $dfid;
$info['type'] = $date_format['type'];
$info['format'] = $date_format['format'];
$info['locked'] = $date_format['locked'];
// Update date_format table.
if (!empty($date_format['is_new'])) {
drupal_write... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f6e2c34230 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21update%21update.authorize.inc/function/update_authorize_run_update/7.x | 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. | Callback for system_authorized_init() in update_manager_update_ready_form_submit().
Parameters:
- $filetransfer: The FileTransfer object created by authorize.php for use during this operation.
- $projects: A nested array of projects to install into the live webroot, keyed by project name. Each subarray contains the fo... | function update_authorize_run_update($filetransfer, $projects) {
$operations = array();
foreach ($projects as $project => $project_info) {
$operations[] = array(
'update_authorize_batch_copy_project',
array(
$project_info['project'],
$project_info['updater_name'],
$project_in... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7088cca6c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_delete_field/7.x | Give me the example code for `hook_field_storage_delete_field($field)` in Drupal 7. Hook description: Act on deletion of a field. | This hook is invoked from field_delete_field() to ask the field storage module to mark all information stored in the field for deletion.
Parameters:
- $field: The field being deleted.
File: modules/field/field.api.php | function hook_field_storage_delete_field($field) {
// Mark all data associated with the field for deletion.
$field['deleted'] = 0;
$table = _field_sql_storage_tablename($field);
$revision_table = _field_sql_storage_revision_tablename($field);
db_update($table)
->fields(array('deleted' => 1))
->execute... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-f70b4a6ab9 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu_alter/7.x | 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. | 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.
Parameters:
- $items: Associative array of menu router definitions returned from hook... | function hook_menu_alter(&$items) {
// Example - disable the page at node/add
$items['node/add']['access callback'] = FALSE;
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-f70bafc803 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_menu_subtree_data/7.x | 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. | 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.
Parameters:
- $link: A fully loaded menu link.
Returns: A subtree of menu links in an array, in the order they should be rendered.
File: modules/book/book.module | function book_menu_subtree_data($link) {
$tree = &drupal_static(__FUNCTION__, array());
// Generate a cache ID (cid) specific for this $menu_name and $link.
$cid = 'links:' . $link['menu_name'] . ':subtree-cid:' . $link['mlid'];
if (!isset($tree[$cid])) {
$cache = cache_get($cid, 'cache_menu');
if ($... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f70d2bc999 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_form_build_preview/7.x | Implement `node_form_build_preview($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for node_form(). | Handles the 'Preview' button on the node form.
File: modules/node/node.pages.inc | function node_form_build_preview($form, &$form_state) {
$node = node_form_submit_build_node($form, $form_state);
$form_state['node_preview'] = node_preview($node);
$form_state['rebuild'] = TRUE;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f70f24e221 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/_overlay_region_list/7.x | 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. | Parameters:
- $type: The type of regions to return. This can either be 'overlay_regions' or 'overlay_supplemental_regions'.
Returns: An array of region names of the given type, within the theme that is being used to display the current page.
File: modules/overlay/overlay.module | function _overlay_region_list($type) {
// Obtain the current theme. We need to first make sure the theme system is
// initialized, since this function can be called early in the page request.
drupal_theme_initialize();
$themes = list_themes();
$theme = $themes[$GLOBALS['theme']];
// Return the list of regio... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7187d0224 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_unpublish_action/7.x | 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. | Parameters:
- $comment: An optional comment object.
- $context (array): Array with components: - 'cid': Comment ID. Required if $comment is not given.
File: modules/comment/comment.module | function comment_unpublish_action($comment, $context = array()) {
if (isset($comment->subject)) {
$subject = $comment->subject;
$comment->status = COMMENT_NOT_PUBLISHED;
}
else {
$cid = $context['cid'];
$subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->f... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f739acd020 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21actions.inc/function/actions_list/7.x | Implement `actions_list($reset = FALSE)` in PHP for Drupal 7. Required behavior: Discovers all available actions by invoking hook_action_info(). | This function contrasts with actions_get_all_actions(); see the documentation of actions_get_all_actions() for an explanation.
Parameters:
- $reset: Reset the action info static cache.
Returns: An associative array keyed on action function name, with the same format as the return value of hook_action_info(), containi... | function actions_list($reset = FALSE) {
$actions = &drupal_static(__FUNCTION__);
if (!isset($actions) || $reset) {
$actions = module_invoke_all('action_info');
drupal_alter('action_info', $actions);
}
// See module_implements() for an explanation of this cast.
return (array) $actions;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f746766017 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_path_token/7.x | Implement `image_style_path_token($style_name, $uri)` in PHP for Drupal 7. Required behavior: Generates a token to protect an image style derivative. | This prevents unauthorized generation of an image style derivative, which can be costly both in CPU time and disk space.
Parameters:
- $style_name: The name of the image style.
- $uri: The URI of the image for this style, for example as returned by image_style_path().
Returns: An eight-character token which can be us... | function image_style_path_token($style_name, $uri) {
// Return the first eight characters.
return substr(drupal_hmac_base64($style_name . ':' . $uri, drupal_get_private_key() . drupal_get_hash_salt()), 0, 8);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7494ff4f7 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.install/function/shortcut_install/7.x | In Drupal 7, write the function `shortcut_install()` (file modules/shortcut/shortcut.install) so that it does the following: Implements hook_install(). | File: modules/shortcut/shortcut.install | function shortcut_install() {
$t = get_t();
// Create an initial default shortcut set.
$shortcut_set = new stdClass();
$shortcut_set->title = $t('Default');
$shortcut_set->links = array(
array(
'link_path' => 'node/add',
'link_title' => $t('Add content'),
'weight' => -20,
),
arra... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f75871286e | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_html_head_alter/7.x | 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(). | 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.
Parameters:
- $head_elements: An array of renderable... | function hook_html_head_alter(&$head_elements) {
foreach ($head_elements as $key => $element) {
if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
// I want a custom canonical URL.
$head_elements[$key]['#attributes']['href'] = mymodule_canonical_url();
}
... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-f779b7f016 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_validate_current_pass/7.x | 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(). | File: modules/user/user.module | function user_validate_current_pass(&$form, &$form_state) {
$account = $form['#user'];
foreach ($form_state['values']['current_pass_required_values'] as $key => $name) {
// This validation only works for required textfields (like mail) or
// form values like password_confirm that have their own validation
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f79203c511 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21path.inc/function/path_save/7.x | 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. | Parameters:
- $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.
File: includes/path.inc | function path_save(&$path) {
$path += array('language' => LANGUAGE_NONE);
// Load the stored alias, if any.
if (!empty($path['pid']) && !isset($path['original'])) {
$path['original'] = path_load($path['pid']);
}
if (empty($path['pid'])) {
drupal_write_record('url_alias', $path);
module_invoke_al... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7a1aa2b30 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21batch.inc/function/_batch_process/7.x | In Drupal 7, write the function `_batch_process()` (file includes/batch.inc) so that it does the following: Processes sets in a batch. | 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.
Returns: An array containing a completion value (in percent) and a statu... | function _batch_process() {
$batch = &batch_get();
$current_set = &_batch_current_set();
// Indicate that this batch set needs to be initialized.
$set_changed = TRUE;
// If this batch was marked for progressive execution (e.g. forms submitted by
// drupal_form_submit()), initialize a timer to determi... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7af53b266 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_add_http_header/7.x | 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. | 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).
Parameters:
- $name: The HTTP header name, or the special 'Status' header name.
- $value: The HTTP header value; if equal to FALSE, the specified header is unset. If $name is 'Stat... | function drupal_add_http_header($name, $value, $append = FALSE) {
// The headers as name/value pairs.
$headers = &drupal_static('drupal_http_headers', array());
$name_lower = strtolower($name);
_drupal_set_preferred_header_name($name);
if ($value === FALSE) {
$headers[$name_lower] = FALSE;
}
elseif ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7cfcd8d08 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21module.inc/function/module_hook/7.x | 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. | Parameters:
- $module: The name of the module (without the .module extension).
- $hook: The name of the hook (e.g. "help" or "menu").
Returns: TRUE if the module is both installed and enabled, and the hook is implemented in that module.
File: includes/module.inc | function module_hook($module, $hook) {
$function = $module . '_' . $hook;
if (function_exists($function)) {
return TRUE;
}
// If the hook implementation does not exist, check whether it may live in an
// optional include file registered via hook_hook_info().
$hook_info = module_hook_info();
if (isset(... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7d959c2a7 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_get_display_page/7.x | Implement `comment_get_display_page($cid, $node_type)` in PHP for Drupal 7. Required behavior: Return the page number for a comment. | Finds the correct page number for a comment taking into account display and paging settings.
Parameters:
- $cid: The comment ID.
- $node_type: The node type the comment is attached to.
Returns: The page number.
File: modules/comment/comment.module | function comment_get_display_page($cid, $node_type) {
$ordinal = comment_get_display_ordinal($cid, $node_type);
$comments_per_page = variable_get('comment_default_per_page_' . $node_type, 50);
return floor($ordinal / $comments_per_page);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7d9f7ebf5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21database%21database.inc/function/db_insert/7.x | 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. | Parameters:
- $table: The table into which to insert.
- $options: An array of options to control how the query operates.
Returns: InsertQuery A new InsertQuery object for this connection.
File: includes/database/database.inc | function db_insert($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->insert($table, $options);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f7fb3688c9 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_update_files_database/7.x | 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. | Parameters:
- $files: An array of files.
- $type: The type of the files.
File: modules/system/system.module | function system_update_files_database(&$files, $type) {
$result = db_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type));
// Add all files that need to be deleted to a DatabaseCondition.
$delete = db_or();
foreach ($result as $file) {
if (isset($files[$file->name]) && is_object($fil... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f809eb26f2 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_trigger_fatal_error/7.x | 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. | 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.
Parameters:
- $error_msg (string): The error messag... | function drupal_trigger_fatal_error($error_msg) {
$fatal_error = &drupal_static(__FUNCTION__, FALSE);
$fatal_error = TRUE;
trigger_error($error_msg, E_USER_ERROR);
$fatal_error = FALSE;
// The standard Drupal error handler should have treated this as a fatal
// error and already ended the page request. But ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f818b1600d | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_trigger_refresh/7.x | Implement `overlay_trigger_refresh()` in PHP for Drupal 7. Required behavior: Checks if the parent window needs to be refreshed on this page load. | 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.
File: modules/overlay/overlay.module | function overlay_trigger_refresh() {
if (!empty($_SESSION['overlay_regions_to_refresh'])) {
$settings = array(
'overlayChild' => array(
'refreshRegions' => $_SESSION['overlay_regions_to_refresh'],
),
);
drupal_add_js($settings, array('type' => 'setting'));
unset($_SESSION['overlay_... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f81909496a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_load/7.x | In Drupal 7, write the function `contact_load($cid)` (file modules/contact/contact.module) so that it does the following: Loads a contact category. | Parameters:
- $cid: The contact category ID.
Returns: An array with the contact category's data.
File: modules/contact/contact.module | function contact_load($cid) {
return db_select('contact', 'c')
->addTag('translatable')
->fields('c')
->condition('cid', $cid)
->execute()
->fetchAssoc();
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f824e14252 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_valid_link/7.x | 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. | Parameters:
- $path: The path to the link.
Returns: TRUE if the shortcut link is valid, FALSE otherwise. Valid links are ones that correspond to actual paths on the site.
File: modules/shortcut/shortcut.module | function shortcut_valid_link($path) {
// Do not use URL aliases.
$normal_path = drupal_get_normal_path($path);
if ($path != $normal_path) {
$path = $normal_path;
}
// An empty path is valid too and will be converted to <front>.
return (!url_is_external($path) && menu_get_item($path)) || empty($path) || ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f82f45002f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.multilingual.inc/function/field_available_languages/7.x | 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. | 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.
Pa... | function field_available_languages($entity_type, $field) {
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['field_languages'] = &drupal_static(__FUNCTION__);
}
$field_languages = &$drupal_static_fast['field_languages'];
$field_name = $field['field_name'];
if (!isset($... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f838d20675 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_user_cancel/7.x | 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(). | File: modules/poll/poll.module | function poll_user_cancel($edit, $account, $method) {
switch ($method) {
case 'user_cancel_reassign':
db_update('poll_vote')
->fields(array('uid' => 0))
->condition('uid', $account->uid)
->execute();
break;
}
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f8539ff2cc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.module/function/theme_exposed_filters/7.x | 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. | Parameters:
- $variables: An associative array containing: - form: An associative array containing the structure of the form.
Returns: A string containing an HTML-formatted form.
File: modules/system/system.module | function theme_exposed_filters($variables) {
$form = $variables['form'];
$output = '';
if (isset($form['current'])) {
$items = array();
foreach (element_children($form['current']) as $key) {
$items[] = drupal_render($form['current'][$key]);
}
$output .= theme('item_list', array('items' => $... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f85b9d3eb3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7042/7.x | 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. | File: modules/system/system.install | function system_update_7042() {
// update_fix_d7_requirements() adds 'fake' source and alias columns to
// allow bootstrap to run without fatal errors. Remove those columns now
// so that we can rename properly.
db_drop_field('url_alias', 'source');
db_drop_field('url_alias', 'alias');
// Drop indexes.
d... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f865669056 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_role_grant_permissions/7.x | Implement `user_role_grant_permissions($rid, array $permissions = array())` in PHP for Drupal 7. Required behavior: Grant permissions to a user role. | Parameters:
- $rid: The ID of a user role to alter.
- $permissions: A list of permission names to grant.
File: modules/user/user.module | function user_role_grant_permissions($rid, array $permissions = array()) {
$modules = user_permission_get_modules();
// Grant new permissions for the role.
foreach ($permissions as $name) {
db_merge('role_permission')
->key(array(
'rid' => $rid,
'permission' => $name,
))
->fi... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f8bba9aa57 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_redirect_form/7.x | 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. | 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.
Usually (for exceptions, see below) $... | function drupal_redirect_form($form_state) {
// Skip redirection for form submissions invoked via drupal_form_submit().
if (!empty($form_state['programmed'])) {
return;
}
// Skip redirection if rebuild is activated.
if (!empty($form_state['rebuild'])) {
return;
}
// Skip redirection if it was expl... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f8e5447df8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_get_query_array/7.x | Implement `drupal_get_query_array($query)` in PHP for Drupal 7. Required behavior: Splits a URL-encoded query string into an array. | Parameters:
- $query: The query string to split.
Returns: An array of URL decoded couples $param_name => $value.
File: includes/common.inc | function drupal_get_query_array($query) {
$result = array();
if (!empty($query)) {
foreach (explode('&', $query) as $param) {
$param = explode('=', $param, 2);
$result[$param[0]] = isset($param[1]) ? rawurldecode($param[1]) : '';
}
}
return $result;
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f8eb09cfad | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_unpublish_by_keyword_action/7.x | 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. | Parameters:
- $comment (object): Comment object to modify.
- $context (array): Array with components: - 'keywords': Keywords to look for. If the comment contains at least one of the keywords, it is unpublished.
File: modules/comment/comment.module | function comment_unpublish_by_keyword_action($comment, $context) {
$node = node_load($comment->nid);
$build = comment_view($comment, $node);
$text = drupal_render($build);
foreach ($context['keywords'] as $keyword) {
if (strpos($text, $keyword) !== FALSE) {
$comment->status = COMMENT_NOT_PUBLISHED;
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f9049d197d | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_get_announcements/7.x | 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. | Returns (array): A build array with announcements.
File: modules/announcements_feed/announcements_feed.inc | function announcements_feed_get_announcements() {
drupal_set_title(t('Community announcements'));
drupal_add_css(drupal_get_path('module', 'announcements_feed')
. '/announcements_feed.css', array(
'group' => CSS_DEFAULT,
'every_page' => TRUE,
));
try {
$announcements = announcements_feed_g... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f92561c6dc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_admin_display_form/7.x | 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. | Parameters:
- $blocks: An array of blocks, as returned by block_admin_display_prepare_blocks().
- $theme: A string representing the name of the theme to edit blocks for.
- $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... | function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_regions = NULL) {
$form['#attached']['css'] = array(drupal_get_path('module', 'block') . '/block.css');
// Get a list of block regions if one was not provided.
if (!isset($block_regions)) {
$block_regions = system_region_list($th... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f9272f4cfb | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_permalink/7.x | 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. | 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 c... | function comment_permalink($cid) {
if (($comment = comment_load($cid)) && ($node = node_load($comment->nid))) {
// Find the current display page for this comment.
$page = comment_get_display_page($comment->cid, $node->type);
// Set $_GET['q'] and $_GET['page'] ourselves so that the node callback
// ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f930448069 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_dependencies/7.x | Implement `user_update_dependencies()` in PHP for Drupal 7. Required behavior: Implements hook_update_dependencies(). | File: modules/user/user.install | function user_update_dependencies() {
// user_update_7006() updates data in the {role_permission} table, so it must
// run after system_update_7007(), which populates that table.
$dependencies['user'][7006] = array(
'system' => 7007,
);
// user_update_7010() needs to query the {filter_format} table to ge... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f9305ee793 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_import_locales/7.x | 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. | Parameters:
- $install_state: An array of information about the current installation state.
Returns: The batch definition, if there are language files to import.
File: includes/install.core.inc | function install_import_locales(&$install_state) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
$install_locale = $install_state['parameters']['locale'];
include_once DRUPAL_ROOT . '/includes/iso.inc';
$predefined = _locale_get_predefined_list();
if (!isset($predefined[$install_locale])) {
// Drupa... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f942aed720 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21block%21block.install/function/block_update_7006/7.x | I need the code for `block_update_7006()` in Drupal 7 (modules/block/block.install). It must do this: Recreates cache_block table. | Converts fields that hold serialized variables from text to blob. Removes 'headers' column.
File: modules/block/block.install | function block_update_7006() {
$schema = system_schema_cache_7054();
db_drop_table('cache_block');
db_create_table('cache_block', $schema);
} | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f95fca383f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_send_headers/7.x | 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. | 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().
Parameters:
- $default_headers (array): (optional) An array of headers as name/value pairs.
- $only_default (bool): (optional) If TRUE and headers have already been sent, send on... | function drupal_send_headers($default_headers = array(), $only_default = FALSE) {
$headers_sent = &drupal_static(__FUNCTION__, FALSE);
$headers = drupal_get_http_header();
if ($only_default && $headers_sent) {
$headers = array();
}
$headers_sent = TRUE;
$header_names = _drupal_set_preferred_header_name... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f967bad34f | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_disable/7.x | 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. | Parameters:
- $theme_list: An array of theme names.
File: includes/theme.inc | function theme_disable($theme_list) {
// Don't disable the default theme.
if ($pos = array_search(variable_get('theme_default', 'bartik'), $theme_list) !== FALSE) {
unset($theme_list[$pos]);
if (empty($theme_list)) {
return;
}
}
drupal_clear_css_cache();
foreach ($theme_list as $key) {
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f96bff9ce7 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21book%21book.module/function/_book_update_outline/7.x | 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. | This common helper function performs all additions and updates to the book outline through node addition, node editing, node deletion, or the outline tab.
Parameters:
- $node: The node that is being saved, added, deleted, or moved.
Returns: TRUE if the menu link was saved; FALSE otherwise.
File: modules/book/book.mo... | function _book_update_outline($node) {
if (empty($node->book['bid'])) {
return FALSE;
}
$new = empty($node->book['mlid']);
$node->book['link_path'] = 'node/' . $node->nid;
$node->book['link_title'] = $node->title;
$node->book['parent_mismatch'] = FALSE; // The normal case.
if ($node->book['bid'] == ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f97ac1d7c5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/hook_search_admin/7.x | In Drupal 7, show an example implementation for `hook_search_admin()` (modules/search/search.api.php): Add elements to the search settings form. | Returns: Form array for the Search settings page at admin/config/search/settings.
File: modules/search/search.api.php | function hook_search_admin() {
// Output form for defining rank factor weights.
$form['content_ranking'] = array(
'#type' => 'fieldset',
'#title' => t('Content ranking'),
);
$form['content_ranking']['#theme'] = 'node_search_admin';
$form['content_ranking']['info'] = array(
'#value' => '<em>' . t('... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-f97b91cbc8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/theme_dashboard_disabled_blocks/7.x | Implement `theme_dashboard_disabled_blocks($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for disabled blocks, for use in dashboard customization mode. | Parameters:
- $variables: An associative array containing: - blocks: An array of block objects from _block_rehash().
File: modules/dashboard/dashboard.module | function theme_dashboard_disabled_blocks($variables) {
extract($variables);
$output = '<div class="canvas-content"><p>' . t('Drag and drop these blocks to the columns below. Changes are automatically saved. More options are available on the <a href="@dashboard-url">configuration page</a>.', array('@dashboard-url' =... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f97db1663a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.module/function/template_preprocess_announcements_feed/7.x | 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. | File: modules/announcements_feed/announcements_feed.module | function template_preprocess_announcements_feed(&$variables) {
if (!empty($variables['featured'])) {
foreach($variables['featured'] as &$announcement) {
_announcements_feed_preprocess_item($announcement);
}
}
if (!empty($variables['standard'])) {
foreach($variables['standard'] as &$announcement)... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-f9cc1ec5b3 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_uninstall/7.x | I need the code for `image_uninstall()` in Drupal 7 (modules/image/image.install). It must do this: Implements hook_uninstall(). | File: modules/image/image.install | function image_uninstall() {
// Remove the styles directory and generated images.
file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f9d06e2283 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21openid%21openid.install/function/openid_requirements/7.x | Implement `openid_requirements($phase)` in PHP for Drupal 7. Required behavior: Implements hook_requirements(). | File: modules/openid/openid.install | function openid_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// Check for the PHP BC Math library.
if (!function_exists('bcadd') && !function_exists('gmp_add')) {
$requirements['openid_math'] = array(
'value' => t('Not installed'),
'severity' => REQUIREME... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f9e2410425 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21statistics%21statistics.install/function/statistics_uninstall/7.x | Implement `statistics_uninstall()` in PHP for Drupal 7. Required behavior: Implements hook_uninstall(). | File: modules/statistics/statistics.install | function statistics_uninstall() {
// Remove variables.
variable_del('statistics_count_content_views');
variable_del('statistics_count_content_views_ajax');
variable_del('statistics_enable_access_log');
variable_del('statistics_flush_accesslog_timer');
variable_del('statistics_day_timestamp');
variable_del... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f9e35bc1b1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21comment%21comment.install/function/comment_uninstall/7.x | Implement `comment_uninstall()` in PHP for Drupal 7. Required behavior: Implements hook_uninstall(). | File: modules/comment/comment.install | function comment_uninstall() {
// Remove variables.
variable_del('comment_block_count');
$node_types = array_keys(node_type_get_types());
foreach ($node_types as $node_type) {
field_attach_delete_bundle('comment', 'comment_node_' . $node_type);
variable_del('comment_' . $node_type);
variable_del('co... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f9eac9f781 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21tracker%21tracker.module/function/tracker_comment_update/7.x | Implement `tracker_comment_update($comment)` in PHP for Drupal 7. Required behavior: Implements hook_comment_update(). | Comment module doesn't call hook_comment_unpublish() when saving individual comments so we need to check for those here.
File: modules/tracker/tracker.module | function tracker_comment_update($comment) {
// comment_save() calls hook_comment_publish() for all published comments
// so we need to handle all other values here.
if ($comment->status != COMMENT_PUBLISHED) {
_tracker_remove($comment->nid, $comment->uid, $comment->changed);
}
} | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-f9f00d3e56 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_overview/7.x | 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. | Messages are truncated at 56 chars. Full-length messages can be viewed on the message details page.
File: modules/dblog/dblog.admin.inc | function dblog_overview() {
$filter = dblog_build_filter_query();
$rows = array();
$classes = array(
WATCHDOG_DEBUG => 'dblog-debug',
WATCHDOG_INFO => 'dblog-info',
WATCHDOG_NOTICE => 'dblog-notice',
WATCHDOG_WARNING => 'dblog-warning',
WATCHDOG_ERROR => 'dblog-error',
WA... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fa11e13b3b | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21unicode.inc/function/drupal_strtolower/7.x | Implement `drupal_strtolower($text)` in PHP for Drupal 7. Required behavior: Lowercase a UTF-8 string. | Parameters:
- $text: The string to run the operation on.
Returns (string): The string in lowercase.
File: includes/unicode.inc | function drupal_strtolower($text) {
global $multibyte;
if ($multibyte == UNICODE_MULTIBYTE) {
return mb_strtolower($text);
}
else {
// Use C-locale for ASCII-only lowercase
$text = strtolower($text);
// Case flip Latin-1 accented letters
$text = preg_replace_callback('/\xC3[\x80-\x96\x98-\x9... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fa2a60aa78 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21announcements_feed%21announcements_feed.inc/function/announcements_feed_validate_url/7.x | Implement `announcements_feed_validate_url($url)` in PHP for Drupal 7. Required behavior: Check whether a link is controlled by drupal.org. | Parameters:
- $url (string): URL to check.
Returns (bool): Return TRUE if the URL is controlled by drupal.org.
File: modules/announcements_feed/announcements_feed.inc | function announcements_feed_validate_url($url) {
if (empty($url)) {
return FALSE;
}
$host = parse_url($url, PHP_URL_HOST);
// First character can only be a letter or a digit.
// @see https://www.rfc-editor.org/rfc/rfc1123#page-13
return $host && preg_match('/^([a-zA-Z0-9][a-zA-Z0-9\-_]*\.)?drupal\.org$... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fa3fd138b0 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.install/function/field_schema/7.x | Implement `field_schema()` in PHP for Drupal 7. Required behavior: Implements hook_schema(). | File: modules/field/field.install | function field_schema() {
// Static (meta) tables.
$schema['field_config'] = array(
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'The primary identifier for a field',
),
'field_name' => array(
'type' => 'varchar',
... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-fa41bec6fa | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_formatter_settings_summary/7.x | Implement `image_field_formatter_settings_summary($field, $instance, $view_mode)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_settings_summary(). | File: modules/image/image.field.inc | function image_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = array();
$image_styles = image_style_options(FALSE, PASS_THROUGH);
// Unset possible 'No defined styles' option.
unset($image_styles[''... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-fa5e4e433a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7.x | 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. | The behavior of this function depends on the parameters it is called with.
Generally, it handles the addition of JavaScript to the page, either as
reference to an existing file or as inline code. The following actions can be
performed using this function:
- Add a file ('file'): Adds a reference to a JavaScript file to ... | function drupal_add_js($data = NULL, $options = NULL) {
$javascript = &drupal_static(__FUNCTION__, array());
$jquery_added = &drupal_static(__FUNCTION__ . ':jquery_added', FALSE);
// If the $javascript variable has been reset with drupal_static_reset(),
// jQuery and related files will have been removed from t... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fa747e38d8 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.install/function/_update_7000_field_delete_instance/7.x | In Drupal 7, write the function `_update_7000_field_delete_instance($field_name, $entity_type, $bundle)` (file modules/field/field.install) so that it does the following: Utility function: delete an instance and all its data of a field stored in SQL Storage. | BEWARE: this function deletes user data from the field storage tables.
This function is valid for a database schema version 7000.
File: modules/field/field.install | function _update_7000_field_delete_instance($field_name, $entity_type, $bundle) {
// Delete field instance configuration data.
db_delete('field_config_instance')
->condition('field_name', $field_name)
->condition('entity_type', $entity_type)
->condition('bundle', $bundle)
->execute();
// Nuke dat... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fa7f6de5df | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_pre_update/7.x | Give me the example code for `hook_field_storage_pre_update($entity_type, $entity, &$skip_fields)` in Drupal 7. Hook description: Act before the storage backends update field data. | This hook allows modules to store data before the Field Storage API, optionally preventing the field storage module from doing so.
Parameters:
- $entity_type: The type of $entity; for example, 'node' or 'user'.
- $entity: The entity with fields to save.
- $skip_fields: An array keyed by field IDs whose data has alread... | function hook_field_storage_pre_update($entity_type, $entity, &$skip_fields) {
$first_call = &drupal_static(__FUNCTION__, array());
if ($entity_type == 'node' && $entity->status && _forum_node_check_node_type($entity)) {
// We don't maintain data for old revisions, so clear all previous values
// from the ... | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-fa93569bdc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21node%21node.pages.inc/function/node_form_submit/7.x | I need the code for `node_form_submit($form, &$form_state)` in Drupal 7 (modules/node/node.pages.inc). It must do this: Form submission handler for node_form(). | File: modules/node/node.pages.inc | function node_form_submit($form, &$form_state) {
$node = node_form_submit_build_node($form, $form_state);
$insert = empty($node->nid);
node_save($node);
$node_link = l(t('view'), 'node/' . $node->nid);
$watchdog_args = array('@type' => $node->type, '%title' => $node->title);
$t_args = array('@type' => node_... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fa97cff425 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_export_po_form/7.x | Implement `locale_translate_export_po_form($form, &$form_state, $names)` in PHP for Drupal 7. Required behavior: Form to export PO files for the languages provided. | Parameters:
- $names: An associate array with localized language names
File: modules/locale/locale.admin.inc | function locale_translate_export_po_form($form, &$form_state, $names) {
$form['export_title'] = array('#type' => 'item',
'#title' => t('Export translation'),
);
$form['langcode'] = array('#type' => 'select',
'#title' => t('Language name'),
'#options' => $names,
'#description' => t('Select the lang... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fa98048a58 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21file.inc/function/file_unmanaged_save_data/7.x | Implement `file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME)` in PHP for Drupal 7. Required behavior: Saves a string to the specified destination without invoking file API. | This function is identical to file_save_data() except the file will not be saved to the {file_managed} table and none of the file_* hooks will be called.
Parameters:
- $data: A string containing the contents of the file.
- $destination: A string containing the destination location. This must be a stream wrapper URI. I... | function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
// Write the data to a temporary file.
$temp_name = drupal_tempnam('temporary://', 'file');
if (file_put_contents($temp_name, $data) === FALSE) {
drupal_set_message(t('The file could not be created.'), 'error');
... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-faa7df2ecc | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21menu%21menu.api.php/function/hook_menu_insert/7.x | Give me the example code for `hook_menu_insert($menu)` in Drupal 7. Hook description: Respond to a custom menu creation. | This hook is used to notify modules that a custom menu has been created. Contributed modules may use the information to perform actions based on the information entered into the menu system.
Parameters:
- $menu: An array representing a custom menu: - menu_name: The unique name of the custom menu. - title: The human re... | function hook_menu_insert($menu) {
// For example, we track available menus in a variable.
$my_menus = variable_get('my_module_menus', array());
$my_menus[$menu['menu_name']] = $menu['menu_name'];
variable_set('my_module_menus', $my_menus);
} | [
"code-task",
"hook-definition"
] | 2026-09-30T00:00:00 |
api-drupal7-fad1a96db1 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21pager.inc/function/theme_pager_link/7.x | In Drupal 7, write the function `theme_pager_link($variables)` (file includes/pager.inc) so that it does the following: Returns HTML for a link to a specific query result page. | Parameters:
- $variables: An associative array containing: - text: The link text. Also used to figure out the title attribute of the link, if it is not provided in $variables['attributes']['title']; in this case, $variables['text'] must be one of the standard pager link text strings that would be generated by the pager... | function theme_pager_link($variables) {
$text = $variables['text'];
$page_new = $variables['page_new'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$attributes = $variables['attributes'];
$page = isset($_GET['page']) ? $_GET['page'] : '';
if ($new_page = implode(',', pager_l... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fadd177cc5 | 7 | drupal_api_code | https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_info/7.x | Implement `text_field_info()` in PHP for Drupal 7. Required behavior: Implements hook_field_info(). | Field settings:
- max_length: the maximum length for a varchar field.
Instance settings:
- text_processing: whether text input filters should be used.
- display_summary: whether the summary field should be displayed.
When empty and not displayed the summary will take its value from the
trimmed value of th... | function text_field_info() {
return array(
'text' => array(
'label' => t('Text'),
'description' => t('This field stores varchar text in the database.'),
'settings' => array('max_length' => 255),
'instance_settings' => array('text_processing' => 0),
'default_widget' => 'text_textfield... | [
"code-task",
"hook-implementation"
] | 2026-09-30T00:00:00 |
api-drupal7-fae244a56c | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_set_active_menu_names/7.x | Implement `menu_set_active_menu_names($menu_names = NULL)` in PHP for Drupal 7. Required behavior: Sets (or gets) the active menu for the current page. | The active menu for the page determines the active trail.
Returns: An array of menu machine names, in order of preference. The 'menu_default_active_menus' variable may be used to assert a menu order different from the order of creation, or to prevent a particular menu from being used at all in the active trail. E.g., ... | function menu_set_active_menu_names($menu_names = NULL) {
$active = &drupal_static(__FUNCTION__);
if (isset($menu_names) && is_array($menu_names)) {
$active = $menu_names;
}
elseif (!isset($active)) {
$active = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus()));
}
retur... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fafdbb440a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/_drupal_load_stylesheet/7.x | In Drupal 7, write the function `_drupal_load_stylesheet($matches)` (file includes/common.inc) so that it does the following: Loads stylesheets recursively and returns contents with corrected paths. | This function is used for recursive loading of stylesheets and returns the stylesheet content with all url() paths corrected.
File: includes/common.inc | function _drupal_load_stylesheet($matches) {
$filename = $matches[1];
// Load the imported stylesheet and replace @import commands in there as well.
$file = drupal_load_stylesheet($filename, NULL, FALSE);
// Determine the file's directory.
$directory = dirname($filename);
// If the file is in the current d... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fb162a166b | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21common.inc/function/format_plural/7.x | I need the code for `format_plural($count, $singular, $plural, array $args = array(), array $options = array())` in Drupal 7 (includes/common.inc). It must do this: Formats a string containing a count of items. | This function ensures that the string is pluralized correctly. Since t() is called by this function, make sure not to pass already-localized strings to it.
For example:
Parameters:
- $count: The item count to display.
- $singular: The string for the singular case. Make sure it is clear this is singular, to ease trans... | function format_plural($count, $singular, $plural, array $args = array(), array $options = array()) {
$args['@count'] = $count;
if ($count == 1) {
return t($singular, $args, $options);
}
// Get the plural index through the gettext formula.
$index = (function_exists('locale_get_plural')) ? locale_get_plur... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fb226e8f3a | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_form_callback/7.x | Implement `ajax_form_callback()` in PHP for Drupal 7. Required behavior: Menu callback; handles Ajax requests for the #ajax Form API property. | This rebuilds the form from cache and invokes the defined #ajax['callback'] to return an Ajax command structure for JavaScript. In case no 'callback' has been defined, nothing will happen.
The Form API #ajax property can be set both for buttons and other input elements.
This function is also the canonical example of ... | function ajax_form_callback() {
list($form, $form_state, $form_id, $form_build_id, $commands) = ajax_get_form();
drupal_process_form($form['#form_id'], $form, $form_state);
// We need to return the part of the form (or some other content) that needs
// to be re-rendered so the browser can update the page with ... | [
"code-task",
"function"
] | 2026-09-30T00:00:00 |
api-drupal7-fb2b75ebbf | 7 | drupal_api_code | https://api.drupal.org/api/drupal/includes%21xmlrpcs.inc/function/xmlrpc_server_get_capabilities/7.x | In Drupal 7, write the function `xmlrpc_server_get_capabilities()` (file includes/xmlrpcs.inc) so that it does the following: Returns a list of the capabilities of this server. | XML-RPC method system.getCapabilities maps to this function.
Returns (array): Array of server capabilities.
File: includes/xmlrpcs.inc | function xmlrpc_server_get_capabilities() {
return array(
'xmlrpc' => array(
'specUrl' => 'http://www.xmlrpc.com/spec',
'specVersion' => 1,
),
'faults_interop' => array(
'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
'specVersion' => 20010516,
),
... | [
"code-task",
"function"
] | 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.