On the page /admin/config/content/formats we can order our html filters:

- Full HTML
- Filtered HTML
- Plain Text
- PHP Code

However, Drupal assigns negative weights to order these values (which should not be a problem).
When we use the function filter_default_format() we expect to see 'full_html' as a result. However, we get 'filtered_html' instead.

To solve this we updated the weight of the html filters to use only values >= 0. So full_html would have weight 0 and PHP code weight 3.
Only now filter_default_format() results in 'full_html' as it should have been from the start.

Comments

dame created an issue. See original summary.

David_Rothstein’s picture

Status: Active » Postponed (maintainer needs more info)

I can't reproduce this. I rearranged to put Full HTML on top, confirmed the weights were negative, then saved. Afterwards filter_default_format() returned "full_html" for me.

Note that calling filter_default_format() without passing in a user account returns the default format for the current logged-in user. Is it possible that the first time you ran this code it was with a user who does not have access to the "full_html" format?

David_Rothstein’s picture

Component: other » filter.module
dame’s picture

I ran it as "admin" on a project that is nearly ready for production.
filter_default_format() is used in a drush call that sets "full_html" for all our body fields that we migrated (the migration itself didn't set the filter right).

That is how I discovered the issue.

I suppose that executing via drush would make filter_default_format() return the default filter for anonymous users? (which was probably not "full html")

David_Rothstein’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Right. A Drush command will normally be run as the anonymous user, so I think that's probably what happened. I'm going to close this for now, but feel free to reopen if it turns out there's a reproducible problem.

filter_default_format() is used in a drush call that sets "full_html" for all our body fields that we migrated (the migration itself didn't set the filter right).

Maybe you've tried this already - but if it's one-time migration code and you know you want the result to be "full_html", you could consider just hardcoding that instead.

dame’s picture

The problemm is that I hard coded it to be "full_html" but it would keep resulting in filtered_html fields.
That is how I discovered filter_default_format() --> to check out that full_html was a valid option.

If this problem réoccurs on another project I will reopen this ticket with steps to reproduce