You are here

public function AutocompleteService::buildConfigurationForm in Synonyms 8

Build configuration form.

Parameters

array $form: Form into which your configuration form will be embedded. You are supposed to extend this array with additional configuration form elements that your behavior needs.

\Drupal\Core\Form\FormStateInterface $form_state: Form state object that corresponds to this form.

array $configuration: Array of existing configuration for your behavior. Normally you would use it as a source of default values for your configuration form elements.

\Drupal\synonyms\SynonymInterface $synonym_config: Synonym config entity in the context of which the form is being built.

Return value

array Extended $form that includes the form elements required for configuration of your behavior

Overrides SynonymsBehaviorConfigurableInterface::buildConfigurationForm

File

src/SynonymsService/Behavior/AutocompleteService.php, line 82

Class

AutocompleteService
Synonyms behavior service for autocomplete.

Namespace

Drupal\synonyms\SynonymsService\Behavior

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state, array $configuration, SynonymInterface $synonym_config) {
  $replacements = [
    '#theme' => 'item_list',
    '#list_type' => 'ul',
    '#items' => [],
  ];
  foreach ($synonym_config
    ->getProviderPluginInstance()
    ->formatWordingAvailableTokens() as $token => $token_info) {
    $replacements['#items'][] = Html::escape($token) . ': ' . $token_info;
  }
  $replacements = $this->renderer
    ->renderRoot($replacements);
  $wording = isset($configuration['wording']) ? $configuration['wording'] : '';
  $form['wording'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Wording for autocomplete suggestion'),
    '#default_value' => $wording,
    '#description' => $this
      ->t('Specify the wording with which the autocomplete suggestion should be presented. Available replacement tokens are: @replacements', [
      '@replacements' => $replacements,
    ]),
    '#required' => TRUE,
  ];
  return $form;
}