You are here

protected function LibraryItemFieldFormatter::getActions in Library 8

Get actions.

Parameters

int $in_circulation: Circulation parameter.

int $status: Status parameter.

int $item: Item.

Return value

array Actions.

1 call to LibraryItemFieldFormatter::getActions()
LibraryItemFieldFormatter::viewElements in src/Plugin/Field/FieldFormatter/LibraryItemFieldFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/LibraryItemFieldFormatter.php, line 101

Class

LibraryItemFieldFormatter
Plugin implementation of the 'library_item_field_formatter' formatter.

Namespace

Drupal\library\Plugin\Field\FieldFormatter

Code

protected function getActions($in_circulation, $status, $item) : array {
  $actions = [];
  if ($in_circulation == LibraryItemInterface::IN_CIRCULATION) {
    if ($status == LibraryItemInterface::ITEM_AVAILABLE) {
      $availableActions = \Drupal::entityQuery('library_action')
        ->condition('action', LibraryAction::CHANGE_TO_UNAVAILABLE)
        ->execute();
      $actions = $this
        ->renderAction($availableActions, $item);
    }
    else {
      $query = \Drupal::entityQuery('library_action');
      $group = $query
        ->orConditionGroup()
        ->condition('action', LibraryAction::CHANGE_TO_AVAILABLE)
        ->condition('action', LibraryAction::NO_CHANGE);
      $availableActions = $query
        ->condition($group)
        ->execute();
      $actions = $this
        ->renderAction($availableActions, $item);
      $actions['edit'] = $this
        ->renderEditAction($item);
    }
  }
  return $actions;
}