You are here

public function TextExtractorFormSettings::buildForm in Search API attachments 8

Same name and namespace in other branches
  1. 9.0.x src/Form/TextExtractorFormSettings.php \Drupal\search_api_attachments\Form\TextExtractorFormSettings::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/TextExtractorFormSettings.php, line 74

Class

TextExtractorFormSettings
Configuration form.

Namespace

Drupal\search_api_attachments\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $config = $this
    ->config(static::CONFIGNAME);
  $form['extraction_method'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Extraction method'),
    '#description' => $this
      ->t('Select the extraction method you want to use.'),
    '#empty_value' => '',
    '#options' => $this
      ->getExtractionPluginInformations()['labels'],
    '#default_value' => $config
      ->get('extraction_method'),
    '#required' => TRUE,
    '#ajax' => [
      'callback' => [
        get_class($this),
        'buildAjaxTextExtractorConfigForm',
      ],
      'wrapper' => 'search-api-attachments-extractor-config-form',
      'method' => 'replace',
      'effect' => 'fade',
    ],
  ];
  $this
    ->buildTextExtractorConfigForm($form, $form_state);
  $trigger = $form_state
    ->getTriggeringElement();
  if (!empty($trigger['#is_button'])) {
    $this
      ->buildTextExtractorTestResultForm($form, $form_state);
  }
  $url = Url::fromRoute('system.performance_settings')
    ->toString();
  $form['preserve_cache'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Preserve cached extractions across cache clears.'),
    '#default_value' => $config
      ->get('preserve_cache'),
    '#description' => $this
      ->t('When checked, <a href=":url">clearing the sitewide cache</a> will not clear the cache of extracted files.', [
      ':url' => $url,
    ]),
  ];
  $form['read_text_files_directly'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Get contents of text attachments directly using file_get_contents.'),
    '#default_value' => $config
      ->get('read_text_files_directly'),
    '#description' => $this
      ->t('When checked, get contents of text files directly using file_get_contents, rather than sending the whole file to Solr. This may cause problems when reading non-UTF-8 text files.'),
  ];
  $form['actions']['submit']['#value'] = $this
    ->t('Submit and test extraction');
  return $form;
}