drupal 7 api doc

38
Drupal 7 API Components Table of Contents Drupal 7 API Components................................................................................................................1 Preface.............................................................................................................................................1 Module System (Hooks)...................................................................................................................1 Functions & methods...................................................................................................................2 Database Abstraction Layer.............................................................................................................9 SELECT.......................................................................................................................................9 INSERT, UPDATE and DELETE................................................................................................11 Transactions...............................................................................................................................11 Classes......................................................................................................................................12 Interfaces...................................................................................................................................14 Functions & methods.................................................................................................................14 Constants..................................................................................................................................14 Menu System.................................................................................................................................14 Functions & methods.................................................................................................................15 Constants..................................................................................................................................18 Groups.......................................................................................................................................19 Form Generation............................................................................................................................19 The $form_state keys are:.........................................................................................................20 Functions & methods.................................................................................................................21 File Management System...............................................................................................................24 Fields on the file object:.............................................................................................................24 Functions & methods.................................................................................................................24 Constants..................................................................................................................................26 Field API.........................................................................................................................................26 Classes......................................................................................................................................27 Functions & methods.................................................................................................................27 Constants..................................................................................................................................28 Search System...............................................................................................................................28 Functions & methods.................................................................................................................28 Node Access System.....................................................................................................................29 Functions & methods.................................................................................................................29 Theme System...............................................................................................................................30 See also.....................................................................................................................................31 Functions & methods.................................................................................................................31 Constants.......................................................................................................................................36 Global variables..............................................................................................................................37 Preface The following technical document is compiled from the official Drupal API information published at http://api.drupal.org/api/drupal/7 It is intended for use by developers aiming to master Drupal 7. Module System (Hooks) Allow modules to interact with the Drupal core. Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is

Upload: aron-novak

Post on 24-Jul-2016

253 views

Category:

Documents


6 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Drupal 7 API doc

Drupal 7 API Components

Table of ContentsDrupal 7 API Components................................................................................................................1Preface.............................................................................................................................................1Module System (Hooks)...................................................................................................................1

Functions & methods...................................................................................................................2Database Abstraction Layer.............................................................................................................9

SELECT.......................................................................................................................................9INSERT, UPDATE and DELETE................................................................................................11Transactions...............................................................................................................................11Classes......................................................................................................................................12Interfaces...................................................................................................................................14Functions & methods.................................................................................................................14Constants..................................................................................................................................14

Menu System.................................................................................................................................14Functions & methods.................................................................................................................15Constants..................................................................................................................................18Groups.......................................................................................................................................19

Form Generation............................................................................................................................19The $form_state keys are:.........................................................................................................20Functions & methods.................................................................................................................21

File Management System...............................................................................................................24Fields on the file object:.............................................................................................................24Functions & methods.................................................................................................................24Constants..................................................................................................................................26

Field API.........................................................................................................................................26Classes......................................................................................................................................27Functions & methods.................................................................................................................27Constants..................................................................................................................................28

Search System...............................................................................................................................28Functions & methods.................................................................................................................28

Node Access System.....................................................................................................................29Functions & methods.................................................................................................................29

Theme System...............................................................................................................................30See also.....................................................................................................................................31Functions & methods.................................................................................................................31

Constants.......................................................................................................................................36Global variables..............................................................................................................................37

PrefaceThe following technical document is compiled from the official Drupal API information published at http://api.drupal.org/api/drupal/7

It is intended for use by developers aiming to master Drupal 7.

Module System (Hooks)Allow modules to interact with the Drupal core.

Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is

Page 2: Drupal 7 API doc

named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.

To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.

The available hooks to implement are explained here in the Hooks section of the developer documentation. The string "hook" is used as a placeholder for the module name in the hook definitions. For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().

The example functions included are not part of the Drupal core, they are just models that you can modify. Only the hooks implemented within modules are executed when running Drupal.

See also the themeable group page.

Functions & methodsName Descriptionhook_actions_delete Executes code after an action is deleted.hook_action_info Declares information about actions.hook_action_info_alter Alters the actions declared by another module.hook_admin_paths Define administrative paths.

hook_admin_paths_alter Redefine administrative paths defined by other modules.

hook_aggregator_fetch Implement this hook to create an alternative fetcher for aggregator module.

hook_aggregator_fetch_info Implement this hook to expose the title and a short description of your fetcher.

hook_aggregator_parse Implement this hook to create an alternative parser for aggregator module.

hook_aggregator_parse_info Implement this hook to expose the title and a short description of your parser.

hook_aggregator_process Implement this hook to create a processor for aggregator module.

hook_aggregator_process_info Implement this hook to expose the title and a short description of your processor.

hook_aggregator_removeImplement this hook to remove stored data if a feed is being deleted or a feed's items are being removed.

hook_ajax_render_alterAlter the commands that are sent to the user through the AJAX framework.

hook_archiver_info Declare archivers to the system.

hook_archiver_info_alter Alter archiver information declared by other modules.

hook_batch_alter Alter batch information before a batch is processed.

hook_block_configure Define a configuration form for a block.hook_block_info Define all blocks provided by the module.

hook_block_info_alter Change block definition before saving to the database.

hook_block_list_alter Act on blocks prior to rendering.

hook_block_saveSave the configuration options fromhook_block_configure().

Page 3: Drupal 7 API doc

Name Descriptionhook_block_view Return a rendered or renderable view of a block.hook_block_view_alter Perform alterations to the content of a block.hook_block_view_MODULE_DELTA_alter Perform alterations to a specific block.hook_boot Perform setup tasks. See also, hook_init.hook_comment_delete The comment is being deleted by the moderator.hook_comment_insert The comment is being inserted.hook_comment_load Comments are being loaded from the database.

hook_comment_presave The comment passed validation and is about to be saved.

hook_comment_publish The comment is being published by the moderator.

hook_comment_unpublish The comment is being unpublished by the moderator.

hook_comment_update The comment is being updated.

hook_comment_viewThe comment is being viewed. This hook can be used to add additional data to the comment before theming.

hook_comment_view_alter The comment was built; the module may modify the structured content.

hook_contextual_links_view_alter Alter a contextual links element before it is rendered.

hook_countries_alter Alter the default country list.hook_cron Perform periodic actions.

hook_cron_queue_info Declare queues holding items that need to be run periodically.

hook_cron_queue_info_alter Alter cron queue information before cron runs.

hook_css_alterAlter CSS files before they are output on the page.

hook_custom_themeReturn the machine-readable name of the theme to use for the current page.

hook_dashboard_regions Adds regions to the dashboard.hook_dashboard_regions_alter Alter dashboard regions provided by modules.hook_date_formats Defines additional date formats.

hook_date_formats_alter Alters date types and formats declared by another module.

hook_date_format_types Defines additional date types.hook_date_format_types_alter Modify existing date format types.hook_delete Respond to node deletion.

hook_disablePerform necessary actions before module is disabled.

hook_drupal_goto_alterChange the page the user is sent to bydrupal_goto().

hook_element_infoAllows modules to declare their own Forms API element types and specify their default values.

hook_element_info_alterAlter the element type information returned from modules.

hook_enablePerform necessary actions after module is enabled.

hook_entity_delete Act on entities when deleted.

hook_entity_info Inform the base system and the Field API about one or more entity types.

hook_entity_info_alter Alter the entity info.hook_entity_insert Act on entities when inserted.

Page 4: Drupal 7 API doc

Name Descriptionhook_entity_load Act on entities when loaded.

hook_entity_prepare_view Act on entities as they are being prepared for view.

hook_entity_query_alter Alter or execute an EntityFieldQuery.hook_entity_update Act on entities when updated.hook_entity_view Act on entities being assembled before rendering.hook_entity_view_alter Alter the results of ENTITY_view().hook_exit Perform cleanup tasks.

hook_filetransfer_backendsProvide information on available file transfer backends.

hook_file_copy Respond to a file that has been copied.hook_file_delete Respond to a file being deleted.

hook_file_downloadControl access to private file downloads and specify HTTP headers.

hook_file_insert Respond to a file being added.hook_file_load Load additional information into file objects.

hook_file_mimetype_mapping_alterAlter MIME type mappings used to determine MIME type from a file extension.

hook_file_move Respond to a file that has been moved.hook_file_update Respond to a file being updated.hook_file_url_alter Alter the URL to a file.hook_file_validate Check that files meet a given criteria.

hook_filter_format_disablePerform actions when a text format has been disabled.

hook_filter_format_insertPerform actions when a new text format has been created.

hook_filter_format_updatePerform actions when a text format has been updated.

hook_filter_info Define content filters.hook_filter_info_alter Perform alterations on filter definitions.hook_flush_caches Add a list of cache tables to be cleared.hook_form Display a node editing form.hook_forms Map form_ids to form builder functions.hook_form_alter Perform alterations before a form is rendered.

hook_form_BASE_FORM_ID_alterProvide a form-specific alteration for shared forms.

hook_form_FORM_ID_alterProvide a form-specific alteration instead of the global hook_form_alter().

hook_help Provide online user help.

hook_hook_info Defines one or more hooks that are exposed by a module.

hook_hook_info_alter Alter information from hook_hook_info().

hook_html_head_alterAlter XHTML HEAD tags before they are rendered by drupal_get_html_head().

hook_image_default_stylesProvide module-based image styles for reuse throughout Drupal.

hook_image_effect_infoDefine information about image effects provided by a module.

hook_image_effect_info_alterAlter the information provided inhook_image_effect_info().

hook_image_styles_alterModify any image styles provided by other modules or the user.

hook_image_style_delete Respond to image style deletion.

Page 5: Drupal 7 API doc

Name Descriptionhook_image_style_flush Respond to image style flushing.hook_image_style_save Respond to image style updating.hook_image_toolkits Define image toolkits provided by this module.hook_init Perform setup tasks. See also, hook_boot.hook_insert Respond to creation of a new node.hook_install Perform setup tasks when the module is installed.

hook_install_tasksReturn an array of tasks to be performed by an installation profile.

hook_install_tasks_alter Alter the full list of installation tasks.

