You are here

function oa_comment_oa_settings_form in OA Comment 7.2

Implements hook_oa_settings_form().

File

./oa_comment.module, line 144

Code

function oa_comment_oa_settings_form(&$form_state) {
  $forms = array();
  $form = array();
  $form['oa_comment_strip_sig'] = array(
    '#type' => 'textfield',
    '#title' => t('Strip signatures from comments'),
    '#description' => t('After the first line matching this string, any further text will be hidden. A typical value is <strong>"-- "</strong> that is two dashes followed by a blank in an otherwise empty line. Leave blank to include signature text in nodes.'),
    '#default_value' => variable_get('oa_comment_strip_sig', '-- '),
  );
  $form_state['comments_enabled'] = oa_comment_content_types_enabled();
  foreach (node_type_get_names() as $machine_name => $name) {
    $default = variable_get('comment_' . $machine_name, COMMENT_NODE_OPEN);
    $form[$machine_name] = array(
      '#type' => 'fieldset',
      '#title' => check_plain($name),
    );
    $form[$machine_name]['comment_' . $machine_name] = array(
      '#type' => 'checkbox',
      '#title' => t('Comments'),
      // _HIDDEN is 0 so can be used as false, but may be set to _CLOSED (1).
      '#default_value' => in_array($default, array(
        COMMENT_NODE_OPEN,
        COMMENT_NODE_HIDDEN,
      )) ? $default : COMMENT_NODE_HIDDEN,
      '#return_value' => COMMENT_NODE_OPEN,
    );
    if (module_exists('oa_related')) {
      $enabled_related = oa_related_get_content_types();
      $paragraphs_enabled = variable_get('oa_related_comment_' . $machine_name, in_array($machine_name, $enabled_related));
      $form[$machine_name]['oa_related_comment_' . $machine_name] = array(
        '#type' => 'checkbox',
        '#title' => t('Paragraphs field'),
        '#description' => t('Disabling this will remove the field from the comments for this type and loose any data in those fields.'),
        '#default_value' => $paragraphs_enabled,
        '#states' => array(
          'visible' => array(
            ':input[name="comment_' . $machine_name . '"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      if ($paragraphs_enabled) {
        $form_state['comments_oa_related_enabled'][$machine_name] = $machine_name;
      }
    }
  }
  if (module_exists('oa_related')) {
    $enabled_related = oa_related_get_content_types();

    // Add enabling of oa_related.
    $_bundles = paragraphs_bundle_load();
    foreach ($_bundles as $machine_name => $bundle) {
      $bundles[$machine_name] = $bundle->name;
    }
    $form['comment_paragraph_bundles'] = array(
      '#title' => t('Enabled paragraph bundles'),
      '#description' => t('Select which bundles comments with paragraphs field should have.'),
      '#type' => 'checkboxes',
      '#required' => TRUE,
      '#default_value' => array_filter(variable_get('comment_paragraph_bundles', array_keys($bundles))),
      '#options' => $bundles,
    );
    $form_state['comment_paragraph_bundles'] = $form['comment_paragraph_bundles']['#default_value'];
  }
  $forms[] = array(
    'caption' => t('Comments'),
    'form' => $form,
    'submit' => 'oa_comment_oa_settings_form_submit',
  );
  return $forms;
}