PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/system/system.api.php

https://bitbucket.org/amar_ravikumar/sassy-drupal-drinks-coffee
PHP | 4780 lines | 1372 code | 183 blank | 3225 comment | 127 complexity | 5b839370cbc960220f1cbee9994f4856 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, AGPL-1.0, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by Drupal core and the System module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Defines one or more hooks that are exposed by a module.
  12. *
  13. * Normally hooks do not need to be explicitly defined. However, by declaring a
  14. * hook explicitly, a module may define a "group" for it. Modules that implement
  15. * a hook may then place their implementation in either $module.module or in
  16. * $module.$group.inc. If the hook is located in $module.$group.inc, then that
  17. * file will be automatically loaded when needed.
  18. * In general, hooks that are rarely invoked and/or are very large should be
  19. * placed in a separate include file, while hooks that are very short or very
  20. * frequently called should be left in the main module file so that they are
  21. * always available.
  22. *
  23. * @return
  24. * An associative array whose keys are hook names and whose values are an
  25. * associative array containing:
  26. * - group: A string defining the group to which the hook belongs. The module
  27. * system will determine whether a file with the name $module.$group.inc
  28. * exists, and automatically load it when required.
  29. *
  30. * See system_hook_info() for all hook groups defined by Drupal core.
  31. *
  32. * @see hook_hook_info_alter().
  33. */
  34. function hook_hook_info() {
  35. $hooks['token_info'] = array(
  36. 'group' => 'tokens',
  37. );
  38. $hooks['tokens'] = array(
  39. 'group' => 'tokens',
  40. );
  41. return $hooks;
  42. }
  43. /**
  44. * Alter information from hook_hook_info().
  45. *
  46. * @param $hooks
  47. * Information gathered by module_hook_info() from other modules'
  48. * implementations of hook_hook_info(). Alter this array directly.
  49. * See hook_hook_info() for information on what this may contain.
  50. */
  51. function hook_hook_info_alter(&$hooks) {
  52. // Our module wants to completely override the core tokens, so make
  53. // sure the core token hooks are not found.
  54. $hooks['token_info']['group'] = 'mytokens';
  55. $hooks['tokens']['group'] = 'mytokens';
  56. }
  57. /**
  58. * Inform the base system and the Field API about one or more entity types.
  59. *
  60. * Inform the system about one or more entity types (i.e., object types that
  61. * can be loaded via entity_load() and, optionally, to which fields can be
  62. * attached).
  63. *
  64. * @return
  65. * An array whose keys are entity type names and whose values identify
  66. * properties of those types that the system needs to know about:
  67. * - label: The human-readable name of the type.
  68. * - controller class: The name of the class that is used to load the objects.
  69. * The class has to implement the DrupalEntityControllerInterface interface.
  70. * Leave blank to use the DrupalDefaultEntityController implementation.
  71. * - base table: (used by DrupalDefaultEntityController) The name of the
  72. * entity type's base table.
  73. * - revision table: The name of the entity type's revision table (if any).
  74. * - static cache: (used by DrupalDefaultEntityController) FALSE to disable
  75. * static caching of entities during a page request. Defaults to TRUE.
  76. * - field cache: (used by Field API loading and saving of field data) FALSE
  77. * to disable Field API's persistent cache of field data. Only recommended
  78. * if a higher level persistent cache is available for the entity type.
  79. * Defaults to TRUE.
  80. * - load hook: The name of the hook which should be invoked by
  81. * DrupalDefaultEntityController:attachLoad(), for example 'node_load'.
  82. * - uri callback: A function taking an entity as argument and returning the
  83. * URI elements of the entity, e.g. 'path' and 'options'. The actual entity
  84. * URI can be constructed by passing these elements to url().
  85. * - label callback: (optional) A function taking an entity and an entity type
  86. * as arguments and returning the label of the entity. The entity label is
  87. * the main string associated with an entity; for example, the title of a
  88. * node or the subject of a comment. If there is an entity object property
  89. * that defines the label, use the 'label' element of the 'entity keys'
  90. * return value component to provide this information (see below). If more
  91. * complex logic is needed to determine the label of an entity, you can
  92. * instead specify a callback function here, which will be called to
  93. * determine the entity label. See also the entity_label() function, which
  94. * implements this logic.
  95. * - language callback: (optional) A function taking an entity and an entity
  96. * type as arguments and returning a language code. In most situations, when
  97. * needing to determine this value, inspecting a property named after the
  98. * 'language' element of the 'entity keys' should be enough. The language
  99. * callback is meant to be used primarily for temporary alterations of the
  100. * property value: entity-defining modules are encouraged to always define a
  101. * language property, instead of using the callback as main entity language
  102. * source. In fact not having a language property defined is likely to
  103. * prevent an entity from being queried by language. Moreover, given that
  104. * entity_language() is not necessarily used everywhere it would be
  105. * appropriate, modules implementing the language callback should be aware
  106. * that this might not be always called.
  107. * - fieldable: Set to TRUE if you want your entity type to accept fields
  108. * being attached to it.
  109. * - translation: An associative array of modules registered as field
  110. * translation handlers. Array keys are the module names, array values
  111. * can be any data structure the module uses to provide field translation.
  112. * Any empty value disallows the module to appear as a translation handler.
  113. * - entity keys: An array describing how the Field API can extract the
  114. * information it needs from the objects of the type. Elements:
  115. * - id: The name of the property that contains the primary id of the
  116. * entity. Every entity object passed to the Field API must have this
  117. * property and its value must be numeric.
  118. * - revision: The name of the property that contains the revision id of
  119. * the entity. The Field API assumes that all revision ids are unique
  120. * across all entities of a type. This entry can be omitted if the
  121. * entities of this type are not versionable.
  122. * - bundle: The name of the property that contains the bundle name for the
  123. * entity. The bundle name defines which set of fields are attached to
  124. * the entity (e.g. what nodes call "content type"). This entry can be
  125. * omitted if this entity type exposes a single bundle (all entities have
  126. * the same collection of fields). The name of this single bundle will be
  127. * the same as the entity type.
  128. * - label: The name of the property that contains the entity label. For
  129. * example, if the entity's label is located in $entity->subject, then
  130. * 'subject' should be specified here. If complex logic is required to
  131. * build the label, a 'label callback' should be defined instead (see
  132. * the 'label callback' section above for details).
  133. * - language: The name of the property, typically 'language', that contains
  134. * the language code representing the language the entity has been created
  135. * in. This value may be changed when editing the entity and represents
  136. * the language its textual components are supposed to have. If no
  137. * language property is available, the 'language callback' may be used
  138. * instead. This entry can be omitted if the entities of this type are not
  139. * language-aware.
  140. * - bundle keys: An array describing how the Field API can extract the
  141. * information it needs from the bundle objects for this type. This entry
  142. * is required if the 'path' provided in the 'bundles'/'admin' section
  143. * identifies the bundle using a named menu placeholder whose loader
  144. * callback returns an object (e.g., $vocabulary for taxonomy terms, or
  145. * $node_type for nodes). If the path does not include the bundle, or the
  146. * bundle is just a string rather than an automatically loaded object, then
  147. * this can be omitted. Elements:
  148. * - bundle: The name of the property of the bundle object that contains
  149. * the name of the bundle object.
  150. * - bundles: An array describing all bundles for this object type. Keys are
  151. * bundles machine names, as found in the objects' 'bundle' property
  152. * (defined in the 'entity keys' entry above). Elements:
  153. * - label: The human-readable name of the bundle.
  154. * - uri callback: Same as the 'uri callback' key documented above for the
  155. * entity type, but for the bundle only. When determining the URI of an
  156. * entity, if a 'uri callback' is defined for both the entity type and
  157. * the bundle, the one for the bundle is used.
  158. * - admin: An array of information that allows Field UI pages to attach
  159. * themselves to the existing administration pages for the bundle.
  160. * Elements:
  161. * - path: the path of the bundle's main administration page, as defined
  162. * in hook_menu(). If the path includes a placeholder for the bundle,
  163. * the 'bundle argument' and 'real path' keys below are required.
  164. * - bundle argument: The position of the bundle placeholder in 'path', if
  165. * any.
  166. * - real path: The actual path (no placeholder) of the bundle's main
  167. * administration page. This will be used to generate links.
  168. * - access callback: As in hook_menu(). 'user_access' will be assumed if
  169. * no value is provided.
  170. * - access arguments: As in hook_menu().
  171. * - view modes: An array describing the view modes for the entity type. View
  172. * modes let entities be displayed differently depending on the context.
  173. * For instance, a node can be displayed differently on its own page
  174. * ('full' mode), on the home page or taxonomy listings ('teaser' mode), or
  175. * in an RSS feed ('rss' mode). Modules taking part in the display of the
  176. * entity (notably the Field API) can adjust their behavior depending on
  177. * the requested view mode. An additional 'default' view mode is available
  178. * for all entity types. This view mode is not intended for actual entity
  179. * display, but holds default display settings. For each available view
  180. * mode, administrators can configure whether it should use its own set of
  181. * field display settings, or just replicate the settings of the 'default'
  182. * view mode, thus reducing the amount of display configurations to keep
  183. * track of. Keys of the array are view mode names. Each view mode is
  184. * described by an array with the following key/value pairs:
  185. * - label: The human-readable name of the view mode
  186. * - custom settings: A boolean specifying whether the view mode should by
  187. * default use its own custom field display settings. If FALSE, entities
  188. * displayed in this view mode will reuse the 'default' display settings
  189. * by default (e.g. right after the module exposing the view mode is
  190. * enabled), but administrators can later use the Field UI to apply custom
  191. * display settings specific to the view mode.
  192. *
  193. * @see entity_load()
  194. * @see hook_entity_info_alter()
  195. */
  196. function hook_entity_info() {
  197. $return = array(
  198. 'node' => array(
  199. 'label' => t('Node'),
  200. 'controller class' => 'NodeController',
  201. 'base table' => 'node',
  202. 'revision table' => 'node_revision',
  203. 'uri callback' => 'node_uri',
  204. 'fieldable' => TRUE,
  205. 'translation' => array(
  206. 'locale' => TRUE,
  207. ),
  208. 'entity keys' => array(
  209. 'id' => 'nid',
  210. 'revision' => 'vid',
  211. 'bundle' => 'type',
  212. 'language' => 'language',
  213. ),
  214. 'bundle keys' => array(
  215. 'bundle' => 'type',
  216. ),
  217. 'bundles' => array(),
  218. 'view modes' => array(
  219. 'full' => array(
  220. 'label' => t('Full content'),
  221. 'custom settings' => FALSE,
  222. ),
  223. 'teaser' => array(
  224. 'label' => t('Teaser'),
  225. 'custom settings' => TRUE,
  226. ),
  227. 'rss' => array(
  228. 'label' => t('RSS'),
  229. 'custom settings' => FALSE,
  230. ),
  231. ),
  232. ),
  233. );
  234. // Search integration is provided by node.module, so search-related
  235. // view modes for nodes are defined here and not in search.module.
  236. if (module_exists('search')) {
  237. $return['node']['view modes'] += array(
  238. 'search_index' => array(
  239. 'label' => t('Search index'),
  240. 'custom settings' => FALSE,
  241. ),
  242. 'search_result' => array(
  243. 'label' => t('Search result'),
  244. 'custom settings' => FALSE,
  245. ),
  246. );
  247. }
  248. // Bundles must provide a human readable name so we can create help and error
  249. // messages, and the path to attach Field admin pages to.
  250. foreach (node_type_get_names() as $type => $name) {
  251. $return['node']['bundles'][$type] = array(
  252. 'label' => $name,
  253. 'admin' => array(
  254. 'path' => 'admin/structure/types/manage/%node_type',
  255. 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type),
  256. 'bundle argument' => 4,
  257. 'access arguments' => array('administer content types'),
  258. ),
  259. );
  260. }
  261. return $return;
  262. }
  263. /**
  264. * Alter the entity info.
  265. *
  266. * Modules may implement this hook to alter the information that defines an
  267. * entity. All properties that are available in hook_entity_info() can be
  268. * altered here.
  269. *
  270. * @param $entity_info
  271. * The entity info array, keyed by entity name.
  272. *
  273. * @see hook_entity_info()
  274. */
  275. function hook_entity_info_alter(&$entity_info) {
  276. // Set the controller class for nodes to an alternate implementation of the
  277. // DrupalEntityController interface.
  278. $entity_info['node']['controller class'] = 'MyCustomNodeController';
  279. }
  280. /**
  281. * Act on entities when loaded.
  282. *
  283. * This is a generic load hook called for all entity types loaded via the
  284. * entity API.
  285. *
  286. * @param $entities
  287. * The entities keyed by entity ID.
  288. * @param $type
  289. * The type of entities being loaded (i.e. node, user, comment).
  290. */
  291. function hook_entity_load($entities, $type) {
  292. foreach ($entities as $entity) {
  293. $entity->foo = mymodule_add_something($entity, $type);
  294. }
  295. }
  296. /**
  297. * Act on an entity before it is about to be created or updated.
  298. *
  299. * @param $entity
  300. * The entity object.
  301. * @param $type
  302. * The type of entity being saved (i.e. node, user, comment).
  303. */
  304. function hook_entity_presave($entity, $type) {
  305. $entity->changed = REQUEST_TIME;
  306. }
  307. /**
  308. * Act on entities when inserted.
  309. *
  310. * @param $entity
  311. * The entity object.
  312. * @param $type
  313. * The type of entity being inserted (i.e. node, user, comment).
  314. */
  315. function hook_entity_insert($entity, $type) {
  316. // Insert the new entity into a fictional table of all entities.
  317. $info = entity_get_info($type);
  318. list($id) = entity_extract_ids($type, $entity);
  319. db_insert('example_entity')
  320. ->fields(array(
  321. 'type' => $type,
  322. 'id' => $id,
  323. 'created' => REQUEST_TIME,
  324. 'updated' => REQUEST_TIME,
  325. ))
  326. ->execute();
  327. }
  328. /**
  329. * Act on entities when updated.
  330. *
  331. * @param $entity
  332. * The entity object.
  333. * @param $type
  334. * The type of entity being updated (i.e. node, user, comment).
  335. */
  336. function hook_entity_update($entity, $type) {
  337. // Update the entity's entry in a fictional table of all entities.
  338. $info = entity_get_info($type);
  339. list($id) = entity_extract_ids($type, $entity);
  340. db_update('example_entity')
  341. ->fields(array(
  342. 'updated' => REQUEST_TIME,
  343. ))
  344. ->condition('type', $type)
  345. ->condition('id', $id)
  346. ->execute();
  347. }
  348. /**
  349. * Act on entities when deleted.
  350. *
  351. * @param $entity
  352. * The entity object.
  353. * @param $type
  354. * The type of entity being deleted (i.e. node, user, comment).
  355. */
  356. function hook_entity_delete($entity, $type) {
  357. // Delete the entity's entry from a fictional table of all entities.
  358. $info = entity_get_info($type);
  359. list($id) = entity_extract_ids($type, $entity);
  360. db_delete('example_entity')
  361. ->condition('type', $type)
  362. ->condition('id', $id)
  363. ->execute();
  364. }
  365. /**
  366. * Alter or execute an EntityFieldQuery.
  367. *
  368. * @param EntityFieldQuery $query
  369. * An EntityFieldQuery. One of the most important properties to be changed is
  370. * EntityFieldQuery::executeCallback. If this is set to an existing function,
  371. * this function will get the query as its single argument and its result
  372. * will be the returned as the result of EntityFieldQuery::execute(). This can
  373. * be used to change the behavior of EntityFieldQuery entirely. For example,
  374. * the default implementation can only deal with one field storage engine, but
  375. * it is possible to write a module that can query across field storage
  376. * engines. Also, the default implementation presumes entities are stored in
  377. * SQL, but the execute callback could instead query any other entity storage,
  378. * local or remote.
  379. *
  380. * Note the $query->altered attribute which is TRUE in case the query has
  381. * already been altered once. This happens with cloned queries.
  382. * If there is a pager, then such a cloned query will be executed to count
  383. * all elements. This query can be detected by checking for
  384. * ($query->pager && $query->count), allowing the driver to return 0 from
  385. * the count query and disable the pager.
  386. */
  387. function hook_entity_query_alter($query) {
  388. $query->executeCallback = 'my_module_query_callback';
  389. }
  390. /**
  391. * Act on entities being assembled before rendering.
  392. *
  393. * @param $entity
  394. * The entity object.
  395. * @param $type
  396. * The type of entity being rendered (i.e. node, user, comment).
  397. * @param $view_mode
  398. * The view mode the entity is rendered in.
  399. * @param $langcode
  400. * The language code used for rendering.
  401. *
  402. * The module may add elements to $entity->content prior to rendering. The
  403. * structure of $entity->content is a renderable array as expected by
  404. * drupal_render().
  405. *
  406. * @see hook_entity_view_alter()
  407. * @see hook_comment_view()
  408. * @see hook_node_view()
  409. * @see hook_user_view()
  410. */
  411. function hook_entity_view($entity, $type, $view_mode, $langcode) {
  412. $entity->content['my_additional_field'] = array(
  413. '#markup' => $additional_field,
  414. '#weight' => 10,
  415. '#theme' => 'mymodule_my_additional_field',
  416. );
  417. }
  418. /**
  419. * Alter the results of ENTITY_view().
  420. *
  421. * This hook is called after the content has been assembled in a structured
  422. * array and may be used for doing processing which requires that the complete
  423. * entity content structure has been built.
  424. *
  425. * If a module wishes to act on the rendered HTML of the entity rather than the
  426. * structured content array, it may use this hook to add a #post_render
  427. * callback. Alternatively, it could also implement hook_preprocess_ENTITY().
  428. * See drupal_render() and theme() for details.
  429. *
  430. * @param $build
  431. * A renderable array representing the entity content.
  432. * @param $type
  433. * The type of entity being rendered (i.e. node, user, comment).
  434. *
  435. * @see hook_entity_view()
  436. * @see hook_comment_view_alter()
  437. * @see hook_node_view_alter()
  438. * @see hook_taxonomy_term_view_alter()
  439. * @see hook_user_view_alter()
  440. */
  441. function hook_entity_view_alter(&$build, $type) {
  442. if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
  443. // Change its weight.
  444. $build['an_additional_field']['#weight'] = -10;
  445. // Add a #post_render callback to act on the rendered HTML of the entity.
  446. $build['#post_render'][] = 'my_module_node_post_render';
  447. }
  448. }
  449. /**
  450. * Change the view mode of an entity that is being displayed.
  451. *
  452. * @param string $view_mode
  453. * The view_mode that is to be used to display the entity.
  454. * @param array $context
  455. * Array with contextual information, including:
  456. * - entity_type: The type of the entity that is being viewed.
  457. * - entity: The entity object.
  458. * - langcode: The langcode the entity is being viewed in.
  459. */
  460. function hook_entity_view_mode_alter(&$view_mode, $context) {
  461. // For nodes, change the view mode when it is teaser.
  462. if ($context['entity_type'] == 'node' && $view_mode == 'teaser') {
  463. $view_mode = 'my_custom_view_mode';
  464. }
  465. }
  466. /**
  467. * Define administrative paths.
  468. *
  469. * Modules may specify whether or not the paths they define in hook_menu() are
  470. * to be considered administrative. Other modules may use this information to
  471. * display those pages differently (e.g. in a modal overlay, or in a different
  472. * theme).
  473. *
  474. * To change the administrative status of menu items defined in another module's
  475. * hook_menu(), modules should implement hook_admin_paths_alter().
  476. *
  477. * @return
  478. * An associative array. For each item, the key is the path in question, in
  479. * a format acceptable to drupal_match_path(). The value for each item should
  480. * be TRUE (for paths considered administrative) or FALSE (for non-
  481. * administrative paths).
  482. *
  483. * @see hook_menu()
  484. * @see drupal_match_path()
  485. * @see hook_admin_paths_alter()
  486. */
  487. function hook_admin_paths() {
  488. $paths = array(
  489. 'mymodule/*/add' => TRUE,
  490. 'mymodule/*/edit' => TRUE,
  491. );
  492. return $paths;
  493. }
  494. /**
  495. * Redefine administrative paths defined by other modules.
  496. *
  497. * @param $paths
  498. * An associative array of administrative paths, as defined by implementations
  499. * of hook_admin_paths().
  500. *
  501. * @see hook_admin_paths()
  502. */
  503. function hook_admin_paths_alter(&$paths) {
  504. // Treat all user pages as administrative.
  505. $paths['user'] = TRUE;
  506. $paths['user/*'] = TRUE;
  507. // Treat the forum topic node form as a non-administrative page.
  508. $paths['node/add/forum'] = FALSE;
  509. }
  510. /**
  511. * Act on entities as they are being prepared for view.
  512. *
  513. * Allows you to operate on multiple entities as they are being prepared for
  514. * view. Only use this if attaching the data during the entity_load() phase
  515. * is not appropriate, for example when attaching other 'entity' style objects.
  516. *
  517. * @param $entities
  518. * The entities keyed by entity ID.
  519. * @param $type
  520. * The type of entities being loaded (i.e. node, user, comment).
  521. * @param $langcode
  522. * The language to display the entity in.
  523. */
  524. function hook_entity_prepare_view($entities, $type, $langcode) {
  525. // Load a specific node into the user object for later theming.
  526. if ($type == 'user') {
  527. $nodes = mymodule_get_user_nodes(array_keys($entities));
  528. foreach ($entities as $uid => $entity) {
  529. $entity->user_node = $nodes[$uid];
  530. }
  531. }
  532. }
  533. /**
  534. * Perform periodic actions.
  535. *
  536. * Modules that require some commands to be executed periodically can
  537. * implement hook_cron(). The engine will then call the hook whenever a cron
  538. * run happens, as defined by the administrator. Typical tasks managed by
  539. * hook_cron() are database maintenance, backups, recalculation of settings
  540. * or parameters, automated mailing, and retrieving remote data.
  541. *
  542. * Short-running or non-resource-intensive tasks can be executed directly in
  543. * the hook_cron() implementation.
  544. *
  545. * Long-running tasks and tasks that could time out, such as retrieving remote
  546. * data, sending email, and intensive file tasks, should use the queue API
  547. * instead of executing the tasks directly. To do this, first define one or
  548. * more queues via hook_cron_queue_info(). Then, add items that need to be
  549. * processed to the defined queues.
  550. */
  551. function hook_cron() {
  552. // Short-running operation example, not using a queue:
  553. // Delete all expired records since the last cron run.
  554. $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME);
  555. db_delete('mymodule_table')
  556. ->condition('expires', $expires, '>=')
  557. ->execute();
  558. variable_set('mymodule_cron_last_run', REQUEST_TIME);
  559. // Long-running operation example, leveraging a queue:
  560. // Fetch feeds from other sites.
  561. $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array(
  562. ':time' => REQUEST_TIME,
  563. ':never' => AGGREGATOR_CLEAR_NEVER,
  564. ));
  565. $queue = DrupalQueue::get('aggregator_feeds');
  566. foreach ($result as $feed) {
  567. $queue->createItem($feed);
  568. }
  569. }
  570. /**
  571. * Declare queues holding items that need to be run periodically.
  572. *
  573. * While there can be only one hook_cron() process running at the same time,
  574. * there can be any number of processes defined here running. Because of
  575. * this, long running tasks are much better suited for this API. Items queued
  576. * in hook_cron() might be processed in the same cron run if there are not many
  577. * items in the queue, otherwise it might take several requests, which can be
  578. * run in parallel.
  579. *
  580. * @return
  581. * An associative array where the key is the queue name and the value is
  582. * again an associative array. Possible keys are:
  583. * - 'worker callback': The name of the function to call. It will be called
  584. * with one argument, the item created via DrupalQueue::createItem() in
  585. * hook_cron().
  586. * - 'time': (optional) How much time Drupal should spend on calling this
  587. * worker in seconds. Defaults to 15.
  588. *
  589. * @see hook_cron()
  590. * @see hook_cron_queue_info_alter()
  591. */
  592. function hook_cron_queue_info() {
  593. $queues['aggregator_feeds'] = array(
  594. 'worker callback' => 'aggregator_refresh',
  595. 'time' => 60,
  596. );
  597. return $queues;
  598. }
  599. /**
  600. * Alter cron queue information before cron runs.
  601. *
  602. * Called by drupal_cron_run() to allow modules to alter cron queue settings
  603. * before any jobs are processesed.
  604. *
  605. * @param array $queues
  606. * An array of cron queue information.
  607. *
  608. * @see hook_cron_queue_info()
  609. * @see drupal_cron_run()
  610. */
  611. function hook_cron_queue_info_alter(&$queues) {
  612. // This site has many feeds so let's spend 90 seconds on each cron run
  613. // updating feeds instead of the default 60.
  614. $queues['aggregator_feeds']['time'] = 90;
  615. }
  616. /**
  617. * Allows modules to declare their own Form API element types and specify their
  618. * default values.
  619. *
  620. * This hook allows modules to declare their own form element types and to
  621. * specify their default values. The values returned by this hook will be
  622. * merged with the elements returned by hook_form() implementations and so
  623. * can return defaults for any Form APIs keys in addition to those explicitly
  624. * mentioned below.
  625. *
  626. * Each of the form element types defined by this hook is assumed to have
  627. * a matching theme function, e.g. theme_elementtype(), which should be
  628. * registered with hook_theme() as normal.
  629. *
  630. * For more information about custom element types see the explanation at
  631. * http://drupal.org/node/169815.
  632. *
  633. * @return
  634. * An associative array describing the element types being defined. The array
  635. * contains a sub-array for each element type, with the machine-readable type
  636. * name as the key. Each sub-array has a number of possible attributes:
  637. * - "#input": boolean indicating whether or not this element carries a value
  638. * (even if it's hidden).
  639. * - "#process": array of callback functions taking $element, $form_state,
  640. * and $complete_form.
  641. * - "#after_build": array of callback functions taking $element and $form_state.
  642. * - "#validate": array of callback functions taking $form and $form_state.
  643. * - "#element_validate": array of callback functions taking $element and
  644. * $form_state.
  645. * - "#pre_render": array of callback functions taking $element and $form_state.
  646. * - "#post_render": array of callback functions taking $element and $form_state.
  647. * - "#submit": array of callback functions taking $form and $form_state.
  648. * - "#title_display": optional string indicating if and how #title should be
  649. * displayed, see theme_form_element() and theme_form_element_label().
  650. *
  651. * @see hook_element_info_alter()
  652. * @see system_element_info()
  653. */
  654. function hook_element_info() {
  655. $types['filter_format'] = array(
  656. '#input' => TRUE,
  657. );
  658. return $types;
  659. }
  660. /**
  661. * Alter the element type information returned from modules.
  662. *
  663. * A module may implement this hook in order to alter the element type defaults
  664. * defined by a module.
  665. *
  666. * @param $type
  667. * All element type defaults as collected by hook_element_info().
  668. *
  669. * @see hook_element_info()
  670. */
  671. function hook_element_info_alter(&$type) {
  672. // Decrease the default size of textfields.
  673. if (isset($type['textfield']['#size'])) {
  674. $type['textfield']['#size'] = 40;
  675. }
  676. }
  677. /**
  678. * Perform cleanup tasks.
  679. *
  680. * This hook is run at the end of each page request. It is often used for
  681. * page logging and specialized cleanup. This hook MUST NOT print anything
  682. * because by the time it runs the response is already sent to the browser.
  683. *
  684. * Only use this hook if your code must run even for cached page views.
  685. * If you have code which must run once on all non-cached pages, use
  686. * hook_init() instead. That is the usual case. If you implement this hook
  687. * and see an error like 'Call to undefined function', it is likely that
  688. * you are depending on the presence of a module which has not been loaded yet.
  689. * It is not loaded because Drupal is still in bootstrap mode.
  690. *
  691. * @param $destination
  692. * If this hook is invoked as part of a drupal_goto() call, then this argument
  693. * will be a fully-qualified URL that is the destination of the redirect.
  694. */
  695. function hook_exit($destination = NULL) {
  696. db_update('counter')
  697. ->expression('hits', 'hits + 1')
  698. ->condition('type', 1)
  699. ->execute();
  700. }
  701. /**
  702. * Perform necessary alterations to the JavaScript before it is presented on
  703. * the page.
  704. *
  705. * @param $javascript
  706. * An array of all JavaScript being presented on the page.
  707. *
  708. * @see drupal_add_js()
  709. * @see drupal_get_js()
  710. * @see drupal_js_defaults()
  711. */
  712. function hook_js_alter(&$javascript) {
  713. // Swap out jQuery to use an updated version of the library.
  714. $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';
  715. }
  716. /**
  717. * Registers JavaScript/CSS libraries associated with a module.
  718. *
  719. * Modules implementing this return an array of arrays. The key to each
  720. * sub-array is the machine readable name of the library. Each library may
  721. * contain the following items:
  722. *
  723. * - 'title': The human readable name of the library.
  724. * - 'website': The URL of the library's web site.
  725. * - 'version': A string specifying the version of the library; intentionally
  726. * not a float because a version like "1.2.3" is not a valid float. Use PHP's
  727. * version_compare() to compare different versions.
  728. * - 'js': An array of JavaScript elements; each element's key is used as $data
  729. * argument, each element's value is used as $options array for
  730. * drupal_add_js(). To add library-specific (not module-specific) JavaScript
  731. * settings, the key may be skipped, the value must specify
  732. * 'type' => 'setting', and the actual settings must be contained in a 'data'
  733. * element of the value.
  734. * - 'css': Like 'js', an array of CSS elements passed to drupal_add_css().
  735. * - 'dependencies': An array of libraries that are required for a library. Each
  736. * element is an array listing the module and name of another library. Note
  737. * that all dependencies for each dependent library will also be added when
  738. * this library is added.
  739. *
  740. * Registered information for a library should contain re-usable data only.
  741. * Module- or implementation-specific data and integration logic should be added
  742. * separately.
  743. *
  744. * @return
  745. * An array defining libraries associated with a module.
  746. *
  747. * @see system_library()
  748. * @see drupal_add_library()
  749. * @see drupal_get_library()
  750. */
  751. function hook_library() {
  752. // Library One.
  753. $libraries['library-1'] = array(
  754. 'title' => 'Library One',
  755. 'website' => 'http://example.com/library-1',
  756. 'version' => '1.2',
  757. 'js' => array(
  758. drupal_get_path('module', 'my_module') . '/library-1.js' => array(),
  759. ),
  760. 'css' => array(
  761. drupal_get_path('module', 'my_module') . '/library-2.css' => array(
  762. 'type' => 'file',
  763. 'media' => 'screen',
  764. ),
  765. ),
  766. );
  767. // Library Two.
  768. $libraries['library-2'] = array(
  769. 'title' => 'Library Two',
  770. 'website' => 'http://example.com/library-2',
  771. 'version' => '3.1-beta1',
  772. 'js' => array(
  773. // JavaScript settings may use the 'data' key.
  774. array(
  775. 'type' => 'setting',
  776. 'data' => array('library2' => TRUE),
  777. ),
  778. ),
  779. 'dependencies' => array(
  780. // Require jQuery UI core by System module.
  781. array('system', 'ui'),
  782. // Require our other library.
  783. array('my_module', 'library-1'),
  784. // Require another library.
  785. array('other_module', 'library-3'),
  786. ),
  787. );
  788. return $libraries;
  789. }
  790. /**
  791. * Alters the JavaScript/CSS library registry.
  792. *
  793. * Allows certain, contributed modules to update libraries to newer versions
  794. * while ensuring backwards compatibility. In general, such manipulations should
  795. * only be done by designated modules, since most modules that integrate with a
  796. * certain library also depend on the API of a certain library version.
  797. *
  798. * @param $libraries
  799. * The JavaScript/CSS libraries provided by $module. Keyed by internal library
  800. * name and passed by reference.
  801. * @param $module
  802. * The name of the module that registered the libraries.
  803. *
  804. * @see hook_library()
  805. */
  806. function hook_library_alter(&$libraries, $module) {
  807. // Update Farbtastic to version 2.0.
  808. if ($module == 'system' && isset($libraries['farbtastic'])) {
  809. // Verify existing version is older than the one we are updating to.
  810. if (version_compare($libraries['farbtastic']['version'], '2.0', '<')) {
  811. // Update the existing Farbtastic to version 2.0.
  812. $libraries['farbtastic']['version'] = '2.0';
  813. $libraries['farbtastic']['js'] = array(
  814. drupal_get_path('module', 'farbtastic_update') . '/farbtastic-2.0.js' => array(),
  815. );
  816. }
  817. }
  818. }
  819. /**
  820. * Alter CSS files before they are output on the page.
  821. *
  822. * @param $css
  823. * An array of all CSS items (files and inline CSS) being requested on the page.
  824. *
  825. * @see drupal_add_css()
  826. * @see drupal_get_css()
  827. */
  828. function hook_css_alter(&$css) {
  829. // Remove defaults.css file.
  830. unset($css[drupal_get_path('module', 'system') . '/defaults.css']);
  831. }
  832. /**
  833. * Alter the commands that are sent to the user through the Ajax framework.
  834. *
  835. * @param $commands
  836. * An array of all commands that will be sent to the user.
  837. *
  838. * @see ajax_render()
  839. */
  840. function hook_ajax_render_alter($commands) {
  841. // Inject any new status messages into the content area.
  842. $commands[] = ajax_command_prepend('#block-system-main .content', theme('status_messages'));
  843. }
  844. /**
  845. * Add elements to a page before it is rendered.
  846. *
  847. * Use this hook when you want to add elements at the page level. For your
  848. * additions to be printed, they have to be placed below a top level array key
  849. * of the $page array that has the name of a region of the active theme.
  850. *
  851. * By default, valid region keys are 'page_top', 'header', 'sidebar_first',
  852. * 'content', 'sidebar_second' and 'page_bottom'. To get a list of all regions
  853. * of the active theme, use system_region_list($theme). Note that $theme is a
  854. * global variable.
  855. *
  856. * If you want to alter the elements added by other modules or if your module
  857. * depends on the elements of other modules, use hook_page_alter() instead which
  858. * runs after this hook.
  859. *
  860. * @param $page
  861. * Nested array of renderable elements that make up the page.
  862. *
  863. * @see hook_page_alter()
  864. * @see drupal_render_page()
  865. */
  866. function hook_page_build(&$page) {
  867. if (menu_get_object('node', 1)) {
  868. // We are on a node detail page. Append a standard disclaimer to the
  869. // content region.
  870. $page['content']['disclaimer'] = array(
  871. '#markup' => t('Acme, Inc. is not responsible for the contents of this sample code.'),
  872. '#weight' => 25,
  873. );
  874. }
  875. }
  876. /**
  877. * Alter a menu router item right after it has been retrieved from the database or cache.
  878. *
  879. * This hook is invoked by menu_get_item() and allows for run-time alteration of router
  880. * information (page_callback, title, and so on) before it is translated and checked for
  881. * access. The passed-in $router_item is statically cached for the current request, so this
  882. * hook is only invoked once for any router item that is retrieved via menu_get_item().
  883. *
  884. * Usually, modules will only want to inspect the router item and conditionally
  885. * perform other actions (such as preparing a state for the current request).
  886. * Note that this hook is invoked for any router item that is retrieved by
  887. * menu_get_item(), which may or may not be called on the path itself, so implementations
  888. * should check the $path parameter if the alteration should fire for the current request
  889. * only.
  890. *
  891. * @param $router_item
  892. * The menu router item for $path.
  893. * @param $path
  894. * The originally passed path, for which $router_item is responsible.
  895. * @param $original_map
  896. * The path argument map, as contained in $path.
  897. *
  898. * @see menu_get_item()
  899. */
  900. function hook_menu_get_item_alter(&$router_item, $path, $original_map) {
  901. // When retrieving the router item for the current path...
  902. if ($path == $_GET['q']) {
  903. // ...call a function that prepares something for this request.
  904. mymodule_prepare_something();
  905. }
  906. }
  907. /**
  908. * Define menu items and page callbacks.
  909. *
  910. * This hook enables modules to register paths in order to define how URL
  911. * requests are handled. Paths may be registered for URL handling only, or they
  912. * can register a link to be placed in a menu (usually the Navigation menu). A
  913. * path and its associated information is commonly called a "menu router item".
  914. * This hook is rarely called (for example, when modules are enabled), and
  915. * its results are cached in the database.
  916. *
  917. * hook_menu() implementations return an associative array whose keys define
  918. * paths and whose values are an associative array of properties for each
  919. * path. (The complete list of properties is in the return value section below.)
  920. *
  921. * The definition for each path may include a page callback function, which is
  922. * invoked when the registered path is requested. If there is no other
  923. * registered path that fits the requested path better, any further path
  924. * components are passed to the callback function. For example, your module
  925. * could register path 'abc/def':
  926. * @code
  927. * function mymodule_menu() {
  928. * $items['abc/def'] = array(
  929. * 'page callback' => 'mymodule_abc_view',
  930. * );
  931. * return $items;
  932. * }
  933. *
  934. * function mymodule_abc_view($ghi = 0, $jkl = '') {
  935. * // ...
  936. * }
  937. * @endcode
  938. * When path 'abc/def' is requested, no further path components are in the
  939. * request, and no additional arguments are passed to the callback function (so
  940. * $ghi and $jkl would take the default values as defined in the function
  941. * signature). When 'abc/def/123/foo' is requested, $ghi will be '123' and
  942. * $jkl will be 'foo'. Note that this automatic passing of optional path
  943. * arguments applies only to page and theme callback functions.
  944. *
  945. * In addition to optional path arguments, the page callback and other callback
  946. * functions may specify argument lists as arrays. These argument lists may
  947. * contain both fixed/hard-coded argument values and integers that correspond
  948. * to path components. When integers are used and the callback function is
  949. * called, the corresponding path components will be substituted for the
  950. * integers. That is, the integer 0 in an argument list will be replaced with
  951. * the first path component, integer 1 with the second, and so on (path
  952. * components are numbered starting from zero). To pass an integer without it
  953. * being replaced with its respective path component, use the string value of
  954. * the integer (e.g., '1') as the argument value. This substitution feature
  955. * allows you to re-use a callback function for several different paths. For
  956. * example:
  957. * @code
  958. * function mymodule_menu() {
  959. * $items['abc/def'] = array(
  960. * 'page callback' => 'mymodule_abc_view',
  961. * 'page arguments' => array(1, 'foo'),
  962. * );
  963. * return $items;
  964. * }
  965. * @endcode
  966. * When path 'abc/def' is requested, the page callback function will get 'def'
  967. * as the first argument and (always) 'foo' as the second argument.
  968. *
  969. * If a page callback function uses an argument list array, and its path is
  970. * requested with optional path arguments, then the list array's arguments are
  971. * passed to the callback function first, followed by the optional path
  972. * arguments. Using the above example, when path 'abc/def/bar/baz' is requested,
  973. * mymodule_abc_view() will be called with 'def', 'foo', 'bar' and 'baz' as
  974. * arguments, in that order.
  975. *
  976. * Special care should be taken for the page callback drupal_get_form(), because
  977. * your specific form callback function will always receive $form and
  978. * &$form_state as the first function arguments:
  979. * @code
  980. * function mymodule_abc_form($form, &$form_state) {
  981. * // ...
  982. * return $form;
  983. * }
  984. * @endcode
  985. * See @link form_api Form API documentation @endlink for details.
  986. *
  987. * Wildcards within paths also work with integer substitution. For example,
  988. * your module could register path 'my-module/%/edit':
  989. * @code
  990. * $items['my-module/%/edit'] = array(
  991. * 'page callback' => 'mymodule_abc_edit',
  992. * 'page arguments' => array(1),
  993. * );
  994. * @endcode
  995. * When path 'my-module/foo/edit' is requested, integer 1 will be replaced
  996. * with 'foo' and passed to the callback function. Note that wildcards may not
  997. * be used as the first component.
  998. *
  999. * Registered paths may also contain special "auto-loader" wildcard components
  1000. * in the form of '%mymodule_abc', where the '%' part means that this path
  1001. * component is a wildcard, and the 'mymodule_abc' part defines the prefix for a
  1002. * load function, which here would be named mymodule_abc_load(). When a matching
  1003. * path is requested, your load function will receive as its first argument the
  1004. * path component in the position of the wildcard; load functions may also be
  1005. * passed additional arguments (see "load arguments" in the return value
  1006. * section below). For example, your module could register path
  1007. * 'my-module/%mymodule_abc/edit':
  1008. * @code
  1009. * $items['my-module/%mymodule_abc/edit'] = array(
  1010. * 'page callback' => 'mymodule_abc_edit',
  1011. * 'page arguments' => array(1),
  1012. * );
  1013. * @endcode
  1014. * When path 'my-module/123/edit' is requested, your load function
  1015. * mymodule_abc_load() will be invoked with the argument '123', and should
  1016. * load and return an "abc" object with internal id 123:
  1017. * @code
  1018. * function mymodule_abc_load($abc_id) {
  1019. * return db_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject();
  1020. * }
  1021. * @endcode
  1022. * This 'abc' object will then be passed into the callback functions defined
  1023. * for the menu item, such as the page callback function mymodule_abc_edit()
  1024. * to replace the integer 1 in the argument array. Note that a load function
  1025. * should return FALSE when it is unable to provide a loadable object. For
  1026. * example, the node_load() function for the 'node/%node/edit' menu item will
  1027. * return FALSE for the path 'node/999/edit' if a node with a node ID of 999
  1028. * does not exist. The menu routing system will return a 404 error in this case.
  1029. *
  1030. * You can also define a %wildcard_to_arg() function (for the example menu
  1031. * entry above this would be 'mymodule_abc_to_arg()'). The _to_arg() function
  1032. * is invoked to retrieve a value that is used in the path in place of the
  1033. * wildcard. A good example is user.module, which defines
  1034. * user_uid_optional_to_arg() (corresponding to the menu entry
  1035. * 'tracker/%user_uid_optional'). This function returns the user ID of the
  1036. * current user.
  1037. *
  1038. * The _to_arg() function will get called with three arguments:
  1039. * - $arg: A string representing whatever argument may have been supplied by
  1040. * the caller (this is particularly useful if you want the _to_arg()
  1041. * function only supply a (default) value if no other value is specified,
  1042. * as in the case of user_uid_optional_to_arg().
  1043. * - $map: An array of all path fragments (e.g. array('node','123','edit') for
  1044. * 'node/123/edit').
  1045. * - $index: An integer indicating which element of $map corresponds to $arg.
  1046. *
  1047. * _load() and _to_arg() functions may seem similar at first glance, but they
  1048. * have different purposes and are called at different times. _load()
  1049. * functions are called when the menu system is collecting arguments to pass
  1050. * to the callback functions defined for the menu item. _to_arg() functions
  1051. * are called when the menu system is generating links to related paths, such
  1052. * as the tabs for a set of MENU_LOCAL_TASK items.
  1053. *
  1054. * You can also make groups of menu items to be rendered (by default) as tabs
  1055. * on a page. To do that, first create one menu item of type MENU_NORMAL_ITEM,
  1056. * with your chosen path, such as 'foo'. Then duplicate that menu item, using a
  1057. * subdirectory path, such as 'foo/tab1', and changing the type to
  1058. * MENU_DEFAULT_LOCAL_TASK to make it the default tab for the group. Then add
  1059. * the additional tab items, with paths such as "foo/tab2" etc., with type
  1060. * MENU_LOCAL_TASK. Example:
  1061. * @code
  1062. * // Make "Foo settings" appear on the admin Config page
  1063. * $items['admin/config/system/foo'] = array(
  1064. * 'title' => 'Foo settings',
  1065. * 'type' => MENU_NORMAL_ITEM,
  1066. * // Page callback, etc. need to be added here.
  1067. * );
  1068. * // Make "Tab 1" the main tab on the "Foo settings" page
  1069. * $items['admin/config/system/foo/tab1'] = array(
  1070. * 'title' => 'Tab 1',
  1071. * 'type' => MENU_DEFAULT_LOCAL_TASK,
  1072. * // Access callback, page callback, and theme callback will be inherited
  1073. * // from 'admin/config/system/foo', if not specified here to override.
  1074. * );
  1075. * // Make an additional tab called "Tab 2" on "Foo settings"
  1076. * $items['admin/config/system/foo/tab2'] = array(
  1077. * 'title' => 'Tab 2',
  1078. * 'type' => MENU_LOCAL_TASK,
  1079. * // Page callback and theme callback will be inherited from
  1080. * // 'admin/config/system/foo', if not specified here to override.
  1081. * // Need to add access callback or access arguments.
  1082. * );
  1083. * @endcode
  1084. *
  1085. * @return
  1086. * An array of menu items. Each menu item has a key corresponding to the
  1087. * Drupal path being registered. The corresponding array value is an
  1088. * associative array that may contain the following key-value pairs:
  1089. * - "title": Required. The untranslated title of the menu item.
  1090. * - "title callback": Function to generate the title; defaults to t().
  1091. * If you require only the raw string to be output, set this to FALSE.
  1092. * - "title arguments": Arguments to send to t() or your custom callback,
  1093. * with path component substitution as described above.
  1094. * - "description": The untranslated description of the menu item.
  1095. * - "page callback": The function to call to display a web page when the user
  1096. * visits the path. If omitted, the parent menu item's callback will be used
  1097. * instead.
  1098. * - "page arguments": An array of arguments to pass to the page callback
  1099. * function, with path component substitution as described above.
  1100. * - "delivery callback": The function to call to package the result of the
  1101. * page callback function and send it to the browser. Defaults to
  1102. * drupal_deliver_html_page() unless a value is inherited from a parent menu
  1103. * item. Note that this function is called even if the access checks fail,
  1104. * so any custom delivery callback function should take that into account.
  1105. * See drupal_deliver_html_page() for an example.
  1106. * - "access callback": A function returning TRUE if the user has access
  1107. * rights to this menu item, and FALSE if not. It can also be a boolean
  1108. * constant instead of a function, and you can also use numeric values
  1109. * (will be cast to boolean). Defaults to user_access() unless a value is
  1110. * inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items
  1111. * can inherit access callbacks. To use the user_access() default callback,
  1112. * you must specify the permission to check as 'access arguments' (see
  1113. * below).
  1114. * - "access arguments": An array of arguments to pass to the access callback
  1115. * function, with path component substitution as described above. If the
  1116. * access callback is inherited (see above), the access arguments will be
  1117. * inherited with it, unless overridden in the child menu item.
  1118. * - "theme callback": (optional) A function returning the machine-readable
  1119. * name of the theme that will be used to render the page. If not provided,
  1120. * the value will be inherited from a parent menu item. If there is no
  1121. * theme callback, or if the function does not return the name of a current
  1122. * active theme on the site, the theme for this page will be determined by
  1123. * either hook_custom_theme() or the default theme instead. As a general
  1124. * rule, the use of theme callback functions should be limited to pages
  1125. * whose functionality is very closely tied to a particular theme, since
  1126. * they can only be overridden by modules which specifically target those
  1127. * pages in hook_menu_alter(). Modules implementing more generic theme
  1128. * switching functionality (for example, a module which allows the theme to
  1129. * be set dynamically based on the current user's role) should use
  1130. * hook_custom_theme() instead.
  1131. * - "theme arguments": An array of arguments to pass to the theme callback
  1132. * function, with path component substitution as described above.
  1133. * - "file": A file that will be included before the page callback is called;
  1134. * this allows page callback functions to be in separate files. The file
  1135. * should be relative to the implementing module's directory unless
  1136. * otherwise specified by the "file path" option. Does not apply to other
  1137. * callbacks (only page callback).
  1138. * - "file path": The path to the directory containing the file specified in
  1139. * "file". This defaults to the path to the module implementing the hook.
  1140. * - "load arguments": An array of arguments to be passed to each of the
  1141. * wildcard object loaders in the path, after the path argument itself.
  1142. * For example, if a module registers path node/%node/revisions/%/view
  1143. * with load arguments set to array(3), the '%node' in the path indicates
  1144. * that the loader function node_load() will be called with the second
  1145. * path component as the first argument. The 3 in the load argum…

Large files files are truncated, but you can click here to view the full file