I have a module that provides a custom paragraph type.
What is the recommended way to attach javascript to the custom paragraph type for a specific view mode only, from the module (not the theme)? The javascript should only be loaded when viewing an entity containing that paragraph type with that view mode.
Note I have no need to supply any theming whatsoever from within the module, but I do need to attach the javascript logic.
(Sorry, getting my head around how these things work in D8)
Comments
Comment #2
kwfinken commented@John Pitcairn, Did you ever get an answer for this? I am looking for similar info.
Comment #3
johnpitcairn commentedNope.
Comment #4
berdirJust like any other entity type. Implement yourmodule_paragraph_view() or also preprocess, check for the paragraph type & view mode, add a library through #attached.
It's better to ask those kind of generic questions on Drupal Answers, Slack or so, the answer is always the same, just the name of the hook changes...
Comment #5
berdirhttps://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets... has tons of examples, including a preprocess function.