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-afb10e6122
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.admin.inc/function/shortcut_link_delete/7.x
Implement `shortcut_link_delete($form, &$form_state, $shortcut_link)` in PHP for Drupal 7. Required behavior: Form callback: builds the confirmation form for deleting a shortcut link.
Parameters: - $form: An associative array containing the structure of the form. - $form_state: An associative array containing the current state of the form. - $shortcut_link: An array representing the link that will be deleted. Returns: An array representing the form definition. File: modules/shortcut/shortcut.admin...
function shortcut_link_delete($form, &$form_state, $shortcut_link) { $form['shortcut_link'] = array( '#type' => 'value', '#value' => $shortcut_link, ); return confirm_form( $form, t('Are you sure you want to delete the shortcut %title?', array('%title' => $shortcut_link['link_title'])), 'admi...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-afb2f3058b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_get_info/7.x
Implement `system_get_info($type, $name = NULL)` in PHP for Drupal 7. Required behavior: Returns an array of information about enabled modules or themes.
This function returns the information from the {system} table corresponding to the cached contents of the .info file for each active module or theme. Parameters: - $type: Either 'module' or 'theme'. - $name: (optional) The name of a module or theme whose information shall be returned. If omitted, all records for the p...
function system_get_info($type, $name = NULL) { $info = array(); if ($type == 'module') { $type = 'module_enabled'; } $list = system_list($type); foreach ($list as $shortname => $item) { if (!empty($item->status)) { $info[$shortname] = $item->info; } } if (isset($name)) { return isse...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-afb6155bd6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7002/7.x
In Drupal 7, write the function `system_update_7002()` (file modules/system/system.install) so that it does the following: Add a table to store blocked IP addresses.
File: modules/system/system.install
function system_update_7002() { $schema['blocked_ips'] = array( 'description' => 'Stores blocked IP addresses.', 'fields' => array( 'iid' => array( 'description' => 'Primary Key: unique ID for IP addresses.', 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-afc19a82bb
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_get_http_header/7.x
I need the code for `drupal_get_http_header($name = NULL)` in Drupal 7 (includes/bootstrap.inc). It must do this: Gets the HTTP response headers for the current page.
Parameters: - $name: An HTTP header name. If omitted, all headers are returned as name/value pairs. If an array value is FALSE, the header has been unset. Returns: A string containing the header value, or FALSE if the header has been set, or NULL if the header has not been set. File: includes/bootstrap.inc
function drupal_get_http_header($name = NULL) { $headers = &drupal_static('drupal_http_headers', array()); if (isset($name)) { $name = strtolower($name); return isset($headers[$name]) ? $headers[$name] : NULL; } else { return $headers; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-afec5f793f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_view/7.x
Implement `blog_view($node, $view_mode)` in PHP for Drupal 7. Required behavior: Implements hook_view().
File: modules/blog/blog.module
function blog_view($node, $view_mode) { if ($view_mode == 'full' && node_is_page($node)) { // Breadcrumb navigation. l() escapes title, so we should not escape !name. drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t("!name's blog", array('!name' => format_username($node))), 'blog/' ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-aff9e1bf7c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/_field_sort_items/7.x
Implement `_field_sort_items($field, $items)` in PHP for Drupal 7. Required behavior: Helper function to sort items in a field according to user drag-n-drop reordering.
File: modules/field/field.module
function _field_sort_items($field, $items) { if (($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) && isset($items[0]['_weight'])) { usort($items, '_field_sort_items_helper'); foreach ($items as $delta => $item) { if (is_array($items[$delta])) { unset($items[$de...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b03296b0b2
7
drupal_api_code
https://api.drupal.org/api/drupal/profiles%21testing%21testing.install/function/testing_install/7.x
Implement `testing_install()` in PHP for Drupal 7. Required behavior: Implements hook_install().
Perform actions to set up the site for this profile. File: profiles/testing/testing.install
function testing_install() { // Allow visitor account creation, but with administrative approval. variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL); // Enable default permissions for system roles. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content')); user_rol...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b05db3e5ef
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21theme.api.php/function/hook_process_HOOK/7.x
Give me the example code for `hook_process_HOOK(&$variables)` in Drupal 7. Hook description: Process theme variables for a specific theme hook.
This hook allows modules to process theme variables for a specific theme hook. It should only be used if a module needs to override or add to the theme processing for a theme hook it didn't define. For more detailed information, see theme(). Parameters: - $variables: The variables array (modify in place). File: modu...
function hook_process_HOOK(&$variables) { // @todo There are no use-cases in Drupal core for this hook. Find one from a // contributed module, or come up with a good example. Coming up with a good // example might be tough, since the intent is for nearly everything to be // achievable via preprocess funct...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b065d4dc6b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_prepare_translation/7.x
In Drupal 7, show an example implementation for `hook_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode)` (modules/field/field.api.php): Define custom prepare_translation behavior for this module's field types.
Parameters: - $entity_type: The type of $entity. - $entity: The entity for the operation. - $field: The field structure for the operation. - $instance: The instance structure for $field on $entity's bundle. - $langcode: The language associated to $items. - $entity ($items): ->{$field['field_name']}[$langcode], or an em...
function hook_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode) { // If the translating user is not permitted to use the assigned text format, // we must not expose the source values. $field_name = $field['field_name']; $formats = filter_fo...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b066bcd6ff
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_delete/7.x
Implement `menu_link_delete($mlid, $path = NULL)` in PHP for Drupal 7. Required behavior: Delete one or several menu links.
Parameters: - $mlid: A valid menu link mlid or NULL. If NULL, $path is used. - $path: The path to the menu items to be deleted. $mlid must be NULL. File: includes/menu.inc
function menu_link_delete($mlid, $path = NULL) { if (isset($mlid)) { _menu_delete_item(db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc()); } else { $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path)); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b07085d885
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_fieldset/7.x
In Drupal 7, write the function `theme_fieldset($variables)` (file includes/form.inc) so that it does the following: Returns HTML for a fieldset form element and its children.
Parameters: - $variables: An associative array containing: - element: An associative array containing the properties of the element. Properties used: #attributes, #children, #collapsed, #collapsible, #description, #id, #title, #value. File: includes/form.inc
function theme_fieldset($variables) { $element = $variables['element']; element_set_attributes($element, array('id')); _form_set_class($element, array('form-wrapper')); $output = '<fieldset' . drupal_attributes($element['#attributes']) . '>'; if (!empty($element['#title'])) { // Always wrap fieldset lege...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b080e8a30e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_cron_queue_info/7.x
In Drupal 7, show an example implementation for `hook_cron_queue_info()` (modules/system/system.api.php): Declare queues holding items that need to be run periodically.
While there can be only one hook_cron() process running at the same time, there can be any number of processes defined here running. Because of this, long running tasks are much better suited for this API. Items queued in hook_cron() might be processed in the same cron run if there are not many items in the queue, othe...
function hook_cron_queue_info() { $queues['aggregator_feeds'] = array( 'worker callback' => 'aggregator_refresh', 'time' => 60, ); return $queues; }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b09e4e88ce
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_access/7.x
I need the code for `field_access($op, $field, $entity_type, $entity = NULL, $account = NULL)` in Drupal 7 (modules/field/field.module). It must do this: Determine whether the user has access to a given field.
This function does not determine whether access is granted to the entity itself, only the specific field. Callers are responsible for ensuring that entity access is also respected. For example, when checking field access for nodes, check node_access() before checking field_access(), and when checking field access for e...
function field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) { global $user; if (!isset($account)) { $account = $user; } foreach (module_implements('field_access') as $module) { $function = $module . '_field_access'; $access = $function($op, $field, $entity_type, $entity, $acc...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b0a457fe59
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21image.gd.inc/function/image_gd_create_tmp/7.x
In Drupal 7, write the function `image_gd_create_tmp(stdClass $image, $width, $height)` (file modules/system/image.gd.inc) so that it does the following: Create a truecolor image preserving transparency from a provided image.
Parameters: - $image: An image object. - $width: The new width of the new image, in pixels. - $height: The new height of the new image, in pixels. Returns: A GD image handle. File: modules/system/image.gd.inc
function image_gd_create_tmp(stdClass $image, $width, $height) { $res = imagecreatetruecolor($width, $height); if ($image->info['extension'] == 'gif') { // Find out if a transparent color is set, will return -1 if no // transparent color has been defined in the image. $transparent = imagecolortranspare...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b0a825a045
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21poll%21poll.module/function/poll_menu/7.x
I need the code for `poll_menu()` in Drupal 7 (modules/poll/poll.module). It must do this: Implements hook_menu().
File: modules/poll/poll.module
function poll_menu() { $items['poll'] = array( 'title' => 'Polls', 'page callback' => 'poll_page', 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, 'file' => 'poll.pages.inc', ); $items['node/%node/votes'] = array( 'title' => 'Votes', 'page callback' => 'p...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b0c2fb053f
7
drupal_api_code
https://api.drupal.org/api/drupal/profiles%21minimal%21minimal.install/function/minimal_install/7.x
I need the code for `minimal_install()` in Drupal 7 (profiles/minimal/minimal.install). It must do this: Implements hook_install().
Performs actions to set up the site for this profile. File: profiles/minimal/minimal.install
function minimal_install() { // Enable some standard blocks. $default_theme = variable_get('theme_default', 'bartik'); $values = array( array( 'module' => 'system', 'delta' => 'main', 'theme' => $default_theme, 'status' => 1, 'weight' => 0, 'region' => 'content', 'pag...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b0c3ae83c4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_external_load/7.x
Implement `user_external_load($authname)` in PHP for Drupal 7. Required behavior: Fetches a user object based on an external authentication source.
Parameters: - $authname (string): The external authentication username. Returns: A fully-loaded user object if the user is found or FALSE if not found. File: modules/user/user.module
function user_external_load($authname) { $uid = db_query("SELECT uid FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchField(); if ($uid) { return user_load($uid); } else { return FALSE; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b0c7c6bf98
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_delete_bundle/7.x
In Drupal 7, write the function `field_attach_delete_bundle($entity_type, $bundle)` (file modules/field/field.attach.inc) so that it does the following: Notify field.module the a bundle was deleted.
This deletes the data for the field instances as well as the field instances themselves. This function actually just marks the data and field instances and deleted, leaving the garbage collection for a separate process, because it is not always possible to delete this much data in a single page request (particularly si...
function field_attach_delete_bundle($entity_type, $bundle) { // First, delete the instances themselves. field_read_instances() must be // used here since field_info_instances() does not return instances for // disabled entity types or bundles. $instances = field_read_instances(array('entity_type' => $entity_typ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b0ce56fbd6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_form_required_marker/7.x
I need the code for `theme_form_required_marker($variables)` in Drupal 7 (includes/form.inc). It must do this: Returns HTML for a marker for required form elements.
Parameters: - $variables: An associative array containing: - element: An associative array containing the properties of the element. File: includes/form.inc
function theme_form_required_marker($variables) { // This is also used in the installer, pre-database setup. $t = get_t(); $attributes = array( 'class' => 'form-required', 'title' => $t('This field is required.'), ); return '<span' . drupal_attributes($attributes) . '>*</span>'; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b0cff085df
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/theme_system_modules_fieldset/7.x
I need the code for `theme_system_modules_fieldset($variables)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Returns HTML for the modules form.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/system/system.admin.inc
function theme_system_modules_fieldset($variables) { $form = $variables['form']; // Individual table headers. $rows = array(); // Iterate through all the modules, which are // children of this fieldset. foreach (element_children($form) as $key) { // Stick it into $module for easier accessing. $modu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b0ddeb47bd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21registry.inc/function/_registry_parse_file/7.x
Implement `_registry_parse_file($filename, $contents, $module = '', $weight = 0)` in PHP for Drupal 7. Required behavior: Parse a file and save its interface and class listings.
Parameters: - $filename: Name of the file we are going to parse. - $contents: Contents of the file we are going to parse as a string. - $module: (optional) Name of the module this file belongs to. - $weight: (optional) Weight of the module. File: includes/registry.inc
function _registry_parse_file($filename, $contents, $module = '', $weight = 0) { if (preg_match_all('/^\s*(?:abstract|final)?\s*(class|interface|trait)\s+([a-zA-Z0-9_]+)/m', $contents, $matches)) { foreach ($matches[2] as $key => $name) { db_merge('registry') ->key(array( 'name' => $name, ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b0ede103b4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.module/function/locale_language_types_info/7.x
I need the code for `locale_language_types_info()` in Drupal 7 (modules/locale/locale.module). It must do this: Implements hook_language_types_info().
Defines the three core language types: - Interface language is the only configurable language type in core. It is used by t() as the default language if none is specified. - Content language is by default non-configurable and inherits the interface language negotiated value. It is used by the Field API to determine...
function locale_language_types_info() { require_once DRUPAL_ROOT . '/includes/locale.inc'; return array( LANGUAGE_TYPE_INTERFACE => array( 'name' => t('User interface text'), 'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is a...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b0f9142ac8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/theme_user_list/7.x
I need the code for `theme_user_list($variables)` in Drupal 7 (modules/user/user.module). It must do this: Returns HTML for a list of users.
Parameters: - $variables: An associative array containing: - users: An array with user objects. Should contain at least the name and uid. - title: (optional) Title to pass on to theme_item_list(). File: modules/user/user.module
function theme_user_list($variables) { $users = $variables['users']; $title = $variables['title']; $items = array(); if (!empty($users)) { foreach ($users as $user) { $items[] = theme('username', array('account' => $user)); } } return theme('item_list', array('items' => $items, 'title' => $ti...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b106b7bfc1
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_storage_write/7.x
In Drupal 7, show an example implementation for `hook_field_storage_write($entity_type, $entity, $op, $fields)` (modules/field/field.api.php): Write field data for an entity.
This hook is invoked from field_attach_insert() and field_attach_update(), to ask the field storage module to save field data. Parameters: - $entity_type: The entity type of entity, such as 'node' or 'user'. - $entity: The entity on which to operate. - $op: FIELD_STORAGE_UPDATE when updating an existing entity, FIELD_...
function hook_field_storage_write($entity_type, $entity, $op, $fields) { list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); if (!isset($vid)) { $vid = $id; } foreach ($fields as $field_id) { $field = field_info_field_by_id($field_id); $field_name = $field['field_name']; $tabl...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b12a59a685
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.pages.inc/function/openid_authentication_page/7.x
I need the code for `openid_authentication_page()` in Drupal 7 (modules/openid/openid.pages.inc). It must do this: Menu callback; Process an OpenID authentication.
File: modules/openid/openid.pages.inc
function openid_authentication_page() { $result = openid_complete(); switch ($result['status']) { case 'success': return openid_authentication($result); case 'failed': drupal_set_message(t('OpenID login failed.'), 'error'); break; case 'cancel': drupal_set_message(t('OpenID login...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b130452d67
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.admin.inc/function/node_admin_nodes_validate/7.x
Implement `node_admin_nodes_validate($form, &$form_state)` in PHP for Drupal 7. Required behavior: Validate node_admin_nodes form submissions.
Checks whether any nodes have been selected to perform the chosen 'Update option' on. File: modules/node/node.admin.inc
function node_admin_nodes_validate($form, &$form_state) { // Error if there are no items to select. if (!is_array($form_state['values']['nodes']) || !count(array_filter($form_state['values']['nodes']))) { form_set_error('', t('No items selected.')); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b17f64092b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/_drupal_schema_initialize/7.x
In Drupal 7, write the function `_drupal_schema_initialize(&$schema, $module, $remove_descriptions = TRUE)` (file includes/common.inc) so that it does the following: Fills in required default values for table definitions from hook_schema().
Parameters: - $schema: The schema definition array as it was returned by the module's hook_schema(). - $module: The module for which hook_schema() was invoked. - $remove_descriptions: (optional) Whether to additionally remove 'description' keys of all tables and fields to improve performance of serialize() and unserial...
function _drupal_schema_initialize(&$schema, $module, $remove_descriptions = TRUE) { // Set the name and module key for all tables. foreach ($schema as $name => &$table) { if (empty($table['module'])) { $table['module'] = $module; } if (!isset($table['name'])) { $table['name'] = $name; }...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b180e04927
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_instance/7.x
I need the code for `field_info_instance($entity_type, $field_name, $bundle_name)` in Drupal 7 (modules/field/field.info.inc). It must do this: Returns an array of instance data for a specific field and bundle.
The function populates a static cache with all fields and instances used in the bundle, allowing fast retrieval of field_info_field() or field_info_instance() later in the request. Parameters: - $entity_type: The entity type for the instance. - $field_name: The field name for the instance. - $bundle_name: The bundle n...
function field_info_instance($entity_type, $field_name, $bundle_name) { $cache = _field_info_field_cache(); $info = $cache->getBundleInstances($entity_type, $bundle_name); if (isset($info[$field_name])) { return $info[$field_name]; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b1854372b4
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7004/7.x
I need the code for `system_update_7004(&$sandbox)` in Drupal 7 (modules/system/system.install). It must do this: Remove hardcoded numeric deltas from all blocks in core.
File: modules/system/system.install
function system_update_7004(&$sandbox) { // Get an array of the renamed block deltas, organized by module. $renamed_deltas = array( 'blog' => array('0' => 'recent'), 'book' => array('0' => 'navigation'), 'comment' => array('0' => 'recent'), 'forum' => array( '0' => 'active', '1' => 'new'...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b19216cf8c
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_stream_wrapper_uri_normalize/7.x
Implement `file_stream_wrapper_uri_normalize($uri)` in PHP for Drupal 7. Required behavior: Normalizes a URI by making it syntactically correct.
A stream is referenced as "scheme://target". The following actions are taken: - Remove trailing slashes from target - Trim erroneous leading slashes from target. e.g. ":///" becomes "://". Parameters: - $uri: String reference containing the URI to normalize. Returns: The normalized URI. File: includes/file.inc
function file_stream_wrapper_uri_normalize($uri) { // Inline file_uri_scheme() function call for performance reasons. $position = strpos($uri, '://'); $scheme = $position ? substr($uri, 0, $position) : FALSE; if ($scheme && file_stream_wrapper_valid_scheme($scheme)) { $target = file_uri_target($uri); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b1a7f30305
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21search%21search.api.php/function/callback_search_conditions/7.x
In Drupal 7, show an example implementation for `callback_search_conditions($keys)` (modules/search/search.api.php): Provide search query conditions.
Callback for hook_search_info(). This callback is invoked by search_view() to get an array of additional search conditions to pass to search_data(). For example, a search module may get additional keywords, filters, or modifiers for the search from the query string. This example pulls additional search keywords out o...
function callback_search_conditions($keys) { $conditions = array(); if (!empty($_REQUEST['keys'])) { $conditions['keys'] = $_REQUEST['keys']; } if (!empty($_REQUEST['sample_search_keys'])) { $conditions['sample_search_keys'] = $_REQUEST['sample_search_keys']; } if ($force_keys = config('sample_sear...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b1a8088c44
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_get_tree/7.x
In Drupal 7, write the function `taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE)` (file modules/taxonomy/taxonomy.module) so that it does the following: Create a hierarchical representation of a vocabulary.
Parameters: - $vid: Which vocabulary to generate the tree for. - $parent: The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary. - $max_depth: The number of levels of the tree to return. Leave NULL to return all levels. - $load_entities: If TRUE, a full entity load will occur o...
function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE) { $children = &drupal_static(__FUNCTION__, array()); $parents = &drupal_static(__FUNCTION__ . ':parents', array()); $terms = &drupal_static(__FUNCTION__ . ':terms', array()); // We cache trees, so it's not CPU-intensive to...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b1ed781598
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/book_block_save/7.x
In Drupal 7, write the function `book_block_save($delta = '', $edit = array())` (file modules/book/book.module) so that it does the following: Implements hook_block_save().
File: modules/book/book.module
function book_block_save($delta = '', $edit = array()) { $block = array(); variable_set('book_block_mode', $edit['book_block_mode']); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b214116ec0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21trigger%21trigger.admin.inc/function/trigger_unassign/7.x
I need the code for `trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL)` in Drupal 7 (modules/trigger/trigger.admin.inc). It must do this: Form constructor for confirmation page for removal of an assigned action.
Parameters: - $module: The tab of triggers the user will be directed to after successful removal of the action, or if the confirmation form is cancelled. - $hook: The name of the trigger hook, e.g., 'node_insert'. - $aid: The action ID. File: modules/trigger/trigger.admin.inc
function trigger_unassign($form, $form_state, $module, $hook = NULL, $aid = NULL) { if (!isset($hook, $aid)) { drupal_goto('admin/structure/trigger'); } $form['hook'] = array( '#type' => 'value', '#value' => $hook, ); $form['module'] = array( '#type' => 'value', '#value' => $module, ); ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b2236f417d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21mail.inc/function/drupal_mail/7.x
Implement `drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)` in PHP for Drupal 7. Required behavior: Composes and optionally sends an e-mail message.
Sending an e-mail works with defining an e-mail template (subject, text and possibly e-mail headers) and the replacement values to use in the appropriate places in the template. Processed e-mail templates are requested from hook_mail() from the module sending the e-mail. Any module can modify the composed e-mail messag...
function drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE) { $default_from = variable_get('site_mail', ini_get('sendmail_from')); // Bundle up the variables into a structured array for altering. $message = array( 'id' => $module . '_' . $key, 'module' => $m...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b224741078
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21locale.inc/function/locale_language_url_rewrite_session/7.x
Implement `locale_language_url_rewrite_session(&$path, &$options)` in PHP for Drupal 7. Required behavior: Rewrite URLs for the Session language provider.
File: includes/locale.inc
function locale_language_url_rewrite_session(&$path, &$options) { static $query_rewrite, $query_param, $query_value; // The following values are not supposed to change during a single page // request processing. if (!isset($query_rewrite)) { global $user; if (!$user->uid) { $languages = language_...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b2358acfa9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_menu/7.x
In Drupal 7, write the function `taxonomy_menu()` (file modules/taxonomy/taxonomy.module) so that it does the following: Implements hook_menu().
File: modules/taxonomy/taxonomy.module
function taxonomy_menu() { $items['admin/structure/taxonomy'] = array( 'title' => 'Taxonomy', 'description' => 'Manage tagging, categorization, and classification of your content.', 'page callback' => 'drupal_get_form', 'page arguments' => array('taxonomy_overview_vocabularies'), 'access arguments...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b23a552735
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_attach_purge/7.x
Give me the example code for `hook_field_attach_purge($entity_type, $entity, $field, $instance)` in Drupal 7. Hook description: Act on field_purge_data().
This hook is invoked in field_purge_data() and allows modules to act on purging data from a single field pseudo-entity. For example, if a module relates data in the field with its own data, it may purge its own data during this process as well. Parameters: - $entity_type: The type of $entity; for example, 'node' or 'u...
function hook_field_attach_purge($entity_type, $entity, $field, $instance) { // find the corresponding data in mymodule and purge it if ($entity_type == 'node' && $field->field_name == 'my_field_name') { mymodule_remove_mydata($entity->nid); } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b24437beb3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.field.inc/function/image_field_widget_settings_form/7.x
Implement `image_field_widget_settings_form($field, $instance)` in PHP for Drupal 7. Required behavior: Implements hook_field_widget_settings_form().
File: modules/image/image.field.inc
function image_field_widget_settings_form($field, $instance) { $widget = $instance['widget']; $settings = $widget['settings']; // Use the file widget settings form. $form = file_field_widget_settings_form($field, $instance); $form['preview_image_style'] = array( '#title' => t('Preview image style'), ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b25128be8d
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/file_htaccess_lines/7.x
In Drupal 7, write the function `file_htaccess_lines($private = TRUE)` (file includes/file.inc) so that it does the following: Returns the standard .htaccess lines that Drupal writes to file directories.
Parameters: - $private: (Optional) Set to FALSE to return the .htaccess lines for an open and public directory. The default is TRUE, which returns the .htaccess lines for a private and protected directory. Returns: A string representing the desired contents of the .htaccess file. File: includes/file.inc
function file_htaccess_lines($private = TRUE) { $lines = <<<EOF # Turn off all options we don't need. Options None Options +FollowSymLinks # Set the catch-all handler to prevent scripts from being executed. SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006 <Files *> # Override the handler again if we're run...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b264cf6769
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_json_encode/7.x
I need the code for `drupal_json_encode($var)` in Drupal 7 (includes/common.inc). It must do this: Converts a PHP variable into its JavaScript equivalent.
We use HTML-safe strings, with several characters escaped. File: includes/common.inc
function drupal_json_encode($var) { // The PHP version cannot change within a request. static $php530; if (!isset($php530)) { $php530 = version_compare(PHP_VERSION, '5.3.0', '>='); } if ($php530) { // Encode <, >, ', &, and " using the json_encode() options parameter. return json_encode($var, JS...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b269bb1e9c
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_unpublish_action/7.x
Implement `node_unpublish_action($node, $context = array())` in PHP for Drupal 7. Required behavior: Sets the status of a node to 0 (unpublished).
Parameters: - $node: A node object. - $context: (optional) Array of additional information about what triggered the action. Not used for this action. File: modules/node/node.module
function node_unpublish_action($node, $context = array()) { $node->status = NODE_NOT_PUBLISHED; watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->title)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b26db95cff
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_schema/7.x
Give me the example code for `hook_field_schema($field)` in Drupal 7. Hook description: Define the Field API schema for a field structure.
This is invoked when a field is created, in order to obtain the database schema from the module that defines the field's type. This hook must be defined in the module's .install file for it to be detected during installation and upgrade. Parameters: - $field: A field structure. Returns: An associative array with the...
function hook_field_schema($field) { if ($field['type'] == 'text_long') { $columns = array( 'value' => array( 'type' => 'text', 'size' => 'big', 'not null' => FALSE, ), ); } else { $columns = array( 'value' => array( 'type' => 'varchar', 'lengt...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b26fb6bd9f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.admin.inc/function/menu_overview_form_submit/7.x
In Drupal 7, write the function `menu_overview_form_submit($form, &$form_state)` (file modules/menu/menu.admin.inc) so that it does the following: Submit handler for the menu overview form.
This function takes great care in saving parent items first, then items underneath them. Saving items in the incorrect order can break the menu tree. File: modules/menu/menu.admin.inc
function menu_overview_form_submit($form, &$form_state) { // When dealing with saving menu items, the order in which these items are // saved is critical. If a changed child item is saved before its parent, // the child item could be saved with an invalid path past its immediate // parent. To prevent this, save...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b272b7c45e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_field_extra_fields/7.x
I need the code for `comment_field_extra_fields()` in Drupal 7 (modules/comment/comment.module). It must do this: Implements hook_field_extra_fields().
File: modules/comment/comment.module
function comment_field_extra_fields() { $return = array(); foreach (node_type_get_types() as $type) { if (variable_get('comment_subject_field_' . $type->type, 1) == 1) { $return['comment']['comment_node_' . $type->type] = array( 'form' => array( 'author' => array( 'label' =>...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b29f653566
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21graph.inc/function/drupal_depth_first_search/7.x
In Drupal 7, write the function `drupal_depth_first_search(&$graph)` (file includes/graph.inc) so that it does the following: Performs a depth-first search and sort on a directed acyclic graph.
Parameters: - $graph: A three dimensional associated array, with the first keys being the names of the vertices, these can be strings or numbers. The second key is 'edges' and the third one are again vertices, each such key representing an edge. Values of array elements are copied over. Example: @code $graph[1]['edges'...
function drupal_depth_first_search(&$graph) { $state = array( // The order of last visit of the depth first search. This is the reverse // of the topological order if the graph is acyclic. 'last_visit_order' => array(), // The components of the graph. 'components' => array(), ); // Perform the...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b2bb6570c0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.install/function/system_update_7018/7.x
I need the code for `system_update_7018()` in Drupal 7 (modules/system/system.install). It must do this: Shorten the {system}.type column and modify indexes.
File: modules/system/system.install
function system_update_7018() { db_drop_index('system', 'modules'); db_drop_index('system', 'type_name'); db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '')); db_add_index('system', 'type_name', array('type', 'name')); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b2ce285f06
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.admin.inc/function/aggregator_form_opml/7.x
I need the code for `aggregator_form_opml($form, &$form_state)` in Drupal 7 (modules/aggregator/aggregator.admin.inc). It must do this: Form constructor for importing feeds from OPML.
File: modules/aggregator/aggregator.admin.inc
function aggregator_form_opml($form, &$form_state) { $period = drupal_map_assoc(array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); $form['upload'] = array( '#type' => 'file', '#title' => t('OPML File'), '#description' =>...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b2d5a806be
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.install/function/_image_update_7002_add_columns/7.x
Implement `_image_update_7002_add_columns($table, $field_name)` in PHP for Drupal 7. Required behavior: Add width and height columns to a specific table.
Parameters: - $table: The name of the database table to be updated. - $columns: Keyed array of columns this table is supposed to have. File: modules/image/image.install
function _image_update_7002_add_columns($table, $field_name) { $spec = array( 'type' => 'int', 'unsigned' => TRUE, ); $spec['description'] = 'The width of the image in pixels.'; db_add_field($table, $field_name . '_width', $spec); $spec['description'] = 'The height of the image in pixels.'; db_add...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b302b6b67f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_validate_picture/7.x
Implement `user_validate_picture(&$form, &$form_state)` in PHP for Drupal 7. Required behavior: Validates an image uploaded by a user.
File: modules/user/user.module
function user_validate_picture(&$form, &$form_state) { // If required, validate the uploaded picture. $validators = array( 'file_validate_is_image' => array(), 'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')), 'file_validate_size' => array((int) variable_get('u...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b34181e3c2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21simpletest%21simpletest.module/function/simpletest_clean_environment/7.x
In Drupal 7, write the function `simpletest_clean_environment()` (file modules/simpletest/simpletest.module) so that it does the following: Remove all temporary database tables and directories.
File: modules/simpletest/simpletest.module
function simpletest_clean_environment() { simpletest_clean_database(); simpletest_clean_temporary_directories(); if (variable_get('simpletest_clear_results', TRUE)) { $count = simpletest_clean_results_table(); drupal_set_message(format_plural($count, 'Removed 1 test result.', 'Removed @count test results....
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b34bd5c503
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_cron_cleanup/7.x
Implement `drupal_cron_cleanup()` in PHP for Drupal 7. Required behavior: DEPRECATED: Shutdown function: Performs cron cleanup.
This function is deprecated because the 'cron_semaphore' variable it references no longer exists. It is therefore no longer used as a shutdown function by Drupal core. File: includes/common.inc
function drupal_cron_cleanup() { // See if the semaphore is still locked. if (variable_get('cron_semaphore', FALSE)) { watchdog('cron', 'Cron run exceeded the time limit and was aborted.', array(), WATCHDOG_WARNING); // Release cron semaphore. variable_del('cron_semaphore'); } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b3621dba1b
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/registry_rebuild/7.x
Implement `registry_rebuild()` in PHP for Drupal 7. Required behavior: Rescans all enabled modules and rebuilds the registry.
Rescans all code in modules or includes directories, storing the location of each interface or class in the database. File: includes/bootstrap.inc
function registry_rebuild() { system_rebuild_module_data(); registry_update(); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b365b55a0e
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_theme_settings_submit/7.x
In Drupal 7, write the function `system_theme_settings_submit($form, &$form_state)` (file modules/system/system.admin.inc) so that it does the following: Process system_theme_settings form submissions.
File: modules/system/system.admin.inc
function system_theme_settings_submit($form, &$form_state) { // Exclude unnecessary elements before saving. form_state_values_clean($form_state); $values = $form_state['values']; // Extract the name of the theme from the submitted form values, then remove // it from the array so that it is not saved as part...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b37c122d7a
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_js_defaults/7.x
Implement `drupal_js_defaults($data = NULL)` in PHP for Drupal 7. Required behavior: Constructs an array of the defaults that are used for JavaScript items.
Parameters: - $data: (optional) The default data parameter for the JavaScript item array. File: includes/common.inc
function drupal_js_defaults($data = NULL) { return array( 'type' => 'file', 'group' => JS_DEFAULT, 'every_page' => FALSE, 'weight' => 0, 'requires_jquery' => TRUE, 'scope' => 'header', 'cache' => TRUE, 'defer' => FALSE, 'preprocess' => TRUE, 'version' => NULL, 'data' => $da...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b3a522f650
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21block%21block.module/function/_block_get_renderable_array/7.x
I need the code for `_block_get_renderable_array($list = array())` in Drupal 7 (modules/block/block.module). It must do this: Gets an array of blocks suitable for drupal_render().
Parameters: - $list: A list of blocks such as that returned by block_list(). Returns: A renderable array. File: modules/block/block.module
function _block_get_renderable_array($list = array()) { $weight = 0; $build = array(); foreach ($list as $key => $block) { $build[$key] = $block->content; unset($block->content); // Add contextual links for this block; skip the main content block, since // contextual links are basically output as...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b3ac09d668
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/filter_theme/7.x
In Drupal 7, write the function `filter_theme()` (file modules/filter/filter.module) so that it does the following: Implements hook_theme().
File: modules/filter/filter.module
function filter_theme() { return array( 'filter_admin_overview' => array( 'render element' => 'form', 'file' => 'filter.admin.inc', ), 'filter_admin_format_filter_order' => array( 'render element' => 'element', 'file' => 'filter.admin.inc', ), 'filter_tips' => array( ...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b3d8f878e2
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.info.inc/function/field_info_storage_types/7.x
In Drupal 7, write the function `field_info_storage_types($storage_type = NULL)` (file modules/field/field.info.inc) so that it does the following: Returns information about field storage from hook_field_storage_info().
Parameters: - $storage_type: (optional) A storage type name. If omitted, all storage types will be returned. Returns: Either a storage type description, as provided by hook_field_storage_info(), or an array of all existing storage types, keyed by storage type name. File: modules/field/field.info.inc
function field_info_storage_types($storage_type = NULL) { $info = _field_info_collate_types(); $storage_types = $info['storage types']; if ($storage_type) { if (isset($storage_types[$storage_type])) { return $storage_types[$storage_type]; } } else { return $storage_types; } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b3e3258b13
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field_ui%21field_ui.admin.inc/function/_field_ui_field_name_exists/7.x
In Drupal 7, write the function `_field_ui_field_name_exists($value)` (file modules/field_ui/field_ui.admin.inc) so that it does the following: Render API callback: Checks if a field machine name is taken.
Parameters: - $value: The machine name, not prefixed with 'field_'. Returns: Whether or not the field machine name is taken. File: modules/field_ui/field_ui.admin.inc
function _field_ui_field_name_exists($value) { // Prefix with 'field_'. $field_name = 'field_' . $value; // We need to check inactive fields as well, so we can't use // field_info_fields(). return (bool) field_read_fields(array('field_name' => $field_name), array('include_inactive' => TRUE)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b3f307faf0
7
drupal_api_code
https://api.drupal.org/api/drupal/themes%21seven%21template.php/function/seven_admin_block_content/7.x
I need the code for `seven_admin_block_content($variables)` in Drupal 7 (themes/seven/template.php). It must do this: Overrides theme_admin_block_content().
Use unordered list markup in both compact and extended mode. File: themes/seven/template.php
function seven_admin_block_content($variables) { $content = $variables['content']; $output = ''; if (!empty($content)) { $output = system_admin_compact_mode() ? '<ul class="admin-list compact">' : '<ul class="admin-list">'; foreach ($content as $item) { $output .= '<li class="leaf">'; $output ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b3f93c6767
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_permission/7.x
Implement `overlay_permission()` in PHP for Drupal 7. Required behavior: Implements hook_permission().
File: modules/overlay/overlay.module
function overlay_permission() { return array( 'access overlay' => array( 'title' => t('Access the administrative overlay'), 'description' => t('View administrative pages in the overlay.'), ), ); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b40fbd5de6
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/_theme_registry_callback/7.x
In Drupal 7, write the function `_theme_registry_callback($callback = NULL, array $arguments = array())` (file includes/theme.inc) so that it does the following: Sets the callback that will be used by theme_get_registry().
Parameters: - $callback: The name of the callback function. - $arguments: The arguments to pass to the function. File: includes/theme.inc
function _theme_registry_callback($callback = NULL, array $arguments = array()) { static $stored; if (isset($callback)) { $stored = array($callback, $arguments); } return $stored; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b42f1616b9
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_get_registry/7.x
In Drupal 7, write the function `theme_get_registry($complete = TRUE)` (file includes/theme.inc) so that it does the following: Gets the theme registry.
Parameters: - $complete: Optional boolean to indicate whether to return the complete theme registry array or an instance of the ThemeRegistry class. If TRUE, the complete theme registry array will be returned. This is useful if you want to foreach over the whole registry, use array_* functions or inspect it in a debugg...
function theme_get_registry($complete = TRUE) { // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; if (!isset($drupal_static_fast)) { $drupal_static_fast['registry'] = &drupal_static('theme_get_registry'); } $theme_registry = &$drupal_static_fast['reg...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b4c563bd2b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21shortcut%21shortcut.install/function/shortcut_schema/7.x
Implement `shortcut_schema()` in PHP for Drupal 7. Required behavior: Implements hook_schema().
File: modules/shortcut/shortcut.install
function shortcut_schema() { $schema['shortcut_set'] = array( 'description' => 'Stores information about sets of shortcuts links.', 'fields' => array( 'set_name' => array( 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '', 'description' => "...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b4cd7ba0ea
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_ip_blocking_delete_submit/7.x
I need the code for `system_ip_blocking_delete_submit($form, &$form_state)` in Drupal 7 (modules/system/system.admin.inc). It must do this: Process system_ip_blocking_delete form submissions.
File: modules/system/system.admin.inc
function system_ip_blocking_delete_submit($form, &$form_state) { $blocked_ip = $form_state['values']['blocked_ip']; db_delete('blocked_ips') ->condition('iid', $blocked_ip['iid']) ->execute(); watchdog('user', 'Deleted %ip', array('%ip' => $blocked_ip['ip'])); drupal_set_message(t('The IP address %ip wa...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b4d1bd7b2a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21filter%21filter.module/function/check_markup/7.x
I need the code for `check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)` in Drupal 7 (modules/filter/filter.module). It must do this: Runs all the enabled filters on a piece of text.
Note: Because filters can inject JavaScript or execute PHP code, security is vital here. When a user supplies a text format, you should validate it using filter_access() before accepting/using it. This is normally done in the validation stage of the Form API. You should for example never make a preview of content in a ...
function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE) { if (!isset($format_id)) { $format_id = filter_fallback_format(); } // If the requested text format does not exist, the text cannot be filtered. if (!$format = filter_format_load($format_id)) { watchdog('filter', 'Missing t...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b4db61a4d9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/_update_cache_set/7.x
Implement `_update_cache_set($cid, $data, $expire)` in PHP for Drupal 7. Required behavior: Stores data in the private update status cache table.
Parameters: - $cid: The cache ID to save the data with. - $data: The data to store. - $expire: One of the following values: - CACHE_PERMANENT: Indicates that the item should never be removed except by explicitly using _update_cache_clear(). - A Unix timestamp: Indicates that the item should be kept at least until the g...
function _update_cache_set($cid, $data, $expire) { $fields = array( 'created' => REQUEST_TIME, 'expire' => $expire, ); if (!is_string($data)) { $fields['data'] = serialize($data); $fields['serialized'] = 1; } else { $fields['data'] = $data; $fields['serialized'] = 0; } db_merge('ca...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b4dcfcc0db
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21file%21file.module/function/file_theme/7.x
I need the code for `file_theme()` in Drupal 7 (modules/file/file.module). It must do this: Implements hook_theme().
File: modules/file/file.module
function file_theme() { return array( // file.module. 'file_link' => array( 'variables' => array('file' => NULL, 'icon_directory' => NULL), ), 'file_icon' => array( 'variables' => array('file' => NULL, 'icon_directory' => NULL, 'alt' => ''), ), 'file_managed_file' => array( '...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b4eec14f43
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21aggregator%21aggregator.pages.inc/function/aggregator_feed_items_load/7.x
I need the code for `aggregator_feed_items_load($type, $data = NULL)` in Drupal 7 (modules/aggregator/aggregator.pages.inc). It must do this: Loads and optionally filters feed items.
Parameters: - $type: The type of filter for the items. Possible values are: - sum: No filtering. - source: Filter the feed items, limiting the result to items from a single source. - category: Filter the feed items by category. - $data: Feed or category data used for filtering. The type and value of $data depends on $t...
function aggregator_feed_items_load($type, $data = NULL) { $items = array(); switch ($type) { case 'sum': $query = db_select('aggregator_item', 'i'); $query->join('aggregator_feed', 'f', 'i.fid = f.fid'); $query->fields('i'); $query->addField('f', 'title', 'ftitle'); $query->addFie...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b4f869db80
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21book%21book.module/function/_book_add_form_elements/7.x
Implement `_book_add_form_elements(&$form, &$form_state, $node)` in PHP for Drupal 7. Required behavior: Builds the common elements of the book form for the node and outline forms.
Parameters: - $node: The node whose form is being viewed. File: modules/book/book.module
function _book_add_form_elements(&$form, &$form_state, $node) { // If the form is being processed during the Ajax callback of our book bid // dropdown, then $form_state will hold the value that was selected. if (isset($form_state['values']['book'])) { $node->book = $form_state['values']['book']; } $form[...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b4f8f29545
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.module/function/image_effect_save/7.x
Implement `image_effect_save($effect)` in PHP for Drupal 7. Required behavior: Saves an image effect.
Parameters: - $effect: An image effect array. Returns: An image effect array. In the case of a new effect, 'ieid' will be set. File: modules/image/image.module
function image_effect_save($effect) { if (!empty($effect['ieid'])) { drupal_write_record('image_effects', $effect, 'ieid'); } else { drupal_write_record('image_effects', $effect); } $style = image_style_load(NULL, $effect['isid']); image_style_flush($style); return $effect; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b51a9e9080
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.admin.inc/function/theme_image_style_effects/7.x
I need the code for `theme_image_style_effects($variables)` in Drupal 7 (modules/image/image.admin.inc). It must do this: Returns HTML for a listing of the effects within a specific image style.
Parameters: - $variables: An associative array containing: - form: A render element representing the form. File: modules/image/image.admin.inc
function theme_image_style_effects($variables) { $form = $variables['form']; $rows = array(); foreach (element_children($form) as $key) { $row = array(); $form[$key]['weight']['#attributes']['class'] = array('image-effect-order-weight'); if (is_numeric($key)) { $summary = drupal_render($form[$...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b51e6f214b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21update%21update.module/function/theme_update_last_check/7.x
Implement `theme_update_last_check($variables)` in PHP for Drupal 7. Required behavior: Returns HTML for the last time we checked for update data.
In addition to properly formatting the given timestamp, this function also provides a "Check manually" link that refreshes the available update and redirects back to the same page. Parameters: - $variables: An associative array containing: - last: The timestamp when the site last checked for available updates. File: ...
function theme_update_last_check($variables) { $last = $variables['last']; $output = '<div class="update checked">'; $output .= $last ? t('Last checked: @time ago', array('@time' => format_interval(REQUEST_TIME - $last))) : t('Last checked: never'); $output .= ' <span class="check-manually">(' . l(t('Check manu...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b5270ae802
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy_options_list/7.x
I need the code for `taxonomy_options_list($field, $instance, $entity_type, $entity)` in Drupal 7 (modules/taxonomy/taxonomy.module). It must do this: Implements hook_options_list().
File: modules/taxonomy/taxonomy.module
function taxonomy_options_list($field, $instance, $entity_type, $entity) { $function = !empty($field['settings']['options_list_callback']) ? $field['settings']['options_list_callback'] : 'taxonomy_allowed_values'; return $function($field); }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b5426cc57f
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_info/7.x
Give me the example code for `hook_node_info()` in Drupal 7. Hook description: Define module-provided node types.
This hook allows a module to define one or more of its own node types. For example, the blog module uses it to define a blog node-type named "Blog entry." The name and attributes of each desired node type are specified in an array returned by the hook. Only module-provided node types should be defined through this hoo...
function hook_node_info() { return array( 'blog' => array( 'name' => t('Blog entry'), 'base' => 'blog', 'description' => t('Use for multi-user blogs. Every user gets a personal blog.'), ) ); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b5628aa797
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21menu%21menu.module/function/menu_parent_options/7.x
Implement `menu_parent_options($menus, $item, $type = '')` in PHP for Drupal 7. Required behavior: Return a list of menu items that are valid possible parents for the given menu item.
Parameters: - $menus: An array of menu names and titles, such as from menu_get_menus(). - $item: The menu item or the node type for which to generate a list of parents. If $item['mlid'] == 0 then the complete tree is returned. - $type: The node type for which to generate a list of parents. If $item itself is a node typ...
function menu_parent_options($menus, $item, $type = '') { // The menu_links table can be practically any size and we need a way to // allow contrib modules to provide more scalable pattern choosers. // hook_form_alter is too late in itself because all the possible parents are // retrieved here, unless menu_over...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b5652e54e8
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_form_taxonomy_form_vocabulary_alter/7.x
Implement `forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state, $form_id)` in PHP for Drupal 7. Required behavior: Implements hook_form_FORM_ID_alter() for taxonomy_form_vocabulary().
File: modules/forum/forum.module
function forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state, $form_id) { $vid = variable_get('forum_nav_vocabulary', 0); if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) { $form['help_forum_vocab'] = array( '#markup' => t('This is the designated forum vocabulary. Some of th...
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b56c2747fc
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_uninstall_schema/7.x
I need the code for `drupal_uninstall_schema($module)` in Drupal 7 (includes/common.inc). It must do this: Removes all tables defined in a module's hook_schema().
Note: This function does not pass the module's schema through hook_schema_alter(). The module's tables will be created exactly as the module defines them. Parameters: - $module: The module for which the tables will be removed. Returns: An array of arrays with the following key/value pairs: - success: a boolean indica...
function drupal_uninstall_schema($module) { $schema = drupal_get_schema_unprocessed($module); _drupal_schema_initialize($schema, $module, FALSE); foreach ($schema as $table) { if (db_table_exists($table['name'])) { db_drop_table($table['name']); } } }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b57fd97c8a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.pages.inc/function/openid_user_delete_form/7.x
Implement `openid_user_delete_form($form, $form_state, $account, $aid = 0)` in PHP for Drupal 7. Required behavior: Menu callback; Delete the specified OpenID identity from the system.
File: modules/openid/openid.pages.inc
function openid_user_delete_form($form, $form_state, $account, $aid = 0) { $authname = db_query("SELECT authname FROM {authmap} WHERE uid = :uid AND aid = :aid AND module = 'openid'", array( ':uid' => $account->uid, ':aid' => $aid, )) ->fetchField(); return confirm_form(array(), t('Are you sure you want...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b586045e6a
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21forum%21forum.module/function/forum_node_insert/7.x
In Drupal 7, write the function `forum_node_insert($node)` (file modules/forum/forum.module) so that it does the following: Implements hook_node_insert().
File: modules/forum/forum.module
function forum_node_insert($node) { if (_forum_node_check_node_type($node)) { if (!empty($node->forum_tid)) { $nid = db_insert('forum') ->fields(array( 'tid' => $node->forum_tid, 'vid' => $node->vid, 'nid' => $node->nid, )) ->execute(); } } }
[ "code-task", "hook-implementation" ]
2026-09-30T00:00:00
api-drupal7-b588f0efb7
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_formatter_info/7.x
In Drupal 7, show an example implementation for `hook_field_formatter_info()` (modules/field/field.api.php): Expose Field API formatter types.
Formatters handle the display of field values. Formatter hooks are typically called by the Field Attach API field_attach_prepare_view() and field_attach_view() functions. Returns: An array describing the formatter types implemented by the module. The keys are formatter type names. To avoid name clashes, formatter type...
function hook_field_formatter_info() { return array( 'text_default' => array( 'label' => t('Default'), 'field types' => array('text', 'text_long', 'text_with_summary'), ), 'text_plain' => array( 'label' => t('Plain text'), 'field types' => array('text', 'text_long', 'text_with_summ...
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b5a8494e46
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21field%21modules%21field_sql_storage%21field_sql_storage.install/function/_update_7000_field_sql_storage_write/7.x
Implement `_update_7000_field_sql_storage_write($entity_type, $bundle, $entity_id, $revision_id, $field_name, $data)` in PHP for Drupal 7. Required behavior: Utility function: write field data directly to SQL storage.
This function can be used for databases whose schema is at field module version 7000 or higher. File: modules/field/modules/field_sql_storage/field_sql_storage.install
function _update_7000_field_sql_storage_write($entity_type, $bundle, $entity_id, $revision_id, $field_name, $data) { $table_name = "field_data_{$field_name}"; $revision_name = "field_revision_{$field_name}"; db_delete($table_name) ->condition('entity_type', $entity_type) ->condition('entity_id', $entity_...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b5b9388c6d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21dblog%21dblog.admin.inc/function/dblog_build_filter_query/7.x
Implement `dblog_build_filter_query()` in PHP for Drupal 7. Required behavior: Builds a query for database log administration filters based on session.
Returns (array): An associative array with keys 'where' and 'args'. File: modules/dblog/dblog.admin.inc
function dblog_build_filter_query() { if (empty($_SESSION['dblog_overview_filter'])) { return; } $filters = dblog_filters(); // Build query $where = $args = array(); foreach ($_SESSION['dblog_overview_filter'] as $key => $filter) { $filter_where = array(); foreach ($filter as $value) { $...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b5cd726ba6
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/_node_revision_access/7.x
I need the code for `_node_revision_access($node, $op = 'view', $account = NULL)` in Drupal 7 (modules/node/node.module). It must do this: Access callback: Checks node revision access.
Parameters: - $node: The node to check. - $op: (optional) The specific operation being checked. Defaults to 'view.' - $account (object): (optional) A user object representing the user for whom the operation is to be performed. Determines access for a user other than the current user. Returns: TRUE if the operation may...
function _node_revision_access($node, $op = 'view', $account = NULL) { $access = &drupal_static(__FUNCTION__, array()); $map = array( 'view' => 'view revisions', 'update' => 'revert revisions', 'delete' => 'delete revisions', ); if (!$node || !isset($map[$op])) { // If there was no node to che...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b5e390a8df
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_valid_token/7.x
I need the code for `drupal_valid_token($token, $value = '', $skip_anonymous = FALSE)` in Drupal 7 (includes/common.inc). It must do this: Validates a token based on $value, the user session, and the private key.
Parameters: - $token: The token to be validated. - $value: An additional value to base the token on. - $skip_anonymous: Set to true to skip token validation for anonymous users. Returns: True for a valid token, false for an invalid token. When $skip_anonymous is true, the return value will always be true for anonymous...
function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) { global $user; return (($skip_anonymous && $user->uid == 0) || ($token === drupal_get_token($value))); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b621d71af9
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_show/7.x
Implement `node_show($node, $message = FALSE)` in PHP for Drupal 7. Required behavior: Generates an array which displays a node detail page.
Parameters: - $node: A node object. - $message: A flag which sets a page title relevant to the revision being viewed. Returns: A $page element suitable for use by drupal_render(). File: modules/node/node.module
function node_show($node, $message = FALSE) { if ($message) { drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp))), PASS_THROUGH); } // For markup consistency with other pages, use node_view_multiple() rather than node_view()....
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b623babea1
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_realpath/7.x
In Drupal 7, write the function `drupal_realpath($uri)` (file includes/file.inc) so that it does the following: Resolves the absolute filepath of a local URI or filepath.
The use of drupal_realpath() is discouraged, because it does not work for remote URIs. Except in rare cases, URIs should not be manually resolved. Only use this function if you know that the stream wrapper in the URI uses the local file system, and you need to pass an absolute path to a function that is incompatible w...
function drupal_realpath($uri) { // If this URI is a stream, pass it off to the appropriate stream wrapper. // Otherwise, attempt PHP's realpath. This allows use of drupal_realpath even // for unmanaged files outside of the stream wrapper interface. if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b63cf632e0
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_make_sticky_action/7.x
I need the code for `node_make_sticky_action($node, $context = array())` in Drupal 7 (modules/node/node.module). It must do this: Sets the sticky-at-top-of-list property of a node to 1.
Parameters: - $node: A node object. - $context: (optional) Array of additional information about what triggered the action. Not used for this action. File: modules/node/node.module
function node_make_sticky_action($node, $context = array()) { $node->sticky = NODE_STICKY; watchdog('action', 'Set @type %title to sticky.', array('@type' => node_type_get_name($node), '%title' => $node->title)); }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b63e9bde8d
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_file_delete/7.x
Give me the example code for `hook_file_delete($file)` in Drupal 7. Hook description: Respond to a file being deleted.
Parameters: - $file: The file that has just been deleted. File: modules/system/system.api.php
function hook_file_delete($file) { // Delete all information associated with the file. db_delete('upload')->condition('fid', $file->fid)->execute(); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b63fee30fd
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_children_relative_depth/7.x
In Drupal 7, write the function `menu_link_children_relative_depth($item)` (file includes/menu.inc) so that it does the following: Finds the depth of an item's children relative to its depth.
For example, if the item has a depth of 2, and the maximum of any child in the menu link tree is 5, the relative depth is 3. Parameters: - $item: An array representing a menu link item. Returns: The relative depth, or zero. File: includes/menu.inc
function menu_link_children_relative_depth($item) { $query = db_select('menu_links'); $query->addField('menu_links', 'depth'); $query->condition('menu_name', $item['menu_name']); $query->orderBy('depth', 'DESC'); $query->range(0, 1); $i = 1; $p = 'p1'; while ($i <= MENU_MAX_DEPTH && $item[$p]) { $q...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b6422bb89b
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21user%21user.module/function/_user_mail_notify/7.x
I need the code for `_user_mail_notify($op, $account, $language = NULL)` in Drupal 7 (modules/user/user.module). It must do this: Conditionally create and send a notification email when a certain operation happens on the given user account.
Parameters: - $op: The operation being performed on the account. Possible values: - 'register_admin_created': Welcome message for user created by the admin. - 'register_no_approval_required': Welcome message when user self-registers. - 'register_pending_approval': Welcome message, user pending admin approval. - 'passwo...
function _user_mail_notify($op, $account, $language = NULL) { // By default, we always notify except for canceled and blocked. $default_notify = ($op != 'status_canceled' && $op != 'status_blocked'); $notify = variable_get('user_mail_' . $op . '_notify', $default_notify); if ($notify) { $params['account'] =...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b64d807d73
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.inc/function/_openid_meta_httpequiv/7.x
In Drupal 7, write the function `_openid_meta_httpequiv($equiv, $html)` (file modules/openid/openid.inc) so that it does the following: Pull the http-equiv attribute out of an html meta element
File: modules/openid/openid.inc
function _openid_meta_httpequiv($equiv, $html) { preg_match('|<meta\s+http-equiv=["\']' . $equiv . '["\'](.*)/?>|iUs', $html, $matches); if (isset($matches[1])) { preg_match('|content=["\']([^"]+)["\']|iUs', $matches[1], $content); if (isset($content[1])) { return $content[1]; } } return FALSE...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b6679cb9a3
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_discovery_method_info_alter/7.x
Give me the example code for `hook_openid_discovery_method_info_alter(&$methods)` in Drupal 7. Hook description: Allow modules to alter discovery methods.
File: modules/openid/openid.api.php
function hook_openid_discovery_method_info_alter(&$methods) { // Remove XRI discovery scheme. unset($methods['xri']); }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b670028d85
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21common.inc/function/url/7.x
I need the code for `url($path = NULL, array $options = array())` in Drupal 7 (includes/common.inc). It must do this: Generates an internal or external URL.
When creating links in modules, consider whether l() could be a better alternative than url(). Parameters: - $path: (optional) The internal path or external URL being linked to, such as "node/34" or "http://example.com/foo". The default value is equivalent to passing in '<front>'. A few notes: - If you provide a full ...
function url($path = NULL, array $options = array()) { // Merge in defaults. $options += array( 'fragment' => '', 'query' => array(), 'absolute' => FALSE, 'alias' => FALSE, 'prefix' => '' ); // Determine whether this is an external link, but ensure that the current // path is always treat...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b673df4a11
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21overlay%21overlay.module/function/overlay_render_region/7.x
Implement `overlay_render_region($region)` in PHP for Drupal 7. Required behavior: Renders an individual page region.
This function is primarily intended to be used for checking the content of supplemental overlay regions (e.g., a region containing a toolbar). Passing in a region that is intended to display the main page content is not supported; the region will be rendered by this function, but the main page content will not appear i...
function overlay_render_region($region) { // Indicate the region that we will be rendering, so that other regions will // be hidden by overlay_page_alter() and overlay_block_list_alter(). overlay_set_regions_to_render(array($region)); // Do what is necessary to force drupal_render_page() to only display HTML ...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b68af68508
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21image%21image.install/function/image_update_7001/7.x
I need the code for `image_update_7001()` in Drupal 7 (modules/image/image.install). It must do this: Rename possibly misnamed {image_effect} table to {image_effects}.
File: modules/image/image.install
function image_update_7001() { // Due to a bug in earlier versions of image_update_7000() it is possible // to end up with an {image_effect} table where there should be an // {image_effects} table. if (!db_table_exists('image_effects') && db_table_exists('image_effect')) { db_rename_table('image_effect', 'i...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b68f351554
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21locale%21locale.admin.inc/function/locale_translate_delete_page/7.x
Implement `locale_translate_delete_page($lid)` in PHP for Drupal 7. Required behavior: String deletion confirmation page.
File: modules/locale/locale.admin.inc
function locale_translate_delete_page($lid) { if ($source = db_query('SELECT lid, source FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject()) { return drupal_get_form('locale_translate_delete_form', $source); } return MENU_NOT_FOUND; }
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b695ee6624
7
drupal_api_code
https://api.drupal.org/api/drupal/modules%21openid%21openid.api.php/function/hook_openid_response/7.x
Give me the example code for `hook_openid_response($response, $account)` in Drupal 7. Hook description: Allow modules to act upon a successful OpenID login.
Parameters: - $response: Response values from the OpenID Provider. - $account: The Drupal user account that logged in File: modules/openid/openid.api.php
function hook_openid_response($response, $account) { if (isset($response['openid.ns.ax'])) { _mymodule_store_ax_fields($response, $account); } }
[ "code-task", "hook-definition" ]
2026-09-30T00:00:00
api-drupal7-b69853d937
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21file.phar.inc/function/file_register_phar_wrapper/7.x
Implement `file_register_phar_wrapper()` in PHP for Drupal 7. Required behavior: Registers a phar stream wrapper that is more secure than PHP's built-in one.
File: includes/file.phar.inc
function file_register_phar_wrapper() { $directory = DRUPAL_ROOT . '/misc/typo3/phar-stream-wrapper/src'; include_once $directory . '/Assertable.php'; include_once $directory . '/Behavior.php'; include_once $directory . '/Exception.php'; include_once $directory . '/Helper.php'; include_once $directory . '/M...
[ "code-task", "function" ]
2026-09-30T00:00:00
api-drupal7-b6ab8a65ed
7
drupal_api_code
https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_object/7.x
I need the code for `menu_get_object($type = 'node', $position = 1, $path = NULL)` in Drupal 7 (includes/menu.inc). It must do this: Gets a loaded object from a router item.
menu_get_object() provides access to objects loaded by the current router item. For example, on the page node/%node, the router loads the %node object, and calling menu_get_object() will return that. Normally, it is necessary to specify the type of object referenced, however node is the default. The following example t...
function menu_get_object($type = 'node', $position = 1, $path = NULL) { $router_item = menu_get_item($path); if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type . '_load') { return $router_item['map'][$position]; ...
[ "code-task", "function" ]
2026-09-30T00:00:00