Closed (fixed)
Project:
Inline and link Drupal objects (Linodef)
Version:
6.x-1.x-dev
Component:
Filter
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Nov 2009 at 19:48 UTC
Updated:
29 Dec 2009 at 23:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
hefox commentedPatch attached
Adds a setting to filter settings
Using token module if exists to process the link title.
Defiently needs work. Added in format into a function to keep track of it due to it not existing as a parameter to any function, making adding it in a bit ugly.
Comment #2
Roi Danton commentedIn the next Linodef version you may set HTML attributes like title: #560042: Add option "attributes" to allow html attributes in embedded tags
However being able to alter the title for simple [#nid] tags would be useful. The approach using a variable and the token module seems fine. But the addition of the variable should happen in _linodef_find_nodesnfields() (linodef-filter.inc) where the hard coded title is added (line 264). Furthermore the patch of #1 violates a Drupal rule: using a variable for the first parameter of t(). This will cause problems with potx.
When this feature is RTBC adding a separate customizable title for terms and views might also be sufficient.
Comment #3
hefox commentedI'm on vacation ATM so don't have time (pay 4 internet hotel ftl) to repatch (which should be against dev instead, considering #560042 will effect it), however I'm confused about the second paragraph.
I think it's due to some part of the patch that I really disliked; I encountered a problem in that the filter id was never passed to the underlining functions, and would cause a lot of editing of function definations, etc., and not knowing if this feature would be desirable, reallly didn't feel like doing it at that stage. So I made a function to store the current filter id. That is why there's some extra code at the top; however, the change was done at around line 264 in that function I believe?
So before re-patch-making, I'd like your opinion on the the above issue (or, if it's been changed in dev, then that'd be nice).
Custimizable titles for terms and views sounds useful to me :).
Comment #4
Roi Danton commentedYou are correct. Your patch already changes the title at the correct place. I'm sorry, I misread it yesterday.
So as you said in #3, passing $format to the filter process functions (e.g. _linodef_find_nodesnfields($nid, $options = array(), $format)) is the way of choice and linodef_filter_format() you dislike won't be needed then (actually this feature is desirable :) ).
/me wondering why I used _linodef_filter_process($text, $format) in hook_filter but didn't use the $format parameter in linodef-filter.inc. With your patch this is fixed also. :)
It would be nice if you could change this part in your code and patch it against rc3 as before.
Btw, instead of t() str_replace() or similar should be used:
I haven't worked with the locale module yet, so I have no experience how to handle translations for admin settings textfields. However the translation of the title is secondary.
Comment #5
hefox commentedMaking patches in stages;
This is against a verison with #560042: Add option "attributes" to allow html attributes in embedded tags already applied.
Below patches are only adding format to the functions.
I added as the second function argument due to it being basically required (though added it as option into the function definitions because hook_filter does).
Haven't tested much; doing step by step.
Next step is to actually re-do the patch part
Patch may have issues patching; using git and haven't made a patch before using it :(.
Comment #6
hefox commentedAgainst 1.x-dev, with first http://drupal.org/node/560042#comment-2217452 (Had some issue apply the patch for that, some error about ending unexpectivally, but manually fixed it I think), then Combination patch from above applied.
Adds the settings to the filter configuration form, adds title text default to node, terms, and view links.
Anyhow, back to coughing up a storm :(.
Comment #7
Roi Danton commentedThanks for your contribution, the patches themselves are working fine!
Unfortunately there are some glitches with token_replace(). It aborts the calling function (e.g. _linodef_find_nodesnfields()) and causing _linodef_filter_process to run again in certain/unknown circumstances. That is confusing since token_replace() doesn't load the input filter of the $node object. Also the tokens ([nid] etc) aren't replaced then. I'm still tracking down the problem, maybe the fault lies at Linodef. My code for debugging:
The output (node with two textfields using Linodef tags):
When removing token_replace() the output is as expected.
Comment #8
hefox commentedWeird; about how often does it occur? It could be due to some other module provided tokens?
I'll try to recreate, but it wasn't occuring when I was testing on a very clean install of drupal (no CCK fields, etc.).
(Hopefully it can be resolved; I love the thought of using cck field token for link title, etc. :>.)
Comment #9
Roi Danton commentedThis problem appears always for me (EDIT: when using fields, see below). It is likely due to some other module, since the problem occurs when
module_invoke_all('token_values', $type, $object, $options)in token_get_values() is executed. node_token_values() is fine, so I've checked the token_values hooks other modules are using. For that I modified module_invoke_all to print the used modules:Correct output in my test installation:
Buggy output:
So the calling of content_token_values() causes the bug, more precisely the line
content_view($node);. I've written a bug report in CCK issue queue: #651236: content_view in content_token_values shouldn't load hook_filterComment #10
Roi Danton commentedThough problem in #9 isn't resolved I'd like to comment the patch:
Since token doesn't support [view] I've changed it to [viewname] which is replaced by the view title in _linodef_find_view().
Therefore the definition of the constants has changed slightly:
(providing a patch for these changes is awkard since I implemented #619166: "Override" option does not support apostrophe and other changes for the new taglists module in my local dev install - and manual editing of patches causes line bugs as you mentioned in #6 - it's about time to finish taglists and commit all this stuff so providing patches is easier for everyone :/ )
Comment #11
hefox commentedA random idea about viewname, it might be best to do an implementation of hook_token_values that provides a view name
To be consistent.
Hm, going to NY drupal camp saturday, but when I get the time I'll look into more; I think the way to fix it is to figure out why calling hook_filter in hook_filter prevents it from working. http://api.drupal.org/api/function/check_markup Perhaps it has to do with the cacheing or such. Hm
Comment #12
hefox commentedOh, that's interesting; I can't reproduce it!
I added a formatted text field, creates 2 nodes with formatted text that uses linodef; changed node title to be the formatted text token so I know it's being called; I even have it linking to itself, which somehow does not cause an infinite loop.
Here's one of the test nodes http://dev.foxinbox.org/content/dfvdfg-dfvdfg-dfvdfg-dfvdfg-dfvdfg-dfvdf... (what, me copy and pasting? never!).
Comment #13
Roi Danton commentedCould you insert the print() functions used in comment #7 in your code, please? So I can see the output at your copy & paste site. ;) However the filter result is as expected (also on my test site) so the user won't actually see this multiple calling of hook_filter. Though it can cause a duplicate appearance of Linedef info/warning/error messages. I'm not sure since the behavior of hook_filter used by cck token values seems to be different (or it is caused due to the execution inside a filter as you said). This would be nice to know.
EDIT: Nevermind, the recursion check for content_view() in token_get_values() seems to be the reason for the different behavior of token_replace in hook_filter called by CCK.
Linodef removes its own tags when embedding fields with Linodef tags. See this comment. Later I've introduced linodef_removetags() in main module file.
Comment #14
Roi Danton commentedIndeed, Linodef messages are duplicated when using token_replace with fields since the complete filter process is run again. Therefore I hesitate to use token_replace() as a default method for title substitution (it will also cause a serious performance hit when using many filters or Linodef tags). Avoiding the duplication as in token_get_values() (with static $running) doesn't seem to work since the filter has to run multiple times when having several nodes on a page. Also the filter doesn't know what function calls it. What a pity! Maybe you have an idea?
Comment #15
hefox commentedWhen looking into tokens a bit more, I was actually thinking the same thing.
I think what is most ideal would be to have checkboxes to enable tokens support on filters. Ie, instead of the three defaults, it'd be 3 defaults + 3 checkboxes for each, and tokens will only be run if they're enabled to run, with the default just being the 'simple' replacements ([nid], [title], category, etc.).
So nodenfields will look like this
Only reason I didn't bring it up earleir because I don't really want to re-roll the patches again (Random lazyness, dealing with revisions numbers, sigh!) and would prefer to provide a patch after the current ones are commited, :<.
hm, $running won't work.. lemme play
The issue is that it needs to run the filter correctly on formatted text fields, correct?
Perhaps, though I'd hate to do it, running function ><
and then where textfields are processed unset the running then reset after, but that seems complicated..
ooorr, put running around the token calls themselves.
And warn people that there is some limitation to token usage due to the potentional for recursion
Comment #16
Roi Danton commentedI'll be off for the weekend and the plane doesn't wait so just a short reply.
Thanks for the testing of the running variant. This make things complicated while it does not provide help: It should avoid problems with textfields with input filters - but we have to unset the running var as you proposed when using these textfields - otherwise token_replace would have no effect either.
But besides making token_replace() optional and warn the admin (in form description) about its flaws we could use the objects (node/term/view) we already have at hand and provide own token-like replacements (without token module). I.e. expanding
$attributes['title'] = str_ireplace(array('[title]', '[nid]'), array($node->title, $node->nid), $attributes['title']);to all the object properties that are available. I don't know if this would fulfill your needs as token does?Btw, thanks for updating your dev site. The output is the same as at my test installation. That I wanted to ensure. :)
Comment #17
hefox commentedI suspect manually doing tokens will get more complex then needed. For example, I'd be likely wanting to use a teaser field (not the one created by drupal manually, a cck text field)
What do you think about combing the last 2 and the first of number 15?
Comment #18
Roi Danton commentedI've committed your proposals and added a few tokens usable without the tokens module. Just the usage of static $running is lacking completely. I'd like if you could provide a patch against the updated dev release.
@#11: Linodef shouldn't add tokens related to other modules (views).
Comment #19
hefox commentedcool =)
Here's the patch as said in #17,
here's it with the test statements: http://dev.foxinbox.org/content/dfvdfg-dfvdfg-dfvdfg-dfvdfg-dfvdfg-dfvdf...
alterntly, output of the test statements
Also corrects a small copy and paste bug token_replace($attributes['title'], 'node', $node); was being used for terms :P.
Comment #20
Roi Danton commentedI've edited your patch from #19 so it also prevents duplicated messages and the static running could be used for other processes, too (if needed in future). Please review for copy & paste accidents. ;)
Additionally to take those 'title' and 'class' attributes in consideration that are defined by option 'attributes' I've made a few minor changes that are not related directly to this issue (but clutter the patch, sorry).
@#15:
This is used when processing the options 'content' and 'formatter'. Actually you are right and I'd like to have a better solution for Drupal6 that heeds views/panels but don't know of it yet.
Comment #21
Roi Danton commentedCommitted to D6 branch. Thx for your contribution!