You are here

function radioactivity_node_form_alter in Radioactivity 6

Implements hook_form_alter().

File

plugins/radioactivity_node.module, line 179
Node radioactivity

Code

function radioactivity_node_form_alter(&$form, &$form_state, $form_id) {
  $node = isset($form['#node']) ? $form['#node'] : FALSE;
  if (user_access('administer node energy') && $node && $form_id == $node->type . '_node_form') {
    $form['radioactivity_node'] = array(
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#title' => t('Radioactivity'),
      '#description' => isset($node->nid) ? t('You can modify this nodes energy by changing the values below.') : t('Once the node has been created you will be able to edit the energy for each decay profile here.'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    // We only allow editing of energy on existing nodes.
    if (isset($node->nid)) {
      $decay_profiles = radioactivity_get_decay_profiles();
      foreach ($decay_profiles as $key => $profile) {
        $form['radioactivity_node'][$key]['energy'] = array(
          '#type' => 'textfield',
          '#title' => t('Energy for @profile decay profile', array(
            '@profile' => $profile['label'],
          )),
          '#default_value' => $node->radioactivity['energy'][$key],
        );
      }
    }
  }
}