You are here

public static function LibraryItemFieldWidget::findHighestBarcode in Library 8

Find the highest barcode number.

Fetches default if not in database.

Return value

int Barcode.

1 call to LibraryItemFieldWidget::findHighestBarcode()
WidgetSubmit::processLibraryItems in src/WidgetSubmit.php
Process library items.

File

src/Plugin/Field/FieldWidget/LibraryItemFieldWidget.php, line 199

Class

LibraryItemFieldWidget
Plugin implementation of the 'library_item_field_widget' widget.

Namespace

Drupal\library\Plugin\Field\FieldWidget

Code

public static function findHighestBarcode() {
  $databaseValue = NULL;
  $results = \Drupal::EntityQuery('library_item')
    ->sort('barcode', 'DESC')
    ->range(0, 1)
    ->execute();
  foreach ($results as $item) {
    $entity = LibraryItem::load($item);
    $databaseValue = $entity
      ->get('barcode')->value;
  }
  if ($databaseValue && $databaseValue > 1) {
    return $databaseValue;
  }
  else {
    return \Drupal::config('library.settings')
      ->get('barcode_starting_point');
  }
}