You are here

public function BasicTitleSearch::getConfigForm in Fast Autocomplete 8

Gets the configuration form for the search plugin.

Parameters

array $plugin_config: The plugin config array.

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

Return value

array The configuration form for the search plugin.

Overrides SearchBase::getConfigForm

File

src/Plugin/Search/BasicTitleSearch.php, line 99

Class

BasicTitleSearch
Provides a basic node title search plugin.

Namespace

Drupal\fac\Plugin\Search

Code

public function getConfigForm(array $plugin_config, FormStateInterface $form_state) {
  $bundle_options = [];
  try {
    $bundles = $this->entityTypeManager
      ->getStorage('node_type')
      ->loadMultiple();
  } catch (InvalidPluginDefinitionException $e) {
    $bundles = [];
  }
  foreach ($bundles as $key => $bundle) {
    $bundle_options[$bundle
      ->id()] = $bundle
      ->label();
  }
  $form['bundle_filter'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Filter by bundle'),
    '#options' => $bundle_options,
    '#multiple' => TRUE,
    '#default_value' => isset($plugin_config['bundle_filter']) ? $plugin_config['bundle_filter'] : [],
    '#description' => $this
      ->t('Select one or more bundles to include in the results. Select no bundles to disable the bundle filter.'),
  ];
  $form['language_filter'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Filter by language'),
    '#default_value' => isset($plugin_config['language_filter']) ? $plugin_config['language_filter'] : '',
    '#description' => $this
      ->t('Check this option if you want the results to be filtered by language'),
  ];
  $form['langcode_includes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('No specific language'),
    '#options' => [
      LanguageInterface::LANGCODE_NOT_APPLICABLE => $this
        ->t('Include "language not applicable"'),
      LanguageInterface::LANGCODE_NOT_SPECIFIED => $this
        ->t('Include "Language not specified"'),
    ],
    '#default_value' => isset($plugin_config['langcode_includes']) ? $plugin_config['langcode_includes'] : [],
    '#states' => [
      'invisible' => [
        ':input[name="plugin[config][language_filter]"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  return $form;
}