function bat_booking_add_end_date_field in Booking and Availability Management Tools for Drupal 8
Same name and namespace in other branches
- 7 modules/bat_booking/bat_booking.module \bat_booking_add_end_date_field()
Add "End Date" field.
1 call to bat_booking_add_end_date_field()
- bat_booking_entity_insert in modules/
bat_booking/ bat_booking.module - Implements hook_entity_insert().
File
- modules/
bat_booking/ bat_booking.module, line 262
Code
function bat_booking_add_end_date_field($bundle) {
$field_name = 'booking_end_date';
$field_storage = FieldStorageConfig::loadByName('bat_booking', $field_name);
$field = FieldConfig::loadByName('bat_booking', $bundle, $field_name);
if (empty($field_storage)) {
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'bat_booking',
'type' => 'datetime',
'cardinality' => 1,
'locked' => 1,
'settings' => [
'cache_count' => 4,
'cache_enabled' => 0,
'granularity' => [
'day' => 'day',
'hour' => 'hour',
'minute' => 'minute',
'month' => 'month',
'second' => 0,
'year' => 'year',
],
'timezone_db' => '',
'todate' => '',
'tz_handling' => 'none',
],
]);
$field_storage
->save();
}
if (empty($field)) {
$field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'bat_booking',
'label' => 'End Date',
'bundle' => $bundle,
'required' => FALSE,
'settings' => [
'default_value' => 'blank',
'default_value2' => 'same',
'default_value_code' => '',
'default_value_code2' => '',
'user_register_form' => FALSE,
],
]);
$field
->save();
}
}