PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/system/system.api.php

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

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