You are here

function _crm_core_user_sync_get_entity_id_from_text in CRM Core 8.2

Same name and namespace in other branches
  1. 7 modules/crm_core_user_sync/crm_core_user_sync.module \_crm_core_user_sync_get_entity_id_from_text()

Retrieves entity object from a text in a format like 'Title [id_key: 123]'.

2 calls to _crm_core_user_sync_get_entity_id_from_text()
crm_core_user_sync_edit_relation_form_submit in modules/crm_core_user_sync/crm_core_user_sync.admin.inc
Submit callback on edit form.
crm_core_user_sync_edit_relation_form_validate in modules/crm_core_user_sync/crm_core_user_sync.admin.inc
Validate callback on edit form.

File

modules/crm_core_user_sync/crm_core_user_sync.module, line 562

Code

function _crm_core_user_sync_get_entity_id_from_text($text, $entity_type) {
  $entity_info = entity_get_info($entity_type);
  if (empty($entity_info) || empty($entity_info['entity keys']['id'])) {
    return FALSE;
  }
  $id_key = $entity_info['entity keys']['id'];
  $matches = array();
  preg_match('/\\[' . $id_key . ':([0-9]+)\\]/', $text, $matches);
  if (!array_key_exists(1, $matches) || !is_numeric($matches[1])) {
    return FALSE;
  }
  $entities = entity_load($entity_type, array(
    $matches[1],
  ));
  if (empty($entities)) {
    return FALSE;
  }
  return $entities[$matches[1]];
}