CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Is it possible to override core PHP files in an extension?
Pages: [1]

Author Topic: Is it possible to override core PHP files in an extension?  (Read 2129 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Is it possible to override core PHP files in an extension?
June 23, 2013, 05:26:57 pm
Currently I have some customization that I did by putting a custom version of a core civicrm PHP file in my custom override PHP folder.
 
For example, I have a custom version of the core file "CRM/Activity/Page/tab.php" in my custom directory because I needed to add an extra select list next to the existing "create activity" select list that is only visible after the user clicks the "Activity" tab on a contact.

Is it possible to place this php file in an CiviCRM native extension instead? 
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Is it possible to override core PHP files in an extension?
June 23, 2013, 09:46:40 pm
yes, use civix to generate the extension and it will work

Beware that as they aren't priority ordering of the extensions, you might/will have problems if several extensions are trying to replace the same file.

Not sure to what extend you select list (or other improvments) are useful for others, but might be easier and better to share them back so they can be added in the core.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Is it possible to override core PHP files in an extension?
June 24, 2013, 12:18:57 am
Yeah, overrides are technically possible -- but a bad idea.

I don't entirely understand what the override is accomplishing in this case -- is it adding a new <SELECT> that's adjacent to the existing <SELECT>? Or adding a new <OPTION> inside the existing <SELECT>? Since the <OPTION>s are auto-generated, shouldn't the default be right (i.e. all useable activity types should be included in the list)?

In any event, there are some other tools you can use to manipulate the output of that tab. For example, one might try to add some extra Javascript code ( http://wiki.civicrm.org/confluence/display/CRMDOC43/Resource+Reference ) to manipulate the tab:

Code: [Select]
function mymodule_civicrm_pageRun($page) {
  if ($page instanceof  CRM_Activity_Page_Tab) {
    CRM_Core_Resources::singleton()->addScript("
      cj('.whatever-widget').append('<whatever-html>");
    ");
  }
}

function mymodule_civicrm_pageRun($page) {
  if ($page instanceof  CRM_Activity_Page_Tab) {
    CRM_Core_Resources::singleton()->addScript("
      cj('.whatever-widget').append('<whatever-html>");
    ");
  }
}

// ... or ...

function mymodule_civicrm_pageRun($page) {
  if ($page instanceof  CRM_Contact_Page_View_Summary) {
    CRM_Core_Resources::singleton()->addScriptFile("org.example.myext","myext.js");
  }
}


In many cases, one could use some PHP code to manipulate the outputted region ( http://wiki.civicrm.org/confluence/display/CRMDOC43/Region+Reference ).

I haven't tested these with the activity tab per-se. There could be an issue since it's generated via AJAX (and we've mostly tested resource/region stuff with standalone pages) -- if there is an issue, let's identify that and fix it. It's more maintainable than using overrides.

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Is it possible to override core PHP files in an extension?
June 24, 2013, 04:18:50 pm
The hook "civicrm_pageRun" did the trick. I no longer need to override the .tpl file.   What I am doing: creating a new select list that contains a list of existing activities. If the user chooses one, then that activity is copied as a new activity record. (Different activity id of course. I also leave the "assignee" field empty and use the current date stamp as the new activity date)

The purpose is to save data-entry time for the end-user when most of the new activities they need to create are virtually the same as an existing activity record. (In this environment there is a lot of custom data for each activity).
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Is it possible to override core PHP files in an extension?

This forum was archived on 2017-11-26.