You are here

public function ScannerAdminForm::buildForm in Search and Replace Scanner 8

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/ScannerAdminForm.php, line 119

Class

ScannerAdminForm
Form for configuring the default scanner settings.

Namespace

Drupal\scanner\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('scanner.admin_settings');
  $form['settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Default options'),
  ];
  $form['settings']['scanner_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Default: Case sensitive search mode'),
    '#default_value' => $config
      ->get('scanner_mode'),
  ];
  $form['settings']['scanner_wholeword'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Default: Match whole word'),
    '#default_value' => $config
      ->get('scanner_wholeword'),
  ];
  $form['settings']['scanner_regex'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Default: Regular expression search'),
    '#default_value' => $config
      ->get('scanner_regex'),
  ];
  $form['settings']['scanner_published'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Default: Search published nodes only'),
    '#default_value' => $config
      ->get('scanner_published'),
  ];
  $form['settings']['scanner_pathauto'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Default: Maintain custom aliases'),
    '#default_value' => $config
      ->get('scanner_pathauto'),
  ];
  $langs = $this
    ->getLanguages();
  $form['settings']['scanner_language'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default: Content language'),
    '#options' => $langs,
    '#default_value' => $config
      ->get('scanner_language'),
  ];
  $available_entity_types = $this
    ->getAvailableEntityTypes();
  $form['enabled_content_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Enabled entity types'),
    '#options' => $available_entity_types,
    '#default_value' => $config
      ->get('enabled_content_types'),
    '#description' => $this
      ->t('Third party plugins can be written to add more options here.'),
    '#ajax' => [
      'callback' => [
        $this,
        'getFieldsCallback',
      ],
      'event' => 'change',
      'wrapper' => 'content-type-fields',
    ],
  ];
  $enabled_entity_types = $form_state
    ->getValue('enabled_content_types');
  if ($enabled_entity_types === NULL) {
    $enabled_entity_types = $this
      ->config('scanner.admin_settings')
      ->get('enabled_content_types');
  }
  $fields = $this
    ->getEntityTypeFields($available_entity_types, $enabled_entity_types);
  $form['fields_of_selected_content_type'] = [
    '#title' => $this
      ->t('Enabled fields'),
    '#type' => 'checkboxes',
    '#options' => $fields,
    '#default_value' => $config
      ->get('fields_of_selected_content_type'),
    '#prefix' => '<div id="content-type-fields">',
    '#suffix' => '</div>',
  ];
  return parent::buildForm($form, $form_state);
}