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) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Hooks and Joomla
Pages: [1]

Author Topic: Hooks and Joomla  (Read 7376 times)

rogerco

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 5
Hooks and Joomla
August 15, 2008, 02:03:04 am
I'm trying to get my head around how I might use the CiviCRM hooks to perform additional actions when a profile form is submitted.

Unfortunately all the docs seem to talk in terms of Drupal modules, if I understand correctly it is possible to register a function that extends a hook:: object in CiviCRM?

Is this even possible in Joomla - I am guessing it would be implemented as a Plugin rather than a component or module (joomla 1.5 terms) since I don't need any user interface.

Anyone done this/got a working example/give me a clue?

RogerCO
 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hooks and Joomla
August 15, 2008, 02:10:32 pm

Since joomla does not have a hook mechanism, we only allow "one" implementation

Soif you implement the funcitons joomla_civicrm_pre or joomla_civicrm_post, they will get called in joomla. The next issue is you need to make sure the file is included when civicrm is running

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

mcsmom

  • I post frequently
  • ***
  • Posts: 266
  • Karma: 23
    • Official Joomla! Book
  • CiviCRM version: 4 and 3.4
  • CMS version: Joomla!
Re: Hooks and Joomla
August 19, 2008, 02:39:50 am
Plugins are definitely one of the keys.  Right now civi on the whole does not take advantage of the framework or the plugin structure. The Joomla part is really the same as it was in 1.0 but modified just enough to get it to run in 1.5. Plugins are one way to get around that.  (If you start looking inside those files you will see lots of places with mos--those are the areas that have not been touched.)

Also, i've been spending a lot of time recently working on the front end. If you create a real Joomla front end, with a view for your profile (or event etc) you can take advantage of the framework without touching the civi files. I think that will solve a lot of the issues.






rogerco

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 5
Re: Hooks and Joomla
August 19, 2008, 08:59:49 am
Quote from: mcsmom on August 19, 2008, 02:39:50 am
...Also, i've been spending a lot of time recently working on the front end. If you create a real Joomla front end, with a view for your profile (or event etc) you can take advantage of the framework without touching the civi files. I think that will solve a lot of the issues.
Interesting - I've been musing about this (the possibility of building a proper Joomla front-end using the J1.5 framework) as a way of getting around some of the many issues with getting useful access to the Civi data in Joomla.
Leave Civi to get on with the backend admin stuff and do a proper front end (which would also automatically pickup your site template styles etc)...many advantages...might be a bit client specific though, I wonder if there are some generic views that could be defined...perhaps a separate thread to discuss?

mcsmom

  • I post frequently
  • ***
  • Posts: 266
  • Karma: 23
    • Official Joomla! Book
  • CiviCRM version: 4 and 3.4
  • CMS version: Joomla!
Re: Hooks and Joomla
August 22, 2008, 03:08:17 pm
That's exactly what I have been doing, trying to define generic views for the 4 main types (profile, event, contribution and dash) and one I want (actvitity). I believe that if that can be accomplished suddenly we are in a whole new world of usability.

I think it would be cool to start a thread. I believe most of the code needed can be extracted from the civi backend files pretty easily. (she says optimistically).

« Last Edit: August 22, 2008, 03:29:12 pm by mcsmom »

Cedeira

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 1
    • CompuLogiX Systems, Inc.
Re: Hooks and Joomla
October 16, 2008, 09:10:49 am
Are these hooks for Joomla documented somewhere in the wiki or on a thread?

I was going to start using the hooks to build a relationship during Event sign up when a user is signing up  multiple people until I realized the hooks are only for Drupal.

I am using Joomla 1.5.x and Drupal 2.1.

This is what I wanted to do:

When a user selects an Event to sign up for a Profile for a Household is displayed with the option to sign up multiple members(so far the new upgrade to signing up multiple people for an event is a good addition!), when the last member (Contact) is added to the DB, the Profile form would fire the code to call the relationship api calls to create the relationship between all the signup members.

Do you think this is possible to do with some code? I checked the contact.php and found where the pre and post hooks are called.

I wouldn't want to change the core files. I still have some items to think about such as:

How to link the first (assuming a Household) and last (contact) sign up so that I can create the relationship. Some folks in the forum have been discussing this feature but I haven't seen anyone volunteering the code  :(

This was my overall solution, steps:

1. Intercept the call on the profile to add the household
2. Within my own code save the Household ID number (or add a relationship for each contact added once the first one is added?)
3. Intercept the last Save on the last contact (I think Civi already has this), but I would want to call my code here to create the relationship between the contact and the household.

which files should I be looking at, besides the Relationships.php API file and the Contacts.php?

Just throwing this out there to see if anyone has suggestions?

thanks in advance,
Jose


 
God grant me the serenity to accept the things I can not change, valor to change the ones I can, and the knowledge to recognize the difference!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hooks and Joomla
October 16, 2008, 10:54:50 am

