You are here

function biblio_create in Bibliography Module 7.2

Same name and namespace in other branches
  1. 7.3 biblio.module \biblio_create()

Create a biblio entity object

Parameters

string $publication_type: The publication type of the biblio to be created (bundle)

array $values: An associative array of any additional values to be set when creating this entity. These values will be carried throughout the biblio object's life. Example: $values['language'] => 'en';

Return value

object The biblio object, with default values.

6 calls to biblio_create()
biblio_form in ./biblio.module
Displays the Add/Edit form for a biblio entity
biblio_pm_form_biblio_form_submit in modules/pubmed/biblio_pm.module
biblio_ris_form_biblio_form_submit in modules/RIS/biblio_ris.module
_biblio_bibtex_import in modules/bibtexParse/biblio_bibtex.module
_biblio_pm_create_node_from_xml in modules/pubmed/biblio_pm.module

... See full list

File

./biblio.module, line 2826

Code

function biblio_create($publication_type, $values = array()) {
  module_load_include('inc', 'biblio', 'includes/biblio.fields');
  biblio_check_instances($publication_type);
  $values['publication_type'] = $publication_type;
  $field_values = array();
  foreach ($values as $property => $value) {
    if (biblio_is_field_instance($property, 'biblio', $publication_type)) {

      // We'll let the metadata wrapper handle field data
      $field_values[$property] = $value;
    }
    else {

      // Set all aother properties during entity creation
      $initial_values[$property] = $value;
    }
  }
  $biblio = entity_create('biblio', $initial_values);
  $wrapper = biblio_wrapper($biblio);
  $property_info = $wrapper
    ->getPropertyInfo();
  foreach ($field_values as $property => $value) {

    // 'text_formatted' field types have an extra layer of properties
    // see http://drupal.org/node/1396046
    $value_prop = isset($property_info[$property]['property info']['value']);
    if ($value_prop) {
      $wrapper->{$property} = array(
        'value' => $value,
      );
    }
    else {

      // Most normal fields
      $wrapper->{$property}
        ->set($value);
    }
  }
  return $biblio;
}