Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
2ca7eb71
Commit
2ca7eb71
authored
Apr 28, 2004
by
Dries
Browse files
- Patch
#6612
by JonBob: extended the node API with new hooks.
parent
31172585
Changes
2
Hide whitespace changes
Inline
Side-by-side
modules/node.module
View file @
2ca7eb71
...
...
@@ -312,12 +312,12 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
}
}
function
node_invoke_nodeapi
(
&
$node
,
$op
,
$a
rg
=
0
)
{
function
node_invoke_nodeapi
(
&
$node
,
$op
,
$a
3
=
NULL
,
$a4
=
NULL
)
{
$return
=
array
();
foreach
(
module_list
()
as
$name
)
{
$function
=
$name
.
'_nodeapi'
;
if
(
function_exists
(
$function
))
{
$result
=
$function
(
$node
,
$op
,
$a
rg
);
$result
=
$function
(
$node
,
$op
,
$a
3
,
$a4
);
if
(
isset
(
$result
))
{
$return
=
array_merge
(
$return
,
$result
);
}
...
...
@@ -362,6 +362,12 @@ function node_load($conditions, $revision = -1) {
}
}
if
(
$extra
=
node_invoke_nodeapi
(
$node
,
'load'
))
{
foreach
(
$extra
as
$key
=>
$value
)
{
$node
->
$key
=
$value
;
}
}
/*
** Return the desired revision
*/
...
...
@@ -477,6 +483,9 @@ function node_view($node, $main = 0, $page = 0) {
$node
->
body
=
str_replace
(
'<!--break-->'
,
''
,
$node
->
body
);
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi
(
$node
,
'view'
,
$main
,
$page
);
/*
** The 'view' hook can be implemented to overwrite the default function
** to display nodes.
...
...
@@ -780,24 +789,6 @@ function node_admin_settings($edit) {
$output
.
=
theme
(
'table'
,
$header
,
$rows
);
/* This is an idea for the future.
foreach (node_list() as $type) {
$node->type = $type;
// Create theme('table', ) data:
$header = array_keys(node_invoke_nodeapi($node, 'settings'));
$cols = array();
foreach (node_invoke_nodeapi($node, 'settings') as $setting) {
$cols[] = array('data' => $setting, 'align' => 'center', 'width' => 75);
}
$output .= '<h2>'. node_invoke($node, 'node_name') .'</h2>';
$output .= theme('table', $header, array($cols));
$output .= '<br /><br />';
}
}
*/
$output
.
=
form_submit
(
t
(
'Save configuration'
));
$output
.
=
form_submit
(
t
(
'Reset to defaults'
));
...
...
@@ -1188,7 +1179,7 @@ function node_form($edit, $error = NULL) {
$output
.
=
form_group
(
t
(
'Options'
),
$options
);
$output
.
=
"</div>
\n
"
;
$extras
.
=
implode
(
"</div><div class=
\"
extra
\"
>"
,
node_invoke_nodeapi
(
$edit
,
'form admin'
));
$extras
.
=
implode
(
"</div><div class=
\"
extra
\"
>"
,
node_invoke_nodeapi
(
$edit
,
'form admin'
,
$error
));
$output
.
=
$extras
?
"<div class=
\"
extra
\"
>
$extras
</div></div>"
:
"</div>"
;
}
...
...
@@ -1247,6 +1238,16 @@ function node_form($edit, $error = NULL) {
$output
.
=
"</div></div>"
;
$extra
=
node_invoke_nodeapi
(
$edit
,
"form param"
);
foreach
(
$extra
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
$param
[
$key
]
=
array_merge
(
$param
[
$key
],
$value
);
}
else
{
$param
[
$key
]
=
$value
;
}
}
return
form
(
$output
,
(
$param
[
'method'
]
?
$param
[
'method'
]
:
'post'
),
$param
[
'action'
],
array_merge
(
$param
[
'options'
],
array
(
'id'
=>
'node-form'
)));
}
...
...
modules/node/node.module
View file @
2ca7eb71
...
...
@@ -312,12 +312,12 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
}
}
function
node_invoke_nodeapi
(
&
$node
,
$op
,
$a
rg
=
0
)
{
function
node_invoke_nodeapi
(
&
$node
,
$op
,
$a
3
=
NULL
,
$a4
=
NULL
)
{
$return
=
array
();
foreach
(
module_list
()
as
$name
)
{
$function
=
$name
.
'_nodeapi'
;
if
(
function_exists
(
$function
))
{
$result
=
$function
(
$node
,
$op
,
$a
rg
);
$result
=
$function
(
$node
,
$op
,
$a
3
,
$a4
);
if
(
isset
(
$result
))
{
$return
=
array_merge
(
$return
,
$result
);
}
...
...
@@ -362,6 +362,12 @@ function node_load($conditions, $revision = -1) {
}
}
if
(
$extra
=
node_invoke_nodeapi
(
$node
,
'load'
))
{
foreach
(
$extra
as
$key
=>
$value
)
{
$node
->
$key
=
$value
;
}
}
/*
** Return the desired revision
*/
...
...
@@ -477,6 +483,9 @@ function node_view($node, $main = 0, $page = 0) {
$node
->
body
=
str_replace
(
'<!--break-->'
,
''
,
$node
->
body
);
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi
(
$node
,
'view'
,
$main
,
$page
);
/*
** The 'view' hook can be implemented to overwrite the default function
** to display nodes.
...
...
@@ -780,24 +789,6 @@ function node_admin_settings($edit) {
$output
.
=
theme
(
'table'
,
$header
,
$rows
);
/* This is an idea for the future.
foreach (node_list() as $type) {
$node->type = $type;
// Create theme('table', ) data:
$header = array_keys(node_invoke_nodeapi($node, 'settings'));
$cols = array();
foreach (node_invoke_nodeapi($node, 'settings') as $setting) {
$cols[] = array('data' => $setting, 'align' => 'center', 'width' => 75);
}
$output .= '<h2>'. node_invoke($node, 'node_name') .'</h2>';
$output .= theme('table', $header, array($cols));
$output .= '<br /><br />';
}
}
*/
$output
.
=
form_submit
(
t
(
'Save configuration'
));
$output
.
=
form_submit
(
t
(
'Reset to defaults'
));
...
...
@@ -1188,7 +1179,7 @@ function node_form($edit, $error = NULL) {
$output
.
=
form_group
(
t
(
'Options'
),
$options
);
$output
.
=
"</div>
\n
"
;
$extras
.
=
implode
(
"</div><div class=
\"
extra
\"
>"
,
node_invoke_nodeapi
(
$edit
,
'form admin'
));
$extras
.
=
implode
(
"</div><div class=
\"
extra
\"
>"
,
node_invoke_nodeapi
(
$edit
,
'form admin'
,
$error
));
$output
.
=
$extras
?
"<div class=
\"
extra
\"
>
$extras
</div></div>"
:
"</div>"
;
}
...
...
@@ -1247,6 +1238,16 @@ function node_form($edit, $error = NULL) {
$output
.
=
"</div></div>"
;
$extra
=
node_invoke_nodeapi
(
$edit
,
"form param"
);
foreach
(
$extra
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
$param
[
$key
]
=
array_merge
(
$param
[
$key
],
$value
);
}
else
{
$param
[
$key
]
=
$value
;
}
}
return
form
(
$output
,
(
$param
[
'method'
]
?
$param
[
'method'
]
:
'post'
),
$param
[
'action'
],
array_merge
(
$param
[
'options'
],
array
(
'id'
=>
'node-form'
)));
}
...
...
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