synonyms_behavior_implementation_field_based.html 2.8 KB

1234567891011121314151617181920212223242526272829303132
  1. <p>If you are looking into implementing a behavior for storage that is eventually field-based, then you are on the right page! Since it is quite likely that many behavior implementations will be field-based, we have walked an extra mile to facilitate this particular case.</p>
  2. <p>First of all, there is <em>synonyms_provider_field</em> submodule that:</p>
  3. <ul>
  4. <li>implements some behaviors for a set of common field types (see <a href="&topic:synonyms/synonyms&">this page</a> for particular details)</li>
  5. <li>provides a good starting point for implementing behaviors for new field types</li>
  6. </ul>
  7. <p>Apparently, on this page we will focus on the 2nd item from the list above. If you implement a behavior for a new field type, then:</p>
  8. <ul>
  9. <li>Implement behavior interface for a particular field type. You are encouraged to extend your PHP class from <em>AbstractFieldSynonymsBehavior</em>. It has a few methods that will make your life easy. However, you are nowhere close to be obliged to use that abstract class; only as long as it helps you to achieve your goal.</li>
  10. <li>Notify <em>synonyms_provider_field</em> submodule about availability of a new field type.</li>
  11. </ul>
  12. <p>Now let us see each of the steps in further details.</p>
  13. <h2>Implementing behavior interface</h2>
  14. <p>Look up in behavior cTools plugin definition of your interest what interface it declares. The cTools plugin must be of type <em>behavior</em> owned by <em>synonyms</em> module. The interface is declared under the <em>interface</em> property of the plugin definition. Read the documentation for that interface and write a PHP class that implements this interface for your particular field type. We cannot give more precise instructions about this step, because it all depends on the interface of the behavior.</p>
  15. <h2>Notifying synonyms_provider_field submodule about your new implementation</h2>
  16. <p>For the purposes of such notification we have the following hooks in <em>synonyms_provider_field</em> submodule:</p>
  17. <ul>
  18. <li><em>hook_synonyms_field_behavior_implementation_info()</em> to collect info from modules about field types available for synonyms behavior implementations</li>
  19. <li><em>hook_synonyms_provider_field_behavior_implementation_info_alter()</em> to alter previously collected info from modules about field types available for synonyms behavior implementations</li>
  20. </ul>
  21. <p>Implementing either of the 2 hooks is highly straight forward, you will just inform the submodule about what field type is exposed to behavior implementation through what PHP class for a given behavior. Then the <em>synonyms_provider_field</em> submodule will analyze what fields are attached to what entity types and will convert this data into the format expected by the core Synonyms module. For more details, refer to <b>synonyms_provider_field.api.php</b> file.</p>