CVS edit link for FatherShawn

This is my first Drupal module. It adds a feature to CiviCRM that I need for a project I'm building. After feedback from other CiviCRM developers I've made it useful for this class of problem in general.

CiviCRM Relate creates a CiviCRM relationship between the acting user and a CiviCRM contact created by the acting user through the submission of a designated CiviCRM profile form.

The module has a simple configuration page which accepts via select fields the Profile to use and the relationship to create.

Comments

fathershawn’s picture

StatusFileSize
new3.54 KB

Here's my module

fathershawn’s picture

Status: Postponed (maintainer needs more info) » Needs review
fathershawn’s picture

StatusFileSize
new2.8 KB

Updated code - forgot to implement hook_uninstall to remove the two variables set by this module.

avpaderno’s picture

Status: Needs review » Needs work
Issue tags: +Module review

Hello, and thanks for applying for a CVS account. I am adding the review tags, and some volunteers will review your code, pointing out what needs to be changed.

As per http://drupal.org/cvs-application/requirements, the motivation message should be expanded to contain more details about the features of the proposed module, and it should include also a comparison with the existing solutions.

fathershawn’s picture

Thanks, and I'm happy to give more detail about the purpose of the module.

CiviCRM provides hooks (http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+hook+specifica...) and APIs (http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs) in a manner inspired by Drupal that allow the extension of CiviCRM or the manipulation of its data. One of the core functions of CiviCRM is the ability to expose to a user a form (a profile in CiviCRM terms) to collect contact information. Another core function is the ability to define relationship types and to create a relationship between two contacts. CiviCRM Relate uses Civi's hooks and APIs to combine those two functions.

This is "one-trick pony". It solves a specific problem. There is no other module in contrib that addresses this. The only current solution is to create custom code for each project using hooks and APIs. I had originally written a custom module with the profile and relationship hard coded into the module because I needed this feature for a Drupal/CiviCRM base app that I'm creating. In the course of that work, I hit a snag and sought help on the CiviCRM developer forums (http://forum.civicrm.org/). Other CiviCRM developers said essentially, "That's cool!" so I decided to add code to make it a general solution.

In it's current form, it loads from the civicrm db all the appropriately defined profiles and all the relationships and displays those via select fields in a Site Config. settings page. Those selections are stored as variables and used to match against the profile id, creating the relationship when the appropriate profile id is saved.

avpaderno’s picture

Status: Needs work » Needs review

Thank you for your reply.

fathershawn’s picture

StatusFileSize
new2.85 KB

Changed some code formatting to match Drupal standards. Note that Coder flags the lack of curly braces around table names, but placing them breaks the query syntax and the query is to CiviCRM and is not sanitized through Drupal.

fathershawn’s picture

StatusFileSize
new2.51 KB

Revised again, now uses CiviCRM API for all database access and satisfies coding standards.

fathershawn’s picture

StatusFileSize
new3.53 KB

Added a README with installation and configuration instructions

dman’s picture

Status: Needs review » Needs work

I'm probably unable to judge the actual code going on here without going through a whole civicrm install, but WRT Drupal expectations...

1. use of require_once()

/**
 *  Initialize CiviCRM with the Profile & Relationship APIs
 */
function civi_relate_prep() {
  civicrm_initialize();
  require_once('api/v2/UFGroup.php');
  require_once('api/v2/UFJoin.php');
  require_once('api/v2/Relationship.php');
}

I presume civicrm_initialize() has done something to the include_path already? Because that require_once wouldn't normally work. Not a bug if it does indeed work, and if civicrm isn't set up in a way that allows module_load_include like we'd normally expect. I appreciate that as a 'bridge' module sometimes you have to use non-Drupal conventions when talking to the other side. It just looks like non-drupal-style code.

2. Uneven indentation

...
    if ( civicrm_error ( $result )) {
      return $created_result['error_message'];
      }
    else {
      return $created_result['id'];
      }
    }
}

Throughout, the close braces seem to be floating a bit. Drupal coding standards have them match.
Seeing as you've run coder.module, I would have thought it would have caught that.
Indenting is uneven in many places.

3. Use t()

  $options = array('NONE' => '- Select a Profile -');

Throughout, any place you enter user-facing English text, you should wrap it in t(). This helps English folk too who just want to override the wording.

4. Declare the use of hooks

/* Define the menu link so that the setting page just set up is displayed. */
function civi_relate_menu() {
..

This was the only func I recognized as a Drupal hook, should probably have had "implementation of HOOK_menu()" or something. I'm not sure from looking at the code if any of the other functions are hooks or unique local functions or specific to the civicrm side of things.

5. CamelCase?

function civi_relate_civicrm_postProcess( $formName, &$form )

Didn't coder.module warn about this?
If it is due to the civicrm side of things, that's why a doc saying "this is a civicrm callback function" would be the thing here.

6. operators?

  if ( $formName == 'CRM_Profile_Form_Edit' and 
       $profile_id==$selected_profile and
       $mode==4) {

I don't think there's anything in the standards about this, but everywhere else in Drupal, we use && not and. Is there a reason you need to change the operator precedence here?
Also spacing.
Also camelCase. I'd forgive camelCase if it's a civicrm convention for that variable.

...
I'm unable to evaluate it for security WRT integrity of data and data access permissions, but it doesn't introduce anything blatantly unsafe like uploads, XSS or injection. So it's doing nothing wrong there. Which is to say, "probably safe".

fathershawn’s picture

StatusFileSize
new2.92 KB

Thank you so much for helping me learn to do things the Drupal way!

The CamelCase names are in fact CiviCRM conventions. I think I've addressed everything else and I've retested the module and it still works!

fathershawn’s picture

Status: Needs work » Needs review

Forgot to switch the status...

dgeilhufe@yahoo.com’s picture

Status: Needs review » Reviewed & tested by the community

Can't comment on the coding standards which seem to have already been resolved. I can confirm it installs and works as expected with CiviCRM.

avpaderno’s picture

Status: Reviewed & tested by the community » Needs review

Reviews are not supposed to check if the module installs, and if the module works as expected (in that case, reviews will become a debugging session, and that is not what we want).

I am setting the previous status, waiting for somebody to make a review of the code, and to confirm the previous issues have been resolved.

dman’s picture

Status: Needs review » Reviewed & tested by the community

I commented "I'm probably unable to judge the actual code going on here without going through a whole civicrm install, " above. So someone elses assertion that it does indeed work as expected is a constructive addition, thanks for that!

  1. fixed
  2. Better. A few columns seem indented by 7 spaces where 6 would be expected, but this doesn't effect the quality or layout. very minor - Not a blocker
  3. Fixed
  4. Fixed, but the exact layout of the /** comments */ is not quite correct doxygen yet. As far as documentation goes however, its adequate. minor - Not a blocker (as there is no doxygen for contrib available anyway)
  5. Good
  6. Fixed
avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, dman, for the confirmation.

Thank you for your contribution! I am going to update your account.
These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the dedicated reviewers as well.

fathershawn’s picture

Status: Fixed » Closed (fixed)

Project set up - thanks!

avpaderno’s picture

Component: Miscellaneous » new project application
Issue summary: View changes
avpaderno’s picture

Assigned: Unassigned » avpaderno
fathershawn’s picture

Bulk change? This issue has been closed for 8 years ;-)

avpaderno’s picture

I am giving credit to the users who participated and adding the default message with the useful links.