danielebarchiesi@0: 'tokens', danielebarchiesi@0: ); danielebarchiesi@0: $hooks['tokens'] = array( danielebarchiesi@0: 'group' => 'tokens', danielebarchiesi@0: ); danielebarchiesi@0: return $hooks; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter information from hook_hook_info(). danielebarchiesi@0: * danielebarchiesi@0: * @param $hooks danielebarchiesi@0: * Information gathered by module_hook_info() from other modules' danielebarchiesi@0: * implementations of hook_hook_info(). Alter this array directly. danielebarchiesi@0: * See hook_hook_info() for information on what this may contain. danielebarchiesi@0: */ danielebarchiesi@0: function hook_hook_info_alter(&$hooks) { danielebarchiesi@0: // Our module wants to completely override the core tokens, so make danielebarchiesi@0: // sure the core token hooks are not found. danielebarchiesi@0: $hooks['token_info']['group'] = 'mytokens'; danielebarchiesi@0: $hooks['tokens']['group'] = 'mytokens'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform the base system and the Field API about one or more entity types. danielebarchiesi@0: * danielebarchiesi@0: * Inform the system about one or more entity types (i.e., object types that danielebarchiesi@0: * can be loaded via entity_load() and, optionally, to which fields can be danielebarchiesi@0: * attached). danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array whose keys are entity type names and whose values identify danielebarchiesi@0: * properties of those types that the system needs to know about: danielebarchiesi@0: * - label: The human-readable name of the type. danielebarchiesi@0: * - controller class: The name of the class that is used to load the objects. danielebarchiesi@0: * The class has to implement the DrupalEntityControllerInterface interface. danielebarchiesi@0: * Leave blank to use the DrupalDefaultEntityController implementation. danielebarchiesi@0: * - base table: (used by DrupalDefaultEntityController) The name of the danielebarchiesi@0: * entity type's base table. danielebarchiesi@0: * - revision table: The name of the entity type's revision table (if any). danielebarchiesi@0: * - static cache: (used by DrupalDefaultEntityController) FALSE to disable danielebarchiesi@0: * static caching of entities during a page request. Defaults to TRUE. danielebarchiesi@0: * - field cache: (used by Field API loading and saving of field data) FALSE danielebarchiesi@0: * to disable Field API's persistent cache of field data. Only recommended danielebarchiesi@0: * if a higher level persistent cache is available for the entity type. danielebarchiesi@0: * Defaults to TRUE. danielebarchiesi@0: * - load hook: The name of the hook which should be invoked by danielebarchiesi@0: * DrupalDefaultEntityController:attachLoad(), for example 'node_load'. danielebarchiesi@0: * - uri callback: The name of an implementation of danielebarchiesi@0: * callback_entity_info_uri(). danielebarchiesi@0: * - label callback: (optional) The name of an implementation of danielebarchiesi@0: * callback_entity_info_label(), which returns the label of the entity. The danielebarchiesi@0: * entity label is the main string associated with an entity; for example, danielebarchiesi@0: * the title of a node or the subject of a comment. If there is an entity danielebarchiesi@0: * object property that defines the label, then using the 'label' element of danielebarchiesi@0: * the 'entity keys' return value component suffices to provide this danielebarchiesi@0: * information (see below). Alternatively, specifying this callback allows danielebarchiesi@0: * more complex logic to determine the label of an entity. See also the danielebarchiesi@0: * entity_label() function, which implements this logic. danielebarchiesi@0: * - language callback: (optional) The name of an implementation of danielebarchiesi@0: * callback_entity_info_language(). In most situations, when needing to danielebarchiesi@0: * determine this value, inspecting a property named after the 'language' danielebarchiesi@0: * element of the 'entity keys' should be enough. The language callback is danielebarchiesi@0: * meant to be used primarily for temporary alterations of the property danielebarchiesi@0: * value: entity-defining modules are encouraged to always define a danielebarchiesi@0: * language property, instead of using the callback as main entity language danielebarchiesi@0: * source. In fact not having a language property defined is likely to danielebarchiesi@0: * prevent an entity from being queried by language. Moreover, given that danielebarchiesi@0: * entity_language() is not necessarily used everywhere it would be danielebarchiesi@0: * appropriate, modules implementing the language callback should be aware danielebarchiesi@0: * that this might not be always called. danielebarchiesi@0: * - fieldable: Set to TRUE if you want your entity type to accept fields danielebarchiesi@0: * being attached to it. danielebarchiesi@0: * - translation: An associative array of modules registered as field danielebarchiesi@0: * translation handlers. Array keys are the module names, array values danielebarchiesi@0: * can be any data structure the module uses to provide field translation. danielebarchiesi@0: * Any empty value disallows the module to appear as a translation handler. danielebarchiesi@0: * - entity keys: An array describing how the Field API can extract the danielebarchiesi@0: * information it needs from the objects of the type. Elements: danielebarchiesi@0: * - id: The name of the property that contains the primary id of the danielebarchiesi@0: * entity. Every entity object passed to the Field API must have this danielebarchiesi@0: * property and its value must be numeric. danielebarchiesi@0: * - revision: The name of the property that contains the revision id of danielebarchiesi@0: * the entity. The Field API assumes that all revision ids are unique danielebarchiesi@0: * across all entities of a type. This entry can be omitted if the danielebarchiesi@0: * entities of this type are not versionable. danielebarchiesi@0: * - bundle: The name of the property that contains the bundle name for the danielebarchiesi@0: * entity. The bundle name defines which set of fields are attached to danielebarchiesi@0: * the entity (e.g. what nodes call "content type"). This entry can be danielebarchiesi@0: * omitted if this entity type exposes a single bundle (all entities have danielebarchiesi@0: * the same collection of fields). The name of this single bundle will be danielebarchiesi@0: * the same as the entity type. danielebarchiesi@0: * - label: The name of the property that contains the entity label. For danielebarchiesi@0: * example, if the entity's label is located in $entity->subject, then danielebarchiesi@0: * 'subject' should be specified here. If complex logic is required to danielebarchiesi@0: * build the label, a 'label callback' should be defined instead (see danielebarchiesi@0: * the 'label callback' section above for details). danielebarchiesi@0: * - language: The name of the property, typically 'language', that contains danielebarchiesi@0: * the language code representing the language the entity has been created danielebarchiesi@0: * in. This value may be changed when editing the entity and represents danielebarchiesi@0: * the language its textual components are supposed to have. If no danielebarchiesi@0: * language property is available, the 'language callback' may be used danielebarchiesi@0: * instead. This entry can be omitted if the entities of this type are not danielebarchiesi@0: * language-aware. danielebarchiesi@0: * - bundle keys: An array describing how the Field API can extract the danielebarchiesi@0: * information it needs from the bundle objects for this type. This entry danielebarchiesi@0: * is required if the 'path' provided in the 'bundles'/'admin' section danielebarchiesi@0: * identifies the bundle using a named menu placeholder whose loader danielebarchiesi@0: * callback returns an object (e.g., $vocabulary for taxonomy terms, or danielebarchiesi@0: * $node_type for nodes). If the path does not include the bundle, or the danielebarchiesi@0: * bundle is just a string rather than an automatically loaded object, then danielebarchiesi@0: * this can be omitted. Elements: danielebarchiesi@0: * - bundle: The name of the property of the bundle object that contains danielebarchiesi@0: * the name of the bundle object. danielebarchiesi@0: * - bundles: An array describing all bundles for this object type. Keys are danielebarchiesi@0: * bundles machine names, as found in the objects' 'bundle' property danielebarchiesi@0: * (defined in the 'entity keys' entry above). This entry can be omitted if danielebarchiesi@0: * this entity type exposes a single bundle (all entities have the same danielebarchiesi@0: * collection of fields). The name of this single bundle will be the same as danielebarchiesi@0: * the entity type. Elements: danielebarchiesi@0: * - label: The human-readable name of the bundle. danielebarchiesi@0: * - uri callback: Same as the 'uri callback' key documented above for the danielebarchiesi@0: * entity type, but for the bundle only. When determining the URI of an danielebarchiesi@0: * entity, if a 'uri callback' is defined for both the entity type and danielebarchiesi@0: * the bundle, the one for the bundle is used. danielebarchiesi@0: * - admin: An array of information that allows Field UI pages to attach danielebarchiesi@0: * themselves to the existing administration pages for the bundle. danielebarchiesi@0: * Elements: danielebarchiesi@0: * - path: the path of the bundle's main administration page, as defined danielebarchiesi@0: * in hook_menu(). If the path includes a placeholder for the bundle, danielebarchiesi@0: * the 'bundle argument' and 'real path' keys below are required. danielebarchiesi@0: * - bundle argument: The position of the bundle placeholder in 'path', if danielebarchiesi@0: * any. danielebarchiesi@0: * - real path: The actual path (no placeholder) of the bundle's main danielebarchiesi@0: * administration page. This will be used to generate links. danielebarchiesi@0: * - access callback: As in hook_menu(). 'user_access' will be assumed if danielebarchiesi@0: * no value is provided. danielebarchiesi@0: * - access arguments: As in hook_menu(). danielebarchiesi@0: * - view modes: An array describing the view modes for the entity type. View danielebarchiesi@0: * modes let entities be displayed differently depending on the context. danielebarchiesi@0: * For instance, a node can be displayed differently on its own page danielebarchiesi@0: * ('full' mode), on the home page or taxonomy listings ('teaser' mode), or danielebarchiesi@0: * in an RSS feed ('rss' mode). Modules taking part in the display of the danielebarchiesi@0: * entity (notably the Field API) can adjust their behavior depending on danielebarchiesi@0: * the requested view mode. An additional 'default' view mode is available danielebarchiesi@0: * for all entity types. This view mode is not intended for actual entity danielebarchiesi@0: * display, but holds default display settings. For each available view danielebarchiesi@0: * mode, administrators can configure whether it should use its own set of danielebarchiesi@0: * field display settings, or just replicate the settings of the 'default' danielebarchiesi@0: * view mode, thus reducing the amount of display configurations to keep danielebarchiesi@0: * track of. Keys of the array are view mode names. Each view mode is danielebarchiesi@0: * described by an array with the following key/value pairs: danielebarchiesi@0: * - label: The human-readable name of the view mode danielebarchiesi@0: * - custom settings: A boolean specifying whether the view mode should by danielebarchiesi@0: * default use its own custom field display settings. If FALSE, entities danielebarchiesi@0: * displayed in this view mode will reuse the 'default' display settings danielebarchiesi@0: * by default (e.g. right after the module exposing the view mode is danielebarchiesi@0: * enabled), but administrators can later use the Field UI to apply custom danielebarchiesi@0: * display settings specific to the view mode. danielebarchiesi@0: * danielebarchiesi@0: * @see entity_load() danielebarchiesi@0: * @see hook_entity_info_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_info() { danielebarchiesi@0: $return = array( danielebarchiesi@0: 'node' => array( danielebarchiesi@0: 'label' => t('Node'), danielebarchiesi@0: 'controller class' => 'NodeController', danielebarchiesi@0: 'base table' => 'node', danielebarchiesi@0: 'revision table' => 'node_revision', danielebarchiesi@0: 'uri callback' => 'node_uri', danielebarchiesi@0: 'fieldable' => TRUE, danielebarchiesi@0: 'translation' => array( danielebarchiesi@0: 'locale' => TRUE, danielebarchiesi@0: ), danielebarchiesi@0: 'entity keys' => array( danielebarchiesi@0: 'id' => 'nid', danielebarchiesi@0: 'revision' => 'vid', danielebarchiesi@0: 'bundle' => 'type', danielebarchiesi@0: 'language' => 'language', danielebarchiesi@0: ), danielebarchiesi@0: 'bundle keys' => array( danielebarchiesi@0: 'bundle' => 'type', danielebarchiesi@0: ), danielebarchiesi@0: 'bundles' => array(), danielebarchiesi@0: 'view modes' => array( danielebarchiesi@0: 'full' => array( danielebarchiesi@0: 'label' => t('Full content'), danielebarchiesi@0: 'custom settings' => FALSE, danielebarchiesi@0: ), danielebarchiesi@0: 'teaser' => array( danielebarchiesi@0: 'label' => t('Teaser'), danielebarchiesi@0: 'custom settings' => TRUE, danielebarchiesi@0: ), danielebarchiesi@0: 'rss' => array( danielebarchiesi@0: 'label' => t('RSS'), danielebarchiesi@0: 'custom settings' => FALSE, danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Search integration is provided by node.module, so search-related danielebarchiesi@0: // view modes for nodes are defined here and not in search.module. danielebarchiesi@0: if (module_exists('search')) { danielebarchiesi@0: $return['node']['view modes'] += array( danielebarchiesi@0: 'search_index' => array( danielebarchiesi@0: 'label' => t('Search index'), danielebarchiesi@0: 'custom settings' => FALSE, danielebarchiesi@0: ), danielebarchiesi@0: 'search_result' => array( danielebarchiesi@0: 'label' => t('Search result'), danielebarchiesi@0: 'custom settings' => FALSE, danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Bundles must provide a human readable name so we can create help and error danielebarchiesi@0: // messages, and the path to attach Field admin pages to. danielebarchiesi@0: foreach (node_type_get_names() as $type => $name) { danielebarchiesi@0: $return['node']['bundles'][$type] = array( danielebarchiesi@0: 'label' => $name, danielebarchiesi@0: 'admin' => array( danielebarchiesi@0: 'path' => 'admin/structure/types/manage/%node_type', danielebarchiesi@0: 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type), danielebarchiesi@0: 'bundle argument' => 4, danielebarchiesi@0: 'access arguments' => array('administer content types'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $return; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the entity info. danielebarchiesi@0: * danielebarchiesi@0: * Modules may implement this hook to alter the information that defines an danielebarchiesi@0: * entity. All properties that are available in hook_entity_info() can be danielebarchiesi@0: * altered here. danielebarchiesi@0: * danielebarchiesi@0: * @param $entity_info danielebarchiesi@0: * The entity info array, keyed by entity name. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_entity_info() danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_info_alter(&$entity_info) { danielebarchiesi@0: // Set the controller class for nodes to an alternate implementation of the danielebarchiesi@0: // DrupalEntityController interface. danielebarchiesi@0: $entity_info['node']['controller class'] = 'MyCustomNodeController'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on entities when loaded. danielebarchiesi@0: * danielebarchiesi@0: * This is a generic load hook called for all entity types loaded via the danielebarchiesi@0: * entity API. danielebarchiesi@0: * danielebarchiesi@0: * @param $entities danielebarchiesi@0: * The entities keyed by entity ID. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entities being loaded (i.e. node, user, comment). danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_load($entities, $type) { danielebarchiesi@0: foreach ($entities as $entity) { danielebarchiesi@0: $entity->foo = mymodule_add_something($entity, $type); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on an entity before it is about to be created or updated. danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity object. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entity being saved (i.e. node, user, comment). danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_presave($entity, $type) { danielebarchiesi@0: $entity->changed = REQUEST_TIME; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on entities when inserted. danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity object. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entity being inserted (i.e. node, user, comment). danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_insert($entity, $type) { danielebarchiesi@0: // Insert the new entity into a fictional table of all entities. danielebarchiesi@0: $info = entity_get_info($type); danielebarchiesi@0: list($id) = entity_extract_ids($type, $entity); danielebarchiesi@0: db_insert('example_entity') danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'type' => $type, danielebarchiesi@0: 'id' => $id, danielebarchiesi@0: 'created' => REQUEST_TIME, danielebarchiesi@0: 'updated' => REQUEST_TIME, danielebarchiesi@0: )) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on entities when updated. danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity object. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entity being updated (i.e. node, user, comment). danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_update($entity, $type) { danielebarchiesi@0: // Update the entity's entry in a fictional table of all entities. danielebarchiesi@0: $info = entity_get_info($type); danielebarchiesi@0: list($id) = entity_extract_ids($type, $entity); danielebarchiesi@0: db_update('example_entity') danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'updated' => REQUEST_TIME, danielebarchiesi@0: )) danielebarchiesi@0: ->condition('type', $type) danielebarchiesi@0: ->condition('id', $id) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on entities when deleted. danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity object. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entity being deleted (i.e. node, user, comment). danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_delete($entity, $type) { danielebarchiesi@0: // Delete the entity's entry from a fictional table of all entities. danielebarchiesi@0: $info = entity_get_info($type); danielebarchiesi@0: list($id) = entity_extract_ids($type, $entity); danielebarchiesi@0: db_delete('example_entity') danielebarchiesi@0: ->condition('type', $type) danielebarchiesi@0: ->condition('id', $id) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter or execute an EntityFieldQuery. danielebarchiesi@0: * danielebarchiesi@0: * @param EntityFieldQuery $query danielebarchiesi@0: * An EntityFieldQuery. One of the most important properties to be changed is danielebarchiesi@0: * EntityFieldQuery::executeCallback. If this is set to an existing function, danielebarchiesi@0: * this function will get the query as its single argument and its result danielebarchiesi@0: * will be the returned as the result of EntityFieldQuery::execute(). This can danielebarchiesi@0: * be used to change the behavior of EntityFieldQuery entirely. For example, danielebarchiesi@0: * the default implementation can only deal with one field storage engine, but danielebarchiesi@0: * it is possible to write a module that can query across field storage danielebarchiesi@0: * engines. Also, the default implementation presumes entities are stored in danielebarchiesi@0: * SQL, but the execute callback could instead query any other entity storage, danielebarchiesi@0: * local or remote. danielebarchiesi@0: * danielebarchiesi@0: * Note the $query->altered attribute which is TRUE in case the query has danielebarchiesi@0: * already been altered once. This happens with cloned queries. danielebarchiesi@0: * If there is a pager, then such a cloned query will be executed to count danielebarchiesi@0: * all elements. This query can be detected by checking for danielebarchiesi@0: * ($query->pager && $query->count), allowing the driver to return 0 from danielebarchiesi@0: * the count query and disable the pager. danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_query_alter($query) { danielebarchiesi@0: $query->executeCallback = 'my_module_query_callback'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on entities being assembled before rendering. danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity object. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entity being rendered (i.e. node, user, comment). danielebarchiesi@0: * @param $view_mode danielebarchiesi@0: * The view mode the entity is rendered in. danielebarchiesi@0: * @param $langcode danielebarchiesi@0: * The language code used for rendering. danielebarchiesi@0: * danielebarchiesi@0: * The module may add elements to $entity->content prior to rendering. The danielebarchiesi@0: * structure of $entity->content is a renderable array as expected by danielebarchiesi@0: * drupal_render(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_entity_view_alter() danielebarchiesi@0: * @see hook_comment_view() danielebarchiesi@0: * @see hook_node_view() danielebarchiesi@0: * @see hook_user_view() danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_view($entity, $type, $view_mode, $langcode) { danielebarchiesi@0: $entity->content['my_additional_field'] = array( danielebarchiesi@0: '#markup' => $additional_field, danielebarchiesi@0: '#weight' => 10, danielebarchiesi@0: '#theme' => 'mymodule_my_additional_field', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the results of ENTITY_view(). danielebarchiesi@0: * danielebarchiesi@0: * This hook is called after the content has been assembled in a structured danielebarchiesi@0: * array and may be used for doing processing which requires that the complete danielebarchiesi@0: * entity content structure has been built. danielebarchiesi@0: * danielebarchiesi@0: * If a module wishes to act on the rendered HTML of the entity rather than the danielebarchiesi@0: * structured content array, it may use this hook to add a #post_render danielebarchiesi@0: * callback. Alternatively, it could also implement hook_preprocess_ENTITY(). danielebarchiesi@0: * See drupal_render() and theme() for details. danielebarchiesi@0: * danielebarchiesi@0: * @param $build danielebarchiesi@0: * A renderable array representing the entity content. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entity being rendered (i.e. node, user, comment). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_entity_view() danielebarchiesi@0: * @see hook_comment_view_alter() danielebarchiesi@0: * @see hook_node_view_alter() danielebarchiesi@0: * @see hook_taxonomy_term_view_alter() danielebarchiesi@0: * @see hook_user_view_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_view_alter(&$build, $type) { danielebarchiesi@0: if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { danielebarchiesi@0: // Change its weight. danielebarchiesi@0: $build['an_additional_field']['#weight'] = -10; danielebarchiesi@0: danielebarchiesi@0: // Add a #post_render callback to act on the rendered HTML of the entity. danielebarchiesi@0: $build['#post_render'][] = 'my_module_node_post_render'; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Change the view mode of an entity that is being displayed. danielebarchiesi@0: * danielebarchiesi@0: * @param string $view_mode danielebarchiesi@0: * The view_mode that is to be used to display the entity. danielebarchiesi@0: * @param array $context danielebarchiesi@0: * Array with contextual information, including: danielebarchiesi@0: * - entity_type: The type of the entity that is being viewed. danielebarchiesi@0: * - entity: The entity object. danielebarchiesi@0: * - langcode: The langcode the entity is being viewed in. danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_view_mode_alter(&$view_mode, $context) { danielebarchiesi@0: // For nodes, change the view mode when it is teaser. danielebarchiesi@0: if ($context['entity_type'] == 'node' && $view_mode == 'teaser') { danielebarchiesi@0: $view_mode = 'my_custom_view_mode'; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Define administrative paths. danielebarchiesi@0: * danielebarchiesi@0: * Modules may specify whether or not the paths they define in hook_menu() are danielebarchiesi@0: * to be considered administrative. Other modules may use this information to danielebarchiesi@0: * display those pages differently (e.g. in a modal overlay, or in a different danielebarchiesi@0: * theme). danielebarchiesi@0: * danielebarchiesi@0: * To change the administrative status of menu items defined in another module's danielebarchiesi@0: * hook_menu(), modules should implement hook_admin_paths_alter(). danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array. For each item, the key is the path in question, in danielebarchiesi@0: * a format acceptable to drupal_match_path(). The value for each item should danielebarchiesi@0: * be TRUE (for paths considered administrative) or FALSE (for non- danielebarchiesi@0: * administrative paths). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_menu() danielebarchiesi@0: * @see drupal_match_path() danielebarchiesi@0: * @see hook_admin_paths_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_admin_paths() { danielebarchiesi@0: $paths = array( danielebarchiesi@0: 'mymodule/*/add' => TRUE, danielebarchiesi@0: 'mymodule/*/edit' => TRUE, danielebarchiesi@0: ); danielebarchiesi@0: return $paths; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Redefine administrative paths defined by other modules. danielebarchiesi@0: * danielebarchiesi@0: * @param $paths danielebarchiesi@0: * An associative array of administrative paths, as defined by implementations danielebarchiesi@0: * of hook_admin_paths(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_admin_paths() danielebarchiesi@0: */ danielebarchiesi@0: function hook_admin_paths_alter(&$paths) { danielebarchiesi@0: // Treat all user pages as administrative. danielebarchiesi@0: $paths['user'] = TRUE; danielebarchiesi@0: $paths['user/*'] = TRUE; danielebarchiesi@0: // Treat the forum topic node form as a non-administrative page. danielebarchiesi@0: $paths['node/add/forum'] = FALSE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on entities as they are being prepared for view. danielebarchiesi@0: * danielebarchiesi@0: * Allows you to operate on multiple entities as they are being prepared for danielebarchiesi@0: * view. Only use this if attaching the data during the entity_load() phase danielebarchiesi@0: * is not appropriate, for example when attaching other 'entity' style objects. danielebarchiesi@0: * danielebarchiesi@0: * @param $entities danielebarchiesi@0: * The entities keyed by entity ID. danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of entities being loaded (i.e. node, user, comment). danielebarchiesi@0: * @param $langcode danielebarchiesi@0: * The language to display the entity in. danielebarchiesi@0: */ danielebarchiesi@0: function hook_entity_prepare_view($entities, $type, $langcode) { danielebarchiesi@0: // Load a specific node into the user object for later theming. danielebarchiesi@0: if ($type == 'user') { danielebarchiesi@0: $nodes = mymodule_get_user_nodes(array_keys($entities)); danielebarchiesi@0: foreach ($entities as $uid => $entity) { danielebarchiesi@0: $entity->user_node = $nodes[$uid]; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform periodic actions. danielebarchiesi@0: * danielebarchiesi@0: * Modules that require some commands to be executed periodically can danielebarchiesi@0: * implement hook_cron(). The engine will then call the hook whenever a cron danielebarchiesi@0: * run happens, as defined by the administrator. Typical tasks managed by danielebarchiesi@0: * hook_cron() are database maintenance, backups, recalculation of settings danielebarchiesi@0: * or parameters, automated mailing, and retrieving remote data. danielebarchiesi@0: * danielebarchiesi@0: * Short-running or non-resource-intensive tasks can be executed directly in danielebarchiesi@0: * the hook_cron() implementation. danielebarchiesi@0: * danielebarchiesi@0: * Long-running tasks and tasks that could time out, such as retrieving remote danielebarchiesi@0: * data, sending email, and intensive file tasks, should use the queue API danielebarchiesi@0: * instead of executing the tasks directly. To do this, first define one or danielebarchiesi@0: * more queues via hook_cron_queue_info(). Then, add items that need to be danielebarchiesi@0: * processed to the defined queues. danielebarchiesi@0: */ danielebarchiesi@0: function hook_cron() { danielebarchiesi@0: // Short-running operation example, not using a queue: danielebarchiesi@0: // Delete all expired records since the last cron run. danielebarchiesi@0: $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME); danielebarchiesi@0: db_delete('mymodule_table') danielebarchiesi@0: ->condition('expires', $expires, '>=') danielebarchiesi@0: ->execute(); danielebarchiesi@0: variable_set('mymodule_cron_last_run', REQUEST_TIME); danielebarchiesi@0: danielebarchiesi@0: // Long-running operation example, leveraging a queue: danielebarchiesi@0: // Fetch feeds from other sites. danielebarchiesi@0: $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array( danielebarchiesi@0: ':time' => REQUEST_TIME, danielebarchiesi@0: ':never' => AGGREGATOR_CLEAR_NEVER, danielebarchiesi@0: )); danielebarchiesi@0: $queue = DrupalQueue::get('aggregator_feeds'); danielebarchiesi@0: foreach ($result as $feed) { danielebarchiesi@0: $queue->createItem($feed); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Declare queues holding items that need to be run periodically. danielebarchiesi@0: * danielebarchiesi@0: * While there can be only one hook_cron() process running at the same time, danielebarchiesi@0: * there can be any number of processes defined here running. Because of danielebarchiesi@0: * this, long running tasks are much better suited for this API. Items queued danielebarchiesi@0: * in hook_cron() might be processed in the same cron run if there are not many danielebarchiesi@0: * items in the queue, otherwise it might take several requests, which can be danielebarchiesi@0: * run in parallel. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array where the key is the queue name and the value is danielebarchiesi@0: * again an associative array. Possible keys are: danielebarchiesi@0: * - 'worker callback': The name of the function to call. It will be called danielebarchiesi@0: * with one argument, the item created via DrupalQueue::createItem() in danielebarchiesi@0: * hook_cron(). danielebarchiesi@0: * - 'time': (optional) How much time Drupal should spend on calling this danielebarchiesi@0: * worker in seconds. Defaults to 15. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_cron() danielebarchiesi@0: * @see hook_cron_queue_info_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_cron_queue_info() { danielebarchiesi@0: $queues['aggregator_feeds'] = array( danielebarchiesi@0: 'worker callback' => 'aggregator_refresh', danielebarchiesi@0: 'time' => 60, danielebarchiesi@0: ); danielebarchiesi@0: return $queues; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter cron queue information before cron runs. danielebarchiesi@0: * danielebarchiesi@0: * Called by drupal_cron_run() to allow modules to alter cron queue settings danielebarchiesi@0: * before any jobs are processesed. danielebarchiesi@0: * danielebarchiesi@0: * @param array $queues danielebarchiesi@0: * An array of cron queue information. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_cron_queue_info() danielebarchiesi@0: * @see drupal_cron_run() danielebarchiesi@0: */ danielebarchiesi@0: function hook_cron_queue_info_alter(&$queues) { danielebarchiesi@0: // This site has many feeds so let's spend 90 seconds on each cron run danielebarchiesi@0: // updating feeds instead of the default 60. danielebarchiesi@0: $queues['aggregator_feeds']['time'] = 90; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Allows modules to declare their own Form API element types and specify their danielebarchiesi@0: * default values. danielebarchiesi@0: * danielebarchiesi@0: * This hook allows modules to declare their own form element types and to danielebarchiesi@0: * specify their default values. The values returned by this hook will be danielebarchiesi@0: * merged with the elements returned by hook_form() implementations and so danielebarchiesi@0: * can return defaults for any Form APIs keys in addition to those explicitly danielebarchiesi@0: * mentioned below. danielebarchiesi@0: * danielebarchiesi@0: * Each of the form element types defined by this hook is assumed to have danielebarchiesi@0: * a matching theme function, e.g. theme_elementtype(), which should be danielebarchiesi@0: * registered with hook_theme() as normal. danielebarchiesi@0: * danielebarchiesi@0: * For more information about custom element types see the explanation at danielebarchiesi@0: * http://drupal.org/node/169815. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array describing the element types being defined. The array danielebarchiesi@0: * contains a sub-array for each element type, with the machine-readable type danielebarchiesi@0: * name as the key. Each sub-array has a number of possible attributes: danielebarchiesi@0: * - "#input": boolean indicating whether or not this element carries a value danielebarchiesi@0: * (even if it's hidden). danielebarchiesi@0: * - "#process": array of callback functions taking $element, $form_state, danielebarchiesi@0: * and $complete_form. danielebarchiesi@0: * - "#after_build": array of callback functions taking $element and $form_state. danielebarchiesi@0: * - "#validate": array of callback functions taking $form and $form_state. danielebarchiesi@0: * - "#element_validate": array of callback functions taking $element and danielebarchiesi@0: * $form_state. danielebarchiesi@0: * - "#pre_render": array of callback functions taking $element and $form_state. danielebarchiesi@0: * - "#post_render": array of callback functions taking $element and $form_state. danielebarchiesi@0: * - "#submit": array of callback functions taking $form and $form_state. danielebarchiesi@0: * - "#title_display": optional string indicating if and how #title should be danielebarchiesi@0: * displayed, see theme_form_element() and theme_form_element_label(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_element_info_alter() danielebarchiesi@0: * @see system_element_info() danielebarchiesi@0: */ danielebarchiesi@0: function hook_element_info() { danielebarchiesi@0: $types['filter_format'] = array( danielebarchiesi@0: '#input' => TRUE, danielebarchiesi@0: ); danielebarchiesi@0: return $types; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the element type information returned from modules. danielebarchiesi@0: * danielebarchiesi@0: * A module may implement this hook in order to alter the element type defaults danielebarchiesi@0: * defined by a module. danielebarchiesi@0: * danielebarchiesi@0: * @param $type danielebarchiesi@0: * All element type defaults as collected by hook_element_info(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_element_info() danielebarchiesi@0: */ danielebarchiesi@0: function hook_element_info_alter(&$type) { danielebarchiesi@0: // Decrease the default size of textfields. danielebarchiesi@0: if (isset($type['textfield']['#size'])) { danielebarchiesi@0: $type['textfield']['#size'] = 40; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform cleanup tasks. danielebarchiesi@0: * danielebarchiesi@0: * This hook is run at the end of most regular page requests. It is often danielebarchiesi@0: * used for page logging and specialized cleanup. This hook MUST NOT print danielebarchiesi@0: * anything because by the time it runs the response is already sent to danielebarchiesi@0: * the browser. danielebarchiesi@0: * danielebarchiesi@0: * Only use this hook if your code must run even for cached page views. danielebarchiesi@0: * If you have code which must run once on all non-cached pages, use danielebarchiesi@0: * hook_init() instead. That is the usual case. If you implement this hook danielebarchiesi@0: * and see an error like 'Call to undefined function', it is likely that danielebarchiesi@0: * you are depending on the presence of a module which has not been loaded yet. danielebarchiesi@0: * It is not loaded because Drupal is still in bootstrap mode. danielebarchiesi@0: * danielebarchiesi@0: * @param $destination danielebarchiesi@0: * If this hook is invoked as part of a drupal_goto() call, then this argument danielebarchiesi@0: * will be a fully-qualified URL that is the destination of the redirect. danielebarchiesi@0: */ danielebarchiesi@0: function hook_exit($destination = NULL) { danielebarchiesi@0: db_update('counter') danielebarchiesi@0: ->expression('hits', 'hits + 1') danielebarchiesi@0: ->condition('type', 1) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary alterations to the JavaScript before it is presented on danielebarchiesi@0: * the page. danielebarchiesi@0: * danielebarchiesi@0: * @param $javascript danielebarchiesi@0: * An array of all JavaScript being presented on the page. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_add_js() danielebarchiesi@0: * @see drupal_get_js() danielebarchiesi@0: * @see drupal_js_defaults() danielebarchiesi@0: */ danielebarchiesi@0: function hook_js_alter(&$javascript) { danielebarchiesi@0: // Swap out jQuery to use an updated version of the library. danielebarchiesi@0: $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Registers JavaScript/CSS libraries associated with a module. danielebarchiesi@0: * danielebarchiesi@0: * Modules implementing this return an array of arrays. The key to each danielebarchiesi@0: * sub-array is the machine readable name of the library. Each library may danielebarchiesi@0: * contain the following items: danielebarchiesi@0: * danielebarchiesi@0: * - 'title': The human readable name of the library. danielebarchiesi@0: * - 'website': The URL of the library's web site. danielebarchiesi@0: * - 'version': A string specifying the version of the library; intentionally danielebarchiesi@0: * not a float because a version like "1.2.3" is not a valid float. Use PHP's danielebarchiesi@0: * version_compare() to compare different versions. danielebarchiesi@0: * - 'js': An array of JavaScript elements; each element's key is used as $data danielebarchiesi@0: * argument, each element's value is used as $options array for danielebarchiesi@0: * drupal_add_js(). To add library-specific (not module-specific) JavaScript danielebarchiesi@0: * settings, the key may be skipped, the value must specify danielebarchiesi@0: * 'type' => 'setting', and the actual settings must be contained in a 'data' danielebarchiesi@0: * element of the value. danielebarchiesi@0: * - 'css': Like 'js', an array of CSS elements passed to drupal_add_css(). danielebarchiesi@0: * - 'dependencies': An array of libraries that are required for a library. Each danielebarchiesi@0: * element is an array listing the module and name of another library. Note danielebarchiesi@0: * that all dependencies for each dependent library will also be added when danielebarchiesi@0: * this library is added. danielebarchiesi@0: * danielebarchiesi@0: * Registered information for a library should contain re-usable data only. danielebarchiesi@0: * Module- or implementation-specific data and integration logic should be added danielebarchiesi@0: * separately. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array defining libraries associated with a module. danielebarchiesi@0: * danielebarchiesi@0: * @see system_library() danielebarchiesi@0: * @see drupal_add_library() danielebarchiesi@0: * @see drupal_get_library() danielebarchiesi@0: */ danielebarchiesi@0: function hook_library() { danielebarchiesi@0: // Library One. danielebarchiesi@0: $libraries['library-1'] = array( danielebarchiesi@0: 'title' => 'Library One', danielebarchiesi@0: 'website' => 'http://example.com/library-1', danielebarchiesi@0: 'version' => '1.2', danielebarchiesi@0: 'js' => array( danielebarchiesi@0: drupal_get_path('module', 'my_module') . '/library-1.js' => array(), danielebarchiesi@0: ), danielebarchiesi@0: 'css' => array( danielebarchiesi@0: drupal_get_path('module', 'my_module') . '/library-2.css' => array( danielebarchiesi@0: 'type' => 'file', danielebarchiesi@0: 'media' => 'screen', danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: // Library Two. danielebarchiesi@0: $libraries['library-2'] = array( danielebarchiesi@0: 'title' => 'Library Two', danielebarchiesi@0: 'website' => 'http://example.com/library-2', danielebarchiesi@0: 'version' => '3.1-beta1', danielebarchiesi@0: 'js' => array( danielebarchiesi@0: // JavaScript settings may use the 'data' key. danielebarchiesi@0: array( danielebarchiesi@0: 'type' => 'setting', danielebarchiesi@0: 'data' => array('library2' => TRUE), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: 'dependencies' => array( danielebarchiesi@0: // Require jQuery UI core by System module. danielebarchiesi@0: array('system', 'ui'), danielebarchiesi@0: // Require our other library. danielebarchiesi@0: array('my_module', 'library-1'), danielebarchiesi@0: // Require another library. danielebarchiesi@0: array('other_module', 'library-3'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: return $libraries; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters the JavaScript/CSS library registry. danielebarchiesi@0: * danielebarchiesi@0: * Allows certain, contributed modules to update libraries to newer versions danielebarchiesi@0: * while ensuring backwards compatibility. In general, such manipulations should danielebarchiesi@0: * only be done by designated modules, since most modules that integrate with a danielebarchiesi@0: * certain library also depend on the API of a certain library version. danielebarchiesi@0: * danielebarchiesi@0: * @param $libraries danielebarchiesi@0: * The JavaScript/CSS libraries provided by $module. Keyed by internal library danielebarchiesi@0: * name and passed by reference. danielebarchiesi@0: * @param $module danielebarchiesi@0: * The name of the module that registered the libraries. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_library() danielebarchiesi@0: */ danielebarchiesi@0: function hook_library_alter(&$libraries, $module) { danielebarchiesi@0: // Update Farbtastic to version 2.0. danielebarchiesi@0: if ($module == 'system' && isset($libraries['farbtastic'])) { danielebarchiesi@0: // Verify existing version is older than the one we are updating to. danielebarchiesi@0: if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) { danielebarchiesi@0: // Update the existing Farbtastic to version 2.0. danielebarchiesi@0: $libraries['farbtastic']['version'] = '2.0'; danielebarchiesi@0: $libraries['farbtastic']['js'] = array( danielebarchiesi@0: drupal_get_path('module', 'farbtastic_update') . '/farbtastic-2.0.js' => array(), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter CSS files before they are output on the page. danielebarchiesi@0: * danielebarchiesi@0: * @param $css danielebarchiesi@0: * An array of all CSS items (files and inline CSS) being requested on the page. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_add_css() danielebarchiesi@0: * @see drupal_get_css() danielebarchiesi@0: */ danielebarchiesi@0: function hook_css_alter(&$css) { danielebarchiesi@0: // Remove defaults.css file. danielebarchiesi@0: unset($css[drupal_get_path('module', 'system') . '/defaults.css']); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the commands that are sent to the user through the Ajax framework. danielebarchiesi@0: * danielebarchiesi@0: * @param $commands danielebarchiesi@0: * An array of all commands that will be sent to the user. danielebarchiesi@0: * danielebarchiesi@0: * @see ajax_render() danielebarchiesi@0: */ danielebarchiesi@0: function hook_ajax_render_alter($commands) { danielebarchiesi@0: // Inject any new status messages into the content area. danielebarchiesi@0: $commands[] = ajax_command_prepend('#block-system-main .content', theme('status_messages')); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Add elements to a page before it is rendered. danielebarchiesi@0: * danielebarchiesi@0: * Use this hook when you want to add elements at the page level. For your danielebarchiesi@0: * additions to be printed, they have to be placed below a top level array key danielebarchiesi@0: * of the $page array that has the name of a region of the active theme. danielebarchiesi@0: * danielebarchiesi@0: * By default, valid region keys are 'page_top', 'header', 'sidebar_first', danielebarchiesi@0: * 'content', 'sidebar_second' and 'page_bottom'. To get a list of all regions danielebarchiesi@0: * of the active theme, use system_region_list($theme). Note that $theme is a danielebarchiesi@0: * global variable. danielebarchiesi@0: * danielebarchiesi@0: * If you want to alter the elements added by other modules or if your module danielebarchiesi@0: * depends on the elements of other modules, use hook_page_alter() instead which danielebarchiesi@0: * runs after this hook. danielebarchiesi@0: * danielebarchiesi@0: * @param $page danielebarchiesi@0: * Nested array of renderable elements that make up the page. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_page_alter() danielebarchiesi@0: * @see drupal_render_page() danielebarchiesi@0: */ danielebarchiesi@0: function hook_page_build(&$page) { danielebarchiesi@0: if (menu_get_object('node', 1)) { danielebarchiesi@0: // We are on a node detail page. Append a standard disclaimer to the danielebarchiesi@0: // content region. danielebarchiesi@0: $page['content']['disclaimer'] = array( danielebarchiesi@0: '#markup' => t('Acme, Inc. is not responsible for the contents of this sample code.'), danielebarchiesi@0: '#weight' => 25, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter a menu router item right after it has been retrieved from the database or cache. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked by menu_get_item() and allows for run-time alteration of router danielebarchiesi@0: * information (page_callback, title, and so on) before it is translated and checked for danielebarchiesi@0: * access. The passed-in $router_item is statically cached for the current request, so this danielebarchiesi@0: * hook is only invoked once for any router item that is retrieved via menu_get_item(). danielebarchiesi@0: * danielebarchiesi@0: * Usually, modules will only want to inspect the router item and conditionally danielebarchiesi@0: * perform other actions (such as preparing a state for the current request). danielebarchiesi@0: * Note that this hook is invoked for any router item that is retrieved by danielebarchiesi@0: * menu_get_item(), which may or may not be called on the path itself, so implementations danielebarchiesi@0: * should check the $path parameter if the alteration should fire for the current request danielebarchiesi@0: * only. danielebarchiesi@0: * danielebarchiesi@0: * @param $router_item danielebarchiesi@0: * The menu router item for $path. danielebarchiesi@0: * @param $path danielebarchiesi@0: * The originally passed path, for which $router_item is responsible. danielebarchiesi@0: * @param $original_map danielebarchiesi@0: * The path argument map, as contained in $path. danielebarchiesi@0: * danielebarchiesi@0: * @see menu_get_item() danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_get_item_alter(&$router_item, $path, $original_map) { danielebarchiesi@0: // When retrieving the router item for the current path... danielebarchiesi@0: if ($path == $_GET['q']) { danielebarchiesi@0: // ...call a function that prepares something for this request. danielebarchiesi@0: mymodule_prepare_something(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Define menu items and page callbacks. danielebarchiesi@0: * danielebarchiesi@0: * This hook enables modules to register paths in order to define how URL danielebarchiesi@0: * requests are handled. Paths may be registered for URL handling only, or they danielebarchiesi@0: * can register a link to be placed in a menu (usually the Navigation menu). A danielebarchiesi@0: * path and its associated information is commonly called a "menu router item". danielebarchiesi@0: * This hook is rarely called (for example, when modules are enabled), and danielebarchiesi@0: * its results are cached in the database. danielebarchiesi@0: * danielebarchiesi@0: * hook_menu() implementations return an associative array whose keys define danielebarchiesi@0: * paths and whose values are an associative array of properties for each danielebarchiesi@0: * path. (The complete list of properties is in the return value section below.) danielebarchiesi@0: * danielebarchiesi@0: * @section sec_callback_funcs Callback Functions danielebarchiesi@0: * The definition for each path may include a page callback function, which is danielebarchiesi@0: * invoked when the registered path is requested. If there is no other danielebarchiesi@0: * registered path that fits the requested path better, any further path danielebarchiesi@0: * components are passed to the callback function. For example, your module danielebarchiesi@0: * could register path 'abc/def': danielebarchiesi@0: * @code danielebarchiesi@0: * function mymodule_menu() { danielebarchiesi@0: * $items['abc/def'] = array( danielebarchiesi@0: * 'page callback' => 'mymodule_abc_view', danielebarchiesi@0: * ); danielebarchiesi@0: * return $items; danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function mymodule_abc_view($ghi = 0, $jkl = '') { danielebarchiesi@0: * // ... danielebarchiesi@0: * } danielebarchiesi@0: * @endcode danielebarchiesi@0: * When path 'abc/def' is requested, no further path components are in the danielebarchiesi@0: * request, and no additional arguments are passed to the callback function (so danielebarchiesi@0: * $ghi and $jkl would take the default values as defined in the function danielebarchiesi@0: * signature). When 'abc/def/123/foo' is requested, $ghi will be '123' and danielebarchiesi@0: * $jkl will be 'foo'. Note that this automatic passing of optional path danielebarchiesi@0: * arguments applies only to page and theme callback functions. danielebarchiesi@0: * danielebarchiesi@0: * @subsection sub_callback_arguments Callback Arguments danielebarchiesi@0: * In addition to optional path arguments, the page callback and other callback danielebarchiesi@0: * functions may specify argument lists as arrays. These argument lists may danielebarchiesi@0: * contain both fixed/hard-coded argument values and integers that correspond danielebarchiesi@0: * to path components. When integers are used and the callback function is danielebarchiesi@0: * called, the corresponding path components will be substituted for the danielebarchiesi@0: * integers. That is, the integer 0 in an argument list will be replaced with danielebarchiesi@0: * the first path component, integer 1 with the second, and so on (path danielebarchiesi@0: * components are numbered starting from zero). To pass an integer without it danielebarchiesi@0: * being replaced with its respective path component, use the string value of danielebarchiesi@0: * the integer (e.g., '1') as the argument value. This substitution feature danielebarchiesi@0: * allows you to re-use a callback function for several different paths. For danielebarchiesi@0: * example: danielebarchiesi@0: * @code danielebarchiesi@0: * function mymodule_menu() { danielebarchiesi@0: * $items['abc/def'] = array( danielebarchiesi@0: * 'page callback' => 'mymodule_abc_view', danielebarchiesi@0: * 'page arguments' => array(1, 'foo'), danielebarchiesi@0: * ); danielebarchiesi@0: * return $items; danielebarchiesi@0: * } danielebarchiesi@0: * @endcode danielebarchiesi@0: * When path 'abc/def' is requested, the page callback function will get 'def' danielebarchiesi@0: * as the first argument and (always) 'foo' as the second argument. danielebarchiesi@0: * danielebarchiesi@0: * If a page callback function uses an argument list array, and its path is danielebarchiesi@0: * requested with optional path arguments, then the list array's arguments are danielebarchiesi@0: * passed to the callback function first, followed by the optional path danielebarchiesi@0: * arguments. Using the above example, when path 'abc/def/bar/baz' is requested, danielebarchiesi@0: * mymodule_abc_view() will be called with 'def', 'foo', 'bar' and 'baz' as danielebarchiesi@0: * arguments, in that order. danielebarchiesi@0: * danielebarchiesi@0: * Special care should be taken for the page callback drupal_get_form(), because danielebarchiesi@0: * your specific form callback function will always receive $form and danielebarchiesi@0: * &$form_state as the first function arguments: danielebarchiesi@0: * @code danielebarchiesi@0: * function mymodule_abc_form($form, &$form_state) { danielebarchiesi@0: * // ... danielebarchiesi@0: * return $form; danielebarchiesi@0: * } danielebarchiesi@0: * @endcode danielebarchiesi@0: * See @link form_api Form API documentation @endlink for details. danielebarchiesi@0: * danielebarchiesi@0: * @section sec_path_wildcards Wildcards in Paths danielebarchiesi@0: * @subsection sub_simple_wildcards Simple Wildcards danielebarchiesi@0: * Wildcards within paths also work with integer substitution. For example, danielebarchiesi@0: * your module could register path 'my-module/%/edit': danielebarchiesi@0: * @code danielebarchiesi@0: * $items['my-module/%/edit'] = array( danielebarchiesi@0: * 'page callback' => 'mymodule_abc_edit', danielebarchiesi@0: * 'page arguments' => array(1), danielebarchiesi@0: * ); danielebarchiesi@0: * @endcode danielebarchiesi@0: * When path 'my-module/foo/edit' is requested, integer 1 will be replaced danielebarchiesi@0: * with 'foo' and passed to the callback function. Note that wildcards may not danielebarchiesi@0: * be used as the first component. danielebarchiesi@0: * danielebarchiesi@0: * @subsection sub_autoload_wildcards Auto-Loader Wildcards danielebarchiesi@0: * Registered paths may also contain special "auto-loader" wildcard components danielebarchiesi@0: * in the form of '%mymodule_abc', where the '%' part means that this path danielebarchiesi@0: * component is a wildcard, and the 'mymodule_abc' part defines the prefix for a danielebarchiesi@0: * load function, which here would be named mymodule_abc_load(). When a matching danielebarchiesi@0: * path is requested, your load function will receive as its first argument the danielebarchiesi@0: * path component in the position of the wildcard; load functions may also be danielebarchiesi@0: * passed additional arguments (see "load arguments" in the return value danielebarchiesi@0: * section below). For example, your module could register path danielebarchiesi@0: * 'my-module/%mymodule_abc/edit': danielebarchiesi@0: * @code danielebarchiesi@0: * $items['my-module/%mymodule_abc/edit'] = array( danielebarchiesi@0: * 'page callback' => 'mymodule_abc_edit', danielebarchiesi@0: * 'page arguments' => array(1), danielebarchiesi@0: * ); danielebarchiesi@0: * @endcode danielebarchiesi@0: * When path 'my-module/123/edit' is requested, your load function danielebarchiesi@0: * mymodule_abc_load() will be invoked with the argument '123', and should danielebarchiesi@0: * load and return an "abc" object with internal id 123: danielebarchiesi@0: * @code danielebarchiesi@0: * function mymodule_abc_load($abc_id) { danielebarchiesi@0: * return db_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject(); danielebarchiesi@0: * } danielebarchiesi@0: * @endcode danielebarchiesi@0: * This 'abc' object will then be passed into the callback functions defined danielebarchiesi@0: * for the menu item, such as the page callback function mymodule_abc_edit() danielebarchiesi@0: * to replace the integer 1 in the argument array. Note that a load function danielebarchiesi@0: * should return FALSE when it is unable to provide a loadable object. For danielebarchiesi@0: * example, the node_load() function for the 'node/%node/edit' menu item will danielebarchiesi@0: * return FALSE for the path 'node/999/edit' if a node with a node ID of 999 danielebarchiesi@0: * does not exist. The menu routing system will return a 404 error in this case. danielebarchiesi@0: * danielebarchiesi@0: * @subsection sub_argument_wildcards Argument Wildcards danielebarchiesi@0: * You can also define a %wildcard_to_arg() function (for the example menu danielebarchiesi@0: * entry above this would be 'mymodule_abc_to_arg()'). The _to_arg() function danielebarchiesi@0: * is invoked to retrieve a value that is used in the path in place of the danielebarchiesi@0: * wildcard. A good example is user.module, which defines danielebarchiesi@0: * user_uid_optional_to_arg() (corresponding to the menu entry danielebarchiesi@0: * 'tracker/%user_uid_optional'). This function returns the user ID of the danielebarchiesi@0: * current user. danielebarchiesi@0: * danielebarchiesi@0: * The _to_arg() function will get called with three arguments: danielebarchiesi@0: * - $arg: A string representing whatever argument may have been supplied by danielebarchiesi@0: * the caller (this is particularly useful if you want the _to_arg() danielebarchiesi@0: * function only supply a (default) value if no other value is specified, danielebarchiesi@0: * as in the case of user_uid_optional_to_arg(). danielebarchiesi@0: * - $map: An array of all path fragments (e.g. array('node','123','edit') for danielebarchiesi@0: * 'node/123/edit'). danielebarchiesi@0: * - $index: An integer indicating which element of $map corresponds to $arg. danielebarchiesi@0: * danielebarchiesi@0: * _load() and _to_arg() functions may seem similar at first glance, but they danielebarchiesi@0: * have different purposes and are called at different times. _load() danielebarchiesi@0: * functions are called when the menu system is collecting arguments to pass danielebarchiesi@0: * to the callback functions defined for the menu item. _to_arg() functions danielebarchiesi@0: * are called when the menu system is generating links to related paths, such danielebarchiesi@0: * as the tabs for a set of MENU_LOCAL_TASK items. danielebarchiesi@0: * danielebarchiesi@0: * @section sec_render_tabs Rendering Menu Items As Tabs danielebarchiesi@0: * You can also make groups of menu items to be rendered (by default) as tabs danielebarchiesi@0: * on a page. To do that, first create one menu item of type MENU_NORMAL_ITEM, danielebarchiesi@0: * with your chosen path, such as 'foo'. Then duplicate that menu item, using a danielebarchiesi@0: * subdirectory path, such as 'foo/tab1', and changing the type to danielebarchiesi@0: * MENU_DEFAULT_LOCAL_TASK to make it the default tab for the group. Then add danielebarchiesi@0: * the additional tab items, with paths such as "foo/tab2" etc., with type danielebarchiesi@0: * MENU_LOCAL_TASK. Example: danielebarchiesi@0: * @code danielebarchiesi@0: * // Make "Foo settings" appear on the admin Config page danielebarchiesi@0: * $items['admin/config/system/foo'] = array( danielebarchiesi@0: * 'title' => 'Foo settings', danielebarchiesi@0: * 'type' => MENU_NORMAL_ITEM, danielebarchiesi@0: * // Page callback, etc. need to be added here. danielebarchiesi@0: * ); danielebarchiesi@0: * // Make "Tab 1" the main tab on the "Foo settings" page danielebarchiesi@0: * $items['admin/config/system/foo/tab1'] = array( danielebarchiesi@0: * 'title' => 'Tab 1', danielebarchiesi@0: * 'type' => MENU_DEFAULT_LOCAL_TASK, danielebarchiesi@0: * // Access callback, page callback, and theme callback will be inherited danielebarchiesi@0: * // from 'admin/config/system/foo', if not specified here to override. danielebarchiesi@0: * ); danielebarchiesi@0: * // Make an additional tab called "Tab 2" on "Foo settings" danielebarchiesi@0: * $items['admin/config/system/foo/tab2'] = array( danielebarchiesi@0: * 'title' => 'Tab 2', danielebarchiesi@0: * 'type' => MENU_LOCAL_TASK, danielebarchiesi@0: * // Page callback and theme callback will be inherited from danielebarchiesi@0: * // 'admin/config/system/foo', if not specified here to override. danielebarchiesi@0: * // Need to add access callback or access arguments. danielebarchiesi@0: * ); danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array of menu items. Each menu item has a key corresponding to the danielebarchiesi@0: * Drupal path being registered. The corresponding array value is an danielebarchiesi@0: * associative array that may contain the following key-value pairs: danielebarchiesi@0: * - "title": Required. The untranslated title of the menu item. danielebarchiesi@0: * - "title callback": Function to generate the title; defaults to t(). danielebarchiesi@0: * If you require only the raw string to be output, set this to FALSE. danielebarchiesi@0: * - "title arguments": Arguments to send to t() or your custom callback, danielebarchiesi@0: * with path component substitution as described above. danielebarchiesi@0: * - "description": The untranslated description of the menu item. danielebarchiesi@0: * - "page callback": The function to call to display a web page when the user danielebarchiesi@0: * visits the path. If omitted, the parent menu item's callback will be used danielebarchiesi@0: * instead. danielebarchiesi@0: * - "page arguments": An array of arguments to pass to the page callback danielebarchiesi@0: * function, with path component substitution as described above. danielebarchiesi@0: * - "delivery callback": The function to call to package the result of the danielebarchiesi@0: * page callback function and send it to the browser. Defaults to danielebarchiesi@0: * drupal_deliver_html_page() unless a value is inherited from a parent menu danielebarchiesi@0: * item. Note that this function is called even if the access checks fail, danielebarchiesi@0: * so any custom delivery callback function should take that into account. danielebarchiesi@0: * See drupal_deliver_html_page() for an example. danielebarchiesi@0: * - "access callback": A function returning TRUE if the user has access danielebarchiesi@0: * rights to this menu item, and FALSE if not. It can also be a boolean danielebarchiesi@0: * constant instead of a function, and you can also use numeric values danielebarchiesi@0: * (will be cast to boolean). Defaults to user_access() unless a value is danielebarchiesi@0: * inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items danielebarchiesi@0: * can inherit access callbacks. To use the user_access() default callback, danielebarchiesi@0: * you must specify the permission to check as 'access arguments' (see danielebarchiesi@0: * below). danielebarchiesi@0: * - "access arguments": An array of arguments to pass to the access callback danielebarchiesi@0: * function, with path component substitution as described above. If the danielebarchiesi@0: * access callback is inherited (see above), the access arguments will be danielebarchiesi@0: * inherited with it, unless overridden in the child menu item. danielebarchiesi@0: * - "theme callback": (optional) A function returning the machine-readable danielebarchiesi@0: * name of the theme that will be used to render the page. If not provided, danielebarchiesi@0: * the value will be inherited from a parent menu item. If there is no danielebarchiesi@0: * theme callback, or if the function does not return the name of a current danielebarchiesi@0: * active theme on the site, the theme for this page will be determined by danielebarchiesi@0: * either hook_custom_theme() or the default theme instead. As a general danielebarchiesi@0: * rule, the use of theme callback functions should be limited to pages danielebarchiesi@0: * whose functionality is very closely tied to a particular theme, since danielebarchiesi@0: * they can only be overridden by modules which specifically target those danielebarchiesi@0: * pages in hook_menu_alter(). Modules implementing more generic theme danielebarchiesi@0: * switching functionality (for example, a module which allows the theme to danielebarchiesi@0: * be set dynamically based on the current user's role) should use danielebarchiesi@0: * hook_custom_theme() instead. danielebarchiesi@0: * - "theme arguments": An array of arguments to pass to the theme callback danielebarchiesi@0: * function, with path component substitution as described above. danielebarchiesi@0: * - "file": A file that will be included before the page callback is called; danielebarchiesi@0: * this allows page callback functions to be in separate files. The file danielebarchiesi@0: * should be relative to the implementing module's directory unless danielebarchiesi@0: * otherwise specified by the "file path" option. Does not apply to other danielebarchiesi@0: * callbacks (only page callback). danielebarchiesi@0: * - "file path": The path to the directory containing the file specified in danielebarchiesi@0: * "file". This defaults to the path to the module implementing the hook. danielebarchiesi@0: * - "load arguments": An array of arguments to be passed to each of the danielebarchiesi@0: * wildcard object loaders in the path, after the path argument itself. danielebarchiesi@0: * For example, if a module registers path node/%node/revisions/%/view danielebarchiesi@0: * with load arguments set to array(3), the '%node' in the path indicates danielebarchiesi@0: * that the loader function node_load() will be called with the second danielebarchiesi@0: * path component as the first argument. The 3 in the load arguments danielebarchiesi@0: * indicates that the fourth path component will also be passed to danielebarchiesi@0: * node_load() (numbering of path components starts at zero). So, if path danielebarchiesi@0: * node/12/revisions/29/view is requested, node_load(12, 29) will be called. danielebarchiesi@0: * There are also two "magic" values that can be used in load arguments. danielebarchiesi@0: * "%index" indicates the index of the wildcard path component. "%map" danielebarchiesi@0: * indicates the path components as an array. For example, if a module danielebarchiesi@0: * registers for several paths of the form 'user/%user_category/edit/*', all danielebarchiesi@0: * of them can use the same load function user_category_load(), by setting danielebarchiesi@0: * the load arguments to array('%map', '%index'). For instance, if the user danielebarchiesi@0: * is editing category 'foo' by requesting path 'user/32/edit/foo', the load danielebarchiesi@0: * function user_category_load() will be called with 32 as its first danielebarchiesi@0: * argument, the array ('user', 32, 'edit', 'foo') as the map argument, danielebarchiesi@0: * and 1 as the index argument (because %user_category is the second path danielebarchiesi@0: * component and numbering starts at zero). user_category_load() can then danielebarchiesi@0: * use these values to extract the information that 'foo' is the category danielebarchiesi@0: * being requested. danielebarchiesi@0: * - "weight": An integer that determines the relative position of items in danielebarchiesi@0: * the menu; higher-weighted items sink. Defaults to 0. Menu items with the danielebarchiesi@0: * same weight are ordered alphabetically. danielebarchiesi@0: * - "menu_name": Optional. Set this to a custom menu if you don't want your danielebarchiesi@0: * item to be placed in Navigation. danielebarchiesi@0: * - "expanded": Optional. If set to TRUE, and if a menu link is provided for danielebarchiesi@0: * this menu item (as a result of other properties), then the menu link is danielebarchiesi@0: * always expanded, equivalent to its 'always expanded' checkbox being set danielebarchiesi@0: * in the UI. danielebarchiesi@0: * - "context": (optional) Defines the context a tab may appear in. By danielebarchiesi@0: * default, all tabs are only displayed as local tasks when being rendered danielebarchiesi@0: * in a page context. All tabs that should be accessible as contextual links danielebarchiesi@0: * in page region containers outside of the parent menu item's primary page danielebarchiesi@0: * context should be registered using one of the following contexts: danielebarchiesi@0: * - MENU_CONTEXT_PAGE: (default) The tab is displayed as local task for the danielebarchiesi@0: * page context only. danielebarchiesi@0: * - MENU_CONTEXT_INLINE: The tab is displayed as contextual link outside of danielebarchiesi@0: * the primary page context only. danielebarchiesi@0: * Contexts can be combined. For example, to display a tab both on a page danielebarchiesi@0: * and inline, a menu router item may specify: danielebarchiesi@0: * @code danielebarchiesi@0: * 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, danielebarchiesi@0: * @endcode danielebarchiesi@0: * - "tab_parent": For local task menu items, the path of the task's parent danielebarchiesi@0: * item; defaults to the same path without the last component (e.g., the danielebarchiesi@0: * default parent for 'admin/people/create' is 'admin/people'). danielebarchiesi@0: * - "tab_root": For local task menu items, the path of the closest non-tab danielebarchiesi@0: * item; same default as "tab_parent". danielebarchiesi@0: * - "position": Position of the block ('left' or 'right') on the system danielebarchiesi@0: * administration page for this item. danielebarchiesi@0: * - "type": A bitmask of flags describing properties of the menu item. danielebarchiesi@0: * Many shortcut bitmasks are provided as constants in menu.inc: danielebarchiesi@0: * - MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be danielebarchiesi@0: * moved/hidden by the administrator. danielebarchiesi@0: * - MENU_CALLBACK: Callbacks simply register a path so that the correct danielebarchiesi@0: * information is generated when the path is accessed. danielebarchiesi@0: * - MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the danielebarchiesi@0: * administrator may enable. danielebarchiesi@0: * - MENU_LOCAL_ACTION: Local actions are menu items that describe actions danielebarchiesi@0: * on the parent item such as adding a new user or block, and are danielebarchiesi@0: * rendered in the action-links list in your theme. danielebarchiesi@0: * - MENU_LOCAL_TASK: Local tasks are menu items that describe different danielebarchiesi@0: * displays of data, and are generally rendered as tabs. danielebarchiesi@0: * - MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one danielebarchiesi@0: * "default" task, which should display the same page as the parent item. danielebarchiesi@0: * If the "type" element is omitted, MENU_NORMAL_ITEM is assumed. danielebarchiesi@0: * - "options": An array of options to be passed to l() when generating a link danielebarchiesi@0: * from this menu item. Note that the "options" parameter has no effect on danielebarchiesi@0: * MENU_LOCAL_TASK, MENU_DEFAULT_LOCAL_TASK, and MENU_LOCAL_ACTION items. danielebarchiesi@0: * danielebarchiesi@0: * For a detailed usage example, see page_example.module. danielebarchiesi@0: * For comprehensive documentation on the menu system, see danielebarchiesi@0: * http://drupal.org/node/102338. danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu() { danielebarchiesi@0: $items['example'] = array( danielebarchiesi@0: 'title' => 'Example Page', danielebarchiesi@0: 'page callback' => 'example_page', danielebarchiesi@0: 'access arguments' => array('access content'), danielebarchiesi@0: 'type' => MENU_SUGGESTED_ITEM, danielebarchiesi@0: ); danielebarchiesi@0: $items['example/feed'] = array( danielebarchiesi@0: 'title' => 'Example RSS feed', danielebarchiesi@0: 'page callback' => 'example_feed', danielebarchiesi@0: 'access arguments' => array('access content'), danielebarchiesi@0: 'type' => MENU_CALLBACK, danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: return $items; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the data being saved to the {menu_router} table after hook_menu is invoked. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked by menu_router_build(). The menu definitions are passed danielebarchiesi@0: * in by reference. Each element of the $items array is one item returned danielebarchiesi@0: * by a module from hook_menu. Additional items may be added, or existing items danielebarchiesi@0: * altered. danielebarchiesi@0: * danielebarchiesi@0: * @param $items danielebarchiesi@0: * Associative array of menu router definitions returned from hook_menu(). danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_alter(&$items) { danielebarchiesi@0: // Example - disable the page at node/add danielebarchiesi@0: $items['node/add']['access callback'] = FALSE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the data being saved to the {menu_links} table by menu_link_save(). danielebarchiesi@0: * danielebarchiesi@0: * @param $item danielebarchiesi@0: * Associative array defining a menu link as passed into menu_link_save(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_translated_menu_link_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_link_alter(&$item) { danielebarchiesi@0: // Make all new admin links hidden (a.k.a disabled). danielebarchiesi@0: if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) { danielebarchiesi@0: $item['hidden'] = 1; danielebarchiesi@0: } danielebarchiesi@0: // Flag a link to be altered by hook_translated_menu_link_alter(). danielebarchiesi@0: if ($item['link_path'] == 'devel/cache/clear') { danielebarchiesi@0: $item['options']['alter'] = TRUE; danielebarchiesi@0: } danielebarchiesi@0: // Flag a link to be altered by hook_translated_menu_link_alter(), but only danielebarchiesi@0: // if it is derived from a menu router item; i.e., do not alter a custom danielebarchiesi@0: // menu link pointing to the same path that has been created by a user. danielebarchiesi@0: if ($item['link_path'] == 'user' && $item['module'] == 'system') { danielebarchiesi@0: $item['options']['alter'] = TRUE; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter a menu link after it has been translated and before it is rendered. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked from _menu_link_translate() after a menu link has been danielebarchiesi@0: * translated; i.e., after dynamic path argument placeholders (%) have been danielebarchiesi@0: * replaced with actual values, the user access to the link's target page has danielebarchiesi@0: * been checked, and the link has been localized. It is only invoked if danielebarchiesi@0: * $item['options']['alter'] has been set to a non-empty value (e.g., TRUE). danielebarchiesi@0: * This flag should be set using hook_menu_link_alter(). danielebarchiesi@0: * danielebarchiesi@0: * Implementations of this hook are able to alter any property of the menu link. danielebarchiesi@0: * For example, this hook may be used to add a page-specific query string to all danielebarchiesi@0: * menu links, or hide a certain link by setting: danielebarchiesi@0: * @code danielebarchiesi@0: * 'hidden' => 1, danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * @param $item danielebarchiesi@0: * Associative array defining a menu link after _menu_link_translate() danielebarchiesi@0: * @param $map danielebarchiesi@0: * Associative array containing the menu $map (path parts and/or objects). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_menu_link_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_translated_menu_link_alter(&$item, $map) { danielebarchiesi@0: if ($item['href'] == 'devel/cache/clear') { danielebarchiesi@0: $item['localized_options']['query'] = drupal_get_destination(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform modules that a menu link has been created. danielebarchiesi@0: * danielebarchiesi@0: * This hook is used to notify modules that menu items have been danielebarchiesi@0: * created. Contributed modules may use the information to perform danielebarchiesi@0: * actions based on the information entered into the menu system. danielebarchiesi@0: * danielebarchiesi@0: * @param $link danielebarchiesi@0: * Associative array defining a menu link as passed into menu_link_save(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_menu_link_update() danielebarchiesi@0: * @see hook_menu_link_delete() danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_link_insert($link) { danielebarchiesi@0: // In our sample case, we track menu items as editing sections danielebarchiesi@0: // of the site. These are stored in our table as 'disabled' items. danielebarchiesi@0: $record['mlid'] = $link['mlid']; danielebarchiesi@0: $record['menu_name'] = $link['menu_name']; danielebarchiesi@0: $record['status'] = 0; danielebarchiesi@0: drupal_write_record('menu_example', $record); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform modules that a menu link has been updated. danielebarchiesi@0: * danielebarchiesi@0: * This hook is used to notify modules that menu items have been danielebarchiesi@0: * updated. Contributed modules may use the information to perform danielebarchiesi@0: * actions based on the information entered into the menu system. danielebarchiesi@0: * danielebarchiesi@0: * @param $link danielebarchiesi@0: * Associative array defining a menu link as passed into menu_link_save(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_menu_link_insert() danielebarchiesi@0: * @see hook_menu_link_delete() danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_link_update($link) { danielebarchiesi@0: // If the parent menu has changed, update our record. danielebarchiesi@0: $menu_name = db_query("SELECT menu_name FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid']))->fetchField(); danielebarchiesi@0: if ($menu_name != $link['menu_name']) { danielebarchiesi@0: db_update('menu_example') danielebarchiesi@0: ->fields(array('menu_name' => $link['menu_name'])) danielebarchiesi@0: ->condition('mlid', $link['mlid']) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform modules that a menu link has been deleted. danielebarchiesi@0: * danielebarchiesi@0: * This hook is used to notify modules that menu items have been danielebarchiesi@0: * deleted. Contributed modules may use the information to perform danielebarchiesi@0: * actions based on the information entered into the menu system. danielebarchiesi@0: * danielebarchiesi@0: * @param $link danielebarchiesi@0: * Associative array defining a menu link as passed into menu_link_save(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_menu_link_insert() danielebarchiesi@0: * @see hook_menu_link_update() danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_link_delete($link) { danielebarchiesi@0: // Delete the record from our table. danielebarchiesi@0: db_delete('menu_example') danielebarchiesi@0: ->condition('mlid', $link['mlid']) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter tabs and actions displayed on the page before they are rendered. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked by menu_local_tasks(). The system-determined tabs and danielebarchiesi@0: * actions are passed in by reference. Additional tabs or actions may be added, danielebarchiesi@0: * or existing items altered. danielebarchiesi@0: * danielebarchiesi@0: * Each tab or action is an associative array containing: danielebarchiesi@0: * - #theme: The theme function to use to render. danielebarchiesi@0: * - #link: An associative array containing: danielebarchiesi@0: * - title: The localized title of the link. danielebarchiesi@0: * - href: The system path to link to. danielebarchiesi@0: * - localized_options: An array of options to pass to l(). danielebarchiesi@0: * - #active: Whether the link should be marked as 'active'. danielebarchiesi@0: * danielebarchiesi@0: * @param $data danielebarchiesi@0: * An associative array containing: danielebarchiesi@0: * - actions: An associative array containing: danielebarchiesi@0: * - count: The amount of actions determined by the menu system, which can danielebarchiesi@0: * be ignored. danielebarchiesi@0: * - output: A list of of actions, each one being an associative array danielebarchiesi@0: * as described above. danielebarchiesi@0: * - tabs: An indexed array (list) of tab levels (up to 2 levels), each danielebarchiesi@0: * containing an associative array: danielebarchiesi@0: * - count: The amount of tabs determined by the menu system. This value danielebarchiesi@0: * does not need to be altered if there is more than one tab. danielebarchiesi@0: * - output: A list of of tabs, each one being an associative array as danielebarchiesi@0: * described above. danielebarchiesi@0: * @param $router_item danielebarchiesi@0: * The menu system router item of the page. danielebarchiesi@0: * @param $root_path danielebarchiesi@0: * The path to the root item for this set of tabs. danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_local_tasks_alter(&$data, $router_item, $root_path) { danielebarchiesi@0: // Add an action linking to node/add to all pages. danielebarchiesi@0: $data['actions']['output'][] = array( danielebarchiesi@0: '#theme' => 'menu_local_task', danielebarchiesi@0: '#link' => array( danielebarchiesi@0: 'title' => t('Add new content'), danielebarchiesi@0: 'href' => 'node/add', danielebarchiesi@0: 'localized_options' => array( danielebarchiesi@0: 'attributes' => array( danielebarchiesi@0: 'title' => t('Add new content'), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Add a tab linking to node/add to all pages. danielebarchiesi@0: $data['tabs'][0]['output'][] = array( danielebarchiesi@0: '#theme' => 'menu_local_task', danielebarchiesi@0: '#link' => array( danielebarchiesi@0: 'title' => t('Example tab'), danielebarchiesi@0: 'href' => 'node/add', danielebarchiesi@0: 'localized_options' => array( danielebarchiesi@0: 'attributes' => array( danielebarchiesi@0: 'title' => t('Add new content'), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: // Define whether this link is active. This can be omitted for danielebarchiesi@0: // implementations that add links to pages outside of the current page danielebarchiesi@0: // context. danielebarchiesi@0: '#active' => ($router_item['path'] == $root_path), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter links in the active trail before it is rendered as the breadcrumb. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked by menu_get_active_breadcrumb() and allows alteration danielebarchiesi@0: * of the breadcrumb links for the current page, which may be preferred instead danielebarchiesi@0: * of setting a custom breadcrumb via drupal_set_breadcrumb(). danielebarchiesi@0: * danielebarchiesi@0: * Implementations should take into account that menu_get_active_breadcrumb() danielebarchiesi@0: * subsequently performs the following adjustments to the active trail *after* danielebarchiesi@0: * this hook has been invoked: danielebarchiesi@0: * - The last link in $active_trail is removed, if its 'href' is identical to danielebarchiesi@0: * the 'href' of $item. This happens, because the breadcrumb normally does danielebarchiesi@0: * not contain a link to the current page. danielebarchiesi@0: * - The (second to) last link in $active_trail is removed, if the current $item danielebarchiesi@0: * is a MENU_DEFAULT_LOCAL_TASK. This happens in order to do not show a link danielebarchiesi@0: * to the current page, when being on the path for the default local task; danielebarchiesi@0: * e.g. when being on the path node/%/view, the breadcrumb should not contain danielebarchiesi@0: * a link to node/%. danielebarchiesi@0: * danielebarchiesi@0: * Each link in the active trail must contain: danielebarchiesi@0: * - title: The localized title of the link. danielebarchiesi@0: * - href: The system path to link to. danielebarchiesi@0: * - localized_options: An array of options to pass to url(). danielebarchiesi@0: * danielebarchiesi@0: * @param $active_trail danielebarchiesi@0: * An array containing breadcrumb links for the current page. danielebarchiesi@0: * @param $item danielebarchiesi@0: * The menu router item of the current page. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_set_breadcrumb() danielebarchiesi@0: * @see menu_get_active_breadcrumb() danielebarchiesi@0: * @see menu_get_active_trail() danielebarchiesi@0: * @see menu_set_active_trail() danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_breadcrumb_alter(&$active_trail, $item) { danielebarchiesi@0: // Always display a link to the current page by duplicating the last link in danielebarchiesi@0: // the active trail. This means that menu_get_active_breadcrumb() will remove danielebarchiesi@0: // the last link (for the current page), but since it is added once more here, danielebarchiesi@0: // it will appear. danielebarchiesi@0: if (!drupal_is_front_page()) { danielebarchiesi@0: $end = end($active_trail); danielebarchiesi@0: if ($item['href'] == $end['href']) { danielebarchiesi@0: $active_trail[] = $end; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter contextual links before they are rendered. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked by menu_contextual_links(). The system-determined danielebarchiesi@0: * contextual links are passed in by reference. Additional links may be added danielebarchiesi@0: * or existing links can be altered. danielebarchiesi@0: * danielebarchiesi@0: * Each contextual link must at least contain: danielebarchiesi@0: * - title: The localized title of the link. danielebarchiesi@0: * - href: The system path to link to. danielebarchiesi@0: * - localized_options: An array of options to pass to url(). danielebarchiesi@0: * danielebarchiesi@0: * @param $links danielebarchiesi@0: * An associative array containing contextual links for the given $root_path, danielebarchiesi@0: * as described above. The array keys are used to build CSS class names for danielebarchiesi@0: * contextual links and must therefore be unique for each set of contextual danielebarchiesi@0: * links. danielebarchiesi@0: * @param $router_item danielebarchiesi@0: * The menu router item belonging to the $root_path being requested. danielebarchiesi@0: * @param $root_path danielebarchiesi@0: * The (parent) path that has been requested to build contextual links for. danielebarchiesi@0: * This is a normalized path, which means that an originally passed path of danielebarchiesi@0: * 'node/123' became 'node/%'. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_contextual_links_view_alter() danielebarchiesi@0: * @see menu_contextual_links() danielebarchiesi@0: * @see hook_menu() danielebarchiesi@0: * @see contextual_preprocess() danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_contextual_links_alter(&$links, $router_item, $root_path) { danielebarchiesi@0: // Add a link to all contextual links for nodes. danielebarchiesi@0: if ($root_path == 'node/%') { danielebarchiesi@0: $links['foo'] = array( danielebarchiesi@0: 'title' => t('Do fu'), danielebarchiesi@0: 'href' => 'foo/do', danielebarchiesi@0: 'localized_options' => array( danielebarchiesi@0: 'query' => array( danielebarchiesi@0: 'foo' => 'bar', danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform alterations before a page is rendered. danielebarchiesi@0: * danielebarchiesi@0: * Use this hook when you want to remove or alter elements at the page danielebarchiesi@0: * level, or add elements at the page level that depend on an other module's danielebarchiesi@0: * elements (this hook runs after hook_page_build(). danielebarchiesi@0: * danielebarchiesi@0: * If you are making changes to entities such as forms, menus, or user danielebarchiesi@0: * profiles, use those objects' native alter hooks instead (hook_form_alter(), danielebarchiesi@0: * for example). danielebarchiesi@0: * danielebarchiesi@0: * The $page array contains top level elements for each block region: danielebarchiesi@0: * @code danielebarchiesi@0: * $page['page_top'] danielebarchiesi@0: * $page['header'] danielebarchiesi@0: * $page['sidebar_first'] danielebarchiesi@0: * $page['content'] danielebarchiesi@0: * $page['sidebar_second'] danielebarchiesi@0: * $page['page_bottom'] danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * The 'content' element contains the main content of the current page, and its danielebarchiesi@0: * structure will vary depending on what module is responsible for building the danielebarchiesi@0: * page. Some legacy modules may not return structured content at all: their danielebarchiesi@0: * pre-rendered markup will be located in $page['content']['main']['#markup']. danielebarchiesi@0: * danielebarchiesi@0: * Pages built by Drupal's core Node and Blog modules use a standard structure: danielebarchiesi@0: * danielebarchiesi@0: * @code danielebarchiesi@0: * // Node body. danielebarchiesi@0: * $page['content']['system_main']['nodes'][$nid]['body'] danielebarchiesi@0: * // Array of links attached to the node (add comments, read more). danielebarchiesi@0: * $page['content']['system_main']['nodes'][$nid]['links'] danielebarchiesi@0: * // The node object itself. danielebarchiesi@0: * $page['content']['system_main']['nodes'][$nid]['#node'] danielebarchiesi@0: * // The results pager. danielebarchiesi@0: * $page['content']['system_main']['pager'] danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * Blocks may be referenced by their module/delta pair within a region: danielebarchiesi@0: * @code danielebarchiesi@0: * // The login block in the first sidebar region. danielebarchiesi@0: * $page['sidebar_first']['user_login']['#block']; danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * @param $page danielebarchiesi@0: * Nested array of renderable elements that make up the page. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_page_build() danielebarchiesi@0: * @see drupal_render_page() danielebarchiesi@0: */ danielebarchiesi@0: function hook_page_alter(&$page) { danielebarchiesi@0: // Add help text to the user login block. danielebarchiesi@0: $page['sidebar_first']['user_login']['help'] = array( danielebarchiesi@0: '#weight' => -10, danielebarchiesi@0: '#markup' => t('To post comments or add new content, you first have to log in.'), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform alterations before a form is rendered. danielebarchiesi@0: * danielebarchiesi@0: * One popular use of this hook is to add form elements to the node form. When danielebarchiesi@0: * altering a node form, the node object can be accessed at $form['#node']. danielebarchiesi@0: * danielebarchiesi@0: * In addition to hook_form_alter(), which is called for all forms, there are danielebarchiesi@0: * two more specific form hooks available. The first, danielebarchiesi@0: * hook_form_BASE_FORM_ID_alter(), allows targeting of a form/forms via a base danielebarchiesi@0: * form (if one exists). The second, hook_form_FORM_ID_alter(), can be used to danielebarchiesi@0: * target a specific form directly. danielebarchiesi@0: * danielebarchiesi@0: * The call order is as follows: all existing form alter functions are called danielebarchiesi@0: * for module A, then all for module B, etc., followed by all for any base danielebarchiesi@0: * theme(s), and finally for the theme itself. The module order is determined danielebarchiesi@0: * by system weight, then by module name. danielebarchiesi@0: * danielebarchiesi@0: * Within each module, form alter hooks are called in the following order: danielebarchiesi@0: * first, hook_form_alter(); second, hook_form_BASE_FORM_ID_alter(); third, danielebarchiesi@0: * hook_form_FORM_ID_alter(). So, for each module, the more general hooks are danielebarchiesi@0: * called first followed by the more specific. danielebarchiesi@0: * danielebarchiesi@0: * @param $form danielebarchiesi@0: * Nested array of form elements that comprise the form. danielebarchiesi@0: * @param $form_state danielebarchiesi@0: * A keyed array containing the current state of the form. The arguments danielebarchiesi@0: * that drupal_get_form() was originally called with are available in the danielebarchiesi@0: * array $form_state['build_info']['args']. danielebarchiesi@0: * @param $form_id danielebarchiesi@0: * String representing the name of the form itself. Typically this is the danielebarchiesi@0: * name of the function that generated the form. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_form_BASE_FORM_ID_alter() danielebarchiesi@0: * @see hook_form_FORM_ID_alter() danielebarchiesi@0: * @see forms_api_reference.html danielebarchiesi@0: */ danielebarchiesi@0: function hook_form_alter(&$form, &$form_state, $form_id) { danielebarchiesi@0: if (isset($form['type']) && $form['type']['#value'] . '_node_settings' == $form_id) { danielebarchiesi@0: $form['workflow']['upload_' . $form['type']['#value']] = array( danielebarchiesi@0: '#type' => 'radios', danielebarchiesi@0: '#title' => t('Attachments'), danielebarchiesi@0: '#default_value' => variable_get('upload_' . $form['type']['#value'], 1), danielebarchiesi@0: '#options' => array(t('Disabled'), t('Enabled')), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Provide a form-specific alteration instead of the global hook_form_alter(). danielebarchiesi@0: * danielebarchiesi@0: * Modules can implement hook_form_FORM_ID_alter() to modify a specific form, danielebarchiesi@0: * rather than implementing hook_form_alter() and checking the form ID, or danielebarchiesi@0: * using long switch statements to alter multiple forms. danielebarchiesi@0: * danielebarchiesi@0: * Form alter hooks are called in the following order: hook_form_alter(), danielebarchiesi@0: * hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter(). See danielebarchiesi@0: * hook_form_alter() for more details. danielebarchiesi@0: * danielebarchiesi@0: * @param $form danielebarchiesi@0: * Nested array of form elements that comprise the form. danielebarchiesi@0: * @param $form_state danielebarchiesi@0: * A keyed array containing the current state of the form. The arguments danielebarchiesi@0: * that drupal_get_form() was originally called with are available in the danielebarchiesi@0: * array $form_state['build_info']['args']. danielebarchiesi@0: * @param $form_id danielebarchiesi@0: * String representing the name of the form itself. Typically this is the danielebarchiesi@0: * name of the function that generated the form. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_form_alter() danielebarchiesi@0: * @see hook_form_BASE_FORM_ID_alter() danielebarchiesi@0: * @see drupal_prepare_form() danielebarchiesi@0: * @see forms_api_reference.html danielebarchiesi@0: */ danielebarchiesi@0: function hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) { danielebarchiesi@0: // Modification for the form with the given form ID goes here. For example, if danielebarchiesi@0: // FORM_ID is "user_register_form" this code would run only on the user danielebarchiesi@0: // registration form. danielebarchiesi@0: danielebarchiesi@0: // Add a checkbox to registration form about agreeing to terms of use. danielebarchiesi@0: $form['terms_of_use'] = array( danielebarchiesi@0: '#type' => 'checkbox', danielebarchiesi@0: '#title' => t("I agree with the website's terms and conditions."), danielebarchiesi@0: '#required' => TRUE, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Provide a form-specific alteration for shared ('base') forms. danielebarchiesi@0: * danielebarchiesi@0: * By default, when drupal_get_form() is called, Drupal looks for a function danielebarchiesi@0: * with the same name as the form ID, and uses that function to build the form. danielebarchiesi@0: * In contrast, base forms allow multiple form IDs to be mapped to a single base danielebarchiesi@0: * (also called 'factory') form function. danielebarchiesi@0: * danielebarchiesi@0: * Modules can implement hook_form_BASE_FORM_ID_alter() to modify a specific danielebarchiesi@0: * base form, rather than implementing hook_form_alter() and checking for danielebarchiesi@0: * conditions that would identify the shared form constructor. danielebarchiesi@0: * danielebarchiesi@0: * To identify the base form ID for a particular form (or to determine whether danielebarchiesi@0: * one exists) check the $form_state. The base form ID is stored under danielebarchiesi@0: * $form_state['build_info']['base_form_id']. danielebarchiesi@0: * danielebarchiesi@0: * See hook_forms() for more information on how to implement base forms in danielebarchiesi@0: * Drupal. danielebarchiesi@0: * danielebarchiesi@0: * Form alter hooks are called in the following order: hook_form_alter(), danielebarchiesi@0: * hook_form_BASE_FORM_ID_alter(), hook_form_FORM_ID_alter(). See danielebarchiesi@0: * hook_form_alter() for more details. danielebarchiesi@0: * danielebarchiesi@0: * @param $form danielebarchiesi@0: * Nested array of form elements that comprise the form. danielebarchiesi@0: * @param $form_state danielebarchiesi@0: * A keyed array containing the current state of the form. danielebarchiesi@0: * @param $form_id danielebarchiesi@0: * String representing the name of the form itself. Typically this is the danielebarchiesi@0: * name of the function that generated the form. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_form_alter() danielebarchiesi@0: * @see hook_form_FORM_ID_alter() danielebarchiesi@0: * @see drupal_prepare_form() danielebarchiesi@0: * @see hook_forms() danielebarchiesi@0: */ danielebarchiesi@0: function hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id) { danielebarchiesi@0: // Modification for the form with the given BASE_FORM_ID goes here. For danielebarchiesi@0: // example, if BASE_FORM_ID is "node_form", this code would run on every danielebarchiesi@0: // node form, regardless of node type. danielebarchiesi@0: danielebarchiesi@0: // Add a checkbox to the node form about agreeing to terms of use. danielebarchiesi@0: $form['terms_of_use'] = array( danielebarchiesi@0: '#type' => 'checkbox', danielebarchiesi@0: '#title' => t("I agree with the website's terms and conditions."), danielebarchiesi@0: '#required' => TRUE, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Map form_ids to form builder functions. danielebarchiesi@0: * danielebarchiesi@0: * By default, when drupal_get_form() is called, the system will look for a danielebarchiesi@0: * function with the same name as the form ID, and use that function to build danielebarchiesi@0: * the form. If no such function is found, Drupal calls this hook. Modules danielebarchiesi@0: * implementing this hook can then provide their own instructions for mapping danielebarchiesi@0: * form IDs to constructor functions. As a result, you can easily map multiple danielebarchiesi@0: * form IDs to a single form constructor (referred to as a 'base' form). danielebarchiesi@0: * danielebarchiesi@0: * Using a base form can help to avoid code duplication, by allowing many danielebarchiesi@0: * similar forms to use the same code base. Another benefit is that it becomes danielebarchiesi@0: * much easier for other modules to apply a general change to the group of danielebarchiesi@0: * forms; hook_form_BASE_FORM_ID_alter() can be used to easily alter multiple danielebarchiesi@0: * forms at once by directly targeting the shared base form. danielebarchiesi@0: * danielebarchiesi@0: * Two example use cases where base forms may be useful are given below. danielebarchiesi@0: * danielebarchiesi@0: * First, you can use this hook to tell the form system to use a different danielebarchiesi@0: * function to build certain forms in your module; this is often used to define danielebarchiesi@0: * a form "factory" function that is used to build several similar forms. In danielebarchiesi@0: * this case, your hook implementation will likely ignore all of the input danielebarchiesi@0: * arguments. See node_forms() for an example of this. Note, node_forms() is the danielebarchiesi@0: * hook_forms() implementation; the base form itself is defined in node_form(). danielebarchiesi@0: * danielebarchiesi@0: * Second, you could use this hook to define how to build a form with a danielebarchiesi@0: * dynamically-generated form ID. In this case, you would need to verify that danielebarchiesi@0: * the $form_id input matched your module's format for dynamically-generated danielebarchiesi@0: * form IDs, and if so, act appropriately. danielebarchiesi@0: * danielebarchiesi@0: * @param $form_id danielebarchiesi@0: * The unique string identifying the desired form. danielebarchiesi@0: * @param $args danielebarchiesi@0: * An array containing the original arguments provided to drupal_get_form() danielebarchiesi@0: * or drupal_form_submit(). These are always passed to the form builder and danielebarchiesi@0: * do not have to be specified manually in 'callback arguments'. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array whose keys define form_ids and whose values are an danielebarchiesi@0: * associative array defining the following keys: danielebarchiesi@0: * - callback: The name of the form builder function to invoke. This will be danielebarchiesi@0: * used for the base form ID, for example, to target a base form using danielebarchiesi@0: * hook_form_BASE_FORM_ID_alter(). danielebarchiesi@0: * - callback arguments: (optional) Additional arguments to pass to the danielebarchiesi@0: * function defined in 'callback', which are prepended to $args. danielebarchiesi@0: * - wrapper_callback: (optional) The name of a form builder function to danielebarchiesi@0: * invoke before the form builder defined in 'callback' is invoked. This danielebarchiesi@0: * wrapper callback may prepopulate the $form array with form elements, danielebarchiesi@0: * which will then be already contained in the $form that is passed on to danielebarchiesi@0: * the form builder defined in 'callback'. For example, a wrapper callback danielebarchiesi@0: * could setup wizard-alike form buttons that are the same for a variety of danielebarchiesi@0: * forms that belong to the wizard, which all share the same wrapper danielebarchiesi@0: * callback. danielebarchiesi@0: */ danielebarchiesi@0: function hook_forms($form_id, $args) { danielebarchiesi@0: // Simply reroute the (non-existing) $form_id 'mymodule_first_form' to danielebarchiesi@0: // 'mymodule_main_form'. danielebarchiesi@0: $forms['mymodule_first_form'] = array( danielebarchiesi@0: 'callback' => 'mymodule_main_form', danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Reroute the $form_id and prepend an additional argument that gets passed to danielebarchiesi@0: // the 'mymodule_main_form' form builder function. danielebarchiesi@0: $forms['mymodule_second_form'] = array( danielebarchiesi@0: 'callback' => 'mymodule_main_form', danielebarchiesi@0: 'callback arguments' => array('some parameter'), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Reroute the $form_id, but invoke the form builder function danielebarchiesi@0: // 'mymodule_main_form_wrapper' first, so we can prepopulate the $form array danielebarchiesi@0: // that is passed to the actual form builder 'mymodule_main_form'. danielebarchiesi@0: $forms['mymodule_wrapped_form'] = array( danielebarchiesi@0: 'callback' => 'mymodule_main_form', danielebarchiesi@0: 'wrapper_callback' => 'mymodule_main_form_wrapper', danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: return $forms; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform setup tasks for all page requests. danielebarchiesi@0: * danielebarchiesi@0: * This hook is run at the beginning of the page request. It is typically danielebarchiesi@0: * used to set up global parameters that are needed later in the request. danielebarchiesi@0: * danielebarchiesi@0: * Only use this hook if your code must run even for cached page views. This danielebarchiesi@0: * hook is called before the theme, modules, or most include files are loaded danielebarchiesi@0: * into memory. It happens while Drupal is still in bootstrap mode. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_init() danielebarchiesi@0: */ danielebarchiesi@0: function hook_boot() { danielebarchiesi@0: // We need user_access() in the shutdown function. Make sure it gets loaded. danielebarchiesi@0: drupal_load('module', 'user'); danielebarchiesi@0: drupal_register_shutdown_function('devel_shutdown'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform setup tasks for non-cached page requests. danielebarchiesi@0: * danielebarchiesi@0: * This hook is run at the beginning of the page request. It is typically danielebarchiesi@0: * used to set up global parameters that are needed later in the request. danielebarchiesi@0: * When this hook is called, the theme and all modules are already loaded in danielebarchiesi@0: * memory. danielebarchiesi@0: * danielebarchiesi@0: * This hook is not run on cached pages. danielebarchiesi@0: * danielebarchiesi@0: * To add CSS or JS that should be present on all pages, modules should not danielebarchiesi@0: * implement this hook, but declare these files in their .info file. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_boot() danielebarchiesi@0: */ danielebarchiesi@0: function hook_init() { danielebarchiesi@0: // Since this file should only be loaded on the front page, it cannot be danielebarchiesi@0: // declared in the info file. danielebarchiesi@0: if (drupal_is_front_page()) { danielebarchiesi@0: drupal_add_css(drupal_get_path('module', 'foo') . '/foo.css'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Define image toolkits provided by this module. danielebarchiesi@0: * danielebarchiesi@0: * The file which includes each toolkit's functions must be declared as part of danielebarchiesi@0: * the files array in the module .info file so that the registry will find and danielebarchiesi@0: * parse it. danielebarchiesi@0: * danielebarchiesi@0: * The toolkit's functions must be named image_toolkitname_operation(). danielebarchiesi@0: * where the operation may be: danielebarchiesi@0: * - 'load': Required. See image_gd_load() for usage. danielebarchiesi@0: * - 'save': Required. See image_gd_save() for usage. danielebarchiesi@0: * - 'settings': Optional. See image_gd_settings() for usage. danielebarchiesi@0: * - 'resize': Optional. See image_gd_resize() for usage. danielebarchiesi@0: * - 'rotate': Optional. See image_gd_rotate() for usage. danielebarchiesi@0: * - 'crop': Optional. See image_gd_crop() for usage. danielebarchiesi@0: * - 'desaturate': Optional. See image_gd_desaturate() for usage. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array with the toolkit name as keys and sub-arrays with these keys: danielebarchiesi@0: * - 'title': A string with the toolkit's title. danielebarchiesi@0: * - 'available': A Boolean value to indicate that the toolkit is operating danielebarchiesi@0: * properly, e.g. all required libraries exist. danielebarchiesi@0: * danielebarchiesi@0: * @see system_image_toolkits() danielebarchiesi@0: */ danielebarchiesi@0: function hook_image_toolkits() { danielebarchiesi@0: return array( danielebarchiesi@0: 'working' => array( danielebarchiesi@0: 'title' => t('A toolkit that works.'), danielebarchiesi@0: 'available' => TRUE, danielebarchiesi@0: ), danielebarchiesi@0: 'broken' => array( danielebarchiesi@0: 'title' => t('A toolkit that is "broken" and will not be listed.'), danielebarchiesi@0: 'available' => FALSE, danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter an email message created with the drupal_mail() function. danielebarchiesi@0: * danielebarchiesi@0: * hook_mail_alter() allows modification of email messages created and sent danielebarchiesi@0: * with drupal_mail(). Usage examples include adding and/or changing message danielebarchiesi@0: * text, message fields, and message headers. danielebarchiesi@0: * danielebarchiesi@0: * Email messages sent using functions other than drupal_mail() will not danielebarchiesi@0: * invoke hook_mail_alter(). For example, a contributed module directly danielebarchiesi@0: * calling the drupal_mail_system()->mail() or PHP mail() function danielebarchiesi@0: * will not invoke this hook. All core modules use drupal_mail() for danielebarchiesi@0: * messaging, it is best practice but not mandatory in contributed modules. danielebarchiesi@0: * danielebarchiesi@0: * @param $message danielebarchiesi@0: * An array containing the message data. Keys in this array include: danielebarchiesi@0: * - 'id': danielebarchiesi@0: * The drupal_mail() id of the message. Look at module source code or danielebarchiesi@0: * drupal_mail() for possible id values. danielebarchiesi@0: * - 'to': danielebarchiesi@0: * The address or addresses the message will be sent to. The formatting of danielebarchiesi@0: * this string will be validated with the danielebarchiesi@0: * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink danielebarchiesi@0: * - 'from': danielebarchiesi@0: * The address the message will be marked as being from, which is danielebarchiesi@0: * either a custom address or the site-wide default email address. danielebarchiesi@0: * - 'subject': danielebarchiesi@0: * Subject of the email to be sent. This must not contain any newline danielebarchiesi@0: * characters, or the email may not be sent properly. danielebarchiesi@0: * - 'body': danielebarchiesi@0: * An array of strings containing the message text. The message body is danielebarchiesi@0: * created by concatenating the individual array strings into a single text danielebarchiesi@0: * string using "\n\n" as a separator. danielebarchiesi@0: * - 'headers': danielebarchiesi@0: * Associative array containing mail headers, such as From, Sender, danielebarchiesi@0: * MIME-Version, Content-Type, etc. danielebarchiesi@0: * - 'params': danielebarchiesi@0: * An array of optional parameters supplied by the caller of drupal_mail() danielebarchiesi@0: * that is used to build the message before hook_mail_alter() is invoked. danielebarchiesi@0: * - 'language': danielebarchiesi@0: * The language object used to build the message before hook_mail_alter() danielebarchiesi@0: * is invoked. danielebarchiesi@0: * - 'send': danielebarchiesi@0: * Set to FALSE to abort sending this email message. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_mail() danielebarchiesi@0: */ danielebarchiesi@0: function hook_mail_alter(&$message) { danielebarchiesi@0: if ($message['id'] == 'modulename_messagekey') { danielebarchiesi@0: if (!example_notifications_optin($message['to'], $message['id'])) { danielebarchiesi@0: // If the recipient has opted to not receive such messages, cancel danielebarchiesi@0: // sending. danielebarchiesi@0: $message['send'] = FALSE; danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: $message['body'][] = "--\nMail sent out from " . variable_get('site_name', t('Drupal')); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the registry of modules implementing a hook. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked during module_implements(). A module may implement this danielebarchiesi@0: * hook in order to reorder the implementing modules, which are otherwise danielebarchiesi@0: * ordered by the module's system weight. danielebarchiesi@0: * danielebarchiesi@0: * Note that hooks invoked using drupal_alter() can have multiple variations danielebarchiesi@0: * (such as hook_form_alter() and hook_form_FORM_ID_alter()). drupal_alter() danielebarchiesi@0: * will call all such variants defined by a single module in turn. For the danielebarchiesi@0: * purposes of hook_module_implements_alter(), these variants are treated as danielebarchiesi@0: * a single hook. Thus, to ensure that your implementation of danielebarchiesi@0: * hook_form_FORM_ID_alter() is called at the right time, you will have to danielebarchiesi@0: * change the order of hook_form_alter() implementation in danielebarchiesi@0: * hook_module_implements_alter(). danielebarchiesi@0: * danielebarchiesi@0: * @param $implementations danielebarchiesi@0: * An array keyed by the module's name. The value of each item corresponds danielebarchiesi@0: * to a $group, which is usually FALSE, unless the implementation is in a danielebarchiesi@0: * file named $module.$group.inc. danielebarchiesi@0: * @param $hook danielebarchiesi@0: * The name of the module hook being implemented. danielebarchiesi@0: */ danielebarchiesi@0: function hook_module_implements_alter(&$implementations, $hook) { danielebarchiesi@0: if ($hook == 'rdf_mapping') { danielebarchiesi@0: // Move my_module_rdf_mapping() to the end of the list. module_implements() danielebarchiesi@0: // iterates through $implementations with a foreach loop which PHP iterates danielebarchiesi@0: // in the order that the items were added, so to move an item to the end of danielebarchiesi@0: // the array, we remove it and then add it. danielebarchiesi@0: $group = $implementations['my_module']; danielebarchiesi@0: unset($implementations['my_module']); danielebarchiesi@0: $implementations['my_module'] = $group; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return additional themes provided by modules. danielebarchiesi@0: * danielebarchiesi@0: * Only use this hook for testing purposes. Use a hidden MYMODULE_test.module danielebarchiesi@0: * to implement this hook. Testing themes should be hidden, too. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked from _system_rebuild_theme_data() and allows modules to danielebarchiesi@0: * register additional themes outside of the regular 'themes' directories of a danielebarchiesi@0: * Drupal installation. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array. Each key is the system name of a theme and each value danielebarchiesi@0: * is the corresponding path to the theme's .info file. danielebarchiesi@0: */ danielebarchiesi@0: function hook_system_theme_info() { danielebarchiesi@0: $themes['mymodule_test_theme'] = drupal_get_path('module', 'mymodule') . '/mymodule_test_theme/mymodule_test_theme.info'; danielebarchiesi@0: return $themes; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the information parsed from module and theme .info files danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked in _system_rebuild_module_data() and in danielebarchiesi@0: * _system_rebuild_theme_data(). A module may implement this hook in order to danielebarchiesi@0: * add to or alter the data generated by reading the .info file with danielebarchiesi@0: * drupal_parse_info_file(). danielebarchiesi@0: * danielebarchiesi@0: * @param $info danielebarchiesi@0: * The .info file contents, passed by reference so that it can be altered. danielebarchiesi@0: * @param $file danielebarchiesi@0: * Full information about the module or theme, including $file->name, and danielebarchiesi@0: * $file->filename danielebarchiesi@0: * @param $type danielebarchiesi@0: * Either 'module' or 'theme', depending on the type of .info file that was danielebarchiesi@0: * passed. danielebarchiesi@0: */ danielebarchiesi@0: function hook_system_info_alter(&$info, $file, $type) { danielebarchiesi@0: // Only fill this in if the .info file does not define a 'datestamp'. danielebarchiesi@0: if (empty($info['datestamp'])) { danielebarchiesi@0: $info['datestamp'] = filemtime($file->filename); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Define user permissions. danielebarchiesi@0: * danielebarchiesi@0: * This hook can supply permissions that the module defines, so that they danielebarchiesi@0: * can be selected on the user permissions page and used to grant or restrict danielebarchiesi@0: * access to actions the module performs. danielebarchiesi@0: * danielebarchiesi@0: * Permissions are checked using user_access(). danielebarchiesi@0: * danielebarchiesi@0: * For a detailed usage example, see page_example.module. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array whose keys are permission names and whose corresponding values danielebarchiesi@0: * are arrays containing the following key-value pairs: danielebarchiesi@0: * - title: The human-readable name of the permission, to be shown on the danielebarchiesi@0: * permission administration page. This should be wrapped in the t() danielebarchiesi@0: * function so it can be translated. danielebarchiesi@0: * - description: (optional) A description of what the permission does. This danielebarchiesi@0: * should be wrapped in the t() function so it can be translated. danielebarchiesi@0: * - restrict access: (optional) A boolean which can be set to TRUE to danielebarchiesi@0: * indicate that site administrators should restrict access to this danielebarchiesi@0: * permission to trusted users. This should be used for permissions that danielebarchiesi@0: * have inherent security risks across a variety of potential use cases danielebarchiesi@0: * (for example, the "administer filters" and "bypass node access" danielebarchiesi@0: * permissions provided by Drupal core). When set to TRUE, a standard danielebarchiesi@0: * warning message defined in user_admin_permissions() and output via danielebarchiesi@0: * theme_user_permission_description() will be associated with the danielebarchiesi@0: * permission and displayed with it on the permission administration page. danielebarchiesi@0: * Defaults to FALSE. danielebarchiesi@0: * - warning: (optional) A translated warning message to display for this danielebarchiesi@0: * permission on the permission administration page. This warning overrides danielebarchiesi@0: * the automatic warning generated by 'restrict access' being set to TRUE. danielebarchiesi@0: * This should rarely be used, since it is important for all permissions to danielebarchiesi@0: * have a clear, consistent security warning that is the same across the danielebarchiesi@0: * site. Use the 'description' key instead to provide any information that danielebarchiesi@0: * is specific to the permission you are defining. danielebarchiesi@0: * danielebarchiesi@0: * @see theme_user_permission_description() danielebarchiesi@0: */ danielebarchiesi@0: function hook_permission() { danielebarchiesi@0: return array( danielebarchiesi@0: 'administer my module' => array( danielebarchiesi@0: 'title' => t('Administer my module'), danielebarchiesi@0: 'description' => t('Perform administration tasks for my module.'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Register a module (or theme's) theme implementations. danielebarchiesi@0: * danielebarchiesi@0: * The implementations declared by this hook have two purposes: either they danielebarchiesi@0: * specify how a particular render array is to be rendered as HTML (this is danielebarchiesi@0: * usually the case if the theme function is assigned to the render array's danielebarchiesi@0: * #theme property), or they return the HTML that should be returned by an danielebarchiesi@0: * invocation of theme(). See danielebarchiesi@0: * @link http://drupal.org/node/933976 Using the theme layer Drupal 7.x @endlink danielebarchiesi@0: * for more information on how to implement theme hooks. danielebarchiesi@0: * danielebarchiesi@0: * The following parameters are all optional. danielebarchiesi@0: * danielebarchiesi@0: * @param array $existing danielebarchiesi@0: * An array of existing implementations that may be used for override danielebarchiesi@0: * purposes. This is primarily useful for themes that may wish to examine danielebarchiesi@0: * existing implementations to extract data (such as arguments) so that danielebarchiesi@0: * it may properly register its own, higher priority implementations. danielebarchiesi@0: * @param $type danielebarchiesi@0: * Whether a theme, module, etc. is being processed. This is primarily useful danielebarchiesi@0: * so that themes tell if they are the actual theme being called or a parent danielebarchiesi@0: * theme. May be one of: danielebarchiesi@0: * - 'module': A module is being checked for theme implementations. danielebarchiesi@0: * - 'base_theme_engine': A theme engine is being checked for a theme that is danielebarchiesi@0: * a parent of the actual theme being used. danielebarchiesi@0: * - 'theme_engine': A theme engine is being checked for the actual theme danielebarchiesi@0: * being used. danielebarchiesi@0: * - 'base_theme': A base theme is being checked for theme implementations. danielebarchiesi@0: * - 'theme': The actual theme in use is being checked. danielebarchiesi@0: * @param $theme danielebarchiesi@0: * The actual name of theme, module, etc. that is being being processed. danielebarchiesi@0: * @param $path danielebarchiesi@0: * The directory path of the theme or module, so that it doesn't need to be danielebarchiesi@0: * looked up. danielebarchiesi@0: * danielebarchiesi@0: * @return array danielebarchiesi@0: * An associative array of theme hook information. The keys on the outer danielebarchiesi@0: * array are the internal names of the hooks, and the values are arrays danielebarchiesi@0: * containing information about the hook. Each information array must contain danielebarchiesi@0: * either a 'variables' element or a 'render element' element, but not both. danielebarchiesi@0: * Use 'render element' if you are theming a single element or element tree danielebarchiesi@0: * composed of elements, such as a form array, a page array, or a single danielebarchiesi@0: * checkbox element. Use 'variables' if your theme implementation is danielebarchiesi@0: * intended to be called directly through theme() and has multiple arguments danielebarchiesi@0: * for the data and style; in this case, the variables not supplied by the danielebarchiesi@0: * calling function will be given default values and passed to the template danielebarchiesi@0: * or theme function. The returned theme information array can contain the danielebarchiesi@0: * following key/value pairs: danielebarchiesi@0: * - variables: (see above) Each array key is the name of the variable, and danielebarchiesi@0: * the value given is used as the default value if the function calling danielebarchiesi@0: * theme() does not supply it. Template implementations receive each array danielebarchiesi@0: * key as a variable in the template file (so they must be legal PHP danielebarchiesi@0: * variable names). Function implementations are passed the variables in a danielebarchiesi@0: * single $variables function argument. danielebarchiesi@0: * - render element: (see above) The name of the renderable element or element danielebarchiesi@0: * tree to pass to the theme function. This name is used as the name of the danielebarchiesi@0: * variable that holds the renderable element or tree in preprocess and danielebarchiesi@0: * process functions. danielebarchiesi@0: * - file: The file the implementation resides in. This file will be included danielebarchiesi@0: * prior to the theme being rendered, to make sure that the function or danielebarchiesi@0: * preprocess function (as needed) is actually loaded; this makes it danielebarchiesi@0: * possible to split theme functions out into separate files quite easily. danielebarchiesi@0: * - path: Override the path of the file to be used. Ordinarily the module or danielebarchiesi@0: * theme path will be used, but if the file will not be in the default danielebarchiesi@0: * path, include it here. This path should be relative to the Drupal root danielebarchiesi@0: * directory. danielebarchiesi@0: * - template: If specified, this theme implementation is a template, and danielebarchiesi@0: * this is the template file without an extension. Do not put .tpl.php on danielebarchiesi@0: * this file; that extension will be added automatically by the default danielebarchiesi@0: * rendering engine (which is PHPTemplate). If 'path', above, is specified, danielebarchiesi@0: * the template should also be in this path. danielebarchiesi@0: * - function: If specified, this will be the function name to invoke for danielebarchiesi@0: * this implementation. If neither 'template' nor 'function' is specified, danielebarchiesi@0: * a default function name will be assumed. For example, if a module danielebarchiesi@0: * registers the 'node' theme hook, 'theme_node' will be assigned to its danielebarchiesi@0: * function. If the chameleon theme registers the node hook, it will be danielebarchiesi@0: * assigned 'chameleon_node' as its function. danielebarchiesi@0: * - base hook: A string declaring the base theme hook if this theme danielebarchiesi@0: * implementation is actually implementing a suggestion for another theme danielebarchiesi@0: * hook. danielebarchiesi@0: * - pattern: A regular expression pattern to be used to allow this theme danielebarchiesi@0: * implementation to have a dynamic name. The convention is to use __ to danielebarchiesi@0: * differentiate the dynamic portion of the theme. For example, to allow danielebarchiesi@0: * forums to be themed individually, the pattern might be: 'forum__'. Then, danielebarchiesi@0: * when the forum is themed, call: danielebarchiesi@0: * @code danielebarchiesi@0: * theme(array('forum__' . $tid, 'forum'), $forum) danielebarchiesi@0: * @endcode danielebarchiesi@0: * - preprocess functions: A list of functions used to preprocess this data. danielebarchiesi@0: * Ordinarily this won't be used; it's automatically filled in. By default, danielebarchiesi@0: * for a module this will be filled in as template_preprocess_HOOK. For danielebarchiesi@0: * a theme this will be filled in as phptemplate_preprocess and danielebarchiesi@0: * phptemplate_preprocess_HOOK as well as themename_preprocess and danielebarchiesi@0: * themename_preprocess_HOOK. danielebarchiesi@0: * - override preprocess functions: Set to TRUE when a theme does NOT want danielebarchiesi@0: * the standard preprocess functions to run. This can be used to give a danielebarchiesi@0: * theme FULL control over how variables are set. For example, if a theme danielebarchiesi@0: * wants total control over how certain variables in the page.tpl.php are danielebarchiesi@0: * set, this can be set to true. Please keep in mind that when this is used danielebarchiesi@0: * by a theme, that theme becomes responsible for making sure necessary danielebarchiesi@0: * variables are set. danielebarchiesi@0: * - type: (automatically derived) Where the theme hook is defined: danielebarchiesi@0: * 'module', 'theme_engine', or 'theme'. danielebarchiesi@0: * - theme path: (automatically derived) The directory path of the theme or danielebarchiesi@0: * module, so that it doesn't need to be looked up. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_theme_registry_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_theme($existing, $type, $theme, $path) { danielebarchiesi@0: return array( danielebarchiesi@0: 'forum_display' => array( danielebarchiesi@0: 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), danielebarchiesi@0: ), danielebarchiesi@0: 'forum_list' => array( danielebarchiesi@0: 'variables' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL), danielebarchiesi@0: ), danielebarchiesi@0: 'forum_topic_list' => array( danielebarchiesi@0: 'variables' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), danielebarchiesi@0: ), danielebarchiesi@0: 'forum_icon' => array( danielebarchiesi@0: 'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0), danielebarchiesi@0: ), danielebarchiesi@0: 'status_report' => array( danielebarchiesi@0: 'render element' => 'requirements', danielebarchiesi@0: 'file' => 'system.admin.inc', danielebarchiesi@0: ), danielebarchiesi@0: 'system_date_time_settings' => array( danielebarchiesi@0: 'render element' => 'form', danielebarchiesi@0: 'file' => 'system.admin.inc', danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the theme registry information returned from hook_theme(). danielebarchiesi@0: * danielebarchiesi@0: * The theme registry stores information about all available theme hooks, danielebarchiesi@0: * including which callback functions those hooks will call when triggered, danielebarchiesi@0: * what template files are exposed by these hooks, and so on. danielebarchiesi@0: * danielebarchiesi@0: * Note that this hook is only executed as the theme cache is re-built. danielebarchiesi@0: * Changes here will not be visible until the next cache clear. danielebarchiesi@0: * danielebarchiesi@0: * The $theme_registry array is keyed by theme hook name, and contains the danielebarchiesi@0: * information returned from hook_theme(), as well as additional properties danielebarchiesi@0: * added by _theme_process_registry(). danielebarchiesi@0: * danielebarchiesi@0: * For example: danielebarchiesi@0: * @code danielebarchiesi@0: * $theme_registry['user_profile'] = array( danielebarchiesi@0: * 'variables' => array( danielebarchiesi@0: * 'account' => NULL, danielebarchiesi@0: * ), danielebarchiesi@0: * 'template' => 'modules/user/user-profile', danielebarchiesi@0: * 'file' => 'modules/user/user.pages.inc', danielebarchiesi@0: * 'type' => 'module', danielebarchiesi@0: * 'theme path' => 'modules/user', danielebarchiesi@0: * 'preprocess functions' => array( danielebarchiesi@0: * 0 => 'template_preprocess', danielebarchiesi@0: * 1 => 'template_preprocess_user_profile', danielebarchiesi@0: * ), danielebarchiesi@0: * ); danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * @param $theme_registry danielebarchiesi@0: * The entire cache of theme registry information, post-processing. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_theme() danielebarchiesi@0: * @see _theme_process_registry() danielebarchiesi@0: */ danielebarchiesi@0: function hook_theme_registry_alter(&$theme_registry) { danielebarchiesi@0: // Kill the next/previous forum topic navigation links. danielebarchiesi@0: foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) { danielebarchiesi@0: if ($value == 'template_preprocess_forum_topic_navigation') { danielebarchiesi@0: unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return the machine-readable name of the theme to use for the current page. danielebarchiesi@0: * danielebarchiesi@0: * This hook can be used to dynamically set the theme for the current page danielebarchiesi@0: * request. It should be used by modules which need to override the theme danielebarchiesi@0: * based on dynamic conditions (for example, a module which allows the theme to danielebarchiesi@0: * be set based on the current user's role). The return value of this hook will danielebarchiesi@0: * be used on all pages except those which have a valid per-page or per-section danielebarchiesi@0: * theme set via a theme callback function in hook_menu(); the themes on those danielebarchiesi@0: * pages can only be overridden using hook_menu_alter(). danielebarchiesi@0: * danielebarchiesi@0: * Note that returning different themes for the same path may not work with page danielebarchiesi@0: * caching. This is most likely to be a problem if an anonymous user on a given danielebarchiesi@0: * path could have different themes returned under different conditions. danielebarchiesi@0: * danielebarchiesi@0: * Since only one theme can be used at a time, the last (i.e., highest danielebarchiesi@0: * weighted) module which returns a valid theme name from this hook will danielebarchiesi@0: * prevail. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * The machine-readable name of the theme that should be used for the current danielebarchiesi@0: * page request. The value returned from this function will only have an danielebarchiesi@0: * effect if it corresponds to a currently-active theme on the site. Do not danielebarchiesi@0: * return a value if you do not wish to set a custom theme. danielebarchiesi@0: */ danielebarchiesi@0: function hook_custom_theme() { danielebarchiesi@0: // Allow the user to request a particular theme via a query parameter. danielebarchiesi@0: if (isset($_GET['theme'])) { danielebarchiesi@0: return $_GET['theme']; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Register XML-RPC callbacks. danielebarchiesi@0: * danielebarchiesi@0: * This hook lets a module register callback functions to be called when danielebarchiesi@0: * particular XML-RPC methods are invoked by a client. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array which maps XML-RPC methods to Drupal functions. Each array danielebarchiesi@0: * element is either a pair of method => function or an array with four danielebarchiesi@0: * entries: danielebarchiesi@0: * - The XML-RPC method name (for example, module.function). danielebarchiesi@0: * - The Drupal callback function (for example, module_function). danielebarchiesi@0: * - The method signature is an array of XML-RPC types. The first element danielebarchiesi@0: * of this array is the type of return value and then you should write a danielebarchiesi@0: * list of the types of the parameters. XML-RPC types are the following danielebarchiesi@0: * (See the types at http://www.xmlrpc.com/spec): danielebarchiesi@0: * - "boolean": 0 (false) or 1 (true). danielebarchiesi@0: * - "double": a floating point number (for example, -12.214). danielebarchiesi@0: * - "int": a integer number (for example, -12). danielebarchiesi@0: * - "array": an array without keys (for example, array(1, 2, 3)). danielebarchiesi@0: * - "struct": an associative array or an object (for example, danielebarchiesi@0: * array('one' => 1, 'two' => 2)). danielebarchiesi@0: * - "date": when you return a date, then you may either return a danielebarchiesi@0: * timestamp (time(), mktime() etc.) or an ISO8601 timestamp. When danielebarchiesi@0: * date is specified as an input parameter, then you get an object, danielebarchiesi@0: * which is described in the function xmlrpc_date danielebarchiesi@0: * - "base64": a string containing binary data, automatically danielebarchiesi@0: * encoded/decoded automatically. danielebarchiesi@0: * - "string": anything else, typically a string. danielebarchiesi@0: * - A descriptive help string, enclosed in a t() function for translation danielebarchiesi@0: * purposes. danielebarchiesi@0: * Both forms are shown in the example. danielebarchiesi@0: */ danielebarchiesi@0: function hook_xmlrpc() { danielebarchiesi@0: return array( danielebarchiesi@0: 'drupal.login' => 'drupal_login', danielebarchiesi@0: array( danielebarchiesi@0: 'drupal.site.ping', danielebarchiesi@0: 'drupal_directory_ping', danielebarchiesi@0: array('boolean', 'string', 'string', 'string', 'string', 'string'), danielebarchiesi@0: t('Handling ping request')) danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters the definition of XML-RPC methods before they are called. danielebarchiesi@0: * danielebarchiesi@0: * This hook allows modules to modify the callback definition of declared danielebarchiesi@0: * XML-RPC methods, right before they are invoked by a client. Methods may be danielebarchiesi@0: * added, or existing methods may be altered. danielebarchiesi@0: * danielebarchiesi@0: * Note that hook_xmlrpc() supports two distinct and incompatible formats to danielebarchiesi@0: * define a callback, so care must be taken when altering other methods. danielebarchiesi@0: * danielebarchiesi@0: * @param $methods danielebarchiesi@0: * An asssociative array of method callback definitions, as returned from danielebarchiesi@0: * hook_xmlrpc() implementations. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_xmlrpc() danielebarchiesi@0: * @see xmlrpc_server() danielebarchiesi@0: */ danielebarchiesi@0: function hook_xmlrpc_alter(&$methods) { danielebarchiesi@0: // Directly change a simple method. danielebarchiesi@0: $methods['drupal.login'] = 'mymodule_login'; danielebarchiesi@0: danielebarchiesi@0: // Alter complex definitions. danielebarchiesi@0: foreach ($methods as $key => &$method) { danielebarchiesi@0: // Skip simple method definitions. danielebarchiesi@0: if (!is_int($key)) { danielebarchiesi@0: continue; danielebarchiesi@0: } danielebarchiesi@0: // Perform the wanted manipulation. danielebarchiesi@0: if ($method[0] == 'drupal.site.ping') { danielebarchiesi@0: $method[1] = 'mymodule_directory_ping'; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Log an event message. danielebarchiesi@0: * danielebarchiesi@0: * This hook allows modules to route log events to custom destinations, such as danielebarchiesi@0: * SMS, Email, pager, syslog, ...etc. danielebarchiesi@0: * danielebarchiesi@0: * @param $log_entry danielebarchiesi@0: * An associative array containing the following keys: danielebarchiesi@0: * - type: The type of message for this entry. danielebarchiesi@0: * - user: The user object for the user who was logged in when the event danielebarchiesi@0: * happened. danielebarchiesi@0: * - uid: The user ID for the user who was logged in when the event happened. danielebarchiesi@0: * - request_uri: The request URI for the page the event happened in. danielebarchiesi@0: * - referer: The page that referred the user to the page where the event danielebarchiesi@0: * occurred. danielebarchiesi@0: * - ip: The IP address where the request for the page came from. danielebarchiesi@0: * - timestamp: The UNIX timestamp of the date/time the event occurred. danielebarchiesi@0: * - severity: The severity of the message; one of the following values as danielebarchiesi@0: * defined in @link http://www.faqs.org/rfcs/rfc3164.html RFC 3164: @endlink danielebarchiesi@0: * - WATCHDOG_EMERGENCY: Emergency, system is unusable. danielebarchiesi@0: * - WATCHDOG_ALERT: Alert, action must be taken immediately. danielebarchiesi@0: * - WATCHDOG_CRITICAL: Critical conditions. danielebarchiesi@0: * - WATCHDOG_ERROR: Error conditions. danielebarchiesi@0: * - WATCHDOG_WARNING: Warning conditions. danielebarchiesi@0: * - WATCHDOG_NOTICE: Normal but significant conditions. danielebarchiesi@0: * - WATCHDOG_INFO: Informational messages. danielebarchiesi@0: * - WATCHDOG_DEBUG: Debug-level messages. danielebarchiesi@0: * - link: An optional link provided by the module that called the watchdog() danielebarchiesi@0: * function. danielebarchiesi@0: * - message: The text of the message to be logged. Variables in the message danielebarchiesi@0: * are indicated by using placeholder strings alongside the variables danielebarchiesi@0: * argument to declare the value of the placeholders. See t() for danielebarchiesi@0: * documentation on how the message and variable parameters interact. danielebarchiesi@0: * - variables: An array of variables to be inserted into the message on danielebarchiesi@0: * display. Will be NULL or missing if a message is already translated or if danielebarchiesi@0: * the message is not possible to translate. danielebarchiesi@0: */ danielebarchiesi@0: function hook_watchdog(array $log_entry) { danielebarchiesi@0: global $base_url, $language; danielebarchiesi@0: danielebarchiesi@0: $severity_list = array( danielebarchiesi@0: WATCHDOG_EMERGENCY => t('Emergency'), danielebarchiesi@0: WATCHDOG_ALERT => t('Alert'), danielebarchiesi@0: WATCHDOG_CRITICAL => t('Critical'), danielebarchiesi@0: WATCHDOG_ERROR => t('Error'), danielebarchiesi@0: WATCHDOG_WARNING => t('Warning'), danielebarchiesi@0: WATCHDOG_NOTICE => t('Notice'), danielebarchiesi@0: WATCHDOG_INFO => t('Info'), danielebarchiesi@0: WATCHDOG_DEBUG => t('Debug'), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: $to = 'someone@example.com'; danielebarchiesi@0: $params = array(); danielebarchiesi@0: $params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array( danielebarchiesi@0: '@site_name' => variable_get('site_name', 'Drupal'), danielebarchiesi@0: '@severity_desc' => $severity_list[$log_entry['severity']], danielebarchiesi@0: )); danielebarchiesi@0: danielebarchiesi@0: $params['message'] = "\nSite: @base_url"; danielebarchiesi@0: $params['message'] .= "\nSeverity: (@severity) @severity_desc"; danielebarchiesi@0: $params['message'] .= "\nTimestamp: @timestamp"; danielebarchiesi@0: $params['message'] .= "\nType: @type"; danielebarchiesi@0: $params['message'] .= "\nIP Address: @ip"; danielebarchiesi@0: $params['message'] .= "\nRequest URI: @request_uri"; danielebarchiesi@0: $params['message'] .= "\nReferrer URI: @referer_uri"; danielebarchiesi@0: $params['message'] .= "\nUser: (@uid) @name"; danielebarchiesi@0: $params['message'] .= "\nLink: @link"; danielebarchiesi@0: $params['message'] .= "\nMessage: \n\n@message"; danielebarchiesi@0: danielebarchiesi@0: $params['message'] = t($params['message'], array( danielebarchiesi@0: '@base_url' => $base_url, danielebarchiesi@0: '@severity' => $log_entry['severity'], danielebarchiesi@0: '@severity_desc' => $severity_list[$log_entry['severity']], danielebarchiesi@0: '@timestamp' => format_date($log_entry['timestamp']), danielebarchiesi@0: '@type' => $log_entry['type'], danielebarchiesi@0: '@ip' => $log_entry['ip'], danielebarchiesi@0: '@request_uri' => $log_entry['request_uri'], danielebarchiesi@0: '@referer_uri' => $log_entry['referer'], danielebarchiesi@0: '@uid' => $log_entry['uid'], danielebarchiesi@0: '@name' => $log_entry['user']->name, danielebarchiesi@0: '@link' => strip_tags($log_entry['link']), danielebarchiesi@0: '@message' => strip_tags($log_entry['message']), danielebarchiesi@0: )); danielebarchiesi@0: danielebarchiesi@0: drupal_mail('emaillog', 'entry', $to, $language, $params); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Prepare a message based on parameters; called from drupal_mail(). danielebarchiesi@0: * danielebarchiesi@0: * Note that hook_mail(), unlike hook_mail_alter(), is only called on the danielebarchiesi@0: * $module argument to drupal_mail(), not all modules. danielebarchiesi@0: * danielebarchiesi@0: * @param $key danielebarchiesi@0: * An identifier of the mail. danielebarchiesi@0: * @param $message danielebarchiesi@0: * An array to be filled in. Elements in this array include: danielebarchiesi@0: * - id: An ID to identify the mail sent. Look at module source code danielebarchiesi@0: * or drupal_mail() for possible id values. danielebarchiesi@0: * - to: The address or addresses the message will be sent to. The formatting danielebarchiesi@0: * of this string will be validated with the danielebarchiesi@0: * @link http://php.net/manual/filter.filters.validate.php PHP e-mail validation filter. @endlink danielebarchiesi@0: * - subject: Subject of the e-mail to be sent. This must not contain any danielebarchiesi@0: * newline characters, or the mail may not be sent properly. drupal_mail() danielebarchiesi@0: * sets this to an empty string when the hook is invoked. danielebarchiesi@0: * - body: An array of lines containing the message to be sent. Drupal will danielebarchiesi@0: * format the correct line endings for you. drupal_mail() sets this to an danielebarchiesi@0: * empty array when the hook is invoked. danielebarchiesi@0: * - from: The address the message will be marked as being from, which is danielebarchiesi@0: * set by drupal_mail() to either a custom address or the site-wide danielebarchiesi@0: * default email address when the hook is invoked. danielebarchiesi@0: * - headers: Associative array containing mail headers, such as From, danielebarchiesi@0: * Sender, MIME-Version, Content-Type, etc. drupal_mail() pre-fills danielebarchiesi@0: * several headers in this array. danielebarchiesi@0: * @param $params danielebarchiesi@0: * An array of parameters supplied by the caller of drupal_mail(). danielebarchiesi@0: */ danielebarchiesi@0: function hook_mail($key, &$message, $params) { danielebarchiesi@0: $account = $params['account']; danielebarchiesi@0: $context = $params['context']; danielebarchiesi@0: $variables = array( danielebarchiesi@0: '%site_name' => variable_get('site_name', 'Drupal'), danielebarchiesi@0: '%username' => format_username($account), danielebarchiesi@0: ); danielebarchiesi@0: if ($context['hook'] == 'taxonomy') { danielebarchiesi@0: $entity = $params['entity']; danielebarchiesi@0: $vocabulary = taxonomy_vocabulary_load($entity->vid); danielebarchiesi@0: $variables += array( danielebarchiesi@0: '%term_name' => $entity->name, danielebarchiesi@0: '%term_description' => $entity->description, danielebarchiesi@0: '%term_id' => $entity->tid, danielebarchiesi@0: '%vocabulary_name' => $vocabulary->name, danielebarchiesi@0: '%vocabulary_description' => $vocabulary->description, danielebarchiesi@0: '%vocabulary_id' => $vocabulary->vid, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Node-based variable translation is only available if we have a node. danielebarchiesi@0: if (isset($params['node'])) { danielebarchiesi@0: $node = $params['node']; danielebarchiesi@0: $variables += array( danielebarchiesi@0: '%uid' => $node->uid, danielebarchiesi@0: '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)), danielebarchiesi@0: '%node_type' => node_type_get_name($node), danielebarchiesi@0: '%title' => $node->title, danielebarchiesi@0: '%teaser' => $node->teaser, danielebarchiesi@0: '%body' => $node->body, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: $subject = strtr($context['subject'], $variables); danielebarchiesi@0: $body = strtr($context['message'], $variables); danielebarchiesi@0: $message['subject'] .= str_replace(array("\r", "\n"), '', $subject); danielebarchiesi@0: $message['body'][] = drupal_html_to_text($body); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Add a list of cache tables to be cleared. danielebarchiesi@0: * danielebarchiesi@0: * This hook allows your module to add cache table names to the list of cache danielebarchiesi@0: * tables that will be cleared by the Clear button on the Performance page or danielebarchiesi@0: * whenever drupal_flush_all_caches is invoked. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array of cache table names. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_flush_all_caches() danielebarchiesi@0: */ danielebarchiesi@0: function hook_flush_caches() { danielebarchiesi@0: return array('cache_example'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary actions after modules are installed. danielebarchiesi@0: * danielebarchiesi@0: * This function differs from hook_install() in that it gives all other modules danielebarchiesi@0: * a chance to perform actions when a module is installed, whereas danielebarchiesi@0: * hook_install() is only called on the module actually being installed. See danielebarchiesi@0: * module_enable() for a detailed description of the order in which install and danielebarchiesi@0: * enable hooks are invoked. danielebarchiesi@0: * danielebarchiesi@0: * @param $modules danielebarchiesi@0: * An array of the modules that were installed. danielebarchiesi@0: * danielebarchiesi@0: * @see module_enable() danielebarchiesi@0: * @see hook_modules_enabled() danielebarchiesi@0: * @see hook_install() danielebarchiesi@0: */ danielebarchiesi@0: function hook_modules_installed($modules) { danielebarchiesi@0: if (in_array('lousy_module', $modules)) { danielebarchiesi@0: variable_set('lousy_module_conflicting_variable', FALSE); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary actions after modules are enabled. danielebarchiesi@0: * danielebarchiesi@0: * This function differs from hook_enable() in that it gives all other modules a danielebarchiesi@0: * chance to perform actions when modules are enabled, whereas hook_enable() is danielebarchiesi@0: * only called on the module actually being enabled. See module_enable() for a danielebarchiesi@0: * detailed description of the order in which install and enable hooks are danielebarchiesi@0: * invoked. danielebarchiesi@0: * danielebarchiesi@0: * @param $modules danielebarchiesi@0: * An array of the modules that were enabled. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_enable() danielebarchiesi@0: * @see hook_modules_installed() danielebarchiesi@0: * @see module_enable() danielebarchiesi@0: */ danielebarchiesi@0: function hook_modules_enabled($modules) { danielebarchiesi@0: if (in_array('lousy_module', $modules)) { danielebarchiesi@0: drupal_set_message(t('mymodule is not compatible with lousy_module'), 'error'); danielebarchiesi@0: mymodule_disable_functionality(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary actions after modules are disabled. danielebarchiesi@0: * danielebarchiesi@0: * This function differs from hook_disable() in that it gives all other modules danielebarchiesi@0: * a chance to perform actions when modules are disabled, whereas hook_disable() danielebarchiesi@0: * is only called on the module actually being disabled. danielebarchiesi@0: * danielebarchiesi@0: * @param $modules danielebarchiesi@0: * An array of the modules that were disabled. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_disable() danielebarchiesi@0: * @see hook_modules_uninstalled() danielebarchiesi@0: */ danielebarchiesi@0: function hook_modules_disabled($modules) { danielebarchiesi@0: if (in_array('lousy_module', $modules)) { danielebarchiesi@0: mymodule_enable_functionality(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary actions after modules are uninstalled. danielebarchiesi@0: * danielebarchiesi@0: * This function differs from hook_uninstall() in that it gives all other danielebarchiesi@0: * modules a chance to perform actions when a module is uninstalled, whereas danielebarchiesi@0: * hook_uninstall() is only called on the module actually being uninstalled. danielebarchiesi@0: * danielebarchiesi@0: * It is recommended that you implement this hook if your module stores danielebarchiesi@0: * data that may have been set by other modules. danielebarchiesi@0: * danielebarchiesi@0: * @param $modules danielebarchiesi@0: * An array of the modules that were uninstalled. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_uninstall() danielebarchiesi@0: * @see hook_modules_disabled() danielebarchiesi@0: */ danielebarchiesi@0: function hook_modules_uninstalled($modules) { danielebarchiesi@0: foreach ($modules as $module) { danielebarchiesi@0: db_delete('mymodule_table') danielebarchiesi@0: ->condition('module', $module) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: mymodule_cache_rebuild(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Registers PHP stream wrapper implementations associated with a module. danielebarchiesi@0: * danielebarchiesi@0: * Provide a facility for managing and querying user-defined stream wrappers danielebarchiesi@0: * in PHP. PHP's internal stream_get_wrappers() doesn't return the class danielebarchiesi@0: * registered to handle a stream, which we need to be able to find the handler danielebarchiesi@0: * for class instantiation. danielebarchiesi@0: * danielebarchiesi@0: * If a module registers a scheme that is already registered with PHP, it will danielebarchiesi@0: * be unregistered and replaced with the specified class. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * A nested array, keyed first by scheme name ("public" for "public://"), danielebarchiesi@0: * then keyed by the following values: danielebarchiesi@0: * - 'name' A short string to name the wrapper. danielebarchiesi@0: * - 'class' A string specifying the PHP class that implements the danielebarchiesi@0: * DrupalStreamWrapperInterface interface. danielebarchiesi@0: * - 'description' A string with a short description of what the wrapper does. danielebarchiesi@0: * - 'type' (Optional) A bitmask of flags indicating what type of streams this danielebarchiesi@0: * wrapper will access - local or remote, readable and/or writeable, etc. danielebarchiesi@0: * Many shortcut constants are defined in stream_wrappers.inc. Defaults to danielebarchiesi@0: * STREAM_WRAPPERS_NORMAL which includes all of these bit flags: danielebarchiesi@0: * - STREAM_WRAPPERS_READ danielebarchiesi@0: * - STREAM_WRAPPERS_WRITE danielebarchiesi@0: * - STREAM_WRAPPERS_VISIBLE danielebarchiesi@0: * danielebarchiesi@0: * @see file_get_stream_wrappers() danielebarchiesi@0: * @see hook_stream_wrappers_alter() danielebarchiesi@0: * @see system_stream_wrappers() danielebarchiesi@0: */ danielebarchiesi@0: function hook_stream_wrappers() { danielebarchiesi@0: return array( danielebarchiesi@0: 'public' => array( danielebarchiesi@0: 'name' => t('Public files'), danielebarchiesi@0: 'class' => 'DrupalPublicStreamWrapper', danielebarchiesi@0: 'description' => t('Public local files served by the webserver.'), danielebarchiesi@0: 'type' => STREAM_WRAPPERS_LOCAL_NORMAL, danielebarchiesi@0: ), danielebarchiesi@0: 'private' => array( danielebarchiesi@0: 'name' => t('Private files'), danielebarchiesi@0: 'class' => 'DrupalPrivateStreamWrapper', danielebarchiesi@0: 'description' => t('Private local files served by Drupal.'), danielebarchiesi@0: 'type' => STREAM_WRAPPERS_LOCAL_NORMAL, danielebarchiesi@0: ), danielebarchiesi@0: 'temp' => array( danielebarchiesi@0: 'name' => t('Temporary files'), danielebarchiesi@0: 'class' => 'DrupalTempStreamWrapper', danielebarchiesi@0: 'description' => t('Temporary local files for upload and previews.'), danielebarchiesi@0: 'type' => STREAM_WRAPPERS_LOCAL_HIDDEN, danielebarchiesi@0: ), danielebarchiesi@0: 'cdn' => array( danielebarchiesi@0: 'name' => t('Content delivery network files'), danielebarchiesi@0: 'class' => 'MyModuleCDNStreamWrapper', danielebarchiesi@0: 'description' => t('Files served by a content delivery network.'), danielebarchiesi@0: // 'type' can be omitted to use the default of STREAM_WRAPPERS_NORMAL danielebarchiesi@0: ), danielebarchiesi@0: 'youtube' => array( danielebarchiesi@0: 'name' => t('YouTube video'), danielebarchiesi@0: 'class' => 'MyModuleYouTubeStreamWrapper', danielebarchiesi@0: 'description' => t('Video streamed from YouTube.'), danielebarchiesi@0: // A module implementing YouTube integration may decide to support using danielebarchiesi@0: // the YouTube API for uploading video, but here, we assume that this danielebarchiesi@0: // particular module only supports playing YouTube video. danielebarchiesi@0: 'type' => STREAM_WRAPPERS_READ_VISIBLE, danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters the list of PHP stream wrapper implementations. danielebarchiesi@0: * danielebarchiesi@0: * @see file_get_stream_wrappers() danielebarchiesi@0: * @see hook_stream_wrappers() danielebarchiesi@0: */ danielebarchiesi@0: function hook_stream_wrappers_alter(&$wrappers) { danielebarchiesi@0: // Change the name of private files to reflect the performance. danielebarchiesi@0: $wrappers['private']['name'] = t('Slow files'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Load additional information into file objects. danielebarchiesi@0: * danielebarchiesi@0: * file_load_multiple() calls this hook to allow modules to load danielebarchiesi@0: * additional information into each file. danielebarchiesi@0: * danielebarchiesi@0: * @param $files danielebarchiesi@0: * An array of file objects, indexed by fid. danielebarchiesi@0: * danielebarchiesi@0: * @see file_load_multiple() danielebarchiesi@0: * @see file_load() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_load($files) { danielebarchiesi@0: // Add the upload specific data into the file object. danielebarchiesi@0: $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC); danielebarchiesi@0: foreach ($result as $record) { danielebarchiesi@0: foreach ($record as $key => $value) { danielebarchiesi@0: $files[$record['fid']]->$key = $value; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Check that files meet a given criteria. danielebarchiesi@0: * danielebarchiesi@0: * This hook lets modules perform additional validation on files. They're able danielebarchiesi@0: * to report a failure by returning one or more error messages. danielebarchiesi@0: * danielebarchiesi@0: * @param $file danielebarchiesi@0: * The file object being validated. danielebarchiesi@0: * @return danielebarchiesi@0: * An array of error messages. If there are no problems with the file return danielebarchiesi@0: * an empty array. danielebarchiesi@0: * danielebarchiesi@0: * @see file_validate() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_validate($file) { danielebarchiesi@0: $errors = array(); danielebarchiesi@0: danielebarchiesi@0: if (empty($file->filename)) { danielebarchiesi@0: $errors[] = t("The file's name is empty. Please give a name to the file."); danielebarchiesi@0: } danielebarchiesi@0: if (strlen($file->filename) > 255) { danielebarchiesi@0: $errors[] = t("The file's name exceeds the 255 characters limit. Please rename the file and try again."); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $errors; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on a file being inserted or updated. danielebarchiesi@0: * danielebarchiesi@0: * This hook is called when a file has been added to the database. The hook danielebarchiesi@0: * doesn't distinguish between files created as a result of a copy or those danielebarchiesi@0: * created by an upload. danielebarchiesi@0: * danielebarchiesi@0: * @param $file danielebarchiesi@0: * The file that has just been created. danielebarchiesi@0: * danielebarchiesi@0: * @see file_save() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_presave($file) { danielebarchiesi@0: // Change the file timestamp to an hour prior. danielebarchiesi@0: $file->timestamp -= 3600; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Respond to a file being added. danielebarchiesi@0: * danielebarchiesi@0: * This hook is called after a file has been added to the database. The hook danielebarchiesi@0: * doesn't distinguish between files created as a result of a copy or those danielebarchiesi@0: * created by an upload. danielebarchiesi@0: * danielebarchiesi@0: * @param $file danielebarchiesi@0: * The file that has been added. danielebarchiesi@0: * danielebarchiesi@0: * @see file_save() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_insert($file) { danielebarchiesi@0: // Add a message to the log, if the file is a jpg danielebarchiesi@0: $validate = file_validate_extensions($file, 'jpg'); danielebarchiesi@0: if (empty($validate)) { danielebarchiesi@0: watchdog('file', 'A jpg has been added.'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Respond to a file being updated. danielebarchiesi@0: * danielebarchiesi@0: * This hook is called when file_save() is called on an existing file. danielebarchiesi@0: * danielebarchiesi@0: * @param $file danielebarchiesi@0: * The file that has just been updated. danielebarchiesi@0: * danielebarchiesi@0: * @see file_save() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_update($file) { danielebarchiesi@0: $file_user = user_load($file->uid); danielebarchiesi@0: // Make sure that the file name starts with the owner's user name. danielebarchiesi@0: if (strpos($file->filename, $file_user->name) !== 0) { danielebarchiesi@0: $old_filename = $file->filename; danielebarchiesi@0: $file->filename = $file_user->name . '_' . $file->filename; danielebarchiesi@0: $file->save(); danielebarchiesi@0: danielebarchiesi@0: watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->filename))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Respond to a file that has been copied. danielebarchiesi@0: * danielebarchiesi@0: * @param $file danielebarchiesi@0: * The newly copied file object. danielebarchiesi@0: * @param $source danielebarchiesi@0: * The original file before the copy. danielebarchiesi@0: * danielebarchiesi@0: * @see file_copy() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_copy($file, $source) { danielebarchiesi@0: $file_user = user_load($file->uid); danielebarchiesi@0: // Make sure that the file name starts with the owner's user name. danielebarchiesi@0: if (strpos($file->filename, $file_user->name) !== 0) { danielebarchiesi@0: $file->filename = $file_user->name . '_' . $file->filename; danielebarchiesi@0: $file->save(); danielebarchiesi@0: danielebarchiesi@0: watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Respond to a file that has been moved. danielebarchiesi@0: * danielebarchiesi@0: * @param $file danielebarchiesi@0: * The updated file object after the move. danielebarchiesi@0: * @param $source danielebarchiesi@0: * The original file object before the move. danielebarchiesi@0: * danielebarchiesi@0: * @see file_move() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_move($file, $source) { danielebarchiesi@0: $file_user = user_load($file->uid); danielebarchiesi@0: // Make sure that the file name starts with the owner's user name. danielebarchiesi@0: if (strpos($file->filename, $file_user->name) !== 0) { danielebarchiesi@0: $file->filename = $file_user->name . '_' . $file->filename; danielebarchiesi@0: $file->save(); danielebarchiesi@0: danielebarchiesi@0: watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Respond to a file being deleted. danielebarchiesi@0: * danielebarchiesi@0: * @param $file danielebarchiesi@0: * The file that has just been deleted. danielebarchiesi@0: * danielebarchiesi@0: * @see file_delete() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_delete($file) { danielebarchiesi@0: // Delete all information associated with the file. danielebarchiesi@0: db_delete('upload')->condition('fid', $file->fid)->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Control access to private file downloads and specify HTTP headers. danielebarchiesi@0: * danielebarchiesi@0: * This hook allows modules enforce permissions on file downloads when the danielebarchiesi@0: * private file download method is selected. Modules can also provide headers danielebarchiesi@0: * to specify information like the file's name or MIME type. danielebarchiesi@0: * danielebarchiesi@0: * @param $uri danielebarchiesi@0: * The URI of the file. danielebarchiesi@0: * @return danielebarchiesi@0: * If the user does not have permission to access the file, return -1. If the danielebarchiesi@0: * user has permission, return an array with the appropriate headers. If the danielebarchiesi@0: * file is not controlled by the current module, the return value should be danielebarchiesi@0: * NULL. danielebarchiesi@0: * danielebarchiesi@0: * @see file_download() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_download($uri) { danielebarchiesi@0: // Check if the file is controlled by the current module. danielebarchiesi@0: if (!file_prepare_directory($uri)) { danielebarchiesi@0: $uri = FALSE; danielebarchiesi@0: } danielebarchiesi@0: if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) { danielebarchiesi@0: if (!user_access('access user profiles')) { danielebarchiesi@0: // Access to the file is denied. danielebarchiesi@0: return -1; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $info = image_get_info($uri); danielebarchiesi@0: return array('Content-Type' => $info['mime_type']); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the URL to a file. danielebarchiesi@0: * danielebarchiesi@0: * This hook is called from file_create_url(), and is called fairly danielebarchiesi@0: * frequently (10+ times per page), depending on how many files there are in a danielebarchiesi@0: * given page. danielebarchiesi@0: * If CSS and JS aggregation are disabled, this can become very frequently danielebarchiesi@0: * (50+ times per page) so performance is critical. danielebarchiesi@0: * danielebarchiesi@0: * This function should alter the URI, if it wants to rewrite the file URL. danielebarchiesi@0: * danielebarchiesi@0: * @param $uri danielebarchiesi@0: * The URI to a file for which we need an external URL, or the path to a danielebarchiesi@0: * shipped file. danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_url_alter(&$uri) { danielebarchiesi@0: global $user; danielebarchiesi@0: danielebarchiesi@0: // User 1 will always see the local file in this example. danielebarchiesi@0: if ($user->uid == 1) { danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $cdn1 = 'http://cdn1.example.com'; danielebarchiesi@0: $cdn2 = 'http://cdn2.example.com'; danielebarchiesi@0: $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png'); danielebarchiesi@0: danielebarchiesi@0: // Most CDNs don't support private file transfers without a lot of hassle, danielebarchiesi@0: // so don't support this in the common case. danielebarchiesi@0: $schemes = array('public'); danielebarchiesi@0: danielebarchiesi@0: $scheme = file_uri_scheme($uri); danielebarchiesi@0: danielebarchiesi@0: // Only serve shipped files and public created files from the CDN. danielebarchiesi@0: if (!$scheme || in_array($scheme, $schemes)) { danielebarchiesi@0: // Shipped files. danielebarchiesi@0: if (!$scheme) { danielebarchiesi@0: $path = $uri; danielebarchiesi@0: } danielebarchiesi@0: // Public created files. danielebarchiesi@0: else { danielebarchiesi@0: $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme); danielebarchiesi@0: $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Clean up Windows paths. danielebarchiesi@0: $path = str_replace('\\', '/', $path); danielebarchiesi@0: danielebarchiesi@0: // Serve files with one of the CDN extensions from CDN 1, all others from danielebarchiesi@0: // CDN 2. danielebarchiesi@0: $pathinfo = pathinfo($path); danielebarchiesi@0: if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], $cdn_extensions)) { danielebarchiesi@0: $uri = $cdn1 . '/' . $path; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $uri = $cdn2 . '/' . $path; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Check installation requirements and do status reporting. danielebarchiesi@0: * danielebarchiesi@0: * This hook has three closely related uses, determined by the $phase argument: danielebarchiesi@0: * - Checking installation requirements ($phase == 'install'). danielebarchiesi@0: * - Checking update requirements ($phase == 'update'). danielebarchiesi@0: * - Status reporting ($phase == 'runtime'). danielebarchiesi@0: * danielebarchiesi@0: * Note that this hook, like all others dealing with installation and updates, danielebarchiesi@0: * must reside in a module_name.install file, or it will not properly abort danielebarchiesi@0: * the installation of the module if a critical requirement is missing. danielebarchiesi@0: * danielebarchiesi@0: * During the 'install' phase, modules can for example assert that danielebarchiesi@0: * library or server versions are available or sufficient. danielebarchiesi@0: * Note that the installation of a module can happen during installation of danielebarchiesi@0: * Drupal itself (by install.php) with an installation profile or later by hand. danielebarchiesi@0: * As a consequence, install-time requirements must be checked without access danielebarchiesi@0: * to the full Drupal API, because it is not available during install.php. danielebarchiesi@0: * For localization you should for example use $t = get_t() to danielebarchiesi@0: * retrieve the appropriate localization function name (t() or st()). danielebarchiesi@0: * If a requirement has a severity of REQUIREMENT_ERROR, install.php will abort danielebarchiesi@0: * or at least the module will not install. danielebarchiesi@0: * Other severity levels have no effect on the installation. danielebarchiesi@0: * Module dependencies do not belong to these installation requirements, danielebarchiesi@0: * but should be defined in the module's .info file. danielebarchiesi@0: * danielebarchiesi@0: * The 'runtime' phase is not limited to pure installation requirements danielebarchiesi@0: * but can also be used for more general status information like maintenance danielebarchiesi@0: * tasks and security issues. danielebarchiesi@0: * The returned 'requirements' will be listed on the status report in the danielebarchiesi@0: * administration section, with indication of the severity level. danielebarchiesi@0: * Moreover, any requirement with a severity of REQUIREMENT_ERROR severity will danielebarchiesi@0: * result in a notice on the administration configuration page. danielebarchiesi@0: * danielebarchiesi@0: * @param $phase danielebarchiesi@0: * The phase in which requirements are checked: danielebarchiesi@0: * - install: The module is being installed. danielebarchiesi@0: * - update: The module is enabled and update.php is run. danielebarchiesi@0: * - runtime: The runtime requirements are being checked and shown on the danielebarchiesi@0: * status report page. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array where the keys are arbitrary but must be unique (it danielebarchiesi@0: * is suggested to use the module short name as a prefix) and the values are danielebarchiesi@0: * themselves associative arrays with the following elements: danielebarchiesi@0: * - title: The name of the requirement. danielebarchiesi@0: * - value: The current value (e.g., version, time, level, etc). During danielebarchiesi@0: * install phase, this should only be used for version numbers, do not set danielebarchiesi@0: * it if not applicable. danielebarchiesi@0: * - description: The description of the requirement/status. danielebarchiesi@0: * - severity: The requirement's result/severity level, one of: danielebarchiesi@0: * - REQUIREMENT_INFO: For info only. danielebarchiesi@0: * - REQUIREMENT_OK: The requirement is satisfied. danielebarchiesi@0: * - REQUIREMENT_WARNING: The requirement failed with a warning. danielebarchiesi@0: * - REQUIREMENT_ERROR: The requirement failed with an error. danielebarchiesi@0: */ danielebarchiesi@0: function hook_requirements($phase) { danielebarchiesi@0: $requirements = array(); danielebarchiesi@0: // Ensure translations don't break during installation. danielebarchiesi@0: $t = get_t(); danielebarchiesi@0: danielebarchiesi@0: // Report Drupal version danielebarchiesi@0: if ($phase == 'runtime') { danielebarchiesi@0: $requirements['drupal'] = array( danielebarchiesi@0: 'title' => $t('Drupal'), danielebarchiesi@0: 'value' => VERSION, danielebarchiesi@0: 'severity' => REQUIREMENT_INFO danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Test PHP version danielebarchiesi@0: $requirements['php'] = array( danielebarchiesi@0: 'title' => $t('PHP'), danielebarchiesi@0: 'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/reports/status/php') : phpversion(), danielebarchiesi@0: ); danielebarchiesi@0: if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) { danielebarchiesi@0: $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP)); danielebarchiesi@0: $requirements['php']['severity'] = REQUIREMENT_ERROR; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Report cron status danielebarchiesi@0: if ($phase == 'runtime') { danielebarchiesi@0: $cron_last = variable_get('cron_last'); danielebarchiesi@0: danielebarchiesi@0: if (is_numeric($cron_last)) { danielebarchiesi@0: $requirements['cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last))); danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $requirements['cron'] = array( danielebarchiesi@0: 'description' => $t('Cron has not run. It appears cron jobs have not been setup on your system. Check the help pages for configuring cron jobs.', array('@url' => 'http://drupal.org/cron')), danielebarchiesi@0: 'severity' => REQUIREMENT_ERROR, danielebarchiesi@0: 'value' => $t('Never run'), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $requirements['cron']['description'] .= ' ' . $t('You can run cron manually.', array('@cron' => url('admin/reports/status/run-cron'))); danielebarchiesi@0: danielebarchiesi@0: $requirements['cron']['title'] = $t('Cron maintenance tasks'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $requirements; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Define the current version of the database schema. danielebarchiesi@0: * danielebarchiesi@0: * A Drupal schema definition is an array structure representing one or danielebarchiesi@0: * more tables and their related keys and indexes. A schema is defined by danielebarchiesi@0: * hook_schema() which must live in your module's .install file. danielebarchiesi@0: * danielebarchiesi@0: * This hook is called at install and uninstall time, and in the latter danielebarchiesi@0: * case, it cannot rely on the .module file being loaded or hooks being known. danielebarchiesi@0: * If the .module file is needed, it may be loaded with drupal_load(). danielebarchiesi@0: * danielebarchiesi@0: * The tables declared by this hook will be automatically created when danielebarchiesi@0: * the module is first enabled, and removed when the module is uninstalled. danielebarchiesi@0: * This happens before hook_install() is invoked, and after hook_uninstall() danielebarchiesi@0: * is invoked, respectively. danielebarchiesi@0: * danielebarchiesi@0: * By declaring the tables used by your module via an implementation of danielebarchiesi@0: * hook_schema(), these tables will be available on all supported database danielebarchiesi@0: * engines. You don't have to deal with the different SQL dialects for table danielebarchiesi@0: * creation and alteration of the supported database engines. danielebarchiesi@0: * danielebarchiesi@0: * See the Schema API Handbook at http://drupal.org/node/146843 for danielebarchiesi@0: * details on schema definition structures. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * A schema definition structure array. For each element of the danielebarchiesi@0: * array, the key is a table name and the value is a table structure danielebarchiesi@0: * definition. danielebarchiesi@0: * danielebarchiesi@0: * @ingroup schemaapi danielebarchiesi@0: */ danielebarchiesi@0: function hook_schema() { danielebarchiesi@0: $schema['node'] = array( danielebarchiesi@0: // example (partial) specification for table "node" danielebarchiesi@0: 'description' => 'The base table for nodes.', danielebarchiesi@0: 'fields' => array( danielebarchiesi@0: 'nid' => array( danielebarchiesi@0: 'description' => 'The primary identifier for a node.', danielebarchiesi@0: 'type' => 'serial', danielebarchiesi@0: 'unsigned' => TRUE, danielebarchiesi@0: 'not null' => TRUE, danielebarchiesi@0: ), danielebarchiesi@0: 'vid' => array( danielebarchiesi@0: 'description' => 'The current {node_revision}.vid version identifier.', danielebarchiesi@0: 'type' => 'int', danielebarchiesi@0: 'unsigned' => TRUE, danielebarchiesi@0: 'not null' => TRUE, danielebarchiesi@0: 'default' => 0, danielebarchiesi@0: ), danielebarchiesi@0: 'type' => array( danielebarchiesi@0: 'description' => 'The {node_type} of this node.', danielebarchiesi@0: 'type' => 'varchar', danielebarchiesi@0: 'length' => 32, danielebarchiesi@0: 'not null' => TRUE, danielebarchiesi@0: 'default' => '', danielebarchiesi@0: ), danielebarchiesi@0: 'title' => array( danielebarchiesi@0: 'description' => 'The title of this node, always treated as non-markup plain text.', danielebarchiesi@0: 'type' => 'varchar', danielebarchiesi@0: 'length' => 255, danielebarchiesi@0: 'not null' => TRUE, danielebarchiesi@0: 'default' => '', danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: 'indexes' => array( danielebarchiesi@0: 'node_changed' => array('changed'), danielebarchiesi@0: 'node_created' => array('created'), danielebarchiesi@0: ), danielebarchiesi@0: 'unique keys' => array( danielebarchiesi@0: 'nid_vid' => array('nid', 'vid'), danielebarchiesi@0: 'vid' => array('vid'), danielebarchiesi@0: ), danielebarchiesi@0: 'foreign keys' => array( danielebarchiesi@0: 'node_revision' => array( danielebarchiesi@0: 'table' => 'node_revision', danielebarchiesi@0: 'columns' => array('vid' => 'vid'), danielebarchiesi@0: ), danielebarchiesi@0: 'node_author' => array( danielebarchiesi@0: 'table' => 'users', danielebarchiesi@0: 'columns' => array('uid' => 'uid'), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: 'primary key' => array('nid'), danielebarchiesi@0: ); danielebarchiesi@0: return $schema; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform alterations to existing database schemas. danielebarchiesi@0: * danielebarchiesi@0: * When a module modifies the database structure of another module (by danielebarchiesi@0: * changing, adding or removing fields, keys or indexes), it should danielebarchiesi@0: * implement hook_schema_alter() to update the default $schema to take its danielebarchiesi@0: * changes into account. danielebarchiesi@0: * danielebarchiesi@0: * See hook_schema() for details on the schema definition structure. danielebarchiesi@0: * danielebarchiesi@0: * @param $schema danielebarchiesi@0: * Nested array describing the schemas for all modules. danielebarchiesi@0: * danielebarchiesi@0: * @ingroup schemaapi danielebarchiesi@0: */ danielebarchiesi@0: function hook_schema_alter(&$schema) { danielebarchiesi@0: // Add field to existing schema. danielebarchiesi@0: $schema['users']['fields']['timezone_id'] = array( danielebarchiesi@0: 'type' => 'int', danielebarchiesi@0: 'not null' => TRUE, danielebarchiesi@0: 'default' => 0, danielebarchiesi@0: 'description' => 'Per-user timezone configuration.', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform alterations to a structured query. danielebarchiesi@0: * danielebarchiesi@0: * Structured (aka dynamic) queries that have tags associated may be altered by any module danielebarchiesi@0: * before the query is executed. danielebarchiesi@0: * danielebarchiesi@0: * @param $query danielebarchiesi@0: * A Query object describing the composite parts of a SQL query. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_query_TAG_alter() danielebarchiesi@0: * @see node_query_node_access_alter() danielebarchiesi@0: * @see QueryAlterableInterface danielebarchiesi@0: * @see SelectQueryInterface danielebarchiesi@0: */ danielebarchiesi@0: function hook_query_alter(QueryAlterableInterface $query) { danielebarchiesi@0: if ($query->hasTag('micro_limit')) { danielebarchiesi@0: $query->range(0, 2); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform alterations to a structured query for a given tag. danielebarchiesi@0: * danielebarchiesi@0: * @param $query danielebarchiesi@0: * An Query object describing the composite parts of a SQL query. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_query_alter() danielebarchiesi@0: * @see node_query_node_access_alter() danielebarchiesi@0: * @see QueryAlterableInterface danielebarchiesi@0: * @see SelectQueryInterface danielebarchiesi@0: */ danielebarchiesi@0: function hook_query_TAG_alter(QueryAlterableInterface $query) { danielebarchiesi@0: // Skip the extra expensive alterations if site has no node access control modules. danielebarchiesi@0: if (!node_access_view_all_nodes()) { danielebarchiesi@0: // Prevent duplicates records. danielebarchiesi@0: $query->distinct(); danielebarchiesi@0: // The recognized operations are 'view', 'update', 'delete'. danielebarchiesi@0: if (!$op = $query->getMetaData('op')) { danielebarchiesi@0: $op = 'view'; danielebarchiesi@0: } danielebarchiesi@0: // Skip the extra joins and conditions for node admins. danielebarchiesi@0: if (!user_access('bypass node access')) { danielebarchiesi@0: // The node_access table has the access grants for any given node. danielebarchiesi@0: $access_alias = $query->join('node_access', 'na', '%alias.nid = n.nid'); danielebarchiesi@0: $or = db_or(); danielebarchiesi@0: // If any grant exists for the specified user, then user has access to the node for the specified operation. danielebarchiesi@0: foreach (node_access_grants($op, $query->getMetaData('account')) as $realm => $gids) { danielebarchiesi@0: foreach ($gids as $gid) { danielebarchiesi@0: $or->condition(db_and() danielebarchiesi@0: ->condition($access_alias . '.gid', $gid) danielebarchiesi@0: ->condition($access_alias . '.realm', $realm) danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: if (count($or->conditions())) { danielebarchiesi@0: $query->condition($or); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $query->condition($access_alias . 'grant_' . $op, 1, '>='); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform setup tasks when the module is installed. danielebarchiesi@0: * danielebarchiesi@0: * If the module implements hook_schema(), the database tables will danielebarchiesi@0: * be created before this hook is fired. danielebarchiesi@0: * danielebarchiesi@0: * Implementations of this hook are by convention declared in the module's danielebarchiesi@0: * .install file. The implementation can rely on the .module file being loaded. danielebarchiesi@0: * The hook will only be called the first time a module is enabled or after it danielebarchiesi@0: * is re-enabled after being uninstalled. The module's schema version will be danielebarchiesi@0: * set to the module's greatest numbered update hook. Because of this, any time danielebarchiesi@0: * a hook_update_N() is added to the module, this function needs to be updated danielebarchiesi@0: * to reflect the current version of the database schema. danielebarchiesi@0: * danielebarchiesi@0: * See the @link http://drupal.org/node/146843 Schema API documentation @endlink danielebarchiesi@0: * for details on hook_schema and how database tables are defined. danielebarchiesi@0: * danielebarchiesi@0: * Note that since this function is called from a full bootstrap, all functions danielebarchiesi@0: * (including those in modules enabled by the current page request) are danielebarchiesi@0: * available when this hook is called. Use cases could be displaying a user danielebarchiesi@0: * message, or calling a module function necessary for initial setup, etc. danielebarchiesi@0: * danielebarchiesi@0: * Please be sure that anything added or modified in this function that can danielebarchiesi@0: * be removed during uninstall should be removed with hook_uninstall(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_schema() danielebarchiesi@0: * @see module_enable() danielebarchiesi@0: * @see hook_enable() danielebarchiesi@0: * @see hook_disable() danielebarchiesi@0: * @see hook_uninstall() danielebarchiesi@0: * @see hook_modules_installed() danielebarchiesi@0: */ danielebarchiesi@0: function hook_install() { danielebarchiesi@0: // Populate the default {node_access} record. danielebarchiesi@0: db_insert('node_access') danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'nid' => 0, danielebarchiesi@0: 'gid' => 0, danielebarchiesi@0: 'realm' => 'all', danielebarchiesi@0: 'grant_view' => 1, danielebarchiesi@0: 'grant_update' => 0, danielebarchiesi@0: 'grant_delete' => 0, danielebarchiesi@0: )) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform a single update. danielebarchiesi@0: * danielebarchiesi@0: * For each change that requires one or more actions to be performed when danielebarchiesi@0: * updating a site, add a new hook_update_N(), which will be called by danielebarchiesi@0: * update.php. The documentation block preceding this function is stripped of danielebarchiesi@0: * newlines and used as the description for the update on the pending updates danielebarchiesi@0: * task list. Schema updates should adhere to the danielebarchiesi@0: * @link http://drupal.org/node/150215 Schema API. @endlink danielebarchiesi@0: * danielebarchiesi@0: * Implementations of hook_update_N() are named (module name)_update_(number). danielebarchiesi@0: * The numbers are composed of three parts: danielebarchiesi@0: * - 1 digit for Drupal core compatibility. danielebarchiesi@0: * - 1 digit for your module's major release version (e.g., is this the 7.x-1.* danielebarchiesi@0: * (1) or 7.x-2.* (2) series of your module?). This digit should be 0 for danielebarchiesi@0: * initial porting of your module to a new Drupal core API. danielebarchiesi@0: * - 2 digits for sequential counting, starting with 00. danielebarchiesi@0: * danielebarchiesi@0: * Examples: danielebarchiesi@0: * - mymodule_update_7000(): This is the required update for mymodule to run danielebarchiesi@0: * with Drupal core API 7.x when upgrading from Drupal core API 6.x. danielebarchiesi@0: * - mymodule_update_7100(): This is the first update to get the database ready danielebarchiesi@0: * to run mymodule 7.x-1.*. danielebarchiesi@0: * - mymodule_update_7200(): This is the first update to get the database ready danielebarchiesi@0: * to run mymodule 7.x-2.*. Users can directly update from 6.x-2.* to 7.x-2.* danielebarchiesi@0: * and they get all 70xx and 72xx updates, but not 71xx updates, because danielebarchiesi@0: * those reside in the 7.x-1.x branch only. danielebarchiesi@0: * danielebarchiesi@0: * A good rule of thumb is to remove updates older than two major releases of danielebarchiesi@0: * Drupal. See hook_update_last_removed() to notify Drupal about the removals. danielebarchiesi@0: * For further information about releases and release numbers see: danielebarchiesi@0: * @link http://drupal.org/node/711070 Maintaining a drupal.org project with Git @endlink danielebarchiesi@0: * danielebarchiesi@0: * Never renumber update functions. danielebarchiesi@0: * danielebarchiesi@0: * Implementations of this hook should be placed in a mymodule.install file in danielebarchiesi@0: * the same directory as mymodule.module. Drupal core's updates are implemented danielebarchiesi@0: * using the system module as a name and stored in database/updates.inc. danielebarchiesi@0: * danielebarchiesi@0: * Not all module functions are available from within a hook_update_N() function. danielebarchiesi@0: * In order to call a function from your mymodule.module or an include file, danielebarchiesi@0: * you need to explicitly load that file first. danielebarchiesi@0: * danielebarchiesi@0: * During database updates the schema of any module could be out of date. For danielebarchiesi@0: * this reason, caution is needed when using any API function within an update danielebarchiesi@0: * function - particularly CRUD functions, functions that depend on the schema danielebarchiesi@0: * (for example by using drupal_write_record()), and any functions that invoke danielebarchiesi@0: * hooks. See @link update_api Update versions of API functions @endlink for danielebarchiesi@0: * details. danielebarchiesi@0: * danielebarchiesi@0: * If your update task is potentially time-consuming, you'll need to implement a danielebarchiesi@0: * multipass update to avoid PHP timeouts. Multipass updates use the $sandbox danielebarchiesi@0: * parameter provided by the batch API (normally, $context['sandbox']) to store danielebarchiesi@0: * information between successive calls, and the $sandbox['#finished'] value danielebarchiesi@0: * to provide feedback regarding completion level. danielebarchiesi@0: * danielebarchiesi@0: * See the batch operations page for more information on how to use the danielebarchiesi@0: * @link http://drupal.org/node/180528 Batch API. @endlink danielebarchiesi@0: * danielebarchiesi@0: * @param $sandbox danielebarchiesi@0: * Stores information for multipass updates. See above for more information. danielebarchiesi@0: * danielebarchiesi@0: * @throws DrupalUpdateException, PDOException danielebarchiesi@0: * In case of error, update hooks should throw an instance of DrupalUpdateException danielebarchiesi@0: * with a meaningful message for the user. If a database query fails for whatever danielebarchiesi@0: * reason, it will throw a PDOException. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * Optionally, update hooks may return a translated string that will be danielebarchiesi@0: * displayed to the user after the update has completed. If no message is danielebarchiesi@0: * returned, no message will be presented to the user. danielebarchiesi@0: * danielebarchiesi@0: * @see batch danielebarchiesi@0: * @see schemaapi danielebarchiesi@0: * @see update_api danielebarchiesi@0: * @see hook_update_last_removed() danielebarchiesi@0: * @see update_get_update_list() danielebarchiesi@0: */ danielebarchiesi@0: function hook_update_N(&$sandbox) { danielebarchiesi@0: // For non-multipass updates, the signature can simply be; danielebarchiesi@0: // function hook_update_N() { danielebarchiesi@0: danielebarchiesi@0: // For most updates, the following is sufficient. danielebarchiesi@0: db_add_field('mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE, 'description' => 'My new integer column.')); danielebarchiesi@0: danielebarchiesi@0: // However, for more complex operations that may take a long time, danielebarchiesi@0: // you may hook into Batch API as in the following example. danielebarchiesi@0: danielebarchiesi@0: // Update 3 users at a time to have an exclamation point after their names. danielebarchiesi@0: // (They're really happy that we can do batch API in this hook!) danielebarchiesi@0: if (!isset($sandbox['progress'])) { danielebarchiesi@0: $sandbox['progress'] = 0; danielebarchiesi@0: $sandbox['current_uid'] = 0; danielebarchiesi@0: // We'll -1 to disregard the uid 0... danielebarchiesi@0: $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $users = db_select('users', 'u') danielebarchiesi@0: ->fields('u', array('uid', 'name')) danielebarchiesi@0: ->condition('uid', $sandbox['current_uid'], '>') danielebarchiesi@0: ->range(0, 3) danielebarchiesi@0: ->orderBy('uid', 'ASC') danielebarchiesi@0: ->execute(); danielebarchiesi@0: danielebarchiesi@0: foreach ($users as $user) { danielebarchiesi@0: $user->name .= '!'; danielebarchiesi@0: db_update('users') danielebarchiesi@0: ->fields(array('name' => $user->name)) danielebarchiesi@0: ->condition('uid', $user->uid) danielebarchiesi@0: ->execute(); danielebarchiesi@0: danielebarchiesi@0: $sandbox['progress']++; danielebarchiesi@0: $sandbox['current_uid'] = $user->uid; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); danielebarchiesi@0: danielebarchiesi@0: // To display a message to the user when the update is completed, return it. danielebarchiesi@0: // If you do not want to display a completion message, simply return nothing. danielebarchiesi@0: return t('The update did what it was supposed to do.'); danielebarchiesi@0: danielebarchiesi@0: // In case of an error, simply throw an exception with an error message. danielebarchiesi@0: throw new DrupalUpdateException('Something went wrong; here is what you should do.'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return an array of information about module update dependencies. danielebarchiesi@0: * danielebarchiesi@0: * This can be used to indicate update functions from other modules that your danielebarchiesi@0: * module's update functions depend on, or vice versa. It is used by the update danielebarchiesi@0: * system to determine the appropriate order in which updates should be run, as danielebarchiesi@0: * well as to search for missing dependencies. danielebarchiesi@0: * danielebarchiesi@0: * Implementations of this hook should be placed in a mymodule.install file in danielebarchiesi@0: * the same directory as mymodule.module. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * A multidimensional array containing information about the module update danielebarchiesi@0: * dependencies. The first two levels of keys represent the module and update danielebarchiesi@0: * number (respectively) for which information is being returned, and the danielebarchiesi@0: * value is an array of information about that update's dependencies. Within danielebarchiesi@0: * this array, each key represents a module, and each value represents the danielebarchiesi@0: * number of an update function within that module. In the event that your danielebarchiesi@0: * update function depends on more than one update from a particular module, danielebarchiesi@0: * you should always list the highest numbered one here (since updates within danielebarchiesi@0: * a given module always run in numerical order). danielebarchiesi@0: * danielebarchiesi@0: * @see update_resolve_dependencies() danielebarchiesi@0: * @see hook_update_N() danielebarchiesi@0: */ danielebarchiesi@0: function hook_update_dependencies() { danielebarchiesi@0: // Indicate that the mymodule_update_7000() function provided by this module danielebarchiesi@0: // must run after the another_module_update_7002() function provided by the danielebarchiesi@0: // 'another_module' module. danielebarchiesi@0: $dependencies['mymodule'][7000] = array( danielebarchiesi@0: 'another_module' => 7002, danielebarchiesi@0: ); danielebarchiesi@0: // Indicate that the mymodule_update_7001() function provided by this module danielebarchiesi@0: // must run before the yet_another_module_update_7004() function provided by danielebarchiesi@0: // the 'yet_another_module' module. (Note that declaring dependencies in this danielebarchiesi@0: // direction should be done only in rare situations, since it can lead to the danielebarchiesi@0: // following problem: If a site has already run the yet_another_module danielebarchiesi@0: // module's database updates before it updates its codebase to pick up the danielebarchiesi@0: // newest mymodule code, then the dependency declared here will be ignored.) danielebarchiesi@0: $dependencies['yet_another_module'][7004] = array( danielebarchiesi@0: 'mymodule' => 7001, danielebarchiesi@0: ); danielebarchiesi@0: return $dependencies; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return a number which is no longer available as hook_update_N(). danielebarchiesi@0: * danielebarchiesi@0: * If you remove some update functions from your mymodule.install file, you danielebarchiesi@0: * should notify Drupal of those missing functions. This way, Drupal can danielebarchiesi@0: * ensure that no update is accidentally skipped. danielebarchiesi@0: * danielebarchiesi@0: * Implementations of this hook should be placed in a mymodule.install file in danielebarchiesi@0: * the same directory as mymodule.module. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An integer, corresponding to hook_update_N() which has been removed from danielebarchiesi@0: * mymodule.install. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_update_N() danielebarchiesi@0: */ danielebarchiesi@0: function hook_update_last_removed() { danielebarchiesi@0: // We've removed the 5.x-1.x version of mymodule, including database updates. danielebarchiesi@0: // The next update function is mymodule_update_5200(). danielebarchiesi@0: return 5103; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Remove any information that the module sets. danielebarchiesi@0: * danielebarchiesi@0: * The information that the module should remove includes: danielebarchiesi@0: * - variables that the module has set using variable_set() or system_settings_form() danielebarchiesi@0: * - modifications to existing tables danielebarchiesi@0: * danielebarchiesi@0: * The module should not remove its entry from the {system} table. Database danielebarchiesi@0: * tables defined by hook_schema() will be removed automatically. danielebarchiesi@0: * danielebarchiesi@0: * The uninstall hook must be implemented in the module's .install file. It danielebarchiesi@0: * will fire when the module gets uninstalled but before the module's database danielebarchiesi@0: * tables are removed, allowing your module to query its own tables during danielebarchiesi@0: * this routine. danielebarchiesi@0: * danielebarchiesi@0: * When hook_uninstall() is called, your module will already be disabled, so danielebarchiesi@0: * its .module file will not be automatically included. If you need to call API danielebarchiesi@0: * functions from your .module file in this hook, use drupal_load() to make danielebarchiesi@0: * them available. (Keep this usage to a minimum, though, especially when danielebarchiesi@0: * calling API functions that invoke hooks, or API functions from modules danielebarchiesi@0: * listed as dependencies, since these may not be available or work as expected danielebarchiesi@0: * when the module is disabled.) danielebarchiesi@0: * danielebarchiesi@0: * @see hook_install() danielebarchiesi@0: * @see hook_schema() danielebarchiesi@0: * @see hook_disable() danielebarchiesi@0: * @see hook_modules_uninstalled() danielebarchiesi@0: */ danielebarchiesi@0: function hook_uninstall() { danielebarchiesi@0: variable_del('upload_file_types'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary actions after module is enabled. danielebarchiesi@0: * danielebarchiesi@0: * The hook is called every time the module is enabled. It should be danielebarchiesi@0: * implemented in the module's .install file. The implementation can danielebarchiesi@0: * rely on the .module file being loaded. danielebarchiesi@0: * danielebarchiesi@0: * @see module_enable() danielebarchiesi@0: * @see hook_install() danielebarchiesi@0: * @see hook_modules_enabled() danielebarchiesi@0: */ danielebarchiesi@0: function hook_enable() { danielebarchiesi@0: mymodule_cache_rebuild(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary actions before module is disabled. danielebarchiesi@0: * danielebarchiesi@0: * The hook is called every time the module is disabled. It should be danielebarchiesi@0: * implemented in the module's .install file. The implementation can rely danielebarchiesi@0: * on the .module file being loaded. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_uninstall() danielebarchiesi@0: * @see hook_modules_disabled() danielebarchiesi@0: */ danielebarchiesi@0: function hook_disable() { danielebarchiesi@0: mymodule_cache_rebuild(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Perform necessary alterations to the list of files parsed by the registry. danielebarchiesi@0: * danielebarchiesi@0: * Modules can manually modify the list of files before the registry parses danielebarchiesi@0: * them. The $modules array provides the .info file information, which includes danielebarchiesi@0: * the list of files registered to each module. Any files in the list can then danielebarchiesi@0: * be added to the list of files that the registry will parse, or modify danielebarchiesi@0: * attributes of a file. danielebarchiesi@0: * danielebarchiesi@0: * A necessary alteration made by the core SimpleTest module is to force .test danielebarchiesi@0: * files provided by disabled modules into the list of files parsed by the danielebarchiesi@0: * registry. danielebarchiesi@0: * danielebarchiesi@0: * @param $files danielebarchiesi@0: * List of files to be parsed by the registry. The list will contain danielebarchiesi@0: * files found in each enabled module's info file and the core includes danielebarchiesi@0: * directory. The array is keyed by the file path and contains an array of danielebarchiesi@0: * the related module's name and weight as used internally by danielebarchiesi@0: * _registry_update() and related functions. danielebarchiesi@0: * danielebarchiesi@0: * For example: danielebarchiesi@0: * @code danielebarchiesi@0: * $files["modules/system/system.module"] = array( danielebarchiesi@0: * 'module' => 'system', danielebarchiesi@0: * 'weight' => 0, danielebarchiesi@0: * ); danielebarchiesi@0: * @endcode danielebarchiesi@0: * @param $modules danielebarchiesi@0: * An array containing all module information stored in the {system} table. danielebarchiesi@0: * Each element of the array also contains the module's .info file danielebarchiesi@0: * information in the property 'info'. An additional 'dir' property has been danielebarchiesi@0: * added to the module information which provides the path to the directory danielebarchiesi@0: * in which the module resides. The example shows how to take advantage of danielebarchiesi@0: * both properties. danielebarchiesi@0: * danielebarchiesi@0: * @see _registry_update() danielebarchiesi@0: * @see simpletest_test_get_all() danielebarchiesi@0: */ danielebarchiesi@0: function hook_registry_files_alter(&$files, $modules) { danielebarchiesi@0: foreach ($modules as $module) { danielebarchiesi@0: // Only add test files for disabled modules, as enabled modules should danielebarchiesi@0: // already include any test files they provide. danielebarchiesi@0: if (!$module->status) { danielebarchiesi@0: $dir = $module->dir; danielebarchiesi@0: foreach ($module->info['files'] as $file) { danielebarchiesi@0: if (substr($file, -5) == '.test') { danielebarchiesi@0: $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return an array of tasks to be performed by an installation profile. danielebarchiesi@0: * danielebarchiesi@0: * Any tasks you define here will be run, in order, after the installer has danielebarchiesi@0: * finished the site configuration step but before it has moved on to the danielebarchiesi@0: * final import of languages and the end of the installation. You can have any danielebarchiesi@0: * number of custom tasks to perform during this phase. danielebarchiesi@0: * danielebarchiesi@0: * Each task you define here corresponds to a callback function which you must danielebarchiesi@0: * separately define and which is called when your task is run. This function danielebarchiesi@0: * will receive the global installation state variable, $install_state, as danielebarchiesi@0: * input, and has the opportunity to access or modify any of its settings. See danielebarchiesi@0: * the install_state_defaults() function in the installer for the list of danielebarchiesi@0: * $install_state settings used by Drupal core. danielebarchiesi@0: * danielebarchiesi@0: * At the end of your task function, you can indicate that you want the danielebarchiesi@0: * installer to pause and display a page to the user by returning any themed danielebarchiesi@0: * output that should be displayed on that page (but see below for tasks that danielebarchiesi@0: * use the form API or batch API; the return values of these task functions are danielebarchiesi@0: * handled differently). You should also use drupal_set_title() within the task danielebarchiesi@0: * callback function to set a custom page title. For some tasks, however, you danielebarchiesi@0: * may want to simply do some processing and pass control to the next task danielebarchiesi@0: * without ending the page request; to indicate this, simply do not send back danielebarchiesi@0: * a return value from your task function at all. This can be used, for danielebarchiesi@0: * example, by installation profiles that need to configure certain site danielebarchiesi@0: * settings in the database without obtaining any input from the user. danielebarchiesi@0: * danielebarchiesi@0: * The task function is treated specially if it defines a form or requires danielebarchiesi@0: * batch processing; in that case, you should return either the form API danielebarchiesi@0: * definition or batch API array, as appropriate. See below for more danielebarchiesi@0: * information on the 'type' key that you must define in the task definition danielebarchiesi@0: * to inform the installer that your task falls into one of those two danielebarchiesi@0: * categories. It is important to use these APIs directly, since the installer danielebarchiesi@0: * may be run non-interactively (for example, via a command line script), all danielebarchiesi@0: * in one page request; in that case, the installer will automatically take danielebarchiesi@0: * care of submitting forms and processing batches correctly for both types of danielebarchiesi@0: * installations. You can inspect the $install_state['interactive'] boolean to danielebarchiesi@0: * see whether or not the current installation is interactive, if you need danielebarchiesi@0: * access to this information. danielebarchiesi@0: * danielebarchiesi@0: * Remember that a user installing Drupal interactively will be able to reload danielebarchiesi@0: * an installation page multiple times, so you should use variable_set() and danielebarchiesi@0: * variable_get() if you are collecting any data that you need to store and danielebarchiesi@0: * inspect later. It is important to remove any temporary variables using danielebarchiesi@0: * variable_del() before your last task has completed and control is handed danielebarchiesi@0: * back to the installer. danielebarchiesi@0: * danielebarchiesi@0: * @param array $install_state danielebarchiesi@0: * An array of information about the current installation state. danielebarchiesi@0: * danielebarchiesi@0: * @return array danielebarchiesi@0: * A keyed array of tasks the profile will perform during the final stage of danielebarchiesi@0: * the installation. Each key represents the name of a function (usually a danielebarchiesi@0: * function defined by this profile, although that is not strictly required) danielebarchiesi@0: * that is called when that task is run. The values are associative arrays danielebarchiesi@0: * containing the following key-value pairs (all of which are optional): danielebarchiesi@0: * - display_name: The human-readable name of the task. This will be danielebarchiesi@0: * displayed to the user while the installer is running, along with a list danielebarchiesi@0: * of other tasks that are being run. Leave this unset to prevent the task danielebarchiesi@0: * from appearing in the list. danielebarchiesi@0: * - display: This is a boolean which can be used to provide finer-grained danielebarchiesi@0: * control over whether or not the task will display. This is mostly useful danielebarchiesi@0: * for tasks that are intended to display only under certain conditions; danielebarchiesi@0: * for these tasks, you can set 'display_name' to the name that you want to danielebarchiesi@0: * display, but then use this boolean to hide the task only when certain danielebarchiesi@0: * conditions apply. danielebarchiesi@0: * - type: A string representing the type of task. This parameter has three danielebarchiesi@0: * possible values: danielebarchiesi@0: * - normal: (default) This indicates that the task will be treated as a danielebarchiesi@0: * regular callback function, which does its processing and optionally danielebarchiesi@0: * returns HTML output. danielebarchiesi@0: * - batch: This indicates that the task function will return a batch API danielebarchiesi@0: * definition suitable for batch_set(). The installer will then take care danielebarchiesi@0: * of automatically running the task via batch processing. danielebarchiesi@0: * - form: This indicates that the task function will return a standard danielebarchiesi@0: * form API definition (and separately define validation and submit danielebarchiesi@0: * handlers, as appropriate). The installer will then take care of danielebarchiesi@0: * automatically directing the user through the form submission process. danielebarchiesi@0: * - run: A constant representing the manner in which the task will be run. danielebarchiesi@0: * This parameter has three possible values: danielebarchiesi@0: * - INSTALL_TASK_RUN_IF_NOT_COMPLETED: (default) This indicates that the danielebarchiesi@0: * task will run once during the installation of the profile. danielebarchiesi@0: * - INSTALL_TASK_SKIP: This indicates that the task will not run during danielebarchiesi@0: * the current installation page request. It can be used to skip running danielebarchiesi@0: * an installation task when certain conditions are met, even though the danielebarchiesi@0: * task may still show on the list of installation tasks presented to the danielebarchiesi@0: * user. danielebarchiesi@0: * - INSTALL_TASK_RUN_IF_REACHED: This indicates that the task will run on danielebarchiesi@0: * each installation page request that reaches it. This is rarely danielebarchiesi@0: * necessary for an installation profile to use; it is primarily used by danielebarchiesi@0: * the Drupal installer for bootstrap-related tasks. danielebarchiesi@0: * - function: Normally this does not need to be set, but it can be used to danielebarchiesi@0: * force the installer to call a different function when the task is run danielebarchiesi@0: * (rather than the function whose name is given by the array key). This danielebarchiesi@0: * could be used, for example, to allow the same function to be called by danielebarchiesi@0: * two different tasks. danielebarchiesi@0: * danielebarchiesi@0: * @see install_state_defaults() danielebarchiesi@0: * @see batch_set() danielebarchiesi@0: */ danielebarchiesi@0: function hook_install_tasks(&$install_state) { danielebarchiesi@0: // Here, we define a variable to allow tasks to indicate that a particular, danielebarchiesi@0: // processor-intensive batch process needs to be triggered later on in the danielebarchiesi@0: // installation. danielebarchiesi@0: $myprofile_needs_batch_processing = variable_get('myprofile_needs_batch_processing', FALSE); danielebarchiesi@0: $tasks = array( danielebarchiesi@0: // This is an example of a task that defines a form which the user who is danielebarchiesi@0: // installing the site will be asked to fill out. To implement this task, danielebarchiesi@0: // your profile would define a function named myprofile_data_import_form() danielebarchiesi@0: // as a normal form API callback function, with associated validation and danielebarchiesi@0: // submit handlers. In the submit handler, in addition to saving whatever danielebarchiesi@0: // other data you have collected from the user, you might also call danielebarchiesi@0: // variable_set('myprofile_needs_batch_processing', TRUE) if the user has danielebarchiesi@0: // entered data which requires that batch processing will need to occur danielebarchiesi@0: // later on. danielebarchiesi@0: 'myprofile_data_import_form' => array( danielebarchiesi@0: 'display_name' => st('Data import options'), danielebarchiesi@0: 'type' => 'form', danielebarchiesi@0: ), danielebarchiesi@0: // Similarly, to implement this task, your profile would define a function danielebarchiesi@0: // named myprofile_settings_form() with associated validation and submit danielebarchiesi@0: // handlers. This form might be used to collect and save additional danielebarchiesi@0: // information from the user that your profile needs. There are no extra danielebarchiesi@0: // steps required for your profile to act as an "installation wizard"; you danielebarchiesi@0: // can simply define as many tasks of type 'form' as you wish to execute, danielebarchiesi@0: // and the forms will be presented to the user, one after another. danielebarchiesi@0: 'myprofile_settings_form' => array( danielebarchiesi@0: 'display_name' => st('Additional options'), danielebarchiesi@0: 'type' => 'form', danielebarchiesi@0: ), danielebarchiesi@0: // This is an example of a task that performs batch operations. To danielebarchiesi@0: // implement this task, your profile would define a function named danielebarchiesi@0: // myprofile_batch_processing() which returns a batch API array definition danielebarchiesi@0: // that the installer will use to execute your batch operations. Due to the danielebarchiesi@0: // 'myprofile_needs_batch_processing' variable used here, this task will be danielebarchiesi@0: // hidden and skipped unless your profile set it to TRUE in one of the danielebarchiesi@0: // previous tasks. danielebarchiesi@0: 'myprofile_batch_processing' => array( danielebarchiesi@0: 'display_name' => st('Import additional data'), danielebarchiesi@0: 'display' => $myprofile_needs_batch_processing, danielebarchiesi@0: 'type' => 'batch', danielebarchiesi@0: 'run' => $myprofile_needs_batch_processing ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP, danielebarchiesi@0: ), danielebarchiesi@0: // This is an example of a task that will not be displayed in the list that danielebarchiesi@0: // the user sees. To implement this task, your profile would define a danielebarchiesi@0: // function named myprofile_final_site_setup(), in which additional, danielebarchiesi@0: // automated site setup operations would be performed. Since this is the danielebarchiesi@0: // last task defined by your profile, you should also use this function to danielebarchiesi@0: // call variable_del('myprofile_needs_batch_processing') and clean up the danielebarchiesi@0: // variable that was used above. If you want the user to pass to the final danielebarchiesi@0: // Drupal installation tasks uninterrupted, return no output from this danielebarchiesi@0: // function. Otherwise, return themed output that the user will see (for danielebarchiesi@0: // example, a confirmation page explaining that your profile's tasks are danielebarchiesi@0: // complete, with a link to reload the current page and therefore pass on danielebarchiesi@0: // to the final Drupal installation tasks when the user is ready to do so). danielebarchiesi@0: 'myprofile_final_site_setup' => array( danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: return $tasks; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Change the page the user is sent to by drupal_goto(). danielebarchiesi@0: * danielebarchiesi@0: * @param $path danielebarchiesi@0: * A Drupal path or a full URL. danielebarchiesi@0: * @param $options danielebarchiesi@0: * An associative array of additional URL options to pass to url(). danielebarchiesi@0: * @param $http_response_code danielebarchiesi@0: * The HTTP status code to use for the redirection. See drupal_goto() for more danielebarchiesi@0: * information. danielebarchiesi@0: */ danielebarchiesi@0: function hook_drupal_goto_alter(&$path, &$options, &$http_response_code) { danielebarchiesi@0: // A good addition to misery module. danielebarchiesi@0: $http_response_code = 500; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter XHTML HEAD tags before they are rendered by drupal_get_html_head(). danielebarchiesi@0: * danielebarchiesi@0: * Elements available to be altered are only those added using danielebarchiesi@0: * drupal_add_html_head_link() or drupal_add_html_head(). CSS and JS files danielebarchiesi@0: * are handled using drupal_add_css() and drupal_add_js(), so the head links danielebarchiesi@0: * for those files will not appear in the $head_elements array. danielebarchiesi@0: * danielebarchiesi@0: * @param $head_elements danielebarchiesi@0: * An array of renderable elements. Generally the values of the #attributes danielebarchiesi@0: * array will be the most likely target for changes. danielebarchiesi@0: */ danielebarchiesi@0: function hook_html_head_alter(&$head_elements) { danielebarchiesi@0: foreach ($head_elements as $key => $element) { danielebarchiesi@0: if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') { danielebarchiesi@0: // I want a custom canonical URL. danielebarchiesi@0: $head_elements[$key]['#attributes']['href'] = mymodule_canonical_url(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the full list of installation tasks. danielebarchiesi@0: * danielebarchiesi@0: * @param $tasks danielebarchiesi@0: * An array of all available installation tasks, including those provided by danielebarchiesi@0: * Drupal core. You can modify this array to change or replace any part of danielebarchiesi@0: * the Drupal installation process that occurs after the installation profile danielebarchiesi@0: * is selected. danielebarchiesi@0: * @param $install_state danielebarchiesi@0: * An array of information about the current installation state. danielebarchiesi@0: */ danielebarchiesi@0: function hook_install_tasks_alter(&$tasks, $install_state) { danielebarchiesi@0: // Replace the "Choose language" installation task provided by Drupal core danielebarchiesi@0: // with a custom callback function defined by this installation profile. danielebarchiesi@0: $tasks['install_select_locale']['function'] = 'myprofile_locale_selection'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter MIME type mappings used to determine MIME type from a file extension. danielebarchiesi@0: * danielebarchiesi@0: * This hook is run when file_mimetype_mapping() is called. It is used to danielebarchiesi@0: * allow modules to add to or modify the default mapping from danielebarchiesi@0: * file_default_mimetype_mapping(). danielebarchiesi@0: * danielebarchiesi@0: * @param $mapping danielebarchiesi@0: * An array of mimetypes correlated to the extensions that relate to them. danielebarchiesi@0: * The array has 'mimetypes' and 'extensions' elements, each of which is an danielebarchiesi@0: * array. danielebarchiesi@0: * danielebarchiesi@0: * @see file_default_mimetype_mapping() danielebarchiesi@0: */ danielebarchiesi@0: function hook_file_mimetype_mapping_alter(&$mapping) { danielebarchiesi@0: // Add new MIME type 'drupal/info'. danielebarchiesi@0: $mapping['mimetypes']['example_info'] = 'drupal/info'; danielebarchiesi@0: // Add new extension '.info' and map it to the 'drupal/info' MIME type. danielebarchiesi@0: $mapping['extensions']['info'] = 'example_info'; danielebarchiesi@0: // Override existing extension mapping for '.ogg' files. danielebarchiesi@0: $mapping['extensions']['ogg'] = 189; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Declares information about actions. danielebarchiesi@0: * danielebarchiesi@0: * Any module can define actions, and then call actions_do() to make those danielebarchiesi@0: * actions happen in response to events. The trigger module provides a user danielebarchiesi@0: * interface for associating actions with module-defined triggers, and it makes danielebarchiesi@0: * sure the core triggers fire off actions when their events happen. danielebarchiesi@0: * danielebarchiesi@0: * An action consists of two or three parts: danielebarchiesi@0: * - an action definition (returned by this hook) danielebarchiesi@0: * - a function which performs the action (which by convention is named danielebarchiesi@0: * MODULE_description-of-function_action) danielebarchiesi@0: * - an optional form definition function that defines a configuration form danielebarchiesi@0: * (which has the name of the action function with '_form' appended to it.) danielebarchiesi@0: * danielebarchiesi@0: * The action function takes two to four arguments, which come from the input danielebarchiesi@0: * arguments to actions_do(). danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array of action descriptions. The keys of the array danielebarchiesi@0: * are the names of the action functions, and each corresponding value danielebarchiesi@0: * is an associative array with the following key-value pairs: danielebarchiesi@0: * - 'type': The type of object this action acts upon. Core actions have types danielebarchiesi@0: * 'node', 'user', 'comment', and 'system'. danielebarchiesi@0: * - 'label': The human-readable name of the action, which should be passed danielebarchiesi@0: * through the t() function for translation. danielebarchiesi@0: * - 'configurable': If FALSE, then the action doesn't require any extra danielebarchiesi@0: * configuration. If TRUE, then your module must define a form function with danielebarchiesi@0: * the same name as the action function with '_form' appended (e.g., the danielebarchiesi@0: * form for 'node_assign_owner_action' is 'node_assign_owner_action_form'.) danielebarchiesi@0: * This function takes $context as its only parameter, and is paired with danielebarchiesi@0: * the usual _submit function, and possibly a _validate function. danielebarchiesi@0: * - 'triggers': An array of the events (that is, hooks) that can trigger this danielebarchiesi@0: * action. For example: array('node_insert', 'user_update'). You can also danielebarchiesi@0: * declare support for any trigger by returning array('any') for this value. danielebarchiesi@0: * - 'behavior': (optional) A machine-readable array of behaviors of this danielebarchiesi@0: * action, used to signal additionally required actions that may need to be danielebarchiesi@0: * triggered. Currently recognized behaviors by Trigger module: danielebarchiesi@0: * - 'changes_property': If an action with this behavior is assigned to a danielebarchiesi@0: * trigger other than a "presave" hook, any save actions also assigned to danielebarchiesi@0: * this trigger are moved later in the list. If no save action is present, danielebarchiesi@0: * one will be added. danielebarchiesi@0: * Modules that are processing actions (like Trigger module) should take danielebarchiesi@0: * special care for the "presave" hook, in which case a dependent "save" danielebarchiesi@0: * action should NOT be invoked. danielebarchiesi@0: * danielebarchiesi@0: * @ingroup actions danielebarchiesi@0: */ danielebarchiesi@0: function hook_action_info() { danielebarchiesi@0: return array( danielebarchiesi@0: 'comment_unpublish_action' => array( danielebarchiesi@0: 'type' => 'comment', danielebarchiesi@0: 'label' => t('Unpublish comment'), danielebarchiesi@0: 'configurable' => FALSE, danielebarchiesi@0: 'behavior' => array('changes_property'), danielebarchiesi@0: 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'), danielebarchiesi@0: ), danielebarchiesi@0: 'comment_unpublish_by_keyword_action' => array( danielebarchiesi@0: 'type' => 'comment', danielebarchiesi@0: 'label' => t('Unpublish comment containing keyword(s)'), danielebarchiesi@0: 'configurable' => TRUE, danielebarchiesi@0: 'behavior' => array('changes_property'), danielebarchiesi@0: 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'), danielebarchiesi@0: ), danielebarchiesi@0: 'comment_save_action' => array( danielebarchiesi@0: 'type' => 'comment', danielebarchiesi@0: 'label' => t('Save comment'), danielebarchiesi@0: 'configurable' => FALSE, danielebarchiesi@0: 'triggers' => array('comment_insert', 'comment_update'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Executes code after an action is deleted. danielebarchiesi@0: * danielebarchiesi@0: * @param $aid danielebarchiesi@0: * The action ID. danielebarchiesi@0: */ danielebarchiesi@0: function hook_actions_delete($aid) { danielebarchiesi@0: db_delete('actions_assignments') danielebarchiesi@0: ->condition('aid', $aid) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters the actions declared by another module. danielebarchiesi@0: * danielebarchiesi@0: * Called by actions_list() to allow modules to alter the return values from danielebarchiesi@0: * implementations of hook_action_info(). danielebarchiesi@0: * danielebarchiesi@0: * @see trigger_example_action_info_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_action_info_alter(&$actions) { danielebarchiesi@0: $actions['node_unpublish_action']['label'] = t('Unpublish and remove from public view.'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Declare archivers to the system. danielebarchiesi@0: * danielebarchiesi@0: * An archiver is a class that is able to package and unpackage one or more files danielebarchiesi@0: * into a single possibly compressed file. Common examples of such files are danielebarchiesi@0: * zip files and tar.gz files. All archiver classes must implement danielebarchiesi@0: * ArchiverInterface. danielebarchiesi@0: * danielebarchiesi@0: * Each entry should be keyed on a unique value, and specify three danielebarchiesi@0: * additional keys: danielebarchiesi@0: * - class: The name of the PHP class for this archiver. danielebarchiesi@0: * - extensions: An array of file extensions that this archiver supports. danielebarchiesi@0: * - weight: This optional key specifies the weight of this archiver. danielebarchiesi@0: * When mapping file extensions to archivers, the first archiver by danielebarchiesi@0: * weight found that supports the requested extension will be used. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_archiver_info_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_archiver_info() { danielebarchiesi@0: return array( danielebarchiesi@0: 'tar' => array( danielebarchiesi@0: 'class' => 'ArchiverTar', danielebarchiesi@0: 'extensions' => array('tar', 'tar.gz', 'tar.bz2'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter archiver information declared by other modules. danielebarchiesi@0: * danielebarchiesi@0: * See hook_archiver_info() for a description of archivers and the archiver danielebarchiesi@0: * information structure. danielebarchiesi@0: * danielebarchiesi@0: * @param $info danielebarchiesi@0: * Archiver information to alter (return values from hook_archiver_info()). danielebarchiesi@0: */ danielebarchiesi@0: function hook_archiver_info_alter(&$info) { danielebarchiesi@0: $info['tar']['extensions'][] = 'tgz'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Define additional date types. danielebarchiesi@0: * danielebarchiesi@0: * Next to the 'long', 'medium' and 'short' date types defined in core, any danielebarchiesi@0: * module can define additional types that can be used when displaying dates, danielebarchiesi@0: * by implementing this hook. A date type is basically just a name for a date danielebarchiesi@0: * format. danielebarchiesi@0: * danielebarchiesi@0: * Date types are used in the administration interface: a user can assign danielebarchiesi@0: * date format types defined in hook_date_formats() to date types defined in danielebarchiesi@0: * this hook. Once a format has been assigned by a user, the machine name of a danielebarchiesi@0: * type can be used in the format_date() function to format a date using the danielebarchiesi@0: * chosen formatting. danielebarchiesi@0: * danielebarchiesi@0: * To define a date type in a module and make sure a format has been assigned to danielebarchiesi@0: * it, without requiring a user to visit the administrative interface, use danielebarchiesi@0: * @code variable_set('date_format_' . $type, $format); @endcode danielebarchiesi@0: * where $type is the machine-readable name defined here, and $format is a PHP danielebarchiesi@0: * date format string. danielebarchiesi@0: * danielebarchiesi@0: * To avoid namespace collisions with date types defined by other modules, it is danielebarchiesi@0: * recommended that each date type starts with the module name. A date type danielebarchiesi@0: * can consist of letters, numbers and underscores. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array of date types where the keys are the machine-readable names and danielebarchiesi@0: * the values are the human-readable labels. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_date_formats() danielebarchiesi@0: * @see format_date() danielebarchiesi@0: */ danielebarchiesi@0: function hook_date_format_types() { danielebarchiesi@0: // Define the core date format types. danielebarchiesi@0: return array( danielebarchiesi@0: 'long' => t('Long'), danielebarchiesi@0: 'medium' => t('Medium'), danielebarchiesi@0: 'short' => t('Short'), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Modify existing date types. danielebarchiesi@0: * danielebarchiesi@0: * Allows other modules to modify existing date types like 'long'. Called by danielebarchiesi@0: * _system_date_format_types_build(). For instance, A module may use this hook danielebarchiesi@0: * to apply settings across all date types, such as locking all date types so danielebarchiesi@0: * they appear to be provided by the system. danielebarchiesi@0: * danielebarchiesi@0: * @param $types danielebarchiesi@0: * A list of date types. Each date type is keyed by the machine-readable name danielebarchiesi@0: * and the values are associative arrays containing: danielebarchiesi@0: * - is_new: Set to FALSE to override previous settings. danielebarchiesi@0: * - module: The name of the module that created the date type. danielebarchiesi@0: * - type: The machine-readable date type name. danielebarchiesi@0: * - title: The human-readable date type name. danielebarchiesi@0: * - locked: Specifies that the date type is system-provided. danielebarchiesi@0: */ danielebarchiesi@0: function hook_date_format_types_alter(&$types) { danielebarchiesi@0: foreach ($types as $name => $type) { danielebarchiesi@0: $types[$name]['locked'] = 1; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Define additional date formats. danielebarchiesi@0: * danielebarchiesi@0: * This hook is used to define the PHP date format strings that can be assigned danielebarchiesi@0: * to date types in the administrative interface. A module can provide date danielebarchiesi@0: * format strings for the core-provided date types ('long', 'medium', and danielebarchiesi@0: * 'short'), or for date types defined in hook_date_format_types() by itself danielebarchiesi@0: * or another module. danielebarchiesi@0: * danielebarchiesi@0: * Since date formats can be locale-specific, you can specify the locales that danielebarchiesi@0: * each date format string applies to. There may be more than one locale for a danielebarchiesi@0: * format. There may also be more than one format for the same locale. For danielebarchiesi@0: * example d/m/Y and Y/m/d work equally well in some locales. You may wish to danielebarchiesi@0: * define some additional date formats that aren't specific to any one locale, danielebarchiesi@0: * for example, "Y m". For these cases, the 'locales' component of the return danielebarchiesi@0: * value should be omitted. danielebarchiesi@0: * danielebarchiesi@0: * Providing a date format here does not normally assign the format to be danielebarchiesi@0: * used with the associated date type -- a user has to choose a format for each danielebarchiesi@0: * date type in the administrative interface. There is one exception: locale danielebarchiesi@0: * initialization chooses a locale-specific format for the three core-provided danielebarchiesi@0: * types (see locale_get_localized_date_format() for details). If your module danielebarchiesi@0: * needs to ensure that a date type it defines has a format associated with it, danielebarchiesi@0: * call @code variable_set('date_format_' . $type, $format); @endcode danielebarchiesi@0: * where $type is the machine-readable name defined in hook_date_format_types(), danielebarchiesi@0: * and $format is a PHP date format string. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * A list of date formats to offer as choices in the administrative danielebarchiesi@0: * interface. Each date format is a keyed array consisting of three elements: danielebarchiesi@0: * - 'type': The date type name that this format can be used with, as danielebarchiesi@0: * declared in an implementation of hook_date_format_types(). danielebarchiesi@0: * - 'format': A PHP date format string to use when formatting dates. It danielebarchiesi@0: * can contain any of the formatting options described at danielebarchiesi@0: * http://php.net/manual/en/function.date.php danielebarchiesi@0: * - 'locales': (optional) An array of 2 and 5 character locale codes, danielebarchiesi@0: * defining which locales this format applies to (for example, 'en', danielebarchiesi@0: * 'en-us', etc.). If your date format is not language-specific, leave this danielebarchiesi@0: * array empty. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_date_format_types() danielebarchiesi@0: */ danielebarchiesi@0: function hook_date_formats() { danielebarchiesi@0: return array( danielebarchiesi@0: array( danielebarchiesi@0: 'type' => 'mymodule_extra_long', danielebarchiesi@0: 'format' => 'l jS F Y H:i:s e', danielebarchiesi@0: 'locales' => array('en-ie'), danielebarchiesi@0: ), danielebarchiesi@0: array( danielebarchiesi@0: 'type' => 'mymodule_extra_long', danielebarchiesi@0: 'format' => 'l jS F Y h:i:sa', danielebarchiesi@0: 'locales' => array('en', 'en-us'), danielebarchiesi@0: ), danielebarchiesi@0: array( danielebarchiesi@0: 'type' => 'short', danielebarchiesi@0: 'format' => 'F Y', danielebarchiesi@0: 'locales' => array(), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter date formats declared by another module. danielebarchiesi@0: * danielebarchiesi@0: * Called by _system_date_format_types_build() to allow modules to alter the danielebarchiesi@0: * return values from implementations of hook_date_formats(). danielebarchiesi@0: */ danielebarchiesi@0: function hook_date_formats_alter(&$formats) { danielebarchiesi@0: foreach ($formats as $id => $format) { danielebarchiesi@0: $formats[$id]['locales'][] = 'en-ca'; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters the delivery callback used to send the result of the page callback to the browser. danielebarchiesi@0: * danielebarchiesi@0: * Called by drupal_deliver_page() to allow modules to alter how the danielebarchiesi@0: * page is delivered to the browser. danielebarchiesi@0: * danielebarchiesi@0: * This hook is intended for altering the delivery callback based on danielebarchiesi@0: * information unrelated to the path of the page accessed. For example, danielebarchiesi@0: * it can be used to set the delivery callback based on a HTTP request danielebarchiesi@0: * header (as shown in the code sample). To specify a delivery callback danielebarchiesi@0: * based on path information, use hook_menu() or hook_menu_alter(). danielebarchiesi@0: * danielebarchiesi@0: * This hook can also be used as an API function that can be used to explicitly danielebarchiesi@0: * set the delivery callback from some other function. For example, for a module danielebarchiesi@0: * named MODULE: danielebarchiesi@0: * @code danielebarchiesi@0: * function MODULE_page_delivery_callback_alter(&$callback, $set = FALSE) { danielebarchiesi@0: * static $stored_callback; danielebarchiesi@0: * if ($set) { danielebarchiesi@0: * $stored_callback = $callback; danielebarchiesi@0: * } danielebarchiesi@0: * elseif (isset($stored_callback)) { danielebarchiesi@0: * $callback = $stored_callback; danielebarchiesi@0: * } danielebarchiesi@0: * } danielebarchiesi@0: * function SOMEWHERE_ELSE() { danielebarchiesi@0: * $desired_delivery_callback = 'foo'; danielebarchiesi@0: * MODULE_page_delivery_callback_alter($desired_delivery_callback, TRUE); danielebarchiesi@0: * } danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * @param $callback danielebarchiesi@0: * The name of a function. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_deliver_page() danielebarchiesi@0: */ danielebarchiesi@0: function hook_page_delivery_callback_alter(&$callback) { danielebarchiesi@0: // jQuery sets a HTTP_X_REQUESTED_WITH header of 'XMLHttpRequest'. danielebarchiesi@0: // If a page would normally be delivered as an html page, and it is called danielebarchiesi@0: // from jQuery, deliver it instead as an Ajax response. danielebarchiesi@0: if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && $callback == 'drupal_deliver_html_page') { danielebarchiesi@0: $callback = 'ajax_deliver'; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters theme operation links. danielebarchiesi@0: * danielebarchiesi@0: * @param $theme_groups danielebarchiesi@0: * An associative array containing groups of themes. danielebarchiesi@0: * danielebarchiesi@0: * @see system_themes_page() danielebarchiesi@0: */ danielebarchiesi@0: function hook_system_themes_page_alter(&$theme_groups) { danielebarchiesi@0: foreach ($theme_groups as $state => &$group) { danielebarchiesi@0: foreach ($theme_groups[$state] as &$theme) { danielebarchiesi@0: // Add a foo link to each list of theme operations. danielebarchiesi@0: $theme->operations[] = array( danielebarchiesi@0: 'title' => t('Foo'), danielebarchiesi@0: 'href' => 'admin/appearance/foo', danielebarchiesi@0: 'query' => array('theme' => $theme->name) danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters inbound URL requests. danielebarchiesi@0: * danielebarchiesi@0: * @param $path danielebarchiesi@0: * The path being constructed, which, if a path alias, has been resolved to a danielebarchiesi@0: * Drupal path by the database, and which also may have been altered by other danielebarchiesi@0: * modules before this one. danielebarchiesi@0: * @param $original_path danielebarchiesi@0: * The original path, before being checked for path aliases or altered by any danielebarchiesi@0: * modules. danielebarchiesi@0: * @param $path_language danielebarchiesi@0: * The language of the path. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_get_normal_path() danielebarchiesi@0: */ danielebarchiesi@0: function hook_url_inbound_alter(&$path, $original_path, $path_language) { danielebarchiesi@0: // Create the path user/me/edit, which allows a user to edit their account. danielebarchiesi@0: if (preg_match('|^user/me/edit(/.*)?|', $path, $matches)) { danielebarchiesi@0: global $user; danielebarchiesi@0: $path = 'user/' . $user->uid . '/edit' . $matches[1]; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alters outbound URLs. danielebarchiesi@0: * danielebarchiesi@0: * @param $path danielebarchiesi@0: * The outbound path to alter, not adjusted for path aliases yet. It won't be danielebarchiesi@0: * adjusted for path aliases until all modules are finished altering it, thus danielebarchiesi@0: * being consistent with hook_url_inbound_alter(), which adjusts for all path danielebarchiesi@0: * aliases before allowing modules to alter it. This may have been altered by danielebarchiesi@0: * other modules before this one. danielebarchiesi@0: * @param $options danielebarchiesi@0: * A set of URL options for the URL so elements such as a fragment or a query danielebarchiesi@0: * string can be added to the URL. danielebarchiesi@0: * @param $original_path danielebarchiesi@0: * The original path, before being altered by any modules. danielebarchiesi@0: * danielebarchiesi@0: * @see url() danielebarchiesi@0: */ danielebarchiesi@0: function hook_url_outbound_alter(&$path, &$options, $original_path) { danielebarchiesi@0: // Use an external RSS feed rather than the Drupal one. danielebarchiesi@0: if ($path == 'rss.xml') { danielebarchiesi@0: $path = 'http://example.com/rss.xml'; danielebarchiesi@0: $options['external'] = TRUE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Instead of pointing to user/[uid]/edit, point to user/me/edit. danielebarchiesi@0: if (preg_match('|^user/([0-9]*)/edit(/.*)?|', $path, $matches)) { danielebarchiesi@0: global $user; danielebarchiesi@0: if ($user->uid == $matches[1]) { danielebarchiesi@0: $path = 'user/me/edit' . $matches[2]; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the username that is displayed for a user. danielebarchiesi@0: * danielebarchiesi@0: * Called by format_username() to allow modules to alter the username that's danielebarchiesi@0: * displayed. Can be used to ensure user privacy in situations where danielebarchiesi@0: * $account->name is too revealing. danielebarchiesi@0: * danielebarchiesi@0: * @param $name danielebarchiesi@0: * The string that format_username() will return. danielebarchiesi@0: * danielebarchiesi@0: * @param $account danielebarchiesi@0: * The account object passed to format_username(). danielebarchiesi@0: * danielebarchiesi@0: * @see format_username() danielebarchiesi@0: */ danielebarchiesi@0: function hook_username_alter(&$name, $account) { danielebarchiesi@0: // Display the user's uid instead of name. danielebarchiesi@0: if (isset($account->uid)) { danielebarchiesi@0: $name = t('User !uid', array('!uid' => $account->uid)); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Provide replacement values for placeholder tokens. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked when someone calls token_replace(). That function first danielebarchiesi@0: * scans the text for [type:token] patterns, and splits the needed tokens into danielebarchiesi@0: * groups by type. Then hook_tokens() is invoked on each token-type group, danielebarchiesi@0: * allowing your module to respond by providing replacement text for any of danielebarchiesi@0: * the tokens in the group that your module knows how to process. danielebarchiesi@0: * danielebarchiesi@0: * A module implementing this hook should also implement hook_token_info() in danielebarchiesi@0: * order to list its available tokens on editing screens. danielebarchiesi@0: * danielebarchiesi@0: * @param $type danielebarchiesi@0: * The machine-readable name of the type (group) of token being replaced, such danielebarchiesi@0: * as 'node', 'user', or another type defined by a hook_token_info() danielebarchiesi@0: * implementation. danielebarchiesi@0: * @param $tokens danielebarchiesi@0: * An array of tokens to be replaced. The keys are the machine-readable token danielebarchiesi@0: * names, and the values are the raw [type:token] strings that appeared in the danielebarchiesi@0: * original text. danielebarchiesi@0: * @param $data danielebarchiesi@0: * (optional) An associative array of data objects to be used when generating danielebarchiesi@0: * replacement values, as supplied in the $data parameter to token_replace(). danielebarchiesi@0: * @param $options danielebarchiesi@0: * (optional) An associative array of options for token replacement; see danielebarchiesi@0: * token_replace() for possible values. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array of replacement values, keyed by the raw [type:token] danielebarchiesi@0: * strings from the original text. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_token_info() danielebarchiesi@0: * @see hook_tokens_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_tokens($type, $tokens, array $data = array(), array $options = array()) { danielebarchiesi@0: $url_options = array('absolute' => TRUE); danielebarchiesi@0: if (isset($options['language'])) { danielebarchiesi@0: $url_options['language'] = $options['language']; danielebarchiesi@0: $language_code = $options['language']->language; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $language_code = NULL; danielebarchiesi@0: } danielebarchiesi@0: $sanitize = !empty($options['sanitize']); danielebarchiesi@0: danielebarchiesi@0: $replacements = array(); danielebarchiesi@0: danielebarchiesi@0: if ($type == 'node' && !empty($data['node'])) { danielebarchiesi@0: $node = $data['node']; danielebarchiesi@0: danielebarchiesi@0: foreach ($tokens as $name => $original) { danielebarchiesi@0: switch ($name) { danielebarchiesi@0: // Simple key values on the node. danielebarchiesi@0: case 'nid': danielebarchiesi@0: $replacements[$original] = $node->nid; danielebarchiesi@0: break; danielebarchiesi@0: danielebarchiesi@0: case 'title': danielebarchiesi@0: $replacements[$original] = $sanitize ? check_plain($node->title) : $node->title; danielebarchiesi@0: break; danielebarchiesi@0: danielebarchiesi@0: case 'edit-url': danielebarchiesi@0: $replacements[$original] = url('node/' . $node->nid . '/edit', $url_options); danielebarchiesi@0: break; danielebarchiesi@0: danielebarchiesi@0: // Default values for the chained tokens handled below. danielebarchiesi@0: case 'author': danielebarchiesi@0: $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name; danielebarchiesi@0: $replacements[$original] = $sanitize ? filter_xss($name) : $name; danielebarchiesi@0: break; danielebarchiesi@0: danielebarchiesi@0: case 'created': danielebarchiesi@0: $replacements[$original] = format_date($node->created, 'medium', '', NULL, $language_code); danielebarchiesi@0: break; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: if ($author_tokens = token_find_with_prefix($tokens, 'author')) { danielebarchiesi@0: $author = user_load($node->uid); danielebarchiesi@0: $replacements += token_generate('user', $author_tokens, array('user' => $author), $options); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: if ($created_tokens = token_find_with_prefix($tokens, 'created')) { danielebarchiesi@0: $replacements += token_generate('date', $created_tokens, array('date' => $node->created), $options); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $replacements; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter replacement values for placeholder tokens. danielebarchiesi@0: * danielebarchiesi@0: * @param $replacements danielebarchiesi@0: * An associative array of replacements returned by hook_tokens(). danielebarchiesi@0: * @param $context danielebarchiesi@0: * The context in which hook_tokens() was called. An associative array with danielebarchiesi@0: * the following keys, which have the same meaning as the corresponding danielebarchiesi@0: * parameters of hook_tokens(): danielebarchiesi@0: * - 'type' danielebarchiesi@0: * - 'tokens' danielebarchiesi@0: * - 'data' danielebarchiesi@0: * - 'options' danielebarchiesi@0: * danielebarchiesi@0: * @see hook_tokens() danielebarchiesi@0: */ danielebarchiesi@0: function hook_tokens_alter(array &$replacements, array $context) { danielebarchiesi@0: $options = $context['options']; danielebarchiesi@0: danielebarchiesi@0: if (isset($options['language'])) { danielebarchiesi@0: $url_options['language'] = $options['language']; danielebarchiesi@0: $language_code = $options['language']->language; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $language_code = NULL; danielebarchiesi@0: } danielebarchiesi@0: $sanitize = !empty($options['sanitize']); danielebarchiesi@0: danielebarchiesi@0: if ($context['type'] == 'node' && !empty($context['data']['node'])) { danielebarchiesi@0: $node = $context['data']['node']; danielebarchiesi@0: danielebarchiesi@0: // Alter the [node:title] token, and replace it with the rendered content danielebarchiesi@0: // of a field (field_title). danielebarchiesi@0: if (isset($context['tokens']['title'])) { danielebarchiesi@0: $title = field_view_field('node', $node, 'field_title', 'default', $language_code); danielebarchiesi@0: $replacements[$context['tokens']['title']] = drupal_render($title); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Provide information about available placeholder tokens and token types. danielebarchiesi@0: * danielebarchiesi@0: * Tokens are placeholders that can be put into text by using the syntax danielebarchiesi@0: * [type:token], where type is the machine-readable name of a token type, and danielebarchiesi@0: * token is the machine-readable name of a token within this group. This hook danielebarchiesi@0: * provides a list of types and tokens to be displayed on text editing screens, danielebarchiesi@0: * so that people editing text can see what their token options are. danielebarchiesi@0: * danielebarchiesi@0: * The actual token replacement is done by token_replace(), which invokes danielebarchiesi@0: * hook_tokens(). Your module will need to implement that hook in order to danielebarchiesi@0: * generate token replacements from the tokens defined here. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array of available tokens and token types. The outer array danielebarchiesi@0: * has two components: danielebarchiesi@0: * - types: An associative array of token types (groups). Each token type is danielebarchiesi@0: * an associative array with the following components: danielebarchiesi@0: * - name: The translated human-readable short name of the token type. danielebarchiesi@0: * - description: A translated longer description of the token type. danielebarchiesi@0: * - needs-data: The type of data that must be provided to token_replace() danielebarchiesi@0: * in the $data argument (i.e., the key name in $data) in order for tokens danielebarchiesi@0: * of this type to be used in the $text being processed. For instance, if danielebarchiesi@0: * the token needs a node object, 'needs-data' should be 'node', and to danielebarchiesi@0: * use this token in token_replace(), the caller needs to supply a node danielebarchiesi@0: * object as $data['node']. Some token data can also be supplied danielebarchiesi@0: * indirectly; for instance, a node object in $data supplies a user object danielebarchiesi@0: * (the author of the node), allowing user tokens to be used when only danielebarchiesi@0: * a node data object is supplied. danielebarchiesi@0: * - tokens: An associative array of tokens. The outer array is keyed by the danielebarchiesi@0: * group name (the same key as in the types array). Within each group of danielebarchiesi@0: * tokens, each token item is keyed by the machine name of the token, and danielebarchiesi@0: * each token item has the following components: danielebarchiesi@0: * - name: The translated human-readable short name of the token. danielebarchiesi@0: * - description: A translated longer description of the token. danielebarchiesi@0: * - type (optional): A 'needs-data' data type supplied by this token, which danielebarchiesi@0: * should match a 'needs-data' value from another token type. For example, danielebarchiesi@0: * the node author token provides a user object, which can then be used danielebarchiesi@0: * for token replacement data in token_replace() without having to supply danielebarchiesi@0: * a separate user object. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_token_info_alter() danielebarchiesi@0: * @see hook_tokens() danielebarchiesi@0: */ danielebarchiesi@0: function hook_token_info() { danielebarchiesi@0: $type = array( danielebarchiesi@0: 'name' => t('Nodes'), danielebarchiesi@0: 'description' => t('Tokens related to individual nodes.'), danielebarchiesi@0: 'needs-data' => 'node', danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Core tokens for nodes. danielebarchiesi@0: $node['nid'] = array( danielebarchiesi@0: 'name' => t("Node ID"), danielebarchiesi@0: 'description' => t("The unique ID of the node."), danielebarchiesi@0: ); danielebarchiesi@0: $node['title'] = array( danielebarchiesi@0: 'name' => t("Title"), danielebarchiesi@0: 'description' => t("The title of the node."), danielebarchiesi@0: ); danielebarchiesi@0: $node['edit-url'] = array( danielebarchiesi@0: 'name' => t("Edit URL"), danielebarchiesi@0: 'description' => t("The URL of the node's edit page."), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Chained tokens for nodes. danielebarchiesi@0: $node['created'] = array( danielebarchiesi@0: 'name' => t("Date created"), danielebarchiesi@0: 'description' => t("The date the node was posted."), danielebarchiesi@0: 'type' => 'date', danielebarchiesi@0: ); danielebarchiesi@0: $node['author'] = array( danielebarchiesi@0: 'name' => t("Author"), danielebarchiesi@0: 'description' => t("The author of the node."), danielebarchiesi@0: 'type' => 'user', danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: return array( danielebarchiesi@0: 'types' => array('node' => $type), danielebarchiesi@0: 'tokens' => array('node' => $node), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the metadata about available placeholder tokens and token types. danielebarchiesi@0: * danielebarchiesi@0: * @param $data danielebarchiesi@0: * The associative array of token definitions from hook_token_info(). danielebarchiesi@0: * danielebarchiesi@0: * @see hook_token_info() danielebarchiesi@0: */ danielebarchiesi@0: function hook_token_info_alter(&$data) { danielebarchiesi@0: // Modify description of node tokens for our site. danielebarchiesi@0: $data['tokens']['node']['nid'] = array( danielebarchiesi@0: 'name' => t("Node ID"), danielebarchiesi@0: 'description' => t("The unique ID of the article."), danielebarchiesi@0: ); danielebarchiesi@0: $data['tokens']['node']['title'] = array( danielebarchiesi@0: 'name' => t("Title"), danielebarchiesi@0: 'description' => t("The title of the article."), danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Chained tokens for nodes. danielebarchiesi@0: $data['tokens']['node']['created'] = array( danielebarchiesi@0: 'name' => t("Date created"), danielebarchiesi@0: 'description' => t("The date the article was posted."), danielebarchiesi@0: 'type' => 'date', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter batch information before a batch is processed. danielebarchiesi@0: * danielebarchiesi@0: * Called by batch_process() to allow modules to alter a batch before it is danielebarchiesi@0: * processed. danielebarchiesi@0: * danielebarchiesi@0: * @param $batch danielebarchiesi@0: * The associative array of batch information. See batch_set() for details on danielebarchiesi@0: * what this could contain. danielebarchiesi@0: * danielebarchiesi@0: * @see batch_set() danielebarchiesi@0: * @see batch_process() danielebarchiesi@0: * danielebarchiesi@0: * @ingroup batch danielebarchiesi@0: */ danielebarchiesi@0: function hook_batch_alter(&$batch) { danielebarchiesi@0: // If the current page request is inside the overlay, add ?render=overlay to danielebarchiesi@0: // the success callback URL, so that it appears correctly within the overlay. danielebarchiesi@0: if (overlay_get_mode() == 'child') { danielebarchiesi@0: if (isset($batch['url_options']['query'])) { danielebarchiesi@0: $batch['url_options']['query']['render'] = 'overlay'; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $batch['url_options']['query'] = array('render' => 'overlay'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Provide information on Updaters (classes that can update Drupal). danielebarchiesi@0: * danielebarchiesi@0: * An Updater is a class that knows how to update various parts of the Drupal danielebarchiesi@0: * file system, for example to update modules that have newer releases, or to danielebarchiesi@0: * install a new theme. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array of information about the updater(s) being provided. danielebarchiesi@0: * This array is keyed by a unique identifier for each updater, and the danielebarchiesi@0: * values are subarrays that can contain the following keys: danielebarchiesi@0: * - class: The name of the PHP class which implements this updater. danielebarchiesi@0: * - name: Human-readable name of this updater. danielebarchiesi@0: * - weight: Controls what order the Updater classes are consulted to decide danielebarchiesi@0: * which one should handle a given task. When an update task is being run, danielebarchiesi@0: * the system will loop through all the Updater classes defined in this danielebarchiesi@0: * registry in weight order and let each class respond to the task and danielebarchiesi@0: * decide if each Updater wants to handle the task. In general, this danielebarchiesi@0: * doesn't matter, but if you need to override an existing Updater, make danielebarchiesi@0: * sure your Updater has a lighter weight so that it comes first. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_get_updaters() danielebarchiesi@0: * @see hook_updater_info_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_updater_info() { danielebarchiesi@0: return array( danielebarchiesi@0: 'module' => array( danielebarchiesi@0: 'class' => 'ModuleUpdater', danielebarchiesi@0: 'name' => t('Update modules'), danielebarchiesi@0: 'weight' => 0, danielebarchiesi@0: ), danielebarchiesi@0: 'theme' => array( danielebarchiesi@0: 'class' => 'ThemeUpdater', danielebarchiesi@0: 'name' => t('Update themes'), danielebarchiesi@0: 'weight' => 0, danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the Updater information array. danielebarchiesi@0: * danielebarchiesi@0: * An Updater is a class that knows how to update various parts of the Drupal danielebarchiesi@0: * file system, for example to update modules that have newer releases, or to danielebarchiesi@0: * install a new theme. danielebarchiesi@0: * danielebarchiesi@0: * @param array $updaters danielebarchiesi@0: * Associative array of updaters as defined through hook_updater_info(). danielebarchiesi@0: * Alter this array directly. danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_get_updaters() danielebarchiesi@0: * @see hook_updater_info() danielebarchiesi@0: */ danielebarchiesi@0: function hook_updater_info_alter(&$updaters) { danielebarchiesi@0: // Adjust weight so that the theme Updater gets a chance to handle a given danielebarchiesi@0: // update task before module updaters. danielebarchiesi@0: $updaters['theme']['weight'] = -1; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the default country list. danielebarchiesi@0: * danielebarchiesi@0: * @param $countries danielebarchiesi@0: * The associative array of countries keyed by ISO 3166-1 country code. danielebarchiesi@0: * danielebarchiesi@0: * @see country_get_list() danielebarchiesi@0: * @see _country_get_predefined_list() danielebarchiesi@0: */ danielebarchiesi@0: function hook_countries_alter(&$countries) { danielebarchiesi@0: // Elbonia is now independent, so add it to the country list. danielebarchiesi@0: $countries['EB'] = 'Elbonia'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Control site status before menu dispatching. danielebarchiesi@0: * danielebarchiesi@0: * The hook is called after checking whether the site is offline but before danielebarchiesi@0: * the current router item is retrieved and executed by danielebarchiesi@0: * menu_execute_active_handler(). If the site is in offline mode, danielebarchiesi@0: * $menu_site_status is set to MENU_SITE_OFFLINE. danielebarchiesi@0: * danielebarchiesi@0: * @param $menu_site_status danielebarchiesi@0: * Supported values are MENU_SITE_OFFLINE, MENU_ACCESS_DENIED, danielebarchiesi@0: * MENU_NOT_FOUND and MENU_SITE_ONLINE. Any other value than danielebarchiesi@0: * MENU_SITE_ONLINE will skip the default menu handling system and be passed danielebarchiesi@0: * for delivery to drupal_deliver_page() with a NULL danielebarchiesi@0: * $default_delivery_callback. danielebarchiesi@0: * @param $path danielebarchiesi@0: * Contains the system path that is going to be loaded. This is read only, danielebarchiesi@0: * use hook_url_inbound_alter() to change the path. danielebarchiesi@0: */ danielebarchiesi@0: function hook_menu_site_status_alter(&$menu_site_status, $path) { danielebarchiesi@0: // Allow access to my_module/authentication even if site is in offline mode. danielebarchiesi@0: if ($menu_site_status == MENU_SITE_OFFLINE && user_is_anonymous() && $path == 'my_module/authentication') { danielebarchiesi@0: $menu_site_status = MENU_SITE_ONLINE; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Register information about FileTransfer classes provided by a module. danielebarchiesi@0: * danielebarchiesi@0: * The FileTransfer class allows transferring files over a specific type of danielebarchiesi@0: * connection. Core provides classes for FTP and SSH. Contributed modules are danielebarchiesi@0: * free to extend the FileTransfer base class to add other connection types, danielebarchiesi@0: * and if these classes are registered via hook_filetransfer_info(), those danielebarchiesi@0: * connection types will be available to site administrators using the Update danielebarchiesi@0: * manager when they are redirected to the authorize.php script to authorize danielebarchiesi@0: * the file operations. danielebarchiesi@0: * danielebarchiesi@0: * @return array danielebarchiesi@0: * Nested array of information about FileTransfer classes. Each key is a danielebarchiesi@0: * FileTransfer type (not human readable, used for form elements and danielebarchiesi@0: * variable names, etc), and the values are subarrays that define properties danielebarchiesi@0: * of that type. The keys in each subarray are: danielebarchiesi@0: * - 'title': Required. The human-readable name of the connection type. danielebarchiesi@0: * - 'class': Required. The name of the FileTransfer class. The constructor danielebarchiesi@0: * will always be passed the full path to the root of the site that should danielebarchiesi@0: * be used to restrict where file transfer operations can occur (the $jail) danielebarchiesi@0: * and an array of settings values returned by the settings form. danielebarchiesi@0: * - 'file': Required. The include file containing the FileTransfer class. danielebarchiesi@0: * This should be a separate .inc file, not just the .module file, so that danielebarchiesi@0: * the minimum possible code is loaded when authorize.php is running. danielebarchiesi@0: * - 'file path': Optional. The directory (relative to the Drupal root) danielebarchiesi@0: * where the include file lives. If not defined, defaults to the base danielebarchiesi@0: * directory of the module implementing the hook. danielebarchiesi@0: * - 'weight': Optional. Integer weight used for sorting connection types on danielebarchiesi@0: * the authorize.php form. danielebarchiesi@0: * danielebarchiesi@0: * @see FileTransfer danielebarchiesi@0: * @see authorize.php danielebarchiesi@0: * @see hook_filetransfer_info_alter() danielebarchiesi@0: * @see drupal_get_filetransfer_info() danielebarchiesi@0: */ danielebarchiesi@0: function hook_filetransfer_info() { danielebarchiesi@0: $info['sftp'] = array( danielebarchiesi@0: 'title' => t('SFTP (Secure FTP)'), danielebarchiesi@0: 'file' => 'sftp.filetransfer.inc', danielebarchiesi@0: 'class' => 'FileTransferSFTP', danielebarchiesi@0: 'weight' => 10, danielebarchiesi@0: ); danielebarchiesi@0: return $info; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Alter the FileTransfer class registry. danielebarchiesi@0: * danielebarchiesi@0: * @param array $filetransfer_info danielebarchiesi@0: * Reference to a nested array containing information about the FileTransfer danielebarchiesi@0: * class registry. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_filetransfer_info() danielebarchiesi@0: */ danielebarchiesi@0: function hook_filetransfer_info_alter(&$filetransfer_info) { danielebarchiesi@0: if (variable_get('paranoia', FALSE)) { danielebarchiesi@0: // Remove the FTP option entirely. danielebarchiesi@0: unset($filetransfer_info['ftp']); danielebarchiesi@0: // Make sure the SSH option is listed first. danielebarchiesi@0: $filetransfer_info['ssh']['weight'] = -10; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * @} End of "addtogroup hooks". danielebarchiesi@0: */ danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * @addtogroup callbacks danielebarchiesi@0: * @{ danielebarchiesi@0: */ danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return the URI for an entity. danielebarchiesi@0: * danielebarchiesi@0: * Callback for hook_entity_info(). danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity to return the URI for. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An associative array with the following elements: danielebarchiesi@0: * - 'path': The URL path for the entity. danielebarchiesi@0: * - 'options': (optional) An array of options for the url() function. danielebarchiesi@0: * The actual entity URI can be constructed by passing these elements to danielebarchiesi@0: * url(). danielebarchiesi@0: */ danielebarchiesi@0: function callback_entity_info_uri($entity) { danielebarchiesi@0: return array( danielebarchiesi@0: 'path' => 'node/' . $entity->nid, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return the label of an entity. danielebarchiesi@0: * danielebarchiesi@0: * Callback for hook_entity_info(). danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity for which to generate the label. danielebarchiesi@0: * @param $entity_type danielebarchiesi@0: * The entity type; e.g., 'node' or 'user'. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An unsanitized string with the label of the entity. danielebarchiesi@0: * danielebarchiesi@0: * @see entity_label() danielebarchiesi@0: */ danielebarchiesi@0: function callback_entity_info_label($entity, $entity_type) { danielebarchiesi@0: return empty($entity->title) ? 'Untitled entity' : $entity->title; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return the language code of the entity. danielebarchiesi@0: * danielebarchiesi@0: * Callback for hook_entity_info(). danielebarchiesi@0: * danielebarchiesi@0: * The language callback is meant to be used primarily for temporary alterations danielebarchiesi@0: * of the property value. danielebarchiesi@0: * danielebarchiesi@0: * @param $entity danielebarchiesi@0: * The entity for which to return the language. danielebarchiesi@0: * @param $entity_type danielebarchiesi@0: * The entity type; e.g., 'node' or 'user'. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * The language code for the language of the entity. danielebarchiesi@0: * danielebarchiesi@0: * @see entity_language() danielebarchiesi@0: */ danielebarchiesi@0: function callback_entity_info_language($entity, $entity_type) { danielebarchiesi@0: return $entity->language; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * @} End of "addtogroup callbacks". danielebarchiesi@0: */ danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * @defgroup update_api Update versions of API functions danielebarchiesi@0: * @{ danielebarchiesi@0: * Functions that are similar to normal API functions, but do not invoke hooks. danielebarchiesi@0: * danielebarchiesi@0: * These simplified versions of core API functions are provided for use by danielebarchiesi@0: * update functions (hook_update_N() implementations). danielebarchiesi@0: * danielebarchiesi@0: * During database updates the schema of any module could be out of date. For danielebarchiesi@0: * this reason, caution is needed when using any API function within an update danielebarchiesi@0: * function - particularly CRUD functions, functions that depend on the schema danielebarchiesi@0: * (for example by using drupal_write_record()), and any functions that invoke danielebarchiesi@0: * hooks. danielebarchiesi@0: * danielebarchiesi@0: * Instead, a simplified utility function should be used. If a utility version danielebarchiesi@0: * of the API function you require does not already exist, then you should danielebarchiesi@0: * create a new function. The new utility function should be named danielebarchiesi@0: * _update_N_mymodule_my_function(). N is the schema version the function acts danielebarchiesi@0: * on (the schema version is the number N from the hook_update_N() danielebarchiesi@0: * implementation where this schema was introduced, or a number following the danielebarchiesi@0: * same numbering scheme), and mymodule_my_function is the name of the original danielebarchiesi@0: * API function including the module's name. danielebarchiesi@0: * danielebarchiesi@0: * Examples: danielebarchiesi@0: * - _update_6000_mymodule_save(): This function performs a save operation danielebarchiesi@0: * without invoking any hooks using the 6.x schema. danielebarchiesi@0: * - _update_7000_mymodule_save(): This function performs the same save danielebarchiesi@0: * operation using the 7.x schema. danielebarchiesi@0: * danielebarchiesi@0: * The utility function should not invoke any hooks, and should perform database danielebarchiesi@0: * operations using functions from the danielebarchiesi@0: * @link database Database abstraction layer, @endlink danielebarchiesi@0: * like db_insert(), db_update(), db_delete(), db_query(), and so on. danielebarchiesi@0: * danielebarchiesi@0: * If a change to the schema necessitates a change to the utility function, a danielebarchiesi@0: * new function should be created with a name based on the version of the schema danielebarchiesi@0: * it acts on. See _update_7000_bar_get_types() and _update_7001_bar_get_types() danielebarchiesi@0: * in the code examples that follow. danielebarchiesi@0: * danielebarchiesi@0: * For example, foo.install could contain: danielebarchiesi@0: * @code danielebarchiesi@0: * function foo_update_dependencies() { danielebarchiesi@0: * // foo_update_7010() needs to run after bar_update_7000(). danielebarchiesi@0: * $dependencies['foo'][7010] = array( danielebarchiesi@0: * 'bar' => 7000, danielebarchiesi@0: * ); danielebarchiesi@0: * danielebarchiesi@0: * // foo_update_7036() needs to run after bar_update_7001(). danielebarchiesi@0: * $dependencies['foo'][7036] = array( danielebarchiesi@0: * 'bar' => 7001, danielebarchiesi@0: * ); danielebarchiesi@0: * danielebarchiesi@0: * return $dependencies; danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function foo_update_7000() { danielebarchiesi@0: * // No updates have been run on the {bar_types} table yet, so this needs danielebarchiesi@0: * // to work with the 6.x schema. danielebarchiesi@0: * foreach (_update_6000_bar_get_types() as $type) { danielebarchiesi@0: * // Rename a variable. danielebarchiesi@0: * } danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function foo_update_7010() { danielebarchiesi@0: * // Since foo_update_7010() is going to run after bar_update_7000(), it danielebarchiesi@0: * // needs to operate on the new schema, not the old one. danielebarchiesi@0: * foreach (_update_7000_bar_get_types() as $type) { danielebarchiesi@0: * // Rename a different variable. danielebarchiesi@0: * } danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function foo_update_7036() { danielebarchiesi@0: * // This update will run after bar_update_7001(). danielebarchiesi@0: * foreach (_update_7001_bar_get_types() as $type) { danielebarchiesi@0: * } danielebarchiesi@0: * } danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * And bar.install could contain: danielebarchiesi@0: * @code danielebarchiesi@0: * function bar_update_7000() { danielebarchiesi@0: * // Type and bundle are confusing, so we renamed the table. danielebarchiesi@0: * db_rename_table('bar_types', 'bar_bundles'); danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function bar_update_7001() { danielebarchiesi@0: * // Database table names should be singular when possible. danielebarchiesi@0: * db_rename_table('bar_bundles', 'bar_bundle'); danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function _update_6000_bar_get_types() { danielebarchiesi@0: * db_query('SELECT * FROM {bar_types}')->fetchAll(); danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function _update_7000_bar_get_types() { danielebarchiesi@0: * db_query('SELECT * FROM {bar_bundles'})->fetchAll(); danielebarchiesi@0: * } danielebarchiesi@0: * danielebarchiesi@0: * function _update_7001_bar_get_types() { danielebarchiesi@0: * db_query('SELECT * FROM {bar_bundle}')->fetchAll(); danielebarchiesi@0: * } danielebarchiesi@0: * @endcode danielebarchiesi@0: * danielebarchiesi@0: * @see hook_update_N() danielebarchiesi@0: * @see hook_update_dependencies() danielebarchiesi@0: */ danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * @} End of "defgroup update_api". danielebarchiesi@0: */