Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
lingotek_entity_insert() causes the entity being inserted to be resaved. This then fires update hooks before all the insert hooks have finished firing. All a client site this is resulting in duplicate entries in the url_alias table. Pathauto has a module weight of 1 whilst lingotek has a 0. This guarantees the lingotek hook fires before pathautos.
Proposed resolution
One solution would be to use hook_module_implements_alter and guarantee this comes last. But it is not a good solution. Re-saving the entity during an insert is a pretty tricky thing to do reliably when other modules can come in and do all sorts.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#18 | 2782085.18.patch | 5.35 KB | alexpott |
Comments
Comment #2
alexpottlingotek_entity_update() will have the same problem - resaving an entity during it own save events is not robust.
Comment #3
alexpottI think some of the logic should move to a presave - i.e the calculation of of the hash. And then you just need to compare the original value with the new value.
Comment #4
alexpottActually this is a critical bug for this module as it is likely to not make it inter-operable with many modules. Update hooks firing before insert hooks is very surprising :)
Comment #5
alexpottI think this patch should fail because \Drupal\lingotek\LingotekContentTranslationService::hasEntityChanged is not quite right yet - it needs to account for the presave change.
Comment #9
alexpottGood that failed...
Comment #13
alexpottThe other option here is to try and not save the hash on the content entity. Given the changes content_moderation might bring to core that might be a desirable route. We could just use $entity->original and $entity during hook_entity_insert and hook_entity_update to work out if there is anything to do. That should work in those cases - I'm not 100% certain about the other cases where the hash is used.
Comment #14
alexpottComment #18
alexpottWhoops.
Comment #19
alexpottThis is not great but if we're going to save the hash to content entity probably the best option because it won't result in double saves.
Comment #20
penyaskitoThanks so much Alex for working on this!
For Lingotek translation purposes, if the changed fields are not configured to be translated with lingotek, we want to avoid uploading it again.
Comment #21
penyaskitoThis should be green.
Comment #25
penyaskitoOH, stupid me. Insert is insert and will be the first upload, so @alexpott was right.
Comment #26
penyaskitoHave been talking to Alex on IRC about #13. The naming is a bit poor, but hasChanged() not only checks if there are changes on the entity while it's been saved, but also we consider it changed even if there are no changes to the entity, but to the fields set to be uploaded. So we cannot rely on
$entity->original
for that, unless we track when the config changed.This could be another hard problem and can have other complications.
For now let's commit #18, and will explore soon having a different entity for metadata (as we do with configuration entities actually). That's a re-architecture change that can be made back-compatible, and worth a try as it could help simplifying how we handle revisions too.
RTBCing #18.
Comment #27
penyaskitoComment #28
penyaskitoComment #30
penyaskitoCommitted 46d6f61 and pushed to 8.x-1.x. Thanks!
Comment #31
penyaskitoComment #32
azinck CreditAttribution: azinck commentedIssue is related to #2768973: Incompatible with Search API