You are here

function bat_unit_ids in Booking and Availability Management Tools for Drupal 8

Same name and namespace in other branches
  1. 7 modules/bat_unit/bat_unit.module \bat_unit_ids()

Gets a list of Units keyed by id and name in value.

File

modules/bat_unit/bat_unit.module, line 430
Manage units - Units are things that can be booked for some period of time. (e.g. rooms - but also villas bungalows, cars, drills, you-get-the-idea etc.)

Code

function bat_unit_ids($bundle = '') {
  $units = [];
  $query = \Drupal::entityQuery('bat_unit');
  if ($bundle != '') {
    $query
      ->condition('type', $bundle);
  }
  $result = $query
    ->execute();
  if (count($result) > 0) {
    $entities = Unit::loadMultiple(array_keys($result['bat_unit']));
    foreach ($entities as $unit) {
      $units[$unit
        ->id()] = $unit
        ->label();
    }
  }
  return $units;
}