You are here

private function LibraryItemFieldFormatter::renderEditAction in Library 8

Render the edit action.

Separate, because conditional on existing transactions.

Parameters

int $item: Item by ID.

Return value

array Markup to render.

1 call to LibraryItemFieldFormatter::renderEditAction()
LibraryItemFieldFormatter::getActions in src/Plugin/Field/FieldFormatter/LibraryItemFieldFormatter.php
Get actions.

File

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

Class

LibraryItemFieldFormatter
Plugin implementation of the 'library_item_field_formatter' formatter.

Namespace

Drupal\library\Plugin\Field\FieldFormatter

Code

private function renderEditAction($item) : array {
  $output = [];
  $itemEntity = LibraryItem::load($item);
  if ($itemEntity) {
    $transaction = $itemEntity
      ->getLatestTransaction();
    if (!empty($transaction)) {
      $output = [
        'title' => 'Edit note',
        'url' => Url::fromRoute('library.edit_transaction', [
          'transaction' => array_shift($transaction),
        ]),
      ];
    }
  }
  return $output;
}