Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#752 Add cid parameter when loading custom data via backend f… #15012

Merged
merged 1 commit into from
Aug 13, 2019

Conversation

seamuslee001
Copy link
Contributor

…orms so that hooks can modifiy based on contact_id being viewed

Overview

This picks up work by @sluc23 from #13191, this adds the cid parameter into customdata urls as per discussion in lab

Before

no cid parameter

After

cid parameter

Technical Details

If the PR introduces noteworthy technical changes, please describe them here. Provide code snippets if necessary

Comments

ping @mattwire @eileenmcnaughton @sluc23

@civibot
Copy link

civibot bot commented Aug 11, 2019

(Standard links)

@civibot civibot bot added the master label Aug 11, 2019
@seamuslee001 seamuslee001 force-pushed the dev_core_752 branch 2 times, most recently from 7a9ae68 to 3320adf Compare August 11, 2019 09:25
@eileenmcnaughton
Copy link
Contributor

I feel like $contactID is a more common smarty variable

@seamuslee001
Copy link
Contributor Author

Probably i guess i was just riffing based on the lab ticket

…orms so that hooks can modifiy based on contact_id being viewed

Add in handling for cid not being set

Fix assign of cid and switch to using javascript if rather than smarty
@sluc23
Copy link
Contributor

sluc23 commented Aug 12, 2019

looking forwards to have this merged, tx @seamuslee001 !
This will make our life easier when coding custom field's related logic

@eileenmcnaughton
Copy link
Contributor

Putting aside my preference for meaningful variable / parameter names - I'm OK to merge this if you review it @sluc23

@sluc23
Copy link
Contributor

sluc23 commented Aug 13, 2019

yes, it works.. this hook will set contactID as default value in Activity's custom field (simplest example, then you can use contactID to calculate/search other values) .
Previously some jQuery / $_POST magic was needed..

function testhook_civicrm_buildForm($formName, &$form) {
  if ($formName == 'CRM_Custom_Form_CustomDataByType') {
    if ($form->getAction() == CRM_Core_Action::ADD) {
      foreach ($form->_elements as $index => &$element) {
        if ($element->_attributes['name'] == 'custom_1_-1') {
          // Set Contact ID as default value to a custom field
          $element->_attributes['value'] = $form->getVar('_contactID');
        }
      }
    }
  }
}

Copy link
Contributor

@sluc23 sluc23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested!

@eileenmcnaughton
Copy link
Contributor

Merging based on @sluc23 review

@sluc, @seamuslee001 -is there something here that could be documented?

@eileenmcnaughton eileenmcnaughton merged commit 00f497d into civicrm:master Aug 13, 2019
@sluc23
Copy link
Contributor

sluc23 commented Aug 13, 2019

@eileenmcnaughton do you think is a good idea to add the hook sample i've posted in the hook_civicrm_buildForm documentation?

@sluc23
Copy link
Contributor

sluc23 commented Aug 13, 2019

only issue, so far, is that only works for Activities, until we spread this for the rest of entities.. I will doing some PRs to extend it for the rest..

@eileenmcnaughton eileenmcnaughton deleted the dev_core_752 branch August 13, 2019 10:47
@eileenmcnaughton
Copy link
Contributor

@MegaphoneJon any opinions about where / how to document?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants