You are here

public function Event::getEventLabel in Booking and Availability Management Tools for Drupal 8

Returns the event label.

Return value

string|FALSE

File

modules/bat_event/src/Entity/Event.php, line 440
Contains \Drupal\bat_event\Entity\Event.

Class

Event
Defines the Event entity.

Namespace

Drupal\bat_event\Entity

Code

public function getEventLabel() {
  $type_bundle = bat_event_type_load($this
    ->bundle());
  if (!empty($type_bundle->default_event_label_field_name)) {
    $field_name = $type_bundle->default_event_label_field_name;
    $field = $this
      ->get($field_name);
    if ($field
      ->getFieldDefinition()
      ->getType() == 'entity_reference') {
      if ($entity = $field->entity) {
        return $entity
          ->label();
      }
    }
    else {
      return $field->value;
    }
  }
  return FALSE;
}