commons_bw_handler_node_partial_form   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A option_definition() 0 5 1
A options_form() 0 11 2
B render() 0 26 6
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
9
    $options = parent::option_definition();
10
    $options['bundle'] = array('default' => NULL);
11
    return $options;
12
  }
13
14
  function options_form(&$form, &$form_state) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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