hook_js_alter Perform necessary alterations to the JavaScript before it is presented on the page.

hook_language_fallback_candidates_alter Perform alterations on the language fallback candidates.

hook_language_init Allows modules to act after language initialization has been performed.

hook_language_negotiation_info Allow modules to define their own language providers.

hook_language_negotiation_info_alter Perform alterations on language providers.hook_language_switch_links_alter Perform alterations on language switcher links.

hook_language_types_info Allow modules to define their own language types.

hook_language_types_info_alter Perform alterations on language types.

hook_libraryRegisters JavaScript/CSS libraries associated with a module.

hook_library_alter Alters the JavaScript/CSS library registry.hook_load Act on nodes being loaded from the database.

hook_localeAllows modules to define their own text groups that can be translated.

hook_mailPrepare a message based on parameters; called from drupal_mail().

hook_mail_alterAlter an email message created with thedrupal_mail() function.

hook_menu Define menu items and page callbacks.

hook_menu_alter Alter the data being saved to the {menu_router} table after hook_menu is invoked.

hook_menu_breadcrumb_alter Alter links in the active trail before it is rendered as the breadcrumb.

hook_menu_contextual_links_alter Alter contextual links before they are rendered.

hook_menu_deleteInforms modules that a custom menu was deleted.

hook_menu_insertInforms modules that a custom menu was created.

hook_menu_link_alterAlter the data being saved to the {menu_links} table by menu_link_save().

hook_menu_link_deleteInform modules that a menu link has been deleted.

hook_menu_link_insertInform modules that a menu link has been created.

hook_menu_link_updateInform modules that a menu link has been updated.

hook_menu_local_tasks_alterAlter tabs and actions displayed on the page before they are rendered.

hook_menu_site_status_alter Control site status before menu dispatching.hook_menu_update Informs modules that a custom menu was

Page 6: Drupal 7 API doc

Name Descriptionupdated.

hook_modules_disabled Perform necessary actions after modules are disabled.

hook_modules_enabled Perform necessary actions after modules are enabled.

hook_modules_installed Perform necessary actions after modules are installed.

hook_modules_uninstalled Perform necessary actions after modules are uninstalled.

hook_module_implements_alter Alter the registry of modules implementing a hook.

hook_multilingual_settings_changed Allow modules to react to language settings changes.

hook_node_access Control access to a node.

hook_node_access_recordsSet permissions for a node to be written to the database.

hook_node_access_records_alterAlter permissions for a node before it is written to the database.

hook_node_delete Respond to node deletion.

hook_node_grants Inform the node access system what permissions the user has.

hook_node_grants_alter Alter user access rules when trying to view, edit or delete a node.

hook_node_info Define module-provided node types.hook_node_insert Respond to creation of a new node.hook_node_load Act on nodes being loaded from the database.hook_node_operations Add mass node operations.

hook_node_prepare Act on a node object about to be shown on the add/edit form.

hook_node_presave Act on a node being inserted or updated.hook_node_revision_delete Respond to deletion of a node revision.hook_node_search_result Act on a node being displayed as a search result.

hook_node_submitAct on a node after validated form values have been copied to it.

hook_node_type_delete Respond to node type deletion.hook_node_type_insert Respond to node type creation.hook_node_type_update Respond to node type updates.hook_node_update Respond to updates to a node.hook_node_update_index Act on a node being indexed for searching.

hook_node_validate Perform node validation before a node is created or updated.

hook_node_view Act on a node that is being assembled before rendering.

hook_node_view_alter Alter the results of node_view().

hook_openidAllow modules to modify the OpenID request parameters.

hook_openid_discovery_method_infoAllow modules to declare OpenID discovery methods.

hook_openid_discovery_method_info_alter Allow modules to alter discovery methods.

hook_openid_normalization_method_info Allow modules to declare OpenID normalization methods.

hook_openid_normalization_method_info_alter Allow modules to alter normalization methods.

hook_openid_responseAllow modules to act upon a successful OpenID login.

Page 7: Drupal 7 API doc

Name Description

hook_overlay_child_initializeAllow modules to act when an overlay child window is initialized.

hook_overlay_parent_initializeAllow modules to act when an overlay parent window is initialized.

hook_page_alter Perform alterations before a page is rendered.hook_page_build Add elements to a page before it is rendered.

hook_page_delivery_callback_alterAlters the delivery callback used to send the result of the page callback to the browser.

hook_path_delete The path has been deleted.hook_path_insert The path has been inserted.hook_path_update The path has been updated.hook_permission Define user permissions.

hook_prepareAct on a node object about to be shown on the add/edit form.

hook_query_alter Perform alterations to a structured query.

hook_query_TAG_alter Perform alterations to a structured query for a given tag.

hook_ranking Provide additional methods of scoring for core search results for nodes.

hook_rdf_mapping Allow modules to define RDF mappings for field bundles.

hook_rdf_namespaces Allow modules to define namespaces for RDF mappings.

hook_registry_files_alter Perform necessary alterations to the list of files parsed by the registry.

hook_requirements Check installation requirements and do status reporting.

hook_schema Define the current version of the database schema.

hook_schema_alter Perform alterations to existing database schemas.hook_search_access Define access to a custom search routine.hook_search_admin Add elements to the search settings form.hook_search_execute Execute a search for a set of key words.hook_search_info Define a custom search type.hook_search_page Override the rendering of search results.hook_search_preprocess Preprocess text for search.

hook_search_resetTake action when the search index is going to be rebuilt.

hook_search_status Report the status of indexing.

hook_shortcut_default_set Return the name of a default shortcut set for the provided user account.

hook_simpletest_alter Alter the list of tests.

hook_stream_wrappersRegisters PHP stream wrapper implementations associated with a module.

hook_stream_wrappers_alterAlters the list of PHP stream wrapper implementations.

hook_system_info_alterAlter the information parsed from module and theme .info files

hook_system_themes_page_alter Alters theme operation links.hook_taxonomy_term_delete Respond to the deletion of taxonomy terms.hook_taxonomy_term_insert Act on taxonomy terms when inserted.hook_taxonomy_term_load Act on taxonomy terms when loaded.hook_taxonomy_term_presave Act on taxonomy terms before they are saved.

Page 8: Drupal 7 API doc

Name Descriptionhook_taxonomy_term_update Act on taxonomy terms when updated.hook_taxonomy_term_view_alter Alter the results of taxonomy_term_view().

hook_taxonomy_vocabulary_deleteRespond to the deletion of taxonomy vocabularies.

hook_taxonomy_vocabulary_insert Act on taxonomy vocabularies when inserted.hook_taxonomy_vocabulary_load Act on taxonomy vocabularies when loaded.

hook_taxonomy_vocabulary_presaveAct on taxonomy vocabularies before they are saved.

hook_taxonomy_vocabulary_update Act on taxonomy vocabularies when updated.hook_test_finished An individual test has finished.hook_test_group_finished A test group has finished.hook_test_group_started A test group has started.

