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.
#375907: Make text field use D7 '#text_format' selector shows a need to specify a custom name for the key under which the selected text format comes up in form values, instead of currently hardcoding '[parent_element_key]_format'
Proposal patch coming later today.
Comment | File | Size | Author |
---|---|---|---|
#21 | drupal.text-format-21.patch | 6.82 KB | sun |
#13 | drupal.text-format-13.patch | 7.3 KB | sun |
#10 | drupal.text-format-10.patch | 7.85 KB | sun |
#7 | drupal.text-format.patch | 2.34 KB | sun |
#6 | form_text_format-412016-4.patch | 1.2 KB | yched |
Comments
Comment #1
sunThis is critical.
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commented#text_format itself is an awful hack, so I fail to see why this is critical.
Comment #3
KarenS CreditAttribution: KarenS commentedIt is critical because it is becoming a blocker for the progress of Fields in core, see http://drupal.org/node/375907#comment-1392522. To have body as a field we need #text_format to be smarter.
Comment #4
yched CreditAttribution: yched commentedPatch is pretty trivial, introduces an optional #text_format_key property to specify the key under which the text format will be available in form_state['values']
The corresponding PHPdoc kind of beats me for now, suggestions welcome.
Comment #5
David_Rothstein CreditAttribution: David_Rothstein commentedI think you may have attached the wrong patch? :)
Comment #6
yched CreditAttribution: yched commentedOops, wrong patch indeed.
Here's the correct one.
Comment #7
sunAlternative implementation.
Comment #8
Heine CreditAttribution: Heine commentedThis makes something fugly even fuglier. There's plenty of time until the code freeze to shoot #text_format in the face and go with a sane approach, ie: 1) give a richtext element its rightful place in the FAPI elements pantheon. And 2) always carry format and text around together (object / array).
Comment #9
yched CreditAttribution: yched commented@Heine : possibly so, but right now it's what we have, and its current limitations make it unsuitable for fields.
If it gets kicked out later in favor of a cleaner approach, great, but that's still hypothetical. We need to move forward.
@sun: works for me
Comment #10
sunNow with full tests.
And, yes, I don't like internal form processing. We want to exactly test what developers expect in their form submit handlers.
Comment #11
David_Rothstein CreditAttribution: David_Rothstein commentedAt first glance, @yched's patch in #6 looks better to me because it's nice and simple. Whereas if #text_format is sometimes an integer and sometimes an array, it seems like that will tend to lead to buggy code. For example, if I'm writing a hook_form_alter() implementation to change the default text format, I'd like to just be able to change it -- but now it seems in order to avoid bugs I'd have to write separate logic to change it differently based on whether it is an array or not. What is the proposed benefit of the more complicated approach?
And yes, the whole #text_format thing itself is a hack - see #125315: Textarea with input format attached for voluminous discussion, alternative implementations, etc. However, it's better than Drupal 6, which is what counts :) If someone wants to reopen the other issue I think that would be absolutely great, but that shouldn't stop this issue from going forward, IMO.
Comment #12
chx CreditAttribution: chx commentedI can't say I love #text_format meaning two different things. If we do need that array in the form, define a new property but do not double load one property. In this regard, I dig #6 more because it does add a new property. It might be that #6 is not enough and we need all three which is fine. Do we need all three?
Comment #13
sunWell, also allowing to alter the weight was my reasoning.
Anyway, if all of you prefer a separate FAPI property, then yeah.
Comment #14
KarenS CreditAttribution: KarenS commentedSo #13 is basically the same as #6 with more documentation and tests :) Anyway, I agree with this -- keep it simple, especially if there will be followup discussions about ways to clean the whole process up.
Comment #15
Damien Tournoud CreditAttribution: Damien Tournoud commentedPlease just JSON $form_state['values'] and do proper testing on the parent side.
Comment #16
sunWhy another layer of indirection? So if conversion to JSON is broken, this test will pass? Where's the logic in that?
Comment #17
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is still a hack on a hack. Let's do that properly, and postpone this in favor of #414424: Introduce Form API #type 'text_format'.
Comment #18
sunI disagree.
We want to proceed with #375907: Make text field use D7 '#text_format' selector, which depends on this issue. I'll take care of #414424: Introduce Form API #type 'text_format' once the relevant issues (listed over there) have been committed.
Also, I still don't see why and how testing values in JSON would be better here. The test, as it stands, tests _exactly_ what developers expect, without another layer of indirection. If anything in this process does not work as it should, this test will expose it.
Comment #19
sunComment #21
sunRe-rolled, since #304330: Text format widget has landed.
Comment #22
Dries CreditAttribution: Dries commentedI'd prefer to see us focus on #414424: Introduce Form API #type 'text_format' first but I'm comfortable committing this because it comes with tests. Parts of these tests are re-usable, and the parts that fail will tell us what code to undo/redo. Ultimately, it comes down to timing. If someone volunteers to start work on #414424 in the next day or two, I might hold back this patch, but in absence of that, I will proceed with this.
Comment #24
webchickComment #26
suntestbot?
Comment #28
sunThis was never committed, and in the meantime, it seems we have a much better solution to the overall problem over in #414424: Introduce Form API #type 'text_format'.
I need reviews over there.