You are here

public function TextExtractorFormSettings::buildTextExtractorTestResultForm 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::buildTextExtractorTestResultForm()

Subform to test the configuration of an extraction plugin method.

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

1 call to TextExtractorFormSettings::buildTextExtractorTestResultForm()
TextExtractorFormSettings::buildForm in src/Form/TextExtractorFormSettings.php
Form constructor.

File

src/Form/TextExtractorFormSettings.php, line 270

Class

TextExtractorFormSettings
Configuration form.

Namespace

Drupal\search_api_attachments\Form

Code

public function buildTextExtractorTestResultForm(array &$form, FormStateInterface $form_state) {
  if (isset($form['text_extractor_config'])) {
    $extractor_plugin_id = $form_state
      ->getValue('extraction_method');
    $form['text_extractor_config']['test_result']['#type'] = 'details';
    $form['text_extractor_config']['test_result']['#title'] = $this
      ->t('Test extractor %plugin', [
      '%plugin' => $this
        ->getExtractionPluginInformations()['labels'][$extractor_plugin_id],
    ]);
    $form['text_extractor_config']['test_result']['#open'] = TRUE;
    $storage = $form_state
      ->getStorage();
    if (empty($storage)) {

      // Put the initial thing into the storage.
      $storage = [
        'extracted_test_text' => [
          'message' => $this
            ->t("Extraction doesn't seem to work."),
          'type' => 'error',
        ],
      ];
      $form_state
        ->setStorage($storage);
    }
    $form['text_extractor_config']['test_result']['test_file_path_result'] = [
      '#theme' => 'saa',
      '#message' => $storage['extracted_test_text']['message'],
      '#type' => $storage['extracted_test_text']['type'],
      '#attached' => [
        'library' => [
          'search_api_attachments/extractor_status',
        ],
      ],
    ];
  }
}