function cms_content_sync_entity_update in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x cms_content_sync.module \cms_content_sync_entity_update()
- 2.0.x cms_content_sync.module \cms_content_sync_entity_update()
Push the entity automatically if configured to do so.
Parameters
\Drupal\Core\Entity\EntityInterface $entity:
File
- ./
cms_content_sync.module, line 1113 - Module file for cms_content_sync.
Code
function cms_content_sync_entity_update(EntityInterface $entity) {
if (!_cms_content_sync_is_installed()) {
return;
}
if (!EntityHandlerPluginManager::isSupported($entity
->getEntityTypeId(), $entity
->bundle())) {
return;
}
// When updating the tree, Drupal Core does NOT update the parent and weight of the tern when saving it.
// Instead, they manipulate the tree afterwards WITHOUT triggering the save again.
// The values provided by the form submit are also WRONG as Drupal keeps the parent that was set but changes the
// weight unpredictably.
// So we need to skip pushing these and instead push them all at once after the full save routing from Drupal
// is done.
if (_cms_content_sync_update_taxonomy_tree_static()) {
_cms_content_sync_update_taxonomy_tree_static(TRUE, $entity);
return;
}
if ($entity instanceof FieldableEntityInterface) {
DefaultEntityReferenceHandler::saveEmbeddedPushToPools($entity);
}
// This is actually an update, but for the case this entity existed
// before the synchronization was created or the entity could not be
// pushed before for any reason, using ::ACTION_UPDATE would lead to
// errors. Thus we're just using ::ACTION_CREATE which always works.
if (!_prevent_entity_export($entity)) {
PushIntent::pushEntityFromUi($entity, PushIntent::PUSH_AUTOMATICALLY, SyncIntent::ACTION_UPDATE);
}
$moduleHandler = Drupal::service('module_handler');
// Limit execution to nodes.
// Push manually as well if the entity was scheduled.
if ($moduleHandler
->moduleExists('scheduler') && $entity
->getEntityTypeId() == 'node') {
if ($entity
->isPublished() && !$entity
->get('publish_on')
->getValue()) {
$original = $entity->original;
if ($original && !$original
->isPublished() && $original
->get('publish_on')
->getValue()) {
PushIntent::pushEntityFromUi($entity, PushIntent::PUSH_MANUALLY, SyncIntent::ACTION_UPDATE);
}
}
if (!$entity
->isPublished() && !$entity
->get('unpublish_on')
->getValue()) {
$original = $entity->original;
if ($original && $original
->isPublished() && $original
->get('unpublish_on')
->getValue()) {
PushIntent::pushEntityFromUi($entity, PushIntent::PUSH_MANUALLY, SyncIntent::ACTION_UPDATE);
}
}
}
}