public function SelectService::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/ SelectService.php, line 45
Class
- SelectService
- Synonyms behavior service for select widget.
Namespace
Drupal\synonyms\SynonymsService\BehaviorCode
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 select entry'),
'#default_value' => $wording,
'#description' => $this
->t('Specify the wording with which the select entry should be presented. Available replacement tokens are: @replacements', [
'@replacements' => $replacements,
]),
'#required' => TRUE,
];
return $form;
}