It appears shortcodes are executed (and cached) on the admin/content page. For most of my short codes this isn't an issue, however when dealing with any short codes that leverage theme overrides it spells disaster. If some innocent change (say a tweak to display settings) or a cache clear is performed, and the admin/content page is hit, every node cache's its shortcodes using the admin theme. Any shortcodes that use tpl overrides are rendered on the front end incorrectly.
For example if we were to perform:
function somemodule_SOMECODE_process($attrs, $text){
// ...handle attrs...
$node = node_load(1);
$node_view = node_view($node, 'teaser');
return render($node_view);
}
After a structure change, or a cache clear, hitting admin/content would potentially be disastrous. Is there a way to prevent caching of a given short code?
(This may be a function of the text_filter caching, apologies if it is)
Comments
Comment #1
jpschroeder commentedComment #2
dave reidThis is because doing a node_load() causes any filtered text fields to run through the filter system; see the calls to _text_sanitize() in text_field_load(). This is a core issue and not related to shortcodes.
Comment #3
nicodh commentedUp !
Do you have any solution around this issue ?
I have a shortcode that uses a theme template and inside a call to noad_view, and at each edit/save of the page in admin/content, the text is cached, and the output is made with admin theme and logged user (in my case user 1), so with admin contextual links (like edit, view...). It's annoying...
Thanks in advance !
Comment #4
nicodh commentedComment #5
denes.szabo commented@rkcreation: try this in your Shortcode:
(Code based on the shortcode_embed_content module).
As you see, I remove the contextual_links content from the output. As Dave Reid mentioned you above, it is a core issue, if ever solved it, the solution will be very complicated.
Comment #6
nicodh commented@Denes.Szabo : thanks for the reply.
It's a solution for contextual links, but node.tpl overrides in my front theme is not used.
After search, I don't find any way to force theme used for node_view, if you have a solution (if exists) I'm interested !
Thanks
Comment #7
denes.szabo commented@rkcreation: I would try to add a special node theming into a module (not theme), then use this theming function for display the embedded node.
This theming function should be independent from all enabled themes - just add special css formatting into the theme's css.
Comment #8
jpschroeder commented@Denes.Szabo is right, there is no way around this; you need to manually get the same markup to render no matter what theme is selected (ugly, but possible with a module). The only real solution is to write a separate module to parse your special shortcode way after the text_filter, like in a theme function, say theme_node_preprocess(); I'm going to write a module to this effect and will post a link to it when its done.
EDIT:
The module I've written is sandboxed here: https://www.drupal.org/sandbox/man4mac/2442015
Comment #9
khaled.zaidan commentedIf anyone is still interested in this issue, I did manage a workaround. I have not looked at the module by jpschroeder (but since it's still in sandbox, I'll guess he didn't finish it).
so here's the snippet of code I used on my project:
The bit where I'm checking if the field has a shortcode or not may need to be tweaked, as well as which fields are to be checked.
I suppose the nicer solution would be to fetch all shortcodes (from the shortcode module's API), and all the long text fields (from Drupal's API) and go through them all... Or maybe just always clear them if you're on an admin path and you have a different admin theme than your default theme.
I hope this helps.