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-dd0288c830
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_updater_info_alter/7.x
In Drupal 7, show an example implementation for `hook_updater_info_alter(&$updaters)` (modules/system/system.api.php): Alter the Updater information array.
An Updater is a class that knows how to update various parts of the Drupal file system, for example to update modules that have newer releases, or to install a new theme. Parameters: - $updaters (array): Associative array of updaters as defined through hook_updater_info(). Alter this array directly. File: modules/sys...
function hook_updater_info_alter(&$updaters) { // Adjust weight so that the theme Updater gets a chance to handle a given // update task before module updaters. $updaters['theme']['weight'] = -1; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-dd098aa8dc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_form_validate/7.x
I need the code for `field_attach_form_validate($entity_type, $entity, $form, &$form_state, $options = array())` in Drupal 7 (modules/field/field.attach.inc). It must do this: Perform field validation against form-submitted field values.
There are two levels of validation for fields in forms: widget validation, and field validation. - Widget validation steps are specific to a given widget's own form structure and UI metaphors. They are executed through FAPI's #element_validate property during normal form validation. - Field validation steps are com...
function field_attach_form_validate($entity_type, $entity, $form, &$form_state, $options = array()) { // Validate $options since this is a new parameter added after Drupal 7 was // released. $options = is_array($options) ? $options : array(); // Extract field values from submitted values. _field_invoke_defau...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dd0db49be4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.processor.inc/function/aggregator_expire/7.x
Implement `aggregator_expire($feed)` in PHP for Drupal 7. Required behavior: Expires items from a feed depending on expiration settings.
Parameters: - $feed: Object describing feed. File: modules/aggregator/aggregator.processor.inc
function aggregator_expire($feed) { $aggregator_clear = variable_get('aggregator_clear', 9676800); if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) { // Remove all items that are older than flush item timer. $age = REQUEST_TIME - $aggregator_clear; $iids = db_query('SELECT iid FROM {aggregator_item} WH...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dd16d3d37a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21password.inc/function/user_hash_password/7.x
In Drupal 7, write the function `user_hash_password($password, $count_log2 = 0)` (file includes/password.inc) so that it does the following: Hash a password using a secure hash.
Parameters: - $password: A plain-text password. - $count_log2: Optional integer to specify the iteration count. Generally used only during mass operations where a value less than the default is needed for speed. Returns: A string containing the hashed password (and a salt), or FALSE on failure. File: includes/passwor...
function user_hash_password($password, $count_log2 = 0) { if (empty($count_log2)) { // Use the standard iteration count. $count_log2 = variable_get('password_count_log2', DRUPAL_HASH_COUNT); } return _password_crypt('sha512', $password, _password_generate_salt($count_log2)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dd305b6e6b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.form.inc/function/field_form_set_state/7.x
I need the code for `field_form_set_state($parents, $field_name, $langcode, &$form_state, $field_state)` in Drupal 7 (modules/field/field.form.inc). It must do this: Stores processing information about a field in $form_state.
Parameters: - $parents: The array of #parents where the field lives in the form. - $field_name: The field name. - $langcode: The language in which the field values are entered. - $form_state: The form state. - $field_state: The array of data to store. See field_form_get_state() for the structure and content of the arra...
function field_form_set_state($parents, $field_name, $langcode, &$form_state, $field_state) { $form_state_parents = _field_form_state_parents($parents, $field_name, $langcode); drupal_array_set_nested_value($form_state, $form_state_parents, $field_state); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dd33f701b4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_countries_alter/7.x
Give me the example code for `hook_countries_alter(&$countries)` in Drupal 7. Hook description: Alter the default country list.
Parameters: - $countries: The associative array of countries keyed by ISO 3166-1 country code. File: modules/system/system.api.php
function hook_countries_alter(&$countries) { // Elbonia is now independent, so add it to the country list. $countries['EB'] = 'Elbonia'; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-dd4c0bd991
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_build_tree/7.x
I need the code for `_menu_build_tree($menu_name, array $parameters = array())` in Drupal 7 (includes/menu.inc). It must do this: Builds a menu tree.
This function may be used build the data for a menu tree only, for example to further massage the data manually before further processing happens. menu_tree_check_access() needs to be invoked afterwards. File: includes/menu.inc
function _menu_build_tree($menu_name, array $parameters = array()) { // Static cache of already built menu trees. $trees = &drupal_static(__FUNCTION__, array()); // Build the cache id; sort parents to prevent duplicate storage and remove // default parameter values. if (isset($parameters['expanded'])) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dd68fe8279
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_block_info/7.x
Implement `search_block_info()` in PHP for Drupal 7. Required behavior: Implements hook_block_info().
File: modules/search/search.module
function search_block_info() { $blocks['form']['info'] = t('Search form'); // Not worth caching. $blocks['form']['cache'] = DRUPAL_NO_CACHE; $blocks['form']['properties']['administrative'] = TRUE; return $blocks; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-dd83ce7901
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_output/7.x
I need the code for `menu_tree_output($tree)` in Drupal 7 (includes/menu.inc). It must do this: Returns an output structure for rendering a menu tree.
The menu item's LI element is given one of the following classes: - expanded: The menu item is showing its submenu. - collapsed: The menu item has a submenu which is not shown. - leaf: The menu item has no submenu. Parameters: - $tree: A data structure representing the tree as returned from menu_tree_data. Returns: A...
function menu_tree_output($tree) { $build = array(); $items = array(); // Pull out just the menu links we are going to render so that we // get an accurate count for the first/last classes. foreach ($tree as $data) { if ($data['link']['access'] && !$data['link']['hidden']) { $items[] = $data; }...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dd843083d8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/_filter_url_parse_partial_links/7.x
I need the code for `_filter_url_parse_partial_links($match)` in Drupal 7 (modules/filter/filter.module). It must do this: Makes links out of domain names starting with "www."
Callback for preg_replace_callback() within _filter_url(). File: modules/filter/filter.module
function _filter_url_parse_partial_links($match) { // The $i:th parenthesis in the regexp contains the URL. $i = 1; $match[$i] = decode_entities($match[$i]); $caption = check_plain(_filter_url_trim($match[$i])); $match[$i] = check_plain($match[$i]); return '<a href="http://' . $match[$i] . '">' . $caption ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dd8b91848a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_entity_info/7.x
I need the code for `node_entity_info()` in Drupal 7 (modules/node/node.module). It must do this: Implements hook_entity_info().
File: modules/node/node.module
function node_entity_info() { $return = array( 'node' => array( 'label' => t('Node'), 'controller class' => 'NodeController', 'base table' => 'node', 'revision table' => 'node_revision', 'uri callback' => 'node_uri', 'fieldable' => TRUE, 'entity keys' => array( 'i...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-dd8c6cb161
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21password.inc/function/_password_base64_encode/7.x
In Drupal 7, write the function `_password_base64_encode($input, $count)` (file includes/password.inc) so that it does the following: Encodes bytes into printable base 64 using the *nix standard from crypt().
Parameters: - $input: The string containing bytes to encode. - $count: The number of characters (bytes) to encode. Returns: Encoded string File: includes/password.inc
function _password_base64_encode($input, $count) { $output = ''; $i = 0; $itoa64 = _password_itoa64(); do { $value = ord($input[$i++]); $output .= $itoa64[$value & 0x3f]; if ($i < $count) { $value |= ord($input[$i]) << 8; } $output .= $itoa64[($value >> 6) & 0x3f]; if ($i++ >= $cou...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ddb02142a0
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.core.inc/function/install_system_module/7.x
In Drupal 7, write the function `install_system_module(&$install_state)` (file includes/install.core.inc) so that it does the following: Installation task; install the Drupal system module.
Parameters: - $install_state: An array of information about the current installation state. File: includes/install.core.inc
function install_system_module(&$install_state) { // Install system.module. drupal_install_system(); // Call file_ensure_htaccess() to ensure that all of Drupal's standard // directories (e.g., the public and private files directories) have // appropriate .htaccess files. These directories will have already ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-ddc1bea130
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_library_alter/7.x
In Drupal 7, show an example implementation for `hook_library_alter(&$libraries, $module)` (modules/system/system.api.php): Alters the JavaScript/CSS library registry.
Allows certain, contributed modules to update libraries to newer versions while ensuring backwards compatibility. In general, such manipulations should only be done by designated modules, since most modules that integrate with a certain library also depend on the API of a certain library version. Parameters: - $librar...
function hook_library_alter(&$libraries, $module) { // Update Farbtastic to version 2.0. if ($module == 'system' && isset($libraries['farbtastic'])) { // Verify existing version is older than the one we are updating to. if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) { // Update ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-ddcb9e8eb3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_form_user_register_form_alter/7.x
In Drupal 7, write the function `openid_form_user_register_form_alter(&$form, &$form_state)` (file modules/openid/openid.module) so that it does the following: Implements hook_form_FORM_ID_alter().
Prefills the login form with values acquired via OpenID. File: modules/openid/openid.module
function openid_form_user_register_form_alter(&$form, &$form_state) { if (isset($_SESSION['openid']['response'])) { module_load_include('inc', 'openid'); $response = $_SESSION['openid']['response']; // Extract Simple Registration keys from the response. We only include // signed keys as required by ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-dddfeac8c1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_cron/7.x
I need the code for `search_cron()` in Drupal 7 (modules/search/search.module). It must do this: Implements hook_cron().
Fires hook_update_index() in all modules and cleans up dirty words. File: modules/search/search.module
function search_cron() { // We register a shutdown function to ensure that search_total is always up // to date. drupal_register_shutdown_function('search_update_totals'); foreach (variable_get('search_active_modules', array('node', 'user')) as $module) { // Update word index module_invoke($module, 'up...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-de173e24a3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.admin.inc/function/contact_category_edit_form/7.x
I need the code for `contact_category_edit_form($form, &$form_state, array $category = array())` in Drupal 7 (modules/contact/contact.admin.inc). It must do this: Form constructor for the category edit form.
Parameters: - $category: An array describing the category to be edited. May be empty for new categories. Recognized array keys are: - category: The name of the category. - recipients: A comma-separated list of recipients. - reply: (optional) The body of the auto-reply message. - weight: The weight of the category. - se...
function contact_category_edit_form($form, &$form_state, array $category = array()) { // If this is a new category, add the default values. $category += array( 'category' => '', 'recipients' => '', 'reply' => '', 'weight' => 0, 'selected' => 0, 'cid' => NULL, ); $form['category'] = arra...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-de42862d0e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/l/7.x
In Drupal 7, write the function `l($text, $path, array $options = array())` (file includes/common.inc) so that it does the following: Formats an internal or external URL link as an HTML anchor tag.
This function correctly handles aliased paths and adds an 'active' class attribute to links that point to the current page (for theming), so all internal links output by modules should be generated by this function if possible. However, for links enclosed in translatable text you should use t() and embed the HTML anch...
function l($text, $path, array $options = array()) { global $language_url; static $use_theme = NULL; // Merge in defaults. $options += array( 'attributes' => array(), 'html' => FALSE, ); // Append active class. if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) && ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-de5387d723
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_settings/7.x
I need the code for `ajax_command_settings($argument, $merge = FALSE)` in Drupal 7 (includes/ajax.inc). It must do this: Creates a Drupal Ajax 'settings' command.
The 'settings' command instructs the client either to use the given array as the settings for ajax-loaded content or to extend Drupal.settings with the given array, depending on the value of the $merge parameter. This command is implemented by Drupal.ajax.prototype.commands.settings() defined in misc/ajax.js. Paramet...
function ajax_command_settings($argument, $merge = FALSE) { return array( 'command' => 'settings', 'settings' => $argument, 'merge' => $merge, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-de7869be9a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_role/7.x
In Drupal 7, write the function `user_admin_role($form, $form_state, $role)` (file modules/user/user.admin.inc) so that it does the following: Form to configure a single role.
File: modules/user/user.admin.inc
function user_admin_role($form, $form_state, $role) { if ($role->rid == DRUPAL_ANONYMOUS_RID || $role->rid == DRUPAL_AUTHENTICATED_RID) { drupal_goto('admin/people/permissions/roles'); } // Display the edit role form. $form['name'] = array( '#type' => 'textfield', '#title' => t('Role name'), '#...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dea9ebe7d9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21path.inc/function/path_delete/7.x
Implement `path_delete($criteria)` in PHP for Drupal 7. Required behavior: Delete a URL alias.
Parameters: - $criteria: A number representing the pid or an array of criteria. File: includes/path.inc
function path_delete($criteria) { if (!is_array($criteria)) { $criteria = array('pid' => $criteria); } $path = path_load($criteria); if (isset($path['source'])) { $query = db_delete('url_alias'); foreach ($criteria as $field => $value) { $query->condition($field, $value); } $query->exe...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-debe054f15
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_check_profile/7.x
Implement `drupal_check_profile($profile)` in PHP for Drupal 7. Required behavior: Checks an installation profile's requirements.
Parameters: - $profile: Name of installation profile to check. Returns (Array): of the installation profile's requirements. File: includes/install.inc
function drupal_check_profile($profile) { include_once DRUPAL_ROOT . '/includes/file.inc'; $profile_file = DRUPAL_ROOT . "/profiles/$profile/$profile.profile"; if (!isset($profile) || !file_exists($profile_file)) { throw new Exception(install_no_profile_error()); } $info = install_profile_info($profile...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dec1d52ed0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_modules_enabled/7.x
I need the code for `field_modules_enabled($modules)` in Drupal 7 (modules/field/field.module). It must do this: Implements hook_modules_enabled().
File: modules/field/field.module
function field_modules_enabled($modules) { // Refresh the 'active' status of fields. field_sync_field_status(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-ded020e08f
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland_breadcrumb/7.x
Implement `garland_breadcrumb($variables)` in PHP for Drupal 7. Required behavior: Override of theme_breadcrumb().
File: themes/garland/template.php
function garland_breadcrumb($variables) { $breadcrumb = $variables['breadcrumb']; if (!empty($breadcrumb)) { // Provide a navigational heading to give context for breadcrumb links to // screen-reader users. Make the heading invisible with .element-invisible. $output = '<h2 class="element-invisible">' ....
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dee485d46e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.api.php/function/hook_aggregator_process_info/7.x
Give me the example code for `hook_aggregator_process_info()` in Drupal 7. Hook description: Specify the title and short description of your processor.
The title and the description provided are shown within the configuration page. Use as title the natural name of the processor and as description a brief (40 to 80 characters) explanation of the functionality. This hook is only called if your module implements hook_aggregator_process(). If this hook is not implemented...
function hook_aggregator_process_info() { return array( 'title' => t('Default processor'), 'description' => t('Creates lightweight records of feed items.'), ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-dee68caaef
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.module/function/aggregator_block_configure/7.x
Implement `aggregator_block_configure($delta = '')` in PHP for Drupal 7. Required behavior: Implements hook_block_configure().
File: modules/aggregator/aggregator.module
function aggregator_block_configure($delta = '') { list($type, $id) = explode('-', $delta); if ($type == 'category') { $value = db_query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchField(); $form['block'] = array( '#type' => 'select', '#title' => t('Nu...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-def5260564
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_export_po_form_submit/7.x
In Drupal 7, write the function `locale_translate_export_po_form_submit($form, &$form_state)` (file modules/locale/locale.admin.inc) so that it does the following: Process a translation (or template) export form submission.
File: modules/locale/locale.admin.inc
function locale_translate_export_po_form_submit($form, &$form_state) { // If template is required, language code is not given. $language = NULL; if (isset($form_state['values']['langcode'])) { $languages = language_list(); $language = $languages[$form_state['values']['langcode']]; } _locale_export_po(...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df0cecd307
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.module/function/shortcut_permission/7.x
I need the code for `shortcut_permission()` in Drupal 7 (modules/shortcut/shortcut.module). It must do this: Implements hook_permission().
File: modules/shortcut/shortcut.module
function shortcut_permission() { return array( 'administer shortcuts' => array( 'title' => t('Administer shortcuts'), ), 'customize shortcut links' => array( 'title' => t('Edit current shortcut set'), 'description' => t('Editing the current shortcut set will affect other users if that se...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-df1ba606c0
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21token.inc/function/token_replace/7.x
I need the code for `token_replace($text, array $data = array(), array $options = array())` in Drupal 7 (includes/token.inc). It must do this: Replaces all tokens in a given string with appropriate values.
Parameters: - $text: A string potentially containing replaceable tokens. - $data: (optional) An array of keyed objects. For simple replacement scenarios 'node', 'user', and others are common keys, with an accompanying node or user object being the value. Some token types, like 'site', do not require any explicit inform...
function token_replace($text, array $data = array(), array $options = array()) { $text_tokens = token_scan($text); if (empty($text_tokens)) { return $text; } $replacements = array(); foreach ($text_tokens as $type => $tokens) { $replacements += token_generate($type, $tokens, $data, $options); if ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df22b1e08d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_match_path/7.x
Implement `drupal_match_path($path, $patterns)` in PHP for Drupal 7. Required behavior: Check if a path matches any pattern in a set of patterns.
Parameters: - $path: The path to match. - $patterns: String containing a set of patterns separated by \n, \r or \r\n. Returns (Boolean): value: TRUE if the path matches a pattern, FALSE otherwise. File: includes/path.inc
function drupal_match_path($path, $patterns) { $regexps = &drupal_static(__FUNCTION__); if (!isset($regexps[$patterns])) { // Convert path settings to a regular expression. // Therefore replace newlines with a logical or, /* with asterisks and the <front> with the frontpage. $to_replace = array( ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df22eb2849
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_view_alter/7.x
Give me the example code for `hook_entity_view_alter(&$build, $type)` in Drupal 7. Hook description: Alter the results of ENTITY_view().
This hook is called after the content has been assembled in a structured array and may be used for doing processing which requires that the complete entity content structure has been built. If a module wishes to act on the rendered HTML of the entity rather than the structured content array, it may use this hook to ad...
function hook_entity_view_alter(&$build, $type) { if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. $build['an_additional_field']['#weight'] = -10; // Add a #post_render callback to act on the rendered HTML of the entity. $build['#post_render'][] = 'm...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-df2d4a9939
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_form_access_denied/7.x
I need the code for `filter_form_access_denied($element)` in Drupal 7 (modules/filter/filter.module). It must do this: Render API callback: Hides the field value of 'text_format' elements.
To not break form processing and previews if a user does not have access to a stored text format, the expanded form elements in filter_process_format() are forced to take over the stored #default_values for 'value' and 'format'. However, to prevent the unfiltered, original #value from being displayed to the user, we re...
function filter_form_access_denied($element) { $element['#value'] = t('This field has been disabled because you do not have sufficient permissions to edit it.'); return $element; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df40fecfa2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_fields/7.x
I need the code for `field_info_fields()` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns all field definitions.
Use of this function should be avoided when possible, since it loads and statically caches a potentially large array of information. Use field_info_field_map() instead. When iterating over the fields present in a given bundle after a call to field_info_instances($entity_type, $bundle), it is recommended to use field_i...
function field_info_fields() { $cache = _field_info_field_cache(); $info = $cache->getFields(); $fields = array(); foreach ($info as $key => $field) { if (!$field['deleted']) { $fields[$field['field_name']] = $field; } } return $fields; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df700f0426
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_block_info/7.x
Implement `profile_block_info()` in PHP for Drupal 7. Required behavior: Implements hook_block_info().
File: modules/profile/profile.module
function profile_block_info() { $blocks['author-information']['info'] = t('Author information'); $blocks['author-information']['cache'] = DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE; return $blocks; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-df75f7f155
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.pages.inc/function/poll_results/7.x
Implement `poll_results($node)` in PHP for Drupal 7. Required behavior: Callback for the 'results' tab for polls you can vote on
File: modules/poll/poll.pages.inc
function poll_results($node) { drupal_set_title($node->title); $node->show_results = TRUE; return node_show($node); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df7e1be768
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_file_scan_write_cache/7.x
In Drupal 7, write the function `drupal_file_scan_write_cache()` (file includes/bootstrap.inc) so that it does the following: Writes the file scan cache to the persistent cache.
This cache stores all files marked as missing or moved after a file scan to prevent unnecessary file scans in subsequent requests. This cache is cleared in system_list_reset() (i.e. after a module/theme rebuild). File: includes/bootstrap.inc
function drupal_file_scan_write_cache() { // Only write to the persistent cache if requested, and if we know that any // data previously in the cache was successfully loaded and merged in by // _drupal_file_scan_cache(). $file_scans = &_drupal_file_scan_cache(); if (isset($file_scans['#write_cache']) && isset...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df7f4e5a85
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_path_initialize/7.x
Implement `drupal_path_initialize()` in PHP for Drupal 7. Required behavior: Initialize the $_GET['q'] variable to the proper normal path.
File: includes/path.inc
function drupal_path_initialize() { // Ensure $_GET['q'] is set before calling drupal_normal_path(), to support // path caching with hook_url_inbound_alter(). if (empty($_GET['q'])) { $_GET['q'] = variable_get('site_frontpage', 'node'); } $_GET['q'] = drupal_get_normal_path($_GET['q']); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df8ddbb7bd
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_export_pot_form/7.x
In Drupal 7, write the function `locale_translate_export_pot_form()` (file modules/locale/locale.admin.inc) so that it does the following: Translation template export form.
File: modules/locale/locale.admin.inc
function locale_translate_export_pot_form() { // Complete template export of the strings $form['export_title'] = array('#type' => 'item', '#title' => t('Export template'), '#description' => t('Generate a Gettext Portable Object Template (<em>.pot</em>) file with all strings from the Drupal locale database.'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-df926e68e7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dashboard%21dashboard.module/function/dashboard_permission/7.x
Implement `dashboard_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().
File: modules/dashboard/dashboard.module
function dashboard_permission() { return array( 'access dashboard' => array( 'title' => t('View the administrative dashboard'), // Note: We translate the 'Administer blocks' permission string here with // a separate t() call, to make sure it gets the same translation as when // it's in blo...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-dfda5c180f
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21update.inc/function/update_retrieve_dependencies/7.x
I need the code for `update_retrieve_dependencies()` in Drupal 7 (includes/update.inc). It must do this: Invokes hook_update_dependencies() in all installed modules.
This function is similar to module_invoke_all(), with the main difference that it does not require that a module be enabled to invoke its hook, only that it be installed. This allows the update system to properly perform updates even on modules that are currently disabled. Returns: An array of return values obtained b...
function update_retrieve_dependencies() { $return = array(); // Get a list of installed modules, arranged so that we invoke their hooks in // the same order that module_invoke_all() does. $modules = db_query("SELECT name FROM {system} WHERE type = 'module' AND schema_version <> :schema ORDER BY weight ASC, name...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dfe743e113
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.install/function/profile_update_7001/7.x
In Drupal 7, write the function `profile_update_7001()` (file modules/profile/profile.install) so that it does the following: Rename {profile_fields} table to {profile_field} and {profile_values} to {profile_value}.
File: modules/profile/profile.install
function profile_update_7001() { db_rename_table('profile_fields', 'profile_field'); db_rename_table('profile_values', 'profile_value'); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-dff0b52f01
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/theme_shortcut_set_customize/7.x
In Drupal 7, write the function `theme_shortcut_set_customize($variables)` (file modules/shortcut/shortcut.admin.inc) so that it does the following: Returns HTML for a shortcut set customization form.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/shortcut/shortcut.admin.inc
function theme_shortcut_set_customize($variables) { $form = $variables['form']; $map = array('disabled' => t('Disabled'), 'enabled' => t('Enabled')); $shortcuts_by_status = array( 'enabled' => element_children($form['shortcuts']['enabled']), 'disabled' => element_children($form['shortcuts']['disabled']), ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e016ae846b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.api.php/function/hook_path_insert/7.x
Give me the example code for `hook_path_insert($path)` in Drupal 7. Hook description: Respond to a path being inserted.
Parameters: - $path: An associative array containing the following keys: - source: The internal system path. - alias: The URL alias. - pid: Unique path alias identifier. - language: The language of the alias. File: modules/path/path.api.php
function hook_path_insert($path) { db_insert('mytable') ->fields(array( 'alias' => $path['alias'], 'pid' => $path['pid'], )) ->execute(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e01b20b96a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_box/7.x
I need the code for `search_box($form, &$form_state, $form_id)` in Drupal 7 (modules/search/search.module). It must do this: Form builder; Output a search form for the search block's search box.
File: modules/search/search.module
function search_box($form, &$form_state, $form_id) { $form[$form_id] = array( '#type' => 'textfield', '#title' => t('Search'), '#title_display' => 'invisible', '#size' => 15, '#default_value' => '', '#attributes' => array('title' => t('Enter the terms you wish to search for.')), ); $form['...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e027433d21
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.module/function/dblog_init/7.x
In Drupal 7, write the function `dblog_init()` (file modules/dblog/dblog.module) so that it does the following: Implements hook_init().
File: modules/dblog/dblog.module
function dblog_init() { if (arg(0) == 'admin' && arg(1) == 'reports') { // Add the CSS for this module drupal_add_css(drupal_get_path('module', 'dblog') . '/dblog.css'); } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e029606de0
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/_drupal_get_filename_fallback/7.x
I need the code for `_drupal_get_filename_fallback($type, $name, $trigger_error, $database_unavailable)` in Drupal 7 (includes/bootstrap.inc). It must do this: Performs a cached file system scan as a fallback when searching for a file.
This function looks for the requested file by triggering a file scan, caching the new location if the file has moved and caching the miss if the file is missing. If a file had been marked as missing in a previous file scan, or if it has been marked as moved and is still in the last known location, no new file scan will...
function _drupal_get_filename_fallback($type, $name, $trigger_error, $database_unavailable) { $file_scans = &_drupal_file_scan_cache(); $filename = NULL; // If the cache indicates that the item is missing, or we can verify that the // item exists in the location the cache says it exists in, use that. if (iss...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e04046e2e0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_details/7.x
Give me the example code for `hook_field_storage_details($field)` in Drupal 7. Hook description: Reveal the internal details about the storage for a field.
For example, an SQL storage module might return the Schema API structure for the table. A key/value storage module might return the server name, authentication credentials, and bin name. Field storage modules are not obligated to implement this hook. Modules that rely on these details must only use them for read opera...
function hook_field_storage_details($field) { $details = array(); // Add field columns. foreach ((array) $field['columns'] as $column_name => $attributes) { $real_name = _field_sql_storage_columnname($field['field_name'], $column_name); $columns[$column_name] = $real_name; } return array( 'sql' =...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e0641063ee
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21ajax.inc/function/ajax_command_html/7.x
Implement `ajax_command_html($selector, $html, $settings = NULL)` in PHP for Drupal 7. Required behavior: Creates a Drupal Ajax 'insert/html' command.
The 'insert/html' command instructs the client to use jQuery's html() method to set the HTML content of each element matched by the given selector while leaving the outer tags intact. This command is implemented by Drupal.ajax.prototype.commands.insert() defined in misc/ajax.js. Parameters: - $selector: A jQuery sele...
function ajax_command_html($selector, $html, $settings = NULL) { return array( 'command' => 'insert', 'method' => 'html', 'selector' => $selector, 'data' => $html, 'settings' => $settings, ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e078162c9d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/update_parse_xml/7.x
I need the code for `update_parse_xml($raw_xml)` in Drupal 7 (modules/update/update.fetch.inc). It must do this: Parses the XML of the Drupal release history info files.
Parameters: - $raw_xml: A raw XML string of available release data for a given project. Returns (Array): of parsed data about releases for a given project, or NULL if there was an error parsing the string. File: modules/update/update.fetch.inc
function update_parse_xml($raw_xml) { try { $xml = new SimpleXMLElement($raw_xml); } catch (Exception $e) { // SimpleXMLElement::__construct produces an E_WARNING error message for // each error found in the XML data and throws an exception if errors // were detected. Catch any exception and retur...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e08173295e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_view_alter/7.x
In Drupal 7, show an example implementation for `hook_node_view_alter(&$build)` (modules/node/node.api.php): Alter the results of node_view().
This hook is called after the content has been assembled in a structured array and may be used for doing processing which requires that the complete node content structure has been built. If the module wishes to act on the rendered HTML of the node rather than the structured content array, it may use this hook to add ...
function hook_node_view_alter(&$build) { if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. $build['an_additional_field']['#weight'] = -10; } // Add a #post_render callback to act on the rendered HTML of the node. $build['#post_render'][] = 'my_module_no...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e0821465d5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_delete_field/7.x
Implement `field_delete_field($field_name)` in PHP for Drupal 7. Required behavior: Marks a field and its instances and data for deletion.
Parameters: - $field_name: The field name to delete. File: modules/field/field.crud.inc
function field_delete_field($field_name) { // Delete all non-deleted instances. $field = field_info_field($field_name); if (isset($field['bundles'])) { foreach ($field['bundles'] as $entity_type => $bundles) { foreach ($bundles as $bundle) { $instance = field_info_instance($entity_type, $field_n...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e0d10dfdfe
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_is_anonymous/7.x
In Drupal 7, write the function `user_is_anonymous()` (file modules/user/user.module) so that it does the following: Determines if the current user is anonymous.
Returns (bool): TRUE if the user is anonymous, FALSE if the user is authenticated. File: modules/user/user.module
function user_is_anonymous() { // Menu administrators can see items for anonymous when administering. return !$GLOBALS['user']->uid || !empty($GLOBALS['menu_admin']); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e0d47a94a7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_field_extra_fields/7.x
Implement `user_field_extra_fields()` in PHP for Drupal 7. Required behavior: Implements hook_field_extra_fields().
File: modules/user/user.module
function user_field_extra_fields() { $return['user']['user'] = array( 'form' => array( 'account' => array( 'label' => t('User name and password'), 'description' => t('User module account form elements.'), 'weight' => -10, ), 'timezone' => array( 'label' => t('Time...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e0d8be60bb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_rmdir/7.x
I need the code for `drupal_rmdir($uri, $context = NULL)` in Drupal 7 (includes/file.inc). It must do this: Removes a directory.
PHP's rmdir() is broken on Windows, as it can fail to remove a directory when it has a read-only flag set. Parameters: - $uri: A URI or pathname. - $context: Refer to http://php.net/manual/ref.stream.php Returns (Boolean): TRUE on success, or FALSE on failure. File: includes/file.inc
function drupal_rmdir($uri, $context = NULL) { $scheme = file_uri_scheme($uri); if ((!$scheme || !file_stream_wrapper_valid_scheme($scheme)) && (substr(PHP_OS, 0, 3) == 'WIN')) { chmod($uri, 0700); } if ($context) { return rmdir($uri, $context); } else { return rmdir($uri); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e0d94aa3a1
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/flood_clear_event/7.x
I need the code for `flood_clear_event($name, $identifier = NULL)` in Drupal 7 (includes/common.inc). It must do this: Makes the flood control mechanism forget an event for the current visitor.
Parameters: - $name: The name of an event. - $identifier: Optional identifier (defaults to the current user's IP address). File: includes/common.inc
function flood_clear_event($name, $identifier = NULL) { if (!isset($identifier)) { $identifier = ip_address(); } db_delete('flood') ->condition('event', $name) ->condition('identifier', $identifier) ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e0e95c7721
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7005/7.x
Implement `user_update_7005(&$sandbox)` in PHP for Drupal 7. Required behavior: Changes the users table to allow longer e-mail addresses.
File: modules/user/user.install
function user_update_7005(&$sandbox) { $mail_field = array( 'type' => 'varchar', 'length' => 254, 'not null' => FALSE, 'default' => '', 'description' => "User's e-mail address.", ); $init_field = array( 'type' => 'varchar', 'length' => 254, 'not null' => FALSE, 'default' => '',...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e13b12a068
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_validate/7.x
In Drupal 7, write the function `forum_node_validate($node, $form)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_validate().
Checks in particular that the node is assigned only a "leaf" term in the forum taxonomy. File: modules/forum/forum.module
function forum_node_validate($node, $form) { if (_forum_node_check_node_type($node)) { $langcode = $form['taxonomy_forums']['#language']; // vocabulary is selected, not a "container" term. if (!empty($node->taxonomy_forums[$langcode])) { // Extract the node's proper topic ID. $containers = var...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e13fc1d779
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_taxonomy_vocabulary_update/7.x
In Drupal 7, write the function `taxonomy_taxonomy_vocabulary_update($vocabulary)` (file modules/taxonomy/taxonomy.module) so that it does the following: Implements hook_taxonomy_vocabulary_update().
File: modules/taxonomy/taxonomy.module
function taxonomy_taxonomy_vocabulary_update($vocabulary) { // Reflect machine name changes in the definitions of existing 'taxonomy' // fields. if (!empty($vocabulary->old_machine_name) && $vocabulary->old_machine_name != $vocabulary->machine_name) { $fields = field_read_fields(); foreach ($fields as $fi...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e15cb448e2
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21pager.inc/function/theme_pager/7.x
Implement `theme_pager($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a query pager.
Menu callbacks that display paged query results should call theme('pager') to retrieve a pager control so that users can view other results. Format a list of nearby pages with additional query results. Parameters: - $variables: An associative array containing: - tags: An array of labels for the controls in the pager. ...
function theme_pager($variables) { $tags = $variables['tags']; $element = $variables['element']; $parameters = $variables['parameters']; $quantity = empty($variables['quantity']) ? 0 : $variables['quantity']; global $pager_page_array, $pager_total; // Nothing to do if there is no pager. if (!isset($pager...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e16eb96763
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.pages.inc/function/profile_browse/7.x
I need the code for `profile_browse()` in Drupal 7 (modules/profile/profile.pages.inc). It must do this: Menu callback; display a list of user information.
File: modules/profile/profile.pages.inc
function profile_browse() { // Ensure that the path is converted to 3 levels always. list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, ''); $field = db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_field} WHERE name = :name", array(':name' => $name))->fetchObject(); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e18f2a03a6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_form_element_label/7.x
Implement `theme_form_element_label($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a form element label and required marker.
Form element labels include the #title and a #required marker. The label is associated with the element itself by the element #id. Labels may appear before or after elements, depending on theme_form_element() and #title_display. This function will not be called for elements with no labels, depending on #title_display....
function theme_form_element_label($variables) { $element = $variables['element']; // This is also used in the installer, pre-database setup. $t = get_t(); // If title and required marker are both empty, output no label. if ((!isset($element['#title']) || $element['#title'] === '') && empty($element['#require...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e19e30cc6f
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_state_keys_no_cache/7.x
I need the code for `form_state_keys_no_cache()` in Drupal 7 (includes/form.inc). It must do this: Returns an array of $form_state keys that shouldn't be cached.
File: includes/form.inc
function form_state_keys_no_cache() { return array( // Public properties defined by form constructors and form handlers. 'always_process', 'must_validate', 'rebuild', 'rebuild_info', 'redirect', 'no_redirect', 'temporary', // Internal properties defined by form processing. 'but...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e1b9121aef
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_node_insert/7.x
I need the code for `taxonomy_node_insert($node)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_node_insert().
File: modules/taxonomy/taxonomy.module
function taxonomy_node_insert($node) { // Add taxonomy index entries for the node. taxonomy_build_node_index($node); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e1c24754fb
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_feed_validate/7.x
I need the code for `aggregator_form_feed_validate($form, &$form_state)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Form validation handler for aggregator_form_feed().
File: modules/aggregator/aggregator.admin.inc
function aggregator_form_feed_validate($form, &$form_state) { if ($form_state['values']['op'] == t('Save')) { // Ensure URL is valid. if (!valid_url($form_state['values']['url'], TRUE)) { form_set_error('url', t('The URL %url is invalid. Enter a fully-qualified URL, such as http://www.example.com/feed.x...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e1c55dcbd5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_add_default_view_mode_settings/7.x
I need the code for `_field_ui_add_default_view_mode_settings($entity_type, $bundle, $view_mode, &$settings)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Populates display settings for a new view mode from the default view mode.
When an administrator decides to use custom display settings for a view mode, that view mode needs to be initialized with the display settings for the 'default' view mode, which it was previously using. This helper function adds the new custom display settings to this bundle's instances, and saves them. It also modifie...
function _field_ui_add_default_view_mode_settings($entity_type, $bundle, $view_mode, &$settings) { // Update display settings for field instances. $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle)); foreach ($instances as $instance) { // If this field instance has dis...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e1ca305772
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_registry_files_alter/7.x
Implement `simpletest_registry_files_alter(&$files, $modules)` in PHP for Drupal 7. Required behavior: Implements hook_registry_files_alter().
Add the test files for disabled modules so that we get a list containing all the available tests. File: modules/simpletest/simpletest.module
function simpletest_registry_files_alter(&$files, $modules) { foreach ($modules as $module) { // Only add test files for disabled modules, as enabled modules should // already include any test files they provide. if (!$module->status) { $dir = $module->dir; if (!empty($module->info['files'])) ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e1cd09db71
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_node_submit/7.x
Implement `menu_node_submit($node, $form, $form_state)` in PHP for Drupal 7. Required behavior: Implements hook_node_submit().
File: modules/menu/menu.module
function menu_node_submit($node, $form, $form_state) { // Decompose the selected menu parent option into 'menu_name' and 'plid', if // the form used the default parent selection widget. if (!empty($form_state['values']['menu']['parent'])) { list($node->menu['menu_name'], $node->menu['plid']) = explode(':', $f...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e1dcb1970c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_modules_uninstall_submit/7.x
I need the code for `system_modules_uninstall_submit($form, &$form_state)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Processes the submitted uninstall form.
File: modules/system/system.admin.inc
function system_modules_uninstall_submit($form, &$form_state) { // Make sure the install API is available. include_once DRUPAL_ROOT . '/includes/install.inc'; if (!empty($form['#confirmed'])) { // Call the uninstall routine for each selected module. $modules = array_keys($form_state['values']['uninstall'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e1e5f31d28
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/list_themes/7.x
In Drupal 7, write the function `list_themes($refresh = FALSE)` (file includes/theme.inc) so that it does the following: Returns a list of all currently available themes.
Retrieved from the database, if available and the site is not in maintenance mode; otherwise compiled freshly from the filesystem. Parameters: - $refresh: Whether to reload the list of themes from the database. Defaults to FALSE. Returns: An associative array of the currently available themes. The keys are the themes...
function list_themes($refresh = FALSE) { $list = &drupal_static(__FUNCTION__, array()); if ($refresh) { $list = array(); system_list_reset(); } if (empty($list)) { $list = array(); $themes = array(); // Extract from the database only when it is available. // Also check that the site is...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e21fce0fb9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/rdf_preprocess_user_profile/7.x
Implement `rdf_preprocess_user_profile(&$variables)` in PHP for Drupal 7. Required behavior: Implements MODULE_preprocess_HOOK().
File: modules/rdf/rdf.module
function rdf_preprocess_user_profile(&$variables) { $account = $variables['elements']['#account']; $uri = entity_uri('user', $account); // Adds RDFa markup to the user profile page. Fields displayed in this page // will automatically describe the user. if (!empty($account->rdf_mapping['rdftype'])) { $var...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e22c85eae5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21path%21path.admin.inc/function/path_admin_edit/7.x
In Drupal 7, write the function `path_admin_edit($path = array())` (file modules/path/path.admin.inc) so that it does the following: Page callback: Returns a form creating or editing a path alias.
Parameters: - $path: An array containing the path ID, source, alias, and language code. Returns: A form for adding or editing a URL alias. File: modules/path/path.admin.inc
function path_admin_edit($path = array()) { if ($path) { drupal_set_title($path['alias']); $output = drupal_get_form('path_admin_form', $path); } else { $output = drupal_get_form('path_admin_form'); } return $output; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e2379cd5f6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21unicode.inc/function/mime_header_encode/7.x
In Drupal 7, write the function `mime_header_encode($string)` (file includes/unicode.inc) so that it does the following: Encodes MIME/HTTP header values that contain incorrectly encoded characters.
For example, mime_header_encode('tést.txt') returns "=?UTF-8?B?dMOpc3QudHh0?=". See http://www.rfc-editor.org/rfc/rfc2047.txt for more information. Notes: - Only encode strings that contain non-ASCII characters. - We progressively cut-off a chunk with truncate_utf8(). This is to ensure each chunk starts and ends on...
function mime_header_encode($string) { if (preg_match('/[^\x20-\x7E]/', $string)) { $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75); $len = strlen($string); $output = ''; while ($len > 0) { $chunk = drupal_truncate_bytes($string, $chunk_size); $output .= ' =?UTF-8?B?' . ba...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e25e586e3c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_display_overview_multistep_js/7.x
I need the code for `field_ui_display_overview_multistep_js($form, &$form_state)` in Drupal 7 (modules/field_ui/field_ui.admin.inc). It must do this: Ajax handler for multistep buttons on the 'Manage display' screen.
File: modules/field_ui/field_ui.admin.inc
function field_ui_display_overview_multistep_js($form, &$form_state) { $trigger = $form_state['triggering_element']; $op = $trigger['#op']; // Pick the elements that need to receive the ajax-new-content effect. switch ($op) { case 'edit': $updated_rows = array($trigger['#field_name']); $updated...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e2601d05aa
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_page_build/7.x
Give me the example code for `hook_page_build(&$page)` in Drupal 7. Hook description: Add elements to a page before it is rendered.
Use this hook when you want to add elements at the page level. For your additions to be printed, they have to be placed below a top level array key of the $page array that has the name of a region of the active theme. By default, valid region keys are 'page_top', 'header', 'sidebar_first', 'content', 'sidebar_second' ...
function hook_page_build(&$page) { if (menu_get_object('node', 1)) { // We are on a node detail page. Append a standard disclaimer to the // content region. $page['content']['disclaimer'] = array( '#markup' => t('Acme, Inc. is not responsible for the contents of this sample code.'), '#weight' ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e2631a7d1a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.module/function/_rdf_mapping_load/7.x
I need the code for `_rdf_mapping_load($type, $bundle)` in Drupal 7 (modules/rdf/rdf.module). It must do this: Helper function to retrieve an RDF mapping from the database.
Parameters: - $type: The entity type the mapping refers to. - $bundle: The bundle the mapping refers to. Returns: An RDF mapping structure or an empty array if no record was found. File: modules/rdf/rdf.module
function _rdf_mapping_load($type, $bundle) { $mappings = _rdf_mapping_load_multiple($type, array($bundle)); return $mappings ? reset($mappings) : array(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e270a6cca6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_update_field/7.x
Give me the example code for `hook_field_update_field($field, $prior_field, $has_data)` in Drupal 7. Hook description: Act on a field being updated.
This hook is invoked just after field is updated in field_update_field(). Parameters: - $field: The field as it is post-update. - $prior_field: The field as it was pre-update. - $has_data: Whether any data already exists for this field. File: modules/field/field.api.php
function hook_field_update_field($field, $prior_field, $has_data) { // Reset the static value that keeps track of allowed values for list fields. drupal_static_reset('list_allowed_values'); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e2d84de5b2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21text%21text.module/function/text_field_widget_info/7.x
I need the code for `text_field_widget_info()` in Drupal 7 (modules/field/modules/text/text.module). It must do this: Implements hook_field_widget_info().
File: modules/field/modules/text/text.module
function text_field_widget_info() { return array( 'text_textfield' => array( 'label' => t('Text field'), 'field types' => array('text'), 'settings' => array('size' => 60), ), 'text_textarea' => array( 'label' => t('Text area (multiple rows)'), 'field types' => array('text_lon...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e2eb58416c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_info_alter/7.x
In Drupal 7, show an example implementation for `hook_field_info_alter(&$info)` (modules/field/field.api.php): Perform alterations on Field API field types.
Parameters: - $info: Array of information on field types exposed by hook_field_info() implementations. File: modules/field/field.api.php
function hook_field_info_alter(&$info) { // Add a setting to all field types. foreach ($info as $field_type => $field_type_info) { $info[$field_type]['settings'] += array( 'mymodule_additional_setting' => 'default value', ); } // Change the default widget for fields of type 'foo'. if (isset($in...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e323244a06
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.module/function/openid_cron/7.x
Implement `openid_cron()` in PHP for Drupal 7. Required behavior: Remove expired nonces from the database.
Implements hook_cron(). File: modules/openid/openid.module
function openid_cron() { db_delete('openid_nonce') ->condition('expires', REQUEST_TIME, '<') ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e329f734d1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x
Give me the example code for `hook_menu()` in Drupal 7. Hook description: Define menu items and page callbacks.
This hook enables modules to register paths in order to define how URL requests are handled. Paths may be registered for URL handling only, or they can register a link to be placed in a menu (usually the Navigation menu). A path and its associated information is commonly called a "menu router item". This hook is rarely...
function hook_menu() { $items['example'] = array( 'title' => 'Example Page', 'page callback' => 'example_page', 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, ); $items['example/feed'] = array( 'title' => 'Example RSS feed', 'page callback' => 'example_feed',...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e32ce9fc1b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.admin.inc/function/block_custom_block_delete_submit/7.x
In Drupal 7, write the function `block_custom_block_delete_submit($form, &$form_state)` (file modules/block/block.admin.inc) so that it does the following: Form submission handler for block_custom_block_delete().
File: modules/block/block.admin.inc
function block_custom_block_delete_submit($form, &$form_state) { db_delete('block_custom') ->condition('bid', $form_state['values']['bid']) ->execute(); db_delete('block') ->condition('module', 'block') ->condition('delta', $form_state['values']['bid']) ->execute(); db_delete('block_role') ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e33367d348
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/_menu_link_translate/7.x
In Drupal 7, write the function `_menu_link_translate(&$item, $translate = FALSE)` (file includes/menu.inc) so that it does the following: Provides menu link access control, translation, and argument handling.
This function is similar to _menu_translate(), but it also does link-specific preparation (such as always calling to_arg() functions). Parameters: - $item: A menu link. - $translate: (optional) Whether to try to translate a link containing dynamic path argument placeholders (%) based on the menu router item of the cur...
function _menu_link_translate(&$item, $translate = FALSE) { if (!is_array($item['options'])) { $item['options'] = unserialize($item['options']); } if ($item['external']) { $item['access'] = 1; $map = array(); $item['href'] = $item['link_path']; $item['title'] = $item['link_title']; $item['...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e345815027
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21lock.inc/function/lock_release/7.x
Implement `lock_release($name)` in PHP for Drupal 7. Required behavior: Release a lock previously acquired by lock_acquire().
This will release the named lock if it is still held by the current request. Parameters: - $name: The name of the lock. File: includes/lock.inc
function lock_release($name) { global $locks; unset($locks[$name]); db_delete('semaphore') ->condition('name', $name) ->condition('value', _lock_id()) ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e353c29960
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_forum_load/7.x
I need the code for `forum_forum_load($tid = NULL)` in Drupal 7 (modules/forum/forum.module). It must do this: Returns a tree of all forums for a given taxonomy term ID.
Parameters: - $tid: (optional) Taxonomy term ID of the forum. If not given all forums will be returned. Returns: A tree of taxonomy objects, with the following additional properties: - num_topics: Number of topics in the forum. - num_posts: Total number of posts in all topics. - last_post: Most recent post for the for...
function forum_forum_load($tid = NULL) { $cache = &drupal_static(__FUNCTION__, array()); // Return a cached forum tree if available. if (!isset($tid)) { $tid = 0; } if (isset($cache[$tid])) { return $cache[$tid]; } $vid = variable_get('forum_nav_vocabulary', 0); // Load and validate the paren...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e3a3550a1b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.admin.inc/function/contact_category_edit_form_validate/7.x
I need the code for `contact_category_edit_form_validate($form, &$form_state)` in Drupal 7 (modules/contact/contact.admin.inc). It must do this: Form validation handler for contact_category_edit_form().
File: modules/contact/contact.admin.inc
function contact_category_edit_form_validate($form, &$form_state) { // Validate and each e-mail recipient. $recipients = explode(',', $form_state['values']['recipients']); // When creating a new contact form, or renaming the category on an existing // contact form, make sure that the given category is unique. ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e3b94afc34
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_discovery_method_info/7.x
In Drupal 7, show an example implementation for `hook_openid_discovery_method_info()` (modules/openid/openid.api.php): Allow modules to declare OpenID discovery methods.
The discovery function callbacks will be called in turn with an unique parameter, the claimed identifier. They have to return an associative array with array of services and claimed identifier in the same form as returned by openid_discover(). The resulting array must contain following keys: - 'services' (required) a...
function hook_openid_discovery_method_info() { return array( 'new_discovery_idea' => '_my_discovery_method', ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e40558eb14
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_get_form/7.x
In Drupal 7, write the function `drupal_get_form($form_id)` (file includes/form.inc) so that it does the following: Returns a renderable form array for a given form ID.
This function should be used instead of drupal_build_form() when $form_state is not needed (i.e., when initially rendering the form) and is often used as a menu callback. Parameters: - $form_id: The unique string identifying the desired form. If a function with that name exists, it is called to build the form array. M...
function drupal_get_form($form_id) { $form_state = array(); $args = func_get_args(); // Remove $form_id from the arguments. array_shift($args); $form_state['build_info']['args'] = $args; return drupal_build_form($form_id, $form_state); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e40ca20c6b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.field.inc/function/file_field_formatter_view/7.x
Implement `file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)` in PHP for Drupal 7. Required behavior: Implements hook_field_formatter_view().
File: modules/file/file.field.inc
function file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); switch ($display['type']) { case 'file_default': foreach ($items as $delta => $item) { $element[$delta] = array( '#theme' => 'file_link', '#file' => ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e45592ee90
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_run_tests/7.x
I need the code for `simpletest_run_tests($test_list, $reporter = 'drupal')` in Drupal 7 (modules/simpletest/simpletest.module). It must do this: Actually runs tests.
Parameters: - $test_list: List of tests to run. - $reporter: Which reporter to use. Allowed values are: text, xml, html and drupal, drupal being the default. File: modules/simpletest/simpletest.module
function simpletest_run_tests($test_list, $reporter = 'drupal') { $test_id = db_insert('simpletest_test_id') ->useDefaults(array('test_id')) ->execute(); // Clear out the previous verbose files. file_unmanaged_delete_recursive('public://simpletest/verbose'); // Get the info for the first test being ru...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e459774e70
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21profile%21profile.module/function/profile_help/7.x
I need the code for `profile_help($path, $arg)` in Drupal 7 (modules/profile/profile.module). It must do this: Implements hook_help().
File: modules/profile/profile.module
function profile_help($path, $arg) { switch ($path) { case 'admin/help#profile': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Profile module allows site administrators to define custom fields (such as country, full name, or age) for user profiles, which are t...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e45ddf1455
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21module.inc/function/module_list/7.x
In Drupal 7, write the function `module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL)` (file includes/module.inc) so that it does the following: Returns a list of currently active modules.
Usually, this returns a list of all enabled modules. When called early on in the bootstrap, it will return a list of vital modules only (those needed to generate cached pages). All parameters to this function are optional and should generally not be changed from their defaults. Parameters: - $refresh: (optional) Whet...
function module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL) { static $list = array(), $sorted_list; if (empty($list) || $refresh || $fixed_list) { $list = array(); $sorted_list = NULL; if ($fixed_list) { foreach ($fixed_list as $name => $module) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e463d11e9b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_mail_alter/7.x
I need the code for `simpletest_mail_alter(&$message)` in Drupal 7 (modules/simpletest/simpletest.module). It must do this: Implements hook_mail_alter().
Aborts sending of messages with ID 'simpletest_cancel_test'. File: modules/simpletest/simpletest.module
function simpletest_mail_alter(&$message) { if ($message['id'] == 'simpletest_cancel_test') { $message['send'] = FALSE; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e46e730a03
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.module/function/field_ui_field_attach_rename_bundle/7.x
I need the code for `field_ui_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new)` in Drupal 7 (modules/field_ui/field_ui.module). It must do this: Implements hook_field_attach_rename_bundle().
File: modules/field_ui/field_ui.module
function field_ui_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { // The Field UI relies on entity_get_info() to build menu items for entity // field administration pages. Clear the entity info cache and ensure that // the menu is rebuilt. entity_info_cache_clear(); menu_rebuild(); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e475211129
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_update/7.x
In Drupal 7, write the function `forum_node_update($node)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_update().
File: modules/forum/forum.module
function forum_node_update($node) { if (_forum_node_check_node_type($node)) { if (empty($node->revision) && db_query('SELECT tid FROM {forum} WHERE nid=:nid', array(':nid' => $node->nid))->fetchField()) { if (!empty($node->forum_tid)) { db_update('forum') ->fields(array('tid' => $node->for...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-e48500a2e0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_query/7.x
In Drupal 7, show an example implementation for `hook_field_storage_query($query)` (modules/field/field.api.php): Execute an EntityFieldQuery.
This hook is called to find the entities having certain entity and field conditions and sort them in the given field order. If the field storage engine also handles property sorts and orders, it should unset those properties in the called object to signal that those have been handled. Parameters: - $query (EntityField...
function hook_field_storage_query($query) { $groups = array(); if ($query->age == FIELD_LOAD_CURRENT) { $tablename_function = '_field_sql_storage_tablename'; $id_key = 'entity_id'; } else { $tablename_function = '_field_sql_storage_revision_tablename'; $id_key = 'revision_id'; } $table_alias...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e4d30b16cf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_create_field/7.x
In Drupal 7, show an example implementation for `hook_field_storage_create_field($field)` (modules/field/field.api.php): Act on creation of a new field.
This hook is invoked from field_create_field() to ask the field storage module to save field information and prepare for storing field instances. If there is a problem, the field storage module should throw an exception. Parameters: - $field: The field structure being created. File: modules/field/field.api.php
function hook_field_storage_create_field($field) { $schema = _field_sql_storage_schema($field); foreach ($schema as $name => $table) { db_create_table($name, $table); } drupal_get_schema(NULL, TRUE); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-e4d71d4fa5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_assign/7.x
I need the code for `trigger_assign($module_to_display = NULL)` in Drupal 7 (modules/trigger/trigger.admin.inc). It must do this: Builds a form that allows users to assign actions to triggers.
Parameters: - $module_to_display: Which tab of triggers to display. E.g., 'node' for all node-related triggers. Returns: HTML form. File: modules/trigger/trigger.admin.inc
function trigger_assign($module_to_display = NULL) { // If no type is specified we default to node actions, since they // are the most common. if (!isset($module_to_display)) { drupal_goto('admin/structure/trigger/node'); } $build = array(); $trigger_info = module_invoke_all('trigger_info'); drupal_a...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e4ee52d96e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_delete/7.x
Implement `field_attach_delete($entity_type, $entity)` in PHP for Drupal 7. Required behavior: Delete field data for an existing entity. This deletes all revisions of field data for the entity.
Parameters: - $entity_type: The type of $entity; e.g. 'node' or 'user'. - $entity: The entity whose field data to delete. File: modules/field/field.attach.inc
function field_attach_delete($entity_type, $entity) { _field_invoke('delete', $entity_type, $entity); list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); // Collect the storage backends used by the fields in the entities. $storages = array(); foreach (field_info_instances($entity_type, $bu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e4eec8d079
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_local_actions/7.x
I need the code for `menu_local_actions()` in Drupal 7 (includes/menu.inc). It must do this: Returns the rendered local actions at the current level.
File: includes/menu.inc
function menu_local_actions() { $links = menu_local_tasks(); return $links['actions']['output']; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-e545e3d38f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_menu/7.x
In Drupal 7, write the function `overlay_menu()` (file modules/overlay/overlay.module) so that it does the following: Implements hook_menu().
File: modules/overlay/overlay.module
function overlay_menu() { $items['overlay-ajax/%'] = array( 'title' => '', 'page callback' => 'overlay_ajax_render_region', 'page arguments' => array(1), 'access arguments' => array('access overlay'), 'type' => MENU_CALLBACK, ); $items['overlay/dismiss-message'] = array( 'title' => '', ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00