The hooks are defined here:

http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specification

Not sure if u can define a household profile for event registration. needs to be an individual/participant profile. We dont create household in that flow (only individuals)

You can implement the post hook for civicrm contact and on the first call, create/reuse a household and attach the first contact to the household. on subsequent calls, you can add a relationship between the contact and the household

lobo



A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Cedeira

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 1
    • CompuLogiX Systems, Inc.
Re: Hooks and Joomla
October 19, 2008, 10:02:19 am
Lobo, thanks for the quick answer.

I did read the hooks documention you mention. I even understand that there are only two hooks that can be used in Joomla, the _pre and _post ones. But, for a php/civicrm noob like me it is still a bit hard to understand the relationship of the hooks and how they are fired. I think I need a bit more research on how that is all related. I assume that profile fields can be set through code or access through the hooks, etc. But, where do I place the hook code? is it only a matter of putting an include in one of the php files from Civicrm?

BTW, I was succesful in creating a Household through a profile in the Event registration.

thanks,
Jose
God grant me the serenity to accept the things I can not change, valor to change the ones I can, and the knowledge to recognize the difference!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hooks and Joomla
October 19, 2008, 04:47:17 pm

joomla can use all the hooks as defined. You will need to name the function

joomla_civicrm_pre(...) / joomla_civicrm_post(...) etc (and similar for the other hooks).

You should place the hook code in a specific file, and include the file in

administrator/components/com_civicrm/admin.civicrm.php
components/com_civicrm/admin.civicrm.php

Are u using 2.1? i'm a bit surprised that event reg will create a household record

lobo



A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Cedeira

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 1
    • CompuLogiX Systems, Inc.
Re: Hooks and Joomla
October 19, 2008, 05:03:17 pm
ooops: in my previous post "using Joomla 1.5.x and Drupal 2.1." I meant CiviCRM 2.1.

I will test it again, but I am pretty sure that I did create a household record in the event registration. I don't think it was part of the "... register additional people" work-flow, but through using a household profile. I hope you understand what I mean.

thanks for the code hints. I will give it a try. If I am successful, in creating a relationship through the registration work-flow, I will give it back to the community since I see some folks have been looking for similar functionality.

regards,
Jose

God grant me the serenity to accept the things I can not change, valor to change the ones I can, and the knowledge to recognize the difference!

mcsmom

  • I post frequently
  • ***
  • Posts: 266
  • Karma: 23
    • Official Joomla! Book
  • CiviCRM version: 4 and 3.4
  • CMS version: Joomla!
Re: Hooks and Joomla
November 11, 2008, 05:41:59 am
Lobo,

Why wouldn't you just create the plugins and define a plugin set and call that with the dispatcher?

mcsmom

  • I post frequently
  • ***
  • Posts: 266
  • Karma: 23
    • Official Joomla! Book
  • CiviCRM version: 4 and 3.4
  • CMS version: Joomla!
Re: Hooks and Joomla
November 11, 2008, 06:13:34 am
Ok I talked to Sam and he said:

Add this to admin.civicrm.php

//invoke plugins.
JPluginHelper::importPlugin('civicrm');
$app =& JFactory::getApplication();
$app->triggerEvent('onCiviLoad');

(near the top, I put it right after the php 4 check)


Then you can create a plugin. Attached is an example that just raises a warning.
And that's how you do hooks in Joomla 1.5 :)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Hooks and Joomla
November 11, 2008, 08:29:49 am

cedeira:

do you want to add this and give it a shot. let us know how it works.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

mcsmom

  • I post frequently
  • ***
  • Posts: 266
  • Karma: 23
    • Official Joomla! Book
  • CiviCRM version: 4 and 3.4
  • CMS version: Joomla!
Re: Hooks and Joomla
November 11, 2008, 09:16:04 am
This is a good tutorial on how to make a plugin:

http://developer.joomla.org/tutorials/184-how-to-create-a-joomla-plugin.html

Cedeira

  • I post occasionally
  • **
  • Posts: 45
  • Karma: 1
    • CompuLogiX Systems, Inc.
Re: Hooks and Joomla
November 13, 2008, 07:12:04 am
Lobo,

I would love to try the plugin route, but unfortunately I am under a time constraint to deliver the site before the end of the month, latest mid-December. I decided I will probably hack the code you have on 2.1 that allows relationships for employers to be done in profiles. I don't think it will be too complicated to change the code so that instead of an employer another person is selected to add parent->child relationship. That being said, I have been found to be wrong before ;D !

Once I deliver this site I promise I will take the J plugin route on, in my spare time.

best regards,
Jose


God grant me the serenity to accept the things I can not change, valor to change the ones I can, and the knowledge to recognize the difference!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Hooks and Joomla

This forum was archived on 2017-11-26.