trait ConfigurationTrait in Synonyms 2.0.x
Provider configuration trait.
Hierarchy
- trait \Drupal\synonyms\ProviderInterface\ConfigurationTrait uses StringTranslationTrait
1 file declares its use of ConfigurationTrait
- AbstractProvider.php in src/
Plugin/ Synonyms/ Provider/ AbstractProvider.php
File
- src/
ProviderInterface/ ConfigurationTrait.php, line 13
Namespace
Drupal\synonyms\ProviderInterfaceView source
trait ConfigurationTrait {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'wording' => '',
];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
/**
* {@inheritdoc}
*/
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 = \Drupal::service('renderer')
->renderRoot($replacements);
$wording = isset($configuration['wording']) ? $configuration['wording'] : '';
$form['wording'] = [
'#type' => 'textfield',
'#title' => $this
->t('Wording for this provider'),
'#default_value' => $wording,
'#description' => $this
->t('Specify the wording with which this entry should be presented. Available replacement tokens are: @replacements Note: To avoid unnecessary complexity there is no per-widget wording configuration here at provider level. So, this wording will be used by all installed synonyms-friendly widgets.', [
'@replacements' => $replacements,
]),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state, SynonymInterface $synonym_config) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state, SynonymInterface $synonym_config) {
return [
'wording' => $form_state
->getValue('wording'),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurationTrait:: |
public | function | ||
ConfigurationTrait:: |
public | function | ||
ConfigurationTrait:: |
public | function | ||
ConfigurationTrait:: |
public | function | ||
ConfigurationTrait:: |
public | function | ||
ConfigurationTrait:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |