acquia_perz-4.0.0-rc1/modules/acquia_perz_push/acquia_perz_push.module

modules/acquia_perz_push/acquia_perz_push.module
<?php

/**
 * @file
 * Acquia Perz Push - module file.
 */

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityPublishedInterface;

/**
 * Implements hook_entity_insert().
 */
function acquia_perz_push_entity_insert(EntityInterface $entity): void {
  if ($entity instanceof EntityPublishedInterface && !$entity->isPublished()) {
    // Do not process, entity is unpublished.
    return;
  }

  \Drupal::getContainer()
    ->get('acquia_perz_push.export_content')
    ->exportEntity($entity);
}

/**
 * Implements hook_entity_update().
 */
function acquia_perz_push_entity_update(EntityInterface $entity): void {
  if (!$entity instanceof EntityPublishedInterface) {
    // Do not process, entity is not publishable.
    return;
  }

  $originalEntity = $entity->original ?? NULL;

  // Determine if the original and current entities are eligible for export.
  $isOriginalEligible = \Drupal::service('acquia_perz.entity_helper')->isEligibleForExport($originalEntity);
  $isCurrentEligible = \Drupal::service('acquia_perz.entity_helper')->isEligibleForExport($entity);

  // If the entity is published, decide whether to export or delete.
  if ($entity->isPublished()) {
    if ($isOriginalEligible && !$isCurrentEligible) {
      // The original entity was eligible but the current one is not,
      // so delete the original entity from Personalization.
      \Drupal::getContainer()
        ->get('acquia_perz_push.export_content')
        ->deleteEntity($originalEntity);
    }
    else {
      // Export the current entity.
      \Drupal::getContainer()
        ->get('acquia_perz_push.export_content')
        ->exportEntity($entity);
    }

  }
  else {
    // If the entity is not published, delete the current entity.
    \Drupal::getContainer()
      ->get('acquia_perz_push.export_content')
      ->deleteEntity($entity);
  }
}

/**
 * Implements hook_entity_predelete().
 */
function acquia_perz_push_entity_delete(EntityInterface $entity): void {
  if (\Drupal::service('acquia_perz.entity_helper')->isEligibleForExport($entity)) {
    \Drupal::getContainer()
      ->get('acquia_perz_push.export_content')
      ->deleteEntity($entity);
  }
}

/**
 * Implements hook_entity_translation_predelete().
 */
function acquia_perz_push_entity_translation_delete(EntityInterface $translation): void {
  if (\Drupal::service('acquia_perz.entity_helper')->isEligibleForExport($translation)) {
    \Drupal::getContainer()
      ->get('acquia_perz_push.export_content')
      ->deleteTranslation($translation);
  }
}

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

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