You are here

public static function LibraryItemHelper::computeDueDate in Library 8

Compute the due date.

Fetches due date from field definition in content type.

Parameters

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

int $nid: Node ID.

Return value

int Due date timestamp.

2 calls to LibraryItemHelper::computeDueDate()
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 73

Class

LibraryItemHelper
Helper class for static functions.

Namespace

Drupal\library\Helper

Code

public static function computeDueDate($action, $nid) {
  $action = LibraryAction::load($action);
  if ($action
    ->action() != LibraryAction::CHANGE_TO_AVAILABLE) {
    $due = 30;
    $node = Node::load($nid);
    $bundle_fields = \Drupal::getContainer()
      ->get('entity_field.manager')
      ->getFieldDefinitions('node', $node
      ->getType());
    foreach ($bundle_fields as $field) {
      if ($field
        ->getType() == 'library_item_field_type') {
        $due = $field
          ->getSetting('due_date');
      }
    }
    $due = strtotime('today') + 86400 * $due;
  }
  else {
    $due = 0;
  }
  return $due;
}