You are here

function phonefield_get_entity_id in Phone Field 7

Helper function.

Get corresponding entity_id and bundle.

Parameters

string $field: The field to look up.

string $value: The value to look up.

Return value

array An array with the fields 'entity_id' and 'bundle' (or FALSE if no result).

File

./phonefield.module, line 615
Hooks for a module that defines a simple phone number field type.

Code

function phonefield_get_entity_id($field, $value) {
  $normalized = phonefield_normalize($value, FALSE);

  // The $field param is used to derive various table and field names, but in
  // each case the Database API automatically escapes these values. Note that
  // the API does not do this for all arguments.
  // @see: https://www.drupal.org/project/drupal/issues/2626026
  $query = db_select('field_data_' . $field, 'fdf');
  $query
    ->fields('fdf', array(
    'entity_id',
    'bundle',
    $field . '_linklabel',
  ));
  $query
    ->condition('fdf.' . $field . '_normalized', $normalized);
  $eid = $query
    ->execute()
    ->fetchAssoc();
  return $eid;
}