You are here

public static function LibraryItemHelper::updateItemAvailability in Library 8

Update item availability.

Parameters

int $item: Item ID.

string $action: Action name to perform, e.g. 'check_in'.

2 calls to LibraryItemHelper::updateItemAvailability()
LibraryCheckOutBulkForm::processTransaction in src/Form/LibraryCheckOutBulkForm.php
Process a transaction.
LibraryCheckoutForm::submitForm in src/Form/LibraryCheckoutForm.php
Form submission handler.

File

src/Helper/LibraryItemHelper.php, line 47

Class

LibraryItemHelper
Helper class for static functions.

Namespace

Drupal\library\Helper

Code

public static function updateItemAvailability($item, $action) {
  $action = LibraryAction::load($action);
  $item = LibraryItem::load($item);
  if ($action
    ->action() == LibraryAction::CHANGE_TO_UNAVAILABLE) {
    $item
      ->set('library_status', LibraryItem::ITEM_UNAVAILABLE);
    $item
      ->save();
  }
  elseif ($action
    ->action() == LibraryAction::CHANGE_TO_AVAILABLE) {
    $item
      ->set('library_status', LibraryItem::ITEM_AVAILABLE);
    $item
      ->save();
  }
}