synonyms_behavior_implementation.html 2.3 KB

123456789101112131415161718192021222324252627
  1. 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 field type.
  2. By implementing I mean to provide integration between a field type (between how that field type stores and encodes synonyms data in the database) 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.
  3. 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 implementatios in <em>synonyms/includes/*SynonymsBehavior.class.inc</em> files.
  4. Creating a new implementation pretty much consists of 2 steps:
  5. <ol>
  6. <li>Implementing behavior interface for a particular field type.</li>
  7. <li>Notifying Synonyms module about your new PHP class and what field types and what behavior that PHP class is responsible for.</li>
  8. </ol>
  9. Now let us see each of the steps in further details.
  10. <h2>Implementing behavior interface</h2>
  11. 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. Read the documentation for that interface and write a PHP class that implements this interface. We cannot give more precise instructions about this step, because it all depends on the interface of the behavior.
  12. <h2>Notifying Synonyms module about your new implementation</h2>
  13. For the purposes of such notification we have 2 hooks in Synonyms module:
  14. <ul>
  15. <li>hook_synonyms_behavior_implementation_info() to collect info from modules about existing behavior implementations</li>
  16. <li>hook_synonyms_behavior_implementation_info_alter() to alter info about existing behavior implementations, for example, if you want to overwrite behavior implementation introduced in another module.</li>
  17. </ul>
  18. Implementing either of the 2 hooks is highly straight forward, you will just inform the Synonyms module for requested behavior for what field types you have implementations in what PHP classes. For more details, refer to synonyms.api.php file or look into synonyms_synonyms_behavior_implementation_info() function.