backdrop-contrib / paragraphs

Paragraphs module to control your content flow
https://backdropcms.org/project/paragraphs
GNU General Public License v2.0
5 stars 11 forks source link

Preprocessing difficulty #7

Closed laryn closed 6 years ago

laryn commented 6 years ago

An issue I raised on Gitter and haven't been able to crack yet:

I'm trying to preprocess a Paragraph bundle and following someone's post related to D7, I'm trying to use hook_preprocess_entity but am not able to get anything to even show up in the logs using debug – does that hook still exist in Backdrop?

https://drupal.stackexchange.com/a/185513/33636

@alexfinnarn 10:55

seems to be https://api.backdropcms.org/api/backdrop/core%21modules%21entity%21entity.api.php/function/hook_entity_view_alter/1 "Alternatively, it could also implement hook_preprocess_ENTITY()"

that is all I can tell. Isn’t there some function that gathers all the possible hooks available?

maybe https://api.backdropcms.org/api/backdrop/core%21modules%21system%21system.api.php/function/hook_module_implements_alter/1 and search for it there?

laryn commented 6 years ago

Update: I think I may be having some success (after trying a ton of different function names) with the following in my theme's template.php file:

function THEME_preprocess_paragraphs_items(&$variables) {
  debug($variables);
}

And in the end I was able to accomplish what I needed (adding a class to a certain field within the paragraph) within THEME_preprocess_field.

laryn commented 6 years ago

Reopening because THEME_preprocess_paragraphs_item should really work (but doesn't) and I found a patch on Drupal that seems to do the job. PR coming.

laryn commented 6 years ago

The PR above seems to fix this. I'd appreciate any testing and feedback but I'm using it on a dev site now and it's making things much easier for me...