If you made it up to here, then we expect you to already have decent understanding about what a synonyms behavior is. This page will try to explain how you could create a new one. In technical terms synonyms heaviors are just cTools plugins. Synonyms module defines its own plugin type: behavior, which is owned by synonyms module. Throught writing your own synonyms behavior you can always look into Synonyms module behaviors to get better understanding. You will find the plugins in synonyms/plugins/behavior/*.inc files. If you have never worked before with cTools plugins, if is also worthwhile to check out its documentation. Your plugin implementation may (or must) have the following keys:
title
Required (string) Human-friendly translated title of your behavior.
description
(string) Human-friendly translated description of your behavior. Include a couple of words about what exactly it does and what end user functionality has.
settings form callback
(string) Name of a PHP function that will be invoked to generate settings form of your behavior. End user will fill out the form elements and the settings will be saved in the database for your plugin by Synonyms module. If your behavior does not require any additional configuration, you may omit this parameter. If you do require a settings form, then this callback function should receive the following input arguments:
  1. $form: (array) form array into which your settings form elements will be merged. You do not have to change this $form. It is just provided to you in case you want to traverse through it for whatever reason.
  2. &$form_state: (array) form state array of the form into which your settings form elements will be merged. Again, you are not obliged to change or to use this argument, but it is provided to you in case you find it useful to keep some data in form state.
  3. $settings: (array) array of settings defined for your behavior. This array may be empty, if your behavior hasn't been saved yet, or it may contain previously saved settings. You should use content of this array as default values for your form elements.
Based on these input arguments, your settings form callback function should generate form elements array and return it.
interface
Required: (string) Name of a PHP interface that represents your behavior. This interface should declare any methods that support your behavior. Implementations of your behavior will have to implement this interface for specific field types. To make it easier for you, think of the default synonyms behavior: it introduces the "synonyms" property on entities. Whenever that property is requested, the behavior code loops through enabled default synonyms behavior implementations asking to "extract synonyms from field values". So this "extract synonyms" method is declared in the interface. This way behavior implementations can implement the interface and therefore Synonyms without knowing anything specific about the underlying field type will be able to carry out its part - to get a list of synonyms. We advice to name the interfaces in the following fashion: NameOfYourBehaviorHereSynonymsBehavior. Also, your interface must extend the starting point of all synonyms behaviors - the SynonymsBehavior interface. If your behavior depends on functionality provided by other behaviors (for example, many behaviors depend on the general "synonyms" behavior), then your interface may extend the interface of that behavior (which would be to extend the SynonymsSynonymsBehavior in the case of "synonyms" behavior).
enabled callback
(string) Name of a PHP function that will be invoked to notify your behavior that it has just been enabled on a new field. You could do any set-up routines in this function, if it is required by your behavior. If your behavior does not require any set up logic, you may omit this parameter. If you do specify it, then this callback function should receive the following input arguments:
  1. $behavior_definition: (array) Array of behavior definition. Basically it is your cTools plugin definition.
  2. $settings: (array) Array of settings for your behavior that is getting enabled. If your set up procedure depends on the behavior settings, then you can access the settings through this variable.
  3. $instance: (array) Array of field instance definition on which your behavior has just been enabled. Similarly as with $settings, if your set up procedure depends on field type, entity type, etc., then you can read this information from this var.
disabled callback
(string) Name of a PHP function that will be invoked to notify your behavior that it has just been disabled on a field. You could do any tear-down routines in this function, if it is required by your behavior. If your behavior does not require any tear down logic, you may omit this parameter. If you do specify it, then this callback function should receive the following input arguments:
  1. $behavior_definition: (array) Array of behavior definition. Basically it is your cTools plugin definition.
  2. $behavior_implementation: (array) Array of behavior implementation. It is a return of synonyms_behavior_get() function. This array will contain plenty of information about the context. Among other things it will include settings of your behavior.
  3. $instance: (array) Array of field instance definition on which your behavior has just been disabled. If your tear down procedure depends on field type, entity type, etc., then you can read this information from this var.
Having said the above, let us wrap up on how you should create a new behavior:
  1. Think through what you want your behavior to do and what interface will be required to support your behavior.
  2. Declare your behavior interface, make sure to document and to well comment the interface methods. The better docs it has, the easier it will be for other developers to implement your behavior for new field types. Also, make sure your interface extends the necessary interfaces from other behaviors (if your behavior depends on the functionality of other behaviors).
  3. Write PHP code that will use the interface to achieve some productive action. Depending on what your behavior does, it may be but not limited to implementing a hook, writing a custom PHP function, etc.
  4. Probably you will want to implement your freshly created behavior for at least one field type. Otherwise your behavior won't have any synonyms to work with and will be useless. Read about implementing a behavior for new field types here.