You are here

WishlistItemDelete.php in Commerce Wishlist 8.3

File

src/Plugin/QueueWorker/WishlistItemDelete.php
View source
<?php

namespace Drupal\commerce_wishlist\Plugin\QueueWorker;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Deletes queued wishlist items.
 *
 * @QueueWorker(
 *   id = "commerce_wishlist_item_delete",
 *   title = @Translation("Wishlist item delete"),
 *   cron = {"time" = 10}
 * )
 */
class WishlistItemDelete extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Creates a new WishlistItemDelete object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity_type.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $storage = $this->entityTypeManager
      ->getStorage('commerce_wishlist_item');
    $wishlist_items = $storage
      ->loadMultiple($data['ids']);
    if ($wishlist_items) {
      $storage
        ->delete($wishlist_items);
    }
  }

}

Classes

Namesort descending Description
WishlistItemDelete Deletes queued wishlist items.