I was really suprized to see that I couldn't select an input format for each text field. You can already choose between "Plain Text" and "Filtered text" for text processing, but you should be able to choose a specific input format if you want, like Full HTML for certain fields and PHP or Filtered HTML for another.
I imagine it would look something like this:
Note: An "o" is a radio button, any text in brackets, [ or ], is an explanation, not in the final text.
<strong>Text processing:</strong>
o Plain text
o Filtered text (user selects input format)
> Input format [This would expand to reveal the selectable input formats]
o Filtered HTML
o PHP code
o Full HTML
[All of the radio buttons would be a part of the same selection,
so you could not, for example, select both Plain Text and
Filtered HTML.]
I'm still learning a bit about Drupal and especially CCK, or I would attempt a patch myself, but I don't quite know enough yet.
Comments
Comment #1
beauregard commentedit would be great when we could define per text field what the applied input format should be.
Comment #2
RayZ commentedComment #3
dave reidI'm really wanting this feature as well. I'm going to see if I can create a patch for this in the next couple of days.
Comment #4
cburschkaSubscribing.
I wanted something like this for the longest time as well.
I've recently hacked it in in my version of the Text module, by changing the "user selects input format" to the value "-1" (plain text remains "0"), leaving the way free for setting a fixed input format (which are numbered from "1" upwards). It's a bit ugly; perhaps the real patch should use two fields (the first offers the options "plain text", "user selects", "fixed", and the second field offers the default format that should be used).
Comment #5
cburschkaI don't have time to make a formal patch (and this is a dirty hack anyway, so it shouldn't be used as-is anyway), but here's a diff on my changed file:
Basically, "1" to "-1", then the options for the input formats get added. The condition that checks if a format selector needs to be displayed is extended to remove it not only for "0", but also for greater values. And there's an extra condition in the formatter function that runs it through the proper format filter.
But, as said, it would be much better with two separate fields, especially as that would make it possible to set a default format, but let the user choose another.
Comment #6
ambereyes commentedArancaytar
What version of content.module is this patch against? And can you attach an actual patch file?
Comment #7
highermath commentedIt applies to the text.module, not the content.module.
Thanks for this!
Comment #8
noah@groups.drupal.org commentedAny progress on this?
Comment #9
cburschkaThe patch I have in mind (and have started working on) will do this:
- add another option to "Text processing" - "Filtered text (fixed input format)"
- add a select menu titled "Default format", containing all input formats applicable (filter_formats())
If text processing is set to plain, default format is ignored.
If it is set to user selection, the input format selection form will pre-select the default format (overriding access rights to add it if the user normally can't use it).
If it's set to fixed, the input format selection form will not be shown at all.
----
I'm not sure whether to save the input format for each node the field is made in, regardless of whether the format is set to fixed or not. Doing so makes the filtering process far easier, but on the other hand changing the default format won't be retroactive.
Comment #10
cburschkaCan't win them all. I looked at http://api.drupal.org/api/5/function/filter_form, and overriding the access permissions seems to require tedious re-implementation of a lot of its form-building code. So I left the overriding part out: If Text processing allows a user-selected input format, then the user can only see those formats they have access to, regardless of what the default format is set to. I'll have to test this a bit more to see what actually happens when calling filter_form with a "pre-selected default" that isn't listed.
The rest works, though: Fixed input format fields are rendered correctly, user-selected input format fields get the format selector with the proper format pre-selected.
This patch is rolled against DRUPAL-5, not HEAD. According to a warning message in the repository, HEAD already contains 6.x code, and I'd rather see this in 5.x-1.x-dev first than have to wait and then backport. However, on accidentally checking out HEAD, it seemed that my changes were merged in without conflict; porting to 6.x shouldn't be a major problem.
Comment #11
fersman4 commentedTested and works perfectly. Thanks!
Comment #12
cburschkaIf so, could this be RTBCd?
Comment #13
highermath commentedDitto on the patch working perfectly. It would be nice it this was in CCK for 6.x and rolled into 5.x.
Comment #14
goddess commentedThank you. I came here looking for exactly this, and the patch worked perfectly.
Comment #15
meatbites commentedA godsend, Arancaytar. Your patch works perfectly.
Comment #16
cburschkaNot to come off as impatient, but this is dropping off the page again, and it appears to work, mostly.
I have another week to make changes to the patch if necessary, after that it will fall to someone else or have to wait till November or later...
Comment #17
Waldemar commentedThis works great for me. Can this please be committed it is very useful!
Thanks.
Comment #18
OpenChimp commentedThank you for this. Makes life so much easier. I had a field into which the administrator needed to paste buy ticket button code from a ticket vendor. Unfortunately, the code contained onclick JS, which needed to be there, or the buttons don't work. So if the administrator didn't change the input format from the default to one which didn't strip out these types of code, then the buttons wouldn't work.
Asking most site admins who are adding content to remember to change the input format for a specific field just isn't practical, so this patch is exactly what is needed. Obviously it would be nice to be able to lock the input type for a field, but this patch works great as is.
Thanks much. I hope this will be added to the module for the next release, as I bet a lot of other users would also find it useful.
Comment #19
cburschkaGreggles kindly checked this, and I have made a new version that fixes several indentation errors (the text editor invisibly substituted the spaces for tabs in some lines). The description of the new "default format" field has been slightly modified to be a little clearer. Also, several parts that are actually fairly straightforward are no longer accompanied by inline comments.
Comment #20
cburschkaI'm afraid I'm going to violate good form for a moment to at least attempt to get this some attention. I know that the patch applies, it is apparent from the responses here that it has been tested without problems in multiple production environments, and I think the last patch fixes the remaining code style issues. So at this point, any disqualifying problem is likely going to be along the lines of "this is the wrong way to do it, start over", or "there's a comma missing from an inline comment".
Either of these don't require copious testing and could be arbitrated at a glance by a maintainer, so I dare set this RTBC in the hope that a maintainer at least looks at it. If it does need work... well, at least it doesn't sit here another month with no action.
Comment #21
cburschkaOn my site, I have now added an additional modification to the patched module, that causes the fixed format's Filter Tips to be displayed. As the patch removes the input format selector on a fixed field, the filter tips were also gone. Users were confused what format the field actually expected, and adding "(BBCode allowed)" manually to the help text was a bit of a WTF design.
However, to keep the testing work from piling up, I would rather wait for a review on the current patch before uploading the new modification.
Comment #22
cburschkaI have discovered a bug that occurs during preview. If you create a field with a fixed input format that is not otherwise available to users, the field will show up as "n/a" during preview.
This is because the module tells check_markup to make an access check on the input format if the node is in preview or is empty (I'm not sure under what circumstances the node object would be empty, but that's what it says). As the fixed input format is supposed to override filter permissions, this causes anomalous behavior: While the final node displays the field as intended, during preview the filter is blocked by an access check.
To fix this, I have inserted an additional condition that will bypass the access check if the input format is not selected by the user.
Comment #23
ipwa commentedTracking the issues in this excellent patch, I will install it soon, and give feedback.
Comment #24
cburschkaNo longer my business.
I will have next to no time to dedicate to development for the next half year, and I don't plan on spending the little time I do get on making sure this patch stays clean (let alone improving it or porting it to 6.x). I've watched it for five months, and it applied when I last checked out 5.x-dev but I can't guarantee it from now on. Please take it, leave it or get someone else to track it. It's not my intention to sound bitter, sorry.
Comment #25
goddess commentedI do appreciate the work you've done on it, regardless, as it was quite helpful for me personally. Would it be possible for you to make the last patch you did available here (that addressses the n/a display bug) before you go about your life?
And thanks.
Comment #26
ragaskar commentedgoddess:
I haven't tested this code (and I'm not going to, since my needs don't require me to), but it looks like the preview bug can be fixed by changing one line in text_field_formatter in text.module.
change
to
Untested, and the access testing is there as a security sanity check, so this may be a security issue (but in theory the user would be able to view/execute the content after previewing anyways, so perhaps it's moot).
Arancaytar, thanks for putting together this patch -- saved me a little time. IMO this is a serious defect in CCK, since it is not really possible to set a default format via the form_alter hook.
Comment #27
cburschkaI've rerolled the patch from what I have currently. I think this should take care of both the n/a bug and the fixed filter tips. (From UMTS and the battery's nearly empty - hope the upload goes fine.)
Comment #28
goddess commentedThanks, folks. Much appreciated.
Comment #29
yched commentedReally sorry for letting this go for such a long time without any feedback. We've been really focused (and still are) on the 'cck for D6' port / refactoring, which is critical for Drupal 6 to actually 'take'.
I agree that this would be a useful feature. However, messing with input formats is sensitive stuff and can lead to nasty edge cases. On a (semi-)related note, there has been several attempts in core at assigning 'default input formats' to user roles, all of which were abandoned because of conceptual flaws.
Not to say the current effort should be abandoned, this just makes me a little nervous. We need more careful testing and insightful reviews than the '+1' and 'works for me' that have been voiced so far (no offense intended).
For instance, I'd think that a user trying to create / edit a node without having the rights to use the specified format for the field should get an 'access denied' page. More consistent with core behaviour : if I don't have access to the 'full HTML' format, I get access denied when trying to edit a 'Story' whose body is 'full HTML'.
Comment #30
cburschkaBut that /would/ force the input format system to either get a widely extended permissions system or to be worked around for custom fields.
For example, the site I am extensively using this for uses several content fields with "syntax-coloring" filters that are not supposed to be used anywhere else. If the "Fixed" filter has to pass the user access check, this means I either allow everyone to use this filter everywhere, or I do not use filters at all and instead write a lot of custom code when rendering the node...
The security issue lies not so much with regular users as it does with a jointly administrated site with different permissions. You would need to ensure that a Content Type admin can't give users implicit permission to use a filter in some field unless he is also an Input Format admin - while at the same time avoiding a close meshing of the two modules.
Comment #31
nbchip commentedComment #32
meatbites commentedRe-rolled a patch for CCK 5.x-1.9 based on Arancaytar's most recent patch, but with a few changes:
Comment #33
spiffyd commentedAny chance this can be ported to 6.x? Or does this feature already exist? Thanks!
Comment #34
mikeytown2 commented6.x Request as well.
Or is there another cck module that allows full html/php input already?
Comment #35
mattiasj commentedI think it would be great to be able to use Markdown syntax in custom CCK fields, and as far I understand that is what this discussion is about.
Comment #36
TripleEmcoder commentedHow about doing this the way the http://drupal.org/project/filterbynodetype module does for node bodies? I allows to select any number of input formats valid for a node type. So if you select only one then the input format is fixed, as suggested in this discussion.
One way or the other consider this an official 6.x feature request ;-)
Comment #37
gagarine commentedtracking
Comment #38
markus_petrux commentedMay I suggest giving the Better Formats module a try?
Comment #39
TripleEmcoder commentedWell, Better Formats' description sound great, but from this http://drupal.org/node/350696 it seems that the module doesn't really do what this issue is all about (at least not in the current 1.x version).
Comment #40
nigelcunningham commentedThis patch works for me against cck-6.x-2.5. It's not as feature filled as the 5.x version in earlier comments, but might help someone.
There is an interaction with Better Formats you should be aware of - if Better Formats is enabled and you've specified a fixed format for a field, the Input Formats part of the form may still appear when a user adds/edits a node. The patch will still do its work, but users might be confused by seeing an Input Formats section that's ineffective.
The attach widget isn't working for me, so I'll try inlining the code.
Comment #41
markus_petrux commentedThis is being implemented in Better formats module. Please, check out: #350696: Per field format settings with full BF options via CCK widget.