You are here

protected function Wishlist::getItemIndex in Commerce Wishlist 8.3

Gets the index of the given wishlist item.

Parameters

\Drupal\commerce_wishlist\Entity\WishlistItemInterface $wishlist_item: The wishlist item.

Return value

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

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

File

src/Entity/Wishlist.php, line 243

Class

Wishlist
Defines the wishlist entity class.

Namespace

Drupal\commerce_wishlist\Entity

Code

protected function getItemIndex(WishlistItemInterface $wishlist_item) {
  $values = $this
    ->get('wishlist_items')
    ->getValue();
  $wishlist_item_ids = array_map(function ($value) {
    return $value['target_id'];
  }, $values);
  return array_search($wishlist_item
    ->id(), $wishlist_item_ids);
}