You are here

class ImageStylesPregenerator in Image Style Warmer 8

Executes interface image styles pregeneration queue tasks.

Plugin annotation


@QueueWorker(
  id = "image_style_warmer_pregenerator",
  title = @Translation("Pregenerate image styles"),
  cron = {"time" = 60}
)

Hierarchy

Expanded class hierarchy of ImageStylesPregenerator

File

src/Plugin/QueueWorker/ImageStylesPregenerator.php, line 22

Namespace

Drupal\image_style_warmer\Plugin\QueueWorker
View source
class ImageStylesPregenerator extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The image style warmer settings.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * The file entity storage.
   *
   * @var \Drupal\file\FileStorageInterface
   */
  protected $fileStorage;

  /**
   * The image style warmer service.
   *
   * @var \Drupal\image_style_warmer\ImageStylesWarmerInterface
   */
  protected $imageStylesWarmer;

  /**
   * Constructs a new ImageStylePregenerator 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\Config\Config $image_style_warmer_settings
   *   The image style warmer settings.
   * @param \Drupal\Core\Entity\EntityStorageInterface $file_storage
   *   The file storage.
   * @param \Drupal\image_style_warmer\ImageStylesWarmerInterface $image_styles_warmer
   *   The image style warmer service.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, Config $image_style_warmer_settings, EntityStorageInterface $file_storage, ImageStylesWarmerInterface $image_styles_warmer) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->config = $image_style_warmer_settings;
    $this->fileStorage = $file_storage;
    $this->imageStylesWarmer = $image_styles_warmer;
  }

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

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $file_id = $data['file_id'];
    $queueImageStyles = $data['image_styles'];
    if (!empty($queueImageStyles) && ($file = $this->fileStorage
      ->load($file_id)) && $file instanceof FileInterface) {
      $this->imageStylesWarmer
        ->doWarmUp($file, $queueImageStyles);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImageStylesPregenerator::$config protected property The image style warmer settings.
ImageStylesPregenerator::$fileStorage protected property The file entity storage.
ImageStylesPregenerator::$imageStylesWarmer protected property The image style warmer service.
ImageStylesPregenerator::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ImageStylesPregenerator::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
ImageStylesPregenerator::__construct public function Constructs a new ImageStylePregenerator object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.