class SelectService in Synonyms 2.0.x
Synonyms behavior service for select widget.
Hierarchy
- class \Drupal\synonyms_select\SynonymsService\Behavior\SelectService implements BehaviorInterface, WidgetInterface uses StringTranslationTrait
Expanded class hierarchy of SelectService
1 string reference to 'SelectService'
- synonyms_select.services.yml in modules/
synonyms_select/ synonyms_select.services.yml - modules/synonyms_select/synonyms_select.services.yml
1 service uses SelectService
- synonyms.behavior.select in modules/
synonyms_select/ synonyms_select.services.yml - Drupal\synonyms_select\SynonymsService\Behavior\SelectService
File
- modules/
synonyms_select/ src/ SynonymsService/ Behavior/ SelectService.php, line 13
Namespace
Drupal\synonyms_select\SynonymsService\BehaviorView source
class SelectService implements BehaviorInterface, WidgetInterface {
use StringTranslationTrait;
/**
* The synonyms provider service.
*
* @var \Drupal\synonyms\SynonymsService\ProviderService
*/
protected $providerService;
/**
* SelectService constructor.
*/
public function __construct(ProviderService $provider_service) {
$this->providerService = $provider_service;
}
/**
* {@inheritdoc}
*/
public function getId() {
return 'select';
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this
->t('Select');
}
/**
* {@inheritdoc}
*/
public function getWidgetTitle() {
return $this
->t('Synonyms-friendly select');
}
/**
* Extract a list of synonyms from multiple entities.
*
* @param array $entities
* Array of entities from which to extract the synonyms. It should be keyed
* by entity ID and may only contain entities of the same type and bundle.
*
* @return array
* Array of synonyms. The returned array will be keyed by entity ID and the
* inner array will have the following structure:
* - synonym: (string) Synonym itself
* - wording: (string) Formatted wording with which this synonym should be
* presented to the end user
*/
public function selectGetSynonymsMultiple(array $entities) {
if (empty($entities)) {
return [];
}
$synonyms = [];
foreach ($entities as $entity) {
$synonyms[$entity
->id()] = [];
}
$entity_type = reset($entities)
->getEntityTypeId();
$bundle = reset($entities)
->bundle();
if ($this->providerService
->serviceIsEnabled($entity_type, $bundle, $this
->getId())) {
foreach ($this->providerService
->getSynonymConfigEntities($entity_type, $bundle) as $synonym_config) {
foreach ($synonym_config
->getProviderPluginInstance()
->getSynonymsMultiple($entities) as $entity_id => $entity_synonyms) {
foreach ($entity_synonyms as $entity_synonym) {
$synonyms[$entity_id][] = [
'synonym' => $entity_synonym,
'wording' => $synonym_config
->getProviderPluginInstance()
->synonymFormatWording($entity_synonym, $entities[$entity_id], $synonym_config, $this
->getId()),
];
}
}
}
}
return $synonyms;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SelectService:: |
protected | property | The synonyms provider service. | |
SelectService:: |
public | function |
Get machine readable ID of this behavior. Overrides BehaviorInterface:: |
|
SelectService:: |
public | function |
Get human readable title of this behavior. Overrides BehaviorInterface:: |
|
SelectService:: |
public | function |
Get human readable title of this widget. Overrides WidgetInterface:: |
|
SelectService:: |
public | function | Extract a list of synonyms from multiple entities. | |
SelectService:: |
public | function | SelectService constructor. | |
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. |