image_hotspots-8.x-1.x-dev/image_hotspots.module

image_hotspots.module
<?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.
  \Drupal::moduleHandler()->loadInclude('image', 'inc', '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, '=')
    ->accessCheck()
    ->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, '=')
    ->accessCheck()
    ->execute();
  $queue = Drupal::queue('cron_image_hotspots_deletion', TRUE);
  $queue->createQueue();
  foreach ($hids as $hid) {
    $queue->createItem(['hid' => $hid]);
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc