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-234496cc98
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_menu/7.x
Implement `forum_menu()` in PHP for Drupal 7. Required behavior: Implements hook_menu().
File: modules/forum/forum.module
function forum_menu() { $items['forum'] = array( 'title' => 'Forums', 'page callback' => 'forum_page', 'access arguments' => array('access content'), 'file' => 'forum.pages.inc', ); $items['forum/%forum_forum'] = array( 'title' => 'Forums', 'page callback' => 'forum_page', 'page argume...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2372937c65
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_stream_wrappers_alter/7.x
Give me the example code for `hook_stream_wrappers_alter(&$wrappers)` in Drupal 7. Hook description: Alters the list of PHP stream wrapper implementations.
File: modules/system/system.api.php
function hook_stream_wrappers_alter(&$wrappers) { // Change the name of private files to reflect the performance. $wrappers['private']['name'] = t('Slow files'); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-23d756fd7a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_modules_enabled/7.x
In Drupal 7, show an example implementation for `hook_modules_enabled($modules)` (modules/system/system.api.php): Perform necessary actions after modules are enabled.
This function differs from hook_enable() in that it gives all other modules a chance to perform actions when modules are enabled, whereas hook_enable() is only called on the module actually being enabled. See module_enable() for a detailed description of the order in which install and enable hooks are invoked. Paramet...
function hook_modules_enabled($modules) { if (in_array('lousy_module', $modules)) { drupal_set_message(t('mymodule is not compatible with lousy_module'), 'error'); mymodule_disable_functionality(); } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-23df2c4ef0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.install/function/taxonomy_schema/7.x
I need the code for `taxonomy_schema()` in Drupal 7 (modules/taxonomy/taxonomy.install). It must do this: Implements hook_schema().
File: modules/taxonomy/taxonomy.install
function taxonomy_schema() { $schema['taxonomy_term_data'] = array( 'description' => 'Stores term information.', 'fields' => array( 'tid' => array( 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'Primary Key: Unique term ID.', ), ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-23dfa349fa
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21install.inc/function/drupal_requirements_url/7.x
Implement `drupal_requirements_url($severity)` in PHP for Drupal 7. Required behavior: Returns a URL for proceeding to the next page after a requirements problem.
This function can be called by low-level scripts (such as install.php and update.php) and returns a URL that can be used to attempt to proceed to the next step of the script. Parameters: - $severity: The severity of the requirements problem, as returned by drupal_requirements_severity(). Returns: A URL for attempting...
function drupal_requirements_url($severity) { $query = array(); // If there are no errors, only warnings, append 'continue=1' to the URL so // the user can bypass this screen on the next page load. if ($severity == REQUIREMENT_WARNING) { $query['continue'] = 1; } return drupal_current_script_url($query)...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-23e6e1dd15
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_rdf_mapping/7.x
Implement `comment_rdf_mapping()` in PHP for Drupal 7. Required behavior: Implements hook_rdf_mapping().
File: modules/comment/comment.module
function comment_rdf_mapping() { return array( array( 'type' => 'comment', 'bundle' => RDF_DEFAULT_BUNDLE, 'mapping' => array( 'rdftype' => array('sioc:Post', 'sioct:Comment'), 'title' => array( 'predicates' => array('dc:title'), ), 'created' => array( ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-23fa1e58cc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_scheme_form_submit/7.x
I need the code for `color_scheme_form_submit($form, &$form_state)` in Drupal 7 (modules/color/color.module). It must do this: Form submission handler for color_scheme_form().
File: modules/color/color.module
function color_scheme_form_submit($form, &$form_state) { // Get theme coloring info. if (!isset($form_state['values']['info'])) { return; } $theme = $form_state['values']['theme']; $info = $form_state['values']['info']; // Resolve palette. $palette = $form_state['values']['palette']; if ($form_stat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-242c4c1051
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_prepare_directory/7.x
I need the code for `file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)` in Drupal 7 (includes/file.inc). It must do this: Checks that the directory exists and is writable.
Directories need to have execute permissions to be considered a directory by FTP servers, etc. Parameters: - $directory: A string reference containing the name of a directory path or URI. A trailing slash will be trimmed from a path. - $options: A bitmask to indicate if the directory should be created if it does not e...
function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) { if (!file_stream_wrapper_valid_scheme(file_uri_scheme($directory))) { // Only trim if we're not dealing with a stream. $directory = rtrim($directory, '/\\'); } // Check if directory exists. if (!is_dir($directory)) { ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-242f92e06f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21php%21php.module/function/php_permission/7.x
In Drupal 7, write the function `php_permission()` (file modules/php/php.module) so that it does the following: Implements hook_permission().
File: modules/php/php.module
function php_permission() { return array( 'use PHP for settings' => array( 'title' => t('Use PHP for settings'), 'restrict access' => TRUE, ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-243d30e3ed
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7005/7.x
I need the code for `node_update_7005()` in Drupal 7 (modules/node/node.install). It must do this: Add status/comment/promote and sticky columns to the {node_revision} table.
File: modules/node/node.install
function node_update_7005() { foreach (array('status', 'comment', 'promote', 'sticky') as $column) { db_add_field('node_revision', $column, array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, )); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-247a666175
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_goto/7.x
I need the code for `drupal_goto($path = '', array $options = array(), $http_response_code = 302)` in Drupal 7 (includes/common.inc). It must do this: Sends the user to a different page.
This issues an on-site HTTP redirect. The function makes sure the redirected URL is formatted correctly. Usually the redirected URL is constructed from this function's input parameters. However you may override that behavior by setting a destination in either the $_REQUEST-array (i.e. by using the query string of an U...
function drupal_goto($path = '', array $options = array(), $http_response_code = 302) { // A destination in $_GET always overrides the function arguments. // We do not allow absolute URLs to be passed via $_GET, as this can be an attack vector. if (isset($_GET['destination']) && !url_is_external($_GET['destinatio...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2485e664bf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21rdf%21rdf.api.php/function/hook_rdf_namespaces/7.x
Give me the example code for `hook_rdf_namespaces()` in Drupal 7. Hook description: Allow modules to define namespaces for RDF mappings.
Many common namespace prefixes are defined in rdf_rdf_namespaces(). However, if a module implements hook_rdf_mapping() and uses a prefix that is not defined in rdf_rdf_namespaces(), this hook should be used to define the new namespace prefix. Returns: An associative array of namespaces where the key is the namespace p...
function hook_rdf_namespaces() { return array( 'content' => 'http://purl.org/rss/1.0/modules/content/', 'dc' => 'http://purl.org/dc/terms/', 'foaf' => 'http://xmlns.com/foaf/0.1/', 'og' => 'http://ogp.me/ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'sioc' =...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-24961b818b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/element_validate_number/7.x
In Drupal 7, write the function `element_validate_number($element, &$form_state)` (file includes/form.inc) so that it does the following: Form element validation handler for number elements.
File: includes/form.inc
function element_validate_number($element, &$form_state) { $value = $element['#value']; if ($value != '' && !is_numeric($value)) { form_error($element, t('%name must be a number.', array('%name' => $element['#title']))); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-24a24ccfb7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.api.php/function/hook_block_save/7.x
Give me the example code for `hook_block_save($delta = '', $edit = array())` in Drupal 7. Hook description: Save the configuration options from hook_block_configure().
This hook allows you to save the block-specific configuration settings defined within your hook_block_configure(). Parameters: - $delta: Which block is being configured. This is a unique identifier for the block within the module, defined in hook_block_info(). - $edit: The submitted form data from the configuration fo...
function hook_block_save($delta = '', $edit = array()) { // This example comes from node.module. if ($delta == 'recent') { variable_set('node_recent_block_count', $edit['node_recent_block_count']); } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-24a2a24884
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_delete_file_if_stale/7.x
In Drupal 7, write the function `drupal_delete_file_if_stale($uri)` (file includes/common.inc) so that it does the following: Callback to delete files modified more than a set time ago.
File: includes/common.inc
function drupal_delete_file_if_stale($uri) { // Default stale file threshold is 30 days. if (REQUEST_TIME - filemtime($uri) > variable_get('drupal_stale_file_threshold', 2592000)) { file_unmanaged_delete($uri); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-24bde54be0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contact%21contact.module/function/contact_menu/7.x
In Drupal 7, write the function `contact_menu()` (file modules/contact/contact.module) so that it does the following: Implements hook_menu().
File: modules/contact/contact.module
function contact_menu() { $items['admin/structure/contact'] = array( 'title' => 'Contact form', 'description' => 'Create a system contact form and set up categories for the form to use.', 'page callback' => 'contact_category_list', 'access arguments' => array('administer contact forms'), 'file' =>...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-24c33aaf3b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_rebuild_module_data/7.x
Implement `system_rebuild_module_data()` in PHP for Drupal 7. Required behavior: Rebuild, save, and return data about all currently available modules.
Returns (Array): of all available modules and their data. File: modules/system/system.module
function system_rebuild_module_data() { $modules_cache = &drupal_static(__FUNCTION__); // Only rebuild once per request. $modules and $modules_cache cannot be // combined into one variable, because the $modules_cache variable is reset by // reference from system_list_reset() during the rebuild. if (!isset($mo...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-24d1b00bd7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.admin.inc/function/filter_admin_overview/7.x
In Drupal 7, write the function `filter_admin_overview($form)` (file modules/filter/filter.admin.inc) so that it does the following: Page callback: Form constructor for a form to list and reorder text formats.
File: modules/filter/filter.admin.inc
function filter_admin_overview($form) { // Overview of all formats. $formats = filter_formats(); $fallback_format = filter_fallback_format(); $form['#tree'] = TRUE; foreach ($formats as $id => $format) { // Check whether this is the fallback text format. This format is available // to all roles and c...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-24dce85df5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_get_filters/7.x
I need the code for `filter_get_filters()` in Drupal 7 (modules/filter/filter.module). It must do this: Returns a list of all filters provided by modules.
Returns (array): An array of filter formats. File: modules/filter/filter.module
function filter_get_filters() { $filters = &drupal_static(__FUNCTION__, array()); if (empty($filters)) { foreach (module_implements('filter_info') as $module) { $info = module_invoke($module, 'filter_info'); if (isset($info) && is_array($info)) { // Assign the name of the module implementin...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-24df0b4179
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.pages.inc/function/book_outline_form_submit/7.x
Implement `book_outline_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for book_outline_form().
File: modules/book/book.pages.inc
function book_outline_form_submit($form, &$form_state) { $node = $form['#node']; $form_state['redirect'] = "node/" . $node->nid; $book_link = $form_state['values']['book']; if (!$book_link['bid']) { drupal_set_message(t('No changes were made')); return; } $book_link['menu_name'] = book_menu_name($...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2503c8f7c2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_style_delete/7.x
Give me the example code for `hook_image_style_delete($style)` in Drupal 7. Hook description: Respond to image style deletion.
This hook enables modules to update settings when a image style is being deleted. If a style is deleted, a replacement name may be specified in $style['name'] and the style being deleted will be specified in $style['old_name']. Parameters: - $style: The image style array that being deleted. File: modules/image/image....
function hook_image_style_delete($style) { // Administrators can choose an optional replacement style when deleting. // Update the modules style variable accordingly. if (isset($style['old_name']) && $style['old_name'] == variable_get('mymodule_image_style', '')) { variable_set('mymodule_image_style', $style[...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-250e95db29
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/timer_read/7.x
Implement `timer_read($name)` in PHP for Drupal 7. Required behavior: Reads the current timer value without stopping the timer.
Parameters: - $name: The name of the timer. Returns: The current timer value in ms. File: includes/bootstrap.inc
function timer_read($name) { global $timers; if (isset($timers[$name]['start'])) { $stop = microtime(TRUE); $diff = round(($stop - $timers[$name]['start']) * 1000, 2); if (isset($timers[$name]['time'])) { $diff += $timers[$name]['time']; } return $diff; } return $timers[$name]['time'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2511b8b645
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_hidden/7.x
In Drupal 7, write the function `theme_hidden($variables)` (file includes/form.inc) so that it does the following: Returns HTML for a hidden form element.
Parameters: - $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #name, #value, #attributes. File: includes/form.inc
function theme_hidden($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'hidden'; element_set_attributes($element, array('name', 'value')); return '<input' . drupal_attributes($element['#attributes']) . " />\n"; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-251659f50e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_assign_form_submit/7.x
Implement `trigger_assign_form_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submission handler for trigger_assign_form().
File: modules/trigger/trigger.admin.inc
function trigger_assign_form_submit($form, &$form_state) { if (!empty($form_state['values']['aid'])) { $aid = actions_function_lookup($form_state['values']['aid']); $weight = db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook", array(':hook' => $form_state['values']['hook']))->fetchFie...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-253eb08c9e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_date_types/7.x
In Drupal 7, write the function `system_get_date_types($type = NULL)` (file modules/system/system.module) so that it does the following: Gets the list of available date types and attributes.
Parameters: - $type: (optional) The date type name. Returns: An associative array of date type information keyed by the date type name. Each date type information array has the following elements: - type: The machine-readable name of the date type. - title: The human-readable name of the date type. - locked: A boolean...
function system_get_date_types($type = NULL) { $types = &drupal_static(__FUNCTION__); if (!isset($types)) { $types = _system_date_format_types_build(); } return $type ? (isset($types[$type]) ? $types[$type] : FALSE) : $types; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2551842946
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_url_alter/7.x
Give me the example code for `hook_file_url_alter(&$uri)` in Drupal 7. Hook description: Alter the URL to a file.
This hook is called from file_create_url(), and is called fairly frequently (10+ times per page), depending on how many files there are in a given page. If CSS and JS aggregation are disabled, this can become very frequently (50+ times per page) so performance is critical. This function should alter the URI, if it wa...
function hook_file_url_alter(&$uri) { global $user; // User 1 will always see the local file in this example. if ($user->uid == 1) { return; } $cdn1 = 'http://cdn1.example.com'; $cdn2 = 'http://cdn2.example.com'; $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png'); // Most CDNs don'...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-256bfe3ab8
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_build_tree/7.x
In Drupal 7, write the function `menu_build_tree($menu_name, array $parameters = array())` (file includes/menu.inc) so that it does the following: Builds a menu tree, translates links, and checks access.
Parameters: - $menu_name: The name of the menu. - $parameters: (optional) An associative array of build parameters. Possible keys: - expanded: An array of parent link ids to return only menu links that are children of one of the plids in this list. If empty, the whole menu tree is built, unless 'only_active_trail' is T...
function menu_build_tree($menu_name, array $parameters = array()) { // Build the menu tree. $data = _menu_build_tree($menu_name, $parameters); // Check access for the current user to each item in the tree. menu_tree_check_access($data['tree'], $data['node_links']); return $data['tree']; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-257e4c5296
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/_update_refresh/7.x
I need the code for `_update_refresh()` in Drupal 7 (modules/update/update.fetch.inc). It must do this: Clears out all the cached available update data and initiates re-fetching.
File: modules/update/update.fetch.inc
function _update_refresh() { module_load_include('inc', 'update', 'update.compare'); // Since we're fetching new available update data, we want to clear // our cache of both the projects we care about, and the current update // status of the site. We do *not* want to clear the cache of available // releases ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-258f1cd352
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_set_regions_to_render/7.x
In Drupal 7, write the function `overlay_set_regions_to_render($regions = NULL)` (file modules/overlay/overlay.module) so that it does the following: Sets the regions of the page that rendering will be limited to.
Parameters: - $regions: (Optional) An array containing the names of the regions that should be rendered when drupal_render_page() is called. Pass in an empty array to remove all limits and cause drupal_render_page() to render all page regions (the default behavior). If this parameter is omitted, no change will be made ...
function overlay_set_regions_to_render($regions = NULL) { $regions_to_render = &drupal_static(__FUNCTION__, array()); if (isset($regions)) { $regions_to_render = $regions; } return $regions_to_render; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-259586e372
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_filters/7.x
Implement `dblog_filters()` in PHP for Drupal 7. Required behavior: Creates a list of database log administration filters that can be applied.
Returns (array): Associative array of filters. The top-level keys are used as the form element names for the filters, and the values are arrays with the following elements: - title: Title of the filter. - where: The filter condition. - options: Array of options for the select list for the filter. File: modules/dblog/d...
function dblog_filters() { $filters = array(); foreach (_dblog_get_message_types() as $type) { $types[$type] = t($type); } if (!empty($types)) { $filters['type'] = array( 'title' => t('Type'), 'where' => "w.type = ?", 'options' => $types, ); } $filters['severity'] = array( ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-259c772c06
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.install/function/aggregator_uninstall/7.x
In Drupal 7, write the function `aggregator_uninstall()` (file modules/aggregator/aggregator.install) so that it does the following: Implements hook_uninstall().
File: modules/aggregator/aggregator.install
function aggregator_uninstall() { variable_del('aggregator_allowed_html_tags'); variable_del('aggregator_summary_items'); variable_del('aggregator_clear'); variable_del('aggregator_category_selector'); variable_del('aggregator_fetcher'); variable_del('aggregator_parser'); variable_del('aggregator_processo...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-259e5935d7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21help%21help.admin.inc/function/help_main/7.x
I need the code for `help_main()` in Drupal 7 (modules/help/help.admin.inc). It must do this: Menu callback; prints a page listing a glossary of Drupal terminology.
File: modules/help/help.admin.inc
function help_main() { // Add CSS drupal_add_css(drupal_get_path('module', 'help') . '/help.css'); $output = '<h2>' . t('Help topics') . '</h2><p>' . t('Help is available on the following items:') . '</p>' . help_links_as_list(); return $output; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-25ca9f1a44
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_ip_blocking_form/7.x
I need the code for `system_ip_blocking_form($form, $form_state, $default_ip)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Define the form for blocking IP addresses.
File: modules/system/system.admin.inc
function system_ip_blocking_form($form, $form_state, $default_ip) { $form['ip'] = array( '#title' => t('IP address'), '#type' => 'textfield', '#size' => 48, '#maxlength' => 40, '#default_value' => $default_ip, '#description' => t('Enter a valid IP address.'), ); $form['actions'] = array('#...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-25d6898809
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_effect_delete_form/7.x
I need the code for `image_effect_delete_form($form, &$form_state, $style, $effect)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Form builder; Form for deleting an image effect.
Parameters: - $style: Name of the image style from which the image effect will be removed. - $effect: Name of the image effect to remove. File: modules/image/image.admin.inc
function image_effect_delete_form($form, &$form_state, $style, $effect) { $form_state['image_style'] = $style; $form_state['image_effect'] = $effect; $question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style['label'], '@effect' => $effect['label'])); re...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-25e00e6727
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_rss_feeds_settings/7.x
Implement `system_rss_feeds_settings()` in PHP for Drupal 7. Required behavior: Form builder; Configure how the site handles RSS feeds.
File: modules/system/system.admin.inc
function system_rss_feeds_settings() { $form['feed_description'] = array( '#type' => 'textarea', '#title' => t('Feed description'), '#default_value' => variable_get('feed_description', ''), '#description' => t('Description of your site, included in each feed.') ); $form['feed_default_items'] = arr...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-25f4161852
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_render_blocks/7.x
In Drupal 7, write the function `_block_render_blocks($region_blocks)` (file modules/block/block.module) so that it does the following: Render the content and subject for a set of blocks.
Parameters: - $region_blocks: An array of block objects such as returned for one region by _block_load_blocks(). Returns: An array of visible blocks as expected by drupal_render(). File: modules/block/block.module
function _block_render_blocks($region_blocks) { $cacheable = TRUE; // We preserve the submission of forms in blocks, by fetching from cache only // if the request method is 'GET' (or 'HEAD'). if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != 'HEAD') { $cacheable = FALSE; } // Blo...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-25ffd13eb8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_cron/7.x
In Drupal 7, write the function `update_cron()` (file modules/update/update.module) so that it does the following: Implements hook_cron().
File: modules/update/update.module
function update_cron() { $frequency = variable_get('update_check_frequency', 1); $interval = 60 * 60 * 24 * $frequency; if ((REQUEST_TIME - variable_get('update_last_check', 0)) > $interval) { // If the configured update interval has elapsed, we want to invalidate // the cached data for all projects, atte...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-26211ddd3f
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_directory_temp/7.x
I need the code for `file_directory_temp()` in Drupal 7 (includes/file.inc). It must do this: Gets the path of system-appropriate temporary directory.
File: includes/file.inc
function file_directory_temp() { $temporary_directory = variable_get('file_temporary_path', NULL); if (empty($temporary_directory)) { $directories = array(); // Has PHP been set with an upload_tmp_dir? if (ini_get('upload_tmp_dir')) { $directories[] = ini_get('upload_tmp_dir'); } // Ope...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-26453b8421
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/update_create_fetch_task/7.x
I need the code for `update_create_fetch_task($project)` in Drupal 7 (modules/update/update.module). It must do this: Creates a new fetch task after loading the necessary include file.
Parameters: - $project: Associative array of information about a project. See update_get_projects() for the keys used. File: modules/update/update.module
function update_create_fetch_task($project) { module_load_include('inc', 'update', 'update.fetch'); return _update_create_fetch_task($project); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2651d14dbe
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/_field_extra_fields_pre_render/7.x
In Drupal 7, write the function `_field_extra_fields_pre_render($elements)` (file modules/field/field.module) so that it does the following: Pre-render callback to adjust weights and visibility of non-field elements.
File: modules/field/field.module
function _field_extra_fields_pre_render($elements) { $entity_type = $elements['#entity_type']; $bundle = $elements['#bundle']; if (isset($elements['#type']) && $elements['#type'] == 'form') { $extra_fields = field_info_extra_fields($entity_type, $bundle, 'form'); foreach ($extra_fields as $name => $setti...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-26539e814c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.api.php/function/hook_overlay_parent_initialize/7.x
In Drupal 7, show an example implementation for `hook_overlay_parent_initialize()` (modules/overlay/overlay.api.php): Allow modules to act when an overlay parent window is initialized.
The parent window is initialized when a page is displayed in which the overlay might be required to be displayed, so modules can act here if they need to take action to accommodate the possibility of the overlay appearing within a Drupal page. File: modules/overlay/overlay.api.php
function hook_overlay_parent_initialize() { // Add our custom JavaScript. drupal_add_js(drupal_get_path('module', 'hook') . '/hook-overlay.js'); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-265d27fa0f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_region_list/7.x
In Drupal 7, write the function `system_region_list($theme_key, $show = REGIONS_ALL, $labels = TRUE)` (file modules/system/system.module) so that it does the following: Get a list of available regions from a specified theme.
Parameters: - $theme_key: The name of a theme. - $show: Possible values: REGIONS_ALL or REGIONS_VISIBLE. Visible excludes hidden regions. - $labels (bool): (optional) Boolean to specify whether the human readable machine names should be returned or not. Defaults to TRUE, but calling code can set this to FALSE for bette...
function system_region_list($theme_key, $show = REGIONS_ALL, $labels = TRUE) { $themes = list_themes(); if (!isset($themes[$theme_key])) { return array(); } $list = array(); $info = $themes[$theme_key]->info; // If requested, suppress hidden regions. See block_admin_display_form(). foreach ($info['re...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-265e145dd3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.fetch.inc/function/_update_fetch_data/7.x
Implement `_update_fetch_data()` in PHP for Drupal 7. Required behavior: Attempts to drain the queue of tasks for release history data to fetch.
File: modules/update/update.fetch.inc
function _update_fetch_data() { $queue = DrupalQueue::get('update_fetch_tasks'); $end = time() + variable_get('update_max_fetch_time', UPDATE_MAX_FETCH_TIME); while (time() < $end && ($item = $queue->claimItem())) { _update_process_fetch_task($item->data); $queue->deleteItem($item); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-266c11f344
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/form_type_radios_value/7.x
In Drupal 7, write the function `form_type_radios_value(&$element, $input = FALSE)` (file includes/form.inc) so that it does the following: Form value callback: Determines the value for a #type radios form element.
Parameters: - $element: The form element whose value is being populated. - $input: (optional) The incoming input to populate the form element. If FALSE, the element's default value is returned. Defaults to FALSE. Returns: The data that will appear in $form_state['values'] for this element, or nothing to use the defaul...
function form_type_radios_value(&$element, $input = FALSE) { if ($input !== FALSE) { // When there's user input (including NULL), return it as the value. // However, if NULL is submitted, _form_builder_handle_input_element() will // apply the default value, and we want that validated against #options ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-26b2d3ad9b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_rehash/7.x
I need the code for `_block_rehash($theme = NULL)` in Drupal 7 (modules/block/block.module). It must do this: Updates the 'block' DB table with the blocks currently exported by modules.
Parameters: - $theme: The theme to rehash blocks for. If not provided, defaults to the currently used theme. Returns: Blocks currently exported by modules. File: modules/block/block.module
function _block_rehash($theme = NULL) { global $theme_key; drupal_theme_initialize(); if (!isset($theme)) { // If theme is not specifically set, rehash for the current theme. $theme = $theme_key; } $regions = system_region_list($theme); // These are the blocks the function will return. $blocks =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-26c39e1406
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contextual%21contextual.module/function/contextual_library/7.x
Implement `contextual_library()` in PHP for Drupal 7. Required behavior: Implements hook_library().
File: modules/contextual/contextual.module
function contextual_library() { $path = drupal_get_path('module', 'contextual'); $libraries['contextual-links'] = array( 'title' => 'Contextual links', 'website' => 'http://drupal.org/node/473268', 'version' => '1.0', 'js' => array( $path . '/contextual.js' => array(), ), 'css' => arra...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-26cd268fbe
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_vocabulary_get_names/7.x
I need the code for `taxonomy_vocabulary_get_names()` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Get names for all taxonomy vocabularies.
Returns: An associative array of objects keyed by vocabulary machine name with information about taxonomy vocabularies. Each object has properties: - name: The vocabulary name. - machine_name: The machine name. - vid: The vocabulary ID. File: modules/taxonomy/taxonomy.module
function taxonomy_vocabulary_get_names() { $names = &drupal_static(__FUNCTION__); if (!isset($names)) { $names = db_query('SELECT name, machine_name, vid FROM {taxonomy_vocabulary}')->fetchAllAssoc('machine_name'); } return $names; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-26dfaa4b68
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21engines%21phptemplate%21phptemplate.engine/function/phptemplate_theme/7.x
I need the code for `phptemplate_theme($existing, $type, $theme, $path)` in Drupal 7 (themes/engines/phptemplate/phptemplate.engine). It must do this: Implements hook_theme().
File: themes/engines/phptemplate/phptemplate.engine
function phptemplate_theme($existing, $type, $theme, $path) { $templates = drupal_find_theme_functions($existing, array($theme)); $templates += drupal_find_theme_templates($existing, '.tpl.php', $path); return $templates; }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-26f3d304bc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_field_entity_form_submit/7.x
I need the code for `locale_field_entity_form_submit($entity_type, $form, &$form_state )` in Drupal 7 (modules/locale/locale.module). It must do this: Handles field language on submit for the given entity type.
Checks if Locale is registered as a translation handler and handle possible language changes. File: modules/locale/locale.module
function locale_field_entity_form_submit($entity_type, $form, &$form_state ) { if (field_has_translation_handler($entity_type, 'locale')) { $entity = (object) $form_state['values']; $current_language = entity_language($entity_type, $entity); list(, , $bundle) = entity_extract_ids($entity_type, $entity); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-27057c8737
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_form_submit/7.x
I need the code for `comment_form_submit($form, &$form_state)` in Drupal 7 (modules/comment/comment.module). It must do this: Process comment form submissions; prepare the comment, store it, and set a redirection target.
File: modules/comment/comment.module
function comment_form_submit($form, &$form_state) { $node = node_load($form_state['values']['nid']); $comment = comment_form_submit_build_comment($form, $form_state); if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) { // Save the anonymous user i...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-271b23e46e
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_feed/7.x
In Drupal 7, write the function `drupal_add_feed($url = NULL, $title = '')` (file includes/common.inc) so that it does the following: Adds a feed URL for the current page.
This function can be called as long the HTML header hasn't been sent. Parameters: - $url: An internal system path or a fully qualified external URL of the feed. - $title: The title of the feed. File: includes/common.inc
function drupal_add_feed($url = NULL, $title = '') { $stored_feed_links = &drupal_static(__FUNCTION__, array()); if (isset($url)) { $stored_feed_links[$url] = theme('feed_icon', array('url' => $url, 'title' => $title)); drupal_add_html_head_link(array( 'rel' => 'alternate', 'type' => 'applicat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-27371c40f0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_block_view/7.x
In Drupal 7, write the function `node_block_view($delta = '')` (file modules/node/node.module) so that it does the following: Implements hook_block_view().
File: modules/node/node.module
function node_block_view($delta = '') { $block = array(); switch ($delta) { case 'syndicate': $block['subject'] = t('Syndicate'); $block['content'] = theme('feed_icon', array('url' => 'rss.xml', 'title' => t('Syndicate'))); break; case 'recent': if (user_access('access content')) {...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-275cebf966
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.admin.inc/function/user_admin_role_submit/7.x
Implement `user_admin_role_submit($form, &$form_state)` in PHP for Drupal 7. Required behavior: Form submit handler for the user_admin_role() form.
File: modules/user/user.admin.inc
function user_admin_role_submit($form, &$form_state) { $role = (object) $form_state['values']; if ($form_state['values']['op'] == t('Save role')) { user_role_save($role); drupal_set_message(t('The role has been renamed.')); } elseif ($form_state['values']['op'] == t('Add role')) { user_role_save($ro...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2772ec648f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/theme_color_scheme_form/7.x
Implement `theme_color_scheme_form($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for a theme's color form.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/color/color.module
function theme_color_scheme_form($variables) { $form = $variables['form']; $theme = $form['theme']['#value']; $info = $form['info']['#value']; $path = drupal_get_path('theme', $theme) . '/'; drupal_add_css($path . $info['preview_css']); $preview_js_path = isset($info['preview_js']) ? $path . $info['previe...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-277e1c9da4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/field_ui_field_settings_form_submit/7.x
In Drupal 7, write the function `field_ui_field_settings_form_submit($form, &$form_state)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Form submission handler for field_ui_field_settings_form().
File: modules/field_ui/field_ui.admin.inc
function field_ui_field_settings_form_submit($form, &$form_state) { $form_values = $form_state['values']; $field_values = $form_values['field']; // Merge incoming form values into the existing field. $field = field_info_field($field_values['field_name']); $entity_type = $form['#entity_type']; $bundle = $f...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-27814c7a38
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.admin.inc/function/book_admin_edit_submit/7.x
In Drupal 7, write the function `book_admin_edit_submit($form, &$form_state)` (file modules/book/book.admin.inc) so that it does the following: Form submission handler for book_admin_edit().
This function takes care to save parent menu items before their children. Saving menu items in the incorrect order can break the menu tree. File: modules/book/book.admin.inc
function book_admin_edit_submit($form, &$form_state) { // Save elements in the same order as defined in post rather than the form. // This ensures parents are updated before their children, preventing orphans. $order = array_flip(array_keys($form_state['input']['table'])); $form['table'] = array_merge($order, $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-278d34f7db
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.processor.inc/function/aggregator_form_aggregator_admin_form_alter/7.x
I need the code for `aggregator_form_aggregator_admin_form_alter(&$form, $form_state)` in Drupal 7 (modules/aggregator/aggregator.processor.inc). It must do this: Implements hook_form_aggregator_admin_form_alter().
Form alter aggregator module's own form to keep processor functionality separate from aggregator API functionality. File: modules/aggregator/aggregator.processor.inc
function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { if (in_array('aggregator', variable_get('aggregator_processors', array('aggregator')))) { $info = module_invoke('aggregator', 'aggregator_process_info'); $items = drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items'); ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-27934f9611
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.api.php/function/hook_locale/7.x
In Drupal 7, show an example implementation for `hook_locale($op = 'groups')` (modules/locale/locale.api.php): Allows modules to define their own text groups that can be translated.
Parameters: - $op: Type of operation. Currently, only supports 'groups'. File: modules/locale/locale.api.php
function hook_locale($op = 'groups') { switch ($op) { case 'groups': return array('custom' => t('Custom')); } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-27956094fe
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_process/7.x
Give me the example code for `hook_process(&$variables, $hook)` in Drupal 7. Hook description: Process theme variables for templates.
This hook allows modules to process theme variables for theme templates. It is called for all theme hooks implemented as templates, but not for theme hooks implemented as functions. hook_process_HOOK() can be used to process variables for a specific theme hook, whether implemented as a template or function. For more d...
function hook_process(&$variables, $hook) { // Wraps variables in RDF wrappers. if (!empty($variables['rdf_template_variable_attributes_array'])) { foreach ($variables['rdf_template_variable_attributes_array'] as $variable_name => $attributes) { $context = array( 'hook' => $hook, 'variable...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-27969512be
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_export_string/7.x
I need the code for `_locale_export_string($str)` in Drupal 7 (includes/locale.inc). It must do this: Print out a string on multiple lines
File: includes/locale.inc
function _locale_export_string($str) { $stri = addcslashes($str, "\0..\37\\\""); $parts = array(); // Cut text into several lines while ($stri != "") { $i = strpos($stri, "\\n"); if ($i === FALSE) { $curstr = $stri; $stri = ""; } else { $curstr = substr($stri, 0, $i + 2); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-27b901a342
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/element_children/7.x
In Drupal 7, write the function `element_children(&$elements, $sort = FALSE)` (file includes/common.inc) so that it does the following: Identifies the children of an element array, optionally sorted by weight.
The children of a element array are those key/value pairs whose key does not start with a '#'. See drupal_render() for details. Parameters: - $elements: The element array whose children are to be identified. - $sort: Boolean to indicate whether the children should be sorted by weight. Returns: The array keys of the e...
function element_children(&$elements, $sort = FALSE) { // Do not attempt to sort elements which have already been sorted. $sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort; // Filter out properties from the element, leaving only children. $count = count($elements); $child_weights = array();...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-27d63671ec
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/trigger_user_delete/7.x
In Drupal 7, write the function `trigger_user_delete($account)` (file modules/trigger/trigger.module) so that it does the following: Implements hook_user_delete().
File: modules/trigger/trigger.module
function trigger_user_delete($account) { $edit = array(); _trigger_user('user_delete', $edit, $account, NULL); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-27d8285c37
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_extract_bundle/7.x
Implement `field_extract_bundle($entity_type, $bundle)` in PHP for Drupal 7. Required behavior: Helper function to extract the bundle name of from a bundle object.
Parameters: - $entity_type: The type of $entity; e.g., 'node' or 'user'. - $bundle: The bundle object (or string if bundles for this entity type do not exist as standalone objects). Returns: The bundle name. File: modules/field/field.module
function field_extract_bundle($entity_type, $bundle) { if (is_string($bundle)) { return $bundle; } $info = entity_get_info($entity_type); if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) { return $bundle->{$info['bundle keys']['bundle'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-27eb36ccd7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_multiple_delete_confirm_submit/7.x
I need the code for `node_multiple_delete_confirm_submit($form, &$form_state)` in Drupal 7 (modules/node/node.admin.inc). It must do this: Form submission handler for node_multiple_delete_confirm().
File: modules/node/node.admin.inc
function node_multiple_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { node_delete_multiple(array_keys($form_state['values']['nodes'])); cache_clear_all(); $count = count($form_state['values']['nodes']); watchdog('content', 'Deleted @count posts.', array('@count' =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-27ff1de5fc
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_entity_query_alter/7.x
Implement `taxonomy_entity_query_alter($query)` in PHP for Drupal 7. Required behavior: Implements hook_entity_query_alter().
Converts EntityFieldQuery instances on taxonomy terms that have an entity condition on term bundles (vocabulary machine names). Since the vocabulary machine name is not present in the {taxonomy_term_data} table itself, we have to convert the bundle condition into a property condition of vocabulary IDs to match against ...
function taxonomy_entity_query_alter($query) { $conditions = &$query->entityConditions; // Alter only taxonomy term queries with bundle conditions. if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) { // Convert vocabulary machine ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-280861364b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.module/function/search_menu/7.x
I need the code for `search_menu()` in Drupal 7 (modules/search/search.module). It must do this: Implements hook_menu().
File: modules/search/search.module
function search_menu() { $items['search'] = array( 'title' => 'Search', 'page callback' => 'search_view', 'access callback' => 'search_is_active', 'type' => MENU_SUGGESTED_ITEM, 'file' => 'search.pages.inc', ); $items['admin/config/search/settings'] = array( 'title' => 'Search settings', ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-281f0f46f1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_new_page_count/7.x
Implement `comment_new_page_count($num_comments, $new_replies, $node)` in PHP for Drupal 7. Required behavior: Calculate page number for first new comment.
Parameters: - $num_comments: Number of comments. - $new_replies: Number of new replies. - $node: The first new comment node. Returns: "page=X" if the page number is greater than zero; empty string otherwise. File: modules/comment/comment.module
function comment_new_page_count($num_comments, $new_replies, $node) { $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED); $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50); $pagenum = NULL; $flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE; if ($n...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-28315ee4ce
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_system_theme_info/7.x
Give me the example code for `hook_system_theme_info()` in Drupal 7. Hook description: Return additional themes provided by modules.
Only use this hook for testing purposes. Use a hidden MYMODULE_test.module to implement this hook. Testing themes should be hidden, too. This hook is invoked from _system_rebuild_theme_data() and allows modules to register additional themes outside of the regular 'themes' directories of a Drupal installation. Returns...
function hook_system_theme_info() { $themes['mymodule_test_theme'] = drupal_get_path('module', 'mymodule') . '/mymodule_test_theme/mymodule_test_theme.info'; return $themes; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-283c1dcddf
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_formatter_info_alter/7.x
Give me the example code for `hook_field_formatter_info_alter(&$info)` in Drupal 7. Hook description: Perform alterations on Field API formatter types.
Parameters: - $info: An array of information on formatter types exposed by hook_field_formatter_info() implementations. File: modules/field/field.api.php
function hook_field_formatter_info_alter(&$info) { // Add a setting to a formatter type. $info['text_default']['settings'] += array( 'mymodule_additional_setting' => 'default value', ); // Let a new field type re-use an existing formatter. $info['text_default']['field types'][] = 'my_field_type'; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-284e04ca51
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7087/7.x
In Drupal 7, write the function `system_update_7087()` (file modules/system/system.install) so that it does the following: Enable the Announcements module; see 7.100 Release Notes for opt-out details.
File: modules/system/system.install
function system_update_7087() { if (!variable_get('announcements_feed_enable_by_default_opt_out', FALSE)) { module_enable(array('announcements_feed'), FALSE); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-284f1d0180
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21color%21color.module/function/color_get_info/7.x
I need the code for `color_get_info($theme)` in Drupal 7 (modules/color/color.module). It must do this: Retrieves the Color module information for a particular theme.
File: modules/color/color.module
function color_get_info($theme) { static $theme_info = array(); if (isset($theme_info[$theme])) { return $theme_info[$theme]; } $path = drupal_get_path('theme', $theme); $file = DRUPAL_ROOT . '/' . $path . '/color/color.inc'; if ($path && file_exists($file)) { include $file; $theme_info[$theme...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2856048576
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/field_sql_storage_help/7.x
I need the code for `field_sql_storage_help($path, $arg)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Implements hook_help().
File: modules/field/modules/field_sql_storage/field_sql_storage.module
function field_sql_storage_help($path, $arg) { switch ($path) { case 'admin/help#field_sql_storage': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Field SQL storage module stores field data in the database. It is the default field storage module; other field s...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-285b645922
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/show/7.x
In Drupal 7, write the function `show(&$element)` (file includes/common.inc) so that it does the following: Shows a hidden element for later rendering.
You can also use render($element), which shows the element while rendering it. The first time render() or drupal_render() is called on an element tree, as each element in the tree is rendered, it is marked with a #printed flag and the rendered children of the element are cached. Subsequent calls to render() or drupal_...
function show(&$element) { $element['#printed'] = FALSE; return $element; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-28850e730c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_sort_title/7.x
I need the code for `drupal_sort_title($a, $b)` in Drupal 7 (includes/common.inc). It must do this: Array sorting callback; sorts elements by 'title' key.
File: includes/common.inc
function drupal_sort_title($a, $b) { if (!isset($b['title'])) { return -1; } if (!isset($a['title'])) { return 1; } return strcasecmp($a['title'], $b['title']); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-288cdf72a5
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_entity_info_alter/7.x
In Drupal 7, write the function `locale_entity_info_alter(&$entity_info)` (file modules/locale/locale.module) so that it does the following: Implements hook_entity_info_alter().
File: modules/locale/locale.module
function locale_entity_info_alter(&$entity_info) { $entity_info['node']['translation']['locale'] = TRUE; if (isset($entity_info['comment'])) { $entity_info['comment']['translation']['locale'] = TRUE; } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-2897a4852b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7054/7.x
I need the code for `system_update_7054()` in Drupal 7 (modules/system/system.install). It must do this: Remove {cache_*}.headers columns.
File: modules/system/system.install
function system_update_7054() { // Update: update_fix_d7_requirements() installs this version for cache_path // already, so we don't include it in this particular update. It should be // included in later updates though. $cache_tables = array( 'cache' => 'Generic cache table for caching things not separated...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-28abb398eb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/valid_url/7.x
I need the code for `valid_url($url, $absolute = FALSE)` in Drupal 7 (includes/common.inc). It must do this: Verifies the syntax of the given URL.
This function should only be used on actual URLs. It should not be used for Drupal menu paths, which can contain arbitrary characters. Valid values per RFC 3986. Parameters: - $url: The URL to verify. - $absolute: Whether the URL is absolute (beginning with a scheme such as "http:"). Returns: TRUE if the URL is in a ...
function valid_url($url, $absolute = FALSE) { if ($absolute) { return (bool)preg_match(" /^ # Start at the beginning of the text (?:ftp|https?|feed):\/\/ # Look for ftp, http, https or feed schemes (?: ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-28ae856e17
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_update_nodes/7.x
I need the code for `node_type_update_nodes($old_type, $type)` in Drupal 7 (modules/node/node.module). It must do this: Updates all nodes of one type to be of another type.
Parameters: - $old_type: The current node type of the nodes. - $type: The new node type of the nodes. Returns: The number of nodes whose node type field was modified. File: modules/node/node.module
function node_type_update_nodes($old_type, $type) { return db_update('node') ->fields(array('type' => $type)) ->condition('type', $old_type) ->execute(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-28cd36e33d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_permission/7.x
I need the code for `book_permission()` in Drupal 7 (modules/book/book.module). It must do this: Implements hook_permission().
File: modules/book/book.module
function book_permission() { return array( 'administer book outlines' => array( 'title' => t('Administer book outlines'), ), 'create new books' => array( 'title' => t('Create new books'), ), 'add content to books' => array( 'title' => t('Add content and child pages to books'), ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-28d040cc91
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail_system/7.x
In Drupal 7, write the function `drupal_mail_system($module, $key)` (file includes/mail.inc) so that it does the following: Returns an object that implements the MailSystemInterface interface.
Allows for one or more custom mail backends to format and send mail messages composed using drupal_mail(). An implementation needs to implement the following methods: - format: Allows to preprocess, format, and postprocess a mail message before it is passed to the sending system. By default, all messages may conta...
function drupal_mail_system($module, $key) { $instances = &drupal_static(__FUNCTION__, array()); $id = $module . '_' . $key; $configuration = variable_get('mail_system', array('default-system' => 'DefaultMailSystem')); // Look for overrides for the default class, starting from the most specific // id, and ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2903e3936d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21contextual%21contextual.module/function/contextual_element_info/7.x
I need the code for `contextual_element_info()` in Drupal 7 (modules/contextual/contextual.module). It must do this: Implements hook_element_info().
File: modules/contextual/contextual.module
function contextual_element_info() { $types['contextual_links'] = array( '#pre_render' => array('contextual_pre_render_links'), '#theme' => 'links__contextual', '#links' => array(), '#prefix' => '<div class="contextual-links-wrapper">', '#suffix' => '</div>', '#attributes' => array( 'cla...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-290762c573
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/block_form_system_performance_settings_alter/7.x
I need the code for `block_form_system_performance_settings_alter(&$form, &$form_state)` in Drupal 7 (modules/block/block.module). It must do this: Implements hook_form_FORM_ID_alter().
File: modules/block/block.module
function block_form_system_performance_settings_alter(&$form, &$form_state) { $disabled = (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants'))); $form['caching']['block_cache'] = array( '#type' => 'checkbox', '#title' => t('Cache blocks'), '#default_value' =...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-290b8ddc0f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_assign_form/7.x
Implement `trigger_assign_form($form, $form_state, $module, $hook, $label)` in PHP for Drupal 7. Required behavior: Returns the form for assigning an action to a trigger.
Parameters: - $module: The name of the trigger group, e.g., 'node'. - $hook: The name of the trigger hook, e.g., 'node_insert'. - $label: A plain English description of what this trigger does. File: modules/trigger/trigger.admin.inc
function trigger_assign_form($form, $form_state, $module, $hook, $label) { $form['module'] = array( '#type' => 'hidden', '#value' => $module, ); $form['hook'] = array( '#type' => 'hidden', '#value' => $hook, ); // All of these forms use the same validate and submit functions. $form['#validat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-290d79d5d7
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/_filter_xss_attributes/7.x
I need the code for `_filter_xss_attributes($attr)` in Drupal 7 (includes/common.inc). It must do this: Processes a string of HTML attributes.
Returns: Cleaned up version of the HTML attributes. File: includes/common.inc
function _filter_xss_attributes($attr) { $attrarr = array(); $mode = 0; $attrname = ''; while (strlen($attr) != 0) { // Was the last operation successful? $working = 0; switch ($mode) { case 0: // Attribute name, href for instance. if (preg_match('/^([-a-zA-Z][-a-zA-Z0-9]*)/'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-292fae120d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_node_insert/7.x
Implement `book_node_insert($node)` in PHP for Drupal 7. Required behavior: Implements hook_node_insert().
File: modules/book/book.module
function book_node_insert($node) { if (!empty($node->book['bid'])) { if ($node->book['bid'] == 'new') { // New nodes that are their own book. $node->book['bid'] = $node->nid; } $node->book['nid'] = $node->nid; $node->book['menu_name'] = book_menu_name($node->book['bid']); _book_update_...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-295d7a351e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.module/function/_field_sql_storage_tablename/7.x
I need the code for `_field_sql_storage_tablename($field)` in Drupal 7 (modules/field/modules/field_sql_storage/field_sql_storage.module). It must do this: Generate a table name for a field data table.
Parameters: - $field: The field structure. Returns: A string containing the generated name for the database table File: modules/field/modules/field_sql_storage/field_sql_storage.module
function _field_sql_storage_tablename($field) { if ($field['deleted']) { return "field_deleted_data_{$field['id']}"; } else { return "field_data_{$field['field_name']}"; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-29685b1184
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.install/function/node_update_7000/7.x
In Drupal 7, write the function `node_update_7000()` (file modules/node/node.install) so that it does the following: Upgrade the node type table and fix node type 'module' attribute to avoid name-space conflicts.
File: modules/node/node.install
function node_update_7000() { // Rename the module column to base. db_change_field('node_type', 'module', 'base', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE)); db_add_field('node_type', 'module', array( 'description' => 'The module defining this node type.', 'type' => 'varchar', '...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-297f4f6b54
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21pager.inc/function/pager_load_array/7.x
In Drupal 7, write the function `pager_load_array($value, $element, $old_array)` (file includes/pager.inc) so that it does the following: Helper function
Copies $old_array to $new_array and sets $new_array[$element] = $value Fills in $new_array[0 .. $element - 1] = 0 File: includes/pager.inc
function pager_load_array($value, $element, $old_array) { $new_array = $old_array; // Look for empty elements. for ($i = 0; $i < $element; $i++) { if (empty($new_array[$i])) { // Load found empty element with 0. $new_array[$i] = 0; } } // Update the changed element. $new_array[$element] ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-29acf54c66
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21json-encode.inc/function/drupal_json_encode_helper/7.x
Implement `drupal_json_encode_helper($var)` in PHP for Drupal 7. Required behavior: Encodes a PHP variable to HTML-safe JSON for PHP versions below 5.3.0.
File: includes/json-encode.inc
function drupal_json_encode_helper($var) { switch (gettype($var)) { case 'boolean': return $var ? 'true' : 'false'; // Lowercase necessary! case 'integer': case 'double': return $var; case 'resource': case 'string': // Always use Unicode escape sequences (\u0022) over JSON esca...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-29b182f788
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/image_style_revert_form/7.x
I need the code for `image_style_revert_form($form, &$form_state, $style)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Confirmation form to revert a database style to its default.
File: modules/image/image.admin.inc
function image_style_revert_form($form, &$form_state, $style) { $form_state['image_style'] = $style; return confirm_form( $form, t('Revert the %style style?', array('%style' => $style['label'])), 'admin/config/media/image-styles', t('Reverting this style will delete the customized settings and rest...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-29fbd9b202
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21help%21help.admin.inc/function/help_links_as_list/7.x
In Drupal 7, write the function `help_links_as_list()` (file modules/help/help.admin.inc) so that it does the following: Provides a formatted list of available help topics.
Returns: A string containing the formatted list. File: modules/help/help.admin.inc
function help_links_as_list() { $empty_arg = drupal_help_arg(); $module_info = system_rebuild_module_data(); $modules = array(); foreach (module_implements('help', TRUE) as $module) { if (module_invoke($module, 'help', "admin/help#$module", $empty_arg)) { $modules[$module] = $module_info[$module]->in...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-29ff6f0712
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/_locale_batch_build/7.x
Implement `_locale_batch_build($files, $finished = NULL, $components = array())` in PHP for Drupal 7. Required behavior: Build a locale batch from an array of files.
Parameters: - $files: Array of files to import. - $finished: Optional finished callback for the batch. - $components: Optional list of component names the batch covers. Used in the installer. Returns: A batch structure. File: includes/locale.inc
function _locale_batch_build($files, $finished = NULL, $components = array()) { $t = get_t(); if (count($files)) { $operations = array(); foreach ($files as $file) { // We call _locale_batch_import for every batch operation. $operations[] = array('_locale_batch_import', array($file->uri)); }...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2a063c1f96
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7013/7.x
Implement `system_update_7013()` in PHP for Drupal 7. Required behavior: Convert default time zone offset to default time zone name.
File: modules/system/system.install
function system_update_7013() { $timezone = NULL; $timezones = system_time_zones(); // If the contributed Date module set a default time zone name, use this // setting as the default time zone. if (($timezone_name = variable_get('date_default_timezone_name')) && isset($timezones[$timezone_name])) { $timez...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2a1eb11fce
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_role_load/7.x
In Drupal 7, write the function `user_role_load($rid)` (file modules/user/user.module) so that it does the following: Fetches a user role by role ID.
Parameters: - $rid: An integer representing the role ID. Returns: A fully-loaded role object if a role with the given ID exists, or FALSE otherwise. File: modules/user/user.module
function user_role_load($rid) { return db_select('role', 'r') ->fields('r') ->condition('rid', $rid) ->execute() ->fetchObject(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2a2114d7a9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_uri/7.x
I need the code for `comment_uri($comment)` in Drupal 7 (modules/comment/comment.module). It must do this: Implements callback_entity_info_uri().
File: modules/comment/comment.module
function comment_uri($comment) { return array( 'path' => 'comment/' . $comment->cid, 'options' => array('fragment' => 'comment-' . $comment->cid), ); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2a26cf1371
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_style_path/7.x
I need the code for `image_style_path($style_name, $uri)` in Drupal 7 (modules/image/image.module). It must do this: Returns the URI of an image when using a style.
The path returned by this function may not exist. The default generation method only creates images when they are requested by a user's browser. Parameters: - $style_name: The name of the style to be used with this image. - $uri: The URI or path to the image. Returns: The URI to an image style image. File: modules/i...
function image_style_path($style_name, $uri) { $scheme = file_uri_scheme($uri); if ($scheme) { $path = file_uri_target($uri); } else { $path = $uri; $scheme = file_default_scheme(); } return $scheme . '://styles/' . $style_name . '/' . $scheme . '/' . $path; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2a6752a724
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.module/function/_trigger_comment/7.x
I need the code for `_trigger_comment($a1, $hook)` in Drupal 7 (modules/trigger/trigger.module). It must do this: Calls action functions for comment triggers.
Parameters: - $a1: Comment object or array of form values. - $hook: Hook to trigger. File: modules/trigger/trigger.module
function _trigger_comment($a1, $hook) { // Keep objects for reuse so that changes actions make to objects can persist. static $objects; $aids = trigger_get_assigned_actions($hook); $context = array( 'group' => 'comment', 'hook' => $hook, ); // We need to get the expected object if the action's type ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2a839b4825
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.api.php/function/hook_image_styles_alter/7.x
Give me the example code for `hook_image_styles_alter(&$styles)` in Drupal 7. Hook description: Modify any image styles provided by other modules or the user.
This hook allows modules to modify, add, or remove image styles. This may be useful to modify default styles provided by other modules or enforce that a specific effect is always enabled on a style. Note that modifications to these styles may negatively affect the user experience, such as if an effect is added to a sty...
function hook_image_styles_alter(&$styles) { // Check that we only affect a default style. if ($styles['thumbnail']['storage'] == IMAGE_STORAGE_DEFAULT) { // Add an additional effect to the thumbnail style. $styles['thumbnail']['effects'][] = array( 'name' => 'image_desaturate', 'data' => array(...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-2aa57580fe
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/template_preprocess_poll_bar/7.x
Implement `template_preprocess_poll_bar(&$variables)` in PHP for Drupal 7. Required behavior: Preprocess the poll_bar theme hook.
Inputs: $title, $votes, $total_votes, $voted, $block File: modules/poll/poll.module
function template_preprocess_poll_bar(&$variables) { if ($variables['block']) { $variables['theme_hook_suggestions'][] = 'poll_bar__block'; } $variables['title'] = check_plain($variables['title']); $variables['percentage'] = round($variables['votes'] * 100 / max($variables['total_votes'], 1)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-2aad595375
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21password.inc/function/_password_crypt/7.x
I need the code for `_password_crypt($algo, $password, $setting)` in Drupal 7 (includes/password.inc). It must do this: Hash a password using a secure stretched hash.
By using a salt and repeated hashing the password is "stretched". Its security is increased because it becomes much more computationally costly for an attacker to try to break the hash by brute-force computation of the hashes of a large number of plain-text words or strings to find a match. Parameters: - $algo: The st...
function _password_crypt($algo, $password, $setting) { // Prevent DoS attacks by refusing to hash large passwords. if (strlen($password) > 512) { return FALSE; } // The first 12 characters of an existing hash are its setting string. $setting = substr($setting, 0, 12); if ($setting[0] != '$' || $setting...
[ "code-task", "function" ]
2026-09-30T00:00:00