You are here

public function ItemHistory::show in Library 8

Show item history.

Parameters

\Drupal\node\NodeInterface $node: Node to process.

Return value

array Returns the markup to render.

1 string reference to 'ItemHistory::show'
library.routing.yml in ./library.routing.yml
library.routing.yml

File

src/Controller/ItemHistory.php, line 28

Class

ItemHistory
Item history controller.

Namespace

Drupal\library\Controller

Code

public function show(NodeInterface $node) {
  $output = [];
  $fields = $node
    ->getFieldDefinitions();

  /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields */
  foreach ($fields as $field) {
    if ($field
      ->getType() == 'library_item_field_type') {
      foreach ($node
        ->get($field
        ->getName())
        ->getValue() as $item) {
        if (isset($item['target_id'])) {
          $itemEntity = LibraryItem::load($item['target_id']);
          if ($itemEntity) {
            $output[] = $this
              ->showHistoryForItem($itemEntity);
          }
        }
      }
    }
  }
  if (empty($output)) {
    $output = [
      '#markup' => $this
        ->t('No transactions found.'),
    ];
  }
  return $output;
}