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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • show profile only for contact subtype (was:hook_civicrm_buildUFGroupsForModule()
Pages: [1]

Author Topic: show profile only for contact subtype (was:hook_civicrm_buildUFGroupsForModule()  (Read 1088 times)

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
show profile only for contact subtype (was:hook_civicrm_buildUFGroupsForModule()
May 28, 2013, 09:58:05 am
I've got two custom profiles that are used for "Standalone Form or Directory, Search Views, View/Edit Drupal User Account" - in other words, they appear on the Drupal 'Edit account' page as tabs.  But I want the 'Youth' profile to only appear for users with the contact sub-type of 'Youth' and the 'Leader' profile to only appear for users with the contact sub-type of 'Leader'.

I'm experimenting with the undocumented hook_civicrm_buildUFGroupsForModule() (see http://issues.civicrm.org/jira/browse/CRM-8897) that Lobo pointed me to.  This hook returns the profiles to be displayed in an array. I check the user sub-type and unset array elements if the associated sub-type is not represented. What's odd is that even if the associated sub-type exists - and the array element is not unset - the profile *may* not appear (and sometimes it does appear).

I think this may be a caching issue, though running `drush cc all` and `rm -rf files/civicrm/templates_c/*` does not always get the profile tio return.  Any ideas here?

Update: attached example code.
« Last Edit: July 02, 2013, 08:24:14 pm by fen »

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: hook_civicrm_buildUFGroupsForModule()
June 02, 2013, 01:21:54 pm
If I disable and then re-enable the module containing the hook, the correct profiles appear.  But any change to the Contact sub-type is not noticed (tho I see from watchdog() debug statements the hook is being called).

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_buildUFGroupsForModule()
June 02, 2013, 08:38:40 pm
not sure if it will help, but have tried clearing civicrm cache?

Kurund
Found this reply helpful? Support CiviCRM

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: hook_civicrm_buildUFGroupsForModule()
June 02, 2013, 09:17:58 pm
I have been regularly (as part of testing) running `drush cc all` (running drush 5.9) and `rm -rf files/civicrm/templates_c/*`.  (But thanks for the suggestion.)

It appears hook_civicrm_buildUFGroupsForModule() is called for every profile group, but having difficulty following the code.

What's odd is that if I print_r($ufGroups) in my hook, all profile groups are always there on entry.  The hook (may) unset one or two, but once unset, they stay unset (even though on the next invocation, all profile groups are there again).

Update: The profile menus (e.g., on the Drupal 'Edit Account' page) will continue to be hidden after being unset once even after reset (and even though they appear in $ufGroups on re-entry to the function).  They won't re-appear until I disable the module.  (Clearing cache and removing files/civicrm/templates_c/* has no effect.)
« Last Edit: July 02, 2013, 12:16:17 pm by fen »

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: hook_civicrm_buildUFGroupsForModule()
July 02, 2013, 12:19:57 pm
Quote from: Kurund Jalmi on June 02, 2013, 08:38:40 pm
not sure if it will help, but have tried clearing civicrm cache?

Kurund
Yes - I'm running drush 5.9 which clears the civicrm cache when 'drush cc all' is invoked.

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: show profile only for contact subtype (was:hook_civicrm_buildUFGroupsForModule()
July 02, 2013, 08:31:31 pm
There's code in buildQuickForm() that can prevent the form content of a profile from being displayed (returning the message: "This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.") but this doesn't always work.

While not displaying even a subtype profile's title is preferable (in the case the current contact doesn't match that subtype) fixing the broken code in CRM/Profile/Form.php (around line #615).

I'll take a look at both, but could use some help...

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: show profile only for contact subtype (was:hook_civicrm_buildUFGroupsForModule()
July 16, 2013, 02:05:47 pm
OK, everything works, but sometimes (I hate intermittent bugs!) the 'Youth' or 'Leader' CiviCRM profiles will (or will not) appear in the user/##/edit menu when it is revealed (or hidden) by hook_civicrm_buildUFGroupsForModule().

I can get it to reliably show (or disappear) after running 'drush cc all' so this definitely is a caching issue.

The question I have now is: how do I clear the cache (or mark the profile 'dirty') when the hook makes its changes?

(Once I get this working, I will document my usage of this hook as requested by Lobo.)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • show profile only for contact subtype (was:hook_civicrm_buildUFGroupsForModule()

This forum was archived on 2017-11-26.