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.
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
Comment #2
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedI 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?
Comment #3
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedComment #4
dame CreditAttribution: dame commentedI 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")
Comment #5
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedRight. 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.
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.
Comment #6
dame CreditAttribution: dame commentedThe 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