- Issue created by @cosmicdreams
- πΊπΈUnited States mtalt Maryland
@cosmicdreams
At one point, we were using hook_entity_insert, but the documentation says "Note that hook implementations may not alter the stored entity data.". Saving the entity again was causing other issues, such as webform handlers to be called more than once π Estimated Read Time module make webform send emails twice Fixed .
Does your site also break on previewing a node? I've run into issues in the past where a NID is not always available in the template and we had to wrap code in a condition that checked if the NID was available. The NID will not be present when previewing a new entity. The code you see where we set that we are in a preview is because of similar functionality in core for nodes. This occurs in the links field where those links will not be rendered while previewing.
Is Cohesion using that node ID to render content that would have a meaningful difference on the read time? If not, could you only render that content if a node ID is present? Alternatively, could you create a view mode dedicated for read time calculations that does not require a node ID in the template?
- πΊπΈUnited States cosmicdreams Minneapolis/St. Paul
I've found that condition to cover "in_preview" modes. Perhaps the code needs handle $entity->isNew() conditions.
I see that Drupal 11 is considering including a entity post save hook: https://www.drupal.org/project/drupal/issues/2221347 β¨ Add hook_entity_postsave hook Needs work
That would be cool, but it sounds like the guidance would remain to be that entities aren't re-saved during this event / hook.
I think I'm going to pursue a fix that doesn't compile templates if the entity is new.
- Status changed to Closed: won't fix
8 months ago 6:27pm 15 March 2024 - πΊπΈUnited States mtalt Maryland
Sounds good @cosmicdreams. I'm going to close this issue, but feel free to re-open if you think of a viable alternative.