You are here

function bat_booking_add_event_reference_field in Booking and Availability Management Tools for Drupal 7

Same name and namespace in other branches
  1. 8 modules/bat_booking/bat_booking.module \bat_booking_add_event_reference_field()

Add "Event" reference field.

1 call to bat_booking_add_event_reference_field()
bat_booking_entity_insert in modules/bat_booking/bat_booking.module
Implements hook_entity_insert().

File

modules/bat_booking/bat_booking.module, line 644

Code

function bat_booking_add_event_reference_field($type_bundle) {
  field_info_cache_clear();

  // "booking_event_reference" field.
  if (field_read_field('booking_event_reference') === FALSE) {
    $field = array(
      'field_name' => 'booking_event_reference',
      'type' => 'entityreference',
      'cardinality' => 1,
      'locked' => 1,
      'settings' => array(
        'target_type' => 'bat_event',
      ),
    );
    field_create_field($field);
  }
  field_cache_clear();

  // "booking_event_reference" field instance.
  if (field_read_instance('bat_booking', 'booking_event_reference', $type_bundle) === FALSE) {
    $instance = array(
      'field_name' => 'booking_event_reference',
      'entity_type' => 'bat_booking',
      'label' => 'Event',
      'bundle' => $type_bundle,
      'required' => FALSE,
      'widget' => array(
        'type' => 'entityreference_autocomplete',
      ),
    );
    field_create_instance($instance);
  }
}