You are here

protected function Invoice::getItemIndex in Commerce Invoice 8.2

Gets the index of the given invoice item.

Parameters

\Drupal\commerce_invoice\Entity\InvoiceItemInterface $invoice_item: The invoice item.

Return value

int|bool The index of the given invoice item, or FALSE if not found.

2 calls to Invoice::getItemIndex()
Invoice::hasItem in src/Entity/Invoice.php
Checks whether the invoice has a given invoice item.
Invoice::removeItem in src/Entity/Invoice.php
Removes an invoice item.

File

src/Entity/Invoice.php, line 287

Class

Invoice
Defines the invoice entity class.

Namespace

Drupal\commerce_invoice\Entity

Code

protected function getItemIndex(InvoiceItemInterface $invoice_item) {
  $values = $this
    ->get('invoice_items')
    ->getValue();
  $invoice_item_ids = array_map(function ($value) {
    return $value['target_id'];
  }, $values);
  return array_search($invoice_item
    ->id(), $invoice_item_ids);
}