You are here

protected function BatBooking::defaultLabel in Booking and Availability Management Tools for Drupal 7

Defines the entity label if the 'entity_class_label' callback is used.

Specify 'entity_class_label' as 'label callback' in hook_entity_info() to let the entity label point to this method. Override this in order to implement a custom default label.

Overrides Entity::defaultLabel

File

modules/bat_booking/bat_booking.module, line 203

Class

BatBooking
The class used for booking entities.

Code

protected function defaultLabel() {

  // If the user has configured a field to store the booking name, return that
  // field's value.
  $booking_type = bat_booking_type_load($this->type);
  if (isset($booking_type->default_booking_label_field_name) && $booking_type->default_booking_label_field_name != '') {
    $event_wrapper = entity_metadata_wrapper('bat_booking', $this);
    $value = $event_wrapper->{$booking_type->default_booking_label_field_name}
      ->value(array(
      'sanitize' => TRUE,
    ));

    // Handle entity reference fields - if this is an object, return its
    // label.
    if (is_object($value)) {
      $field_info = field_info_field($booking_type->default_booking_label_field_name);
      if ($field_info['type'] == 'entityreference') {
        return entity_label($field_info['settings']['target_type'], $value);
      }
    }
    elseif ($value) {
      return $value;
    }
  }

  // If we got this far, a field is not configured, we don't support its
  // type, or the field is empty. Return booking label.
  return $this->label;
}