At this point you must possess good technical knowledge about what synonyms behaviors are. In this article we will show how you can implement an arbitrary behavior for an arbitrary storage.

By implementing I mean to provide integration between your storage and a synonym behavior (how that behavior requires to work with synonyms data). It must sound a bit too baked, but the ongoing paragraphs should shed more light onto it.

Throughout writing your own synonyms behavior implementation you can always look into Synonyms module source code to get better understanding. You will find the behavior implementations in synonyms/synonyms_provider_{property,field}/includes/*SynonymsBehavior.class.inc files.

Just one last question before we dive into technical details: is your storage eventually comes from a field? In case it does, you might benefit from reading this page as it narrates about implementing behaviors based on fields. You can leverage some abstractions from synonyms_provider_field submodule to make your life easier.

In case your storage is not field-based or you just happen to be Chuck Norris, read on! Creating a new implementation pretty much consists of 2 steps:

  1. Implementing behavior interface for a particular storage type.
  2. Notifying Synonyms module about your new behavior implementation, that is... for what behavior and what entity type and bundle you have implemented it.

Now let us see each of the steps in further details.

Implementing behavior interface

Look up in behavior cTools plugin definition of your interest what interface it declares. The cTools plugin must be of type behavior owned by synonyms module. The interface is declared under the interface property of the plugin definition. Read the documentation for that interface and write a PHP class that implements this interface for your particular storage. We cannot give more precise instructions about this step, because it all depends on the interface of the behavior.

Notifying Synonyms module about your new implementation

For the purposes of such notification we have the following hook in Synonyms module:

Implementing the hook is highly straight forward, you will just inform the Synonyms module about what behavior implementations your module has to offer for a given behavior, entity type, and bundle. For more details, refer to synonyms.api.php file.