You are here

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

Return the event label.

Overrides Entity::defaultLabel

File

modules/bat_event/bat_event.module, line 1094
Manage Events - Events store the EventValue of a Unit over a period of time.

Class

BatEvent
The class used for Event entities.

Code

protected function defaultLabel() {

  // If the user has configured a field to store the event name, return that
  // field's value.
  $event_type = bat_event_type_load($this->type);
  if (isset($event_type->default_event_label_field_name) && $event_type->default_event_label_field_name != '') {
    $event_wrapper = entity_metadata_wrapper('bat_event', $this);
    $value = $event_wrapper->{$event_type->default_event_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($event_type->default_event_label_field_name);

      // TODO: Support other field types?
      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 the state name for the event, if
  // it has a state set.
  if ($state_info = bat_event_load_state($this
    ->getEventValue())) {
    return $state_info['label'];
  }
  return '';
}