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.
Problem/Motivation
Better Formats currently only works with Fields.
Proposed resolution
Allow developers to trigger Better Formats hiding of format options when creating custom forms using Drupal's form API.
Remaining tasks
Unknown.
User interface changes
None.
API changes
You are able to trigger Better Formats programatically on custom forms built
with the form API:
function my_example_form($form, &$form_state) {
$form = array();
$form['example_text_field'] = array(
'#title' => 'Contribution message ',
'#type' => 'text_format',
'#format' => 'teaser_text',
);
$form['example_text_field']['better_formats'] = array(
'#show_selection' => FALSE,
'#show_tips' => FALSE,
'#show_tips_link' => FALSE,
);
return $form;
}
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#5 | fapi_support-2845424-5.patch | 2.21 KB | michel.g |
#4 | fapi_support-2845424-4.patch | 2.56 KB | PieterDC |
#2 | fapi_support-2845424-2.patch | 2.18 KB | jstoller |
Comments
Comment #2
jstollerPatch attached.
Comment #3
PieterDCThe good: patch works and does not break backwards compatibility.
Can be improved: use hash tags for the new FAPI options, although I'm not certain what's the best here. It can be confusing https://drupal.stackexchange.com/questions/33227/what-are-properties
Would block this patch on: missing test coverage - because the Better Formats module has no test coverage at all, so far.
Comment #4
PieterDCForgot to mention that it's also good the documentation was extended.
Suggesting improved patch.
Also fixed the unnecessary whitespace when all 3 options are set to FALSE and similar to how #2832330: Removing the format field breaks other modules suggests it should be done.
Extended the issue summary while I was at it.
Comment #5
michel.g CreditAttribution: michel.g at Randstad Digital for Government of Flanders commentedThe patch above also breaks other modules.
By setting the format type on hidden, WYSIWYG fields (such as the body) inside a node edit form are not accessible anymore.
The other changes are valid though. So I am going to contribute the same patch without the 'hidden' format type.
Comment #6
joshf CreditAttribution: joshf commented#5 is working for me. Thanks for the patch!
Comment #7
markabur CreditAttribution: markabur commented#5 works for me, thanks! RTBC
Comment #9
joseph.olstadComment #10
joseph.olstadReleased this:
https://www.drupal.org/project/better_formats/releases/7.x-1.0-beta3
And for those using PHP 8.0, PHP 8.1, PHP 8.2, use the latest 2.0 release (currently 7.x-2.0-beta1)
https://www.drupal.org/project/better_formats/releases/7.x-2.0-beta1