You are here

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

Returns the event value

Return value

int|FALSE

File

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

Class

Event
Defines the Event entity.

Namespace

Drupal\bat_event\Entity

Code

public function getEventValue() {
  $langcode = $this->defaultLangcode;
  if ($field = $this
    ->getEventValueField()) {
    $field_info = FieldStorageConfig::loadByName('bat_event', $field);
    $values = $this
      ->getTranslation($langcode)
      ->get($field)
      ->getValue();
    if (!empty($values)) {
      if ($field_info
        ->getType() == 'entity_reference') {
        return $values[0]['target_id'];
      }
      elseif ($field_info
        ->getType() == 'commerce_price') {
        return $values[0]['number'];
      }
      elseif ($field_info
        ->getType() == 'text' || $field_info
        ->getType() == 'string' || $field_info
        ->getType() == 'number_integer') {
        return $values[0]['value'];
      }
    }
    else {
      return FALSE;
    }
  }
}