You are here

function activeedit_node_data_form in Javascript Tools 5

Encode data on nodes for reference by Javascript.

1 call to activeedit_node_data_form()
activeedit_nodeapi in activeedit/modules/node.inc
Implementation of hook_nodeapi().

File

activeedit/modules/node.inc, line 23

Code

function activeedit_node_data_form($node) {
  static $fields;
  static $requires;
  if ($fields == NULL) {
    $fields = array(
      'nid',
      'type',
    );

    // Add fields for all registered targets.
    if (user_access('administer nodes')) {
      $bars = activeedit_get_targets('bars');
      foreach (element_children($bars['node']) as $key) {
        foreach ($bars['node'][$key]['#form']['node_form'] as $element) {
          $fields[] = end($element);
        }
      }
    }
  }
  if ($requires == NULL) {
    $requires = array();

    // Add fields for all registered targets.
    $elements = activeedit_get_targets('elements');
    foreach (element_children($elements['node']) as $key) {
      if ($elements['node'][$key]['#require']) {
        foreach ($elements['node'][$key]['#form']['node_form'] as $element) {
          $requires[] = end($element);
        }
      }
    }
  }

  // Forms API is not worth the overhead here. In any case, these forms should not be
  // submitted, so don't want/need Forms API handling.
  $form = '<form id="activeedit_node_data_' . $node->nid . '" class="activeedit-data">';
  foreach ($fields as $field) {
    if ($node->{$field}) {
      $form .= '<input name="' . $field . '" type ="hidden" value="' . $node->{$field} . '" />';
    }
  }

  // Load the available fields for this content type.
  $require_fields = variable_get('activeedit_fields_' . $node->type, array());

  // If this node type has not been registered as a variable, register it.
  // Detect if the node type supports given fields. For example, not all
  // node types have a 'title' field. We want to attach editing to the node
  // title only if the field exists.
  if ($require_fields == array()) {
    $type_form = node_invoke($node, 'form');
    foreach (element_children($elements['node']) as $key) {
      if ($elements['node'][$key]['#require']) {
        foreach ($elements['node'][$key]['#form']['node_form'] as $element) {
          $require_fields[end($element)] = $type_form[implode('][', $element)] ? 1 : 0;
        }
      }
    }
    variable_set('activeedit_fields_' . $node->type, $require_fields);
  }
  foreach ($requires as $require) {
    $form .= '<input name="' . $require . '" type ="hidden" value="' . $require_fields[$require] . '" />';
  }
  $form .= '</form>';
  return $form;
}