Commit 692dedc7 authored by RoSk0's avatar RoSk0

Added function to get primary field value.

parent 02af6413
......@@ -198,3 +198,36 @@ function crm_core_contact_ui_save_contact_button_name($contact_type) {
'!contact_type' => crm_core_contact_type_get_name($contact_type)
));
}
/**
* Get CRM Core Contact primary field value.
*
* @param CRMCoreContactEntity $contact
* CRM Core Contact.
* @param string $primary_field
* Primary field name.
*
* @return string
*/
function crm_core_contact_get_primary_field_value(CRMCoreContactEntity $contact, $primary_field) {
$contactType = crm_core_contact_type_load($contact->type);
$field = empty($contactType->primary_fields[$primary_field]) ? '' : $contactType->primary_fields[$primary_field];
$field_value = '';
if (empty($field)) {
if(user_access('configure petition email settings')){
// Alert privileged users that we can't send emails.
// Check that user has access to configure crm_core_contact.
$message = "There are no primary contact fields configured for contacts of type @contact_type. The petitions feature cannot send thank-you emails "
. "or targeted emails to contacts unless primary fields are configured for this contact type. Goto admin/settings/crm-core/contact-types, and click the ."
. "edit link to configure primary contact fields for this contact type in order to enable emails.";
drupal_set_message(t($message, array('@contact_type' => $contactType)), 'warning');
// @TODO: should this also go into watchdog?
}
}
else {
$contact_wrapper = entity_metadata_wrapper('crm_core_contact', $contact);
$field_value = $contact_wrapper->{$field}->value();
}
return $field_value;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment