You are here

function _pmpermission_get_field_names_per_field_type in Drupal PM (Project Management) 7.2

Get a list of field names matching a specific type.

This function works reliably for "entityreference" only.

Parameters

string $type: Type of field e.g. entityreference.

Return value

array $field_names Field names categorized by target entity type.

1 call to _pmpermission_get_field_names_per_field_type()
pmpermission_admin in pmpermission/pmpermission.module
Admin settings form.

File

pmpermission/pmpermission.module, line 173
Main module file for the pmpermission module.

Code

function _pmpermission_get_field_names_per_field_type($type, $entity_type = NULL, $bundle_name = NULL) {
  $field_names = array(
    'user' => array(
      '' => t('- None -'),
    ),
    'node' => array(
      '' => t('- None -'),
    ),
  );

  // Get all entityreference field names.
  $query = db_select('field_config', 'f');
  $query
    ->fields('f', array(
    'field_name',
  ));
  $query
    ->condition('f.type', $type);
  $query
    ->distinct();
  $rows = $query
    ->execute();
  foreach ($rows as $row) {
    $field_name = $row->field_name;
    if ($bundle_name and !field_info_instance($entity_type, $field_name, $bundle_name)) {
      continue;
    }
    $field_info = field_info_field($field_name);
    if (isset($field_info['settings']['target_type'])) {

      // Code...
      $field_names[$field_info['settings']['target_type']][$field_name] = $field_name;
    }
  }
  return $field_names;
}