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.
Hi, How can I add <![CDATA[
at the start of some of the item elements?
Comments
Comment #1
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedYou would need to create relevant preprocess functions for those elements, and add CDATA wrapper there. See
views_rss_core_views_rss_item_elements()
and content ofviews_rss_core.inc
for some examples.Comment #2.0
(not verified) CreditAttribution: commentedUpdated issue summary.
Comment #3
truantology CreditAttribution: truantology commentedDid you ever fix this, ermelandus? If so, care to share your code?
Thanks!
Comment #4
wonder95 CreditAttribution: wonder95 commentedFor what it's worth, here's how I was able to do it. I needed to add a custom 'content' element, and then add the CDATA tags to the description and content elements.
The only weird problem is that my '<' is being converted to the HTML entity (
<
), so I need to figure out how to get around that, but this will at least give you an idea how to add the tags to the item.Comment #5
mpv CreditAttribution: mpv commentedIn #2393461: format_xml_elements() does not allow unencoded values there's patch for
format_xml_elements
that allows to avoid the encoding by setting anencoded
property in the xml element.Comment #6
wonder95 CreditAttribution: wonder95 commented@mpv, I saw that, but I'm not seeing where the "encoding" property gets set on the element so that patch works.
Comment #7
mpv CreditAttribution: mpv commented@wonder95 you can set the
encoded
property in the same preprocess functions you are adding the CDATA wrapper. I am using something like this:This together with the patch in #2393461: format_xml_elements() does not allow unencoded values is working for me.
Comment #8
wonder95 CreditAttribution: wonder95 commentedAwesome!! That did the trick. I was close with what I had, but this works perfectly.
Comment #9
aedwards88 CreditAttribution: aedwards88 as a volunteer commentedCould the same be accomplished by just creating a module with a respective Field Formatter for the cdata representation. Thereafter setting the field formatter on the field which is to display the cdata representation of the text.
Comment #10
SnackyStacky CreditAttribution: SnackyStacky commented@wonder95 and/or @mpv: I have been struggling with this for a week now.
I am able to get what @wonder95 had originally that creates the
Should I only be using the code shown by @mpv? Or do they both go into a single .module file? I notice in @mpv's code, there are empty quotes and brackets. Should something be going in there?
Any help would really be appreciated. :)
Comment #11
wonder95 CreditAttribution: wonder95 commented@SnackyStacky; you need @mpv's code (his was an update to mine) and the core update he referenced. His code will not work without the update to common.inc. That issue has yet to be committed (due to some documentation for the change missing), so I've been having to manually re-apply that patch after every D7 core update. However, @mpv just submitted a patch with the required documentation, so hopefully it will be committed to core soon.
FWIW, here's my final code:
Comment #12
SnackyStacky CreditAttribution: SnackyStacky commented@wonder95 - THANK YOU!!!!! SO MUCH!!!!!
I did apply the common.inc patch, so it's been driving me absolutely bonkers that I cannot get this to work. I really appreciate your follow up! I'm out of the office now, but I will be working with this as soon as I get back.
Thank you, again!
Comment #13
SnackyStacky CreditAttribution: SnackyStacky commentedIt worked!!!!
Thank you!!!!