function registration_registrant_create in Entity Registration 8.2
Same name and namespace in other branches
- 7.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 1635
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 = \Drupal::entityManager()
->getDefinition($registrant_entity_type);
if (!empty($info['entity keys']['bundle'])) {
$values[$info['entity keys']['bundle']] = $registration_type->registrant_bundle;
}
$registrant = \Drupal::entityManager()
->getStorage($registrant_entity_type)
->create($values);
if ($mail) {
if ($email_field_col) {
$registrant->{$email_property} = array(
\Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED => array(
array(
$email_field_col => $mail,
),
),
);
}
else {
$registrant->{$email_property} = $mail;
}
}
return entity_metadata_wrapper($registrant_entity_type, $registrant);
}