public function SynonymsFormatWordingTrait::synonymFormatWording in Synonyms 8
Format a synonym into wording as requested by configuration.
Parameters
string $synonym: Synonym that should be formatted.
\Drupal\Core\Entity\ContentEntityInterface $entity: Entity to which this synonym belongs.
\Drupal\synonyms\SynonymInterface $synonym_config: Synonym config entity in the context of which it all happens.
Return value
string Formatted wording
File
- src/
SynonymsProviderInterface/ SynonymsFormatWordingTrait.php, line 26
Class
- SynonymsFormatWordingTrait
- Trait to format wording of a synonym.
Namespace
Drupal\synonyms\SynonymsProviderInterfaceCode
public function synonymFormatWording($synonym, ContentEntityInterface $entity, SynonymInterface $synonym_config) {
// @todo Maybe we should use tokens replacement here? But then it would mean
// an extra dependency on the tokens module. Is it worth it? For now let's
// use stupid str_replace() and incorporate tokens only if user base really
// asks for it.
$map = [
'@synonym' => $synonym,
'@entity_label' => $entity
->label(),
];
return str_replace(array_keys($map), array_values($map), $synonym_config
->getBehaviorConfiguration()['wording']);
}