1

I want to create an extension for CiviCRM that will add an extra column for appended documents inside the activities list of a Case View. That is, when users have appended a document while creating an activity, that document will not be shown in one column together with the View, Edit and More links, but in a separate column together with their filename, for a clearer view.

The changes I need to make contain six patches inside three PHP files, and one patch inside a template file. I used civix to create an extension skeleton. Then, it has been easy to make the adapted template file work by copying it into sites/default/files/civicrm/ext/extensionname/templates/Case/Form/templatename.tpl. The path where the original template lies is sites/all/modules/civicrm/templates/CRM/Case/Form/.

But now, I'm struggling with including the adapted PHP files. I know that hook functions exist and that I could try to find a suitable hook function for each of the six patches, but it seems a very complicated solution to me.

I wonder if there is a solution similar to the way templates can be included in extensions? For example, is there a way to put all the PHP files inside a folder structure like sites/default/files/civicrm/ext/extensionname1/CRM/extensionname2/path/to/example/example.php, and they will simply be called instead of their original CiviCRM "sister file"?

In this example, extensionname1 stands for the name I gave to the extension while creating it with civix generate:module (here: de.company.activities-column-for-documents) and extensionname2 stands for the extension's 'given name' from info.xml (here: ActivitiesColumnForDocuments when info.xml contains <file>activities_column_for_documents</file>).

I came up with this idea after reading https://docs.civicrm.org/dev/en/latest/extensions/structure/ where it sounds like you'd be able to do that, if you only follow the naming conventions (CRM_Myextension_...). Though, it didn't work, even though I renamed all my PHP files, e.g. from Case.php to CRM_ActivitiesColumnForDocuments_Case.php.

The only other related thread I could find was How to Create an extension? but I didn't find it helpful here.

Can I use the CRM directory that is auto-created by civix to easily store custom versions of existing CiviCRM PHP files? How? If not, what is the auto-created CRM directory for?

Any hints are appreciated :) If I can successfully create the extension, I will of course publish it here.

4

Overriding core files was how we used to make changes until collectively we figured out that was storing up trouble for the future.

Another possibility is that if you think this is likely to be a small, useful improvement for most users of this aspect of CiviCRM then you could propose it as a change for core - go here and use the 'improvement' template. If that is agreed then submit your changes as a PR.

3
  • Thank you. To estimate if that could be sufficient for our specific problem: Do you know how long it would approximately/usually take for the changes to be put in place (if agreed)? This information could be useful to know if we need to work on a custom solution in parallel. – emma Jan 7 at 11:10
  • The release process is documented here A new version has just been released so we are at the start of the cycle. Once you submit your PR some checks run automatically that need to pass and it will be reviewed. How long review takes varies a lot depending on the complexity of the change and interest/availability of reviewers but for a small change it can be a few days (even hours). If your change were merged this month, it would be in the Feb RC and then the March release. – Aidan Jan 7 at 12:10
  • ... and once it is merged, you can apply it locally to your site knowing it will part of the official release in a month or two. – Aidan Jan 7 at 12:12
3

The simple answer to "Can I use the CRM directory that is auto-created by civix to easily store custom versions of existing CiviCRM PHP files?" is no, not easily.

While it can be made to work, if you just use a modified copy to replace the core file, then you have to keep your file in sync after every upgrade, which is not fun. So yes it takes extra work with a hook etc but then you don't have to keep updating your copy of the file. Also using modified copies of core files would make your extension ineligible for automatic distribution with civi if you ever wanted to do that.

In this specific case (pun intended) for the activity list, it maybe is a bit more difficult than it could be because of the mix of many technologies used for that table.

4
  • Is there a reason why this solution has been kept with templates? Are templates not being changed during updates, or not so regularly? – emma Feb 15 at 11:36
  • 1
    I don't fully understand the question but core templates do change regularly. – Demerit Feb 15 at 13:45
  • Maybe my question would have been more suitable under Aidan's answer, I see now. I refer myself to "Overriding core files was how we used to make changes until collectively we figured out that was storing up trouble for the future." -> Why does that not apply to templates? It is more of a curiosity question though. – emma Feb 17 at 8:53
  • It does apply to templates, for the same reason as .php and other files. Use hooks in your extension instead, which will avoid problems when you upgrade. The difficulty with using hooks for the activities list is that the activities list is designed in a way that's hard to work with so I don't have a good answer for that problem specifically. – Demerit Feb 17 at 14:09

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.