Repeat Create Node only successful after cache is cleared

Created on 20 October 2023, about 1 year ago
Updated 2 April 2024, 8 months ago

My test model creates a new node when a specific content type is viewed. It also saves the node that was just created. With a cleared cache it runs successfully but if I delete the newly created node, close and reopen the same content that I just viewed to view it again, a new node is not created. If I clear the cache after deleting the created node it runs successfully again.

I need to understand why it behaves this way and if there is something I can do to make it work every time please.

Thanks for your time and thoughts.

πŸ’¬ Support request
Status

Closed: outdated

Version

1.1

Component

Tests

Created by

πŸ‡ΊπŸ‡ΈUnited States guymandude

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @guymandude
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    What's the event, you're starting with? Could well be that the event you chose is not being dispatched on cached pages.

  • πŸ‡ΊπŸ‡ΈUnited States guymandude

    I'm using a Viewed Content Entity as a trigger.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    OK, that's certainly cached and Drupal will not dispatch that if not really needed. You may want to switch to something like Controller found to handle request and then load the entity that's being viewed with the Token: load route parameter action.

  • πŸ‡ΊπŸ‡ΈUnited States guymandude

    Thanks for the prompt feedback. Can you offer a suggestion for a non-coder please? Are there some canned events that fit the bill by chance?

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Can you offer a suggestion for a non-coder please?

    The 2 links in my previous comment do the job. And a sample, that does something similar can be downloaded from Route test.

  • πŸ‡ΊπŸ‡ΈUnited States guymandude

    Thanks again. I imported the example you have here and it works as noted. However it's not clear how to find the value of the token name. The example uses "mynode" for that token name, but it does not appear to be an arbitrary name. I tried changing the value to something else and the message no longer appears on screen when viewing an article.

    From the Load Route Parameter instructions:

    Name of token
    The name of the token, the parameter value gets stored into.

    I used Devel to see if I could find a token called mynode but I could not. Does mynode have special significance to Drupal or ECA?

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    The name of the token there is fully your choice. It is a name you define yourself, it's the place where the value is being stored and you can refer to that value later with the token syntax, e.g. [mynode] or whatever you decide you want to call that. More details about tokens can be found at Tokens

  • Status changed to Postponed: needs info 11 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    What's the status on this?

  • Status changed to Closed: outdated 8 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
Production build 0.71.5 2024