Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
eb6b848d
Commit
eb6b848d
authored
Mar 26, 2007
by
Dries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Patch
#110888
by Eaton: unify hook _alter()
parent
2e0bb6e9
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
56 additions
and
47 deletions
+56
-47
includes/common.inc
includes/common.inc
+39
-5
includes/form.inc
includes/form.inc
+1
-4
includes/menu.inc
includes/menu.inc
+1
-4
modules/color/color.module
modules/color/color.module
+1
-1
modules/comment/comment.module
modules/comment/comment.module
+3
-6
modules/forum/forum.module
modules/forum/forum.module
+2
-2
modules/menu/menu.module
modules/menu/menu.module
+1
-1
modules/node/node.module
modules/node/node.module
+2
-6
modules/path/path.module
modules/path/path.module
+1
-1
modules/taxonomy/taxonomy.module
modules/taxonomy/taxonomy.module
+2
-5
modules/upload/upload.module
modules/upload/upload.module
+2
-5
modules/user/user.module
modules/user/user.module
+1
-7
No files found.
includes/common.inc
View file @
eb6b848d
...
...
@@ -1993,11 +1993,12 @@ function drupal_mail($mailkey, $to, $subject, $body, $from = NULL, $headers = ar
$defaults
[
'From'
]
=
$defaults
[
'Reply-To'
]
=
$defaults
[
'Return-Path'
]
=
$defaults
[
'Errors-To'
]
=
$from
;
}
$headers
=
array_merge
(
$defaults
,
$headers
);
// Custom hook traversal to allow pass by reference
foreach
(
module_implements
(
'mail_alter'
)
AS
$module
)
{
$function
=
$module
.
'_mail_alter'
;
$function
(
$mailkey
,
$to
,
$subject
,
$body
,
$from
,
$headers
);
}
// Bundle up the variables into a structured array for altering.
$message
=
array
(
'#mail_id'
=>
$mailkey
,
'#to'
=>
$to
,
'#subject'
=>
$subject
,
'#body'
=>
$body
,
'#from'
=>
$from
,
'#headers'
=>
$headers
);
drupal_alter
(
'mail'
,
$message
);
list
(
$mailkey
,
$to
,
$subject
,
$body
,
$from
,
$headers
)
=
$message
;
// Allow for custom mail backend
if
(
variable_get
(
'smtp_library'
,
''
)
&&
file_exists
(
variable_get
(
'smtp_library'
,
''
)))
{
include_once
'./'
.
variable_get
(
'smtp_library'
,
''
);
...
...
@@ -2163,6 +2164,39 @@ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1)
return
$files
;
}
/**
* This dispatch function hands off structured Drupal arrays to
* type-specific *_alter implementations. It ensures a consistent
* interface for all altering operations.
*
* @param $type
* The data type of the structured array. 'form', 'links',
* 'node_content', and so on are several examples.
* @param $data
* The structured array to be altered.
* @param ...
* Any additional params will be passed on to the called
* hook_$type_alter functions.
*/
function
drupal_alter
(
$type
,
&
$data
=
array
())
{
// Hang onto a reference to the data array so that it isn't blown away later.
$args
=
array
(
&
$data
);
// Now, use func_get_args() to pull in any aditional paramaters passed into
// the drupal_alter() call.
$aditional_args
=
func_get_args
();
array_shift
(
$aditional_args
);
array_shift
(
$aditional_args
);
$args
=
array_merge
(
$args
,
$aditional_args
);
foreach
(
module_implements
(
$type
.
'_alter'
)
as
$module
)
{
$function
=
$module
.
'_'
.
$type
.
'_alter'
;
call_user_func_array
(
$function
,
$args
);
}
}
/**
* Renders HTML given a structured array tree. Recursively iterates over each
* of the array elements, generating HTML code. This function is usually
...
...
includes/form.inc
View file @
eb6b848d
...
...
@@ -351,10 +351,7 @@ function drupal_prepare_form($form_id, &$form) {
}
}
foreach
(
module_implements
(
'form_alter'
)
as
$module
)
{
$function
=
$module
.
'_form_alter'
;
$function
(
$form_id
,
$form
);
}
drupal_alter
(
'form'
,
$form
,
$form_id
);
$form
=
form_builder
(
$form_id
,
$form
);
}
...
...
includes/menu.inc
View file @
eb6b848d
...
...
@@ -552,10 +552,7 @@ function menu_rebuild() {
// TODO: split menu and menu links storage.
db_query
(
'DELETE FROM {menu}'
);
$menu
=
module_invoke_all
(
'menu'
);
foreach
(
module_implements
(
'menu_alter'
)
as
$module
)
{
$function
=
$module
.
'_menu_alter'
;
$function
(
$menu
);
}
drupal_alter
(
'menu'
,
$menu
);
$mid
=
1
;
// First pass: separate callbacks from pathes, making pathes ready for
// matching. Calculate fitness, and fill some default values.
...
...
modules/color/color.module
View file @
eb6b848d
...
...
@@ -4,7 +4,7 @@
/**
* Implementation of hook_form_alter().
*/
function
color_form_alter
(
$form_id
,
&
$form
)
{
function
color_form_alter
(
&
$form
,
$form_id
)
{
// Insert the color changer into the theme settings page.
// TODO: Last condition in the following if disables color changer when private files are used this should be solved in a different way. See issue #92059.
if
(
$form_id
==
'system_theme_settings'
&&
color_get_info
(
arg
(
4
))
&&
function_exists
(
'gd_info'
)
&&
variable_get
(
'file_downloads'
,
FILE_DOWNLOADS_PUBLIC
)
==
FILE_DOWNLOADS_PUBLIC
)
{
...
...
modules/comment/comment.module
View file @
eb6b848d
...
...
@@ -374,7 +374,7 @@ function comment_link($type, $node = NULL, $teaser = FALSE) {
return
$links
;
}
function
comment_form_alter
(
$form
_id
,
&
$form
)
{
function
comment_form_alter
(
$form
,
$form
_id
)
{
if
(
$form_id
==
'node_type_form'
&&
isset
(
$form
[
'identity'
][
'type'
]))
{
$form
[
'workflow'
][
'comment'
]
=
array
(
'#type'
=>
'radios'
,
...
...
@@ -403,6 +403,7 @@ function comment_form_alter($form_id, &$form) {
);
}
}
return
$form
;
}
/**
...
...
@@ -963,11 +964,7 @@ function comment_render($node, $cid = 0) {
if
(
$comment
=
db_fetch_object
(
$result
))
{
$comment
->
name
=
$comment
->
uid
?
$comment
->
registered_name
:
$comment
->
name
;
$links
=
module_invoke_all
(
'link'
,
'comment'
,
$comment
,
1
);
foreach
(
module_implements
(
'link_alter'
)
as
$module
)
{
$function
=
$module
.
'_link_alter'
;
$function
(
$node
,
$links
);
}
drupal_alter
(
'link'
,
$links
,
$node
);
$output
.
=
theme
(
'comment_view'
,
$comment
,
$links
);
}
...
...
modules/forum/forum.module
View file @
eb6b848d
...
...
@@ -207,7 +207,7 @@ function forum_admin_settings() {
/**
* Implementation of hook_form_alter().
*/
function
forum_form_alter
(
$form_id
,
&
$form
)
{
function
forum_form_alter
(
&
$form
,
$form_id
)
{
// hide critical options from forum vocabulary
if
(
$form_id
==
'taxonomy_form_vocabulary'
)
{
if
(
$form
[
'vid'
][
'#value'
]
==
_forum_get_vid
())
{
...
...
@@ -657,7 +657,7 @@ function _forum_parent_select($tid, $title, $child_type) {
return
array
(
'#type'
=>
'select'
,
'#title'
=>
$title
,
'#default_value'
=>
$parent
,
'#options'
=>
$options
,
'#description'
=>
$description
,
'#required'
=>
TRUE
);
}
function
forum_link_alter
(
&
$
node
,
&
$links
)
{
function
forum_link_alter
(
&
$
links
,
$node
)
{
foreach
(
$links
as
$module
=>
$link
)
{
if
(
strstr
(
$module
,
'taxonomy_term'
))
{
// Link back to the forum and not the taxonomy term page. We'll only
...
...
modules/menu/menu.module
View file @
eb6b848d
...
...
@@ -172,7 +172,7 @@ function menu_perm() {
* Implementation of hook_form_alter().
* Add menu item fields to the node form.
*/
function
menu_form_alter
(
$form_id
,
&
$form
)
{
function
menu_form_alter
(
&
$form
,
$form_id
)
{
if
(
isset
(
$form
[
'type'
])
&&
$form
[
'type'
][
'#value'
]
.
'_node_form'
==
$form_id
)
{
$item
=
array
();
if
(
$form
[
'nid'
][
'#value'
]
>
0
)
{
...
...
modules/node/node.module
View file @
eb6b848d
...
...
@@ -673,11 +673,7 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
if
(
$links
)
{
$node
->
links
=
module_invoke_all
(
'link'
,
'node'
,
$node
,
!
$page
);
foreach
(
module_implements
(
'link_alter'
)
AS
$module
)
{
$function
=
$module
.
'_link_alter'
;
$function
(
$node
,
$node
->
links
);
}
drupal_alter
(
'link'
,
$node
->
links
,
$node
);
}
// Set the proper node part, then unset unused $node part so that a bad
...
...
@@ -2456,7 +2452,7 @@ function node_update_index() {
/**
* Implementation of hook_form_alter().
*/
function
node_form_alter
(
$form_id
,
&
$form
)
{
function
node_form_alter
(
&
$form
,
$form_id
)
{
// Advanced node search form
if
(
$form_id
==
'search_form'
&&
$form
[
'module'
][
'#value'
]
==
'node'
&&
user_access
(
'use advanced search'
))
{
// Keyword boxes:
...
...
modules/path/path.module
View file @
eb6b848d
...
...
@@ -267,7 +267,7 @@ function path_nodeapi(&$node, $op, $arg) {
/**
* Implementation of hook_form_alter().
*/
function
path_form_alter
(
$form_id
,
&
$form
)
{
function
path_form_alter
(
&
$form
,
$form_id
)
{
if
(
isset
(
$form
[
'type'
])
&&
$form
[
'type'
][
'#value'
]
.
'_node_form'
==
$form_id
)
{
$path
=
isset
(
$form
[
'#node'
]
->
path
)
?
$form
[
'#node'
]
->
path
:
NULL
;
$form
[
'path'
]
=
array
(
...
...
modules/taxonomy/taxonomy.module
View file @
eb6b848d
...
...
@@ -39,10 +39,7 @@ function taxonomy_link($type, $node = NULL) {
}
// We call this hook again because some modules and themes call taxonomy_link('taxonomy terms') directly
foreach
(
module_implements
(
'link_alter'
)
as
$module
)
{
$function
=
$module
.
'_link_alter'
;
$function
(
$node
,
$links
);
}
drupal_alter
(
'link'
,
$links
,
$node
);
return
$links
;
}
...
...
@@ -654,7 +651,7 @@ function taxonomy_get_vocabularies($type = NULL) {
* Implementation of hook_form_alter().
* Generate a form for selecting terms to associate with a node.
*/
function
taxonomy_form_alter
(
$form_id
,
&
$form
)
{
function
taxonomy_form_alter
(
&
$form
,
$form_id
)
{
if
(
isset
(
$form
[
'type'
])
&&
$form
[
'type'
][
'#value'
]
.
'_node_form'
==
$form_id
)
{
$node
=
$form
[
'#node'
];
...
...
modules/upload/upload.module
View file @
eb6b848d
...
...
@@ -333,7 +333,7 @@ function _upload_prepare(&$node) {
}
}
function
upload_form_alter
(
$form_id
,
&
$form
)
{
function
upload_form_alter
(
&
$form
,
$form_id
)
{
if
(
$form_id
==
'node_type_form'
&&
isset
(
$form
[
'identity'
][
'type'
]))
{
$form
[
'workflow'
][
'upload'
]
=
array
(
'#type'
=>
'radios'
,
...
...
@@ -883,10 +883,7 @@ function upload_js() {
_upload_validate
(
$node
);
$form
=
_upload_form
(
$node
);
foreach
(
module_implements
(
'form_alter'
)
as
$module
)
{
$function
=
$module
.
'_form_alter'
;
$function
(
'upload_js'
,
$form
);
}
drupal_alter
(
'form'
,
$form
,
'upload_js'
);
$form
=
form_builder
(
'upload_js'
,
$form
);
$output
=
theme
(
'status_messages'
)
.
drupal_render
(
$form
);
// We send the updated file attachments form.
...
...
modules/user/user.module
View file @
eb6b848d
...
...
@@ -1605,13 +1605,7 @@ function user_view($account) {
}
}
// Let modules change the returned fields - useful for personal privacy
// controls. Since modules communicate changes by reference, we cannot use
// module_invoke_all().
foreach
(
module_implements
(
'profile_alter'
)
as
$module
)
{
$function
=
$module
.
'_profile_alter'
;
$function
(
$account
,
$fields
);
}
drupal_alter
(
'profile'
,
$fields
,
$account
);
drupal_set_title
(
check_plain
(
$account
->
name
));
return
theme
(
'user_profile'
,
$account
,
$fields
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment