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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jstoller created an issue. See original summary.

jstoller’s picture

Status: Active » Needs review
FileSize
2.18 KB

Patch attached.

PieterDC’s picture

The 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.

PieterDC’s picture

Issue summary: View changes
FileSize
2.56 KB

Forgot 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.

michel.g’s picture

The 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.

joshf’s picture

#5 is working for me. Thanks for the patch!

markabur’s picture

Status: Needs review » Reviewed & tested by the community

#5 works for me, thanks! RTBC

joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed
joseph.olstad’s picture

Released 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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.