image_hotspots.module in Image Hotspots 8
Same filename and directory in other branches
Main functions of module.
File
image_hotspots.moduleView source
<?php
/**
* @file
* Main functions of module.
*/
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_theme().
*/
function image_hotspots_theme($existing, $type, $theme, $path) {
return [
'image_formatter_with_hotspots' => [
'variables' => [
'item' => NULL,
'item_attributes' => NULL,
'url' => NULL,
'image_style' => NULL,
'info' => NULL,
],
'file' => 'image_hotspots.module',
],
];
}
/**
* Prepares variables for image formatter with hotspots templates.
*
* Default template: image-formatter-with-hotspots.html.twig.
*
* @see template_preprocess_image_formatter
*/
function template_preprocess_image_formatter_with_hotspots(&$variables) {
// Add field.inc file.
module_load_include('inc', 'image', 'image.field');
template_preprocess_image_formatter($variables);
}
/**
* Implements hook_ENTITY_TYPE_delete().
*
* If file was deleted we need to delete all hotspots that referenced on it.
* So insert all of them in on cron run deletion queue.
*/
function image_hotspots_file_delete(EntityInterface $entity) {
$fid = $entity
->id();
$hids = Drupal::entityQuery('image_hotspot')
->condition('fid', $fid, '=')
->execute();
$queue = Drupal::queue('cron_image_hotspots_deletion', TRUE);
$queue
->createQueue();
foreach ($hids as $hid) {
$queue
->createItem([
'hid' => $hid,
]);
}
}
/**
* Implements hook_ENTITY_TYPE_delete().
*
* If image style was deleted we need to delete all hotspots that referenced on
* it. So insert all of them in on cron run deletion queue.
*/
function image_hotspots_image_style_delete(EntityInterface $entity) {
$style_name = $entity
->id();
$hids = Drupal::entityQuery('image_hotspot')
->condition('image_style', $style_name, '=')
->execute();
$queue = Drupal::queue('cron_image_hotspots_deletion', TRUE);
$queue
->createQueue();
foreach ($hids as $hid) {
$queue
->createItem([
'hid' => $hid,
]);
}
}
Functions
Name | Description |
---|---|
image_hotspots_file_delete | Implements hook_ENTITY_TYPE_delete(). |
image_hotspots_image_style_delete | Implements hook_ENTITY_TYPE_delete(). |
image_hotspots_theme | Implements hook_theme(). |
template_preprocess_image_formatter_with_hotspots | Prepares variables for image formatter with hotspots templates. |