Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It would be quite useful to have class "paragraphs-item-[entity_id]" on the main paragraphs item tag.
Possible usage:
- jQuery selection of specific paragraphs item
- CSS selection of specific paragraphs item
- The Paragraphs pack module is adding this class "paragraphs-item-[entity_id]" in hook_preprocess(), but it would be better to have it directly here in Paragraphs module
- The Entity background module needs this class "paragraphs-item-[entity_id]" to target specific paragraphs items too.
Comment | File | Size | Author |
---|---|---|---|
#9 | paragraphs-class_paragraphs_item_id-2427547-9.patch | 823 bytes | dabbor |
#6 | paragraphs-class_paragraphs_item_id-2427547-6.patch | 816 bytes | dabbor |
Comments
Comment #1
dabbor CreditAttribution: dabbor commentedAttaching the patch that provides the class "paragraphs-item-[entity_id]" on the main paragraphs item tag.
Comment #2
dabbor CreditAttribution: dabbor commentedComment #3
dabbor CreditAttribution: dabbor commentedComment #4
jeroen.b CreditAttribution: jeroen.b commentedI don't think PP_PARAGRAPH_TYPE is defined in the code.
Also, it might be better to do a proper preprocess on template_preprocess_paragraphs_item
Comment #5
jeroen.b CreditAttribution: jeroen.b commentedComment #6
dabbor CreditAttribution: dabbor commentedMy mistake about the PP_PARAGRAPH_TYPE, fixed and attached modified patch.
And I was even thinking about looking if the Paragraphs module is using any definition/constant for the 'paragraphs_item' and then I somehow lost attention to substitute PP_PARAGRAPH_TYPE for the 'paragraphs_item'.
Thanks for such a quick response ;)
Comment #7
dabbor CreditAttribution: dabbor commentedI'll give a look to "template_preprocess_paragraphs_item" and if you think it's better solution I can provide patch soon.
Comment #8
jeroen.b CreditAttribution: jeroen.b commentedJust thought about it. template_preprocess_paragraphs_item won't run as theme_paragraphs_item is never used. There is another issue about that. However, I do think it's better to use hook_preprocess_entity in stead of the global hook_preprocess. We don't want it to run on every preprocess.
Comment #9
dabbor CreditAttribution: dabbor commentedAttaching new patch that uses hook_preprocess_entity().
I've played for a while with template_preprocess_paragraphs_item() and tried to understand why it's not called. If I got it right the think is that preprocess for all items "template_preprocess_paragraphs_items()" in paragrahps.themes.inc is run because the paragraphs field formatter has defined #theme_wrapper "$element['#theme_wrappers'] = array('paragraphs_items');" in paragraphs_field_formatter_view(), but the entity paragraphs_item doesn't. So the template_preprocess_entity() is used.
Comment #10
jeroen.b CreditAttribution: jeroen.b commentedI think it's because it uses #theme = 'entity' on the paragraphs item instead of '#theme' = 'paragraphs_item'
Comment #11
dabbor CreditAttribution: dabbor commentedThanks for the answer
Comment #12
Ivan Zugec CreditAttribution: Ivan Zugec commented@jeroen.b Should we switch #theme to 'paragraphs_item' or are you happy with 'entity'?
Comment #13
Ivan Zugec CreditAttribution: Ivan Zugec commentedThere is an existing bug where the paragraphs_item theme never gets executed (#2394519: Paragraphs never calls #theme paragraph_item).
How can we push this patch forward? Are you happy using the 'entity' theme or should we create another patch to fix the issue with 'paragraphs_item'?
Comment #14
Ivan Zugec CreditAttribution: Ivan Zugec commentedShould we look at creating another contrib module? Something like
paragraphs_item_id.module
?I would prefer Paragraphs to handle this if possible.
Comment #15
Ivan Zugec CreditAttribution: Ivan Zugec commentedWe've created a contrib module to handle this called "Paragraphs ID". https://www.drupal.org/project/paragraphs_id
Comment #16
kevinquillen CreditAttribution: kevinquillen at Velir commentedIn my case, the provided template was rendering the paragraphs item despite the preprocess hook existing in my template.php. The paragraph was being rendered before the function was called. No idea what would cause it to be out of order, I am not using anything extra. I defaulted back to using template_preprocess_entity to be able to pass a variable into and print it in the template file.
Comment #17
_San_ CreditAttribution: _San_ commentedNot sure if anyone else is encountering this issue, but I managed to output the paragraph ID in my paragraphs-item--my-custom-paragraph-bundle.tpl.php template like this:
<?php print $variables['elements']['#entity']->item_id ?>
Comment #18
ericdsd CreditAttribution: ericdsd commentedThanks ssteigen #17 does the trick.