function rng_add_event_field_storage in RNG - Events and Registrations 3.x
Same name and namespace in other branches
- 8.2 rng.field.defaults.inc \rng_add_event_field_storage()
- 8 rng.field.defaults.inc \rng_add_event_field_storage()
2 calls to rng_add_event_field_storage()
- EventTypeFieldMappingForm::createField in src/
Form/ EventTypeFieldMappingForm.php - Form submission function to respond to the create field button.
- RngEventType::postSave in src/
Entity/ RngEventType.php - Acts on a saved entity before the insert or update hook is invoked.
File
- ./
rng.field.defaults.inc, line 19 - Creates field config if they do not exist.
Code
function rng_add_event_field_storage($field_name, $entity_type) {
if ($field_storage = FieldStorageConfig::loadByName($entity_type, $field_name)) {
return NULL;
}
$definition = [];
switch ($field_name) {
case EventManagerInterface::FIELD_REGISTRATION_TYPE:
$definition = [
'type' => 'entity_reference',
'settings' => [
'target_type' => 'registration_type',
],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
];
break;
case EventManagerInterface::FIELD_REGISTRATION_GROUPS:
$definition = [
'type' => 'entity_reference',
'settings' => [
'target_type' => 'registration_group',
],
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
];
break;
case EventManagerInterface::FIELD_WAIT_LIST:
case EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS:
case EventManagerInterface::FIELD_STATUS:
case EventManagerInterface::FIELD_CAPACITY_CONFIRMED_ONLY:
$definition = [
'type' => 'boolean',
];
break;
case EventManagerInterface::FIELD_REGISTRANTS_CAPACITY:
$definition = [
'type' => 'integer',
];
break;
case EventManagerInterface::FIELD_EMAIL_REPLY_TO:
$definition = [
'type' => 'email',
];
break;
}
if (!empty($definition)) {
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => $entity_type,
] + $definition);
$field_storage
->save();
}
}