1

The scenario is like this: we have a news website, every page display different type of news nodes. We like to set the in this way that, for a single page, no news node should be display more twice. i.e. should not be duplicate.

We are creating paragraphs, which are fetching different type of news nodes based on taxonomies. For a single page, user can add as many paragraph as they want. Each paragraph display nodes with different layout. Paragraph fetching nodes by entity query and views as well. So question is, how we can restrict nodes, so that if one displaying in one paragraph, it should not display in another paragraph for a single page?

Something like, if we can create a singleton class or static function, so on page load, it create a blank array, and each subsequent call of that function will fill the array and compare with the old list which are already dumped or added. But I am not sure which hook should be used for page load and how to handle the views query.

Beside this should be session specific and also keep it mind about the performance.

Does anyone has any idea on this? Surely its complex.

  • It depends how _we are creating paragraphs, which are fetching different type of news nodes based on taxonomies_, and how _paragraph fetching nodes by entity query and views_. Please develop a bit, how are loaded and rendered all these paragraphs on a page for a given content type (views? blocks? UI vs code? custom page callback) ? If you have some hook candidates in mind, share them. If a single hook can catch all the involved entity queries then you can directly use a static array inside that hook for deduping, after doing some checks (based on view/display name, current path. etc.). – EricLavault Jan 17 '22 at 18:47
  • I am getting the node list in combination for entity query and view. Everything on code inside preprocess function. If its a single paragraph, it can be handled, but as it is multiple paragraphs and everyone loading the node independently, I need a hook which is fetched by both on page load. For Drupal 9, I think I need to event subscription, previous hook_init or hook_boot. – Md. Shafiq Hossain Jan 17 '22 at 19:51
  • It would be more explicit if you could provide some code. You can catch the node ids and/or alter the query if necessary in hook_views_query_alter (ie. SELECT DISTINCT statement, excluding nodes if the view is loaded after the entity query), or even directy in the preprocess hook. Note that drupal's php script handles a single request for a single user and you can rely on a static variable during the whole page load. – EricLavault Jan 17 '22 at 21:08
  • Which type is your page ? You can iterate on paragraphs and news, and check which news will be displayed keep it in static variable (or cache for this page with page cache tags) and do an exclude condition on display. – Thomas Lefetz Feb 21 '22 at 05:15

0 Answers0