You are here

function biblio_field_instances_missing in Bibliography Module 7.2

Determines if the field instances for a publication type have been created. Used to decide whether or not to run biblio_add_field_instances when admin/content/biblio/add is accessed for the first time for a specific publication type.

Parameters

string $bundle:

string $entity_type biblio, biblio_contributor, etc...:

Return value

boolean Whether or not biblio's required field instances are indeed missing.

3 calls to biblio_field_instances_missing()
biblio_check_instances in includes/biblio.fields.inc
biblio_form in ./biblio.module
Displays the Add/Edit form for a biblio entity
biblio_overview_types in includes/biblio.admin.inc
hook_menu callback function for admin/config/content/biblio/publication-types

File

includes/biblio.fields.inc, line 156

Code

function biblio_field_instances_missing($bundle, $entity_type = 'biblio') {
  $file = drupal_get_path('module', 'biblio') . '/misc/default_field_pubtype_map.json';
  $default_field_pubtype_map = json_decode(file_get_contents($file), TRUE);
  $default_instances = $default_field_pubtype_map[$entity_type][$bundle];

  // Field instances that already exist. There could be user-created field
  // instances here, so we can't assume that existing fields means we shouldn't
  // add our default field instances.
  $existing_instances = field_info_instances($entity_type, $bundle);
  if (empty($existing_instances)) {

    // If no instances exist, we definitely need to add the defaults
    return TRUE;
  }
  foreach ($default_instances as $field => $label) {

    // If field name isn't already in the list of existing field instances
    if (!isset($existing_instances[$field])) {

      // As soon as we find one default instance that doesn't already exist, we
      // know that all defaults need to be added
      return TRUE;
    }
  }

  // Every default field instance already exists for the given publication type
  return FALSE;
}