You are here

function registration_registrant_create in Entity Registration 7.2

Same name and namespace in other branches
  1. 8.2 registration.module \registration_registrant_create()

Create a new registrant object for a given registration type. Optionally set registrant email.

Parameters

RegistrationType $registration_type:

string $mail:

Return value

object

1 call to registration_registrant_create()
registration_form_submit in includes/registration.forms.inc
Submit callback for registration_form().

File

./registration.module, line 1667

Code

function registration_registrant_create($registration_type, $mail = NULL) {
  $registrant_entity_type = $registration_type->registrant_entity_type;
  $property_parts = explode(':', $registration_type->registrant_email_property);
  $email_property = $property_parts[0];
  $email_field_col = isset($property_parts[1]) ? $property_parts[1] : NULL;
  $values = array();
  $info = entity_get_info($registrant_entity_type);
  if (!empty($info['entity keys']['bundle'])) {
    $values[$info['entity keys']['bundle']] = $registration_type->registrant_bundle;
  }
  $registrant = entity_create($registrant_entity_type, $values);
  if ($mail) {
    if ($email_field_col) {
      $registrant->{$email_property} = array(
        LANGUAGE_NONE => array(
          array(
            $email_field_col => $mail,
          ),
        ),
      );
    }
    else {
      $registrant->{$email_property} = $mail;
    }
  }
  return entity_metadata_wrapper($registrant_entity_type, $registrant);
}