You are here

function data_node_active_form in Data 6

Form callback for setting the active node.

1 string reference to 'data_node_active_form'
data_node_block in data_node/data_node.module
Implementation of hook_block().

File

data_node/data_node.module, line 111
Hooks and API functions for Data Node module.

Code

function data_node_active_form(&$form_state, $table) {
  $form = array(
    '#attributes' => array(
      'class' => 'data-node-active-form',
    ),
    '#table' => $table,
    '#theme' => 'data_node_active_form',
    // These three are here to keep JS from doing reconstructive URL surgery.
    'ajax_url' => array(
      '#type' => 'hidden',
      '#value' => url('data-node/active/' . $table
        ->get('name')),
      '#attributes' => array(
        'class' => 'data-node-ajax-url',
      ),
    ),
    'add_url' => array(
      '#type' => 'hidden',
      '#value' => url('data-node/add/' . $table
        ->get('name')),
      '#attributes' => array(
        'class' => 'data-node-add-url',
      ),
    ),
    'remove_url' => array(
      '#type' => 'hidden',
      '#value' => url('data-node/remove/' . $table
        ->get('name')),
      '#attributes' => array(
        'class' => 'data-node-remove-url',
      ),
    ),
  );
  $nodes = array(
    0 => '--' . t('Select') . '--',
  );
  $nodes += data_node_get_nodes($table);

  // Grab the node type name and provide a creation option
  $meta = $table
    ->get('meta');
  $names = node_get_types('names');
  $type_name = check_plain($names[$meta['data_node']['content_type']]);
  if (node_access('create', $meta['data_node']['content_type'])) {
    $nodes['new'] = '< ' . t('New !type', array(
      '!type' => $type_name,
    )) . ' >';
  }
  $form['nid'] = array(
    '#type' => 'select',
    '#title' => t('Active !type', array(
      '!type' => $type_name,
    )),
    '#options' => $nodes,
    '#default_value' => data_node_get_active($table
      ->get('name')),
  );
  if (node_access('create', $meta['data_node']['content_type'])) {
    $form['new'] = array(
      '#tree' => FALSE,
    );
    $form['new']['type'] = array(
      '#type' => 'value',
      '#value' => $meta['data_node']['content_type'],
    );
    $form['new']['title'] = array(
      '#type' => 'textfield',
      '#size' => 20,
    );
    $form['new']['create'] = array(
      '#type' => 'submit',
      '#value' => t('Create'),
      '#submit' => array(
        'data_node_active_form_create_submit',
      ),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Set'),
    '#submit' => array(
      'data_node_active_form_submit',
    ),
  );
  return $form;
}