You are here

function apachesolr_multilingual_textfile_form in Apache Solr Multilingual 6

Same name and namespace in other branches
  1. 6.2 apachesolr_multilingual_textfile/apachesolr_multilingual_textfile.module \apachesolr_multilingual_textfile_form()

File

apachesolr_multilingual_textfile/apachesolr_multilingual_textfile.module, line 25

Code

function apachesolr_multilingual_textfile_form(&$node, $form_state) {
  $node->status = 0;

  // do not published
  $apachesolr_multilingual_filetypes = variable_get('apachesolr_multilingual_filetypes', array(
    'stopwords.txt' => 'stopwords.txt',
    'synonyms.txt' => 'synonyms.txt',
    'protwords.txt' => 'protwords.txt',
    'compoundwords.txt' => 'compoundwords.txt',
  ));

  // load / set the filenames
  $schema_source_path = dirname(__FILE__) . '/../resources/';

  // path to resources
  if ($node->filename && $node->language) {
    $node_auto_created = TRUE;
  }
  else {
    $node_auto_created = FALSE;
  }
  $form['title'] = array(
    '#type' => 'value',
    '#value' => $node->title,
  );
  if (!$node_auto_created) {
    $form['filename'] = array(
      '#type' => 'select',
      '#title' => t('select a text type'),
      '#required' => TRUE,
      '#options' => $apachesolr_multilingual_filetypes,
      '#default_value' => $node->filename,
    );
  }
  else {
    $form['filename'] = array(
      '#type' => 'value',
      '#value' => $node->filename,
    );
  }
  if ($node_auto_created) {
    if (file_exists($schema_source_path . $node->filename)) {
      $form[$node->filename] = array(
        '#type' => 'fieldset',
        '#title' => t('original apachesolr %filename example file', array(
          '%filename' => $node->filename,
        )),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form[$node->filename][$node->filename . '_info'] = array(
        '#type' => 'item',
        '#title' => '',
        '#value' => nl2br(file_get_contents($schema_source_path . $node->filename)),
      );
    }
  }
  else {
    foreach ($apachesolr_multilingual_filetypes as $file) {
      if (file_exists($schema_source_path . $file)) {
        $form[$file] = array(
          '#type' => 'fieldset',
          '#title' => t('original apachesolr %file example file', array(
            '%file' => $file,
          )),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
        $form[$file][$file . '_info'] = array(
          '#type' => 'item',
          '#title' => '',
          '#value' => nl2br(file_get_contents($schema_source_path . $file)),
        );
      }
    }
  }
  if ($node->title) {
    $title = $node->title;
  }
  else {
    $title = 'Apache solr textfile';
  }
  $form['body'] = array(
    '#type' => 'textarea',
    '#title' => $title,
    '#rows' => 20,
    '#required' => FALSE,
    '#default_value' => $node->body,
    '#element_validate' => array(
      'apachesolr_multilingual_textfile_form_validate_new_config',
    ),
  );
  return $form;
}