You are here

public static function LibraryItemHelper::findByBarcode in Library 8

Find by barcode.

Parameters

string $barcode: Barcode to search.

Return value

bool|LibraryItem Item or FALSE.

2 calls to LibraryItemHelper::findByBarcode()
LibraryCheckOutBulkForm::submitForm in src/Form/LibraryCheckOutBulkForm.php
Form submission handler.
LibraryCheckOutBulkForm::validateForm in src/Form/LibraryCheckOutBulkForm.php
Form validation handler.

File

src/Helper/LibraryItemHelper.php, line 23

Class

LibraryItemHelper
Helper class for static functions.

Namespace

Drupal\library\Helper

Code

public static function findByBarcode($barcode) {
  $items = [];
  $results = \Drupal::entityQuery('library_item')
    ->condition('barcode', $barcode)
    ->execute();
  foreach ($results as $result) {
    $items[] = LibraryItem::load($result);
  }
  if (count($items) == 1 && $items[0] instanceof LibraryItem) {
    return $items[0];
  }
  else {
    return FALSE;
  }
}