You are here

function rooms_unit_install_create_options_field in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Creates rooms_booking_unit_options field for bookable unit type entities.

2 calls to rooms_unit_install_create_options_field()
rooms_unit_install in modules/rooms_unit/rooms_unit.install
Implements hook_install().
rooms_unit_update_7011 in modules/rooms_unit/rooms_unit.install
Adds options field to Rooms unit type entity.

File

modules/rooms_unit/rooms_unit.install, line 266
Sets up the base table for our entity and a table to store information about the entity types.

Code

function rooms_unit_install_create_options_field() {
  if (field_read_field('rooms_booking_unit_options') === FALSE) {

    // Create field 'rooms_booking_unit_options'.
    $field = array(
      'field_name' => 'rooms_booking_unit_options',
      'type' => 'rooms_options',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    );
    field_create_field($field);
  }
  cache_clear_all();
  field_cache_clear();

  // Attach field 'rooms_booking_unit_options' to instances of rooms_unit_type.
  if (field_info_instance('rooms_unit_type', 'rooms_booking_unit_options', 'rooms_unit_type') === NULL) {
    $instance = array(
      'field_name' => 'rooms_booking_unit_options',
      'entity_type' => 'rooms_unit_type',
      'label' => 'Options',
      'bundle' => 'rooms_unit_type',
      'required' => FALSE,
      'widget' => array(
        'type' => 'rooms_options',
      ),
    );
    field_create_instance($instance);
  }
}