You are here

function theme_views_editablefields_handle_field in Editable Fields 5.3

Same name and namespace in other branches
  1. 5 editablefields.module \theme_views_editablefields_handle_field()
  2. 5.2 editablefields.module \theme_views_editablefields_handle_field()

Themeable function to handle displaying a specific field.

File

./editablefields.module, line 234

Code

function theme_views_editablefields_handle_field($fields, $field, $data) {
  $info = $fields[$field['fullname']];
  $node = node_load($data->nid);
  $type = $node->type;
  $canView = TRUE;
  $canEdit = $field['options'] == 'editable' && node_access("update", $node);
  if ($types = variable_get('cfp_types', null)) {
    if ($types[$type]) {
      $disallowed_fields = unserialize(variable_get('cfp_values', null));
      if ($disallowed_fields) {
        $dfield = $field['field'];
        $dfield = substr($dfield, 0, strrpos($dfield, '_'));
        $value = $disallowed_fields[$type][$dfield];
        if ($value) {
          if (!user_access(_cfp_content_to_readable($type, $dfield, "view"))) {
            $canView = FALSE;
          }
          else {
            if (!user_access(_cfp_content_to_readable($type, $dfield, "edit"))) {
              $canEdit = FALSE;
            }
          }
        }
      }
    }
  }
  if ($canEdit) {
    if ($info['content_field']['field_name']) {
      $form = array();
      global $viewfield_stack;
      $tmp = $viewfield_stack;
      $viewfield_stack = array();
      $form = _editablefields_content_form_field($node, $info['content_field']['field_name']);
      $viewfield_stack = $tmp;
      foreach (element_children($form) as $key) {
        $form["editablefield_" . $data->nid . "_" . $key] = $form[$key];
        unset($form[$key]);
      }
      $form = _editablefields_make_form_ids_unique($form, $data->nid);
      $form = form_builder('editableviewfield', $form);
      return $form = "<div class=\"ajaxeditable noonload\" nid=\"" . $data->nid . "\" field=\"" . $info['content_field']['field_name'] . "\">" . drupal_render_form('editableviewfield', $form) . "</div>";
    }
    else {
      if (!empty($info['form_parents'])) {
        $form = array();
        $node_form = node_invoke($node, 'form');
        foreach (explode('][', $info['form_parents']) as $key) {
          $node_form = $node_form[$key];
        }
        if (is_array($node_form)) {
          $form['editablefield_' . $data->nid . '_' . $field['field']] = $node_form;
        }
        $form = _editablefields_make_form_ids_unique($form, $data->nid);
        $form = form_builder('editableviewfield', $form);
        return $form = drupal_render_form('editableviewfield', $form);
      }
    }
  }

  // sometime fields we can't handle might fall through to here too
  if ($canView) {
    $field['options'] = 'default';
    if ($field['handler'] && function_exists($field['handler'])) {
      return $field['handler']($info, $field, $data->{$field}['queryname'], $data);
    }
    if ($info['handler'] && is_string($info['handler']) && function_exists($info['handler'])) {
      return $info['handler']($info, $field, $data->{$field}['queryname'], $data);
    }
    return check_plain($data->{$field}['queryname']);
  }
  else {
    return '';
  }
}