function rooms_unit_entity_insert in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Implements hook_entity_insert().
File
- modules/
rooms_unit/ rooms_unit.module, line 354 - Manage units - Units are things that can be booked on a nightly basis (e.g. rooms - but also villas bungalows, etc).
Code
function rooms_unit_entity_insert($entity, $type) {
if ($type == 'rooms_unit_type') {
// Create field ('rooms_booking_unit_options') if not exist.
if (field_read_field('rooms_booking_unit_options') === FALSE) {
$field = array(
'field_name' => 'rooms_booking_unit_options',
'type' => 'rooms_options',
'cardinality' => -1,
);
field_create_field($field);
}
if (field_read_instance('rooms_unit', 'rooms_booking_unit_options', $entity->type) === FALSE) {
// Create the instance on the bundle.
$instance = array(
'field_name' => 'rooms_booking_unit_options',
'entity_type' => 'rooms_unit',
'label' => 'Options',
'bundle' => $entity->type,
'required' => FALSE,
'widget' => array(
'type' => 'rooms_options',
),
);
field_create_instance($instance);
}
}
}