Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/custom_forms / src / Plugin / QueueWorker / CustomFormsHandlerQueueWorker.php
Size: Mime:
<?php

namespace Drupal\custom_forms\Plugin\QueueWorker;

use Drupal\Core\Annotation\QueueWorker;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\custom_forms\CustomFormsSubmissionHandlerManager;
use Drupal\custom_forms\Entity\CustomFormSubmission;
use Drupal\custom_forms\Entity\CustomFormSubmissionHandler;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class CustomFormsHandlerQueueWorker
 *
 * @package Drupal\custom_forms\Plugin\QueueWorker
 *
 * @QueueWorker(
 *   id = "custom_forms_submission_handlers",
 *   title = @Translation("Cron submission handler execution"),
 *   cron = {"time" = 30}
 * )
 */
class CustomFormsHandlerQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
  use StringTranslationTrait;

  /**
   * The logger channel factory.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $logger;

  /**
   * @var \Drupal\custom_forms\CustomFormsSubmissionHandlerManager
   *   The plugin manager for submission handler plugins.
   */
  protected $pluginManager;

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

  /**
   * @inheritDoc
   */
  public function __construct(
    array $configuration,
    $plugin_id,
    $plugin_definition,
    CustomFormsSubmissionHandlerManager $pluginManager,
    LoggerChannelFactoryInterface $logger_factory
  ) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->logger           = $logger_factory->get('Custom Forms');
    $this->pluginManager    = $pluginManager;
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    /** @var \Drupal\custom_forms\Entity\CustomFormSubmissionHandlerInterface $handler */
    $handler = CustomFormSubmissionHandler::load($data['handler_id']);
    /** @var \Drupal\custom_forms\Plugin\CustomForms\SubmissionHandler\CustomFormsSubmissionHandlerInterface $plugin */
    $plugin = $handler->getPlugin();
    /** @var \Drupal\custom_forms\Entity\CustomFormSubmissionInterface $submission */
    $submission = CustomFormSubmission::load($data['submission_id']);

    // Execute the handler.
    $plugin->executeHandler($submission, $handler);
  }

}