Professional Documents
Culture Documents
Drupal 7 Api 2010 11 10
Drupal 7 Api 2010 11 10
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.
Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is
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.
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.
SELECT
Most 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
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;
?>
<?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.
<?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.
<?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.
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%;
?>
<?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.
<?php
INSERT INTO node (nid, title, body) VALUES (1, 'my title', 'my body');
?>
<?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.
Transactions
Drupal 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();
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
Classes
Name Description
Primary front-controller for the
Database
database system.
Generic class for a series of conditions
DatabaseCondition
in a query.
DatabaseConnection Base Database API class.
Exception thrown if an undefined
DatabaseConnectionNotDefinedException
database connection is requested.
DatabaseConnection_mysql
DatabaseConnection_pgsql
Specific SQLite implementation of
DatabaseConnection_sqlite
DatabaseConnection.
Exception thrown if no driver is
DatabaseDriverNotSpecifiedException
specified for a database connection.
Name Description
Default implementation of
DatabaseStatementBase
DatabaseStatementInterface.
Empty implementation of a database
DatabaseStatementEmpty
statement.
An implementation of
DatabaseStatementPrefetch DatabaseStatementInterface that
prefetches all data.
Specific SQLite implementation of
DatabaseStatement_sqlite
DatabaseConnection.
A wrapper class for creating and
DatabaseTransaction
managing database transactions.
Exception thrown when a commit()
DatabaseTransactionCommitFailedException
function fails.
Exception to deny attempts to
DatabaseTransactionExplicitCommitNotAllowedException
explicitly manage transactions.
Exception thrown when a savepoint or
DatabaseTransactionNameNonUniqueException
transaction name occurs twice.
Exception for when popTransaction() is
DatabaseTransactionNoActiveException
called with no active transaction.
General class for an abstracted DELETE
DeleteQuery
operation.
SQLite specific implementation of
DeleteQuery_sqlite
DeleteQuery.
Exception thrown if an insert query
FieldsOverlapException
specifies a field twice.
General class for an abstracted INSERT
InsertQuery
query.
InsertQuery_mysql
InsertQuery_pgsql
SQLite specific implementation of
InsertQuery_sqlite
InsertQuery.
Exception thrown for merge queries
InvalidMergeQueryException
that do not make semantic sense.
General class for an abstracted MERGE
MergeQuery
query operation.
Exception thrown if an insert query
NoFieldsException
doesn't specify insert or default fields.
Query Base class for query builders.
SelectQuery Query builder for SELECT statements.
The base extender class for Select
SelectQueryExtender
queries.
SelectQuery_pgsql
SQLite specific query builder for
SelectQuery_sqlite
SELECT statements.
General class for an abstracted
TruncateQuery
TRUNCATE operation.
TruncateQuery_mysql
SQLite specific implementation of
TruncateQuery_sqlite
TruncateQuery.
General class for an abstracted
UpdateQuery
UPDATE operation.
UpdateQuery_pgsql
SQLite specific implementation of
UpdateQuery_sqlite
UpdateQuery.
Interfaces
Name Description
DatabaseStatementInterface 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.
Constants
Name Description
The name by which to obtain a lock for retrive the next insert
POSTGRESQL_NEXTID_LOCK
id.
includes/database/database.inc, line 13
Menu System
Define 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.
• 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.
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().
Name Description
Generates elements for the $arg array in the help
drupal_help_arg
hook.
menu_build_tree Build a menu tree, translate links, and check access.
Clears the cached cached data for a single named
menu_cache_clear
menu.
Clears all cached menu data. This should be called
menu_cache_clear_all any time broad changes might have been made to
the router items or menu links.
Retrieve contextual links for a system object based
menu_contextual_links
on registered local tasks.
Name Description
menu_delete_links Deletes all links for a menu.
Execute the page callback associated with the
menu_execute_active_handler
current path.
Get the breadcrumb for the current page, as
menu_get_active_breadcrumb
determined by the active trail.
Returns the help associated with the active menu
menu_get_active_help
item.
Get the active menu for the current page -
menu_get_active_menu_names
determines the active trail.
Get the title of the current page, as determined by
menu_get_active_title
the active trail.
Gets the active trail (path to root menu root) of the
menu_get_active_trail
current page.
Returns the ancestors (and relevant placeholders)
menu_get_ancestors
for any given path.
Gets the custom theme for the current page, if there
menu_get_custom_theme
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.
Find the depth of an item's children relative to its
menu_link_children_relative_depth
depth.
menu_link_delete Delete one or several menu links.
Lookup the preferred menu link for a given system
menu_link_get_preferred
path.
Get a menu link by its mlid, access checked and link
menu_link_load
translated for rendering.
Insert, update or delete an uncustomized menu link
menu_link_maintain
related to a module.
menu_link_save Save a menu link.
Return an array containing the names of system-
menu_list_system_menus
defined (default) menus.
menu_load_links Returns an array containing all links for a menu.
Returns the rendered local actions at the current
menu_local_actions
level.
Collects the local tasks (tabs), action links, and the
menu_local_tasks
root path.
Return an array of links to be rendered as the Main
menu_main_menu
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.
(Re)populate the database tables used by various
menu_rebuild
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.
Return an array of links to be rendered as the
menu_secondary_menu
Secondary links.
Set the active path, which determines which page is
menu_set_active_item
loaded.
Set (or get) the active menu for the current page -
menu_set_active_menu_names
determines the active trail.
Name Description
Sets or gets the active trail (path to menu tree root)
menu_set_active_trail
of the current page.
Sets a custom theme for the current page, if there is
menu_set_custom_theme
one.
menu_set_item Replaces the statically cached item for a given path.
Returns the router path, or the path of the parent
menu_tab_root_path
tab of a default local task.
menu_tail_to_arg
menu_tree Renders a menu tree based on the current path.
Get the data structure representing a named menu
menu_tree_all_data
tree.
Check access and perform other dynamic
menu_tree_check_access
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.
Get the data structure representing a named menu
menu_tree_page_data
tree, based on the current page.
The menu system uses serialized arrays stored in
the database for arguments. However, often these
menu_unserialize need to change according to the current path. This
function unserializes such an array and does the
necessary change.
Preprocesses the rendered tree
template_preprocess_menu_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.
Check access to a menu item using the access
_menu_check_access
callback
Helper function to clear the page and block caches
_menu_clear_page_cache
at most twice per page load.
Helper function for menu_link_delete; deletes a
_menu_delete_item
single menu link.
_menu_find_router_path Find the router path which will serve this path.
Localize the router item title using t() or another
_menu_item_localize
callback.
_menu_link_build Builds a link from a router item.
This function translates the path elements in the
map using any to_arg helper function. These
_menu_link_map_translate functions take an argument and return an object.
Seehttp://drupal.org/node/109153 for more
information.
Update the children of a menu link that's being
_menu_link_move_children
moved.
Helper function that sets the p1..p9 values for a
_menu_link_parents_set
menu link being saved.
This function is similar to _menu_translate() but
_menu_link_translate does link-specific preparation such as always calling
to_arg functions
Loads objects into the map as defined in the
_menu_load_objects
$item['load_functions'].
Name Description
Helper function to build menu links for the items in
_menu_navigation_links_rebuild
the menu router.
Helper function to build the router table based on
_menu_router_build
the data from hook_menu.
Helper function to store the menu router if we have
_menu_router_cache
it in memory.
Helper function to save data
_menu_router_save
from menu_router_build() to the router table.
Helper function to update a list of menus with
_menu_set_expanded_menus
expanded items
_menu_site_is_offline Checks whether the site is in maintenance mode.
Handles dynamic path translation and menu access
_menu_translate
control.
Recursive helper function
_menu_tree_check_access
for menu_tree_check_access()
Recursive helper function to build the data
_menu_tree_data
representing a menu tree.
Check and update the has_children status for the
_menu_update_parental_status
parent of a link.
Constants
Name Description
Internal menu status code -- Menu item access is
MENU_ACCESS_DENIED
denied.
Menu type -- A hidden, internal callback, typically
MENU_CALLBACK
used for API calls.
Internal menu flag: Local task should be displayed
MENU_CONTEXT_INLINE
inline.
MENU_CONTEXT_NONE Internal menu flag: Invisible local task.
Internal menu flag: Local task should be displayed
MENU_CONTEXT_PAGE
in page context.
Internal menu flag -- menu item was created by
MENU_CREATED_BY_ADMIN
administrator.
Menu type -- The "default" local task, which is
MENU_DEFAULT_LOCAL_TASK
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.
Internal menu flag -- menu item is the root of the
MENU_IS_ROOT
menu tree.
Internal menu flag -- menu item links back to its
MENU_LINKS_TO_PARENT
parent.
Menu type -- An action specific to the parent,
MENU_LOCAL_ACTION
usually rendered as a link.
Menu type -- A task specific to the parent item,
MENU_LOCAL_TASK
usually rendered as a tab.
The maximum depth of a menu links tree - matches
MENU_MAX_DEPTH
the number of p columns.
The maximum number of path elements for a menu
MENU_MAX_PARTS
callback
Internal menu flag -- menu item can be modified by
MENU_MODIFIED_BY_ADMIN
administrator.
Menu type -- A "normal" menu item that's shown in
MENU_NORMAL_ITEM
menu and breadcrumbs.
Name Description
Internal menu status code -- Menu item was not
MENU_NOT_FOUND
found.
Internal menu status code -- Menu item inaccessible
MENU_SITE_OFFLINE
because site is offline.
Internal menu status code -- Everything is working
MENU_SITE_ONLINE
fine.
Menu type -- A normal menu item, hidden until
MENU_SUGGESTED_ITEM
enabled by an administrator.
Internal menu flag -- menu item is visible in the
MENU_VISIBLE_IN_BREADCRUMB
breadcrumb.
Internal menu flag -- menu item is visible in the
MENU_VISIBLE_IN_TREE
menu tree.
Groups
Name Description
Menu context
Flags for use in the "context" attribute of menu router items.
types
Menu flags Flags for use in the "type" attribute of menu items.
Menu item definitions provide one of these constants, which are shortcuts for
Menu item types
combinations of the above flags.
Menu status codes Status codes for menu callbacks.
Menu tree
Menu tree
parameters
includes/menu.inc, line 9
Form Generation
Functions 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.
<?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.
}
function my_module_example_form_submit($form, &$form_state) {
// Submission logic.
}
?>
<?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.
includes/form.inc, line 23
• 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.
Constants
Name Description
FILE_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.
Flag for dealing with existing files: Appends number until name is
FILE_EXISTS_RENAME
unique.
FILE_EXISTS_REPLACE Flag for dealing with existing files: Replace the existing file.
FILE_MODIFY_PERMISSION Flag used by file_prepare_directory() -- file permissions may be
S changed.
FILE_STATUS_PERMANENT Indicates that the file is permanent and should not be deleted.
includes/file.inc, line 18
Field API
Attach 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.
• 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.
Classes
Name Description
FieldUpdateForbiddenException Exception class thrown by hook_field_update_forbid().
Constants
Name Description
FIELD_BEHAVIOR_CUSTOM TODO
FIELD_BEHAVIOR_DEFAULT TODO
FIELD_BEHAVIOR_NONE TODO
Value for $field['cardinality'] property to indicate it can
FIELD_CARDINALITY_UNLIMITED
hold an unlimited number of values.
Age argument for loading the most recent version of an
FIELD_LOAD_CURRENT
entity's field data with field_attach_load().
Age argument for loading the version of an entity's field
FIELD_LOAD_REVISION
data specified in the entity with field_attach_load().
modules/field/field.module, line 28
Search System
The 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.
Theme System
Functions 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
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 also
theme()
hook_theme()
Constants
See http://api.drupal.org/api/drupal/constants/7
Global variables
Name Location Description
The base path of the Drupal
$base_path developer/globals.php
installation.
The root URL of the host, excluding the
$base_root developer/globals.php
path.
An array of objects that represent the
$base_theme_info developer/globals.php
base theme.
The base URL of the Drupal
$base_url developer/globals.php
installation.
An associative array containing title,
$channel developer/globals.php
link, description and other keys.
Array of persistent variables stored in
$conf developer/globals.php
'variable' table.
The domain to be used for session
$cookie_domain developer/globals.php
cookies.
Name of custom theme to override
$custom_theme developer/globals.php
default theme.
$databases developer/globals.php Array of database connections.
modules/simpletest/drupal_ Global variable that holds information
$drupal_test_info
web_test_case.php about the tests being run.
Structured array describing the data to
$element developer/globals.php
be rendered.
An array of forum topic header
$forum_topic_list_header developer/globals.php
information.
Current image tag used by aggregator
$image developer/globals.php
parsing.
The name of the profile that has just
$installed_profile developer/globals.php
been installed.
$item developer/globals.php General string or array.
$items developer/globals.php Array of items used by aggregator.
An object containing the information
$language developer/globals.php
for the active interface language.
An object containing the information
$language_content developer/globals.php
for the active content language.
An object containing the information
$language_url developer/globals.php
for the active URL language.
Boolean indicating that a menu
$menu_admin developer/globals.php administrator is running a menu access
check.
$multibyte developer/globals.php The current multibyte mode.
Array of the number of items per page
$pager_limits developer/globals.php
for each pager.
Array of current page numbers for each
$pager_page_array developer/globals.php
pager.
Array of the total number of pages for
$pager_total developer/globals.php
each pager.
Array of the total number of items for
$pager_total_items developer/globals.php
each pager.
$tag developer/globals.php Active tag name.
$theme developer/globals.php Name of the active theme.
The theme engine related to the active
$theme_engine developer/globals.php
theme.
$theme_info developer/globals.php Active theme object.
Name Location Description
$theme_key developer/globals.php Name of the active theme.
$theme_path developer/globals.php The path to the active theme.
Timers that have been created
$timers developer/globals.php
bytimer_start().
Allows the update.php script to be run
$update_free_access developer/globals.php
when not logged in as administrator.
An object representing the currently
$user developer/globals.php
logged-in user.
2010-11-10
THE END! ( or is it, the beginning? )