hook_themeRegister a module (or theme's) theme implementations.

hook_theme_registry_alterAlter the theme registry information returned from hook_theme().

hook_tokensProvide replacement values for placeholder tokens.

hook_tokens_alter Alter replacement values for placeholder tokens.

hook_token_info Provide information about available placeholder tokens and token types.

hook_token_info_alter Alter the metadata about available placeholder tokens and token types.

hook_translated_menu_link_alter Alter a menu link after it has been translated and before it is rendered.

hook_trigger_info Declare triggers (events) for users to assign actions to.

hook_trigger_info_alter Alter triggers declared by hook_trigger_info().hook_uninstall Remove any information that the module sets.hook_update Respond to updates to a node.

hook_updater_infoProvide information on Updaters (classes that can update Drupal).

hook_updater_info_alter Alter the Updater information array.

hook_update_dependencies Return an array of information about module update dependencies.

hook_update_index Update the search index for this module.

hook_update_last_removedReturn a number which is no longer available as hook_update_N().

hook_update_N Perform a single update.

hook_update_projects_alter Alter the list of projects before fetching data and comparing versions.

hook_update_status_alter Alter the information about available updates for projects.

hook_url_inbound_alter Alters inbound URL requests.hook_url_outbound_alter Alters outbound URLs.hook_username_alter Alter the username that is displayed for a user.hook_user_cancel Act on user account cancellations.hook_user_cancel_methods_alter Modify account cancellation methods.

hook_user_categoriesRetrieve a list of user setting or profile information categories.

hook_user_delete Respond to user deletion.hook_user_insert A user account was created.hook_user_load Act on user objects when loaded from the

Page 9: Drupal 7 API doc

Name Descriptiondatabase.

hook_user_login The user just logged in.hook_user_logout The user just logged out.hook_user_operations Add mass user operations.hook_user_presave A user account is about to be created or updated.

hook_user_role_delete Inform other modules that a user role has been deleted.

hook_user_role_insert Inform other modules that a user role has been added.

hook_user_role_update Inform other modules that a user role has been updated.

hook_user_update A user account was updated.hook_user_view The user's account information is being displayed.

hook_user_view_alter The user was built; the module may modify the structured content.

hook_validate Perform node validation before a node is created or updated.

hook_verify_update_archive Verify an archive after it has been downloaded and extracted.

hook_view Display a node.hook_watchdog Log an event messagehook_xmlrpc Register XML-RPC callbacks.

hook_xmlrpc_alterAlters the definition of XML-RPC methods before they are called.

module_hook Determine whether a module implements a hook.

module_hook_info Retrieve a list of what hooks are explicitly declared.

module_implements Determine which modules are implementing a hook.

module_implements_write_cache Writes the hook implementation cache.module_invoke Invoke a hook in a particular module.

module_invoke_all Invoke a hook in all enabled modules that implement it.

sample_search_conditions_callback An example conditions callback function for search.

includes/module.inc, line 532

Database Abstraction LayerAllow the use of different database servers using the same code base.

Drupal provides a database abstraction layer to provide developers with the ability to support multiple database servers easily. The intent of this layer is to preserve the syntax and power of SQL as much as possible, but also allow developers a way to leverage more complex functionality in a unified way. It also provides a structured interface for dynamically constructing queries when appropriate, and enforcing security checks and similar good practices.

The system is built atop PHP's PDO (PHP Data Objects) database API and inherits much of its syntax and semantics.

SELECTMost Drupal database SELECT queries are performed by a call to db_query() or db_query_range(). Module authors should also consider using the PagerDefault Extender for

Page 10: Drupal 7 API doc

queries that return results that need to be presented on multiple pages, and the Tablesort Extender for generating appropriate queries for sortable tables.

For example, one might wish to return a list of the most recent 10 nodes authored by a given user. Instead of directly issuing the SQL query

<?php

SELECT n.nid, n.title, n.created FROM node n WHERE n.uid = $uid LIMIT 0, 10;?>

one would instead call the Drupal functions:

<?php

$result = db_query_range('SELECT n.nid, n.title, n.created FROM {node} n WHERE n.uid = :uid', 0, 10, array(':uid' => $uid));foreach ($result as $record) { // Perform operations on $node->title, etc. here.}?>

Curly braces are used around "node" to provide table prefixing via DatabaseConnection::prefixTables(). The explicit use of a user ID is pulled out into an argument passed to db_query() so that SQL injection attacks from user input can be caught and nullified. The LIMIT syntax varies between database servers, so that is abstracted into db_query_range() arguments. Finally, note the PDO-based ability to iterate over the result set using foreach ().

All queries are passed as a prepared statement string. A prepared statement is a "template" of a query that omits literal or variable values in favor of placeholders. The values to place into those placeholders are passed separately, and the database driver handles inserting the values into the query in a secure fashion. That means you should never quote or string-escape a value to be inserted into the query.

There are two formats for placeholders: named and unnamed. Named placeholders are strongly preferred in all cases as they are more flexible and self-documenting. Named placeholders should start with a colon ":" and can be followed by one or more letters, numbers or underscores.

Named placeholders begin with a colon followed by a unique string. Example:

<?php

SELECT nid, title FROM {node} WHERE uid=:uid;?>

":uid" is a placeholder that will be replaced with a literal value when the query is executed. A given placeholder label cannot be repeated in a given query, even if the value should be the same. When using named placeholders, the array of arguments to the query must be an associative array where keys are a placeholder label (e.g., :uid) and the value is the corresponding value to use. The array may be in any order.

Unnamed placeholders are simply a question mark. Example:

<?php

SELECT nid, title FROM {node} WHERE uid=?;?>

In this case, the array of arguments must be an indexed array of values to use in the exact same order as the placeholders in the query.

Page 11: Drupal 7 API doc

Note that placeholders should be a "complete" value. For example, when running a LIKE query the SQL wildcard character, %, should be part of the value, not the query itself. Thus, the following is incorrect:

<?php

SELECT nid, title FROM {node} WHERE title LIKE :title%;?>

It should instead read:

<?php

SELECT nid, title FROM {node} WHERE title LIKE :title;?>

and the value for :title should include a % as appropriate. Again, note the lack of quotation marks around :title. Because the value is not inserted into the query as one big string but as an explicitly separate value, the database server knows where the query ends and a value begins. That is considerably more secure against SQL injection than trying to remember which values need quotation marks and string escaping and which don't.

INSERT, UPDATE and DELETEINSERT, UPDATE, and DELETE queries need special care in order to behave consistently across all different databases. Therefore, they use a special object-oriented API for defining a query structurally. For example, rather than:

<?php

INSERT INTO node (nid, title, body) VALUES (1, 'my title', 'my body');?>

one would instead write:

<?php

$fields = array('nid' => 1, 'title' => 'my title', 'body' => 'my body');db_insert('node')->fields($fields)->execute();?>

This method allows databases that need special data type handling to do so, while also allowing optimizations such as multi-insert queries. UPDATE and DELETE queries have a similar pattern.

TransactionsDrupal also supports transactions, including a transparent fallback for databases that do not support transactions. To start a new transaction, simply call $txn = db_transaction(); in your own code. The transaction will remain open for as long as the variable $txn remains in scope. When $txn is destroyed, the transaction will be committed. If your transaction is nested inside of another then Drupal will track each transaction and only commit the outer-most transaction when the last transaction object goes out out of scope, that is, all relevant queries completed successfully.

Example:

<?php

function my_transaction_function() { // The transaction opens here. $txn = db_transaction();

Page 12: Drupal 7 API doc

try { $id = db_insert('example') ->fields(array( 'field1' => 'mystring', 'field2' => 5, )) ->execute();

my_other_function($id);

return $id; } catch (Exception $e) { // Something went wrong somewhere, so roll back now. $txn->rollback(); // Log the exception to watchdog. watchdog_exception('type', $e); }

// $txn goes out of scope here. Unless the transaction was rolled back, it // gets automatically commited here.}

function my_other_function($id) { // The transaction is still open here.

if ($id % 2 == 0) { db_update('example') ->condition('id', $id) ->fields(array('field2' => 10)) ->execute(); }}?>

@link http://drupal.org/developing/api/database

ClassesName Description

DatabasePrimary front-controller for the database system.

DatabaseConditionGeneric class for a series of conditions in a query.

DatabaseConnection Base Database API class.

DatabaseConnectionNotDefinedException Exception thrown if an undefined database connection is requested.

DatabaseConnection_mysqlDatabaseConnection_pgsql

DatabaseConnection_sqlite Specific SQLite implementation of DatabaseConnection.

DatabaseDriverNotSpecifiedException Exception thrown if no driver is specified for a database connection.

Page 13: Drupal 7 API doc

Name Description

DatabaseStatementBaseDefault implementation of DatabaseStatementInterface.

DatabaseStatementEmptyEmpty implementation of a database statement.

DatabaseStatementPrefetchAn implementation of DatabaseStatementInterface that prefetches all data.

DatabaseStatement_sqlite Specific SQLite implementation of DatabaseConnection.

DatabaseTransaction A wrapper class for creating and managing database transactions.

DatabaseTransactionCommitFailedException Exception thrown when a commit() function fails.

DatabaseTransactionExplicitCommitNotAllowedException Exception to deny attempts to explicitly manage transactions.

DatabaseTransactionNameNonUniqueException Exception thrown when a savepoint or transaction name occurs twice.

DatabaseTransactionNoActiveException Exception for when popTransaction() is called with no active transaction.

DeleteQuery General class for an abstracted DELETE operation.

DeleteQuery_sqlite SQLite specific implementation of DeleteQuery.

FieldsOverlapException Exception thrown if an insert query specifies a field twice.

InsertQuery General class for an abstracted INSERT query.

InsertQuery_mysqlInsertQuery_pgsql

InsertQuery_sqlite SQLite specific implementation of InsertQuery.

InvalidMergeQueryException Exception thrown for merge queries that do not make semantic sense.

MergeQuery General class for an abstracted MERGE query operation.

NoFieldsException Exception thrown if an insert query doesn't specify insert or default fields.

Query Base class for query builders.SelectQuery Query builder for SELECT statements.

SelectQueryExtender The base extender class for Select queries.

SelectQuery_pgsql

SelectQuery_sqliteSQLite specific query builder for SELECT statements.

TruncateQueryGeneral class for an abstracted TRUNCATE operation.

TruncateQuery_mysql

TruncateQuery_sqlite SQLite specific implementation of TruncateQuery.

UpdateQuery General class for an abstracted UPDATE operation.

UpdateQuery_pgsql

UpdateQuery_sqliteSQLite specific implementation of UpdateQuery.

Page 14: Drupal 7 API doc

InterfacesName DescriptionDatabaseStatementInterface A prepared statement.QueryAlterableInterface Interface for a query that can be manipulated via an alter hook.QueryConditionInterface Interface for a conditional clause in a query.QueryExtendableInterface Interface for extendable query objects.QueryPlaceholderInterface Interface for a query that accepts placeholders.SelectQueryInterface Interface definition for a Select Query object.

Functions & methodsName Descriptiondb_and Returns a new DatabaseCondition, set to "AND" all conditions together.db_autoload Autoload callback for the database system.db_close Closes the active database connection.db_condition Returns a new DatabaseCondition, set to the specified conjunction.db_delete Returns a new DeleteQuery object for the active database.db_driver Retrieves the name of the currently active database driver.db_escape_field Restricts a dynamic column or constraint name to safe characters.db_escape_table Restricts a dynamic table name to safe characters.db_insert Returns a new InsertQuery object for the active database.db_like Escapes characters that work as wildcard characters in a LIKE pattern.db_merge Returns a new MergeQuery object for the active database.db_next_id Retrieves a unique id.db_or Returns a new DatabaseCondition, set to "OR" all conditions together.db_query Executes an arbitrary query string against the active database.db_query_range Executes a query against the active database, restricted to a range.db_query_temporary Executes a query string and saves the result set to a temporary table.db_select Returns a new SelectQuery object for the active database.db_set_active Sets a new active database.db_transaction Returns a new transaction object for the active database.db_truncate Returns a new TruncateQuery object for the active database.db_update Returns a new UpdateQuery object for the active database.

db_xorReturns a new DatabaseCondition, set to "XOR" all conditions together.

ConstantsName Description

POSTGRESQL_NEXTID_LOCK The name by which to obtain a lock for retrive the next insert id.

includes/database/database.inc, line 13

Menu SystemDefine the navigation menus, and route page requests to code based on URLs.

The Drupal menu system drives both the navigation system from a user perspective and the callback system that Drupal uses to respond to URLs passed from the browser. For this reason, a good understanding of the menu system is fundamental to the creation of complex modules.

Drupal's menu system follows a simple hierarchy defined by paths. Implementations of hook_menu() define menu items and assign them to paths (which should be unique). The menu

Page 15: Drupal 7 API doc

system aggregates these items and determines the menu hierarchy from the paths. For example, if the paths defined were a, a/b, e, a/b/c/d, f/g, and a/b/h, the menu system would form the structure:

• a• a/b

• a/b/c/d• a/b/h

• e• f/g

Note that the number of elements in the path does not necessarily determine the depth of the menu item in the tree.

When responding to a page request, the menu system looks to see if the path requested by the browser is registered as a menu item with a callback. If not, the system searches up the menu tree for the most complete match with a callback it can find. If the path a/b/i is requested in the tree above, the callback for a/b would be used.

The found callback function is called with any arguments specified in the "page arguments" attribute of its menu item. The attribute must be an array. After these arguments, any remaining components of the path are appended as further arguments. In this way, the callback for a/b above could respond to a request for a/b/i differently than a request for a/b/j.

For an illustration of this process, see page_example.module.

Access to the callback functions is also protected by the menu system. The "access callback" with an optional "access arguments" of each menu item is called before the page callback proceeds. If this returns TRUE, then access is granted; if FALSE, then access is denied. Menu items may omit this attribute to use the value provided by an ancestor item.

In the default Drupal interface, you will notice many links rendered as tabs. These are known in the menu system as "local tasks", and they are rendered as tabs by default, though other presentations are possible. Local tasks function just as other menu items in most respects. It is convention that the names of these tasks should be short verbs if possible. In addition, a "default" local task should be provided for each set. When visiting a local task's parent menu item, the default local task will be rendered as if it is selected; this provides for a normal tab user experience. This default task is special in that it links not to its provided path, but to its parent item's path instead. The default task's path is only used to place it appropriately in the menu hierarchy.

Everything described so far is stored in the menu_router table. The menu_links table holds the visible menu links. By default these are derived from the same hook_menu definitions, however you are free to add more with menu_link_save().

Functions & methods

Name Description

drupal_help_arg Generates elements for the $arg array in the help hook.

menu_build_tree Build a menu tree, translate links, and check access.

menu_cache_clearClears the cached cached data for a single named menu.

menu_cache_clear_allClears all cached menu data. This should be called any time broad changes might have been made to the router items or menu links.

menu_contextual_links Retrieve contextual links for a system object based on registered local tasks.

Page 16: Drupal 7 API doc

Name Descriptionmenu_delete_links Deletes all links for a menu.

menu_execute_active_handler Execute the page callback associated with the current path.

menu_get_active_breadcrumb Get the breadcrumb for the current page, as determined by the active trail.

menu_get_active_help Returns the help associated with the active menu item.

menu_get_active_menu_names Get the active menu for the current page - determines the active trail.

menu_get_active_title Get the title of the current page, as determined by the active trail.

menu_get_active_trail Gets the active trail (path to root menu root) of the current page.

menu_get_ancestors Returns the ancestors (and relevant placeholders) for any given path.

menu_get_custom_theme Gets the custom theme for the current page, if there is one.

menu_get_item Get a router item.menu_get_names Build a list of named menus.menu_get_object Get a loaded object from a router item.menu_get_router Get the menu router.menu_links_clone Clone an array of menu links.

menu_link_children_relative_depthFind the depth of an item's children relative to its depth.

menu_link_delete Delete one or several menu links.

menu_link_get_preferred Lookup the preferred menu link for a given system path.

menu_link_load Get a menu link by its mlid, access checked and link translated for rendering.

menu_link_maintain Insert, update or delete an uncustomized menu link related to a module.

menu_link_save Save a menu link.

menu_list_system_menusReturn an array containing the names of system-defined (default) menus.

menu_load_links Returns an array containing all links for a menu.

menu_local_actions Returns the rendered local actions at the current level.

menu_local_tasks Collects the local tasks (tabs), action links, and the root path.

menu_main_menu Return an array of links to be rendered as the Main menu.

menu_navigation_links Return an array of links for a navigation menu.menu_primary_local_tasks Returns the rendered local tasks at the top level.

menu_rebuild (Re)populate the database tables used by various menu functions.

menu_reset_static_cache Resets the menu system static cache.menu_router_build Collect and alter the menu definitions.menu_secondary_local_tasks Returns the rendered local tasks at the second level.

menu_secondary_menuReturn an array of links to be rendered as the Secondary links.

menu_set_active_itemSet the active path, which determines which page is loaded.

menu_set_active_menu_namesSet (or get) the active menu for the current page - determines the active trail.

Page 17: Drupal 7 API doc

Name Description

menu_set_active_trailSets or gets the active trail (path to menu tree root) of the current page.

menu_set_custom_themeSets a custom theme for the current page, if there is one.

menu_set_item Replaces the statically cached item for a given path.

menu_tab_root_path Returns the router path, or the path of the parent tab of a default local task.

menu_tail_to_argmenu_tree Renders a menu tree based on the current path.

menu_tree_all_data Get the data structure representing a named menu tree.

menu_tree_check_access Check access and perform other dynamic operations for each link in the tree.

menu_tree_collect_node_links Recursive helper function - collect node links.menu_tree_data Build the data representing a menu tree.menu_tree_output Returns a rendered menu tree.

menu_tree_page_dataGet the data structure representing a named menu tree, based on the current page.

menu_unserialize

The menu system uses serialized arrays stored in the database for arguments. However, often these need to change according to the current path. This function unserializes such an array and does the necessary change.

template_preprocess_menu_tree Preprocesses the rendered tree for theme_menu_tree().

theme_menu_link Returns HTML for a menu link and submenu.theme_menu_local_action Returns HTML for a single local action link.theme_menu_local_task Returns HTML for a single local task link.theme_menu_local_tasks Returns renderable local tasks.theme_menu_tree Returns HTML for a wrapper for a menu sub-tree._menu_build_tree Build a menu tree.

_menu_check_access Check access to a menu item using the access callback

_menu_clear_page_cache Helper function to clear the page and block caches at most twice per page load.

_menu_delete_item Helper function for menu_link_delete; deletes a single menu link.

_menu_find_router_path Find the router path which will serve this path.

_menu_item_localizeLocalize the router item title using t() or another callback.

_menu_link_build Builds a link from a router item.

_menu_link_map_translate

This function translates the path elements in the map using any to_arg helper function. These functions take an argument and return an object. Seehttp://drupal.org/node/109153 for more information.

_menu_link_move_childrenUpdate the children of a menu link that's being moved.

_menu_link_parents_setHelper function that sets the p1..p9 values for a menu link being saved.

_menu_link_translateThis function is similar to _menu_translate() but does link-specific preparation such as always calling to_arg functions

_menu_load_objects Loads objects into the map as defined in the $item['load_functions'].

Page 18: Drupal 7 API doc

Name Description

_menu_navigation_links_rebuildHelper function to build menu links for the items in the menu router.

_menu_router_buildHelper function to build the router table based on the data from hook_menu.

_menu_router_cacheHelper function to store the menu router if we have it in memory.

_menu_router_saveHelper function to save data from menu_router_build() to the router table.

_menu_set_expanded_menusHelper function to update a list of menus with expanded items

_menu_site_is_offline Checks whether the site is in maintenance mode.

_menu_translate Handles dynamic path translation and menu access control.

_menu_tree_check_access Recursive helper function for menu_tree_check_access()

_menu_tree_data Recursive helper function to build the data representing a menu tree.

_menu_update_parental_status Check and update the has_children status for the parent of a link.

ConstantsName Description

MENU_ACCESS_DENIEDInternal menu status code -- Menu item access is denied.

MENU_CALLBACKMenu type -- A hidden, internal callback, typically used for API calls.

MENU_CONTEXT_INLINEInternal menu flag: Local task should be displayed inline.

MENU_CONTEXT_NONE Internal menu flag: Invisible local task.

MENU_CONTEXT_PAGE Internal menu flag: Local task should be displayed in page context.

MENU_CREATED_BY_ADMIN Internal menu flag -- menu item was created by administrator.

MENU_DEFAULT_LOCAL_TASK Menu type -- The "default" local task, which is initially active.

MENU_FOUND Internal menu status code -- Menu item was found.MENU_IS_LOCAL_ACTION Internal menu flag -- menu item is a local action.MENU_IS_LOCAL_TASK Internal menu flag -- menu item is a local task.

MENU_IS_ROOTInternal menu flag -- menu item is the root of the menu tree.

MENU_LINKS_TO_PARENTInternal menu flag -- menu item links back to its parent.

MENU_LOCAL_ACTIONMenu type -- An action specific to the parent, usually rendered as a link.

MENU_LOCAL_TASKMenu type -- A task specific to the parent item, usually rendered as a tab.

MENU_MAX_DEPTHThe maximum depth of a menu links tree - matches the number of p columns.

MENU_MAX_PARTSThe maximum number of path elements for a menu callback

MENU_MODIFIED_BY_ADMINInternal menu flag -- menu item can be modified by administrator.

MENU_NORMAL_ITEMMenu type -- A "normal" menu item that's shown in menu and breadcrumbs.

Page 19: Drupal 7 API doc

Name Description

MENU_NOT_FOUNDInternal menu status code -- Menu item was not found.

MENU_SITE_OFFLINEInternal menu status code -- Menu item inaccessible because site is offline.

MENU_SITE_ONLINEInternal menu status code -- Everything is working fine.

MENU_SUGGESTED_ITEMMenu type -- A normal menu item, hidden until enabled by an administrator.

MENU_VISIBLE_IN_BREADCRUMBInternal menu flag -- menu item is visible in the breadcrumb.

MENU_VISIBLE_IN_TREEInternal menu flag -- menu item is visible in the menu tree.

GroupsName DescriptionMenu context types

Flags for use in the "context" attribute of menu router items.

Menu flags Flags for use in the "type" attribute of menu items.

Menu item typesMenu item definitions provide one of these constants, which are shortcuts for combinations of the above flags.

Menu status codes Status codes for menu callbacks.Menu tree parameters

Menu tree

includes/menu.inc, line 9

Form GenerationFunctions to enable the processing and display of HTML forms.

Drupal uses these functions to achieve consistency in its form processing and presentation, while simplifying code and reducing the amount of HTML that must be explicitly generated by modules.

The primary function used with forms is drupal_get_form(), which is used for forms presented interactively to a user. Forms can also be built and submitted programmatically without any user input using the drupal_form_submit() function.

drupal_get_form() handles retrieving, processing, and displaying a rendered HTML form for modules automatically.

Here is an example of how to use drupal_get_form() and a form builder function:

<?php

$form = drupal_get_form('my_module_example_form');...function my_module_example_form($form, &$form_state) { $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form;}function my_module_example_form_validate($form, &$form_state) { // Validation logic.

Page 20: Drupal 7 API doc

}function my_module_example_form_submit($form, &$form_state) { // Submission logic.}?>

Or with any number of additional arguments:

<?php

$extra = "extra";$form = drupal_get_form('my_module_example_form', $extra);...function my_module_example_form($form, &$form_state, $extra) { $form['submit'] = array( '#type' => 'submit', '#value' => $extra, ); return $form;}?>

The $form argument to form-related functions is a structured array containing the elements and properties of the form. For information on the array components and format, and more detailed explanations of the Form API workflow, see the Form API reference and the Form API section of the handbook. In addition, there is a set of Form API tutorials in the Form Example Tutorial which provide basics all the way up through multistep forms.

In the form builder, validation, submission, and other form functions, $form_state is the primary influence on the processing of the form and is passed by reference to most functions, so they use it to communicate with the form system and each other.

The $form_state keys are:

• 'values': An associative array of values submitted to the form. The validation functions and submit functions use this array for nearly all their decision making. (Note that #tree determines whether the values are a flat array or an array whose structure parallels the $form array.)

• 'rebuild': If the submit function sets $form_state['rebuild'] to TRUE, submission is not completed and instead the form is rebuilt using any information that the submit function has made available to the form builder function via $form_state. This is commonly used for wizard-style multi-step forms, add-more buttons, and the like. For further information see drupal_build_form().

• 'redirect': a URL that will be used to redirect the form on submission. See drupal_redirect_form() for complete information.

• 'storage': $form_state['storage'] is not a special key, and no specific support is provided for it in the Form API, but by tradition it was the location where application-specific data was stored for communication between the submit, validation, and form builder functions, especially in a multi-step-style form. Form implementations may use any key(s) within $form_state (other than the keys listed here and other reserved ones used by Form API internals) for this kind of storage. The recommended way to ensure that the chosen key doesn't conflict with ones used by the Form API or other modules is to use the module name as the key name or a prefix for the key name. For example, the Node module uses $form_state['node'] in node editing forms to store information about the node being edited, and this information stays available across successive clicks of the "Preview" button as well as when the "Save" button is finally clicked.

Page 21: Drupal 7 API doc

• 'temporary': Since values for all non-reserved keys in $form_state persist throughout a multistep form sequence, the Form API provides the 'temporary' key for modules to use for communicating information across form-related functions during a single page request only. There is no use-case for this functionality in core.

• 'triggering_element': (read-only) The form element that triggered submission. This is the same as the deprecated $form_state['clicked_button']. It is the element that caused submission, which may or may not be a button (in the case of AJAX forms.) This is often used to distinguish between various buttons in a submit handler, and is also used in AJAX handlers.

• 'cache': The typical form workflow involves two page requests. During the first page request, a form is built and returned for the user to fill in. Then the user fills the form in and submits it, triggering a second page request in which the form must be built and processed. By default, $form and $form_state are built from scratch during each of these page requests. In some special use-cases, it is necessary or desired to persist the $form and $form_state variables from the initial page request to the one that processes the submission. A form builder function can set 'cache' to TRUE to do this. One example where this is needed is to handle AJAX submissions, so ajax_process_form() sets this for all forms that include an element with a #ajax property. (In AJAX, the handler has no way to build the form itself, so must rely on the cached version created on each page load, so it's a classic example of this use case.) Note that the persistence of $form and $form_state across successive submissions of a multi-step form happens automatically regardless of the value for 'cache'.

• 'input': The array of values as they were submitted by the user. These are raw and unvalidated, so should not be used without a thorough understanding of security implications. In almost all cases, code should use the data in the 'values' array exclusively. The most common use of this key is for multi-step forms that need to clear some of the user input when setting 'rebuild'.

Functions & methodsName Description

date_validateValidates the date type to stop dates like February 30, 2006.

drupal_build_form Build and process a form based on a form id.drupal_form_submit Retrieves, populates, and processes a form.

drupal_get_formWrapper for drupal_build_form() for use when $form_state is not needed.

drupal_prepare_form

Prepares a structured form array by adding required elements, executing any hook_form_alter functions, and optionally inserting a validation token to prevent tampering.

drupal_process_form Processes a form submission.

drupal_rebuild_form Constructs a new $form from the information in $form_state.

drupal_redirect_form Redirects the user to a URL after a form has been processed.

drupal_retrieve_form Retrieves the structured array that defines a given form.

drupal_validate_formValidates user-submitted form data from the $form_state using the validate functions defined in a structured form array.

form_builder

Walk through the structured form array, adding any required properties to each element and mapping the incoming input data to the proper elements. Also, execute any #process handlers attached to a specific element.

Page 22: Drupal 7 API doc

Name Description

form_clear_errorClear all errors against all form elements made by form_set_error().

form_error Flag an element as having an error.

form_execute_handlers

A helper function used to execute custom validation and submission handlers for a given form. Button-specific handlers are checked first. If none exist, the function falls back to form-level handlers.

form_get_cache Fetch a form from cache.

form_get_error Returns the error message filed against the given form element.

form_get_errors Return an associative array of all errors.

form_get_optionsTraverses a select element's #option array looking for any values that hold the given key. Returns an array of indexes that match.

form_options_flatten Allows PHP array processing of multiple select options with the same value.

form_pre_render_conditional_form_element Add form_element theming to an element if title or description is set.

form_pre_render_fieldset Adds members of this group as actual elements for rendering.

form_process_actions Processes a form actions container element.

form_process_checkboxSets the #checked property of a checkbox element.

form_process_checkboxesform_process_container Processes a container element.form_process_date Roll out a single date element.

form_process_fieldset Adds fieldsets to the specified group or adds group members to this fieldset.

form_process_machine_name Processes a machine-readable name form element.

form_process_password_confirm Expand a password_confirm field into two text boxes.

form_process_radios Roll out a single radios element to a list of radios, using the options array as index.

form_process_select Processes a select list form element.

form_process_tableselectCreate the correct amount of checkbox or radio elements to populate the table.

form_process_vertical_tabs Creates a group formatted as vertical tabs.form_process_weight Expand weight elements into selects.

form_select_optionsConverts a select form element's options array into an HTML.

form_set_cache Store a form in the cache.form_set_error Files an error against a form element.

form_set_valueChange submitted form values during form validation.

form_state_defaults Retrieve default values for the $form_state array.

form_state_keys_no_cache Returns an array of $form_state keys that shouldn't be cached.

form_state_values_clean Removes internal Form API elements and buttons from submitted form values.

form_type_checkboxes_value Helper function to determine the value for a checkboxes form element.

form_type_checkbox_value Helper function to determine the value for a checkbox form element.

Page 23: Drupal 7 API doc

Name Description

form_type_image_button_valueHelper function to determine the value for an image button form element.

form_type_password_confirm_valueHelper function to determine the value for a password_confirm form element.

form_type_select_valueHelper function to determine the value for a select form element.

form_type_tableselect_valueHelper function to determine the value for a tableselect form element.

form_type_textfield_valueHelper function to determine the value for a textfield form element.

form_type_token_valueHelper function to determine the value for form's token value.

form_validate_machine_nameForm element validation handler for #type 'machine_name'.

map_monthHelper function for usage with drupal_map_assoc to display month names.

password_confirm_validate Validate password_confirm element.theme_button Returns HTML for a button form element.theme_checkbox Returns HTML for a checkbox form element.

theme_checkboxes Returns HTML for a set of checkbox form elements.

theme_container Returns HTML for a container for grouped form items.

theme_date Returns HTML for a date selection form element.

theme_fieldsetReturns HTML for a fieldset form element and its children.

theme_file Returns HTML for a file upload form element.theme_form Returns HTML for a form.theme_form_element Returns HTML for a form element.

theme_form_element_label Returns HTML for a form element label and required marker.

theme_form_required_marker Returns HTML for a marker for required form elements.

theme_hidden Returns HTML for a hidden form element.theme_image_button Returns HTML for an image button form element.theme_password Returns HTML for a password form element.theme_radio Returns HTML for a radio button form element.

theme_radios Returns HTML for a set of radio button form elements.

theme_select Returns HTML for a select form element.theme_submit Returns HTML for a submit button form element.

theme_tableselect Returns HTML for a table with radio buttons or checkboxes.

theme_textarea Returns HTML for a textarea form element.theme_textfield Returns HTML for a textfield form element.

theme_vertical_tabs Returns HTML for an element's children fieldsets as vertical tabs.

weight_value If no default value is set for weight select boxes, use 0.

_form_builder_handle_input_elementPopulate the #value and #name properties of input elements so they can be processed and rendered.

_form_button_was_clickedHelper function to handle the convoluted logic of button click detection.

Page 24: Drupal 7 API doc

Name Description

_form_element_triggered_scripted_submissionHelper function to handle the convoluted logic of button click detection.

_form_options_flatten Helper function for form_options_flatten()._form_set_class Sets a form element's class attribute.

_form_validate

Performs validation on form elements. First ensures required fields are completed, #maxlength is not exceeded, and selected options were in the list of options given to the user. Then calls user-defined validators.

includes/form.inc, line 23

File Management SystemCommon file handling functions.

Fields on the file object:

• fid: File ID• uid: The {users}.uid of the user who is associated with the file.• filename: Name of the file with no path components. This may differ from the basename of

the filepath if the file is renamed to avoid overwriting an existing file.• uri: URI of the file.• filemime: The file's MIME type.• filesize: The size of the file in bytes.• status: A bitmapped field indicating the status of the file. The first 8 bits are reserved for

Drupal core. The least significant bit indicates temporary (0) or permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during cron runs.

• timestamp: UNIX timestamp for the date the file was added to the database.

Functions & methodsName Descriptiondrupal_chmod Set the permissions on a file or directory.

drupal_dirnameGets the name of the directory from a given path.

drupal_mkdir Creates a directory using Drupal's default mode.drupal_realpath Returns the absolute path of a file or directorydrupal_rmdir Remove a directory.

drupal_tempnam Creates a file with a unique filename in the specified directory.

drupal_unlink Deletes a file.

file_build_uriGiven a relative path, construct a URI into Drupal's default files location.

file_copyCopies a file to a new location and adds a file record to the database.

file_create_filenameCreate a full file path from a directory and filename.

file_create_htaccess Creates an .htaccess file in the given directory.

file_create_url Creates a web-accessible URL for a stream to an external or local file.

file_default_scheme Get the default file stream implementation.file_delete Delete a file and its database record.

Page 25: Drupal 7 API doc

Name Description

file_destinationDetermines the destination path for a file depending on how replacement of existing files should be handled.

file_directory_temp Get the path of system-appropriate temporary directory.

file_download Menu handler for private file transfers.

file_ensure_htaccessIf missing, create a .htaccess file in each Drupal files directory.

file_get_content_headersExamines a file object and returns appropriate content headers for download.

file_get_mimetypeDetermine an Internet Media Type, or MIME type from a filename.

file_get_stream_wrappers Drupal stream wrapper registry.file_load Load a file object from the database.file_load_multiple Loads file objects from the database.

file_move Move a file to a new location and update the file's database entry.

file_munge_filename Modify a filename as needed for security purposes.

file_prepare_directory Check that the directory exists and is writable.file_save Save a file object to the database.

file_save_data Save a string to the specified destination and create a database file entry.

file_save_upload Saves a file upload to a new location.

file_scan_directoryFinds all files that match a given mask in a given directory.

file_space_usedDetermine total disk space used by a single user or the whole filesystem.

file_stream_wrapper_get_classReturns the stream wrapper class name for a given scheme.

file_stream_wrapper_get_instance_by_schemeReturns a reference to the stream wrapper class responsible for a given scheme.

file_stream_wrapper_get_instance_by_uriReturns a reference to the stream wrapper class responsible for a given URI.

file_stream_wrapper_uri_normalizeNormalizes a URI by making it syntactically correct.

file_stream_wrapper_valid_scheme Check that the scheme of a stream URI is valid.file_transfer Transfer file using HTTP to client.

file_unmanaged_copyCopies a file to a new location without invoking the file API.

file_unmanaged_deleteDelete a file without calling any hooks or making any changes to the database.

file_unmanaged_delete_recursiveRecursively delete all files and directories in the specified filepath.

file_unmanaged_moveMove a file to a new location without calling any hooks or making any changes to the database.

file_unmanaged_save_dataSave a string to the specified destination without invoking file API.

file_unmunge_filename Undo the effect of upload_munge_filename().

file_upload_max_size Determine the maximum file upload size by querying the PHP settings.

file_uri_scheme Returns the scheme of a URI (e.g. a stream).file_uri_target Returns the part of an URI after the schema.file_usage_add Records that a module is using a file.

Page 26: Drupal 7 API doc

Name Description

file_usage_deleteRemoves a record to indicate that a module is no longer using a file.

file_usage_list Determines where a file is used.

file_validate Check that a file meets the criteria specified by the validators.

file_validate_extensions Check that the filename ends with an allowed extension.

file_validate_image_resolution Verify that image dimensions are within the specified maximum and minimum.

file_validate_is_image Check that the file is recognized byimage_get_info() as an image.

file_validate_name_length Check for files with names longer than we can store in the database.

file_validate_size Check that the file's size is below certain limits.

file_valid_uriDetermine whether the URI has a valid scheme for file API operations.

ConstantsName DescriptionFILE_CREATE_DIRECTORY Flag used by file_prepare_directory() -- create directory if not present.FILE_EXISTS_ERROR Flag for dealing with existing files: Do nothing and return FALSE.

FILE_EXISTS_RENAMEFlag for dealing with existing files: Appends number until name is unique.

FILE_EXISTS_REPLACE Flag for dealing with existing files: Replace the existing file.FILE_MODIFY_PERMISSIONS

Flag used by file_prepare_directory() -- file permissions may be changed.

FILE_STATUS_PERMANENT Indicates that the file is permanent and should not be deleted.

includes/file.inc, line 18

Field APIAttach custom data fields to Drupal entities.

The Field API allows custom data fields to be attached to Drupal entities and takes care of storing, loading, editing, and rendering field data. Any entity type (node, user, etc.) can use the Field API to make itself "fieldable" and thus allow fields to be attached to it. Other modules can provide a user interface for managing custom fields via a web browser as well as a wide and flexible variety of data type, form element, and display format capabilities.

• Data structures: Field, Instance, Bundle.

• Field Types API. Defines field types, widget types, and display formatters. Field modules use this API to provide field types like Text and Node Reference along with the associated form elements and display formatters.

• Field CRUD API. Create, updates, and deletes fields, bundles (a.k.a. "content types"), and instances. Modules use this API, often in hook_install(), to create custom data structures.

• Field Attach API. Connects entity types to the Field API. Field Attach API functions load, store, generate Form API structures, display, and perform a variety of other functions for field data connected to individual entities. Fieldable entity types like node and user use this API to make themselves fieldable.

• Field Info API. Exposes information about all fields, instances, widgets, and related information defined by or with the Field API.

Page 27: Drupal 7 API doc

• Field Storage API. Provides a pluggable back-end storage system for actual field data. The default implementation, field_sql_storage.module, stores field data in the local SQL database.

• Field API bulk data deletion. Cleans up after bulk deletion operations such asfield_delete_field() and field_delete_instance().

• Field language API. Provides native multilingual support for the Field API.

ClassesName DescriptionFieldUpdateForbiddenException Exception class thrown by hook_field_update_forbid().

Functions & methodsName Description

field_accessDetermine whether the user has access to a given field.

field_associate_fieldsAllows a module to update the database for fields and columns it controls.

field_bundle_settingsGets or sets administratively defined bundle settings.

field_cache_clear Clear the field info and field data caches.field_cron Implements hook_cron().

field_extract_bundleHelper function to extract the bundle name of from a bundle object.

field_extra_fields_get_displayReturns the display settings to use for pseudo-fields in a given view mode.

field_filter_xssLike filter_xss_admin(), but with a shorter list of allowed tags.

field_flush_caches Implements hook_flush_caches().

field_get_default_value Helper function to get the default value for a field on an entity.

field_get_display Returns the display settings to use for an instance in a given view mode.

field_get_items Returns the field items in the language they currently would be displayed.

field_has_data Determine whether a field has any data.field_help Implements hook_help().field_modules_disabled Implements hook_modules_disabled().field_modules_enabled Implements hook_modules_enabled().field_modules_uninstalled Implements hook_modules_uninstalled().field_theme Implements hook_theme().

field_view_field Returns a renderable array for the value of a single field in an entity.

field_view_mode_settings Returns view mode settings in a given bundle.field_view_value Returns a renderable array for a single field value.

template_preprocess_field Theme preprocess function for theme_field() andfield.tpl.php.

template_process_field Theme process function for theme_field() andfield.tpl.php.

_field_extra_fields_pre_render Pre-render callback to adjust weights and visibility of non-field elements.

_field_filter_items Helper function to filter out empty field values._field_filter_xss_allowed_tags List of tags allowed by field_filter_xss()._field_filter_xss_display_allowed_tags Human-readable list of allowed tags, for display in

Page 28: Drupal 7 API doc

Name Descriptionhelp texts.

_field_sort_items Helper function to sort items in a field according to user drag-n-drop reordering.

_field_sort_items_helper Sort function for items order. (copied formelement_sort(), which acts on #weight keys)

_field_sort_items_value_helper Same as above, using ['_weight']['#value']

ConstantsName DescriptionFIELD_BEHAVIOR_CUSTOM TODOFIELD_BEHAVIOR_DEFAULT TODOFIELD_BEHAVIOR_NONE TODO

FIELD_CARDINALITY_UNLIMITEDValue for $field['cardinality'] property to indicate it can hold an unlimited number of values.

FIELD_LOAD_CURRENTAge argument for loading the most recent version of an entity's field data with field_attach_load().

FIELD_LOAD_REVISIONAge argument for loading the version of an entity's field data specified in the entity with field_attach_load().

modules/field/field.module, line 28

Search SystemThe Drupal search interface manages a global search mechanism.

Modules may plug into this system to provide searches of different types of data. Most of the system is handled by search.module, so this must be enabled for all of the search features to work.

There are three ways to interact with the search system:

Specifically for searching nodes, you can implement hook_node_update_index() and hook_node_search_result(). However, note that the search system already indexes all visible output of a node, i.e. everything displayed normally by hook_view() and hook_node_view(). This is usually sufficient. You should only use this mechanism if you want additional, non-visible data to be indexed.

Implement hook_search_info(). This will create a search tab for your module on the /search page with a simple keyword search form. You will also need to implement hook_search_execute() to perform the search.

Implement hook_update_index(). This allows your module to use Drupal's HTML indexing mechanism for searching full text efficiently.

If your module needs to provide a more complicated search form, then you need to implement it yourself without hook_search_info(). In that case, you should define it as a local task (tab) under the /search page (e.g. /search/mymodule) so that users can easily find it.

Functions & methodsName Descriptionhook_search_access Define access to a custom search routine.hook_search_admin Add elements to the search settings form.hook_search_execute Execute a search for a set of key words.hook_search_info Define a custom search type.hook_search_preprocess Preprocess text for search.hook_search_reset Take action when the search index is going to be rebuilt.

Page 29: Drupal 7 API doc

Name Descriptionhook_search_status Report the status of indexing.hook_update_index Update the search index for this module.sample_search_conditions_callback

An example conditions callback function for search.

search_boxForm builder; Output a search form for the search block's search box.

search_box_form_submit Process a block search form submission.search_data Performs a search by callinghook_search_execute().

search_excerptReturns snippets from a piece of text, with certain keywords highlighted. Used for formatting search results.

search_form Builds a search form.search_index Update the full-text search index for a particular item.template_preprocess_search_block_form

Process variables for search-block-form.tpl.php.

modules/search/search.module, line 897

Node Access SystemThe node access system determines who can do what to which nodes.

In determining access rights for a node, node_access() first checks whether the user has the "bypass node access" permission. Such users have unrestricted access to all nodes. user 1 will always pass this check.

Next, all implementations of hook_node_access() will be called. Each implementation may explicitly allow, explicitly deny, or ignore the access request. If at least one module says to deny the request, it will be rejected. If no modules deny the request and at least one says to allow it, the request will be permitted.

If all modules ignore the access request, then the node_access table is used to determine access. All node access modules are queried using hook_node_grants() to assemble a list of "grant IDs" for the user. This list is compared against the table. If any row contains the node ID in question (or 0, which stands for "all nodes"), one of the grant IDs returned, and a value of TRUE for the operation in question, then access is granted. Note that this table is a list of grants; any matching row is sufficient to grant access to the node.

In node listings, the process above is followed except that hook_node_access() is not called on each node for performance reasons and for proper functioning of the pager system. When adding a node listing to your module, be sure to use a dynamic query created by db_select() and add a tag of "node_access" to ensure that only nodes to which the user has access are retrieved.

Note: Even a single module returning NODE_ACCESS_DENY from hook_node_access() will block access to the node. Therefore, implementers should take care to not deny access unless they really intend to. Unless a module wishes to actively deny access it should return NODE_ACCESS_IGNORE (or simply return nothing) to allow other modules or the node_access table to control access.

To see how to write a node access module of your own, see node_access_example.module.

Functions & methodsName Descriptionhook_node_access Control access to a node.

hook_node_access_records Set permissions for a node to be written to the database.

hook_node_access_records_alter Alter permissions for a node before it is written to the database.

Page 30: Drupal 7 API doc

Name Description

hook_node_grantsInform the node access system what permissions the user has.

hook_node_grants_alterAlter user access rules when trying to view, edit or delete a node.

node_accessDetermine whether the current user may perform the given operation on the specified node.

node_access_acquire_grantsGets the list of node access grants and writes them to the database.

node_access_grantsFetch an array of permission IDs granted to the given user ID.

node_access_needs_rebuildFlag / unflag the node access grants for rebuilding, or read the current value of the flag.

node_access_rebuildRebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.

node_access_view_all_nodes Determines whether the user has a global viewing grant for all nodes.

node_access_write_grants Writes a list of grants to the database, deleting any previously saved ones.

node_list_permissions Helper function to generate standard node permission list for a given type.

node_node_access Implements hook_node_access().

node_permissions_get_configured_typesReturns an array of node types that should be managed by permissions.

node_query_entity_field_access_alter Implements hook_query_TAG_alter().node_query_node_access_alter Implements hook_query_TAG_alter()._node_access_rebuild_batch_finished Post-processing for node_access_rebuild_batch._node_access_rebuild_batch_operation Batch operation for node_access_rebuild_batch._node_query_node_access_alter Helper for node access functions.modules/node/node.module, line 2726

Theme SystemFunctions and templates that present output to the user, and can be implemented by themes.

Drupal's presentation layer is a pluggable system known as the theme layer. Each theme can take control over most of Drupal's output, and has complete control over the CSS.

Inside Drupal, the theme layer is utilized by the use of the theme() function, which is passed the name of a component (the theme hook) and an array of variables. For example, theme('table', array('header' => $header, 'rows' => $rows)); Additionally, the theme() function can take an array of theme hooks, which can be used to provide 'fallback' implementations to allow for more specific control of output. For example, the function: theme(array('table__foo', 'table'), $variables) would look to see if 'table__foo' is registered anywhere; if it is not, it would 'fall back' to the generic 'table' implementation. This can be used to attach specific theme functions to named objects, allowing the themer more control over specific types of output.

As of Drupal 6, every theme hook is required to be registered by the module that owns it, so that Drupal can tell what to do with it and to make it simple for themes to identify and override the behavior for these calls.

The theme hooks are registered via hook_theme(), which returns an array of arrays with information about the hook. It describes the arguments the function or template will need, and provides defaults for the template in case they are not filled in. If the default implementation is a function, by convention it is named theme_HOOK().

Each module should provide a default implementation for theme_hooks that it registers. This

Page 31: Drupal 7 API doc

implementation may be either a function or a template; if it is a function it must be specified via hook_theme(). By convention, default implementations of theme hooks are named theme_HOOK. Default template implementations are stored in the module directory.

Drupal's default template renderer is a simple PHP parsing engine that includes the template and stores the output. Drupal's theme engines can provide alternate template engines, such as XTemplate, Smarty and PHPTal. The most common template engine is PHPTemplate (included with Drupal and implemented in phptemplate.engine, which uses Drupal's default template renderer.

In order to create theme-specific implementations of these hooks, themes can implement their own version of theme hooks, either as functions or templates. These implementations will be used instead of the default implementation. If using a pure .theme without an engine, the .theme is required to implement its own version of hook_theme() to tell Drupal what it is implementing; themes utilizing an engine will have their well-named theming functions automatically registered for them. While this can vary based upon the theme engine, the standard set by phptemplate is that theme functions should be named THEMENAME_HOOK. For example, for Drupal's default theme (Bartik) to implement the 'table' hook, the phptemplate.engine would find bartik_table().

The theme system is described and defined in theme.inc.

End of "defgroup themeable".

See alsotheme()

hook_theme()

Functions & methodsName Description

theme_admin_block Returns HTML for an administrative block for display.

theme_admin_block_content Returns HTML for the content of an administrative block.

theme_admin_page Returns HTML for an administrative page.

theme_aggregator_block_itemReturns HTML for an individual feed item for display in the block.

theme_aggregator_categorize_itemsReturns HTML for the aggregator page list form for assigning categories.

theme_aggregator_feed_sourceImplemented using the aggregator-feed-source.tpl.php template.

theme_aggregator_itemImplemented using the aggregator-item.tpl.phptemplate.

theme_aggregator_page_opml Prints the OPML page for a feed.theme_aggregator_page_rss Prints the RSS page for a feed.

theme_aggregator_summary_itemImplemented using the aggregator-summary-item.tpl.php template.

theme_aggregator_summary_itemsImplemented using the aggregator-summary-items.tpl.php template.

theme_aggregator_wrapperImplemented using the aggregator-wrapper.tpl.phptemplate.

theme_authorize_messageReturns HTML for a single log message from theauthorize.php batch operation.

theme_authorize_reportReturns HTML for a report of the results from an operation run via authorize.php.

theme_block Implemented using the block.tpl.php template.theme_block_admin_display_form Implemented using the block-admin-display-

Page 32: Drupal 7 API doc

Name Descriptionform.tpl.php template.

theme_book_admin_table Returns HTML for a book administration form.

theme_book_all_books_blockImplemented using the book-all-books-block.tpl.phptemplate.

theme_book_export_htmlImplemented using the book-export-html.tpl.phptemplate.

theme_book_navigationImplemented using the book-navigation.tpl.phptemplate.

theme_book_node_export_htmlImplemented using the book-node-export-html.tpl.php template.

theme_book_title_linkReturns HTML for a link to a book title when used as a block title.

theme_breadcrumb Returns HTML for a breadcrumb trail.theme_button Returns HTML for a button form element.theme_checkbox Returns HTML for a checkbox form element.

theme_checkboxes Returns HTML for a set of checkbox form elements.

theme_color_scheme_form Returns HTML for a theme's color form.

theme_commentImplemented using the comment.tpl.php template.

theme_comment_blockReturns HTML for a list of recent comments to be displayed in the comment block.

theme_comment_post_forbiddenReturns HTML for a "you can't post comments" notice.

theme_comment_wrapperImplemented using the comment-wrapper.tpl.phptemplate.

theme_confirm_form Returns HTML for a confirmation form.

theme_container Returns HTML for a container for grouped form items.

theme_dashboard Returns HTML for the entire dashboard.

theme_dashboard_adminReturns HTML for the non-customizable part of the dashboard page.

theme_dashboard_disabled_blockReturns HTML for a disabled block, for display in dashboard customization mode.

theme_dashboard_disabled_blocksReturns HTML for a set of disabled blocks, for display in dashboard customization mode.

theme_dashboard_region Returns HTML for a generic dashboard region.theme_date Returns HTML for a date selection form element.theme_dblog_message Returns HTML for a log message.theme_exposed_filters Returns HTML for an exposed filter form.theme_feed_icon Returns HTML for a feed icon.theme_field Returns HTML for a field.

theme_fieldsetReturns HTML for a fieldset form element and its children.

theme_field_multiple_value_form Returns HTML for an individual form element.

theme_field_ui_display_overview_table Implemented using the field_ui-display-overview-table.tpl.php template.

theme_field_ui_field_overview_form Implemented using the field_ui-field-overview-form.tpl.php template.

theme_field_ui_table Returns HTML for Field UI overview tables.theme_file Returns HTML for a file upload form element.theme_file_formatter_table Returns HTML for a file attachments table.

theme_file_iconReturns HTML for an image with an appropriate icon for the given file.

Page 33: Drupal 7 API doc

Name Descriptiontheme_file_link Returns HTML for a link to a file.theme_file_managed_file Returns HTML for a managed file element.

theme_file_upload_helpReturns HTML for help text based on file upload validators.

theme_file_widget Returns HTML for an individual file upload widget.theme_file_widget_multiple Returns HTML for a group of file upload widgets.theme_filter_admin_format_filter_order Returns HTML for a text format's filter order form.

theme_filter_admin_overview Returns HTML for the text format administration overview form.

theme_filter_guidelines Returns HTML for guidelines for a text format.theme_filter_tips Returns HTML for a set of filter tips.

theme_filter_tips_more_info Returns HTML for a link to the more extensive filter tips.

theme_form Returns HTML for a form.theme_form_element Returns HTML for a form element.

theme_form_element_label Returns HTML for a form element label and required marker.

theme_form_required_marker Returns HTML for a marker for required form elements.

theme_forums Implemented using the forums.tpl.php template.theme_forum_form Returns HTML for a forum form.

theme_forum_icon Implemented using the forum-icon.tpl.phptemplate.

theme_forum_list Implemented using the forum-list.tpl.php template.

theme_forum_submitted Implemented using the forum-submitted.tpl.phptemplate.

theme_forum_topic_list Implemented using the forum-topic-list.tpl.phptemplate.

theme_hidden Returns HTML for a hidden form element.theme_html Implemented using the html.tpl.php template.

theme_html_tag Returns HTML for a generic HTML tag with attributes.

theme_image Returns HTML for an image.

theme_image_anchorReturns HTML for a 3x3 grid of checkboxes for image anchors.

theme_image_button Returns HTML for an image button form element.

theme_image_crop_summary Returns HTML for a summary of an image crop effect.

theme_image_formatter Returns HTML for an image field formatter.

theme_image_resize_summaryReturns HTML for a summary of an image resize effect.

theme_image_rotate_summaryReturns HTML for a summary of an image rotate effect.

theme_image_scale_summaryReturns HTML for a summary of an image scale effect.

theme_image_styleReturns HTML for an image using a specific image style.

theme_image_style_effectsReturns HTML for a listing of the effects within a specific image style.

theme_image_style_listReturns HTML for the page containing the list of image styles.

theme_image_style_preview Returns HTML for a preview of an image style.theme_image_widget Returns HTML for an image field widget.

Page 34: Drupal 7 API doc

Name Description

theme_indentationReturns HTML for an indentation div; used for drag and drop tables.

theme_item_list Returns HTML for a list or nested list of items.theme_link Returns HTML for a link.theme_links Returns HTML for a set of links.theme_locale_date_format_form Returns HTML for a locale date format form.theme_locale_languages_configure_form Returns HTML for a language configuration form.theme_locale_languages_overview_form Returns HTML for the language overview form.

theme_maintenance_pageImplemented using the maintenance-page.tpl.phptemplate.

theme_markReturns HTML for a marker for new or updated content.

theme_menu_admin_overviewReturns HTML for a menu title and description for the menu overview page.

theme_menu_link Returns HTML for a menu link and submenu.theme_menu_local_action Returns HTML for a single local action link.theme_menu_local_task Returns HTML for a single local task link.theme_menu_local_tasks Returns renderable local tasks.

theme_menu_overview_formReturns HTML for the menu overview form into a table.

theme_menu_tree Returns HTML for a wrapper for a menu sub-tree.theme_more_help_link Returns HTML for a "more help" link.

theme_more_linkReturns HTML for a "more" link, like those used in blocks.

theme_node Implemented using the node.tpl.php template.

theme_node_add_list Returns HTML for a list of available node types for node creation.

theme_node_admin_overview Returns HTML for a node type description for the content type admin overview page.

theme_node_preview Returns HTML for a node preview for display during node creation and editing.

theme_node_recent_block Returns HTML for a list of recent content.

theme_node_recent_contentReturns HTML for a recent node to be displayed in the recent content block.

theme_node_search_adminReturns HTML for the content ranking part of the search settings admin page.

theme_options_noneReturns HTML for the label for the empty value for options that are not required.

theme_page Implemented using the page.tpl.php template.theme_pager Returns HTML for a query pager.

theme_pager_firstReturns HTML for the "first page" link in a query pager.

theme_pager_lastReturns HTML for the "last page" link in query pager.

theme_pager_linkReturns HTML for a link to a specific query result page.

theme_pager_nextReturns HTML for the "next page" link in a query pager.

theme_pager_previousReturns HTML for the "previous page" link in a query pager.

theme_password Returns HTML for a password form element.theme_poll_bar Implemented using the poll-bar.tpl.php template.

theme_poll_bar__blockImplemented using the poll-bar--block.tpl.phptemplate.

Page 35: Drupal 7 API doc

Name Descriptiontheme_poll_choices Returns HTML for an admin poll form for choices.

theme_poll_results Implemented using the poll-results.tpl.phptemplate.

theme_poll_results__block Implemented using the poll-results--block.tpl.phptemplate.

theme_poll_vote Implemented using the poll-vote.tpl.php template.

theme_profile_admin_overview Returns HTML for the profile field overview form into a drag and drop enabled table.

theme_profile_block Implemented using the profile-block.tpl.phptemplate.

theme_profile_listing Implemented using the profile-listing.tpl.phptemplate.

theme_profile_wrapper Implemented using the profile-wrapper.tpl.phptemplate.

theme_progress_bar Returns HTML for a progress bar.theme_radio Returns HTML for a radio button form element.

theme_radios Returns HTML for a set of radio button form elements.

theme_rdf_metadata Returns HTML for a series of empty spans for exporting RDF metadata in RDFa.

theme_rdf_template_variable_wrapper Returns HTML for a template variable wrapped in an HTML element with the RDF attributes.

theme_region Implemented using the region.tpl.php template.

theme_search_block_formImplemented using the search-block-form.tpl.phptemplate.

theme_search_resultImplemented using the search-result.tpl.phptemplate.

theme_search_resultsImplemented using the search-results.tpl.phptemplate.

theme_select Returns HTML for a select form element.

theme_shortcut_set_customize Returns HTML for a shortcut set customization form.

theme_simpletest_result_summary Returns HTML for the summary status of a simpletest result.

theme_simpletest_test_table Returns HTML for a test list generated bysimpletest_test_form() into a table.

theme_status_messages Returns HTML for status and/or error messages, grouped by type.

theme_status_report Returns HTML for the status report.theme_submit Returns HTML for a submit button form element.

theme_system_admin_index Returns HTML for the output of the dashboard page.

theme_system_compact_link Returns HTML for a link to show or hide inline help descriptions.

theme_system_date_time_settings Returns HTML for the date settings form.theme_system_modules_fieldset Returns HTML for the modules form.

theme_system_modules_incompatible Returns HTML for a message about incompatible modules.

theme_system_modules_uninstall Returns HTML for a table of currently disabled modules.

theme_system_powered_by Returns HTML for the Powered by Drupal text.theme_system_settings_form Returns HTML for a system settings form.theme_system_themes_page Returns HTML for the Appearance page.

Page 36: Drupal 7 API doc

Name Descriptiontheme_table Returns HTML for a table.

theme_tableselect Returns HTML for a table with radio buttons or checkboxes.

theme_tablesort_indicator Returns HTML for a sort icon.

theme_task_listReturns HTML for a list of maintenance tasks to perform.

theme_taxonomy_overview_termsReturns HTML for a terms overview form as a sortable list of terms.

theme_taxonomy_overview_vocabulariesReturns HTML for the vocabulary overview form as a sortable list of vocabularies.

theme_taxonomy_termImplemented using the taxonomy-term.tpl.phptemplate.

theme_textarea Returns HTML for a textarea form element.theme_textfield Returns HTML for a textfield form element.

theme_text_format_wrapperReturns HTML for a text format-enabled form element.

theme_toolbar Implemented using the toolbar.tpl.php template.

theme_trigger_display Returns HTML for the form showing actions assigned to a trigger.

theme_update_last_check Returns HTML for the last time we checked for update data.

theme_update_manager_update_form Returns HTML for the first page in the update manager wizard to select projects.

theme_update_report Returns HTML for the project status report.theme_update_version Returns HTML for the version display of a project.

theme_username Returns HTML for a username, potentially linked to the user's page.

theme_user_admin_permissions Returns HTML for the administer permissions page.

theme_user_admin_roles Returns HTML for the role order and new role form.

theme_user_list Returns HTML for a list of users.

theme_user_permission_descriptionReturns HTML for an individual permission description.

theme_user_pictureImplemented using the user-picture.tpl.phptemplate.

theme_user_profileImplemented using the user-profile.tpl.phptemplate.

theme_user_profile_categoryImplemented using the user-profile-category.tpl.phptemplate.

theme_user_profile_itemImplemented using the user-profile-item.tpl.phptemplate.

theme_user_signature Returns HTML for a user signature.

theme_vertical_tabs Returns HTML for an element's children fieldsets as vertical tabs.

modules/system/theme.api.php, line 4

ConstantsSee http://api.drupal.org/api/drupal/constants/7

Page 37: Drupal 7 API doc

Global variablesName Location Description

$base_path developer/globals.phpThe base path of the Drupal installation.

$base_root developer/globals.phpThe root URL of the host, excluding the path.

$base_theme_info developer/globals.phpAn array of objects that represent the base theme.

$base_url developer/globals.phpThe base URL of the Drupal installation.

$channel developer/globals.phpAn associative array containing title, link, description and other keys.

$conf developer/globals.phpArray of persistent variables stored in 'variable' table.

$cookie_domain developer/globals.phpThe domain to be used for session cookies.

$custom_theme developer/globals.phpName of custom theme to override default theme.

$databases developer/globals.php Array of database connections.

$drupal_test_info modules/simpletest/drupal_web_test_case.php

Global variable that holds information about the tests being run.

$element developer/globals.phpStructured array describing the data to be rendered.

$forum_topic_list_header developer/globals.phpAn array of forum topic header information.

$image developer/globals.phpCurrent image tag used by aggregator parsing.

$installed_profile developer/globals.phpThe name of the profile that has just been installed.

$item developer/globals.php General string or array.

$items developer/globals.php Array of items used by aggregator.

$language developer/globals.phpAn object containing the information for the active interface language.

$language_content developer/globals.phpAn object containing the information for the active content language.

$language_url developer/globals.phpAn object containing the information for the active URL language.

$menu_admin developer/globals.phpBoolean indicating that a menu administrator is running a menu access check.

$multibyte developer/globals.php The current multibyte mode.

$pager_limits developer/globals.phpArray of the number of items per page for each pager.

$pager_page_array developer/globals.phpArray of current page numbers for each pager.

$pager_total developer/globals.phpArray of the total number of pages for each pager.

$pager_total_items developer/globals.phpArray of the total number of items for each pager.

$tag developer/globals.php Active tag name.

$theme developer/globals.php Name of the active theme.

$theme_engine developer/globals.phpThe theme engine related to the active theme.

$theme_info developer/globals.php Active theme object.