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

John Pitcairn created an issue. See original summary.

kwfinken’s picture

@John Pitcairn, Did you ever get an answer for this? I am looking for similar info.

johnpitcairn’s picture

Nope.

berdir’s picture

Status: Active » Fixed

Just 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...

berdir’s picture

https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets... has tons of examples, including a preprocess function.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.