国外设计欣赏网站 - DOOOOR.com

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,微信登陆

搜索

[Drupal教程] Drupal的组成部分 1.模块系统(Drupal钩子)

[复制链接]
发表于 11-29-2011 07:26 | 显示全部楼层 |阅读模式

让模块与Drupal核心关联。

Drupal的模块系统基于“钩子” 。钩子是一个PHP函数,名为foo_bar ( ) ,其中“foo"是模块的模块(其文件名这样是foo.module )同时“ bar ”是钩子的名字。每个钩子的定义参数设置和某一特定结果的类型。

为了扩大Drupal功能,一个模块只需实现一个简单钩子。当Drupal允许能够模块作用,表明哪些模块执行了一个钩子并且调用这个钩子来启用模块。实现现有的钩子宰这儿被解释开发者文档的钩子部分。字符串“hook”是作为模块名称的钩子定义的一个占位符。例如,如果模块文件名为example.module ,然后实现hook_help( )以该模块example_help( )来定义。


函数

名称
位置
描述
custom_url_rewrite_inboundmodules/system/system.api.phpcustom_url_rewrite_inbound is not a hook, it's a function you can add to settings.php to alter incoming requests so they map to a Drupal path. This function is called before modules are loaded and the menu system is initialized and it changes...
custom_url_rewrite_outboundmodules/system/system.api.phpcustom_url_rewrite_outbound is not a hook, it's a function you can add to settings.php to alter all links generated by Drupal. This function is called from url(). This function is called very frequently (100+ times per page) so performance...
hook_accessmodules/node/node.api.phpDefine access restrictions.
hook_actions_deletemodules/trigger/trigger.api.phpExecute code after an action is deleted.
hook_action_infomodules/trigger/trigger.api.phpDeclare information about one or more Drupal actions.
hook_action_info_altermodules/trigger/trigger.api.phpAlter the actions declared by another module.
hook_aggregator_fetchmodules/aggregator/aggregator.api.phpImplement this hook to create an alternative fetcher for aggregator module.
hook_aggregator_fetch_infomodules/aggregator/aggregator.api.phpImplement this hook to expose the title and a short description of your fetcher.
hook_aggregator_parsemodules/aggregator/aggregator.api.phpImplement this hook to create an alternative parser for aggregator module.
hook_aggregator_parse_infomodules/aggregator/aggregator.api.phpImplement this hook to expose the title and a short description of your parser.
hook_aggregator_processmodules/aggregator/aggregator.api.phpImplement this hook to create a processor for aggregator module.
hook_aggregator_process_infomodules/aggregator/aggregator.api.phpImplement this hook to expose the title and a short description of your processor.
hook_aggregator_removemodules/aggregator/aggregator.api.phpImplement this hook to remove stored data if a feed is being deleted or a feed's items are being removed.
hook_block_configuremodules/block/block.api.phpConfiguration form for the block.
hook_block_listmodules/block/block.api.phpList of all blocks defined by the module.
hook_block_savemodules/block/block.api.phpSave the configuration options.
hook_block_viewmodules/block/block.api.phpProcess the block when enabled in a region in order to view its contents.
hook_bootmodules/system/system.api.phpPerform setup tasks. See also, hook_init.
hook_comment_deletemodules/comment/comment.api.phpThe comment is being deleted by the moderator.
hook_comment_insertmodules/comment/comment.api.phpThe comment is being inserted.
hook_comment_publishmodules/comment/comment.api.phpThe comment is being published by the moderator.
hook_comment_unpublishmodules/comment/comment.api.phpThe comment is being unpublished by the moderator.
hook_comment_updatemodules/comment/comment.api.phpThe comment is being updated.
hook_comment_validatemodules/comment/comment.api.phpThe user has just finished editing the comment and is trying to preview or submit it. This hook can be used to check or even modify the node. Errors should be set with form_set_error().
hook_comment_viewmodules/comment/comment.api.phpThe comment is being viewed. This hook can be used to add additional data to the comment before theming.
hook_cronmodules/system/system.api.phpPerform periodic actions.
hook_db_rewrite_sqlmodules/system/system.api.phpRewrite database queries, usually for access control.
hook_deletemodules/node/node.api.phpRespond to node deletion.
hook_disablemodules/system/system.api.phpPerform necessary actions before module is disabled.
hook_elementsmodules/system/system.api.phpAllows modules to declare their own Forms API element types and specify their default values.
hook_enablemodules/system/system.api.phpPerform necessary actions after module is enabled.
hook_exitmodules/system/system.api.phpPerform cleanup tasks.
hook_file_copymodules/system/system.api.phpRespond to a file that has been copied.
hook_file_deletemodules/system/system.api.phpRespond to a file being deleted.
hook_file_downloadmodules/system/system.api.phpControl access to private file downloads and specify HTTP headers.
hook_file_insertmodules/system/system.api.phpRespond to a file being added.
hook_file_loadmodules/system/system.api.phpLoad additional information into file objects.
hook_file_movemodules/system/system.api.phpRespond to a file that has been moved.
hook_file_referencesmodules/system/system.api.phpReport the number of times a file is referenced by a module.
hook_file_statusmodules/system/system.api.phpRespond to a file that has changed status.
hook_file_updatemodules/system/system.api.phpRespond to a file being updated.
hook_file_validatemodules/system/system.api.phpCheck that files meet a given criteria.
hook_filtermodules/filter/filter.api.phpDefine content filters.
hook_filter_tipsmodules/filter/filter.api.phpProvide tips for using filters.
hook_flush_cachesmodules/system/system.api.phpAdd a list of cache tables to be cleared.
hook_footermodules/system/system.api.phpInsert closing HTML.
hook_formmodules/node/node.api.phpDisplay a node editing form.
hook_formsmodules/system/system.api.phpMap form_ids to builder functions.
hook_form_altermodules/system/system.api.phpPerform alterations before a form is rendered.
hook_form_FORM_ID_altermodules/system/system.api.phpProvide a form-specific alteration instead of the global hook_form_alter().
hook_helpmodules/help/help.api.phpProvide online user help.
hook_hook_infomodules/trigger/trigger.api.phpExpose a list of triggers (events) that your module is allowing users to assign actions to.
hook_image_toolkitsmodules/system/system.api.phpDefine image toolkits provided by this module. * The file which includes each toolkit's functions must be declared as part of the files array in the module .info file so that the registry will find and parse it. * *
hook_initmodules/system/system.api.phpPerform setup tasks. See also, hook_boot.
hook_insertmodules/node/node.api.phpRespond to node insertion.
hook_installmodules/system/system.api.phpInstall the current version of the database schema, and any other setup tasks.
hook_js_altermodules/system/system.api.phpPerform necessary alterations to the JavaScript before it is presented on the page.
hook_linkmodules/system/system.api.phpDefine internal Drupal links.
hook_link_altermodules/system/system.api.phpPerform alterations before links on a comment are rendered. One popular use of this hook is to add/delete links from other modules.
hook_loadmodules/node/node.api.phpLoad node-type-specific information.
hook_localemodules/locale/locale.api.phpAllows modules to define their own text groups that can be translated.
hook_mailmodules/system/system.api.phpPrepare a message based on parameters. @see drupal_mail for more.
hook_mail_altermodules/system/system.api.phpAlter any aspect of the emails sent by Drupal. You can use this hook to add a common site footer to all outgoing emails; add extra header fields and/or modify the mails sent out in any way. HTML-izing the outgoing mails is one possibility. See also...
hook_menumodules/menu/menu.api.phpDefine menu items and page callbacks.
hook_menu_altermodules/menu/menu.api.phpAlter the data being saved to the {menu_router} table after hook_menu is invoked.
hook_menu_link_altermodules/menu/menu.api.phpAlter the data being saved to the {menu_links} table bymenu_link_save().
hook_modules_disabledmodules/system/system.api.phpPerform necessary actions after modules are disabled.
hook_modules_enabledmodules/system/system.api.phpPerform necessary actions after modules are enabled.
hook_modules_installedmodules/system/system.api.phpPerform necessary actions after modules are installed.
hook_modules_uninstalledmodules/system/system.api.phpPerform necessary actions after modules are uninstalled.
hook_nodeapi_altermodules/node/node.api.phpFiter, substitute or otherwise alter the $node's raw text.
hook_nodeapi_deletemodules/node/node.api.phpAct on node deletion.
hook_nodeapi_delete_revisionmodules/node/node.api.phpA revision of the node is deleted.
hook_nodeapi_insertmodules/node/node.api.phpThe node being created (inserted in the database).
hook_nodeapi_loadmodules/node/node.api.phpAct on node objects when loaded.
hook_nodeapi_preparemodules/node/node.api.phpThe node is about to be shown on the add/edit form.
hook_nodeapi_prepare_translationmodules/node/node.api.phpThe node is being cloned for translation.
hook_nodeapi_presavemodules/node/node.api.phpThe node passed validation and is about to be saved.
hook_nodeapi_rss_itemmodules/node/node.api.phpAn RSS feed is being generated.
hook_nodeapi_search_resultmodules/node/node.api.phpThe node is being displayed as a search result.
hook_nodeapi_updatemodules/node/node.api.phpThe node being updated.
hook_nodeapi_update_indexmodules/node/node.api.phpThe node is being indexed.
hook_nodeapi_validatemodules/node/node.api.phpThe user has finished editing the node and is previewing or submitting it.
hook_nodeapi_viewmodules/node/node.api.phpThe node content is being assembled before rendering.
hook_node_access_recordsmodules/node/node.api.phpSet permissions for a node to be written to the database.
hook_node_grantsmodules/node/node.api.phpInform the node access system what permissions the user has.
hook_node_infomodules/node/node.api.phpDefine module-provided node types.
hook_node_operationsmodules/node/node.api.phpAdd mass node operations.
hook_node_typemodules/node/node.api.phpAct on node type changes.
hook_permmodules/system/system.api.phpDefine user permissions.
hook_preparemodules/node/node.api.phpThis is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.
hook_profile_altermodules/system/system.api.phpPerform alterations profile items before they are rendered. You may omit/add/re-sort/re-categorize, etc.
hook_query_altermodules/system/system.api.phpPerform alterations to a structured query.
hook_query_TAG_altermodules/system/system.api.phpPerform alterations to a structured query for a given tag. See alsohook_query_alter()
hook_requirementsmodules/system/system.api.phpCheck installation requirements and do status reporting.
hook_schemamodules/system/system.api.phpDefine the current version of the database schema.
hook_schema_altermodules/system/system.api.phpPerform alterations to existing database schemas.
hook_searchmodules/search/search.api.phpDefine a custom search routine.
hook_search_preprocessmodules/search/search.api.phpPreprocess text for the search index.
hook_system_info_altermodules/system/system.api.phpAlter the information parsed from module and theme .info files
hook_taxonomy_term_deletemodules/taxonomy/taxonomy.api.phpRespond to the deletion of taxonomy terms.
hook_taxonomy_term_insertmodules/taxonomy/taxonomy.api.phpAct on taxonomy terms when inserted.
hook_taxonomy_term_loadmodules/taxonomy/taxonomy.api.phpAct on taxonomy terms when loaded.
hook_taxonomy_term_updatemodules/taxonomy/taxonomy.api.phpAct on taxonomy terms when updated.
hook_taxonomy_vocabulary_deletemodules/taxonomy/taxonomy.api.phpRespond to the deletion of taxonomy vocabularies.
hook_taxonomy_vocabulary_insertmodules/taxonomy/taxonomy.api.phpAct on taxonomy vocabularies when inserted.
hook_taxonomy_vocabulary_loadmodules/taxonomy/taxonomy.api.phpAct on taxonomy vocabularies when loaded.
hook_taxonomy_vocabulary_updatemodules/taxonomy/taxonomy.api.phpAct on taxonomy vocabularies when updated.
hook_thememodules/system/system.api.phpRegister a module (or theme's) theme implementations.
hook_theme_registry_altermodules/system/system.api.phpAlter the theme registry information returned fromhook_theme().
hook_translated_menu_link_altermodules/menu/menu.api.phpAlter a menu link after it's translated, but before it's rendered.
hook_translation_link_altermodules/locale/locale.api.phpPerform alterations on translation links.
hook_uninstallmodules/system/system.api.phpRemove any information that the module sets.
hook_updatemodules/node/node.api.phpRespond to node updating.
hook_update_indexmodules/search/search.api.phpUpdate Drupal's full-text index for this module.
hook_update_Nmodules/system/system.api.phpPerform a single update. For each patch which requires a database change add a newhook_update_N() which will be called by update.php.
hook_update_status_altermodules/update/update.api.phpAlter the information about available updates for projects.
hook_usermodules/user/user.api.phpAct on user account actions.
hook_user_cancelmodules/user/user.api.phpAct on user account cancellations.
hook_user_cancel_methods_altermodules/user/user.api.phpModify account cancellation methods.
hook_user_operationsmodules/user/user.api.phpAdd mass user operations.
hook_validatemodules/node/node.api.phpVerify a node editing form.
hook_viewmodules/node/node.api.phpDisplay a node.
hook_watchdogmodules/system/system.api.phpLog an event message
hook_xmlrpcmodules/system/system.api.phpRegister XML-RPC callbacks.
module_hookincludes/module.incDetermine whether a module implements a hook.
module_implementsincludes/module.incDetermine which modules are implementing a hook.
module_invokeincludes/module.incInvoke a hook in a particular module.
module_invoke_allincludes/module.incInvoke a hook in all enabled modules that implement it.
_module_implements_maintenanceincludes/module.incThis is the maintenance version of module_implements for internal use only.

 楼主| 发表于 11-29-2011 07:53 | 显示全部楼层
补充:




钩子可以认为是Drupal的内部事件。他们也被称为回调,但是他们是通过函数命名约定构建的,而不是通过注册监听器,他们不是真正的回调。钩子允许模块“注入”到Drupal的执行进程中。

假设一个用户登录到你的Drupal网站。当用户登录时,Drupal的会触发hook_user_login()钩子。这意味着任何按照“模块名称+钩子名称”约定命名的函数将被调用。例如:评论(comment)模块的comment_user_login ,本地化(locale )模块的locale_user_login(),节点(node)模块的node_user_login(),以及其他任何类似名称的函数都将被调用。如果你要编写一个定制的模块,名为spammy.module和包含一个函数叫做spammy_user_login(),它发送了一封邮件给用户,将你的函数也会被调用。那么,倒霉的用户每次登录都将收到不请自来的电子邮件。

最常见的方式是,在模块中实现这些钩子以注入到Drupal的核心中。

|2011-2026-版权声明|平台(网站)公约|DOOOOR 设计网 ( 吉ICP备2022003869号 )

GMT+8, 5-1-2025 06:44 , Processed in 0.868328 second(s), 253 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表