acquia_lift-8.x-4.3/modules/acquia_lift_publisher/acquia_lift_publisher.module
modules/acquia_lift_publisher/acquia_lift_publisher.module
<?php
/**
* @file
* Drupal Module: Acquia Lift - Publisher.
*
* Acquia Content Hub Publisher exports content from your Drupal site to
* Content Hub services. This module alters the behavior of the default
* functionality.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\acquia_lift_publisher\Form\ContentPublishingForm;
/**
* Implements hook_entity_insert().
*/
function acquia_lift_publisher_entity_insert(EntityInterface $entity) {
$publishing_actions = Drupal::service('acquia_lift_publisher.publishing_actions');
$push_setting_field_value = $publishing_actions->getPublicationsFieldValue(
ContentPublishingForm::$pushSettingField,
TRUE
);
$export_content_immediately_field_value = $publishing_actions->getPublicationsFieldValue(
ContentPublishingForm::$exportContentImmediatelyField,
TRUE
);
if ($push_setting_field_value === TRUE
&& $export_content_immediately_field_value === TRUE) {
_acquia_lift_publisher_trigger_queue($entity);
}
}
/**
* Implements hook_entity_update().
*/
function acquia_lift_publisher_entity_update(EntityInterface $entity) {
$publishing_actions = Drupal::service('acquia_lift_publisher.publishing_actions');
$push_setting_field_value = $publishing_actions->getPublicationsFieldValue(
ContentPublishingForm::$pushSettingField,
TRUE
);
$export_content_immediately_field_value = $publishing_actions->getPublicationsFieldValue(
ContentPublishingForm::$exportContentImmediatelyField,
TRUE
);
if ($push_setting_field_value === TRUE
&& $export_content_immediately_field_value === TRUE) {
_acquia_lift_publisher_trigger_queue($entity);
}
}
/**
* Triggers the Content Hub export process.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The current entity.
*/
function _acquia_lift_publisher_trigger_queue(EntityInterface $entity): void {
\Drupal::getContainer()
->get('acquia_lift_publisher.publishing_actions')
->triggerQueue($entity);
}
/**
* Implements hook_module_implements_alter().
*/
function acquia_lift_publisher_module_implements_alter(&$implementations, $hook) {
// Make sure that acquia_contenthub_publisher module hooks run before
// acquia_lift_publisher hooks.
$hooks = [
'entity_insert',
'entity_update',
];
if (!in_array($hook, $hooks, TRUE)) {
return;
}
$module = 'acquia_lift_publisher';
$group = $implementations[$module];
unset($implementations[$module]);
$implementations[$module] = $group;
}
