1

I have written a new CiviRules Action and added the entry to the database but I don't know where to put the php file. I have read all the documents I can find but I can't find any information about a directory structure for rules addons. I would like to keep it as part of an extension I have written. Any help with the file location would be appreciated.

Thanks

2

You put it in your own extension, under the CRM folder and subfolders you need to create depending on the class name. See https://docs.civicrm.org/civirules/en/latest/create-your-own-action/#step-2-add-a-class-that-extends-crm_civirule_action

You can include the class file in the Civirules extension if you want,
but you can also include it in your own extension. This class should extend
CRM_Civirules_Action to be able to add your action to the CiviRules Engine

So let's say your class is CRM_Mynamespace_CivirulesActions_Contact_Subtype, then you'd call the file Subtype.php and put it in your extension in CRM/Mynamespace/CivirulesActions/Contact

| improve this answer | |
  • Thank you for the reply. This is the first time I have seen it documented that the Class name is anything other than a random collection of joined words. I suppose it is sort of obvious when you are told but how was I to know? Maybe the text you highlight above should also say "and the class name determines the path to the file containing the new class". I have accepted your answer. Thank you – Crofter Jan 18 at 8:55
  • Up to a point the class name is a random collection of joined words. The file path is a standard PHP PSR-4 autoloader rule. The CRM_Mynamespace part is a little specific to where civi extensions look for files and the convention that civix uses, but otherwise the part after it can be whatever you want. You could do CRM_Mynamespace_Grapple_Grommit_Foo extends CRM_Civirules_Action and put the Foo.php file in CRM/Mynamespace/Grapple/Grommit. Often you would do civix generate:XXX, and then it makes the files for you, there just isn't an XXX command for CiviRules, but it's the same pattern. – Demerit Jan 18 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.