|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Minified node creation form. |
|
5
|
|
|
*/ |
|
6
|
|
|
class commons_bw_handler_node_partial_form extends views_handler_area { |
|
7
|
|
|
|
|
8
|
|
|
function option_definition() { |
|
|
|
|
|
|
9
|
|
|
$options = parent::option_definition(); |
|
10
|
|
|
$options['bundle'] = array('default' => NULL); |
|
11
|
|
|
return $options; |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
function options_form(&$form, &$form_state) { |
|
|
|
|
|
|
15
|
|
|
$bundles = og_get_all_group_content_bundle(); |
|
16
|
|
|
|
|
17
|
|
|
$form['bundle'] = array( |
|
18
|
|
|
'#type' => 'select', |
|
19
|
|
|
'#title' => t('Node type'), |
|
20
|
|
|
'#options' => !empty($bundles['node']) ? $bundles['node'] : array(), |
|
21
|
|
|
'#default_value' => $this->options['bundle'], |
|
22
|
|
|
'#required' => TRUE, |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
function render($empty = FALSE) { |
|
|
|
|
|
|
27
|
|
|
$cache = &drupal_static(__METHOD__, array()); |
|
28
|
|
|
|
|
29
|
|
|
$bundle = $this->options['bundle']; |
|
30
|
|
|
$group_id = !empty($this->view->args[0]) ? $this->view->args[0] : NULL; |
|
31
|
|
|
|
|
32
|
|
|
// Verify content creation access. |
|
33
|
|
|
$permission = "create $bundle content"; |
|
34
|
|
|
if ($group_id && !og_user_access('node', $group_id, $permission)) { |
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
elseif (!user_access($permission)) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Avoid rendering a form for the same bundle twice; Instead, mark that it |
|
42
|
|
|
// should be moved to this position from previously rendered form. |
|
43
|
|
|
// See partial_node_form.js. |
|
44
|
|
|
if (!empty($cache[$bundle])) { |
|
45
|
|
|
return '<div class="partial-node-form-placeholder" data-bundle="' . $bundle . '"></div>'; |
|
46
|
|
|
} |
|
47
|
|
|
$cache[$bundle] = TRUE; |
|
48
|
|
|
|
|
49
|
|
|
$form = drupal_get_form("commons_bw_partial_node_form__$bundle", $bundle, $group_id); |
|
50
|
|
|
return render($form); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.