You are here

BrightcoveVideoLocalDeleteQueueWorker.php in Brightcove Video Connect 8.2

File

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

namespace Drupal\brightcove\Plugin\QueueWorker;

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

/**
 * Processes Entity Local Delete Tasks for Video.
 *
 * @QueueWorker(
 *   id = "brightcove_video_local_delete_queue_worker",
 *   title = @Translation("Brightcove video local delete queue worker."),
 *   cron = { "time" = 30 }
 * )
 */
class BrightcoveVideoLocalDeleteQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The brightcove_video storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Constructs a new BrightcoveVideoLocalDeleteQueueWorker 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 array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   Brightcove Video Entity storage.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->storage = $storage;
  }

  /**
   * {@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')
      ->getStorage('brightcove_video'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {

    /** @var \Drupal\brightcove\Entity\BrightcoveVideo $video */
    $video = $this->storage
      ->load($data);
    if (!is_null($video)) {
      $video
        ->delete(TRUE);
    }
  }

}

Classes

Namesort descending Description
BrightcoveVideoLocalDeleteQueueWorker Processes Entity Local Delete Tasks for Video.