-
Notifications
You must be signed in to change notification settings - Fork 1
/
block_create_node.module
53 lines (42 loc) · 1.18 KB
/
block_create_node.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// $Id$
/**
* @file
* Provides block with node creation forms.
*/
/**
* Implementation of hook_block_info().
*/
function block_create_node_block_info() {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
$types = _node_types_build()->types;
foreach ($types as $type) {
$blocks[$type->type] = array(
'info' => t('Create @type', array('@type' => $type->name)),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
}
return $blocks;
}
/**
* Implementation of hook_block_view().
*/
function block_create_node_block_view($delta) {
include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
global $user;
$types = _node_types_build()->types;
$type = isset($delta) ? str_replace('-', '_', $delta) : NULL;
// If a node type has been specified, validate its existence.
if (isset($types[$type]) && node_access('create', $type)) {
$block['subject'] = t($type);
$node = array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => $type,
'language' => '',
);
$node = (object) $node;
$block['content'] = drupal_get_form($type . '_node_form', $node);
}
return $block;
}