Closed (duplicate)
Project:
Drupal core
Version:
7.x-dev
Component:
filter.module
Priority:
Major
Category:
Feature request
Assigned:
Reporter:
Created:
27 Jan 2012 at 17:46 UTC
Updated:
21 May 2012 at 03:10 UTC
Jump to comment: Most recent file
Comments
Comment #1
wjaspers commentedAdding patch for testing.
Comment #2
wjaspers commentedComment #4
wjaspers commentedJust leaving a note for myself:
In the test case 'text_processing' is a boolean.
Questions to the greater community:
A. Does the test case need to be updated?
B. Should the patch be updated to allow the field settings to use checkboxes instead of radio buttons? Then the field definition can allow multiple specific formats (assuming the end user has access to each of them).
Comment #5
wjaspers commentedJust for anyone who's interested to see that this is working...
I just need to resolve the testing and this patch should apply nicely.
Comment #6
wjaspers commentedFigured out how to make the field capable of defining multiple specific text formats, but at the moment I don't know how much this will affect other areas of core. Still trying to figure out the best course of action for #4.
Comment #7
wjaspers commentedI think I got it now. This patch will allow the formatter to define either "plain text", a single, or multiple formats.
EDITED: Updated to re-trigger test request.
Comment #9
willvincent commentedTestTranslationTestCase is failing, that looks like the only issue
Comment #10
tstoecklerIn general this looks really good. Below is a code-review but those are mostly minor issues.
I have one more general problem with this. Instead of the Form API element trying to figure out, what Field API wants to allow as text formats, really it should be the other way around: Field API specifying upfront in text_field_widget_form() what formats it wants to allow.
The problem is that there is no facility for that in the
#text_formatForm API element. So I would suggest opening a new issue for that, something á la: "Introduce a #formats property for the #text_format element, to preselect/-reduce available formats"Here's the detailed review:
Minor, but I think
if ($format->status)would be more concise. That's just my opinion, though.These changes need to be reverted, the indentation was fine before.
We can initialize the default value of these settings in text_field_info(). That way the check isn't needed.
Yay, I love more #states in core!!!
That comment is incorrect. The condition itself is OK, but it is not described correctly.
Since
text_processingis either0or1, I think simply dropping the!empty()should be fine. That's just a matter of taste, though.I didn't try it out (yet), but I think
$field_info['settings']['text_formats']will always be set (at least if we initialize the default as explained above), so a!empty()would be in order here, I think.We don't use abbreviations in comments. Also I think "unavailable" might be misleading. Maybe we could just write:
Ideally the default would have been specified on the field instance setting form. I don't know, off the top of my hat, though, why that might not be the case.
Comment #11
wjaspers commentedTrying another shot at this where I don't try to preset $element['#format'] if multiple values are defined.
Comment #12
tstoecklerI opened #1423244: #allowed_formats property for #type 'text_format' to filter available formats.
I posted some example code there, and if it really is as easy as I claim over there, then we might want to re-merge the issues. Not sure, though.
Comment #13
wjaspers commented@tstoeckler, Thanks for all your feedback!
I generally don't like to assume that a value that even if it is 1 or 0 could be interpreted as TRUE or FALSE. On the off-chance another module modifies or fouls up the $format->status property, and its NULL, the if() could fail or worse, dump errors on the end-user.
That was a side-effect of playing around too much and forgetting to revert some changes. I've since fixed that, but thanks for catching it.
Good call, I'll give that a try.
I'll cleanup my comments.
Comment #15
wjaspers commentedJust for the sake of comment, it seems like something may be wrong with the TextTranslationTest.
I created a node with multiple longtext fields (with varying format settings), and translated it 3 times for fun. No watchdog errors, no PHP notices, and no fatals. Just to try and throw a wrench in the mix, I updated the field values here and there, but no bugs.
I've attached both the side-by-side screenshots of the original content (English [at left], up to Spanish [at right]).
I've also included a screenshot of the Devel information about a translated node. According to the tests as they failed, the value and format are both present.
Comment #16
wjaspers commentedFollowing @tstoeckler's comments, I've updated my patch. I've also renamed the settings variable we'll use to allow this functionality so its a little more descriptive.
Comment #18
wjaspers commentedHere's another crack at it. Finally figured out how to handle the #default_value property for the format setting as well.
Comment #20
tstoecklerTrailing whitespace.
This comment is incorrect. It's not about whether the user has access to this format or not. That is being handled by the code preceding the bit in the patch. This is about checking whether each of the formats that are allowed for the user, are in the allowed formats for the textfield. That said
array_intersect()could be used here, which would make the code a bit leaner.I still think this should be postponed on #1423244: #allowed_formats property for #type 'text_format' to filter available formats, so marking as such. Please revert if you disagree.
Comment #21
wjaspers commentedNoting that #1295248: Allow per-field-instance configuration of allowed formats is also out there.
Comment #22
David_Rothstein commentedThis is a duplicate of #784672: Allow text field to enforce a specific text format, which is the equivalent issue for Drupal 8. We should only have one issue open for this, and any patch needs to get committed to Drupal 8 first before being considered for possible Drupal 7 backport.
As far as I know, closing this will not prevent the testbot from testing any patches that are posted here (I could be wrong though)... If so, this issue could still be used as a place to get the testbot to test Drupal 7 versions of any patches, which was the original reason it was opened above.