You are here

function contentanalysis_form_alter in Content Analysis 7

Same name and namespace in other branches
  1. 8 contentanalysis.module \contentanalysis_form_alter()
  2. 6 contentanalysis.module \contentanalysis_form_alter()

Implements hook_form_alter().

Add Content Optimizer field set to node edit forms. Add Content Analysis enabled field to content type admin form

File

./contentanalysis.module, line 1540

Code

function contentanalysis_form_alter(&$form, &$form_state, $form_id) {

  // Only use on Node edit forms.
  if (strpos($form_id, '_node_form') == FALSE) {
    return;
  }
  if (isset($form['type']['#value']) && $form['type']['#value'] . '_node_form' == $form_id && variable_get('contentanalysis_type_' . $form['#node']->type . '_enable', 1)) {
    if (!user_access('perform content analysis')) {
      return '';
    }
    $node = $form['#node'];

    //$form['contentanalysis'] = contentanalysis_node_form($form_state, array(), $node, $settings);
    $form['contentanalysis'] = array(
      '#type' => 'fieldset',
      '#title' => t('Content analysis'),
      '#collapsible' => TRUE,
      '#collapsed' => variable_get('contentanalysis_node_edit_form_collapsed', 0),
      //'#attributes' => array('class' => 'contentanalysis'),
      '#group' => 'additional_settings',
      '#weight' => -99,
    );
    $form['contentanalysis'] = array_merge($form['contentanalysis'], contentanalysis_analysis_form($form_state, array(), $node, 'node-edit'));
    $form['#submit'][] = 'contentanalysis_node_submit';
  }
  if ($form_id == 'node_type_form') {
    $form['contentanalysis'] = array(
      '#type' => 'fieldset',
      '#title' => t('Content Analysis Settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#tree' => TRUE,
      '#group' => 'additional_settings',
    );
    $form['contentanalysis']['enable'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Content Analysis'),
      '#description' => t('If checked, the <em>Content Analysis</em> fieldset will appear on the node edit form for those who have permission to perform content analysis.'),
      '#options' => array(
        'enable' => t('Enable'),
      ),
      '#default_value' => variable_get('contentanalysis_type_' . $form['#node_type']->type . '_enable', 1) ? array(
        'enable',
      ) : array(),
    );

    /* TODO get analyzer settings working at node_type level
           require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'contentanalysis') . "/contentanalysis.admin.inc";
           $form['contentanalysis'] = array_merge($form['contentanalysis'], contentanalysis_admin_analyzer_settings_element($mode = 'node_type'));
       */
    $form['#submit'][] = 'contentanalysis_node_type_form_submit';
  }
}